mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
Added some tweaks for debug log
Code edits in SpeedPatch.cpp
This commit is contained in:
+22
-3
@@ -383,7 +383,23 @@ static void __declspec(naked) debugMsg() {
|
||||
}
|
||||
}
|
||||
|
||||
//static const DWORD addrNewLine[] = {0x50B244, 0x50B27C, 0x50B2B6, 0x50B2EE}; // ERROR: attempt to reference * var out of range: %d
|
||||
// Shifts the string one character to the right and inserts a newline control character at the beginning
|
||||
static void MoveDebugString(char* messageAddr) {
|
||||
int i = 0;
|
||||
do {
|
||||
messageAddr[i + 1] = messageAddr[i];
|
||||
i--;
|
||||
} while (messageAddr[i] != '\0');
|
||||
messageAddr[i + 1] = '\n';
|
||||
}
|
||||
|
||||
static const DWORD addrSpaceChar[] = {
|
||||
0x50B244, 0x50B27C, 0x50B2B6, 0x50B2EE // "ERROR: attempt to reference * var out of range: %d"
|
||||
};
|
||||
|
||||
static const DWORD addrNewLineChar[] = {
|
||||
0x500A64, // "Friendly was in the way!"
|
||||
};
|
||||
|
||||
static void DebugModePatch() {
|
||||
int dbgMode = iniGetInt("Debugging", "DebugMode", 0, ddrawIniDef);
|
||||
@@ -427,7 +443,8 @@ static void DebugModePatch() {
|
||||
SafeWrite8(0x4DC34D, 15);
|
||||
|
||||
// Fix the format of some debug messages
|
||||
//SafeWriteBatch<BYTE>(0xA, addrNewLine);
|
||||
SafeWriteBatch<BYTE>('\n', addrNewLineChar);
|
||||
//SafeWriteBatch<BYTE>(' ', addrSpaceChar);
|
||||
const DWORD mapVarErrorAddr[] = {
|
||||
0x482240, // map_set_global_var_
|
||||
0x482274, // map_get_global_var_
|
||||
@@ -435,7 +452,9 @@ static void DebugModePatch() {
|
||||
0x4822D4 // map_get_local_var_
|
||||
};
|
||||
HookCalls(debugMsg, mapVarErrorAddr);
|
||||
|
||||
if (dbgMode != 1) {
|
||||
MoveDebugString((char*)0x500A9B); // "computing attack..."
|
||||
}
|
||||
dlogr(" Done", DL_INIT);
|
||||
}
|
||||
}
|
||||
|
||||
+33
-23
@@ -48,7 +48,7 @@ static bool toggled = false;
|
||||
static bool slideShow = false;
|
||||
|
||||
static double multi;
|
||||
static DWORD storedTickCount = 0;
|
||||
static DWORD sfallTickCount = 0;
|
||||
static DWORD lastTickCount;
|
||||
static double tickCountFraction = 0.0;
|
||||
|
||||
@@ -59,16 +59,12 @@ static struct SpeedCfg {
|
||||
double multiplier;
|
||||
} *speed = nullptr;
|
||||
|
||||
static int modKey;
|
||||
static int modKey[2];
|
||||
static int toggleKey;
|
||||
|
||||
static DWORD __stdcall FakeGetTickCount() {
|
||||
// Keyboard control
|
||||
if (modKey && ((modKey > 0 && KeyDown(modKey))
|
||||
|| (modKey == -1 && (KeyDown(DIK_LCONTROL) || KeyDown(DIK_RCONTROL)))
|
||||
|| (modKey == -2 && (KeyDown(DIK_LMENU) || KeyDown(DIK_RMENU)))
|
||||
|| (modKey == -3 && (KeyDown(DIK_LSHIFT) || KeyDown(DIK_RSHIFT)))))
|
||||
{
|
||||
if (modKey[0] && (KeyDown(modKey[0]) || (modKey[1] && KeyDown(modKey[1])))) {
|
||||
if (toggleKey && KeyDown(toggleKey)) {
|
||||
if (!toggled) {
|
||||
toggled = true;
|
||||
@@ -87,33 +83,30 @@ static DWORD __stdcall FakeGetTickCount() {
|
||||
}
|
||||
|
||||
DWORD newTickCount = GetTickCount();
|
||||
if (newTickCount == lastTickCount) return sfallTickCount;
|
||||
|
||||
// Just in case someone's been running their computer for 49 days straight
|
||||
if (newTickCount < lastTickCount) {
|
||||
newTickCount = lastTickCount;
|
||||
return storedTickCount;
|
||||
if (lastTickCount > newTickCount) {
|
||||
lastTickCount = newTickCount;
|
||||
return sfallTickCount;
|
||||
}
|
||||
|
||||
double elapsed = (double)(newTickCount - lastTickCount);
|
||||
lastTickCount = newTickCount;
|
||||
|
||||
// Multiply the tick count difference by the multiplier
|
||||
if (enabled && !slideShow
|
||||
&& !(GetLoopFlags() & (INVENTORY | INTFACEUSE | INTFACELOOT | DIALOG)))
|
||||
{
|
||||
if (enabled && !slideShow && !(GetLoopFlags() & (INVENTORY | INTFACEUSE | INTFACELOOT | DIALOG))) {
|
||||
elapsed *= multi;
|
||||
tickCountFraction += modf(elapsed, &elapsed);
|
||||
elapsed += tickCountFraction;
|
||||
tickCountFraction = modf(elapsed, &elapsed);
|
||||
}
|
||||
storedTickCount += (DWORD)elapsed;
|
||||
sfallTickCount += (DWORD)elapsed;
|
||||
|
||||
if (tickCountFraction > 1.0) {
|
||||
tickCountFraction -= 1.0;
|
||||
storedTickCount++;
|
||||
}
|
||||
return storedTickCount;
|
||||
return sfallTickCount;
|
||||
}
|
||||
|
||||
void __stdcall FakeGetLocalTime(LPSYSTEMTIME time) {
|
||||
__int64 currentTime = startTime + storedTickCount * 10000;
|
||||
__int64 currentTime = startTime + sfallTickCount * 10000;
|
||||
FileTimeToSystemTime((FILETIME*)¤tTime, time);
|
||||
}
|
||||
|
||||
@@ -156,12 +149,29 @@ void TimerInit() {
|
||||
|
||||
void SpeedPatch_Init() {
|
||||
if (GetConfigInt("Speed", "Enable", 0)) {
|
||||
modKey = GetConfigInt("Input", "SpeedModKey", 0);
|
||||
modKey[0] = GetConfigInt("Input", "SpeedModKey", 0);
|
||||
int init = GetConfigInt("Speed", "SpeedMultiInitial", 100);
|
||||
if (init == 100 && !modKey) return;
|
||||
if (init == 100 && !modKey[0]) return;
|
||||
|
||||
dlog("Applying speed patch.", DL_INIT);
|
||||
|
||||
switch (modKey[0]) {
|
||||
case -1:
|
||||
modKey[0] = DIK_LCONTROL;
|
||||
modKey[1] = DIK_RCONTROL;
|
||||
break;
|
||||
case -2:
|
||||
modKey[0] = DIK_LMENU;
|
||||
modKey[1] = DIK_RMENU;
|
||||
break;
|
||||
case -3:
|
||||
modKey[0] = DIK_LSHIFT;
|
||||
modKey[1] = DIK_RSHIFT;
|
||||
break;
|
||||
default:
|
||||
modKey[1] = 0;
|
||||
}
|
||||
|
||||
multi = (double)init / 100.0;
|
||||
toggleKey = GetConfigInt("Input", "SpeedToggleKey", 0);
|
||||
|
||||
|
||||
+1
-1
@@ -24,4 +24,4 @@ void SpeedPatch_Exit();
|
||||
extern DWORD getTickCountOffs;
|
||||
|
||||
// sfall implementation of the GetTickCount() function
|
||||
DWORD __stdcall SpeedPatch_getTickCount();
|
||||
DWORD SpeedPatch_getTickCount();
|
||||
|
||||
+4
-4
@@ -117,7 +117,7 @@ static void WorldMapFPS() {
|
||||
while (true) {
|
||||
tick = SpeedPatch_getTickCount();
|
||||
// get elapsed time
|
||||
if ((tick - prevTicks) >= 10) break; // delay 10 ms (GetTickCount returns a difference of 10-16 ms)
|
||||
if ((tick - prevTicks) >= 10) break; // delay 10 ms (GetTickCount returns a difference of 14-16 ms)
|
||||
}
|
||||
prevTicks = tick;
|
||||
|
||||
@@ -151,10 +151,10 @@ static void __declspec(naked) wmWorldMap_hook() {
|
||||
call ds:[getTickCountOffs]; // current ticks
|
||||
mov edx, eax;
|
||||
sub eax, worldMapTicks; // get elapsed time (cur.ticks - prev.ticks)
|
||||
cmp eax, 10; // delay 10 ms (GetTickCount returns a difference of 10-16 ms)
|
||||
cmp eax, 10; // delay 10 ms (GetTickCount returns a difference of 14-16 ms)
|
||||
jb skipHook;
|
||||
mov worldMapTicks, edx;
|
||||
call RunGlobalScripts3;
|
||||
call RunGlobalScripts3; // scripts are run every ~15 ms (not more often than 10 ms)
|
||||
skipHook:
|
||||
jmp get_input_;
|
||||
}
|
||||
@@ -353,7 +353,7 @@ static void WorldmapFpsPatch() {
|
||||
if (fpsPatchOK) {
|
||||
void* func;
|
||||
if (worldMapDelay == 0) {
|
||||
func = wmWorldMap_hook;
|
||||
func = wmWorldMap_hook; // only run world map scripts
|
||||
} else if (worldMapDelay > 25) {
|
||||
worldMapLongDelay = true;
|
||||
func = wmWorldMap_hook_patch1;
|
||||
|
||||
Reference in New Issue
Block a user