Exemplo n.º 1
0
        public static void ReplaceScriptsInBIN(string path, string originalPath)
        {
            using (var reader = new TGELib.IO.EndianBinaryReader(File.OpenRead(path), TGELib.IO.Endianness.LittleEndian))
                using (var writer = new TGELib.IO.EndianBinaryWriter(File.Create(path + ".Replaced"), TGELib.IO.Endianness.LittleEndian))
                {
                    while (reader.Position != reader.BaseStream.Length)
                    {
                        // read source entry fields
                        var fileName  = reader.ReadString(TGELib.IO.StringBinaryFormat.FixedLength, 0xFC);
                        int fileSize  = reader.ReadInt32();
                        var fileBytes = reader.ReadBytes(fileSize);
                        reader.Position = AlignmentHelper.Align(reader.Position, 64);

                        // transform bytes depending on the extension
                        if (fileName.EndsWith("bmd"))
                        {
                            fileBytes = ReplaceMessageScript(fileBytes);
                        }
                        else if (fileName.EndsWith("bf"))
                        {
                            fileBytes = ReplaceFlowScript(fileBytes);
                        }

                        // write output entry fields
                        writer.Write(fileName, TGELib.IO.StringBinaryFormat.FixedLength, 0xFC);
                        writer.Write(fileBytes.Length);
                        writer.Write(fileBytes);
                        writer.Position = AlignmentHelper.Align(writer.Position, 64);
                    }
                }
        }
Exemplo n.º 2
0
        public static void ReplaceScriptsInPM1(string path, string originalPath)
        {
            using (var reader = new TGELib.IO.EndianBinaryReader(File.OpenRead(path), TGELib.IO.Endianness.LittleEndian))
                using (var writer = new TGELib.IO.EndianBinaryWriter(File.Create(path + ".Replaced"), TGELib.IO.Endianness.LittleEndian))
                {
                    reader.SeekCurrent(0x50);
                    int type    = reader.ReadInt32();
                    int size    = reader.ReadInt32();
                    int count   = reader.ReadInt32();
                    int address = reader.ReadInt32();

                    if (type != 6 || count == 0 || count == 2)
                    {
                        return;
                    }

                    reader.SeekBegin(address);
                    var bytes          = ReplaceMessageScript(reader.ReadBytes(size));
                    int remainingBytes = (int)(reader.BaseStreamLength - reader.Position);

                    reader.SeekBegin(0);
                    if (bytes.Length <= size)
                    {
                        writer.Write(reader.ReadBytes(address));
                        writer.Write(bytes);
                        for (int i = 0; i < size - bytes.Length; i++)
                        {
                            writer.Write((byte)0);
                        }
                        reader.SeekCurrent(size);
                        writer.Write(reader.ReadBytes(remainingBytes));
                    }
                    else
                    {
                        // write source bytes up until message script header fields
                        writer.Write(reader.ReadBytes(0x50));

                        // write message script fields
                        writer.Write(6);
                        writer.Write(bytes.Length);
                        writer.Write(1);
                        writer.Write((int)reader.BaseStreamLength);

                        // seek past original fields
                        reader.SeekCurrent(0x10);

                        // write source bytes up until end of file
                        remainingBytes = (int)(reader.BaseStreamLength - reader.Position);;
                        writer.Write(reader.ReadBytes(remainingBytes));

                        // append the new script to the file
                        writer.Write(bytes);
                    }
                }
        }
Exemplo n.º 3
0
        public static void ReplaceScriptsInBVP(string path, string originalPath)
        {
            using (var reader = new TGELib.IO.EndianBinaryReader(File.OpenRead(path), TGELib.IO.Endianness.LittleEndian))
                using (var writer = new TGELib.IO.EndianBinaryWriter(File.OpenWrite(path + ".Replaced"), TGELib.IO.Endianness.LittleEndian))
                {
                    // read first entry
                    int flags   = reader.ReadInt32();
                    int address = reader.ReadInt32();
                    int size    = reader.ReadInt32();

                    int firstAddress = address;
                    int nextAddress  = firstAddress;

                    while (reader.Position < firstAddress)
                    {
                        // read & Replace message script
                        reader.EnqueuePosition();
                        reader.SeekBegin(address);
                        var bytes = ReplaceMessageScript(reader.ReadBytes(size));
                        reader.SeekBegin(reader.DequeuePosition());

                        // write new entry
                        writer.Write(flags);
                        writer.Write(nextAddress);
                        writer.Write(bytes.Length);

                        // write new message script
                        writer.EnqueuePosition();
                        writer.SeekBegin(nextAddress);
                        writer.Write(bytes);

                        // write padding
                        for (int i = 0; i < AlignmentHelper.GetAlignedDifference(writer.Position, 16); i++)
                        {
                            writer.Write((byte)0);
                        }

                        nextAddress = (int)writer.Position;

                        writer.SeekBegin(writer.DequeuePosition());

                        // read next entry
                        flags   = reader.ReadInt32();
                        address = reader.ReadInt32();
                        size    = reader.ReadInt32();
                    }
                }
        }