mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Set idle(Sleep) function for losing window focus
Some code correction.
This commit is contained in:
+2
-2
@@ -421,7 +421,7 @@ CorpseDeleteTime=6
|
||||
;Set a number of milliseconds to idle each input loop
|
||||
;Set to -1 to disable
|
||||
;Set to 0 to idle only if other processes are waiting for processor time (WinXP/2000: if processes have equal priority)
|
||||
;Set to 1 (or some higher number if needed) to prevent 100% CPU use. The maximum is 127
|
||||
;Set to 1 (or some higher number if needed) to prevent 100% CPU use. The maximum is 100
|
||||
ProcessorIdle=-1
|
||||
|
||||
;Set to 1 if using the hero appearance mod
|
||||
@@ -599,7 +599,7 @@ ObjCanSeeObj_ShootThru_Fix=0
|
||||
;Set to 1 to fix the broken obj_can_hear_obj script function
|
||||
ObjCanHearObjFix=0
|
||||
|
||||
;Set to 1 to enable the mood argument of start_gdialog script function for talking heads
|
||||
;Set to 1 to enable the 'mood' argument of start_gdialog script function for talking heads
|
||||
;If the argument value is -1, the mood will be determined by the local variable 0 of the script (vanilla behavior)
|
||||
StartGDialogFix=0
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ WRAP_WATCOM_FUNC1(void, display_print, const char*, msg) // Displays message in
|
||||
WRAP_WATCOM_FUNC0(void, display_stats)
|
||||
WRAP_WATCOM_FUNC1(void, EndLoad, fo::DbFile*, file)
|
||||
// Execute script proc by internal proc number (from script's proc table, basically a sequential number of a procedure as defined in code, starting from 1)
|
||||
WRAP_WATCOM_FUNC2(void, executeProcedure, fo::Program*, sptr, long, procNum)
|
||||
WRAP_WATCOM_FUNC2(void, executeProcedure, fo::Program*, sptr, long, procPosition)
|
||||
WRAP_WATCOM_FUNC1(long, folder_print_line, const char*, text)
|
||||
WRAP_WATCOM_FUNC1(long, folder_print_seperator, const char*, text)
|
||||
WRAP_WATCOM_FUNC1(const char*, findCurrentProc, fo::Program*, program) // Returns the name of current procedure by program pointer
|
||||
|
||||
@@ -289,7 +289,7 @@ struct Program {
|
||||
long *codeStackPtr;
|
||||
long field_8;
|
||||
long field_C;
|
||||
long *codePtr;
|
||||
long codePosition; // position in the code stack when reading script opcodes
|
||||
long field_14; // unused?
|
||||
long field_18; // unused?
|
||||
long *dStackPtr;
|
||||
@@ -299,24 +299,17 @@ struct Program {
|
||||
long field_2C;
|
||||
long *stringRefPtr;
|
||||
long *procTablePtr;
|
||||
long field_38; // same as codeStackPtr
|
||||
long *codeStack; // same as codeStackPtr
|
||||
long savedEnv[12]; // saved register values
|
||||
long field_6C; // unused?
|
||||
long field_70; // unused?
|
||||
long field_74; // unused?
|
||||
long field_78;
|
||||
long field_7C;
|
||||
union {
|
||||
long flags;
|
||||
struct {
|
||||
char flags1;
|
||||
char flags2;
|
||||
char flags3;
|
||||
char flags4;
|
||||
};
|
||||
};
|
||||
long timerTick; // unused?
|
||||
long func_7C; // always null?
|
||||
short flags;
|
||||
short fetchOpcode;
|
||||
long currentScriptWin; // current window for executing script
|
||||
long field_88;
|
||||
long shouldRemove;
|
||||
};
|
||||
|
||||
static_assert(sizeof(Program) == 140, "Incorrect Program definition.");
|
||||
|
||||
@@ -2338,10 +2338,12 @@ skip:
|
||||
|
||||
static void __declspec(naked) exec_script_proc_hack() {
|
||||
__asm {
|
||||
mov eax, [esi + 0x58];
|
||||
test edi, edi; // loading?
|
||||
jnz end;
|
||||
mov eax, [esi + 0x58]; // script.procedure_table.start
|
||||
test eax, eax;
|
||||
ja end;
|
||||
inc eax; // start proc
|
||||
ja end; // != 0
|
||||
dec eax; // is bad - set to -1 for skipping execution
|
||||
end:
|
||||
retn;
|
||||
}
|
||||
@@ -2349,10 +2351,10 @@ end:
|
||||
|
||||
static void __declspec(naked) exec_script_proc_hack1() {
|
||||
__asm {
|
||||
mov esi, [edi + 0x58];
|
||||
mov esi, [edi + 0x58]; // script.procedure_table.start
|
||||
test esi, esi;
|
||||
ja end;
|
||||
inc esi; // start proc
|
||||
ja end; // != 0
|
||||
inc esi; // 1 - default position
|
||||
end:
|
||||
retn;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
// Struct for registered hook script
|
||||
struct HookScript {
|
||||
ScriptProgram prog;
|
||||
int callback; // proc number in script's proc table
|
||||
int callback; // procedure position in script's proc table
|
||||
bool isGlobalScript; // false for hs_* scripts, true for gl* scripts
|
||||
};
|
||||
|
||||
|
||||
@@ -808,6 +808,10 @@ void MiscPatches::init() {
|
||||
dlogr(" Done", DL_INIT);
|
||||
}
|
||||
|
||||
// Set idle function
|
||||
fo::var::idle_func = reinterpret_cast<void*>(Sleep);
|
||||
SafeWrite16(0x4C9F12, 0x7D6A); // push 125 (ms)
|
||||
|
||||
BlockCall(0x4425E6); // Patch out ereg call
|
||||
|
||||
SafeWrite8(0x4810AB, CodeType::JumpShort); // Disable selfrun
|
||||
|
||||
@@ -623,27 +623,27 @@ static void ClearGlobalScripts() {
|
||||
|
||||
void RunScriptProc(ScriptProgram* prog, const char* procName) {
|
||||
fo::Program* sptr = prog->ptr;
|
||||
int procNum = fo::func::interpretFindProcedure(sptr, procName);
|
||||
if (procNum != -1) {
|
||||
fo::func::executeProcedure(sptr, procNum);
|
||||
int procPosition = fo::func::interpretFindProcedure(sptr, procName);
|
||||
if (procPosition != -1) {
|
||||
fo::func::executeProcedure(sptr, procPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void RunScriptProc(ScriptProgram* prog, long procId) {
|
||||
if (procId > 0 && procId < fo::Scripts::ScriptProc::count) {
|
||||
int procNum = prog->procLookup[procId];
|
||||
if (procNum != -1) {
|
||||
fo::func::executeProcedure(prog->ptr, procNum);
|
||||
int procPosition = prog->procLookup[procId];
|
||||
if (procPosition != -1) {
|
||||
fo::func::executeProcedure(prog->ptr, procPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int RunScriptStartProc(ScriptProgram* prog) {
|
||||
int procNum = prog->procLookup[fo::Scripts::ScriptProc::start];
|
||||
if (procNum != -1) {
|
||||
fo::func::executeProcedure(prog->ptr, procNum);
|
||||
int procPosition = prog->procLookup[fo::Scripts::ScriptProc::start];
|
||||
if (procPosition != -1) {
|
||||
fo::func::executeProcedure(prog->ptr, procPosition);
|
||||
}
|
||||
return procNum;
|
||||
return procPosition;
|
||||
}
|
||||
|
||||
static void RunScript(GlobalScript* script) {
|
||||
@@ -940,12 +940,7 @@ void ScriptExtender::init() {
|
||||
}
|
||||
|
||||
idle = IniReader::GetConfigInt("Misc", "ProcessorIdle", -1);
|
||||
if (idle > -1) {
|
||||
if (idle > 127) idle = 127;
|
||||
fo::var::idle_func = reinterpret_cast<void*>(Sleep);
|
||||
SafeWrite8(0x4C9F12, 0x6A); // push idle
|
||||
SafeWrite8(0x4C9F13, idle);
|
||||
}
|
||||
if (idle > -1 && idle > 100) idle = 100;
|
||||
|
||||
arraysBehavior = IniReader::GetConfigInt("Misc", "arraysBehavior", 1);
|
||||
if (arraysBehavior > 0) {
|
||||
|
||||
Reference in New Issue
Block a user