Improved the fix for "out of bounds" bug when printing the automap list

* prevent the overflow of _sortlist (holds 24 elements at max).
* NOTE: the fix just cuts off location/elevation lists, and should be
removed once a proper pagination in pipboy is implemented.
This commit is contained in:
NovaRain
2025-03-01 23:28:49 +08:00
parent 80679572c3
commit 43fb1ec5f2
+36 -26
View File
@@ -2393,24 +2393,49 @@ skip:
}
}
static __declspec(naked) void PrintAutoMapList() {
static __declspec(naked) void automap_pip_save_hook() {
__asm {
mov eax, ds:[FO_VAR_wmMaxMapNum];
mov eax, ds:[FO_VAR_map_number];
cmp eax, AUTOMAP_MAX;
jb skip;
mov eax, AUTOMAP_MAX;
jl skip;
xor eax, eax;
skip:
retn;
}
}
static __declspec(naked) void automap_pip_save_hook() {
static __declspec(naked) void PrintAMList_hook() {
__asm {
mov eax, ds:[FO_VAR_map_number];
cmp ebp, 20; // max line count for location list
jge skip;
// replace wmMapMaxCount_ function call
mov eax, ds:[FO_VAR_wmMaxMapNum];
cmp eax, AUTOMAP_MAX;
jb skip;
xor eax, eax;
jle end;
mov eax, AUTOMAP_MAX;
end:
retn;
skip:
mov ebp, 20;
xor eax, eax; // exit loop
retn;
}
}
static __declspec(naked) void PrintAMelevList_hook() {
__asm {
cmp ebp, 18; // max line count for elevation list
jge skip;
// replace wmMapMaxCount_ function call
mov eax, ds:[FO_VAR_wmMaxMapNum];
cmp eax, AUTOMAP_MAX;
jle end;
mov eax, AUTOMAP_MAX;
end:
retn;
skip:
mov ebp, 18;
xor eax, eax; // exit loop
retn;
}
}
@@ -2444,16 +2469,6 @@ static __declspec(naked) void obj_load_dude_hook1() {
}
}
static __declspec(naked) void PrintAMList_hook() {
__asm {
cmp ebp, 20; // max line count
jle skip;
mov ebp, 20;
skip:
jmp fo::funcoffs::qsort_;
}
}
static __declspec(naked) void exec_script_proc_hack() {
__asm {
test edi, edi; // loading?
@@ -4110,15 +4125,10 @@ void BugFixes::init() {
MakeCall(0x48A76B, obj_move_to_tile_hack_seen, 1);
// Fix for the overflow of the automap tables when the number of maps in maps.txt is more than 160
// also fix "out of bounds" bug when printing the automap list
HookCall(0x41C0FC, automap_pip_save_hook);
const DWORD printAutoMapAddr[] = {
0x499212, // PrintAMList_
0x499013 // PrintAMelevList_
};
HookCalls(PrintAutoMapList, printAutoMapAddr);
// Fix "out of bounds" bug when printing the automap list
HookCall(0x499240, PrintAMList_hook);
HookCall(0x499212, PrintAMList_hook);
HookCall(0x499013, PrintAMelevList_hook);
// Fix for a duplicate obj_dude script being created when loading a saved game
HookCall(0x48306E, map_load_file_hook); // removes the redundant saved dude script data from the scripts block