Rewrote some script functions in PerksOps.hpp

* funcs: get_perk_available, set_perk_name/desc, set_selectable_perk,
set_fake_perk/trait.

Minor code refactoring in ObjectsOps.hpp.
This commit is contained in:
NovaRain
2020-03-25 12:26:26 +08:00
parent 7cbde234c6
commit f80e933889
6 changed files with 111 additions and 318 deletions
+16
View File
@@ -1334,6 +1334,10 @@ long __stdcall StatLevel(TGameObj* critter, long statId) {
WRAP_WATCOM_CALL2(stat_level_, critter, statId)
}
long __stdcall PerkCanAdd(TGameObj* critter, long perkId) {
WRAP_WATCOM_CALL2(perk_can_add_, critter, perkId)
}
long __stdcall PerkLevel(TGameObj* critter, long perkId) {
WRAP_WATCOM_CALL2(perk_level_, critter, perkId)
}
@@ -1374,6 +1378,14 @@ TGameObj* __stdcall ObjFindNextAtTile() {
WRAP_WATCOM_CALL0(obj_find_next_at_tile_)
}
long __stdcall ObjLockIsJammed(TGameObj* object) {
WRAP_WATCOM_CALL1(obj_lock_is_jammed_, object)
}
void __stdcall ObjUnjamLock(TGameObj* object) {
WRAP_WATCOM_CALL1(obj_unjam_lock_, object)
}
long __stdcall NewObjId() {
WRAP_WATCOM_CALL0(new_obj_id_)
}
@@ -1406,6 +1418,10 @@ long __fastcall ObjNewSidInst(TGameObj* object, long sType, long scriptIndex) {
WRAP_WATCOM_FCALL3(obj_new_sid_inst_, object, sType, scriptIndex)
}
long __fastcall ObjectUnderMouse(long crSwitch, long inclDude, long elevation) {
WRAP_WATCOM_FCALL3(object_under_mouse_, crSwitch, inclDude, elevation)
}
long __stdcall MessageLoad(MSGList *msgList, const char *msgFilePath) {
WRAP_WATCOM_CALL2(message_load_, msgList, msgFilePath)
}
+8
View File
@@ -1238,6 +1238,8 @@ void __fastcall DisplayTargetInventory(long inventoryOffset, long visibleOffset,
long __stdcall StatLevel(TGameObj* critter, long statId);
long __stdcall PerkCanAdd(TGameObj* critter, long perkId);
long __stdcall PerkLevel(TGameObj* critter, long perkId);
long __stdcall TraitLevel(long traitID);
@@ -1256,6 +1258,10 @@ TGameObj* __stdcall ObjFindNext();
TGameObj* __stdcall ObjFindNextAtTile();
// checks/unjams jammed locks
long __stdcall ObjLockIsJammed(TGameObj* object);
void __stdcall ObjUnjamLock(TGameObj* object);
long __stdcall NewObjId();
FrmFrameData* __fastcall FramePtr(FrmHeaderData* frm, long frame, long direction);
@@ -1272,6 +1278,8 @@ TGameObj* __fastcall ObjBlockingAt(TGameObj* object, long tile, long elevation);
long __fastcall ObjNewSidInst(TGameObj* object, long sType, long scriptIndex);
long __fastcall ObjectUnderMouse(long crSwitch, long inclDude, long elevation);
// loads MSG file into given MessageList
long __stdcall MessageLoad(MSGList *msgList, const char *msgFilePath);
+6 -2
View File
@@ -125,7 +125,7 @@ static void __declspec(naked) funcGetShaderTexture() {
mov edi, eax;
mov eax, ecx;
call interpretPopShort_;
push eax
push eax;
mov eax, ecx;
call interpretPopLong_;
mov ebx, [esp];
@@ -160,6 +160,7 @@ end:
retn;
}
}
static void __declspec(naked) funcSetShaderInt() {
__asm {
push ebx;
@@ -216,6 +217,7 @@ end:
retn;
}
}
static void __declspec(naked) funcSetShaderTexture() {
__asm {
push ebx;
@@ -272,6 +274,7 @@ end:
retn;
}
}
static void __declspec(naked) funcSetShaderFloat() {
__asm {
push ebx;
@@ -333,6 +336,7 @@ end:
retn;
}
}
static void __declspec(naked) funcSetShaderVector() {
__asm {
push ebx;
@@ -426,7 +430,7 @@ static void __declspec(naked) funcSetShaderMode() {
jnz fail;
push eax;
call SetShaderMode;
jmp end
jmp end;
fail:
pop eax;
end:
+1 -1
View File
@@ -563,7 +563,7 @@ next:
error:
xor edx, edx;
dec edx;
mov ebx, VAR_TYPE_INT
mov ebx, VAR_TYPE_INT;
result:
mov eax, edi;
call interpretPushLong_;
+5 -24
View File
@@ -513,25 +513,16 @@ static void sf_real_dude_obj() {
static void sf_lock_is_jammed() {
TGameObj* obj = opHandler.arg(0).asObject();
int result = 0;
if (obj) {
__asm {
mov eax, obj;
call obj_lock_is_jammed_;
mov result, eax;
}
opHandler.setReturn(ObjLockIsJammed(obj));
} else {
OpcodeInvalidArgs("lock_is_jammed");
opHandler.setReturn(0);
}
opHandler.setReturn(result);
}
static void sf_unjam_lock() {
TGameObj* obj = opHandler.arg(0).object();
__asm {
mov eax, obj;
call obj_unjam_lock_;
}
ObjUnjamLock(opHandler.arg(0).object());
}
static void sf_set_unjam_locks_time() {
@@ -562,22 +553,12 @@ static void sf_obj_under_cursor() {
const ScriptValue &crSwitchArg = opHandler.arg(0),
&inclDudeArg = opHandler.arg(1);
long obj = 0;
if (crSwitchArg.isInt() && inclDudeArg.isInt()) {
int crSwitch = crSwitchArg.asBool() ? 1 : -1,
inclDude = inclDudeArg.rawValue();
__asm {
mov ebx, dword ptr ds:[_map_elevation];
mov edx, inclDude;
mov eax, crSwitch;
call object_under_mouse_;
mov obj, eax;
}
opHandler.setReturn(ObjectUnderMouse(crSwitchArg.asBool() ? 1 : -1, inclDudeArg.rawValue(), *ptr_map_elevation));
} else {
OpcodeInvalidArgs("obj_under_cursor");
opHandler.setReturn(0);
}
opHandler.setReturn(obj);
}
static void sf_get_loot_object() {
+75 -291
View File
@@ -54,106 +54,53 @@ end:
}
}
static void _stdcall GetPerkAvailable2() {
const ScriptValue &perkIdArg = opHandler.arg(0);
int result = 0;
if (perkIdArg.isInt()) {
int perkId = perkIdArg.rawValue();
if (perkId >= 0 && perkId < PERK_count) {
result = PerkCanAdd(*ptr_obj_dude, perkId);
}
} else {
OpcodeInvalidArgs("get_perk_available");
}
opHandler.setReturn(result);
}
static void __declspec(naked) GetPerkAvailable() {
__asm {
pushad;
mov ecx, eax;
call interpretPopShort_;
mov edx, eax;
mov eax, ecx;
call interpretPopLong_;
cmp dx, VAR_TYPE_INT;
jnz fail;
cmp eax, PERK_count;
jge fail;
mov edx, eax;
mov eax, ds:[_obj_dude];
call perk_can_add_;
mov edx, eax;
jmp end;
fail:
xor edx, edx;
end:
mov eax, ecx
call interpretPushLong_;
mov edx, VAR_TYPE_INT;
mov eax, ecx;
call interpretPushShort_;
popad;
retn;
_WRAP_OPCODE(GetPerkAvailable2, 1, 1)
}
static void _stdcall funcSetPerkName2() {
const ScriptValue &perkIdArg = opHandler.arg(0),
&stringArg = opHandler.arg(1);
if (perkIdArg.isInt() && stringArg.isString()) {
SetPerkName(perkIdArg.rawValue(), stringArg.strValue());
} else {
OpcodeInvalidArgs("set_perk_name");
}
}
static void __declspec(naked) funcSetPerkName() {
__asm {
pushad;
mov ecx, eax;
call interpretPopShort_;
mov esi, eax;
mov eax, ecx;
call interpretPopLong_;
mov edi, eax;
mov eax, ecx;
call interpretPopShort_;
mov edx, eax;
mov eax, ecx;
call interpretPopLong_;
cmp dx, VAR_TYPE_INT;
jnz end;
cmp si, VAR_TYPE_STR2;
jz next;
cmp si, VAR_TYPE_STR;
jnz end;
next:
mov ebx, edi;
mov edx, esi;
mov esi, eax;
mov eax, ecx;
call interpretGetString_;
push eax;
push esi;
call SetPerkName;
jmp end;
end:
popad;
retn;
_WRAP_OPCODE(funcSetPerkName2, 2, 0)
}
static void _stdcall funcSetPerkDesc2() {
const ScriptValue &perkIdArg = opHandler.arg(0),
&stringArg = opHandler.arg(1);
if (perkIdArg.isInt() && stringArg.isString()) {
SetPerkDesc(perkIdArg.rawValue(), stringArg.strValue());
} else {
OpcodeInvalidArgs("set_perk_desc");
}
}
static void __declspec(naked) funcSetPerkDesc() {
__asm {
pushad;
mov ecx, eax;
call interpretPopShort_;
mov esi, eax;
mov eax, ecx;
call interpretPopLong_;
mov edi, eax;
mov eax, ecx;
call interpretPopShort_;
mov edx, eax;
mov eax, ecx;
call interpretPopLong_;
cmp dx, VAR_TYPE_INT;
jnz end;
cmp si, VAR_TYPE_STR2;
jz next;
cmp si, VAR_TYPE_STR;
jnz end;
next:
mov ebx, edi;
mov edx, esi;
mov esi, eax;
mov eax, ecx;
call interpretGetString_;
push eax;
push esi;
call SetPerkDesc;
jmp end;
end:
popad;
retn;
}
_WRAP_OPCODE(funcSetPerkDesc2, 2, 0)
}
static void __declspec(naked) funcSetPerkValue() {
@@ -178,219 +125,55 @@ end:
}
}
static void _stdcall fSetSelectablePerk2() {
const ScriptValue &nameArg = opHandler.arg(0),
&activeArg = opHandler.arg(1),
&imageArg = opHandler.arg(2),
&descArg = opHandler.arg(3);
if (nameArg.isString() && activeArg.isInt() && imageArg.isInt() && descArg.isString()) {
SetSelectablePerk(nameArg.strValue(), activeArg.rawValue(), imageArg.rawValue(), descArg.strValue());
} else {
OpcodeInvalidArgs("set_selectable_perk");
}
}
static void __declspec(naked) fSetSelectablePerk() {
__asm {
pushad;
mov ecx, eax;
call interpretPopShort_;
push eax;
mov eax, ecx;
call interpretPopLong_;
push eax;
mov eax, ecx;
call interpretPopShort_;
push eax;
mov eax, ecx;
call interpretPopLong_;
push eax;
mov eax, ecx;
call interpretPopShort_;
push eax;
mov eax, ecx;
call interpretPopLong_;
push eax;
mov eax, ecx;
call interpretPopShort_;
push eax;
mov eax, ecx;
call interpretPopLong_;
push eax;
_WRAP_OPCODE(fSetSelectablePerk2, 4, 0)
}
movzx eax, word ptr [esp + 12];
cmp eax, VAR_TYPE_INT;
jne fail;
movzx eax, word ptr [esp + 20];
cmp eax, VAR_TYPE_INT;
jne fail;
movzx eax, word ptr ds:[esp + 4];
cmp eax, VAR_TYPE_STR2;
je next1;
cmp eax, VAR_TYPE_STR;
jne fail;
next1:
movzx eax, word ptr ds:[esp + 28];
cmp eax, VAR_TYPE_STR2;
je next2;
cmp eax, VAR_TYPE_STR;
jne fail;
next2:
mov eax, ecx;
mov edx, [esp + 28];
mov ebx, [esp + 24];
call interpretGetString_;
push eax;
mov eax, [esp + 20];
push eax;
mov eax, [esp + 16];
push eax;
mov eax, ecx;
mov edx, [esp + 16];
mov ebx, [esp + 12];
call interpretGetString_;
push eax;
static void _stdcall fSetFakePerk2() {
const ScriptValue &nameArg = opHandler.arg(0),
&levelArg = opHandler.arg(1),
&imageArg = opHandler.arg(2),
&descArg = opHandler.arg(3);
call SetSelectablePerk;
fail:
add esp, 32;
popad;
retn;
if (nameArg.isString() && levelArg.isInt() && imageArg.isInt() && descArg.isString()) {
SetFakePerk(nameArg.strValue(), levelArg.rawValue(), imageArg.rawValue(), descArg.strValue());
} else {
OpcodeInvalidArgs("set_fake_perk");
}
}
static void __declspec(naked) fSetFakePerk() {
__asm {
pushad;
mov ecx, eax;
call interpretPopShort_;
push eax;
mov eax, ecx;
call interpretPopLong_;
push eax;
mov eax, ecx;
call interpretPopShort_;
push eax;
mov eax, ecx;
call interpretPopLong_;
push eax;
mov eax, ecx;
call interpretPopShort_;
push eax;
mov eax, ecx;
call interpretPopLong_;
push eax;
mov eax, ecx;
call interpretPopShort_;
push eax;
mov eax, ecx;
call interpretPopLong_;
push eax;
_WRAP_OPCODE(fSetFakePerk2, 4, 0)
}
movzx eax, word ptr [esp + 12];
cmp eax, VAR_TYPE_INT;
jne fail;
movzx eax, word ptr [esp + 20];
cmp eax, VAR_TYPE_INT;
jne fail;
movzx eax, word ptr ds:[esp + 4];
cmp eax, VAR_TYPE_STR2;
je next1;
cmp eax, VAR_TYPE_STR;
jne fail;
next1:
movzx eax, word ptr ds:[esp + 28];
cmp eax, VAR_TYPE_STR2;
je next2;
cmp eax, VAR_TYPE_STR;
jne fail;
next2:
mov eax, ecx;
mov edx, [esp + 28];
mov ebx, [esp + 24];
call interpretGetString_;
push eax;
mov eax, [esp + 20];
push eax;
mov eax, [esp + 16];
push eax;
mov eax, ecx;
mov edx, [esp + 16];
mov ebx, [esp + 12];
call interpretGetString_;
push eax;
static void _stdcall fSetFakeTrait2() {
const ScriptValue &nameArg = opHandler.arg(0),
&activeArg = opHandler.arg(1),
&imageArg = opHandler.arg(2),
&descArg = opHandler.arg(3);
call SetFakePerk;
fail:
add esp, 32;
popad;
retn;
if (nameArg.isString() && activeArg.isInt() && imageArg.isInt() && descArg.isString()) {
SetFakeTrait(nameArg.strValue(), activeArg.rawValue(), imageArg.rawValue(), descArg.strValue());
} else {
OpcodeInvalidArgs("set_fake_trait");
}
}
static void __declspec(naked) fSetFakeTrait() {
__asm {
push ebx;
push ecx;
push edx;
push edi;
push esi;
mov ecx, eax;
call interpretPopShort_;
push eax;
mov eax, ecx;
call interpretPopLong_;
push eax;
mov eax, ecx;
call interpretPopShort_;
push eax;
mov eax, ecx;
call interpretPopLong_;
push eax;
mov eax, ecx;
call interpretPopShort_;
push eax;
mov eax, ecx;
call interpretPopLong_;
push eax;
mov eax, ecx;
call interpretPopShort_;
push eax;
mov eax, ecx;
call interpretPopLong_;
push eax;
movzx eax, word ptr [esp + 12];
cmp eax, VAR_TYPE_INT;
jne fail;
movzx eax, word ptr [esp + 20];
cmp eax, VAR_TYPE_INT;
jne fail;
movzx eax, word ptr ds:[esp + 4];
cmp eax, VAR_TYPE_STR2;
je next1;
cmp eax, VAR_TYPE_STR;
jne fail;
next1:
movzx eax, word ptr ds:[esp + 28];
cmp eax, VAR_TYPE_STR2;
je next2;
cmp eax, VAR_TYPE_STR;
jne fail;
next2:
mov eax, ecx;
mov edx, [esp + 28];
mov ebx, [esp + 24];
call interpretGetString_;
push eax;
mov eax, [esp + 20];
push eax;
mov eax, [esp + 16];
push eax;
mov eax, ecx;
mov edx, [esp + 16];
mov ebx, [esp + 12];
call interpretGetString_;
push eax;
call SetFakeTrait;
fail:
add esp, 32;
pop esi;
pop edi;
pop edx;
pop ecx;
pop ebx;
retn;
}
_WRAP_OPCODE(fSetFakeTrait2, 4, 0)
}
static void __declspec(naked) fSetPerkboxTitle() {
@@ -477,6 +260,7 @@ end:
retn;
}
}
static void __declspec(naked) fHasFakeTrait() {
__asm {
push ebx;