From afadbb71c4f6e19fc2792b6100bffd1a63c031a5 Mon Sep 17 00:00:00 2001 From: phobos2077 Date: Tue, 14 Mar 2017 00:20:34 +0700 Subject: [PATCH] Refactor highlighting mod script, added check for outlined_object (via new scripting function), updated ddraw.ini to reflect the actual meaning of highighting-related settings (they way it worked for a long time); #53 HighlightMod is permanently removed from sfall code, it is now only a script. --- artifacts/ddraw.ini | 3 +- artifacts/mods/gl_highlighting.int | Bin 0 -> 3122 bytes artifacts/mods/gl_highlighting.ssl | 48 +++--- artifacts/mods/main.h | 30 ++++ artifacts/mods/readme.txt | 1 + artifacts/scripting/headers/sfall.h | 1 + sfall/FalloutEngine/Variables_def.h | 2 +- sfall/Modules/HighlightingMod.cpp | 160 ------------------ sfall/Modules/HighlightingMod.h | 16 -- sfall/Modules/Scripting/Handlers/Metarule.cpp | 1 + sfall/Modules/Scripting/Handlers/Objects.cpp | 4 + sfall/Modules/Scripting/Handlers/Objects.h | 2 + sfall/ddraw.vcxproj | 2 - sfall/ddraw.vcxproj.filters | 6 - sfall/main.cpp | 2 - 15 files changed, 61 insertions(+), 217 deletions(-) create mode 100644 artifacts/mods/gl_highlighting.int create mode 100644 artifacts/mods/main.h create mode 100644 artifacts/mods/readme.txt delete mode 100644 sfall/Modules/HighlightingMod.cpp delete mode 100644 sfall/Modules/HighlightingMod.h diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 88ecf58d..614a42cc 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -448,8 +448,7 @@ CritterInvSizeLimitMode=0 CritterInvSizeLimit=200 ;Some bit flags to alter behaviour of the motion sensor -;1 - Allow sensor use on automap when motion sensor is in pack rather than hands -;2 - Motion sensor doesn't require charges +;2 - Motion sensor require charges when using highlight feature ;4 - Motion sensor is required to use the item highlight feature MotionScannerFlags=1 diff --git a/artifacts/mods/gl_highlighting.int b/artifacts/mods/gl_highlighting.int new file mode 100644 index 0000000000000000000000000000000000000000..f1173bd6c24fffdf22943ddf2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BjIN(0wgy;d80@lUZfaW6(NDcs{h2LNmjIeah5k;hr zU@n3Ahy!9L`=tgJa3}>dl|lVZQtUTA0lSBx!4S%V#sQZXSR5A4j159C7jr>N)dnL- zoN%#$RkAb)L1~8ueQ5r&ZUnc67@+Bf^9xu7C?|vCoAVr)57Wui-~cfZlrowm!E(^_ z#kmK{GXm2L4HgKMU=eUR3u?(UST#w3!y^M09-NzCAq-Z@2qsx!DTVVGG)1sA2sP{g z$#K4ch;Y8btM4B~6$2|wAD0S5gi8sZJ}xh)Di5eCNM1y96$8#Vljr1DzM5;ATem&2vN@nRnOQU3|4UltO6AC zmXMI)=0Gt4QgTAvk7@!F#71sAunA1ilmSok3<_XzW~izZNQiK!fJI@dnPBM+>KmBq z9;h2$f!+8CtOpW$sBU0^_=1rGtb(OM2vTP=B5HA=2Fu0}kSzBth?$HsATt^DKw=D# m5``HWCae&*@~}WvhJjUPU{T2iQON)fa|X7iB(NGR@d*G~0=TgN literal 0 HcmV?d00001 diff --git a/artifacts/mods/gl_highlighting.ssl b/artifacts/mods/gl_highlighting.ssl index 5fbfe6e9..124f53ef 100644 --- a/artifacts/mods/gl_highlighting.ssl +++ b/artifacts/mods/gl_highlighting.ssl @@ -1,14 +1,24 @@ -#include "..\scripting\headers\sfall.h" -#include "..\scripting\headers\define_extra.h" +/** + + Item Highlight mod. + + Previously was part of sfall itself, now a separate mod. + Features: + - highlighting items, containers (optional) and dead bodies on the ground + - configurable hotkey is used to trigger highlight + - only objects in direct line-of-sight of player are highlighted + - motion scanner is required to enable highlight (optional) + - motion scanner charges are decreesed on each use (optional) + +**/ + +#include "main.h" //#include "..\..\..\!SRC\headers\define.h" #define CRITTER_IS_DEAD (1) #define PID_MOTION_SENSOR (59) #define NO_HIGHLIGHT(obj) (get_flags(obj) bwand FLAG_NOHIGHLIGHT) -#define TRANSLATE(id, default) (get_ini_string(translationIni + "|" id "|" default) -variable ini := "ddraw.ini"; -variable translationIni; variable highlightKey; variable highlightContainers; variable colorContainers; @@ -22,7 +32,7 @@ procedure toggle_highlight_object(variable obj, variable enable) begin and (highlightContainers or not NO_HIGHLIGHT(obj)) then begin set_outline( obj, - enable and (NO_HIGHLIGHT(obj) and colorContainers or OUTLINE_YELLOW) or 0 + enable and (NO_HIGHLIGHT(obj) and colorContainers or OUTLINE_DARK_YELLOW) or 0 ); end end @@ -30,7 +40,9 @@ end procedure toggle_highlight(variable enable) begin variable obj; foreach obj in list_as_array(LIST_GROUNDITEMS) begin - call toggle_highlight_object(obj, enable); + if obj != outlined_object then begin + call toggle_highlight_object(obj, enable); + end end foreach obj in list_as_array(LIST_CRITTERS) begin if critter_state(obj) == CRITTER_IS_DEAD then begin @@ -74,26 +86,6 @@ procedure key_press_handler begin end end -procedure GetConfig(variable section, variable key, variable def) begin - variable val := get_ini_setting(ini + "|" + section + "|" + key); - if val == -1 then val := def; - return val; -end - -procedure GetConfigStr(variable section, variable key, variable def) begin - variable val := get_ini_string(ini + "|" + section + "|" + key); - if val == -1 or val == "" then val := def; - return val; -end - -procedure translate(variable id, variable def) begin - variable str := get_ini_string(translationIni + "|Sfall|" + id); - if not str or (strlen(str) == 0) then begin - str := def; - end - return str; -end - procedure start begin if game_loaded then begin translationIni := GetConfigStr("Main", "TranslationsINI", "./Translations.ini"); @@ -102,7 +94,7 @@ procedure start begin display_msg("key= " + highlightKey); highlightContainers := GetConfig("Input", "HighlightContainers", 0); if highlightContainers == 1 then begin - colorContainers := OUTLINE_YELLOW; + colorContainers := OUTLINE_DARK_YELLOW; end else if highlightContainers == 2 then begin colorContainers := OUTLINE_PURPLE; end diff --git a/artifacts/mods/main.h b/artifacts/mods/main.h new file mode 100644 index 00000000..f62e3305 --- /dev/null +++ b/artifacts/mods/main.h @@ -0,0 +1,30 @@ + +#include "..\scripting\headers\sfall.h" +#include "..\scripting\headers\define_extra.h" + +variable ini := "ddraw.ini"; +variable translationIni; + +// Gets the integer value from ddraw.ini +procedure GetConfig(variable section, variable key, variable def) begin + variable val := get_ini_setting(ini + "|" + section + "|" + key); + if val == -1 then val := def; + return val; +end + +// Gets the string value from ddraw.ini +procedure GetConfigStr(variable section, variable key, variable def) begin + variable val := get_ini_string(ini + "|" + section + "|" + key); + if val == -1 or val == "" then val := def; + return val; +end + +// Translates given string using Translations.ini +procedure translate(variable id, variable def) begin + variable str := get_ini_string(translationIni + "|Sfall|" + id); + if not str or (strlen(str) == 0) then begin + str := def; + end + return str; +end + diff --git a/artifacts/mods/readme.txt b/artifacts/mods/readme.txt new file mode 100644 index 00000000..bcfa2240 --- /dev/null +++ b/artifacts/mods/readme.txt @@ -0,0 +1 @@ +To install each mod, copy *.int file into your \data\scripts\ folder. \ No newline at end of file diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index a16466b5..d523dd8c 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -210,3 +210,4 @@ #define set_flags(obj, color) sfall_func2("set_flags", obj, color) #define get_flags(obj) sfall_func1("get_flags", obj) #define tile_refresh_display sfall_func0("tile_refresh_display") +#define outlined_object sfall_func0("outlined_object") diff --git a/sfall/FalloutEngine/Variables_def.h b/sfall/FalloutEngine/Variables_def.h index 15565066..4009f8ea 100644 --- a/sfall/FalloutEngine/Variables_def.h +++ b/sfall/FalloutEngine/Variables_def.h @@ -114,7 +114,7 @@ VAR_(obj_dude, GameObject*) VAR_(objectTable, DWORD) VAR_(objItemOutlineState, DWORD) VAR_(optionRect, DWORD) -VAR_(outlined_object, DWORD) +VAR_(outlined_object, GameObject*) VAR_(partyMemberAIOptions, DWORD) VAR_(partyMemberCount, DWORD) VAR_(partyMemberLevelUpInfoList, DWORD) diff --git a/sfall/Modules/HighlightingMod.cpp b/sfall/Modules/HighlightingMod.cpp deleted file mode 100644 index 64aee985..00000000 --- a/sfall/Modules/HighlightingMod.cpp +++ /dev/null @@ -1,160 +0,0 @@ -#include "..\main.h" -#include "..\FalloutEngine\Fallout2.h" -#include "..\InputFuncs.h" -#include "MainLoopHook.h" - -#include "HighlightingMod.h" - -namespace sfall -{ - -static DWORD highlightingToggled = 0; -static DWORD motionSensorMode; -static BYTE toggleHighlightsKey; -static DWORD highlightContainers; -static DWORD colorContainers; -static std::string highlightFailMsg1; -static std::string HighlightFailMsg2; - -static void __declspec(naked) obj_outline_all_items_on() { - __asm { - pushad - mov eax, dword ptr ds:[FO_VAR_map_elevation] - call fo::funcoffs::obj_find_first_at_ -loopObject: - test eax, eax - jz end - cmp eax, ds:[FO_VAR_outlined_object] - je nextObject - xchg ecx, eax - mov eax, [ecx+0x20] - and eax, 0xF000000 - sar eax, 0x18 - test eax, eax // This object is an item? - jnz nextObject // No - cmp dword ptr [ecx+0x7C], eax // Owned by someone? - jnz nextObject // Yes - test dword ptr [ecx+0x74], eax // Already outlined? - jnz nextObject // Yes - mov edx, 0x10 // yellow - test byte ptr [ecx+0x25], dl // NoHighlight_ flag is set (is this a container)? - jz NoHighlight // No - cmp highlightContainers, eax // Highlight containers? - je nextObject // No - mov edx, colorContainers // NR: should be set to yellow or purple later -NoHighlight: - mov [ecx+0x74], edx -nextObject: - call fo::funcoffs::obj_find_next_at_ - jmp loopObject -end: - call fo::funcoffs::tile_refresh_display_ - popad - retn - } -} - -static void __declspec(naked) obj_outline_all_items_off() { - __asm { - pushad - mov eax, dword ptr ds:[FO_VAR_map_elevation] - call fo::funcoffs::obj_find_first_at_ -loopObject: - test eax, eax - jz end - cmp eax, ds:[FO_VAR_outlined_object] - je nextObject - xchg ecx, eax - mov eax, [ecx+0x20] - and eax, 0xF000000 - sar eax, 0x18 - test eax, eax // Is this an item? - jnz nextObject // No - cmp dword ptr [ecx+0x7C], eax // Owned by someone? - jnz nextObject // Yes - mov dword ptr [ecx+0x74], eax -nextObject: - call fo::funcoffs::obj_find_next_at_ - jmp loopObject -end: - call fo::funcoffs::tile_refresh_display_ - popad - retn - } -} - -static void __declspec(naked) obj_remove_outline_hook() { - __asm { - call fo::funcoffs::obj_remove_outline_ - test eax, eax - jnz end - cmp highlightingToggled, 1 - jne end - mov ds:[FO_VAR_outlined_object], eax - call obj_outline_all_items_on -end: - retn - } -} - -void ProcessMainLoop() { - if (toggleHighlightsKey) { - //0x48C294 to toggle - if (KeyDown(toggleHighlightsKey)) { - if (!highlightingToggled) { - if (motionSensorMode&4) { - fo::GameObject* scanner = fo::func::inven_pid_is_carried_ptr(fo::var::obj_dude, fo::PID_MOTION_SENSOR); - if (scanner != nullptr) { - if (motionSensorMode & 2) { - highlightingToggled = fo::func::item_m_dec_charges(scanner) + 1; - if (!highlightingToggled) { - fo::func::display_print(HighlightFailMsg2.c_str()); - } - } else highlightingToggled = 1; - } else { - fo::func::display_print(highlightFailMsg1.c_str()); - } - } else { - highlightingToggled = 1; - } - if (highlightingToggled) { - obj_outline_all_items_on(); - } else { - highlightingToggled = 2; - } - } - } else if (highlightingToggled) { - if (highlightingToggled == 1) { - obj_outline_all_items_off(); - } - highlightingToggled = 0; - } - } -} - -void HighlightingMod::init() { - toggleHighlightsKey = GetConfigInt("Input", "ToggleItemHighlightsKey", 0); - if (toggleHighlightsKey) { - motionSensorMode = GetConfigInt("Misc", "MotionScannerFlags", 1); - highlightContainers = GetConfigInt("Input", "HighlightContainers", 0); - switch (highlightContainers) { - case 1: - colorContainers = 0x10; // yellow - break; - case 2: - colorContainers = 0x40; // purple - break; - } - //HookCall(0x44B9BA, &gmouse_bk_process_hook); - HookCall(0x44BD1C, &obj_remove_outline_hook); - HookCall(0x44E559, &obj_remove_outline_hook); - - highlightFailMsg1 = Translate("Sfall", "HighlightFail1", "You aren't carrying a motion sensor."); - HighlightFailMsg2 = Translate("Sfall", "HighlightFail2", "Your motion sensor is out of charge."); - - MainLoopHook::OnCombatLoop() += ProcessMainLoop; - MainLoopHook::OnMainLoop() += ProcessMainLoop; - } -} - -} diff --git a/sfall/Modules/HighlightingMod.h b/sfall/Modules/HighlightingMod.h deleted file mode 100644 index 98addd93..00000000 --- a/sfall/Modules/HighlightingMod.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "Module.h" - -namespace sfall -{ - -class HighlightingMod : public Module -{ -public: - const char* name() { return "HighlightingMod"; } - - void init(); -}; - -} \ No newline at end of file diff --git a/sfall/Modules/Scripting/Handlers/Metarule.cpp b/sfall/Modules/Scripting/Handlers/Metarule.cpp index a977b474..4be7ef29 100644 --- a/sfall/Modules/Scripting/Handlers/Metarule.cpp +++ b/sfall/Modules/Scripting/Handlers/Metarule.cpp @@ -129,6 +129,7 @@ static const SfallMetarule metaruleArray[] = { {"set_flags", sf_set_flags, 2, 2, {ARG_OBJECT, ARG_INT}}, {"get_flags", sf_get_flags, 1, 1, {ARG_OBJECT}}, {"tile_refresh_display", sf_tile_refresh_display, 0, 0}, + {"outlined_object", sf_outlined_object, 0, 0}, }; void InitMetaruleTable() { diff --git a/sfall/Modules/Scripting/Handlers/Objects.cpp b/sfall/Modules/Scripting/Handlers/Objects.cpp index 6b6f2368..6b3caed5 100644 --- a/sfall/Modules/Scripting/Handlers/Objects.cpp +++ b/sfall/Modules/Scripting/Handlers/Objects.cpp @@ -419,5 +419,9 @@ void sf_get_flags(OpcodeContext& ctx) { ctx.setReturn(obj->flags); } +void sf_outlined_object(OpcodeContext& ctx) { + ctx.setReturn(fo::var::outlined_object); +} + } } diff --git a/sfall/Modules/Scripting/Handlers/Objects.h b/sfall/Modules/Scripting/Handlers/Objects.h index 51b28cf8..ec1b7d9c 100644 --- a/sfall/Modules/Scripting/Handlers/Objects.h +++ b/sfall/Modules/Scripting/Handlers/Objects.h @@ -75,5 +75,7 @@ void sf_set_flags(OpcodeContext&); void sf_get_flags(OpcodeContext&); +void sf_outlined_object(OpcodeContext&); + } } diff --git a/sfall/ddraw.vcxproj b/sfall/ddraw.vcxproj index 6b0569b6..440e342f 100644 --- a/sfall/ddraw.vcxproj +++ b/sfall/ddraw.vcxproj @@ -223,7 +223,6 @@ - @@ -305,7 +304,6 @@ - diff --git a/sfall/ddraw.vcxproj.filters b/sfall/ddraw.vcxproj.filters index c24ebffa..a2c88c7c 100644 --- a/sfall/ddraw.vcxproj.filters +++ b/sfall/ddraw.vcxproj.filters @@ -247,9 +247,6 @@ Modules - - Modules - @@ -461,9 +458,6 @@ Modules - - Modules - diff --git a/sfall/main.cpp b/sfall/main.cpp index 8f5ae40f..94427519 100644 --- a/sfall/main.cpp +++ b/sfall/main.cpp @@ -39,7 +39,6 @@ #include "Modules\FileSystem.h" #include "Modules\Graphics.h" #include "Modules\HookScripts.h" -#include "Modules\HighlightingMod.h" #include "Modules\HeroAppearance.h" #include "Modules\Input.h" #include "Modules\Inventory.h" @@ -168,7 +167,6 @@ static void InitModules() { manager.add(); manager.add(); manager.add(); - //manager.add(); manager.add(); manager.initAll();