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.
This commit is contained in:
phobos2077
2017-03-14 00:20:34 +07:00
parent a74bab42e8
commit afadbb71c4
15 changed files with 61 additions and 217 deletions
+1 -2
View File
@@ -448,8 +448,7 @@ CritterInvSizeLimitMode=0
CritterInvSizeLimit=200 CritterInvSizeLimit=200
;Some bit flags to alter behaviour of the motion sensor ;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 require charges when using highlight feature
;2 - Motion sensor doesn't require charges
;4 - Motion sensor is required to use the item highlight feature ;4 - Motion sensor is required to use the item highlight feature
MotionScannerFlags=1 MotionScannerFlags=1
Binary file not shown.
+20 -28
View File
@@ -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" //#include "..\..\..\!SRC\headers\define.h"
#define CRITTER_IS_DEAD (1) #define CRITTER_IS_DEAD (1)
#define PID_MOTION_SENSOR (59) #define PID_MOTION_SENSOR (59)
#define NO_HIGHLIGHT(obj) (get_flags(obj) bwand FLAG_NOHIGHLIGHT) #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 highlightKey;
variable highlightContainers; variable highlightContainers;
variable colorContainers; variable colorContainers;
@@ -22,7 +32,7 @@ procedure toggle_highlight_object(variable obj, variable enable) begin
and (highlightContainers or not NO_HIGHLIGHT(obj)) then begin and (highlightContainers or not NO_HIGHLIGHT(obj)) then begin
set_outline( set_outline(
obj, 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
end end
@@ -30,7 +40,9 @@ end
procedure toggle_highlight(variable enable) begin procedure toggle_highlight(variable enable) begin
variable obj; variable obj;
foreach obj in list_as_array(LIST_GROUNDITEMS) begin 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 end
foreach obj in list_as_array(LIST_CRITTERS) begin foreach obj in list_as_array(LIST_CRITTERS) begin
if critter_state(obj) == CRITTER_IS_DEAD then begin if critter_state(obj) == CRITTER_IS_DEAD then begin
@@ -74,26 +86,6 @@ procedure key_press_handler begin
end end
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 procedure start begin
if game_loaded then begin if game_loaded then begin
translationIni := GetConfigStr("Main", "TranslationsINI", "./Translations.ini"); translationIni := GetConfigStr("Main", "TranslationsINI", "./Translations.ini");
@@ -102,7 +94,7 @@ procedure start begin
display_msg("key= " + highlightKey); display_msg("key= " + highlightKey);
highlightContainers := GetConfig("Input", "HighlightContainers", 0); highlightContainers := GetConfig("Input", "HighlightContainers", 0);
if highlightContainers == 1 then begin if highlightContainers == 1 then begin
colorContainers := OUTLINE_YELLOW; colorContainers := OUTLINE_DARK_YELLOW;
end else if highlightContainers == 2 then begin end else if highlightContainers == 2 then begin
colorContainers := OUTLINE_PURPLE; colorContainers := OUTLINE_PURPLE;
end end
+30
View File
@@ -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
+1
View File
@@ -0,0 +1 @@
To install each mod, copy *.int file into your <Fallout Dir>\data\scripts\ folder.
+1
View File
@@ -210,3 +210,4 @@
#define set_flags(obj, color) sfall_func2("set_flags", obj, color) #define set_flags(obj, color) sfall_func2("set_flags", obj, color)
#define get_flags(obj) sfall_func1("get_flags", obj) #define get_flags(obj) sfall_func1("get_flags", obj)
#define tile_refresh_display sfall_func0("tile_refresh_display") #define tile_refresh_display sfall_func0("tile_refresh_display")
#define outlined_object sfall_func0("outlined_object")
+1 -1
View File
@@ -114,7 +114,7 @@ VAR_(obj_dude, GameObject*)
VAR_(objectTable, DWORD) VAR_(objectTable, DWORD)
VAR_(objItemOutlineState, DWORD) VAR_(objItemOutlineState, DWORD)
VAR_(optionRect, DWORD) VAR_(optionRect, DWORD)
VAR_(outlined_object, DWORD) VAR_(outlined_object, GameObject*)
VAR_(partyMemberAIOptions, DWORD) VAR_(partyMemberAIOptions, DWORD)
VAR_(partyMemberCount, DWORD) VAR_(partyMemberCount, DWORD)
VAR_(partyMemberLevelUpInfoList, DWORD) VAR_(partyMemberLevelUpInfoList, DWORD)
-160
View File
@@ -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;
}
}
}
-16
View File
@@ -1,16 +0,0 @@
#pragma once
#include "Module.h"
namespace sfall
{
class HighlightingMod : public Module
{
public:
const char* name() { return "HighlightingMod"; }
void init();
};
}
@@ -129,6 +129,7 @@ static const SfallMetarule metaruleArray[] = {
{"set_flags", sf_set_flags, 2, 2, {ARG_OBJECT, ARG_INT}}, {"set_flags", sf_set_flags, 2, 2, {ARG_OBJECT, ARG_INT}},
{"get_flags", sf_get_flags, 1, 1, {ARG_OBJECT}}, {"get_flags", sf_get_flags, 1, 1, {ARG_OBJECT}},
{"tile_refresh_display", sf_tile_refresh_display, 0, 0}, {"tile_refresh_display", sf_tile_refresh_display, 0, 0},
{"outlined_object", sf_outlined_object, 0, 0},
}; };
void InitMetaruleTable() { void InitMetaruleTable() {
@@ -419,5 +419,9 @@ void sf_get_flags(OpcodeContext& ctx) {
ctx.setReturn(obj->flags); ctx.setReturn(obj->flags);
} }
void sf_outlined_object(OpcodeContext& ctx) {
ctx.setReturn(fo::var::outlined_object);
}
} }
} }
@@ -75,5 +75,7 @@ void sf_set_flags(OpcodeContext&);
void sf_get_flags(OpcodeContext&); void sf_get_flags(OpcodeContext&);
void sf_outlined_object(OpcodeContext&);
} }
} }
-2
View File
@@ -223,7 +223,6 @@
<ClInclude Include="FalloutEngine\Variables.h" /> <ClInclude Include="FalloutEngine\Variables.h" />
<ClInclude Include="FalloutEngine\Functions.h" /> <ClInclude Include="FalloutEngine\Functions.h" />
<ClInclude Include="FalloutEngine\Functions_def.h" /> <ClInclude Include="FalloutEngine\Functions_def.h" />
<ClInclude Include="Modules\HighlightingMod.h" />
<ClInclude Include="Modules\Input.h" /> <ClInclude Include="Modules\Input.h" />
<ClInclude Include="ModuleManager.h" /> <ClInclude Include="ModuleManager.h" />
<ClInclude Include="Modules\MainLoopHook.h" /> <ClInclude Include="Modules\MainLoopHook.h" />
@@ -305,7 +304,6 @@
<ClCompile Include="FalloutEngine\FunctionOffsets.cpp" /> <ClCompile Include="FalloutEngine\FunctionOffsets.cpp" />
<ClCompile Include="FalloutEngine\Variables.cpp" /> <ClCompile Include="FalloutEngine\Variables.cpp" />
<ClCompile Include="FalloutEngine\Functions.cpp" /> <ClCompile Include="FalloutEngine\Functions.cpp" />
<ClCompile Include="Modules\HighlightingMod.cpp" />
<ClCompile Include="Modules\Input.cpp" /> <ClCompile Include="Modules\Input.cpp" />
<ClCompile Include="ModuleManager.cpp" /> <ClCompile Include="ModuleManager.cpp" />
<ClCompile Include="Modules\AI.cpp" /> <ClCompile Include="Modules\AI.cpp" />
-6
View File
@@ -247,9 +247,6 @@
<ClInclude Include="Modules\MainLoopHook.h"> <ClInclude Include="Modules\MainLoopHook.h">
<Filter>Modules</Filter> <Filter>Modules</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Modules\HighlightingMod.h">
<Filter>Modules</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
@@ -461,9 +458,6 @@
<ClCompile Include="Modules\MainLoopHook.cpp"> <ClCompile Include="Modules\MainLoopHook.cpp">
<Filter>Modules</Filter> <Filter>Modules</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Modules\HighlightingMod.cpp">
<Filter>Modules</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="version.rc" /> <ResourceCompile Include="version.rc" />
-2
View File
@@ -39,7 +39,6 @@
#include "Modules\FileSystem.h" #include "Modules\FileSystem.h"
#include "Modules\Graphics.h" #include "Modules\Graphics.h"
#include "Modules\HookScripts.h" #include "Modules\HookScripts.h"
#include "Modules\HighlightingMod.h"
#include "Modules\HeroAppearance.h" #include "Modules\HeroAppearance.h"
#include "Modules\Input.h" #include "Modules\Input.h"
#include "Modules\Inventory.h" #include "Modules\Inventory.h"
@@ -168,7 +167,6 @@ static void InitModules() {
manager.add<AnimationsAtOnce>(); manager.add<AnimationsAtOnce>();
manager.add<BarBoxes>(); manager.add<BarBoxes>();
manager.add<HeroAppearance>(); manager.add<HeroAppearance>();
//manager.add<HighlightingMod>();
manager.add<MiscPatches>(); manager.add<MiscPatches>();
manager.initAll(); manager.initAll();