From a68498453c6b13d944f469fbecd301d9a5ed0e80 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Sat, 14 Dec 2019 00:32:16 +0800 Subject: [PATCH] Edited the description of hook/functions in the previous commit Rewrote ASM code for tile_under_cursor script function. --- artifacts/scripting/hookscripts.txt | 9 +++--- artifacts/scripting/sfall function notes.txt | 8 ++--- sfall/FalloutEngine/Fallout2.h | 2 +- sfall/Modules/Perks.cpp | 7 ++-- sfall/Modules/Scripting/Handlers/Misc.cpp | 34 +++++++------------- 5 files changed, 26 insertions(+), 34 deletions(-) diff --git a/artifacts/scripting/hookscripts.txt b/artifacts/scripting/hookscripts.txt index 05187799..29c6b4ff 100644 --- a/artifacts/scripting/hookscripts.txt +++ b/artifacts/scripting/hookscripts.txt @@ -653,10 +653,11 @@ int ret1 - pass -1 to cancel the execution of the handler (only for HOOK_STD HOOK_TARGETOBJECT (hs_targetobject.int) -Runs whenever the targeting cursor hovers over something. +Runs when the targeting cursor moves over an object, or when the player tries to attack the target object. +You can override the target object or prevent the player from attacking the chosen target. -int arg1 - event type: 0 - when hovering over the target, 1 - when clicking on the target -int arg2 - 1 if the target is a valid object, 0 otherwise +int arg1 - event type: 0 - when the cursor moves over the object, 1 - when trying to attack the target object +int arg2 - 1 when the target object is valid to attack, 0 otherwise Obj arg3 - the target object -int ret1 - overrides the target object +mixed ret1 - overrides the target object, or pass -1 to prevent the player from attacking the object diff --git a/artifacts/scripting/sfall function notes.txt b/artifacts/scripting/sfall function notes.txt index 01ca2330..6a1b8518 100644 --- a/artifacts/scripting/sfall function notes.txt +++ b/artifacts/scripting/sfall function notes.txt @@ -690,12 +690,12 @@ optional argument: > array sfall_func3("objects_in_radius", int tile, int radius, int elevation) > array sfall_func4("objects_in_radius", int tile, int radius, int elevation, int type) - returns an array of objects of a type (see OBJ_TYPE_* constants in define_extra.h) within the specified radius from the given tile -- The radius is limited to 50 hexes -- passing -1 to the type argument or not specifying it will return all types of objects +- passing -1 to the type argument or not specifying it will return all objects within the radius +- the radius is limited to 50 hexes > int sfall_func2("tile_by_position", int x, int y) -- returns the tile number at the x/y position relative to the top-left corner of the screen -- returns -1 if the position is outside of the screen +- returns the tile number at the x, y position relative to the top-left corner of the screen +- if the position is outside of the range of tiles, it will return -1 ------------------------ ------ MORE INFO ------- diff --git a/sfall/FalloutEngine/Fallout2.h b/sfall/FalloutEngine/Fallout2.h index 37e69ff0..6a6d8d1a 100644 --- a/sfall/FalloutEngine/Fallout2.h +++ b/sfall/FalloutEngine/Fallout2.h @@ -68,7 +68,7 @@ /* Returns the value to the script - eax register must contain the script_ptr + eax and ebx register must contain the script_ptr edx register must contain the returned value */ #define _RET_VAL_INT __asm { \ diff --git a/sfall/Modules/Perks.cpp b/sfall/Modules/Perks.cpp index 37dfde0b..b259520d 100644 --- a/sfall/Modules/Perks.cpp +++ b/sfall/Modules/Perks.cpp @@ -689,7 +689,7 @@ normalPerk: pop edx; test eax, eax; jnz end; - // fix gain perks + // fix gain perks (add to base stats instead of bonus stats) cmp edx, PERK_gain_strength_perk; jl end; cmp edx, PERK_gain_luck_perk; @@ -868,7 +868,7 @@ static void PerkSetup() { if (perksEnable) { char num[4]; for (int i = 0; i < PERK_count; i++) { - _itoa_s(i, num, 10); + _itoa(i, num, 10); if (iniGetString(num, "Name", "", &Name[i * maxNameLen], maxNameLen - 1, perksFile)) { perks[i].name = &Name[i * maxNameLen]; } @@ -1450,10 +1450,11 @@ void Perks::init() { FastShotTraitFix(); + // Disable gain perks for bonus stats for (int i = STAT_st; i <= STAT_lu; i++) SafeWrite8(GainStatPerks[i][0], (BYTE)GainStatPerks[i][1]); PerkEngineInit(); - HookCall(0x442729, PerkInitWrapper); // game_init_ + HookCall(0x442729, PerkInitWrapper); // game_init_ if (GetConfigString("Misc", "PerksFile", "", &perksFile[2], MAX_PATH - 3)) { perksFile[0] = '.'; diff --git a/sfall/Modules/Scripting/Handlers/Misc.cpp b/sfall/Modules/Scripting/Handlers/Misc.cpp index e6ceff47..7e2394cd 100644 --- a/sfall/Modules/Scripting/Handlers/Misc.cpp +++ b/sfall/Modules/Scripting/Handlers/Misc.cpp @@ -937,29 +937,19 @@ end: void __declspec(naked) op_tile_under_cursor() { __asm { - push edx; - push ecx; - push ebx; - mov ecx, eax; - sub esp, 8; - lea edx, [esp]; - lea eax, [esp+4]; + mov esi, ebx; + sub esp, 8; + lea edx, [esp]; + lea eax, [esp + 4]; call fo::funcoffs::mouse_get_position_; - mov ebx, dword ptr ds:[FO_VAR_map_elevation]; - mov edx, [esp]; - mov eax, [esp+4]; - call fo::funcoffs::tile_num_; - mov edx, eax; - mov eax, ecx; - call fo::funcoffs::interpretPushLong_; - mov eax, ecx; - mov edx, VAR_TYPE_INT; - call fo::funcoffs::interpretPushShort_; - add esp, 8; - pop ebx; - pop ecx; - pop edx; - retn; + pop edx; + pop eax; + call fo::funcoffs::tile_num_; // ebx - unused + mov edx, eax; // tile + mov ebx, esi; + mov eax, esi; + _J_RET_VAL_TYPE(VAR_TYPE_INT); +// retn; } }