Skip to content

Commit

Permalink
0.12.1.0
Browse files Browse the repository at this point in the history
! Another GitHub Actions workflow file update

* Empty section names under "Patches" will no longer be parsed for a slight performance boost
* Changed how identical patch names are parsed: "signature" key values are not required to be non-empty at this point in case the data provided for "match", "preserve" and/or "original" are the same throughout different game subsections
  • Loading branch information
cravenge committed Dec 30, 2023
1 parent a28f45a commit 218a4f5
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 115 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ jobs:
with:
path: Source-Scramble
- name: Sort out Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.11'
python-version: '3.12'
- name: Put Python plug-in(s) in place
run: |
python -m pip install --upgrade pip wheel
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
python ../configure.py --enable-optimize --targets=${{ matrix.sptd_arch }} --sdks=none --mms-path="${{ github.workspace }}/metamod-${{ matrix.meta_version }}" --sm-path="${{ github.workspace }}/sourcemod-${{ matrix.sm_version }}"
ambuild
- name: Catalog all compiled files
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: srcscramble-sm${{ matrix.sm_version }}-${{ matrix.os_short }}-${{ env.GITHUB_SHA_SHORT }}
path: Source-Scramble/build/package
148 changes: 66 additions & 82 deletions natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ cell_t CreateMemoryPatchFromConf(IPluginContext* pContext, const cell_t* params)
const PatchGameConfig::PatchConf &patConf = r->value;

void* addr;
if( !gc->GetMemSig(patConf.signatureName.c_str(), reinterpret_cast< void** >( &addr )) || addr == nullptr )
return pContext->ThrowNativeError("Unable to find \"%s\" signature from \"%s\"", patConf.signatureName.c_str(), key);
if( patConf.signatureName.empty() )
return pContext->ThrowNativeError("\"%s\" has no signature", key);
else if( !gc->GetMemSig(patConf.signatureName.c_str(), reinterpret_cast< void** >( &addr )) || addr == nullptr )
return pContext->ThrowNativeError("Sigscan for \"%s\" from \"%s\" failed", patConf.signatureName.c_str(), key);

MemoryPatch* pMemoryPatch = new MemoryPatch( addr, patConf );
if( pMemoryPatch == nullptr )
Expand Down Expand Up @@ -240,7 +242,7 @@ cell_t EnableMemoryPatch(IPluginContext* pContext, const cell_t* params)
} else if( reinterpret_cast< uintptr_t >( pMemoryPatch->pAddr ) < 0x10000 ) {
return pContext->ThrowNativeError("Invalid address 0x%x is pointing to reserved memory", pMemoryPatch->pAddr);
} else if( !pMemoryPatch->overwrite.size() ) {
return pContext->ThrowNativeError("There are no bytes provided to replace the ones in the address");
return pContext->ThrowNativeError("Not even a single byte is provided for patching");
}

bool ret = pMemoryPatch->Enable();
Expand Down Expand Up @@ -296,7 +298,6 @@ cell_t GetMemoryPatchSize(IPluginContext* pContext, const cell_t* params)
} else if( !strcmp( key, "original" ) ) {
return static_cast< cell_t >( pMemoryPatch->original.size() );
}

return pContext->ThrowNativeError("Invalid patch data type \"%s\"", key);
}

Expand Down Expand Up @@ -354,47 +355,40 @@ cell_t GetMemoryPatchData(IPluginContext* pContext, const cell_t* params)
!= HandleError_None )
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err);

char* key;
pContext->LocalToString(params[2], &key);

size_t sz;
if( !strcmp( key, "match" ) ) {
sz = pMemoryPatch->match.size();
} else if( !strcmp( key, "preserve" ) ) {
sz = pMemoryPatch->preserve.size();
} else if( !strcmp( key, "overwrite" ) ) {
sz = pMemoryPatch->overwrite.size();
} else if( !strcmp( key, "original" ) ) {
sz = pMemoryPatch->original.size();
} else {
return pContext->ThrowNativeError("Invalid patch data type \"%s\"", key);
}

cell_t idx = params[3];
if( idx < 0 )
return pContext->ThrowNativeError("Invalid patch data index %d", idx);

