Added internal implementation of engine functions with hooks:

* item_w_mp_cost_ with CALCAPCOST
* is_within_perception_ with WITHINPERCEPTION
This commit is contained in:
NovaRain
2020-05-01 10:27:05 +08:00
parent 3d2d1cdf2a
commit 1f696b9f12
6 changed files with 59 additions and 5 deletions
+2
View File
@@ -26,6 +26,7 @@ WRAP_WATCOM_FFUNC3(FrmFrameData*, frame_ptr, FrmHeaderData*, frm, long, frame, l
WRAP_WATCOM_FFUNC3(void, intface_update_items, long, animate, long, modeLeft,long, modeRight)
WRAP_WATCOM_FFUNC3(GameObject*, inven_find_type, GameObject*, critter, long, itemType, DWORD*, buf)
WRAP_WATCOM_FFUNC3(long, item_add_force, GameObject*, critter, GameObject*, item, long, count)
WRAP_WATCOM_FFUNC3(long, item_w_mp_cost, GameObject*, source, long, hitMode, long, isCalled)
WRAP_WATCOM_FFUNC7(void, make_straight_path_func, GameObject*, objFrom, DWORD, tileFrom, DWORD, tileTo, void*, rotationPtr, DWORD*, result, long, flags, void*, func)
WRAP_WATCOM_FFUNC3(long, message_find, DWORD*, msgFile, long, msgNumber, DWORD*, outBuf)
WRAP_WATCOM_FFUNC4(long, mouse_click_in, long, x, long, y, long, x_end, long, y_end)
@@ -85,6 +86,7 @@ WRAP_WATCOM_FUNC2(void, intface_update_move_points, long, ap, long, freeAP)
WRAP_WATCOM_FUNC0(void, intface_use_item)
WRAP_WATCOM_FUNC2(long, inven_unwield, GameObject*, critter, long, slot)
WRAP_WATCOM_FUNC0(long, is_pc_sneak_working)
WRAP_WATCOM_FUNC2(long, is_within_perception, GameObject*, source, GameObject*, target)
WRAP_WATCOM_FUNC1(long, item_c_curr_size, GameObject*, critter)
WRAP_WATCOM_FUNC1(long, item_caps_total, GameObject*, object)
WRAP_WATCOM_FUNC1(long, item_size, GameObject*, item)
+7 -5
View File
@@ -21,6 +21,8 @@
#include "..\main.h"
#include "..\FalloutEngine\Fallout2.h"
#include "HookScripts\CombatHS.h"
#include "AI.h"
namespace sfall
@@ -282,15 +284,15 @@ fix: // check result
static void __declspec(naked) cai_perform_distance_prefs_hack() {
__asm {
mov ecx, eax; // current distance to target
mov eax, esi;
xor ebx, ebx; // no called shot
mov ebx, eax; // current distance to target
mov ecx, esi;
push 0; // no called shot
mov edx, ATKTYPE_RWEAPON_PRIMARY;
call fo::funcoffs::item_w_mp_cost_;
call sf_item_w_mp_cost;
mov edx, [esi + movePoints];
sub edx, eax; // ap - cost = free AP's
jle moveAway; // <= 0
lea edx, [edx + ecx - 1];
lea edx, [edx + ebx - 1];
cmp edx, 5; // minimum threshold distance
jge skipMove; // distance >= 5?
// check combat rating
+21
View File
@@ -81,6 +81,27 @@ static void __declspec(naked) AfterHitRollHook() {
}
}
// Implementation of item_w_mp_cost_ engine function with the hook
long __fastcall sf_item_w_mp_cost(fo::GameObject* source, long hitMode, long isCalled) {
long cost = fo::func::item_w_mp_cost(source, hitMode, isCalled);
if (!HookScripts::HookHasScript(HOOK_CALCAPCOST)) return cost;
BeginHook();
args[0] = (DWORD)source;
args[1] = hitMode;
args[2] = isCalled;
args[3] = cost;
argCount = 4;
RunHookScript(HOOK_CALCAPCOST);
if (cRet > 0) cost = rets[0];
EndHook();
return cost;
}
static void __declspec(naked) CalcApCostHook() {
__asm {
HookBegin;
+3
View File
@@ -19,4 +19,7 @@ void Inject_OnExplosionHook();
void Inject_SubCombatDamageHook();
void Inject_TargetObjectHook();
// Implementation of item_w_mp_cost_ engine function with the hook
long __fastcall sf_item_w_mp_cost(fo::GameObject* source, long hitMode, long isCalled);
}
+22
View File
@@ -256,6 +256,27 @@ skip:
}
}
// Implementation of is_within_perception_ engine function with the hook
long __fastcall sf_is_within_perception(fo::GameObject* watcher, fo::GameObject* target) {
long result = fo::func::is_within_perception(watcher, target);
if (!HookScripts::HookHasScript(HOOK_WITHINPERCEPTION)) return result;
BeginHook();
args[0] = (DWORD)watcher;
args[1] = (DWORD)target;
args[2] = result;
args[3] = 0; // type
argCount = 4;
RunHookScript(HOOK_WITHINPERCEPTION);
if (cRet > 0) result = rets[0];
EndHook();
return result;
}
static long __stdcall PerceptionRangeHook_Script(int type) {
long result;
__asm {
@@ -314,6 +335,7 @@ static void __declspec(naked) PerceptionRangeHearHook() {
}
static constexpr long maxGasAmount = 80000;
static void CarTravelHook_Script() {
BeginHook();
argCount = 2;
+4
View File
@@ -16,4 +16,8 @@ namespace sfall
void Inject_RestTimerHook();
void Inject_ExplosiveTimerHook();
void Inject_EncounterHook();
// Implementation of is_within_perception_ engine function with the hook
long __fastcall sf_is_within_perception(fo::GameObject* watcher, fo::GameObject* target);
}