Rewrote get_attack_type script function in C++.

This commit is contained in:
NovaRain
2019-06-11 09:37:49 +08:00
parent 480de50f88
commit 7826a937db
7 changed files with 32 additions and 50 deletions
+4
View File
@@ -112,6 +112,10 @@ GameObject* GetActiveItem() {
return fo::var::itemButtonItems[fo::var::itemCurrentItem].item;
}
long GetCurrentAttackMode(DWORD* mode, DWORD* isAimed) {
return fo::func::intface_get_attack(mode, isAimed);
}
bool HeroIsFemale() {
return (fo::func::stat_level(fo::var::obj_dude, fo::Stat::STAT_gender) == fo::Gender::GENDER_FEMALE);
}
+2
View File
@@ -60,6 +60,8 @@ long& GetActiveItemMode();
GameObject* GetActiveItem();
long GetCurrentAttackMode(DWORD* mode, DWORD* isAimed);
bool HeroIsFemale();
long CheckAddictByPid(fo::GameObject* critter, long pid);
+1
View File
@@ -56,6 +56,7 @@ WRAP_WATCOM_FUNC1(void, gdialogDisplayMsg, const char*, message)
WRAP_WATCOM_FUNC1(long, gmouse_3d_set_mode, long, mode)
WRAP_WATCOM_FUNC1(long, gmouse_set_cursor, long, picNum)
WRAP_WATCOM_FUNC1(Window*, GNW_find, long, winRef)
WRAP_WATCOM_FUNC2(long, intface_get_attack, DWORD*, hitMode, DWORD*, isSecondary)
WRAP_WATCOM_FUNC0(long, intface_is_item_right_hand)
// redraws the main game interface windows (useful after changing some data like active hand, etc.)
WRAP_WATCOM_FUNC0(void, intface_redraw)
+8 -1
View File
@@ -216,7 +216,14 @@ struct Program {
#pragma pack(1)
struct ItemButtonItem {
GameObject* item;
long flags;
union {
long flags;
struct {
char cantUse;
char itsWeapon;
short unkFlag;
};
};
long primaryAttack;
long secondaryAttack;
long mode;
+15 -47
View File
@@ -915,47 +915,20 @@ void __declspec(naked) op_refresh_pc_art() {
}
}
static void _stdcall intface_attack_type() {
__asm {
sub esp, 8;
lea edx, [esp];
lea eax, [esp+4];
call fo::funcoffs::intface_get_attack_;
pop edx; // is_secondary
pop ecx; // hit_mode
}
}
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 fo::funcoffs::interpretPushLong_;
mov eax, ecx;
mov edx, VAR_TYPE_INT;
call fo::funcoffs::interpretPushShort_;
pop ecx;
pop edx;
retn;
void sf_get_attack_type(OpcodeContext& ctx) {
DWORD unused, hitMode = -1;
if (fo::var::interfaceWindow != hitMode) {
if (fo::GetCurrentAttackMode(&hitMode, &unused)) {
// get reload mode
long activeHand = fo::var::itemCurrentItem; // 0 - left, 1 - right
if (fo::var::itemButtonItems[activeHand].item && fo::var::itemButtonItems[activeHand].itsWeapon) {
hitMode = fo::AttackType::ATKTYPE_LWEAPON_RELOAD + activeHand;
}
}
} else {
ctx.printOpcodeError("%s() - unable to get attack mode.", ctx.getOpcodeName());
}
ctx.setReturn(hitMode);
}
void __declspec(naked) op_play_sfall_sound() {
@@ -1227,13 +1200,8 @@ end:
}
void sf_attack_is_aimed(OpcodeContext& ctx) {
int is_secondary, result;
__asm {
call intface_attack_type;
mov result, eax;
mov is_secondary, edx;
}
ctx.setReturn((result != -1) ? is_secondary : 0);
DWORD isAimed, unused;
ctx.setReturn((!fo::GetCurrentAttackMode(&unused, &isAimed)) ? isAimed : 0);
}
void sf_sneak_success(OpcodeContext& ctx) {
+1 -1
View File
@@ -113,7 +113,7 @@ void __declspec() op_get_light_level();
void __declspec() op_refresh_pc_art();
void __declspec() op_get_attack_type();
void sf_get_attack_type(OpcodeContext&);
void __declspec() op_play_sfall_sound();
+1 -1
View File
@@ -142,6 +142,7 @@ static SfallOpcodeInfo opcodeInfoArray[] = {
{0x21e, "get_mouse_buttons", sf_get_mouse_buttons, 0, true},
{0x224, "create_message_window", sf_create_message_window, 1, false, {ARG_STRING}},
{0x228, "get_attack_type", sf_get_attack_type, 0, true},
{0x22d, "create_array", sf_create_array, 2, true, {ARG_INT, ARG_INT}},
{0x22e, "set_array", sf_set_array, 3, false, {ARG_OBJECT, ARG_ANY, ARG_ANY}},
{0x22f, "get_array", sf_get_array, 2, true, {ARG_ANY, ARG_ANY}}, // can also be used on strings
@@ -388,7 +389,6 @@ void InitNewOpcodes() {
opcodes[0x225] = op_remove_trait;
opcodes[0x226] = op_get_light_level;
opcodes[0x227] = op_refresh_pc_art;
opcodes[0x228] = op_get_attack_type;
opcodes[0x229] = op_force_encounter_with_flags;
opcodes[0x22a] = op_set_map_time_multi;
opcodes[0x22b] = op_play_sfall_sound;