Example #1
0
File: SNA.cs Project: Zax37/raymap
        public void ReadGPT(string path, RelocationTable rtp)
        {
            this.rtp = rtp;
            Stream gptStream = FileSystem.GetFileReadStream(path);
            uint   gptOffset = (uint)data.Length;

            byte[] gptData = null;
            using (Reader gptReader = new Reader(gptStream, Settings.s.IsLittleEndian)) {
                int maskBytes = Settings.s.encryptPointerFiles ? gptReader.InitMask() : 0;
                gptData = gptReader.ReadBytes((int)gptStream.Length - maskBytes);
            }
            //Util.ByteArrayToFile(path + ".dmp", gptData);
            AppendData(gptData);
            SNAMemoryBlock block;

            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                ushort ptrRelocationKey = GetRelocationKey(rtp.pointerBlocks[0]);
                block = relocation_local[ptrRelocationKey];
            }
            else
            {
                // Tonic Trouble LVL
                block = new SNAMemoryBlock();
            }
            block.pointerList  = null;
            block.dataPosition = gptOffset;
            block.size         = (uint)gptData.Length;
            block.isGpt        = true;
            gpt          = block;
            headerOffset = gpt.dataPosition;
            //R3Loader.Loader.print("Base " + block.baseInMemory + " - Size: " + block.size);
        }
Example #2
0
File: SNA.cs Project: Zax37/raymap
        public void ReadPTX(string path, RelocationTable rtt)
        {
            this.rtt = rtt;
            Stream ptxStream = FileSystem.GetFileReadStream(path);
            uint   ptxOffset = (uint)data.Length;

            byte[] ptxData = null;
            using (Reader ptxReader = new Reader(ptxStream, Settings.s.IsLittleEndian)) {
                int maskBytes = Settings.s.encryptPointerFiles ? ptxReader.InitMask() : 0;
                ptxData = ptxReader.ReadBytes((int)ptxStream.Length - maskBytes);
            }
            //Util.ByteArrayToFile(path + ".dmp", ptxData);
            AppendData(ptxData);
            ptx = new SNAMemoryBlock();
            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                // It doesn't exist in Tonic Trouble
                ushort         ptrRelocationKey = GetRelocationKey(rtt.pointerBlocks[0]);
                SNAMemoryBlock block            = relocation_local[ptrRelocationKey];
                ptx.baseInMemory = block.baseInMemory;
                ptx.id           = block.id;
                ptx.module       = block.module;
                ptx.maxPosMinus9 = block.maxPosMinus9;
                ptx.pointerList  = rtt.pointerBlocks[0];
            }
            ptx.dataPosition = ptxOffset;
            ptx.position     = ptxOffset;
            ptx.size         = (uint)ptxData.Length;
            ptx.sna          = this;
            //R3Loader.Loader.print("Base " + block.baseInMemory + " - Size: " + block.size);
        }
Example #3
0
File: SNA.cs Project: Zax37/raymap
        public void ReadDLG(string path, RelocationTable rtd)
        {
            this.rtd = rtd;
            Stream dlgStream = FileSystem.GetFileReadStream(path);
            uint   dlgOffset = (uint)data.Length;

            byte[] dlgData = null;
            using (Reader dlgReader = new Reader(dlgStream, Settings.s.IsLittleEndian)) {
                int maskBytes = Settings.s.encryptPointerFiles ? dlgReader.InitMask() : 0;
                dlgData = dlgReader.ReadBytes((int)dlgStream.Length - maskBytes);
            }
            //Util.ByteArrayToFile(path + ".dmp", gptData);
            AppendData(dlgData);
            SNAMemoryBlock block;

            if (Settings.s.engineVersion > Settings.EngineVersion.Montreal)
            {
                ushort ptrRelocationKey = GetRelocationKey(rtd.pointerBlocks[0]);
                block = relocation_local[ptrRelocationKey];
            }
            else
            {
                block = new SNAMemoryBlock();
            }
            block.pointerList  = null;
            block.dataPosition = dlgOffset;
            block.size         = (uint)dlgData.Length;
            block.isGpt        = true;
            dlg = block;
            //R3Loader.Loader.print("Base " + block.baseInMemory + " - Size: " + block.size);
        }