char* key;
pContext->LocalToString(params[2], &key);
if( !strcmp( key, "match" ) ) {
if( !pMemoryPatch->match.size() ) {
return pContext->ThrowNativeError("No data in \"match\" is found");
} else if( idx >= pMemoryPatch->match.size() ) {
return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, pMemoryPatch->match.size());
}
if( !sz ) {
return pContext->ThrowNativeError("No data in \"%s\" is found", key);
} else if( idx >= sz ) {
return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, sz);
}

if( !strcmp( key, "match" ) ) {
return static_cast< cell_t >( pMemoryPatch->match[idx] );
} else if( !strcmp( key, "preserve" ) ) {
if( !pMemoryPatch->preserve.size() ) {
return pContext->ThrowNativeError("No data in \"preserve\" is found");
} else if( idx >= pMemoryPatch->preserve.size() ) {
return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, pMemoryPatch->preserve.size());
}

return static_cast< cell_t >( pMemoryPatch->preserve[idx] );
} else if( !strcmp( key, "overwrite" ) ) {
if( !pMemoryPatch->overwrite.size() ) {
return pContext->ThrowNativeError("No data in \"overwrite\" is found");
} else if( idx >= pMemoryPatch->overwrite.size() ) {
return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, pMemoryPatch->overwrite.size());
}

return static_cast< cell_t >( pMemoryPatch->overwrite[idx] );
} else if( !strcmp( key, "original" ) ) {
if( !pMemoryPatch->original.size() ) {
return pContext->ThrowNativeError("No data in \"original\" is found");
} else if( idx >= pMemoryPatch->original.size() ) {
return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, pMemoryPatch->original.size());
}

return static_cast< cell_t >( pMemoryPatch->original[idx] );
}

return pContext->ThrowNativeError("Invalid patch data type \"%s\"", key);
return static_cast< cell_t >( pMemoryPatch->original[idx] );
}

cell_t SetMemoryPatchData(IPluginContext* pContext, const cell_t* params)
Expand All @@ -413,70 +407,60 @@ cell_t SetMemoryPatchData(IPluginContext* pContext, const cell_t* params)
!= HandleError_None )
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", hndl, err);

char* key;
pContext->LocalToString(params[2], &key);

size_t sz;
if( !strcmp( key, "match" ) ) {
sz = pMemoryPatch->match.size();
} else if( !strcmp( key, "preserve" ) ) {
sz = pMemoryPatch->preserve.size();
} else if( !strcmp( key, "overwrite" ) ) {
sz = pMemoryPatch->overwrite.size();
} else if( !strcmp( key, "original" ) ) {
sz = pMemoryPatch->original.size();
} else {
return pContext->ThrowNativeError("Invalid patch data type \"%s\"", key);
}

cell_t idx = params[3];
if( idx < 0 )
return pContext->ThrowNativeError("Invalid patch data index %d", idx);

if( !sz ) {
return pContext->ThrowNativeError("No data in \"%s\" is found", key);
} else if( idx >= sz ) {
return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, sz);
}

cell_t val = params[4];
if( val < -255 || val > 255 )
return pContext->ThrowNativeError("Invalid patch data value %d", val);

if( val <= -129 )
val *= ( -1 );

char* key;
pContext->LocalToString(params[2], &key);
if( !strcmp( key, "match" ) ) {
if( !pMemoryPatch->match.size() ) {
return pContext->ThrowNativeError("No data in \"match\" is found");
} else if( idx >= pMemoryPatch->match.size() ) {
return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, pMemoryPatch->match.size());
}

if( val >= 128 )
if( val >= 128 )
if( !strcmp( key, "match" ) ) {
pMemoryPatch->match[idx] = val;
else
pMemoryPatch->match[idx] = static_cast< uint8_t >( val );
return 0;
} else if( !strcmp( key, "preserve" ) ) {
if( !pMemoryPatch->preserve.size() ) {
return pContext->ThrowNativeError("No data in \"preserve\" is found");
} else if( idx >= pMemoryPatch->preserve.size() ) {
return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, pMemoryPatch->preserve.size());
}

if( val >= 128 )
} else if( !strcmp( key, "preserve" ) ) {
pMemoryPatch->preserve[idx] = val;
else
pMemoryPatch->preserve[idx] = static_cast< uint8_t >( val );
return 0;
} else if( !strcmp( key, "overwrite" ) ) {
if( !pMemoryPatch->overwrite.size() ) {
return pContext->ThrowNativeError("No data in \"overwrite\" is found");
} else if( idx >= pMemoryPatch->overwrite.size() ) {
return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, pMemoryPatch->overwrite.size());
}

