Moved item_count function fix from Inventory.cpp to BugFixes.cpp.

Minor edit to document.
This commit is contained in:
NovaRain
2018-09-25 14:12:06 +08:00
parent ce69e8123e
commit f162a5ab0c
3 changed files with 34 additions and 34 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
---------- GLOBAL SCRIPTS -----------
-------------------------------------
As well as the new functions, sfall also adds global scripts. These run independent of any loaded maps, but do not have an attached object. (i.e. using self_obj without using set_self first will crash the script.) To use a global script, the script must have a name which begins with 'gl' and contains a procedure called 'start', 'map_enter_p_proc', 'map_exit_p_proc', or 'map_update_p_proc'. The start procedure will be executed once when the player loads a saved game or starts a new game. The map_*_p_proc procedures will be executed once when the player enters/leaves a map via exit grids or the world map, or rests/waits on a map. If you wish the script to be executed repeatedly, call set_global_script_repeat on the first run of the start procedure using the number of frames between each run as the argument. (0 disables the script, 1 runs it every frame, 2 runs it every other frame etc.)
As well as the new functions, sfall also adds global scripts. These run independent of any loaded maps, but do not have an attached object. (i.e. using self_obj without using set_self first will crash the script.) To use a global script, the script must have a name which begins with 'gl' and contains a procedure called 'start', 'map_enter_p_proc', 'map_exit_p_proc', or 'map_update_p_proc'. The start procedure will be executed once when the player loads a saved game or starts a new game. The map_*_p_proc procedures will be executed once when a map is being entered/left/updated. If you wish the script to be executed repeatedly, call set_global_script_repeat on the first run of the start procedure using the number of frames between each run as the argument. (0 disables the script, 1 runs it every frame, 2 runs it every other frame etc.)
Global scripts have multiple modes, which can be set using the set_global_script_type function. In the default mode (i.e. mode 0) their execution is linked to the local map game loop, so the script will not run in dialogs or on the world map. In mode 1 their execution is linked to the player input, and so they will run whenever the mouse cursor is visible on screen, including the world map, character dialogs etc. In mode 2, execution is linked to the world map loop, so the script will only be executed on the world map and not on the local map or in any dialog windows. Mode 3 is a combination of modes 0 and 2, so scripts will be executed on both local maps and the world map, but not in dialog windows. Using mode 1 requires the input wrapper to be enabled. Use available_global_script_types to check what is available.
+33 -2
View File
@@ -1099,6 +1099,34 @@ end:
}
}
static int __stdcall ItemCountFixStdcall(fo::GameObject* who, fo::GameObject* item) {
int count = 0;
for (int i = 0; i < who->invenSize; i++) {
auto tableItem = &who->invenTable[i];
if (tableItem->object == item) {
count += tableItem->count;
} else if (fo::func::item_get_type(tableItem->object) == fo::item_type_container) {
count += ItemCountFixStdcall(tableItem->object, item);
}
}
return count;
}
static void __declspec(naked) ItemCountFix() {
__asm {
push ebx;
push ecx;
push edx; // save state
push edx; // item
push eax; // container-object
call ItemCountFixStdcall;
pop edx;
pop ecx;
pop ebx; // restore
retn;
}
}
static void __declspec(naked) Save_as_ASCII_hack() {
__asm {
mov edx, STAT_sequence;
@@ -1579,11 +1607,11 @@ void BugFixes::init()
dlogr(" Done", DL_INIT);
//}
// Corrects the max text width of item weight in trading interface to be 64 (was 80), which matches the table width
// Corrects the max text width of the item weight in trading interface to be 64 (was 80), which matches the table width
SafeWrite32(0x475541, 64);
SafeWrite32(0x475789, 64);
// Corrects the max text width of player name in inventory to be 140 (was 80), which matches the width for item name
// Corrects the max text width of the player name in inventory to be 140 (was 80), which matches the width for item name
SafeWrite32(0x471E48, 140);
//if (GetConfigInt("Misc", "InventoryDragIssuesFix", 1)) {
@@ -1761,6 +1789,9 @@ void BugFixes::init()
// Fix crash when clicking on empty space in the inventory list opened by "Use Inventory Item On" (backpack) action icon
MakeCall(0x471A94, use_inventory_on_hack);
// Fix item_count function returning incorrect value when there is a container-item inside
MakeJump(0x47808C, ItemCountFix); // replacing item_count_ function
// Fix for Sequence stat value not being printed correctly when using "print to file" option
MakeJump(0x4396F5, Save_as_ASCII_hack);
-31
View File
@@ -643,34 +643,6 @@ end:
}
}
int __stdcall ItemCountFixStdcall(fo::GameObject* who, fo::GameObject* item) {
int count = 0;
for (int i = 0; i < who->invenSize; i++) {
auto tableItem = &who->invenTable[i];
if (tableItem->object == item) {
count += tableItem->count;
} else if (fo::func::item_get_type(tableItem->object) == fo::item_type_container) {
count += ItemCountFixStdcall(tableItem->object, item);
}
}
return count;
}
void __declspec(naked) ItemCountFix() {
__asm {
push ebx;
push ecx;
push edx; // save state
push edx; // item
push eax; // container-object
call ItemCountFixStdcall;
pop edx;
pop ecx;
pop ebx; // restore
retn;
}
}
// reimplementation of adjust_fid engine function
// Differences from vanilla:
// - doesn't use art_vault_guy_num as default art, uses current critter FID instead
@@ -866,9 +838,6 @@ void Inventory::init() {
MakeCall(0x4759F1, barter_inventory_hack2);
fo::var::max = 100;
};
// Fix item_count function returning incorrect value when there is a container-item inside
MakeJump(0x47808C, ItemCountFix); // replacing item_count_ function
}
Delegate<DWORD>& Inventory::OnAdjustFid() {