mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Tweaked how disabled unsafe opcodes work
* now disabled opcodes will just do nothing instead of causing the script terminated.
This commit is contained in:
@@ -697,7 +697,7 @@ void Inventory::init() {
|
||||
ApplyInvenApCostPatch();
|
||||
}
|
||||
|
||||
// Set default ammo pid for empty weapons to make them stack regardless of previously loaded ammo
|
||||
// Set default ammo pid for unloaded weapons to make them stack regardless of previously loaded ammo
|
||||
//if (IniReader::GetConfigInt("Misc", "StackEmptyWeapons", 1)) {
|
||||
MakeCall(0x4736C6, inven_action_cursor_hack);
|
||||
HookCall(0x4772AA, item_add_mult_hook);
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace script
|
||||
#define START_VALID_ADDR 0x410000
|
||||
#define END_VALID_ADDR 0x6B403F
|
||||
|
||||
bool unsafeEnabled = false;
|
||||
bool checkValidMemAddr = true;
|
||||
|
||||
void __declspec(naked) op_read_byte() {
|
||||
@@ -108,6 +109,8 @@ void __declspec(naked) op_write_byte() {
|
||||
_GET_ARG_INT(end);
|
||||
cmp cx, VAR_TYPE_INT;
|
||||
jnz end;
|
||||
cmp unsafeEnabled, 0;
|
||||
jz end;
|
||||
// check valid addr
|
||||
cmp checkValidMemAddr, 0;
|
||||
jz noCheck;
|
||||
@@ -134,6 +137,8 @@ void __declspec(naked) op_write_short() {
|
||||
_GET_ARG_INT(end);
|
||||
cmp cx, VAR_TYPE_INT;
|
||||
jnz end;
|
||||
cmp unsafeEnabled, 0;
|
||||
jz end;
|
||||
// check valid addr
|
||||
cmp checkValidMemAddr, 0;
|
||||
jz noCheck;
|
||||
@@ -160,6 +165,8 @@ void __declspec(naked) op_write_int() {
|
||||
_GET_ARG_INT(end);
|
||||
cmp cx, VAR_TYPE_INT;
|
||||
jnz end;
|
||||
cmp unsafeEnabled, 0;
|
||||
jz end;
|
||||
// check valid addr
|
||||
cmp checkValidMemAddr, 0;
|
||||
jz noCheck;
|
||||
@@ -197,6 +204,8 @@ void __declspec(naked) op_write_string() {
|
||||
cmp cx, VAR_TYPE_STR;
|
||||
jnz end;
|
||||
next:
|
||||
cmp unsafeEnabled, 0;
|
||||
jz end;
|
||||
// ecx - type, esi - value
|
||||
// edx - type, eax - addr
|
||||
// check valid address
|
||||
@@ -228,7 +237,7 @@ static void __fastcall CallOffsetInternal(fo::Program* script, DWORD func) {
|
||||
if ((short)fo::func::interpretPopShort(script) != (short)VAR_TYPE_INT) illegalArg++;
|
||||
args[i] = fo::func::interpretPopLong(script);
|
||||
}
|
||||
if (illegalArg || (checkValidMemAddr && (args[0] < 0x410010 || args[0] > 0x4FCE34))) {
|
||||
if (illegalArg || !unsafeEnabled || (checkValidMemAddr && (args[0] < 0x410010 || args[0] > 0x4FCE34))) {
|
||||
args[0] = 0;
|
||||
} else {
|
||||
__asm {
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace sfall
|
||||
namespace script
|
||||
{
|
||||
|
||||
extern bool unsafeEnabled;
|
||||
extern bool checkValidMemAddr;
|
||||
|
||||
// memory_reading_funcs
|
||||
|
||||
@@ -269,7 +269,7 @@ static void __fastcall defaultOpcodeHandler(fo::Program* program, DWORD opcodeOf
|
||||
}
|
||||
|
||||
void Opcodes::InitNew() {
|
||||
dlogr("Adding additional opcodes", DL_SCRIPT);
|
||||
dlogr("Adding sfall opcodes", DL_SCRIPT);
|
||||
|
||||
SafeWrite32(0x46E370, opcodeCount); // Maximum number of allowed opcodes
|
||||
SafeWrite32(0x46CE34, (DWORD)opcodes); // cmp check to make sure opcode exists
|
||||
@@ -284,18 +284,19 @@ void Opcodes::InitNew() {
|
||||
SetExtraKillCounter(KillCounter::UsingExtraKillTypes());
|
||||
|
||||
if (int unsafe = IniReader::GetIntDefaultConfig("Debugging", "AllowUnsafeScripting", 0)) {
|
||||
unsafeEnabled = true;
|
||||
if (unsafe == 2) checkValidMemAddr = false;
|
||||
dlogr(" Unsafe opcodes enabled.", DL_SCRIPT);
|
||||
opcodes[0x1cf] = op_write_byte;
|
||||
opcodes[0x1d0] = op_write_short;
|
||||
opcodes[0x1d1] = op_write_int;
|
||||
opcodes[0x21b] = op_write_string;
|
||||
for (int i = 0x1d2; i < 0x1dc; i++) {
|
||||
opcodes[i] = op_call_offset;
|
||||
}
|
||||
} else {
|
||||
dlogr(" Unsafe opcodes disabled.", DL_SCRIPT);
|
||||
}
|
||||
opcodes[0x1cf] = op_write_byte;
|
||||
opcodes[0x1d0] = op_write_short;
|
||||
opcodes[0x1d1] = op_write_int;
|
||||
opcodes[0x21b] = op_write_string;
|
||||
for (int i = 0x1d2; i < 0x1dc; i++) {
|
||||
opcodes[i] = op_call_offset;
|
||||
}
|
||||
opcodes[0x156] = op_read_byte;
|
||||
opcodes[0x157] = op_read_short;
|
||||
opcodes[0x158] = op_read_int;
|
||||
|
||||
Reference in New Issue
Block a user