Improved performance
This commit is contained in:
Accelerator 2024-05-07 18:10:12 +03:00
parent de0316c500
commit d1809a7085
4 changed files with 49 additions and 58 deletions

View File

@ -142,7 +142,7 @@ jobs:
- name: Uploading package - name: Uploading package
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: with:
name: ${{ github.event.repository.name }}-${{ matrix.sm_version }}-${{ matrix.os_short }} name: ${{ github.event.repository.name }}-${{ matrix.os_short }}-${{ env.GITHUB_SHA_SHORT }}
path: src/build/package path: src/build/package
release: release:

View File

@ -10,36 +10,24 @@ SMEXT_LINK(&g_Cleaner);
CDetour *g_pDetour = 0; CDetour *g_pDetour = 0;
vector<string> szStrings; unordered_set<string> szStrings;
#if SOURCE_ENGINE >= SE_LEFT4DEAD2 #if SOURCE_ENGINE >= SE_LEFT4DEAD2
DETOUR_DECL_MEMBER4(Detour_LogDirect, LoggingResponse_t, LoggingChannelID_t, channelID, LoggingSeverity_t, severity, Color, color, const tchar *, pMessage) DETOUR_DECL_MEMBER4(Detour_LogDirect, LoggingResponse_t, LoggingChannelID_t, channelID, LoggingSeverity_t, severity, Color, color, const tchar *, pMessage)
{ {
for (int i = 0; i < szStrings.size(); ++i) if (szStrings.find(pMessage) != szStrings.end())
{ return LR_CONTINUE;
// make sure we're stripping at least 2 or more chars just in case we accidentally inhale a \0
// also there's no reason to strip a single char ever return DETOUR_MEMBER_CALL(Detour_LogDirect)(channelID, severity, color, pMessage);
if (szStrings[i].length() >= 2 && strstr(pMessage, szStrings[i].c_str()) != 0) }
{
return LR_CONTINUE;
}
}
return DETOUR_MEMBER_CALL(Detour_LogDirect)(channelID, severity, color, pMessage);
}
#else #else
DETOUR_DECL_STATIC2(Detour_DefSpew, SpewRetval_t, SpewType_t, channel, char *, text) DETOUR_DECL_STATIC2(Detour_DefSpew, SpewRetval_t, SpewType_t, channel, char *, text)
{ {
for (int i = 0; i < szStrings.size(); ++i) if (szStrings.find(text) != szStrings.end())
{ return SPEW_CONTINUE;
// make sure we're stripping at least 2 or more chars just in case we accidentally inhale a \0
// also there's no reason to strip a single char ever return DETOUR_STATIC_CALL(Detour_DefSpew)(channel, text);
if (szStrings[i].length() >= 2 && strstr(text, szStrings[i].c_str()) != 0) }
{
return SPEW_CONTINUE;
}
}
return DETOUR_STATIC_CALL(Detour_DefSpew)(channel, text);
}
#endif #endif
// https://stackoverflow.com/questions/10178700/c-strip-non-ascii-characters-from-string // https://stackoverflow.com/questions/10178700/c-strip-non-ascii-characters-from-string
@ -73,47 +61,50 @@ bool Cleaner::SDK_OnLoad(char *error, size_t maxlength, bool late)
stripBadChars(line); stripBadChars(line);
// don't strip tiny (including 1 len or less) strings // don't strip tiny (including 1 len or less) strings
if (line.length() < 1) if (line.length() >= 2)
{ {
rootconsole->ConsolePrint("[CLEANER] Not stripping string on -> L%i with 1 or less length! Length: %i", counter, line.length()); szStrings.insert(line);
} }
else else
{ {
szStrings.push_back(line); rootconsole->ConsolePrint("[CLEANER] Not stripping string on -> L%i with 1 or less length! Length: %i", counter, line.length());
} }
counter++; counter++;
} }
rootconsole->ConsolePrint("[CLEANER] %i strings added from cleaner.cfg", szStrings.size()); rootconsole->ConsolePrint("[CLEANER] %i strings added from cleaner.cfg", szStrings.size());
cleanerConfig.close(); cleanerConfig.close();
// init our detours // init our detours
#if SOURCE_ENGINE >= SE_LEFT4DEAD2 #if SOURCE_ENGINE >= SE_LEFT4DEAD2
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
HMODULE tier0 = GetModuleHandle(TIER0_NAME); HMODULE tier0 = GetModuleHandle(TIER0_NAME);
void * fn = memutils->FindPattern(tier0, SIG_WINDOWS, SIG_WIN_SIZE); void * fn = memutils->FindPattern(tier0, SIG_WINDOWS, SIG_WIN_SIZE);
#elif defined PLATFORM_LINUX #elif defined PLATFORM_LINUX
void * tier0 = dlopen(TIER0_NAME, RTLD_NOW); void * tier0 = dlopen(TIER0_NAME, RTLD_NOW);
void * fn = memutils->ResolveSymbol(tier0, SIG_LINUX); void * fn = memutils->ResolveSymbol(tier0, SIG_LINUX);
dlclose(tier0); dlclose(tier0);
#else #else
#error "Unsupported OS" #error "Unsupported OS"
#endif #endif
if (!fn) if (!fn)
{ {
rootconsole->ConsolePrint("[CLEANER] Failed to find signature. Please contact the author."); rootconsole->ConsolePrint("[CLEANER] Failed to find signature. Please contact the author.");
return false; return false;
} }
#if defined SIG_LINUX_OFFSET
#ifdef PLATFORM_LINUX #if defined SIG_LINUX_OFFSET
fn = (void *)((intptr_t)fn + SIG_LINUX_OFFSET); #ifdef PLATFORM_LINUX
#endif fn = (void *)((intptr_t)fn + SIG_LINUX_OFFSET);
#endif #endif
g_pDetour = DETOUR_CREATE_MEMBER(Detour_LogDirect, fn); #endif
#else
g_pDetour = DETOUR_CREATE_STATIC(Detour_DefSpew, (gpointer)GetSpewOutputFunc()); g_pDetour = DETOUR_CREATE_MEMBER(Detour_LogDirect, fn);
#endif #else
g_pDetour = DETOUR_CREATE_STATIC(Detour_DefSpew, (gpointer)GetSpewOutputFunc());
#endif
if (g_pDetour == NULL) if (g_pDetour == NULL)
{ {

View File

@ -47,7 +47,7 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <cctype> #include <cctype>
#include <vector> #include <unordered_set>
#include <fstream> #include <fstream>

View File

@ -40,7 +40,7 @@
/* Basic information exposed publicly */ /* Basic information exposed publicly */
#define SMEXT_CONF_NAME "Console Cleaner" #define SMEXT_CONF_NAME "Console Cleaner"
#define SMEXT_CONF_DESCRIPTION "Console warning suppressor" #define SMEXT_CONF_DESCRIPTION "Console warning suppressor"
#define SMEXT_CONF_VERSION "1.3.1" #define SMEXT_CONF_VERSION "1.4.0"
#define SMEXT_CONF_AUTHOR "Accelerator, Zephyrus" #define SMEXT_CONF_AUTHOR "Accelerator, Zephyrus"
#define SMEXT_CONF_URL "https://github.com/Accelerator74/Cleaner" #define SMEXT_CONF_URL "https://github.com/Accelerator74/Cleaner"
#define SMEXT_CONF_LOGTAG "Cleaner" #define SMEXT_CONF_LOGTAG "Cleaner"