Skip to content

Commit baab29d

Browse files
authored
Merge pull request server-imp#10 from Evasion3356/ModernizeThread
Modernized everModded thread.
2 parents 2b122f9 + 9b33151 commit baab29d

File tree

5 files changed

+19
-30
lines changed

5 files changed

+19
-30
lines changed

cfg.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#pragma once
2-
#ifndef _CFG
3-
#define _CFG
42
#include "pch.h"
5-
#include "log.h";
3+
#include "log.h"
64
#include "util.h"
75

86
namespace cfg
@@ -314,6 +312,4 @@ namespace cfg
314312
_properties.push_back(prop);
315313
}
316314
};
317-
}
318-
319-
#endif
315+
}

log.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace logging
2424
fprintf(logfile, "[%s] [%s] %02d:%02d:%02d ", HEADER, tag, local_time->tm_hour, local_time->tm_min, local_time->tm_sec);
2525

2626
va_list args;
27-
va_start(args, _fmt);
27+
va_start(args, fmt);
2828

2929
vprintf(_fmt, args);
3030
vfprintf(logfile, _fmt, args);
@@ -49,7 +49,7 @@ namespace logging
4949
logfile = fopen(LOG_FILE, "w+");
5050

5151
va_list args;
52-
va_start(args, _fmt);
52+
va_start(args, fmt);
5353

5454
vprintf(_fmt, args);
5555
vfprintf(logfile, _fmt, args);

memory.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ namespace memory
239239
}
240240
else
241241
{
242-
bytes.push_back(strtoul(i, &i, 16));
242+
bytes.push_back(static_cast<uint8_t>(strtoul(i, &i, 16)));
243243
mask.push_back(1);
244244
}
245245
}
@@ -312,7 +312,9 @@ namespace memory
312312
}
313313

314314
if (closestMatch)
315+
{
315316
dbg("Failed to find pattern, closest match is 0x%p [%d/%d]", closestMatch, closestMatchCount, bytes.size());
317+
}
316318

317319
return false;
318320
}
@@ -536,7 +538,7 @@ namespace memory
536538
if (pattern::find(pattern.pattern, &pointer, moduleName))
537539
{
538540
valid = true;
539-
pointer = pointer.add(pattern.offset);
541+
pointer = pointer.add(static_cast<int32_t>(pattern.offset));
540542
break;
541543
}
542544
}

sfae.h

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -252,26 +252,20 @@ public:\
252252
if (pointers::everModded.raw())
253253
{
254254
// enter an infinite loop to monitor everModded for the duration of game session
255-
// should run about 200 times per second
256-
255+
// should run about 10 times per second
257256
info("Monitoring \"Ever Modded\"");
258-
CreateThread(nullptr, 0, [](PVOID) -> DWORD
257+
std::thread([] {
258+
auto ptr = pointers::everModded.as<uint8_t*>();
259+
while (true)
259260
{
260-
auto ptr = pointers::everModded.as<uint8_t*>();
261-
while (true)
261+
if (*ptr != 0)
262262
{
263-
264-
// if everModded is not 0, change it back to 0
265-
if (*ptr != 0)
266-
{
267-
*ptr = 0;
268-
269-
info("Blocked \"Ever Modded\" Change");
270-
}
271-
272-
std::this_thread::sleep_for(5ms);
263+
*ptr = 0;
264+
info("Blocked \"Ever Modded\" Change");
273265
}
274-
}, 0, 0, 0);
266+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
267+
}
268+
}).detach(); // Detach to allow independent execution
275269
}
276270

277271
if (settings.getEnableASILoader())

util.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ namespace util
105105
fs::remove(filePath);
106106
return true;
107107
}
108-
catch (const std::exception& ex)
109-
{
110-
;
111-
}
108+
catch (const std::exception&) {}
112109
}
113110

114111
return false;

0 commit comments

Comments
 (0)