mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Fixed some args in HOOK_BARTERPRICE hook when trading with PM
And added a new argument to indicate trading with a party member.
This commit is contained in:
@@ -248,13 +248,14 @@ Obj arg1 - the owner that the object is being removed from
|
||||
item arg2 - the item that is being removed
|
||||
int arg3 - the number of items to remove
|
||||
int arg4 - The reason the object is being removed (see RMOBJ_* constants)
|
||||
Obj arg5 - The destination object when the item is moved to another object, otherwise 0
|
||||
Obj arg5 - The destination object when the item is moved to another object, 0 otherwise
|
||||
|
||||
-------------------------------------------
|
||||
|
||||
HOOK_BARTERPRICE (hs_barterprice.int)
|
||||
|
||||
Runs whenever the value of goods being purchased is calculated
|
||||
NOTE: the hook is executed twice when entering the barter screen or after transaction: the first time is for the player and the second time is for NPC
|
||||
|
||||
critter arg1 - the critter doing the bartering (either dude_obj or inven_dude)
|
||||
critter arg2 - the critter being bartered with
|
||||
@@ -264,7 +265,8 @@ int arg5 - the amount of actual caps in the barter stack (as opposed to good
|
||||
int arg6 - the value of all goods being traded before skill modifications
|
||||
critter arg7 - table of offered goods (being sold to NPC)
|
||||
int arg8 - the total cost of the goods offered by the player
|
||||
int arg9 - set 1 if the "offers" button was pressed (not for a party member), otherwise 0
|
||||
int arg9 - 1 if the "offers" button was pressed (not for a party member), 0 otherwise
|
||||
int arg10 - 1 if trading with a party member, 0 otherwise
|
||||
|
||||
int ret1 - the modified value of all of the goods (pass -1 if you just want to modify offered goods)
|
||||
int ret2 - the modified value of all offered goods
|
||||
|
||||
@@ -71,6 +71,7 @@ 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)
|
||||
WRAP_WATCOM_FUNC1(long, item_total_cost, GameObject*, object)
|
||||
WRAP_WATCOM_FUNC1(long, item_total_weight, GameObject*, object)
|
||||
WRAP_WATCOM_FUNC1(long, item_w_anim_code, GameObject*, item)
|
||||
WRAP_WATCOM_FUNC2(long, item_w_anim_weap, GameObject*, item, DWORD, hitMode)
|
||||
WRAP_WATCOM_FUNC2(long, item_w_compute_ammo_cost, GameObject*, item, DWORD*, rounds)
|
||||
|
||||
@@ -178,7 +178,7 @@ void _stdcall RegisterHook(fo::Program* script, int id, int procNum) {
|
||||
|
||||
ScriptProgram *prog = GetGlobalScriptProgram(script);
|
||||
if (prog) {
|
||||
dlog_f("Global script %08x registered as hook id %d\n", DL_HOOK, script, id);
|
||||
dlog_f("Global script %08x registered as hook ID %d\n", DL_HOOK, script, id);
|
||||
HookScript hook;
|
||||
hook.prog = *prog;
|
||||
hook.callback = procNum;
|
||||
|
||||
@@ -11,17 +11,17 @@
|
||||
namespace sfall
|
||||
{
|
||||
|
||||
// TODO: For now the hook gets executed twice, the first time for the player and the second time for the trader.
|
||||
// it is necessary to change the implementation so that the hook only gets executed once
|
||||
// The hook is executed twice when entering the barter screen or after transaction: the first time is for the player and the second time is for NPC
|
||||
static DWORD __fastcall BarterPriceHook_Script(register fo::GameObject* source, register fo::GameObject* target, DWORD callAddr) {
|
||||
bool barterIsParty = (*(DWORD*)FO_VAR_dialog_target_is_party != 0);
|
||||
int computeCost = fo::func::barter_compute_value(source, target);
|
||||
|
||||
BeginHook();
|
||||
argCount = 9;
|
||||
argCount = 10;
|
||||
|
||||
args[0] = (DWORD)source;
|
||||
args[1] = (DWORD)target;
|
||||
args[2] = computeCost;
|
||||
args[2] = !barterIsParty ? computeCost : 0;
|
||||
|
||||
fo::GameObject* bTable = (fo::GameObject*)fo::var::btable;
|
||||
args[3] = (DWORD)bTable;
|
||||
@@ -30,24 +30,24 @@ static DWORD __fastcall BarterPriceHook_Script(register fo::GameObject* source,
|
||||
|
||||
fo::GameObject* pTable = (fo::GameObject*)fo::var::ptable;
|
||||
args[6] = (DWORD)pTable;
|
||||
int pcCost = fo::func::item_total_cost(pTable);
|
||||
args[7] = pcCost;
|
||||
int pcCost = !barterIsParty ? fo::func::item_total_cost(pTable) : fo::func::item_total_weight(pTable);
|
||||
args[7] = !barterIsParty ? pcCost : 0;
|
||||
|
||||
args[8] = (DWORD)(callAddr == 0x474D51); // check offers button
|
||||
args[8] = (DWORD)(callAddr == 0x474D51); // offers button is pressed
|
||||
args[9] = (DWORD)barterIsParty;
|
||||
|
||||
RunHookScript(HOOK_BARTERPRICE);
|
||||
|
||||
bool isPCHook = (callAddr == 0x47551F);
|
||||
bool isPCHook = (callAddr == -1);
|
||||
int cost = isPCHook ? pcCost : computeCost;
|
||||
if (cRet > 0) {
|
||||
if (!barterIsParty && cRet > 0) {
|
||||
if (isPCHook) {
|
||||
if (cRet > 1) cost = rets[1]; // new cost for pc
|
||||
} else if ((int)rets[0] > -1) {
|
||||
cost = rets[0]; // new cost for trader
|
||||
cost = rets[0]; // new cost for npc
|
||||
}
|
||||
}
|
||||
EndHook();
|
||||
|
||||
return cost;
|
||||
}
|
||||
|
||||
@@ -65,13 +65,13 @@ static void __declspec(naked) BarterPriceHook() {
|
||||
}
|
||||
}
|
||||
|
||||
static DWORD offersGoodsCost; // keep last cost
|
||||
static DWORD offersGoodsCost; // keep last cost for pc
|
||||
static void __declspec(naked) PC_BarterPriceHook() {
|
||||
__asm {
|
||||
push edx;
|
||||
push ecx;
|
||||
//-------
|
||||
push [esp + 8]; // address on call stack
|
||||
push -1; // address on call stack
|
||||
mov ecx, dword ptr ds:[FO_VAR_obj_dude]; // source
|
||||
mov edx, dword ptr ds:[FO_VAR_target_stack]; // target
|
||||
call BarterPriceHook_Script;
|
||||
@@ -82,11 +82,10 @@ static void __declspec(naked) PC_BarterPriceHook() {
|
||||
}
|
||||
}
|
||||
|
||||
static const DWORD OverrideCostRet = 0x474D44;
|
||||
static void __declspec(naked) OverrideCost_BarterPriceHack() {
|
||||
static void __declspec(naked) OverrideCost_BarterPriceHook() {
|
||||
__asm {
|
||||
mov eax, offersGoodsCost;
|
||||
jmp OverrideCostRet;
|
||||
retn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,12 +521,12 @@ end:
|
||||
|
||||
void Inject_BarterPriceHook() {
|
||||
HookCalls(BarterPriceHook, {
|
||||
0x474D4C,
|
||||
0x475735,
|
||||
0x475762
|
||||
0x474D4C, // barter_attempt_transaction_ (offers button)
|
||||
0x475735, // display_table_inventories_ (for party members)
|
||||
0x475762 // display_table_inventories_
|
||||
});
|
||||
HookCall(0X47551A, PC_BarterPriceHook);
|
||||
MakeJump(0x474D3F, OverrideCost_BarterPriceHack); // just overrides cost of offered goods
|
||||
HookCalls(PC_BarterPriceHook, {0x4754F4, 0x47551A}); // display_table_inventories_
|
||||
HookCall(0x474D3F, OverrideCost_BarterPriceHook); // barter_attempt_transaction_ (just overrides cost of offered goods)
|
||||
}
|
||||
|
||||
void Inject_UseSkillHook() {
|
||||
|
||||
@@ -184,7 +184,7 @@ static SfallOpcodeInfo opcodeInfoArray[] = {
|
||||
{0x260, "reg_anim_turn_towards", sf_reg_anim_turn_towards, 3, false, {ARG_OBJECT, ARG_INT, ARG_INT}},
|
||||
|
||||
{0x261, "metarule2_explosions", sf_explosions_metarule, 3, true, {ARG_INT, ARG_INT, ARG_INT}},
|
||||
{0x262, "register_hook_proc", sf_register_hook, 2, false, {ARG_INT, ARG_INT}},
|
||||
{0x262, "register_hook_proc", sf_register_hook, 2, false, {ARG_INT, ARG_ANY}},
|
||||
{0x263, "power", sf_power, 2, true, {ARG_NUMBER, ARG_NUMBER}},
|
||||
{0x264, "log", sf_log, 1, true, {ARG_NUMBER}},
|
||||
{0x265, "exponent", sf_exponent, 1, true, {ARG_NUMBER}},
|
||||
|
||||
Reference in New Issue
Block a user