Redid the idle implementation for ProcessorIdle

Renamed RunGlobalScripts# functions to the same as 4.x.
This commit is contained in:
NovaRain
2022-01-11 10:03:35 +08:00
parent 52126bf62d
commit de51b6838b
7 changed files with 31 additions and 22 deletions
+1 -1
View File
@@ -280,7 +280,7 @@ public:
return RealDevice->GetDeviceData(a, buf, count, d);
}
RunGlobalScripts2();
RunGlobalScriptsOnInput();
if (!buf || bufferedPresses.empty() || (d & DIGDD_PEEK)) {
HRESULT hr = RealDevice->GetDeviceData(a, buf, count, d);
+1
View File
@@ -681,6 +681,7 @@ void Interface::init() {
InventoryCharacterRotationSpeedPatch();
UIAnimationSpeedPatch();
// Remove window position rounding for script-created windows
//if (IniReader::GetConfigInt("Misc", "RemoveWindowRounding", 1)) {
const DWORD windowRoundingAddr[] = {0x4D6EDD, 0x4D6F12};
SafeWriteBatch<BYTE>(CodeType::JumpShort, windowRoundingAddr);
+2 -2
View File
@@ -15,12 +15,12 @@ static void MainGameLoopResetStates() {
}
static void __stdcall MainGameLoop() { // OnMainLoop
RunGlobalScripts1();
RunGlobalScriptsOnMainLoop();
MainGameLoopResetStates();
}
static void __stdcall CombatLoop() { // OnCombatLoop
RunGlobalScripts1();
RunGlobalScriptsOnMainLoop();
}
static void __stdcall AfterCombatAttack() { // OnAfterCombatAttack
+15
View File
@@ -29,12 +29,23 @@
namespace sfall
{
static int idle = -1;
static char mapName[16] = {};
static char patchName[65] = {};
static char versionString[65] = {};
static int* scriptDialog = nullptr;
static void __declspec(naked) GNW95_process_message_hack() {
__asm {
push idle;
call Sleep;
cmp ds:[FO_VAR_GNW95_isActive], 0;
retn;
}
}
static void __declspec(naked) WeaponAnimHook() {
__asm {
cmp edx, 11;
@@ -978,6 +989,10 @@ void MiscPatches::init() {
*fo::ptr::idle_func = reinterpret_cast<void*>(Sleep);
SafeWrite16(0x4C9F12, 0x7D6A); // push 125 (ms)
int ms = IniReader::GetConfigInt("Misc", "ProcessorIdle", -1);
if (ms > idle) idle = (ms > 30) ? 30 : ms;
if (idle >= 0) MakeCall(0x4C9CF8, GNW95_process_message_hack, 2);
BlockCall(0x4425E6); // Patch out ereg call
SafeWrite8(0x4810AB, CodeType::JumpShort); // Disable selfrun
+3 -14
View File
@@ -55,8 +55,6 @@ static int outlineColor;
static char highlightFail1[128];
static char highlightFail2[128];
static int idle;
char ScriptExtender::gTextBuffer[5120]; // used as global temp text buffer for script functions
bool ScriptExtender::OnMapLeave;
@@ -774,9 +772,7 @@ static inline void RunGlobalScripts(int mode1, int mode2) {
ResetStateAfterFrame();
}
void RunGlobalScripts1() {
if (idle > -1) Sleep(idle);
void RunGlobalScriptsOnMainLoop() {
if (toggleHighlightsKey) {
// 0x48C294 to toggle
if (KeyDown(toggleHighlightsKey)) {
@@ -808,17 +804,13 @@ void RunGlobalScripts1() {
RunGlobalScripts(0, 3);
}
void RunGlobalScripts2() {
void RunGlobalScriptsOnInput() {
if (IsGameLoaded()) {
if (idle > -1) Sleep(idle);
RunGlobalScripts(1, 1);
}
}
void RunGlobalScripts3() {
if (idle > -1) Sleep(idle);
void RunGlobalScriptsOnWorldMap() {
RunGlobalScripts(2, 3);
}
@@ -1175,9 +1167,6 @@ void ScriptExtender::init() {
HookCall(0x44E559, obj_remove_outline_hook); // gmouse_remove_item_outline_
}
idle = IniReader::GetConfigInt("Misc", "ProcessorIdle", -1);
if (idle > -1 && idle > 30) idle = 30;
alwaysFindScripts = isDebug && (IniReader::GetIntDefaultConfig("Debugging", "AlwaysFindScripts", 0) != 0);
if (alwaysFindScripts) dlogr("Always searching for global scripts behavior enabled.", DL_SCRIPT);
+3 -3
View File
@@ -84,9 +84,9 @@ void LoadGlobalScripts();
void InitGlobalScripts();
bool IsGameScript(const char* filename);
void RunGlobalScripts1();
void RunGlobalScripts2();
void RunGlobalScripts3();
void RunGlobalScriptsOnMainLoop();
void RunGlobalScriptsOnInput();
void RunGlobalScriptsOnWorldMap();
void RunGlobalScriptsAtProc(DWORD procId);
bool LoadGlobals(HANDLE h);
+6 -2
View File
@@ -51,6 +51,10 @@ static float scriptMapMulti = 1.0f;
static bool addYear = false; // used as additional years indicator
static DWORD addedYears = 0;
static void __stdcall WorldmapLoopHook() { // OnWorldmapLoop
RunGlobalScriptsOnWorldMap();
}
static __declspec(naked) void TimeDateFix() {
__asm {
test edi, edi; // year buf
@@ -116,7 +120,7 @@ end:
static void WorldMapFPS() {
DWORD prevTicks = worldMapTicks; // previous ticks
do {
RunGlobalScripts3();
WorldmapLoopHook();
if (worldMapLongDelay) {
__asm call fo::funcoffs::process_bk_;
}
@@ -157,7 +161,7 @@ static void __declspec(naked) wmWorldMap_hook() {
cmp eax, worldMapTicks;
je skipHook;
mov worldMapTicks, eax;
call RunGlobalScripts3; // scripts are run every ~15 ms (GetTickCount returns a difference of 14-16 ms)
call WorldmapLoopHook; // hook is called every ~15 ms (GetTickCount returns a difference of 14-16 ms)
skipHook:
jmp fo::funcoffs::get_input_;
}