Replace adjust_fid engine function with C++ implementation

This commit is contained in:
phobos2077
2017-03-31 20:55:45 +07:00
parent cbe987df25
commit 34500d9dd5
5 changed files with 78 additions and 21 deletions
+1
View File
@@ -34,6 +34,7 @@ WRAP_WATCOM_FUNC2(long, db_fwriteInt, DbFile*, file, long, value)
WRAP_WATCOM_FUNC2(long, combat_turn, GameObject*, critter, long, isDudeTurn)
WRAP_WATCOM_FUNC1(long, gmouse_set_cursor, long, picNum)
WRAP_WATCOM_FUNC1(Window*, GNW_find, long, winRef)
WRAP_WATCOM_FUNC0(long, intface_is_item_right_hand)
WRAP_WATCOM_FUNC0(void, intface_toggle_item_state)
WRAP_WATCOM_FUNC0(void, intface_use_item)
WRAP_WATCOM_FUNC1(long, item_w_max_ammo, GameObject*, item)
+3 -3
View File
@@ -63,10 +63,10 @@ VAR_(holo_flag, DWORD)
VAR_(holopages, DWORD)
VAR_(hot_line_count, DWORD)
VAR_(i_fid, DWORD)
VAR_(i_lhand, DWORD)
VAR_(i_rhand, DWORD)
VAR_(i_lhand, GameObject*)
VAR_(i_rhand, GameObject*)
VAR_(i_wid, DWORD)
VAR_(i_worn, DWORD)
VAR_(i_worn, GameObject*)
VAR_(idle_func, DWORD)
VAR_(In_WorldMap, DWORD)
VAR_(info_line, DWORD)
+9 -18
View File
@@ -20,6 +20,7 @@
#include "..\main.h"
#include "..\FalloutEngine\Fallout2.h"
#include "Inventory.h"
#include "LoadGameHook.h"
#include "Message.h"
#include "PartyControl.h"
@@ -395,23 +396,12 @@ static void __declspec(naked) AdjustHeroBaseArt() {
//---------------------------------------------------------
//adjust armor art if num below hero art range
static void __declspec(naked) AdjustHeroArmorArt() {
__asm {
pop ebx //get ret addr
mov dword ptr ss:[esp], ebx //reinsert ret addr in old (push 0)
xor ebx, ebx
push 0
call fo::funcoffs::art_id_ //call load frm func
cmp isControllingNPC, 1;
jz EndFunc;
mov dx, ax
and dh, 0xFF00 //mask out current weapon flag
cmp edx, critterListSize //check if critter art in PC range
jg EndFunc
add eax, critterListSize //shift critter art index up into hero range
EndFunc:
//mov dword ptr ds:[FO_VAR_i_fid],eax
ret
static void AdjustHeroArmorArt(DWORD fid) {
if (!PartyControl::IsNpcControlled()) {
DWORD fidBase = fid & 0xFFF;
if (fidBase <= critterListSize) {
fo::var::i_fid += critterListSize;
}
}
}
@@ -1866,10 +1856,11 @@ void HeroAppearance::init() {
if (GetConfigInt("Misc", "EnableHeroAppearanceMod", 0)) {
dlog("Setting up Appearance Char Screen buttons.", DL_INIT);
EnableHeroAppearanceMod();
dlogr(" Done", DL_INIT);
LoadGameHook::OnAfterNewGame() += SetNewCharAppearanceGlobals;
LoadGameHook::OnAfterGameStarted() += LoadHeroAppearance;
Inventory::OnAdjustFid() += AdjustHeroArmorArt;
dlogr(" Done", DL_INIT);
}
}
+60
View File
@@ -29,6 +29,8 @@
namespace sfall
{
static Delegate<DWORD> onAdjustFid;
static DWORD mode;
static DWORD maxItemSize;
static DWORD reloadWeaponKey = 0;
@@ -606,6 +608,56 @@ void __declspec(naked) ItemCountFix() {
}
}
// reimplementation adjust_fid engine function
DWORD __stdcall adjust_fid_replacement2() {
using namespace fo;
DWORD fid;
if ((var::inven_dude->artFid & 0xF000000) >> 24 == OBJ_TYPE_CRITTER) {
DWORD frameNum = var::art_vault_guy_num;
DWORD weaponAnimCode = 0;
auto critterPro = GetProto(var::inven_pid);
if (critterPro != nullptr) {
frameNum = critterPro->fid & 0xFFF;
}
if (var::i_worn != nullptr) {
auto armorPro = GetProto(var::i_worn->protoId);
frameNum = func::stat_level(var::inven_dude, STAT_gender) == GENDER_FEMALE
? armorPro->item.armor.femaleFid
: armorPro->item.armor.maleFid;
if (frameNum == -1) {
frameNum = var::art_vault_guy_num;
}
}
auto itemInHand = func::intface_is_item_right_hand()
? var::i_rhand
: var::i_lhand;
if (itemInHand != nullptr) {
auto itemPro = GetProto(itemInHand->protoId);
if (itemPro->item.type == item_type_weapon) {
weaponAnimCode = itemPro->item.weapon.animationCode;
}
}
fid = func::art_id(OBJ_TYPE_CRITTER, frameNum, 0, weaponAnimCode, 0);
} else {
fid = var::inven_dude->artFid;
}
var::i_fid = fid;
onAdjustFid.invoke(fid);
return var::i_fid;
}
void __declspec(naked) adjust_fid_replacement() {
__asm {
pushad;
call adjust_fid_replacement2;
popad;
mov eax, [FO_VAR_i_fid];
retn;
}
}
void InventoryReset() {
invenapcost = GetConfigInt("Misc", "InventoryApCost", 4);
}
@@ -614,6 +666,8 @@ void Inventory::init() {
OnKeyPressed() += InventoryKeyPressedHook;
LoadGameHook::OnGameReset() += InventoryReset;
MakeJump(fo::funcoffs::adjust_fid_, adjust_fid_replacement);
mode = GetConfigInt("Misc", "CritterInvSizeLimitMode", 0);
invenapcost = GetConfigInt("Misc", "InventoryApCost", 4);
invenapqpreduction = GetConfigInt("Misc", "QuickPocketsApCostReduction", 2);
@@ -687,4 +741,10 @@ void Inventory::init() {
MakeJump(0x47808C, ItemCountFix); // replacing item_count_ function
}
Delegate<DWORD>& Inventory::OnAdjustFid() {
return onAdjustFid;
}
}
+5
View File
@@ -18,14 +18,19 @@
#pragma once
#include "Delegate.h"
#include "Module.h"
namespace sfall
{
class Inventory : public Module {
public:
const char* name() { return "Inventory"; }
void init();
// Called after game calculated dude FID for displaying on inventory screen
static Delegate<DWORD>& OnAdjustFid();
};
void _stdcall SetInvenApCost(int a);