Example #4
0
        public void ReadPTX(string path, RelocationTable rtt)
        {
            this.rtt = rtt;
            Stream ptxStream = File.OpenRead(path);
            uint   ptxOffset = (uint)data.Length;

            byte[] ptxData = null;
            using (EndianBinaryReader gptReader = new EndianBinaryReader(ptxStream, MapLoader.Loader.IsLittleEndian)) {
                ptxData = gptReader.ReadBytes((int)ptxStream.Length);
            }
            data = data.Concat(ptxData).ToArray(); //Array.Resize(ref data, (int)(data.Length + gptData.Length));
            reader.Close();
            reader = new EndianBinaryReader(new MemoryStream(data), MapLoader.Loader.IsLittleEndian);
            ushort         ptrRelocationKey = GetRelocationKey(rtp.pointerBlocks[0]);
            SNAMemoryBlock block            = relocation_local[ptrRelocationKey];

            ptx = new SNAMemoryBlock();
            ptx.baseInMemory = block.baseInMemory;
            ptx.dataPosition = ptxOffset;
            ptx.id           = block.id;
            ptx.module       = block.module;
            ptx.maxPosMinus9 = block.maxPosMinus9;
            ptx.pointerList  = rtt.pointerBlocks[0];
            ptx.position     = ptxOffset;
            ptx.size         = (uint)ptxData.Length;
            ptx.sna          = this;
            //R3Loader.Loader.print("Base " + block.baseInMemory + " - Size: " + block.size);
        }
Example #5
0
File: SNA.cs Project: Zax37/raymap
 public SNA(string name, Stream stream, RelocationTable rtb)
 {
     baseOffset   = 0; // we're skipping the first 4 bytes for this one.
     headerOffset = 0;
     this.name    = name;
     this.rtb     = rtb;
     using (Reader encodedReader = new Reader(stream, Settings.s.IsLittleEndian)) {
         int maskBytes = encodedReader.InitMask();
         data = encodedReader.ReadBytes((int)stream.Length - maskBytes);
     }
     reader = new Reader(new MemoryStream(data), Settings.s.IsLittleEndian);
     ReadSNA();
 }
Example #6
0
 public SNA(string name, Stream stream, RelocationTable rtb)
 {
     baseOffset   = 0; // we're skipping the first 4 bytes for this one.
     headerOffset = 0;
     this.name    = name;
     this.rtb     = rtb;
     using (EndianBinaryReader encodedReader = new EndianBinaryReader(stream, MapLoader.Loader.IsLittleEndian)) {
         encodedReader.ReadMask();
         data = encodedReader.ReadBytes((int)stream.Length - 4);
     }
     reader = new EndianBinaryReader(new MemoryStream(data), MapLoader.Loader.IsLittleEndian);
     ReadSNA();
 }
Example #7
0
        private void RelocatePointerFile(SNAMemoryBlock pf, RelocationTable rt)
        {
            MapLoader l = MapLoader.Loader;

            reader.BaseStream.Seek(pf.dataPosition, SeekOrigin.Begin);
            foreach (RelocationPointerList ptrList in rt.pointerBlocks)
            {
                int listIndex = 0;
                for (uint i = 0; i < pf.size / 4; i++)
                {
                    uint ptrValue = reader.ReadUInt32();
                    if (ptrList.pointers[listIndex].offsetInMemory == ptrValue)
                    {
                        RelocationPointerInfo info      = ptrList.pointers[listIndex];
                        ushort         ptrRelocationKey = GetRelocationKey(info);
                        SNAMemoryBlock ptr_block_local  = relocation_local[ptrRelocationKey];
                        SNAMemoryBlock ptr_block_global = (ptr_block_local.size != 0) ? ptr_block_local : l.relocation_global[ptrRelocationKey];
                        if (ptr_block_global != null && ptr_block_local != null && ptr_block_local.baseInMemory != -1)
                        {
                            ptrValue -= (uint)ptr_block_local.baseInMemory;
                            if (info.module != tmpModule)
                            {
                                ptrValue += ptr_block_global.dataPosition;
                            }
                            Pointer pointer = new Pointer(ptrValue, ptr_block_global.sna);
                            pointers[pf.dataPosition + (i * 4)] = pointer;
                        }
                        else
                        {
                            l.print("Pointer error: SNA part (" + info.module + "," + info.id + ") not found.");
                        }
                        listIndex++;
                        if (listIndex >= ptrList.pointers.Length)
                        {
                            break;
                        }
                    }
                }
            }
        }
 // Used for Tonic Trouble's Fixlvl.rtb, which contains a list of fix->lvl pointers that should be loaded along with the fix.rtb file
 public void Add(RelocationTable rt)
 {
     if (rt == null)
     {
         return;
     }
     for (int i = 0; i < rt.pointerBlocks.Length; i++)
     {
         RelocationPointerList ptrList = GetListForPart(rt.pointerBlocks[i].module, rt.pointerBlocks[i].id);
         if (ptrList == null)
         {
             Array.Resize(ref pointerBlocks, pointerBlocks.Length + 1);
             pointerBlocks[pointerBlocks.Length - 1] = rt.pointerBlocks[i];
         }
         else
         {
             ptrList.count += rt.pointerBlocks[i].count;
             Array.Resize(ref ptrList.pointers, (int)ptrList.count);
             Array.Copy(rt.pointerBlocks[i].pointers, 0, ptrList.pointers, ptrList.count - rt.pointerBlocks[i].count, rt.pointerBlocks[i].count);
         }
     }
 }
