ushort GetRelocationKey(RelocationPointerInfo info) // Details about a pointer to a certain block { return(GetRelocationKey(info.module, info.id)); }
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; } } } } }