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 00000000..f1173bd6 Binary files /dev/null and b/artifacts/mods/gl_highlighting.int differ 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();