Example #9
0
        public void ReadGPT(string path, RelocationTable rtp)
        {
            this.rtp = rtp;
            Stream gptStream = File.OpenRead(path);
            uint   gptOffset = (uint)data.Length;

            byte[] gptData = null;
            using (EndianBinaryReader gptReader = new EndianBinaryReader(gptStream, MapLoader.Loader.IsLittleEndian)) {
                gptData = gptReader.ReadBytes((int)gptStream.Length);
            }
            data = data.Concat(gptData).ToArray(); //Array.Resize(ref data, (int)(data.Length + gptData.Length));
            reader.Close();
            reader = new EndianBinaryReader(new MemoryStream(data), MapLoader.Loader.IsLittleEndian);
            ushort         ptrRelocationKey = GetRelocationKey(rtp.pointerBlocks[0]);
            SNAMemoryBlock block            = relocation_local[ptrRelocationKey];

            block.pointerList  = null;
            block.dataPosition = gptOffset;
            block.size         = (uint)gptData.Length;
            block.isGpt        = true;
            gpt          = block;
            headerOffset = gpt.dataPosition;
            //R3Loader.Loader.print("Base " + block.baseInMemory + " - Size: " + block.size);
        }
Example #10
0
File: SNA.cs Project: Zax37/raymap
        private void RelocatePointerFile(SNAMemoryBlock pf, RelocationTable rt)
        {
            MapLoader l = MapLoader.Loader;

            reader.BaseStream.Seek(pf.dataPosition, SeekOrigin.Begin);
            if (rt != null)
            {
                foreach (RelocationPointerList ptrList in rt.pointerBlocks)
                {
                    int listIndex = 0;
                    for (uint i = 0; i < pf.size / 4; i++)
                    {
                        uint ptrValue = reader.ReadUInt32();
                        RelocationPointerInfo info = null;
                        if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
                        {
                            foreach (RelocationPointerInfo info_new in ptrList.pointers)
                            {
                                if (info_new.offsetInMemory == ptrValue)
                                {
                                    info = info_new;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (ptrList.pointers[listIndex].offsetInMemory == ptrValue)
                            {
                                info = ptrList.pointers[listIndex];
                            }
                        }
                        if (info != null)
                        {
                            ushort         ptrRelocationKey = GetRelocationKey(info);
                            SNAMemoryBlock ptr_block_local  = relocation_local[ptrRelocationKey];
                            SNAMemoryBlock ptr_block_global = (ptr_block_local.size != 0) ? ptr_block_local : l.relocation_global[ptrRelocationKey];
                            if (ptr_block_global != null && ptr_block_local != null && ptr_block_local.baseInMemory != -1)
                            {
                                ptrValue -= (uint)ptr_block_local.baseInMemory;
                                if (info.module != tmpModule)
                                {
                                    ptrValue += ptr_block_global.dataPosition;
                                }
                                Pointer pointer = new Pointer(ptrValue, ptr_block_global.sna);
                                pointers[pf.dataPosition + (i * 4)] = pointer;
                            }
                            else
                            {
                                l.print("Pointer error: SNA part (" + info.module + "," + info.id + ") not found.");
                            }
                            if (Settings.s.engineVersion != Settings.EngineVersion.Montreal)
                            {
                                listIndex++;
                                if (listIndex >= ptrList.pointers.Length)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                // Tonic Trouble has rt=null for the levels, so let's go with a little hack
                for (uint i = 0; i < pf.size / 4; i++)
                {
                    uint ptrValue = reader.ReadUInt32();
                    foreach (SNAMemoryBlock block in MapLoader.Loader.relocation_global.Values)
                    {
                        if (ptrValue > block.baseInMemory && ptrValue < block.baseInMemory + block.size)
                        {
                            ptrValue -= (uint)block.baseInMemory;
                            ptrValue += block.dataPosition;
                            Pointer pointer = new Pointer(ptrValue, block.sna);
                            pointers[pf.dataPosition + (i * 4)] = pointer;
                        }
                    }
                }
            }
        }
Example #11
0
File: SNA.cs Project: Zax37/raymap
 public SNA(string name, string path, RelocationTable rtb) : this(name, FileSystem.GetFileReadStream(path), rtb)
 {
     this.path = path;
 }
Example #12
0
 public SNA(string name, string path, RelocationTable rtb) : this(name, File.OpenRead(path), rtb)
 {
 }