fixed a bug when retroactively applying unk2 patches
This commit is contained in:
		| @@ -385,10 +385,14 @@ static void ApplyImportTable1Patches(CROHeader* header, u32 base, bool relocated | ||||
|     } | ||||
| } | ||||
|  | ||||
| static u32 GetCROBaseByName(char* name) { | ||||
| static u32 GetCROBaseByName(char* name, bool relocated) { | ||||
|     for (u32 base : loaded_cros) { | ||||
|         CROHeader* header = reinterpret_cast<CROHeader*>(Memory::GetPointer(base)); | ||||
|         if (!strcmp(reinterpret_cast<char*>(header) + header->name_offset, name)) | ||||
|         char* cro_name = reinterpret_cast<char*>(header) + header->name_offset; | ||||
|         if (relocated) | ||||
|             cro_name = reinterpret_cast<char*>(Memory::GetPointer(header->name_offset)); | ||||
|  | ||||
|         if (!strcmp(cro_name, name)) | ||||
|             return base; | ||||
|     } | ||||
|     return 0; | ||||
| @@ -397,7 +401,7 @@ static u32 GetCROBaseByName(char* name) { | ||||
| static void ApplyUnk2Patches(CROHeader* header, u32 base, bool relocated) { | ||||
|     for (int i = 0; i < header->unk2_num; ++i) { | ||||
|         Unk2Patch* entry = header->GetUnk2PatchEntry(i); | ||||
|         u32 cro_base = GetCROBaseByName(reinterpret_cast<char*>(Memory::GetPointer(entry->string_offset))); | ||||
|         u32 cro_base = GetCROBaseByName(reinterpret_cast<char*>(Memory::GetPointer(entry->string_offset)), relocated); | ||||
|         if (cro_base == 0) | ||||
|             continue; | ||||
|  | ||||
| @@ -421,7 +425,11 @@ static void ApplyUnk2Patches(CROHeader* header, u32 base, bool relocated) { | ||||
|             u32 target_segment_offset = table2_entry->offset_or_index >> 4; | ||||
|             SegmentTableEntry* target_base_segment = patch_cro->GetSegmentTableEntry(target_segment_id, relocated); | ||||
|  | ||||
|             Patch* first_patch = reinterpret_cast<Patch*>(Memory::GetPointer(base + table2_entry->patches_offset)); | ||||
|             Patch* first_patch = nullptr; | ||||
|             if (relocated) | ||||
|                 first_patch = reinterpret_cast<Patch*>(Memory::GetPointer(table2_entry->patches_offset)); | ||||
|             else | ||||
|                 first_patch = reinterpret_cast<Patch*>(Memory::GetPointer(base + table2_entry->patches_offset)); | ||||
|             ApplyListPatches(header, first_patch, target_base_segment->segment_offset + target_segment_offset, relocated); | ||||
|         } | ||||
|     } | ||||
| @@ -527,7 +535,7 @@ static void LoadCRO(u32 base, u8* cro, bool relocate_segments, u32 data_section0 | ||||
|     for (u32 cro_base : loaded_cros) { | ||||
|         CROHeader* cro_header = reinterpret_cast<CROHeader*>(Memory::GetPointer(cro_base)); | ||||
|         ApplyImportTable1Patches(cro_header, cro_base, true); | ||||
|         ApplyUnk2Patches(header, cro_base, true); | ||||
|         ApplyUnk2Patches(cro_header, cro_base, true); | ||||
|     } | ||||
|  | ||||
|     // Relocate all offsets | ||||
| @@ -679,7 +687,7 @@ const Interface::FunctionInfo FunctionTable[] = { | ||||
|     {0x00060042, nullptr,               "CRO_Load?"}, | ||||
|     {0x00070042, nullptr,               "LoadCROSymbols"}, | ||||
|     {0x00080042, nullptr,               "Shutdown"}, | ||||
|     {0x000902C2, nullptr,               "LoadExeCRO_New?"}, | ||||
|     {0x000902C2, LoadExeCRO,            "LoadExeCRO_New?"}, | ||||
| }; | ||||
|  | ||||
| //////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Subv
					Subv