Ejemplo n.º 1
0
 private static string GetString(DataReader reader, int offset)
 {
     int tempOffset = reader.Offset;
     reader.SetOffset(offset);
     var value = reader.ReadZString();
     reader.SetOffset(tempOffset);
     return value;
 }
Ejemplo n.º 2
0
        private static string GetString(DataReader reader, int offset)
        {
            int tempOffset = reader.Offset;

            reader.SetOffset(offset);
            var value = reader.ReadZString();

            reader.SetOffset(tempOffset);
            return(value);
        }
Ejemplo n.º 3
0
        public void ReadDirectory()
        {
            var reader     = new DataReader(FileData, _startOffset, _dataLen);
            var numEntries = reader.ReadInt32();

            for (var entry = 0; entry < numEntries; ++entry)
            {
                if (EngineVersion.ReturnToArms == _engineVersion || EngineVersion.JusticeLeagueHeroes == _engineVersion)
                {
                    var stringOffset = reader.ReadInt32();
                    var dataOffset   = reader.ReadInt32();
                    var dataLength   = reader.ReadInt32();

                    var tempOffset = reader.Offset;
                    reader.SetOffset(stringOffset);
                    var name = reader.ReadZString();
                    reader.SetOffset(tempOffset);

                    var info = new EntryInfo()
                    {
                        Name = name, StartOffset = dataOffset + _startOffset, Length = dataLength
                    };
                    Directory[name] = info;
                }
                else
                {
                    var headerOffset = _startOffset + 4 + entry * 64;
                    var subfileName  = DataUtil.GetString(FileData, headerOffset);

                    var subOffset = BitConverter.ToInt32(FileData, headerOffset + 56);
                    var subLen    = BitConverter.ToInt32(FileData, headerOffset + 60);

                    var info = new EntryInfo()
                    {
                        Name        = subfileName,
                        StartOffset = subOffset + _startOffset,
                        Length      = subLen
                    };
                    Directory[subfileName] = info;
                }
            }
        }
Ejemplo n.º 4
0
        public void ReadDirectory()
        {
            var reader = new DataReader(FileData, _startOffset, _dataLen);
            int numEntries = reader.ReadInt32();

            for (int entry = 0; entry < numEntries; ++entry) {
                if (EngineVersion.ReturnToArms == _engineVersion)
                {
                    int stringOffset = reader.ReadInt32();
                    int dataOffset = reader.ReadInt32();
                    int dataLength = reader.ReadInt32();

                    var tempOffset = reader.Offset;
                    reader.SetOffset(stringOffset);
                    var name = reader.ReadZString();
                    reader.SetOffset(tempOffset);

                    var info = new EntryInfo() { Name = name, StartOffset = dataOffset + _startOffset, Length = dataLength };
                    Directory[name] = info;
                }
                else
                {
                    int headerOffset = _startOffset + 4 + entry * 64;
                    String subfileName = DataUtil.GetString(FileData, headerOffset);

                    int subOffset = BitConverter.ToInt32(FileData, headerOffset + 56);
                    int subLen = BitConverter.ToInt32(FileData, headerOffset + 60);

                    var info = new EntryInfo()
                    {Name = subfileName, StartOffset = subOffset + _startOffset, Length = subLen};
                    Directory[subfileName] = info;
                }
            }
        }
