Attempted to fix the crash with sfall array and missing script (#281)

Replaced all pushad/popad in script opcodes with pushaop/popaop macros.
This commit is contained in:
NovaRain
2020-03-25 20:22:54 +08:00
parent f80e933889
commit 4243bead5d
5 changed files with 90 additions and 90 deletions
+10 -9
View File
@@ -28,16 +28,18 @@
- use this macros outside of other __asm {} blocks (obviously)
*/
// Macros for quick replacement of pushad/popad in script opcodes
#define pushaop __asm push ebx __asm push ecx __asm push edx __asm push esi __asm push edi __asm push ebp
#define popaop __asm pop ebp __asm pop edi __asm pop esi __asm pop edx __asm pop ecx __asm pop ebx
// rscript - 32-bit register where script pointer will be put (it is used for several related functions)
#define _OP_BEGIN(rscript) __asm \
{ \
__asm pushad \
#define _OP_BEGIN(rscript) __asm { \
pushaop \
__asm mov rscript, eax \
}
#define _OP_END __asm \
{ \
__asm popad \
#define _OP_END __asm { \
popaop \
__asm retn \
}
@@ -46,14 +48,13 @@
arguments come in reverse order (from last to first)
all arguments should be valid r32 registers
*/
#define _GET_ARG_R32(rscript, rtype, rval) __asm \
{ \
#define _GET_ARG_R32(rscript, rtype, rval) __asm { \
__asm mov eax, rscript \
__asm call interpretPopShort_ \
__asm mov rtype, eax \
__asm mov eax, rscript \
__asm call interpretPopLong_ \
__asm mov rval, eax \
__asm mov rval, eax \
}
/*
+8 -8
View File
@@ -243,14 +243,14 @@ paramWasFloat:
fail:
add esp, 0x10;
end:
popad;
popaop;
retn;
}
}
static void __declspec(naked) SetWeaponKnockback() {
__asm {
pushad;
pushaop;
push 0;
jmp SetKnockback;
}
@@ -258,7 +258,7 @@ static void __declspec(naked) SetWeaponKnockback() {
static void __declspec(naked) SetTargetKnockback() {
__asm {
pushad;
pushaop;
push 1;
jmp SetKnockback;
}
@@ -266,7 +266,7 @@ static void __declspec(naked) SetTargetKnockback() {
static void __declspec(naked) SetAttackerKnockback() {
__asm {
pushad;
pushaop;
push 2;
jmp SetKnockback;
}
@@ -287,14 +287,14 @@ static void __declspec(naked) RemoveKnockback() {
fail:
add esp, 4;
end:
popad;
popaop;
retn;
}
}
static void __declspec(naked) RemoveWeaponKnockback() {
__asm {
pushad;
pushaop;
push 0;
jmp RemoveKnockback;
}
@@ -302,7 +302,7 @@ static void __declspec(naked) RemoveWeaponKnockback() {
static void __declspec(naked) RemoveTargetKnockback() {
__asm {
pushad;
pushaop;
push 1;
jmp RemoveKnockback;
}
@@ -310,7 +310,7 @@ static void __declspec(naked) RemoveTargetKnockback() {
static void __declspec(naked) RemoveAttackerKnockback() {
__asm {
pushad;
pushaop;
push 2;
jmp RemoveKnockback;
}
+66 -66
View File
@@ -20,9 +20,9 @@
static void __declspec(naked) create_array() {
__asm {
pushad;
pushaop;
mov edi, eax;
call interpretPopShort_
call interpretPopShort_;
mov ebx, eax;
mov eax, edi;
call interpretPopLong_;
@@ -50,29 +50,29 @@ end:
mov edx, VAR_TYPE_INT;
mov eax, edi;
call interpretPushShort_;
popad;
popaop;
retn;
}
}
static void __declspec(naked) set_array() {
__asm {
pushad;
pushaop;
mov ebp, eax;
//Get args
call interpretPopShort_
call interpretPopShort_;
mov edx, eax;
mov eax, ebp;
call interpretPopLong_;
mov edi, eax; // value
mov eax, ebp;
call interpretPopShort_
call interpretPopShort_;
mov ecx, eax;
mov eax, ebp;
call interpretPopLong_;
mov esi, eax; // key
mov eax, ebp;
call interpretPopShort_
call interpretPopShort_;
mov ebx, eax;
mov eax, ebp;
call interpretPopLong_;
@@ -110,7 +110,7 @@ notstring1:
push edi; // arg 1: arrayID
call SetArray
end:
popad;
popaop;
retn;
}
}
@@ -132,16 +132,16 @@ static char* _stdcall GetArraySubstr(const char* str, size_t index) {
static void __declspec(naked) get_array() {
__asm {
pushad;
pushaop;
mov ebp, eax;
//Get args
call interpretPopShort_
call interpretPopShort_;
mov ebx, eax;
mov eax, ebp;
call interpretPopLong_;
mov edi, eax;
mov eax, ebp;
call interpretPopShort_
call interpretPopShort_;
mov ecx, eax;
mov eax, ebp;
call interpretPopLong_;
@@ -207,14 +207,14 @@ notstring:
mov edx, ebx;
mov eax, ebp;
call interpretPushShort_;
popad;
popaop;
retn;
}
}
static void __declspec(naked) free_array() {
__asm {
pushad;
pushaop;
mov edi, eax;
call interpretPopShort_;
mov ebx, eax;
@@ -225,14 +225,14 @@ static void __declspec(naked) free_array() {
push eax;
call FreeArray;
end:
popad;
popaop;
retn;
}
}
static void __declspec(naked) len_array() {
__asm {
pushad;
pushaop;
mov edi, eax;
call interpretPopShort_;
mov ebx, eax;
@@ -252,23 +252,23 @@ end:
mov edx, VAR_TYPE_INT;
mov eax, edi;
call interpretPushShort_;
popad;
popaop;
retn;
}
}
static void __declspec(naked) resize_array() {
__asm {
pushad;
pushaop;
mov ebp, eax;
//Get args
call interpretPopShort_
call interpretPopShort_;
mov ebx, eax;
mov eax, ebp;
call interpretPopLong_;
mov edi, eax;
mov eax, ebp;
call interpretPopShort_
call interpretPopShort_;
mov ecx, eax;
mov eax, ebp;
call interpretPopLong_;
@@ -283,16 +283,16 @@ static void __declspec(naked) resize_array() {
push esi;
call ResizeArray;
end:
popad;
popaop;
retn;
}
}
static void __declspec(naked) temp_array() {
__asm {
pushad;
pushaop;
mov edi, eax;
call interpretPopShort_
call interpretPopShort_;
mov ebx, eax;
mov eax, edi;
call interpretPopLong_;
@@ -320,14 +320,14 @@ end:
mov edx, VAR_TYPE_INT;
mov eax, edi;
call interpretPushShort_;
popad;
popaop;
retn;
}
}
static void __declspec(naked) fix_array() {
__asm {
pushad;
pushaop;
mov edi, eax;
call interpretPopShort_;
mov ebx, eax;
@@ -338,23 +338,23 @@ static void __declspec(naked) fix_array() {
push eax;
call FixArray;
end:
popad;
popaop;
retn;
}
}
static void __declspec(naked) scan_array() {
__asm {
pushad;
pushaop;
mov ebp, eax;
//Get args
call interpretPopShort_
call interpretPopShort_;
mov edx, eax;
mov eax, ebp;
call interpretPopLong_;
mov edi, eax; // value (needle)
mov eax, ebp;
call interpretPopShort_
call interpretPopShort_;
mov ecx, eax;
mov eax, ebp;
call interpretPopLong_;
@@ -397,49 +397,49 @@ resultnotstr:
mov edx, ebx;
mov eax, ebp;
call interpretPushShort_;
popad;
popaop;
retn;
}
}
static void __declspec(naked) op_save_array() {
_OP_BEGIN(ebp)
_OP_BEGIN(ebp);
// Get args
_GET_ARG_R32(ebp, ebx, edi)
_GET_ARG_R32(ebp, edx, ecx)
_GET_ARG_R32(ebp, ebx, edi);
_GET_ARG_R32(ebp, edx, ecx);
__asm {
// arg check:
cmp bx, VAR_TYPE_INT
jne end
cmp bx, VAR_TYPE_INT;
jne end;
}
_CHECK_PARSE_STR(1, ebp, dx, ecx)
_CHECK_PARSE_STR(1, ebp, dx, ecx);
__asm {
push edi // arg 3: arrayID
push edx // arg 2: keyType
push ecx // arg 1: key
call SaveArray
push edi; // arg 3: arrayID
push edx; // arg 2: keyType
push ecx; // arg 1: key
call SaveArray;
}
end:
_OP_END
_OP_END;
}
static void __declspec(naked) op_load_array() {
_OP_BEGIN(ebp)
_GET_ARG_R32(ebp, edx, ecx)
_CHECK_PARSE_STR(1, ebp, dx, ecx)
_OP_BEGIN(ebp);
_GET_ARG_R32(ebp, edx, ecx);
_CHECK_PARSE_STR(1, ebp, dx, ecx);
__asm {
push edx; // arg 2: keyType
push ecx; // arg 1: key
call LoadArray;
}
_RET_VAL_INT32(ebp)
_OP_END
_RET_VAL_INT32(ebp);
_OP_END;
}
static void __declspec(naked) op_get_array_key() {
_OP_BEGIN(ebp)
_GET_ARG_R32(ebp, edx, ecx) // index
_GET_ARG_R32(ebp, ebx, edi) // arrayID
_OP_BEGIN(ebp);
_GET_ARG_R32(ebp, edx, ecx); // index
_GET_ARG_R32(ebp, ebx, edi); // arrayID
__asm {
// arg check:
cmp bx, VAR_TYPE_INT;
@@ -451,39 +451,39 @@ static void __declspec(naked) op_get_array_key() {
push edi; // arg 1: arrayID
call GetArrayKey;
}
_RET_VAL_POSSIBLY_STR(1, ebp, [esp])
_RET_VAL_POSSIBLY_STR(1, ebp, [esp]);
goto end;
__asm {
wrongarg:
xor eax, eax; // return 0 on wrong arguments
}
_RET_VAL_INT32(ebp)
_RET_VAL_INT32(ebp);
end:
_OP_END
_OP_END;
}
static void __declspec(naked) op_stack_array() {
_OP_BEGIN(ebp)
_GET_ARG_R32(ebp, edx, esi) // value
_GET_ARG_R32(ebp, ebx, edi) // key
_OP_BEGIN(ebp);
_GET_ARG_R32(ebp, edx, esi); // value
_GET_ARG_R32(ebp, ebx, edi); // key
__asm {
push edx // arg 4: valueType
push ebx
push edx; // arg 4: valueType
push ebx;
}
_CHECK_PARSE_STR(1, ebp, dx, esi)
_CHECK_PARSE_STR(1, ebp, dx, esi);
__asm {
pop ebx
mov ecx, ebx
pop ebx;
mov ecx, ebx;
}
_CHECK_PARSE_STR(2, ebp, bx, edi)
_CHECK_PARSE_STR(2, ebp, bx, edi);
__asm {
push esi // arg 3: value
push ecx // arg 2: keyType
push edi // arg 1: key
call StackArray
push esi; // arg 3: value
push ecx; // arg 2: keyType
push edi; // arg 1: key
call StackArray;
}
_RET_VAL_INT32(ebp)
_OP_END
_RET_VAL_INT32(ebp);
_OP_END;
}
// object LISTS
+2 -3
View File
@@ -361,7 +361,7 @@ static char* _stdcall mysprintf(const char* format, DWORD value, DWORD valueType
static void __declspec(naked) op_sprintf() {
__asm {
pushad;
pushaop;
mov edi, eax;
call interpretPopShort_;
mov edx, eax;
@@ -369,7 +369,6 @@ static void __declspec(naked) op_sprintf() {
call interpretPopLong_; // any value
mov ebx, eax;
mov eax, edi;
call interpretPopShort_;
mov ecx, eax;
mov eax, edi;
@@ -410,7 +409,7 @@ notstring:
mov eax, edi;
call interpretPushShort_;
fail:
popad;
popaop;
retn;
}
}
+4 -4
View File
@@ -221,7 +221,7 @@ static void __declspec(naked) GetCritterExtraStat() {
static void __declspec(naked) set_critter_skill_points() {
__asm {
pushad;
pushaop;
//Get function args
mov ecx, eax;
call interpretPopShort_;
@@ -264,14 +264,14 @@ static void __declspec(naked) set_critter_skill_points() {
end:
//Restore registers and return
add esp, 12;
popad
popaop;
retn;
}
}
static void __declspec(naked) get_critter_skill_points() {
__asm {
pushad;
pushaop;
//Get function args
mov ecx, eax;
call interpretPopShort_;
@@ -313,7 +313,7 @@ end:
call interpretPushShort_;
//Restore registers and return
add esp, 8;
popad
popaop;
retn;
}
}