Added a file size check for scripts

* this is for filtering out some clearly defective (or not even valid)
scripts.
This commit is contained in:
NovaRain
2026-04-24 21:37:46 +08:00
parent fb47779d4c
commit f4eaaccc57
+18
View File
@@ -846,6 +846,21 @@ void SetGlobals(GlobalVar* globals) {
}
}
static __declspec(naked) void allocateProgram_hook() {
static const DWORD allocateProgram_Error = 0x467752;
__asm {
call fo::funcoffs::db_filelength_;
cmp eax, 118; // minimum size in bytes
jl error;
retn;
error:
mov eax, ebp; // file
call fo::funcoffs::db_fclose_;
add esp, 4;
jmp allocateProgram_Error;
}
}
static DWORD pcFlagSneak;
static __declspec(naked) void map_save_in_game_hook() {
@@ -970,6 +985,9 @@ void ScriptExtender::init() {
HookCall(0x421B72, CombatBeginHook);
HookCall(0x421FC1, CombatOverHook);
// Add a basic file size check for scripts
HookCall(0x467777, allocateProgram_hook);
// Reorder the execution of functions before exiting the map
// Call saving party member prototypes and removing the drug effects for NPC after executing map_exit_p_proc procedure
HookCall(0x483CB4, map_save_in_game_hook);