From aab04764ae019742a4c336ab806138a21be5de54 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Tue, 17 Mar 2020 13:39:05 +0800 Subject: [PATCH] Added a new value to AllowUnsafeScripting * for disabling the memory address check in write_xxx unsafe functions. --- artifacts/ddraw.ini | 1 + sfall/ScriptExtender.cpp | 3 ++- sfall/ScriptOps/MemoryOps.hpp | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/artifacts/ddraw.ini b/artifacts/ddraw.ini index 51b7608f..8e3095fe 100644 --- a/artifacts/ddraw.ini +++ b/artifacts/ddraw.ini @@ -770,6 +770,7 @@ SkipSizeCheck=0 DontDeleteProtos=0 ;Set to 1 to give scripts direct access to Fallout's address space, and to make arbitrary calls into Fallout's code +;Set to 2 to also disable the memory address check in unsafe script functions ;Does not require sfall debugging mode AllowUnsafeScripting=0 diff --git a/sfall/ScriptExtender.cpp b/sfall/ScriptExtender.cpp index 264cc90c..7b9e4800 100644 --- a/sfall/ScriptExtender.cpp +++ b/sfall/ScriptExtender.cpp @@ -1791,7 +1791,8 @@ void ScriptExtenderInit() { SetExtraKillCounter(UsingExtraKillTypes()); - if (iniGetInt("Debugging", "AllowUnsafeScripting", 0, ddrawIniDef)) { + if (int unsafe = iniGetInt("Debugging", "AllowUnsafeScripting", 0, ddrawIniDef)) { + if (unsafe == 2) checkValidMemAddr = false; dlogr(" Unsafe opcodes enabled.", DL_SCRIPT); opcodes[0x1cf] = WriteByte; opcodes[0x1d0] = WriteShort; diff --git a/sfall/ScriptOps/MemoryOps.hpp b/sfall/ScriptOps/MemoryOps.hpp index 00f86ff0..7ca35f49 100644 --- a/sfall/ScriptOps/MemoryOps.hpp +++ b/sfall/ScriptOps/MemoryOps.hpp @@ -24,6 +24,8 @@ #define START_VALID_ADDR 0x410000 #define END_VALID_ADDR 0x6B403F +bool checkValidMemAddr = true; + // memory_reading_funcs static void __declspec(naked) ReadByte() { __asm { @@ -102,10 +104,13 @@ static void __declspec(naked) WriteByte() { cmp cx, VAR_TYPE_INT; jnz end; // check valid addr + cmp checkValidMemAddr, 0; + jz noCheck; cmp eax, START_VALID_ADDR; jb end; cmp eax, END_VALID_ADDR; ja end; +noCheck: and esi, 0xFF; push esi; push eax; @@ -129,10 +134,13 @@ static void __declspec(naked) WriteShort() { cmp cx, VAR_TYPE_INT; jnz end; // check valid addr + cmp checkValidMemAddr, 0; + jz noCheck; cmp eax, START_VALID_ADDR; jb end; cmp eax, END_VALID_ADDR; ja end; +noCheck: and esi, 0xFFFF; push esi; push eax; @@ -156,10 +164,13 @@ static void __declspec(naked) WriteInt() { cmp cx, VAR_TYPE_INT; jnz end; // check valid addr + cmp checkValidMemAddr, 0; + jz noCheck; cmp eax, START_VALID_ADDR; jb end; cmp eax, END_VALID_ADDR; ja end; +noCheck: push esi; push eax; call SafeWrite32; @@ -196,10 +207,13 @@ next: // ecx - type, esi - value // edx - type, eax - addr // check valid address + cmp checkValidMemAddr, 0; + jz noCheck; cmp eax, START_VALID_ADDR; jb end; cmp eax, END_VALID_ADDR; ja end; +noCheck: push ebx; // script push esi; // str value mov edx, ecx; // type