Changed the behavior of ObjCanSeeObj_ShootThru_Fix

* now the critter can only see through objects in front of it.
This commit is contained in:
NovaRain
2020-08-08 11:52:17 +08:00
parent 112c931ea3
commit 2305128adc
5 changed files with 32 additions and 12 deletions
+1 -1
View File
@@ -562,7 +562,7 @@ InventoryApCost=4
QuickPocketsApCostReduction=2
;Set to 1 to fix obj_can_see_obj script function to allow critters to see through other critters and objects with 'ShootThru' flag set
;Note that enabling this option can cause unexpected NPC behavior in some situations, e.g. able to attack or enter into a dialogue with the player behind some objects
;Note that enabling this option can cause unexpected NPC behavior in some cases, e.g. initiating combat or dialogue when the player is hiding behind some obstacles
ObjCanSeeObj_ShootThru_Fix=0
;Set to 1 to fix the broken obj_can_hear_obj script function
+2 -2
View File
@@ -246,8 +246,8 @@
// returns the corrected tile distance between two objects to the distance variable (return value >= 9996 is an error when getting the distance)
#define distance_objs(distance, obj1, obj2) distance := tile_distance_objs(obj1, obj2) - 1; \
if (get_flags(obj1) bwand FLAG_MULTIHEX) distance--; \
if (get_flags(obj2) bwand FLAG_MULTIHEX) distance--
if (get_flags(obj1) bwand FLAG_MULTIHEX) then distance--; \
if (get_flags(obj2) bwand FLAG_MULTIHEX) then distance--
/* sfall metalure3 function macros */
+2
View File
@@ -298,6 +298,7 @@ const DWORD block_for_tocks_ = 0x4C93B8;
const DWORD buf_to_buf_ = 0x4D36D4;
const DWORD cai_attempt_w_reload_ = 0x42AECC;
const DWORD caiHasWeapPrefType_ = 0x42938C;
const DWORD can_see_ = 0x412BEC;
const DWORD check_death_ = 0x410814;
const DWORD check_for_death_ = 0x424EE8;
const DWORD Check4Keys_ = 0x43F73C;
@@ -541,6 +542,7 @@ const DWORD main_init_system_ = 0x480CC0;
const DWORD main_menu_hide_ = 0x481A00;
const DWORD main_menu_loop_ = 0x481AEC;
const DWORD make_path_func_ = 0x415EFC;
const DWORD make_straight_path_ = 0x4163AC;
const DWORD make_straight_path_func_ = 0x4163C8;
const DWORD map_disable_bk_processes_ = 0x482104;
const DWORD map_enable_bk_processes_ = 0x4820C0;
+2
View File
@@ -575,6 +575,7 @@ extern const DWORD block_for_tocks_;
extern const DWORD buf_to_buf_;
extern const DWORD cai_attempt_w_reload_;
extern const DWORD caiHasWeapPrefType_;
extern const DWORD can_see_;
extern const DWORD check_death_;
extern const DWORD check_for_death_;
extern const DWORD Check4Keys_;
@@ -824,6 +825,7 @@ extern const DWORD main_menu_loop_;
// - path is saved in ecx as a sequence of tile directions (0..5) to move on each step,
// - returns path length
extern const DWORD make_path_func_;
extern const DWORD make_straight_path_;
extern const DWORD make_straight_path_func_; // (TGameObj *aObj<eax>, int aTileFrom<edx>, int a3<ecx>, signed int aTileTo<ebx>, TGameObj **aObjResult, int a5, int (*a6)(void))
extern const DWORD map_disable_bk_processes_;
extern const DWORD map_enable_bk_processes_;
+21 -5
View File
@@ -128,16 +128,27 @@ static void __declspec(naked) op_obj_can_see_obj_hook() {
using namespace Fields;
__asm {
mov edi, [esp + 4]; // buf **ret_objStruct
test ebp, ebp;
jz onlyOnce;
xor ebp, ebp;
push edx;
mov edx, [edi - 8]; // target
push eax; // source
call can_see_;
test eax, eax;
pop eax;
pop edx;
jz normal;
onlyOnce:
push obj_shoot_blocking_at_; // check hex objects func pointer
push 0x20; // flags, 0x20 = check ShootThru
push edi;
call make_straight_path_func_;
// fix: see through critters
mov edx, [esp + 4];
mov ebx, [edx];
// see through critter
mov ebx, [edi];
test ebx, ebx;
jz skip;
cmp ebx, [edx - 8]; // target
cmp ebx, [edi - 8]; // target
jne noTarget;
skip:
retn 8;
@@ -148,9 +159,14 @@ noTarget:
je isCritter;
retn 8;
isCritter:
mov [edx - 4], ebx; // replace source
mov [edi - 4], ebx; // replace source
mov dword ptr [esp], 0x456BAB; // continue
retn 8;
normal: // vanilla behavior
push 0x10;
push edi;
call make_straight_path_;
retn 8;
}
}