Skip to content

Commit

Permalink
1.4.0
Browse files Browse the repository at this point in the history
Improved performance
  • Loading branch information
accelerator74 committed May 7, 2024
1 parent de0316c commit d1809a7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ jobs:
- name: Uploading package
uses: actions/upload-artifact@v4
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

release:
Expand Down
103 changes: 47 additions & 56 deletions extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,24 @@ SMEXT_LINK(&g_Cleaner);

CDetour *g_pDetour = 0;

vector<string> szStrings;
unordered_set<string> szStrings;

#if SOURCE_ENGINE >= SE_LEFT4DEAD2
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)
{
// 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
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);
}
DETOUR_DECL_MEMBER4(Detour_LogDirect, LoggingResponse_t, LoggingChannelID_t, channelID, LoggingSeverity_t, severity, Color, color, const tchar *, pMessage)
{
if (szStrings.find(pMessage) != szStrings.end())
return LR_CONTINUE;

return DETOUR_MEMBER_CALL(Detour_LogDirect)(channelID, severity, color, pMessage);
}
#else
DETOUR_DECL_STATIC2(Detour_DefSpew, SpewRetval_t, SpewType_t, channel, char *, text)
{
for (int i = 0; i < szStrings.size(); ++i)
{
// 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
if (szStrings[i].length() >= 2 && strstr(text, szStrings[i].c_str()) != 0)
{
return SPEW_CONTINUE;
}
}
return DETOUR_STATIC_CALL(Detour_DefSpew)(channel, text);
}
DETOUR_DECL_STATIC2(Detour_DefSpew, SpewRetval_t, SpewType_t, channel, char *, text)
{
if (szStrings.find(text) != szStrings.end())
return SPEW_CONTINUE;

return DETOUR_STATIC_CALL(Detour_DefSpew)(channel, text);
}
#endif

// https://stackoverflow.com/questions/10178700/c-strip-non-ascii-characters-from-string
Expand Down Expand Up @@ -73,47 +61,50 @@ bool Cleaner::SDK_OnLoad(char *error, size_t maxlength, bool late)
stripBadChars(line);

// 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
{
szStrings.push_back(line);
rootconsole->ConsolePrint("[CLEANER] Not stripping string on -> L%i with 1 or less length! Length: %i", counter, line.length());
}

counter++;
}

rootconsole->ConsolePrint("[CLEANER] %i strings added from cleaner.cfg", szStrings.size());
cleanerConfig.close();

// init our detours
#if SOURCE_ENGINE >= SE_LEFT4DEAD2
#ifdef PLATFORM_WINDOWS
HMODULE tier0 = GetModuleHandle(TIER0_NAME);
void * fn = memutils->FindPattern(tier0, SIG_WINDOWS, SIG_WIN_SIZE);
#elif defined PLATFORM_LINUX
void * tier0 = dlopen(TIER0_NAME, RTLD_NOW);
void * fn = memutils->ResolveSymbol(tier0, SIG_LINUX);
dlclose(tier0);
#else
#error "Unsupported OS"
#endif

if (!fn)
{
rootconsole->ConsolePrint("[CLEANER] Failed to find signature. Please contact the author.");
return false;
}
#if defined SIG_LINUX_OFFSET
#ifdef PLATFORM_LINUX
fn = (void *)((intptr_t)fn + SIG_LINUX_OFFSET);
#endif
#endif
g_pDetour = DETOUR_CREATE_MEMBER(Detour_LogDirect, fn);
#else
g_pDetour = DETOUR_CREATE_STATIC(Detour_DefSpew, (gpointer)GetSpewOutputFunc());
#endif
#if SOURCE_ENGINE >= SE_LEFT4DEAD2
#ifdef PLATFORM_WINDOWS
HMODULE tier0 = GetModuleHandle(TIER0_NAME);
void * fn = memutils->FindPattern(tier0, SIG_WINDOWS, SIG_WIN_SIZE);
#elif defined PLATFORM_LINUX
void * tier0 = dlopen(TIER0_NAME, RTLD_NOW);
void * fn = memutils->ResolveSymbol(tier0, SIG_LINUX);
dlclose(tier0);
#else
#error "Unsupported OS"
#endif

if (!fn)
{
rootconsole->ConsolePrint("[CLEANER] Failed to find signature. Please contact the author.");
return false;
}

#if defined SIG_LINUX_OFFSET
#ifdef PLATFORM_LINUX
fn = (void *)((intptr_t)fn + SIG_LINUX_OFFSET);
#endif
#endif

g_pDetour = DETOUR_CREATE_MEMBER(Detour_LogDirect, fn);
#else
g_pDetour = DETOUR_CREATE_STATIC(Detour_DefSpew, (gpointer)GetSpewOutputFunc());
#endif

if (g_pDetour == NULL)
{
Expand Down
2 changes: 1 addition & 1 deletion extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include <string>
#include <iostream>
#include <cctype>
#include <vector>
#include <unordered_set>
#include <fstream>


Expand Down
2 changes: 1 addition & 1 deletion smsdk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/* Basic information exposed publicly */
#define SMEXT_CONF_NAME "Console Cleaner"
#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_URL "https://github.com/Accelerator74/Cleaner"
#define SMEXT_CONF_LOGTAG "Cleaner"
Expand Down

0 comments on commit d1809a7

Please sign in to comment.