if( val >= 128 )
} else if( !strcmp( key, "overwrite" ) ) {
pMemoryPatch->overwrite[idx] = val;
else
pMemoryPatch->overwrite[idx] = static_cast< uint8_t >( val );
return 0;
} else if( !strcmp( key, "original" ) ) {
if( !pMemoryPatch->original.size() ) {
return pContext->ThrowNativeError("No data in \"original\" is found");
} else if( idx >= pMemoryPatch->original.size() ) {
return pContext->ThrowNativeError("Invalid index %d (count: %d)", idx, pMemoryPatch->original.size());
}

if( val >= 128 )
} else {
pMemoryPatch->original[idx] = val;
else
}
else
if( !strcmp( key, "match" ) ) {
pMemoryPatch->match[idx] = static_cast< uint8_t >( val );
} else if( !strcmp( key, "preserve" ) ) {
pMemoryPatch->preserve[idx] = static_cast< uint8_t >( val );
} else if( !strcmp( key, "overwrite" ) ) {
pMemoryPatch->overwrite[idx] = static_cast< uint8_t >( val );
} else {
pMemoryPatch->original[idx] = static_cast< uint8_t >( val );
return 0;
}

return pContext->ThrowNativeError("Invalid patch data type \"%s\"", key);
}
return 0;
}

cell_t GetMemoryPatchAddress(IPluginContext* pContext, const cell_t* params)
Expand Down
45 changes: 21 additions & 24 deletions patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#define PSTATE_GAMEDEFS_PATCHES 1
#define PSTATE_GAMEDEFS_PATCHES_PATCH 2
#define PSTATE_GAMEDEFS_PATCHES_PATCH_REPLACE 3
#define PSTATE_GAMEDEFS_PATCHES_PATCH_MATCH 3

