Replaced HRP addresses with the define values

Refactored get_attack_type opcode.
This commit is contained in:
NovaRain
2021-08-23 15:10:27 +08:00
parent c0737d9bea
commit c7e29b5d01
5 changed files with 52 additions and 43 deletions
+20
View File
@@ -625,6 +625,26 @@ TGameObj* GetActiveItem() {
return ptr_itemButtonItems[*ptr_itemCurrentItem].item;
}
long GetCurrentAttackMode() {
long hitMode = -1;
if (*ptr_interfaceWindow != -1) {
long activeHand = *ptr_itemCurrentItem; // 0 - left, 1 - right
switch (ptr_itemButtonItems[activeHand].mode) {
case 1:
case 2: // called shot
hitMode = ptr_itemButtonItems[activeHand].primaryAttack;
break;
case 3:
case 4: // called shot
hitMode = ptr_itemButtonItems[activeHand].secondaryAttack;
break;
case 5: // reload mode
hitMode = ATKTYPE_LWEAPON_RELOAD + activeHand;
}
}
return hitMode;
}
AttackSubType GetWeaponType(DWORD weaponFlag) {
static const AttackSubType weapon_types[9] = {
ATKSUBTYPE_NONE,
+12
View File
@@ -346,6 +346,16 @@
#define FO_VAR_WhiteColor 0x6AB8CF
#define FO_VAR_YellowColor 0x6AB8BB // Light
// HRP offsets
#define HRP_VAR_disp_width 0x1006EB70
#define HRP_VAR_display_string_buf 0x10068708
#define HRP_VAR_FOG_OF_WAR 0x100683D4
#define HRP_VAR_MOVIE_SIZE 0x1006EC10
#define HRP_VAR_IFACE_BAR_MODE 0x1006EB0C
#define HRP_VAR_HR_IFACE_FRM_STR 0x10039358
#define HRP_VAR_VERSION_STR 0x10039940
// Global variable pointers
// TODO: move to separate namespace
@@ -555,6 +565,8 @@ long& GetActiveItemMode();
TGameObj* GetActiveItem();
long GetCurrentAttackMode();
AttackSubType GetWeaponType(DWORD weaponFlag);
bool HeroIsFemale();
+6 -37
View File
@@ -220,45 +220,14 @@ end:
}
}
static void __stdcall intface_attack_type() {
__asm {
sub esp, 8;
lea edx, [esp];
lea eax, [esp + 4];
call intface_get_attack_;
pop edx; // is_secondary
pop ecx; // hit_mode
}
}
static void __declspec(naked) op_get_attack_type() {
__asm {
push edx;
push ecx;
push eax;
call intface_attack_type;
mov edx, ecx; // hit_mode
test eax, eax;
jz skip;
// get reload
cmp ds:[FO_VAR_interfaceWindow], eax;
jz end;
mov ecx, ds:[FO_VAR_itemCurrentItem]; // 0 - left, 1 - right
imul edx, ecx, 0x18;
cmp ds:[FO_VAR_itemButtonItems + 5 + edx], 1; // .itsWeapon
jnz end;
lea eax, [ecx + 6];
end:
mov edx, eax; // result
skip:
pop ecx;
mov eax, ecx;
call interpretPushLong_;
mov eax, ecx;
mov edx, VAR_TYPE_INT;
call interpretPushShort_;
pop ecx;
pop edx;
mov esi, ecx;
call GetCurrentAttackMode;
mov edx, eax;
mov eax, ebx;
_RET_VAL_INT;
mov ecx, esi;
retn;
}
}
+4 -4
View File
@@ -85,7 +85,7 @@ bool hrpVersionValid = false; // HRP 4.1.8 version validation
static DWORD hrpDLLBaseAddr = 0x10000000;
DWORD HRPAddress(DWORD addr) {
return (hrpDLLBaseAddr + (addr & 0xFFFFF));
return (hrpDLLBaseAddr | (addr & 0xFFFFF));
}
char falloutConfigName[65] = {0};
@@ -241,9 +241,9 @@ static void InitModules() {
static void __stdcall OnExit() {
Graphics_Exit();
EngineTweaks_Exit();
//EngineTweaks_Exit();
Books_Exit();
Movies_Exit();
//Movies_Exit();
Interface_Exit();
SpeedPatch_Exit();
Skills_Exit();
@@ -253,7 +253,7 @@ static void __stdcall OnExit() {
Console_Exit();
ExtraSaveSlots_Exit();
Message_Exit();
Animations_Exit();
//Animations_Exit();
BarBoxes_Exit();
HeroAppearance_Exit();
MiscPatches_Exit();
+10 -2
View File
@@ -78,9 +78,17 @@ struct ddrawDll {
#define pushadc __asm push eax __asm push edx __asm push ecx
#define popadc __asm pop ecx __asm pop edx __asm pop eax
DWORD HRPAddress(DWORD addr);
extern bool hrpIsEnabled;
extern bool hrpVersionValid;
extern char falloutConfigName[65];
DWORD HRPAddress(DWORD addr);
__inline long GetIntHRPValue(DWORD addr) {
return *reinterpret_cast<DWORD*>(HRPAddress(addr));
}
__inline char GetByteHRPValue(DWORD addr) {
return *reinterpret_cast<BYTE*>(HRPAddress(addr));
}