Example #1
0
def readAnimation(file):
    data = []
    with open(file, "rb") as f:
        br = BinaryReader(f)
        magic = br.ReadBytesToString(4, 'latin1')
        version = br.ReadInt()

        animCount = br.ReadInt()
        for i in range(animCount):
            skaPath = br.ReadBytesToString(br.ReadInt(), 'latin1')
            animName = br.ReadBytesToString(br.ReadInt(), 'latin1')
            fps = br.ReadFloat()
            numberOfFrames = br.ReadInt()
            threshold = br.ReadInt()
            isCompressed = True if br.ReadInt() else False
            customSpeed = br.ReadInt()

            bones = []
            boneCount = br.ReadInt()
            for j in range(boneCount):
                boneName = br.ReadBytesToString(br.ReadInt(), 'latin1')
                defaultPosition = br.ReadFloatToList(12)

                positions = []
                positionCount = br.ReadInt()
                for k in range(positionCount):
                    positions.append({
                        "frame": br.ReadInt16(),
                        "flags": br.ReadInt16(),
                        "position": {
                            "x": br.ReadFloat(),
                            "y": br.ReadFloat(),
                            "z": br.ReadFloat()
                        }
                    })

                rotations = []
                rotationCount = br.ReadInt()
                for k in range(rotationCount):
                    rotations.append({
                        "frame": br.ReadInt16(),
                        "flags": br.ReadInt16(),
                        "position": {
                            "w": br.ReadFloat(),
                            "x": br.ReadFloat(),
                            "y": br.ReadFloat(),
                            "z": br.ReadFloat()
                        }
                    })

                offsetLen = br.ReadFloat()

                bones.append({
                    "boneName": boneName,
                    "defaultPosition": defaultPosition,  # matrix12
                    "positions": positions,
                    "rotations": rotations,
                    "offsetLen": offsetLen
                })

            data.append({
                "skaPath": skaPath,
                "name": animName,
                "fps": fps,
                "frameCount": numberOfFrames,
                "threshold": threshold,
                "isCompressed": isCompressed,
                "customSpeed": customSpeed,
                "bones": bones,
                "morphCount": br.ReadInt()
            })

    return {"magic": magic, "version": version, "animations": data}
Example #2
0
def readMob(file):
    DEF_SMC_LENGTH = 128
    DEF_ANI_LENGTH = 64

    data = []
    with open(file, "rb") as f:
        br = BinaryReader(f)
        dataCount = br.ReadInt()

        for i in range(dataCount):
            data.append({
                "npcId": br.ReadInt(),
                "level": br.ReadInt(),
                "health": br.ReadInt(),
                "mana": br.ReadInt(),
                "flag": br.ReadInt(),
                "flag1": br.ReadInt(),
                "speed": {
                    "attack": br.ReadInt(),
                    "walk": br.ReadFloat(),
                    "run": br.ReadFloat(),
                },
                "scale": br.ReadFloat(),
                "attackArea": br.ReadFloat(),
                "size": br.ReadFloat(),
                "master": {
                    "skill": br.ByteToInt(br.ReadByte()),
                    "specialSkill": br.ByteToInt(br.ReadByte())
                },
                "skillEffect": br.ReadIntToList(5),
                "attackType": br.ByteToInt(br.ReadByte()),
                "fire": {
                    "delayCount": br.ByteToInt(br.ReadByte()),
                    "delay": br.ReadFloatToList(4),
                    "object": br.ByteToInt(br.ReadByte()),
                    "speed": br.ReadFloat()
                },
                "skill": {
                    "skill0": [br.ReadInt(),
                               br.ByteToInt(br.ReadByte())],
                    "skill1": [br.ReadInt(),
                               br.ByteToInt(br.ReadByte())]
                },
                "rvr": {
                    "grade": br.ReadInt(),
                    "value": br.ReadInt()
                },
                "bound": br.ReadFloat(),
                "model": {
                    "smc": br.ReadBytesToString(DEF_SMC_LENGTH, 'latin1'),
                    "animation": {
                        "idle": br.ReadBytesToString(DEF_ANI_LENGTH, 'latin1'),
                        "walk": br.ReadBytesToString(DEF_ANI_LENGTH, 'latin1'),
                        "damage": br.ReadBytesToString(DEF_ANI_LENGTH,
                                                       'latin1'),
                        "attack": br.ReadBytesToString(DEF_ANI_LENGTH,
                                                       'latin1'),
                        "die": br.ReadBytesToString(DEF_ANI_LENGTH, 'latin1'),
                        "run": br.ReadBytesToString(DEF_ANI_LENGTH, 'latin1'),
                        "idle2": br.ReadBytesToString(DEF_ANI_LENGTH,
                                                      'latin1'),
                        "attack2":
                        br.ReadBytesToString(DEF_ANI_LENGTH, 'latin1'),
                    },
                },
                "fireEffect": {
                    "0": br.ReadBytesToString(DEF_ANI_LENGTH, 'latin1'),
                    "1": br.ReadBytesToString(DEF_ANI_LENGTH, 'latin1'),
                    "2": br.ReadBytesToString(DEF_ANI_LENGTH, 'latin1')
                }
            })

    return data