#ifdef PLATFORM_X64
#define PLATFORM_ARCH_SUFFIX "64"
Expand Down Expand Up @@ -70,37 +70,36 @@ void PatchGameConfig::ReadSMC_ParseStart() {

SMCResult PatchGameConfig::ReadSMC_NewSection(const SMCStates *states, const char *name)
{
if( m_IgnoreLevel ) {
if( ( m_IgnoreLevel ) || ( !*name ) ) {
++m_IgnoreLevel;
return SMCResult_Continue;
}

if( m_ParseState == PSTATE_GAMEDEFS_PATCHES ) {
m_Patch = name;
if( !m_Patch.empty() ) {
StringHashMap< PatchConf >::Result r = m_Patches.find(name);
if( r.found() ) {
PatchConf &patConf = r->value;

m_PatchSignature = std::move( patConf.signatureName );
m_PatchOffset = patConf.offset;
m_PatchMatch = std::move( patConf.match );
m_PatchPreserve = std::move( patConf.preserve );
m_PatchOverwrite = std::move( patConf.overwrite );
m_PatchOneTime = patConf.onetime;
}

StringHashMap< PatchConf >::Result r = m_Patches.find(name);
if( r.found() ) {
PatchConf &patConf = r->value;

m_PatchSignature = std::move( patConf.signatureName );
m_PatchOffset = patConf.offset;
m_PatchMatch = std::move( patConf.match );
m_PatchPreserve = std::move( patConf.preserve );
m_PatchOverwrite = std::move( patConf.overwrite );
m_PatchOneTime = patConf.onetime;
}

m_ParseState = PSTATE_GAMEDEFS_PATCHES_PATCH;
} else if( m_ParseState == PSTATE_GAMEDEFS_PATCHES_PATCH ) {
if( DoesPlatformMatch( name ) ) {
m_ParseState = PSTATE_GAMEDEFS_PATCHES_PATCH_REPLACE;
m_ParseState = PSTATE_GAMEDEFS_PATCHES_PATCH_MATCH;
return SMCResult_Continue;
}

if( strcmp( name, "linux" ) && strcmp( name, "windows" ) && strcmp( name, "mac" ) &&
strcmp( name, "linux64") && strcmp( name, "windows64" ) && strcmp( name, "mac64" ) ) {
smutils->LogError(myself, "Error while parsing Patches section for \"%s\":", m_Patch.c_str());
smutils->LogError(myself, "Error while parsing Patch section for \"%s\":", m_Patch.c_str());
smutils->LogError(myself, "Unrecognized platform \"%s\"", name);
}

Expand All @@ -113,7 +112,8 @@ SMCResult PatchGameConfig::ReadSMC_NewSection(const SMCStates *states, const cha

SMCResult PatchGameConfig::ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value)
{
if( ( m_IgnoreLevel ) || ( ( m_ParseState != PSTATE_GAMEDEFS_PATCHES_PATCH ) && ( m_ParseState != PSTATE_GAMEDEFS_PATCHES_PATCH_REPLACE ) ) ) {
if( ( m_IgnoreLevel ) || ( ( m_ParseState != PSTATE_GAMEDEFS_PATCHES_PATCH ) && ( m_ParseState != PSTATE_GAMEDEFS_PATCHES_PATCH_MATCH ) ) || ( !*key ) ||
( !*value ) ) {
return SMCResult_Continue;
}

Expand Down Expand Up @@ -146,12 +146,8 @@ SMCResult PatchGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
}

if( m_ParseState == PSTATE_GAMEDEFS_PATCHES_PATCH ) {
if( ( !m_Patch.empty() ) && ( !m_PatchSignature.empty() ) ) {
PatchConf patConf( std::move( m_PatchSignature ), m_PatchOffset, std::move( m_PatchMatch ), std::move( m_PatchPreserve ), std::move( m_PatchOverwrite ), m_PatchOneTime );
m_Patches.replace(m_Patch.c_str(), patConf);

m_PatchSignature.clear();
}
PatchConf patConf( std::move( m_PatchSignature ), m_PatchOffset, std::move( m_PatchMatch ), std::move( m_PatchPreserve ), std::move( m_PatchOverwrite ), m_PatchOneTime );
m_Patches.replace(m_Patch.c_str(), patConf);

if( m_PatchOneTime )
m_PatchOneTime = false;
Expand All @@ -160,9 +156,10 @@ SMCResult PatchGameConfig::ReadSMC_LeavingSection(const SMCStates *states)
m_PatchMatch.clear();
if( m_PatchOffset )
m_PatchOffset = 0;
m_PatchSignature.clear();

m_ParseState = PSTATE_GAMEDEFS_PATCHES;
} else if( m_ParseState == PSTATE_GAMEDEFS_PATCHES_PATCH_REPLACE ) {
} else if( m_ParseState == PSTATE_GAMEDEFS_PATCHES_PATCH_MATCH ) {
m_ParseState = PSTATE_GAMEDEFS_PATCHES_PATCH;
}
return SMCResult_Continue;
Expand Down
2 changes: 1 addition & 1 deletion product.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.0
0.12.1
2 changes: 1 addition & 1 deletion smsdk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

#define SMEXT_CONF_NAME "Source Scramble"
#define SMEXT_CONF_DESCRIPTION "Presents more tools for developers to work with memory reallocations"
#define SMEXT_CONF_VERSION "0.12.0.0"
#define SMEXT_CONF_VERSION "0.12.1.0"
#define SMEXT_CONF_AUTHOR "nosoop | Updated by cravenge"
#define SMEXT_CONF_URL "https://github.com/cravenge/Source-Scramble"
#define SMEXT_CONF_LOGTAG "SRCSCRMBL"
Expand Down
8 changes: 4 additions & 4 deletions version.rc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,12,0,0
PRODUCTVERSION 0,12,0,0
FILEVERSION 0,12,1,0
PRODUCTVERSION 0,12,1,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -45,12 +45,12 @@ BEGIN
BEGIN
VALUE "Comments", "Source Scramble Extension"
VALUE "FileDescription", "SourceMod Source Scramble Extension"
VALUE "FileVersion", "0.12.0.0"
VALUE "FileVersion", "0.12.1.0"
VALUE "InternalName", "SourceMod Source Scramble Extension"
VALUE "LegalCopyright", "Copyright (c) 2019, nosoop"
VALUE "OriginalFilename", BINARY_NAME
VALUE "ProductName", "SourceMod Source Scramble Extension"
VALUE "ProductVersion", "0.12.0.0"
VALUE "ProductVersion", "0.12.1.0"
END
END
BLOCK "VarFileInfo"
Expand Down

0 comments on commit 218a4f5

Please sign in to comment.