Skip to content

Commit

Permalink
Fix indentation & clean warnings
Browse files Browse the repository at this point in the history
* All indentation now should be using tabs
* Clean up code to remove some minor compiler warnings
  • Loading branch information
Mooshua committed May 11, 2023
1 parent a4d4551 commit 81b8fdd
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 124 deletions.
55 changes: 29 additions & 26 deletions src/scripting/include/asm_patch.sp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ stock bool ByteOverflowCheck(const any[] list, int listsize)

stock void NoOpAddress(Address start, const char[] key, int size)
{
any[] originals = new any[size];
any[] originals = new any[size];

for(int i = 0;i<size;i++)
{
any byte = LoadFromAddress(start + Address:i, NumberType_Int8);
originals[i] = byte;
{
any byte = LoadFromAddress(start + Address:i, NumberType_Int8);
originals[i] = byte;
StoreToAddress(start + Address:i, 0x90, NumberType_Int8);
}
}

// "false" replace ensures we don't accidentally overwrite valid original with no-ops
Originals.SetArray(key, originals, size, false);
// "false" replace ensures we don't accidentally overwrite valid original with no-ops
Originals.SetArray(key, originals, size, false);
}

// Designed to patch the beginning of an instruction
Expand All @@ -59,12 +59,12 @@ stock void PatchAddressInstBegin(Address start, const char[] key, int size, cons
int noopSize = size - replacementSize;

for(int i = 0; i<noopSize; i++)
{
any byte = LoadFromAddress(start + Address:i, NumberType_Int8);
originals[i] = byte;
{
any byte = LoadFromAddress(start + Address:i, NumberType_Int8);
originals[i] = byte;
StoreToAddress(start + Address:i, 0x90, NumberType_Int8);
}
}

// Then, patch some bytes!
// These are very helpful comments, I know.
Expand All @@ -73,13 +73,13 @@ stock void PatchAddressInstBegin(Address start, const char[] key, int size, cons
for (int i = 0; i<replacementSize; i++)
{
any byte = LoadFromAddress(start + Address:i + Address:patchBegin, NumberType_Int8);
originals[i + patchBegin] = byte;
originals[i + patchBegin] = byte;
StoreToAddress(start + Address:i + Address:patchBegin, replacement[i], NumberType_Int8);
}

// "false" replace ensures we don't accidentally overwrite valid original with no-ops
Originals.SetArray(key, originals, size, false);
Originals.SetArray(key, originals, size, false);
}

// =============================================================
Expand All @@ -88,18 +88,18 @@ stock void PatchAddressInstBegin(Address start, const char[] key, int size, cons

stock void RestoreAddress(Address start, const char[] key, int size)
{
any[] originals = new any[size];
any[] originals = new any[size];

if (!Originals.GetArray(key, originals, size))
{
LogError("Unable to recover originals for no-op '%s'.", key);
if (!Originals.GetArray(key, originals, size))
{
LogError("Unable to recover originals for no-op '%s'.", key);
return;
}
}

for(int i = 0;i<size;i++)
{
for(int i = 0;i<size;i++)
{
StoreToAddress(start + Address:i, originals[i] , NumberType_Int8);
}
}
}

// =============================================================
Expand Down Expand Up @@ -156,7 +156,7 @@ stock void PatchFunction(GameData gamedata, const char[] name, const char[] size

stock void RecoverFunction(GameData gamedata, const char[] name, const char[] sizename)
{
Address Func = gamedata.GetAddress(name);
Address Func = gamedata.GetAddress(name);

if (Func == NULLPTR) {
LogError("Unable to find address for %s. Fix will not be reverted for that exploit.", name);
Expand Down Expand Up @@ -213,4 +213,7 @@ public Action Command_PatchStatus(int client, int argc)

ReplyToCommand(client, "[SourceForks Patches] Goodbye!");
return Plugin_Handled;
}
}

#undef BUFFER_SIZE
#undef NULLPTR
66 changes: 33 additions & 33 deletions src/scripting/include/asm_x86.sp
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,55 @@
// Jump Rel-8
enum JSHORT
{
// Overflow
JSHORT_NO = 0x70,
JSHORT_O = 0x71,
// Overflow
JSHORT_NO = 0x70,
JSHORT_O = 0x71,

// Carry
JSHORT_C = 0x72,
JSHORT_NC = 0x73,
// Carry
JSHORT_C = 0x72,
JSHORT_NC = 0x73,

// Zero
JSHORT_Z = 0x74,
JSHORT_NZ = 0x75,
// Zero
JSHORT_Z = 0x74,
JSHORT_NZ = 0x75,

// Below/Equal
JSHORT_BE = 0x76,
JSHORT_NBE = 0x77,
// Below/Equal
JSHORT_BE = 0x76,
JSHORT_NBE = 0x77,

// Sign
JSHORT_S = 0x78,
JSHORT_NS = 0x79,
// Sign
JSHORT_S = 0x78,
JSHORT_NS = 0x79,

// Parity
JSHORT_P = 0x7A,
JSHORT_NP = 0x7B,
// Parity
JSHORT_P = 0x7A,
JSHORT_NP = 0x7B,

// Less
JSHORT_L = 0x7C,
JSHORT_NL = 0x7D,
// Less
JSHORT_L = 0x7C,
JSHORT_NL = 0x7D,

// Less/Equal
JSHORT_LE = 0x7E,
JSHORT_NLE = 0x7F,
// Less/Equal
JSHORT_LE = 0x7E,
JSHORT_NLE = 0x7F,

// Greater (Alias)
JSHORT_G = JSHORT_NLE,
JSHORT_GE = JSHORT_NL,
// Greater (Alias)
JSHORT_G = JSHORT_NLE,
JSHORT_GE = JSHORT_NL,
};

enum PREFIX
{
PREFIX_OPERAND = 0x66,
PREFIX_ADDRESS = 0x67
PREFIX_OPERAND = 0x66,
PREFIX_ADDRESS = 0x67
};

enum PUSH
{
PUSH_IMM8 = 0x6A,
// Warning: Do not use without a prefix
PUSH_IMM16 = 0x68,
PUSH_IMM32 = 0x68
PUSH_IMM8 = 0x6A,
// Warning: Do not use without a prefix
PUSH_IMM16 = 0x68,
PUSH_IMM32 = 0x68
};

// Jump rel-16/32
Expand Down
64 changes: 32 additions & 32 deletions src/scripting/include/sdk_clients.sp
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,46 @@ Handle SDKCall_GetMsgHandler;

void SdkClients_Setup()
{
GameData Data = LoadGameConfigFile("sourceforks_sdk_clients");
GameData Data = LoadGameConfigFile("sourceforks_sdk_clients");

StartPrepSDKCall( SDKCall_Raw );
PrepSDKCall_SetFromConf( Data, SDKConf_Virtual, "CNetChan::GetMsgHandler" );
PrepSDKCall_SetReturnInfo( SDKType_PlainOldData, SDKPass_Plain );
SDKCall_GetMsgHandler = EndPrepSDKCall();
StartPrepSDKCall( SDKCall_Raw );
PrepSDKCall_SetFromConf( Data, SDKConf_Virtual, "CNetChan::GetMsgHandler" );
PrepSDKCall_SetReturnInfo( SDKType_PlainOldData, SDKPass_Plain );
SDKCall_GetMsgHandler = EndPrepSDKCall();

StartPrepSDKCall( SDKCall_Raw );
PrepSDKCall_SetFromConf( Data, SDKConf_Virtual, "CBaseClient::GetPlayerSlot" );
PrepSDKCall_SetReturnInfo( SDKType_PlainOldData, SDKPass_Plain );
SDKCall_GetPlayerSlot = EndPrepSDKCall();
StartPrepSDKCall( SDKCall_Raw );
PrepSDKCall_SetFromConf( Data, SDKConf_Virtual, "CBaseClient::GetPlayerSlot" );
PrepSDKCall_SetReturnInfo( SDKType_PlainOldData, SDKPass_Plain );
SDKCall_GetPlayerSlot = EndPrepSDKCall();

if (SDKCall_GetMsgHandler == INVALID_HANDLE)
SetFailState("[SourceForks SDK] Failed to initialize CNetChan::GetMsgHandler");
if (SDKCall_GetMsgHandler == INVALID_HANDLE)
SetFailState("[SourceForks SDK] Failed to initialize CNetChan::GetMsgHandler");

if (SDKCall_GetPlayerSlot == INVALID_HANDLE)
SetFailState("[SourceForks SDK] Failed to initialize CBaseClient::GetPlayerSlot");
if (SDKCall_GetPlayerSlot == INVALID_HANDLE)
SetFailState("[SourceForks SDK] Failed to initialize CBaseClient::GetPlayerSlot");
}

// From STAC. Thanks sappho!
// https://github.com/sapphonie/StAC-tf2/blob/fixup-oversights/scripting/stac/stac_memory.sp#L145-L168
bool SdkClients_GetClientFromNetChan(Address pThis, Address& IClient, int& client)
{
IClient = Address_Null;
client = -1;
// sanity check
if (!pThis)
{
return false;
}

IClient = SDKCall( SDKCall_GetMsgHandler, pThis );
// Clients will be null when connecting and disconnecting
if (!IClient)
{
return false;
}

// Client's ent index is always GetPlayerSlot() + 1
client = SDKCall(SDKCall_GetPlayerSlot, IClient) + 1;

return true;
IClient = Address_Null;
client = -1;
// sanity check
if (!pThis)
{
return false;
}

IClient = SDKCall( SDKCall_GetMsgHandler, pThis );
// Clients will be null when connecting and disconnecting
if (!IClient)
{
return false;
}

// Client's ent index is always GetPlayerSlot() + 1
client = SDKCall(SDKCall_GetPlayerSlot, IClient) + 1;

return true;
}
60 changes: 31 additions & 29 deletions src/scripting/include/sourceforks_admin_utils.sp
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,69 @@

#define BUFFER_SIZE 512

stock void PrintToAdmins(const char[] format, AdminFlag flags, ...)
stock void PrintToAdmins(const char[] format, int flags, ...)
{
char buffer[BUFFER_SIZE];
VFormat(buffer, sizeof(buffer), format, 3);

PrintToServer("[SourceForks Server]: %s", buffer);
PrintToServer("[SourceForks Server]: %s", buffer);

for (int admin = 1; admin < MAXPLAYERS; admin++)
{
if (!CheckCommandAccess(admin, "", int:flags, true))
if (!CheckCommandAccess(admin, "", flags, true))
continue;

PrintToChat(admin, "[SourceForks]: %s", buffer);
}
}

stock void CPrintToAdmins(const char[] in_format, AdminFlag flags, ...)
stock void CPrintToAdmins(const char[] in_format, int flags, ...)
{
char buffer[BUFFER_SIZE];
char format[BUFFER_SIZE];
char format[BUFFER_SIZE];

strcopy(format, sizeof(format), in_format);
// Consume buffer early to print to server
{
CRemoveTags(format, sizeof(format));
VFormat(buffer, sizeof(buffer), format, 3);
PrintToServer("[SourceForks Server]: %s", buffer);
}
strcopy(format, sizeof(format), in_format);
strcopy(format, sizeof(format), in_format);
// Consume buffer early to print to server
{
CRemoveTags(format, sizeof(format));
VFormat(buffer, sizeof(buffer), format, 3);
PrintToServer("[SourceForks Server]: %s", buffer);
}
strcopy(format, sizeof(format), in_format);

// Now do color formatting
{
CFormatColor(format, sizeof(format), -1);
VFormat(buffer, sizeof(buffer), format, 3);
}
// Now do color formatting
{
CFormatColor(format, sizeof(format), -1);
VFormat(buffer, sizeof(buffer), format, 3);
}
for (int admin = 1; admin < MAXPLAYERS; admin++)
{
if (!CheckCommandAccess(admin, "", int:flags, true))
if (!CheckCommandAccess(admin, "", flags, true))
continue;

PrintToChat(admin, "[SourceForks]: %s", buffer);
}
}

stock void CPrintToAdminsNoServer(const char[] in_format, AdminFlag flags, ...)
stock void CPrintToAdminsNoServer(const char[] in_format, int flags, ...)
{
char buffer[BUFFER_SIZE];
char format[BUFFER_SIZE];
char format[BUFFER_SIZE];

strcopy(format, sizeof(format), in_format);
strcopy(format, sizeof(format), in_format);

// Now do color formatting
{
CFormatColor(format, sizeof(format), -1);
VFormat(buffer, sizeof(buffer), format, 3);
}
// Now do color formatting
{
CFormatColor(format, sizeof(format), -1);
VFormat(buffer, sizeof(buffer), format, 3);
}
for (int admin = 1; admin < MAXPLAYERS; admin++)
{
if (!CheckCommandAccess(admin, "", int:flags, true))
if (!CheckCommandAccess(admin, "", flags, true))
continue;

PrintToChat(admin, "[SourceForks]: %s", buffer);
}
}
}

#undef BUFFER_SIZE
Loading

0 comments on commit 81b8fdd

Please sign in to comment.