Ejemplo n.º 5
0
        public static Script Decode(byte[] data, int startOffset, int length)
        {
            if (length == 0)
            {
                return(new Script());
            }

            var reader = new DataReader(data, startOffset + HEADER_SIZE, length);

            var script = new Script
            {
                offset0 = reader.ReadInt32(),
                hw1     = reader.ReadInt16(),
                hw2     = reader.ReadInt16(),
                hw3     = reader.ReadInt16(),
                hw4     = reader.ReadInt16(),

                instructionsOffset = reader.ReadInt32(),
                stringsOffset      = reader.ReadInt32(),

                offset3 = reader.ReadInt32(),
                offset4 = reader.ReadInt32(),
                offset5 = reader.ReadInt32(),

                numInternals    = reader.ReadInt32(),
                offsetInternals = reader.ReadInt32(),
                numExternals    = reader.ReadInt32(),
                offsetExternals = reader.ReadInt32()
            };

            var internalOffset = startOffset + script.offsetInternals + HEADER_SIZE;

            for (var i = 0; i < script.numInternals; ++i)
            {
                var internalReader = new DataReader(data, internalOffset, 0x18);
                var labelAddress   = internalReader.ReadInt32();
                var label          = internalReader.ReadZString();
                script.internalsByAddr.Add(labelAddress, label);
                internalOffset += 0x18;
            }

            var externalOffset = startOffset + script.offsetExternals + HEADER_SIZE;

            script.externals = new string[script.numExternals];
            for (var i = 0; i < script.numExternals; ++i)
            {
                var externalReader = new DataReader(data, externalOffset, 0x18);
                var labelAddress   = externalReader.ReadInt32();
                if (labelAddress != 0)
                {
                    script.parseWarnings += "found a non-zero external label address\n";
                }
                var label = externalReader.ReadZString();
                script.externals[i] = label;

                externalOffset += 0x18;
            }

            var stringTableLen  = script.offset3 - script.stringsOffset;
            var instructionLen  = script.stringsOffset - script.instructionsOffset;
            var thisStringStart = -1;
            var stringReader    = new DataReader(data, startOffset + HEADER_SIZE + script.stringsOffset, stringTableLen + 1);
            var thisString      = new StringBuilder();

            for (var i = 0; i < stringTableLen; i += 4)
            {
                if (thisStringStart < 0)
                {
                    thisString      = new StringBuilder();
                    thisStringStart = i;
                }
                var bytes = stringReader.ReadBytes(4);
                for (var b = 3; b >= 0; --b)
                {
                    if (bytes[b] != 0)
                    {
                        thisString.Append((char)bytes[b]);
                    }
                    else
                    {
                        script.stringTable.Add(thisStringStart, thisString.ToString());
                        thisStringStart = -1;
                        break;
                    }
                }
            }
            DecodeInstructions(script, data, startOffset + HEADER_SIZE + script.instructionsOffset, instructionLen);
            return(script);
        }
Ejemplo n.º 6
0
        public static CutScene Decode(byte[] data, int startOffset, int length)
        {
            if (length == 0)
            {
                return(new CutScene());
            }

            var reader = new DataReader(data, startOffset, length);

            var scene = new CutScene
            {
                flags                = reader.ReadInt32(),
                keyframeOffset       = reader.ReadInt32(),
                numKeyframes         = reader.ReadInt32(),
                characterBlockOffset = reader.ReadInt32(),
                numCharacters        = reader.ReadInt32()
            };

            reader.SetOffset(0x20);
            scene.subtitles = reader.ReadZString();
            reader.SetOffset(0x48);
            scene.string48 = reader.ReadZString();
            reader.SetOffset(0x70);
            scene.scale    = reader.ReadInt32();
            scene.string74 = reader.ReadZString();

            for (var c = 0; c < scene.numCharacters; ++c)
            {
                var character = new CutScene.Character();

                var charOffset = scene.characterBlockOffset + c * 0x2C;
                reader.SetOffset(charOffset);
                character.extra0 = reader.ReadInt32();
                character.extra4 = reader.ReadInt32();
                character.name   = reader.ReadZString();
                reader.SetOffset(charOffset + 0x1C);
                character.x   = reader.ReadFloat();
                character.y   = reader.ReadFloat();
                character.z   = reader.ReadFloat();
                character.s28 = reader.ReadInt16();
                scene.cast.Add(character);
            }

            for (var kf = 0; kf < scene.numKeyframes; ++kf)
            {
                var keyframe = new CutScene.Keyframe();
                var kfOffset = scene.keyframeOffset + kf * 0x14;
                reader.SetOffset(kfOffset);
                keyframe.time   = reader.ReadFloat();
                keyframe.actor  = reader.ReadInt16();
                keyframe.action = reader.ReadInt16();
                keyframe.i8     = reader.ReadInt32();
                keyframe.ic     = reader.ReadInt32();
                keyframe.i10    = reader.ReadInt32();
                if (keyframe.actor == -100 && keyframe.action == 5)
                {
                    reader.Rewind(12);
                    keyframe.f8  = reader.ReadFloat();
                    keyframe.fc  = reader.ReadFloat();
                    keyframe.f10 = reader.ReadFloat();
                }

                scene.keyframes.Add(keyframe);
            }

            return(scene);
        }