mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Code edits to ScriptExtender.cpp
Updated FalloutStructs.h and ddraw.ini.
This commit is contained in:
+1
-1
@@ -808,7 +808,7 @@ HideObjIsNullMsg=0
|
|||||||
;Has pretty nasty side effects when saving/reloading, so don't use for regular gameplay
|
;Has pretty nasty side effects when saving/reloading, so don't use for regular gameplay
|
||||||
DontDeleteProtos=0
|
DontDeleteProtos=0
|
||||||
|
|
||||||
;Set to 1 to force sfall to search for global scripts every time the game loads rather than only the first time
|
;Set to 1 to force sfall to search for global/hook scripts every time the game loads rather than only the first time
|
||||||
AlwaysFindScripts=0
|
AlwaysFindScripts=0
|
||||||
|
|
||||||
;Set to 1 to force critters to display combat float messages
|
;Set to 1 to force critters to display combat float messages
|
||||||
|
|||||||
+14
-8
@@ -247,20 +247,20 @@ struct TProgram {
|
|||||||
long field_8;
|
long field_8;
|
||||||
long field_C;
|
long field_C;
|
||||||
long *codePtr;
|
long *codePtr;
|
||||||
long field_14;
|
long field_14; // unused?
|
||||||
long field_18;
|
long field_18; // unused?
|
||||||
long *dStackPtr;
|
long *dStackPtr;
|
||||||
long *aStackPtr;
|
long *aStackPtr;
|
||||||
long *dStackOffs;
|
long *dStackOffs;
|
||||||
long *aStackOffs;
|
long *aStackOffs;
|
||||||
long field_2C;
|
long field_2C;
|
||||||
long *stringRefPtr;
|
long *stringRefPtr;
|
||||||
long field_34; // procTablePtr
|
long *procTablePtr;
|
||||||
long *procTablePtr; // field_38
|
long field_38; // same as codeStackPtr
|
||||||
long regs[12];
|
long savedEnv[12]; // saved register values
|
||||||
long field_6C;
|
long field_6C; // unused?
|
||||||
long field_70;
|
long field_70; // unused?
|
||||||
long field_74;
|
long field_74; // unused?
|
||||||
long field_78;
|
long field_78;
|
||||||
long field_7C;
|
long field_7C;
|
||||||
union {
|
union {
|
||||||
@@ -278,6 +278,12 @@ struct TProgram {
|
|||||||
|
|
||||||
static_assert(sizeof(TProgram) == 140, "Incorrect TProgram definition.");
|
static_assert(sizeof(TProgram) == 140, "Incorrect TProgram definition.");
|
||||||
|
|
||||||
|
struct ProgramList {
|
||||||
|
TProgram* progPtr;
|
||||||
|
ProgramList* next;
|
||||||
|
ProgramList* prev;
|
||||||
|
};
|
||||||
|
|
||||||
struct ItemButtonItem {
|
struct ItemButtonItem {
|
||||||
TGameObj* item;
|
TGameObj* item;
|
||||||
union {
|
union {
|
||||||
|
|||||||
@@ -1705,11 +1705,11 @@ void LoadHookScript(const char* name, int id) {
|
|||||||
dlog_f("Found hook script: %s\n", DL_HOOK, name);
|
dlog_f("Found hook script: %s\n", DL_HOOK, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadHookScriptFile(const char* name, int id) {
|
static void InitHookScriptFile(const char* name, int id) {
|
||||||
sScriptProgram prog;
|
sScriptProgram prog;
|
||||||
dlog("> ", DL_HOOK);
|
dlog("> ", DL_HOOK);
|
||||||
dlog(name, DL_HOOK);
|
dlog(name, DL_HOOK);
|
||||||
LoadScriptProgram(prog, name);
|
InitScriptProgram(prog, name);
|
||||||
if (prog.ptr) {
|
if (prog.ptr) {
|
||||||
sHookScript hook;
|
sHookScript hook;
|
||||||
hook.prog = prog;
|
hook.prog = prog;
|
||||||
@@ -1770,14 +1770,14 @@ void InitHookScripts() {
|
|||||||
dlogr("Running hook scripts...", DL_HOOK);
|
dlogr("Running hook scripts...", DL_HOOK);
|
||||||
|
|
||||||
for (std::vector<HookFile>::const_iterator it = hookScriptFilesList.begin(); it != hookScriptFilesList.end(); ++it) {
|
for (std::vector<HookFile>::const_iterator it = hookScriptFilesList.begin(); it != hookScriptFilesList.end(); ++it) {
|
||||||
LoadHookScriptFile(it->name.c_str(), it->id);
|
InitHookScriptFile(it->name.c_str(), it->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
initingHookScripts = 1;
|
initingHookScripts = 1;
|
||||||
for (int i = 0; i < numHooks; i++) {
|
for (int i = 0; i < numHooks; i++) {
|
||||||
if (!hooks[i].empty()) {
|
if (!hooks[i].empty()) {
|
||||||
hooksInfo[i].hasHsScript = true;
|
hooksInfo[i].hasHsScript = true;
|
||||||
InitScriptProgram(hooks[i][0].prog); // zero hook is always hs_*.int script because Hook scripts are loaded BEFORE global scripts
|
RunScriptProgram(hooks[i][0].prog); // zero hook is always hs_*.int script because Hook scripts are loaded BEFORE global scripts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initingHookScripts = 0;
|
initingHookScripts = 0;
|
||||||
|
|||||||
+22
-23
@@ -1066,9 +1066,9 @@ static void __declspec(naked) ExecMapScriptsHack() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static sExportedVar* __fastcall GetGlobalExportedVarPtr(const char* name) {
|
static sExportedVar* __fastcall GetGlobalExportedVarPtr(const char* name) {
|
||||||
|
devlog_f("Trying to find exported var %s\n", DL_MAIN, name);
|
||||||
std::string str(name);
|
std::string str(name);
|
||||||
ExportedVarsMap::iterator it = globalExportedVars.find(str);
|
ExportedVarsMap::iterator it = globalExportedVars.find(str);
|
||||||
//dlog_f("\n Trying to find exported var %s... ", DL_MAIN, name);
|
|
||||||
if (it != globalExportedVars.end()) {
|
if (it != globalExportedVars.end()) {
|
||||||
sExportedVar *ptr = &it->second;
|
sExportedVar *ptr = &it->second;
|
||||||
return ptr;
|
return ptr;
|
||||||
@@ -1076,8 +1076,8 @@ static sExportedVar* __fastcall GetGlobalExportedVarPtr(const char* name) {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __stdcall CreateGlobalExportedVar(DWORD scr, const char* name) {
|
static void __fastcall CreateGlobalExportedVar(TProgram* script, const char* name) {
|
||||||
//dlog_f("\nTrying to export variable %s (%d)\n", DL_MAIN, name, isGlobalScriptLoading);
|
devlog_f("Trying to export variable %s (%d)\n", DL_MAIN, name, isGlobalScriptLoading);
|
||||||
std::string str(name);
|
std::string str(name);
|
||||||
globalExportedVars[str] = sExportedVar(); // add new
|
globalExportedVars[str] = sExportedVar(); // add new
|
||||||
}
|
}
|
||||||
@@ -1094,7 +1094,7 @@ static void __declspec(naked) Export_FetchOrStore_FindVar_Hook() {
|
|||||||
__asm {
|
__asm {
|
||||||
push ecx;
|
push ecx;
|
||||||
push edx;
|
push edx;
|
||||||
mov ecx, edx; // varName
|
mov ecx, edx; // varName
|
||||||
call GetGlobalExportedVarPtr;
|
call GetGlobalExportedVarPtr;
|
||||||
pop edx;
|
pop edx;
|
||||||
pop ecx;
|
pop ecx;
|
||||||
@@ -1108,19 +1108,18 @@ proceedNormal:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __declspec(naked) Export_Export_FindVar_Hook() {
|
static void __declspec(naked) exportExportVariable_hook() {
|
||||||
static const DWORD Export_Export_FindVar_back = 0x4414AE;
|
static const DWORD exportExportVariable_BackRet = 0x4414AE;
|
||||||
__asm {
|
__asm {
|
||||||
cmp isGlobalScriptLoading, 0;
|
cmp isGlobalScriptLoading, 0;
|
||||||
jz proceedNormal;
|
jz proceedNormal;
|
||||||
push edx; // var name
|
mov ecx, ebp; // script ptr
|
||||||
push ebp; // script ptr
|
call CreateGlobalExportedVar; // edx - var name
|
||||||
call CreateGlobalExportedVar;
|
|
||||||
xor eax, eax;
|
xor eax, eax;
|
||||||
add esp, 4; // destroy return
|
add esp, 4; // destroy return
|
||||||
jmp Export_Export_FindVar_back; // if sfall exported var, jump to the end of function
|
jmp exportExportVariable_BackRet; // if sfall exported var, jump to the end of function
|
||||||
proceedNormal:
|
proceedNormal:
|
||||||
jmp findVar_; // else - proceed normal
|
jmp findVar_; // else - proceed normal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1268,7 +1267,7 @@ end:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// loads script from .int file into a sScriptProgram struct, filling script pointer and proc lookup table
|
// loads script from .int file into a sScriptProgram struct, filling script pointer and proc lookup table
|
||||||
void LoadScriptProgram(sScriptProgram &prog, const char* fileName) {
|
void InitScriptProgram(sScriptProgram &prog, const char* fileName) {
|
||||||
TProgram* scriptPtr = fo_loadProgram(fileName);
|
TProgram* scriptPtr = fo_loadProgram(fileName);
|
||||||
|
|
||||||
if (scriptPtr) {
|
if (scriptPtr) {
|
||||||
@@ -1278,17 +1277,17 @@ void LoadScriptProgram(sScriptProgram &prog, const char* fileName) {
|
|||||||
for (int i = 0; i < Scripts::count; ++i) {
|
for (int i = 0; i < Scripts::count; ++i) {
|
||||||
prog.procLookup[i] = fo_interpretFindProcedure(prog.ptr, procTable[i]);
|
prog.procLookup[i] = fo_interpretFindProcedure(prog.ptr, procTable[i]);
|
||||||
}
|
}
|
||||||
prog.initialized = 0;
|
prog.initialized = false;
|
||||||
} else {
|
} else {
|
||||||
prog.ptr = nullptr;
|
prog.ptr = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitScriptProgram(sScriptProgram &prog) {
|
void RunScriptProgram(sScriptProgram &prog) {
|
||||||
if (prog.initialized == 0) {
|
if (!prog.initialized) {
|
||||||
fo_runProgram(prog.ptr);
|
fo_runProgram(prog.ptr);
|
||||||
fo_interpret(prog.ptr, -1);
|
fo_interpret(prog.ptr, -1);
|
||||||
prog.initialized = 1;
|
prog.initialized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1328,7 +1327,7 @@ static void LoadGlobalScriptsList() {
|
|||||||
const std::string &scriptFile = *it;
|
const std::string &scriptFile = *it;
|
||||||
dlog("> ", DL_SCRIPT);
|
dlog("> ", DL_SCRIPT);
|
||||||
dlog(scriptFile.c_str(), DL_SCRIPT);
|
dlog(scriptFile.c_str(), DL_SCRIPT);
|
||||||
LoadScriptProgram(prog, scriptFile.c_str());
|
InitScriptProgram(prog, scriptFile.c_str());
|
||||||
if (prog.ptr) {
|
if (prog.ptr) {
|
||||||
sGlobalScript gscript = sGlobalScript(prog);
|
sGlobalScript gscript = sGlobalScript(prog);
|
||||||
gscript.startProc = prog.procLookup[Scripts::start]; // get 'start' procedure position
|
gscript.startProc = prog.procLookup[Scripts::start]; // get 'start' procedure position
|
||||||
@@ -1336,7 +1335,7 @@ static void LoadGlobalScriptsList() {
|
|||||||
AddProgramToMap(prog);
|
AddProgramToMap(prog);
|
||||||
dlogr(" Done", DL_SCRIPT);
|
dlogr(" Done", DL_SCRIPT);
|
||||||
// initialize script (start proc will be executed for the first time) -- this needs to be after script is added to "globalScripts" array
|
// initialize script (start proc will be executed for the first time) -- this needs to be after script is added to "globalScripts" array
|
||||||
InitScriptProgram(prog);
|
RunScriptProgram(prog);
|
||||||
} else {
|
} else {
|
||||||
dlogr(" Error!", DL_SCRIPT);
|
dlogr(" Error!", DL_SCRIPT);
|
||||||
}
|
}
|
||||||
@@ -1368,7 +1367,7 @@ static void PrepareGlobalScriptsList() {
|
|||||||
std::string baseName(name);
|
std::string baseName(name);
|
||||||
int lastDot = baseName.find_last_of('.');
|
int lastDot = baseName.find_last_of('.');
|
||||||
if ((baseName.length() - lastDot) > 4) continue; // skip files with invalid extension (bug in db_get_file_list fuction)
|
if ((baseName.length() - lastDot) > 4) continue; // skip files with invalid extension (bug in db_get_file_list fuction)
|
||||||
dlog_f("Found global script: %s\n", DL_INIT, name);
|
dlog_f("Found global script: %s\n", DL_SCRIPT, name);
|
||||||
|
|
||||||
baseName = baseName.substr(0, lastDot); // script name without extension
|
baseName = baseName.substr(0, lastDot); // script name without extension
|
||||||
if (!IsGameScript(baseName.c_str())) {
|
if (!IsGameScript(baseName.c_str())) {
|
||||||
@@ -1823,10 +1822,10 @@ void ScriptExtender_Init() {
|
|||||||
HookCall(0x4A3E08, script_chk_timed_events_hook);
|
HookCall(0x4A3E08, script_chk_timed_events_hook);
|
||||||
|
|
||||||
// this patch makes it possible to export variables from sfall global scripts
|
// this patch makes it possible to export variables from sfall global scripts
|
||||||
HookCall(0x4414C8, Export_Export_FindVar_Hook);
|
HookCall(0x4414C8, exportExportVariable_hook);
|
||||||
const DWORD exportFindVarAddr[] = {
|
const DWORD exportFindVarAddr[] = {
|
||||||
0x441285, // store
|
0x441285, // exportStoreVariable_
|
||||||
0x4413D9 // fetch
|
0x4413D9 // exportFetchVariable_
|
||||||
};
|
};
|
||||||
HookCalls(Export_FetchOrStore_FindVar_Hook, exportFindVarAddr);
|
HookCalls(Export_FetchOrStore_FindVar_Hook, exportFindVarAddr);
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ enum SfallDataType : unsigned long {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
TProgram* ptr;
|
TProgram* ptr;
|
||||||
int procLookup[Scripts::count];
|
int procLookup[Scripts::count];
|
||||||
char initialized;
|
bool initialized;
|
||||||
} sScriptProgram;
|
} sScriptProgram;
|
||||||
|
|
||||||
#pragma pack(push, 8)
|
#pragma pack(push, 8)
|
||||||
@@ -70,10 +70,10 @@ int __stdcall ScriptHasLoaded(TProgram* script);
|
|||||||
// loads script from .int file into a sScriptProgram struct, filling script pointer and proc lookup table
|
// loads script from .int file into a sScriptProgram struct, filling script pointer and proc lookup table
|
||||||
// prog - reference to program structure
|
// prog - reference to program structure
|
||||||
// fileName - the script file name without extension
|
// fileName - the script file name without extension
|
||||||
void LoadScriptProgram(sScriptProgram &prog, const char* fileName);
|
void InitScriptProgram(sScriptProgram &prog, const char* fileName);
|
||||||
|
|
||||||
// init program after load, needs to be called once
|
// init program after load, needs to be called once
|
||||||
void InitScriptProgram(sScriptProgram &prog);
|
void RunScriptProgram(sScriptProgram &prog);
|
||||||
|
|
||||||
// execute script by specific proc name
|
// execute script by specific proc name
|
||||||
void RunScriptProc(sScriptProgram* prog, const char* procName);
|
void RunScriptProc(sScriptProgram* prog, const char* procName);
|
||||||
|
|||||||
Reference in New Issue
Block a user