diff --git a/addons/sourcemod/gamedata/gokz-momsurffix.games.txt b/addons/sourcemod/gamedata/gokz-momsurffix.games.txt index b160484e..43f797c4 100644 --- a/addons/sourcemod/gamedata/gokz-momsurffix.games.txt +++ b/addons/sourcemod/gamedata/gokz-momsurffix.games.txt @@ -47,22 +47,6 @@ "CTraceFilterSimple::size" "16" } - "Addresses" - { - "CGameMovement::TryPlayerMove_Start" - { - "windows" - { - "signature" "CGameMovement::TryPlayerMove" - } - "linux" - { - "signature" "CGameMovement::TryPlayerMove" - } - "offset" "0" - } - } - "Offsets" { "OSType" @@ -340,7 +324,7 @@ "windows" { "signature" "CGameMovement::TryPlayerMove" - "read" "700" + "read" "718" } "linux" { diff --git a/addons/sourcemod/scripting/gokz-core.sp b/addons/sourcemod/scripting/gokz-core.sp index 05596759..aaa1cd7b 100644 --- a/addons/sourcemod/scripting/gokz-core.sp +++ b/addons/sourcemod/scripting/gokz-core.sp @@ -384,6 +384,13 @@ public Action OnNormalSound(int clients[MAXPLAYERS], int &numClients, char sampl public void OnEntityCreated(int entity, const char[] classname) { + // Don't react to player related entities + if (StrEqual(classname, "predicted_viewmodel") || StrEqual(classname, "item_assaultsuit") + || StrEqual(classname, "cs_bot") || StrEqual(classname, "player") + || StrContains(classname, "weapon") != -1) + { + return; + } SDKHook(entity, SDKHook_Spawn, OnEntitySpawned); SDKHook(entity, SDKHook_SpawnPost, OnEntitySpawnedPost); OnEntityCreated_Triggerfix(entity, classname); diff --git a/addons/sourcemod/scripting/gokz-global/send_run.sp b/addons/sourcemod/scripting/gokz-global/send_run.sp index e098d072..f560958f 100644 --- a/addons/sourcemod/scripting/gokz-global/send_run.sp +++ b/addons/sourcemod/scripting/gokz-global/send_run.sp @@ -121,7 +121,7 @@ bool IsReplayReadyToSend(int client, int course, int timeType, float time) public void SendReplay(int client) { - DataPack dp; + DataPack dp = new DataPack(); dp.WriteString(deleteRecord[client] ? storedReplayPath[client] : ""); GlobalAPI_CreateReplayForRecordId(SendReplayCallback, dp, lastRecordId[client], storedReplayPath[client]); lastRecordId[client] = -1; diff --git a/addons/sourcemod/scripting/gokz-jumpstats/jump_tracking.sp b/addons/sourcemod/scripting/gokz-jumpstats/jump_tracking.sp index 6b290aaf..27d3a037 100644 --- a/addons/sourcemod/scripting/gokz-jumpstats/jump_tracking.sp +++ b/addons/sourcemod/scripting/gokz-jumpstats/jump_tracking.sp @@ -94,7 +94,7 @@ enum struct JumpTracker // We need to do that before we reset the jump cause we need the // offset and type of the previous jump this.lastType = this.DetermineType(jumped, ladderJump, jumpbug); - + // We need this for weirdjump w-release int releaseWTemp = this.jump.releaseW; @@ -151,10 +151,10 @@ enum struct JumpTracker We check for speed reduction for abuse; while prop abuses increase speed, wall collision will very likely (if not always) result in a speed reduction. */ - float actualSpeed = GetVectorHorizontalDistance(this.position, pose(-1).position) * 128; + float actualSpeed = GetVectorHorizontalDistance(this.position, pose(-1).position) / GetTickInterval(); if (FloatAbs(speed - actualSpeed) > JS_SPEED_MODIFICATION_TOLERANCE && this.jump.duration != 0) { - if (actualSpeed <= pose(-1).speed) + if (actualSpeed <= pose(-1).speed) { pose(0).speed = actualSpeed; } @@ -164,7 +164,13 @@ enum struct JumpTracker this.Invalidate(); } } - + // You shouldn't gain any vertical velocity during a jump. + // This would only happen if you get boosted back up somehow, or you edgebugged. + if (!Movement_GetOnGround(this.jumper) && pose(0).velocity[2] > pose(-1).velocity[2]) + { + this.Invalidate(); + } + this.jump.height = FloatMax(this.jump.height, this.position[2] - this.takeoffOrigin[2]); this.jump.maxSpeed = FloatMax(this.jump.maxSpeed, speed); this.jump.crouchTicks += Movement_GetDucking(this.jumper) ? 1 : 0; @@ -965,7 +971,7 @@ enum struct JumpTracker endBlock[coordDev] = middle[coordDev]; startBlock[2] = middle[2]; endBlock[2] = middle[2]; - + // Search for the blocks if (!TraceHullPosition(middle, startBlock, sweepBoxMin, sweepBoxMax, startBlock) || !TraceHullPosition(middle, endBlock, sweepBoxMin, sweepBoxMax, endBlock)) @@ -976,6 +982,8 @@ enum struct JumpTracker // Make sure the edges of the blocks are parallel. if (!this.BlockAreEdgesParallel(startBlock, endBlock, this.jump.deviation + 32.0, coordDist, coordDev)) { + this.jump.block = 0; + this.jump.edge = -1.0; return; } diff --git a/addons/sourcemod/scripting/gokz-momsurffix.sp b/addons/sourcemod/scripting/gokz-momsurffix.sp index b6ed0837..ddfad1c5 100644 --- a/addons/sourcemod/scripting/gokz-momsurffix.sp +++ b/addons/sourcemod/scripting/gokz-momsurffix.sp @@ -37,9 +37,11 @@ enum OSType OSType gOSType; EngineVersion gEngineVersion; -#define CUSTOM_ASSERTION_FAILSTATE -#define FAILSTATE_FUNC SetFailStateCustom +#define ASSERTUTILS_FAILSTATE_FUNC SetFailStateCustom +#define MEMUTILS_PLUGINENDCALL #include "glib/memutils" +#undef MEMUTILS_PLUGINENDCALL + #include "momsurffix/utils.sp" #include "momsurffix/baseplayer.sp" #include "momsurffix/gametrace.sp" @@ -50,22 +52,27 @@ ConVar gBounce; float vec3_origin[3] = {0.0, 0.0, 0.0}; bool gBasePlayerLoadedTooEarly; -PatchHandler gASMPatch; -Handle gStoreToAddressFast; -Address gTryPlayerMoveStart; - #if defined DEBUG_PROFILE #include "profiler" -#define PROF_START() if(gProf) gProf.Start() -#define PROF_STOP(%1)%2; if(gProf)\ -{\ - gProf.Stop();\ - Prof_Check(%1);\ -} - Profiler gProf; ArrayList gProfData; float gProfTime; + +void PROF_START() +{ + if(gProf) + gProf.Start(); +} + +void PROF_STOP(int idx) +{ + if(gProf) + { + gProf.Stop(); + Prof_Check(idx); + } +} + #else #define PROF_START%1; #define PROF_STOP%1; @@ -100,7 +107,6 @@ public void OnPluginStart() InitGameMovement(gd); SetupDhooks(gd); - SetupASMOptimizations(gd); delete gd; } @@ -190,48 +196,6 @@ public Action Prof_Check_Timer(Handle timer, int client) } #endif -void SetupASMOptimizations(GameData gd) -{ - //CGameMovement::TryPlayerMove_Start - gTryPlayerMoveStart = gd.GetAddress("CGameMovement::TryPlayerMove_Start"); - ASSERT_MSG(gTryPlayerMoveStart, "Can't find start of the \"CGameMovement::TryPlayerMove\" function."); - - gASMPatch = PatchHandler(gTryPlayerMoveStart + ASM_START_OFFSET); - gASMPatch.Save(ASM_PATCH_LEN); - - Address start = gASMPatch.Address; - - /*StoreToAddressFast asm: - * push ebp - * mov ebp, esp - * - * mov eax, [ebp + 12] - * mov ecx, [ebp + 8] - * mov [ecx], eax - * - * mov esp, ebp - * pop ebp - * ret 8 - */ - - StoreToAddress(start, 0x8B_EC_8B_55, NumberType_Int32); - StoreToAddress(start + 4, 0x4D_8B_0C_45, NumberType_Int32); - StoreToAddress(start + 8, 0x8B_01_89_08, NumberType_Int32); - StoreToAddress(start + 12, 0x08_C2_5D_E5, NumberType_Int32); - StoreToAddress(start + 16, 0x00, NumberType_Int8); - - //StoreToAddressFast - StartPrepSDKCall(SDKCall_Static); - - PrepSDKCall_SetAddress(start); - PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); - PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); - PrepSDKCall_SetReturnInfo(SDKType_PlainOldData, SDKPass_Plain); - - gStoreToAddressFast = EndPrepSDKCall(); - ASSERT(gStoreToAddressFast); -} - void ValidateGameAndOS(GameData gd) { gOSType = view_as(gd.GetOffset("OSType")); @@ -345,7 +309,13 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace VectorCopy(view_as({0.0, 0.0, 0.0}), valid_plane); float offset[3], offset_mins[3], offset_maxs[3], buff[3]; - Ray_t ray = Ray_t(); + static Ray_t ray; + + // Keep this variable allocated only once + // since ray.Init should take care of removing any left garbage values + if(ray.Address == Address_Null) + ray = Ray_t(); + for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) @@ -413,7 +383,6 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace } } } - ray.Free(); if(valid_planes != 0 && !CloseEnough(valid_plane, view_as({0.0, 0.0, 0.0}))) { @@ -669,12 +638,20 @@ stock bool CloseEnoughFloat(float a, float b, float eps = FLT_EPSILON) public void SetFailStateCustom(const char[] fmt, any ...) { - char buff[ASSERT_FMT_STRING_LEN]; + char buff[512]; VFormat(buff, sizeof(buff), fmt, 2); CleanUpUtils(); - SetFailState(buff); + char ostype[32]; + switch(gOSType) + { + case OSLinux: ostype = "LIN"; + case OSWindows: ostype = "WIN"; + default: ostype = "UNK"; + } + + SetFailState("[%s | %i] %s", ostype, gEngineVersion, buff); } // 0-2 are axial planes @@ -706,7 +683,7 @@ stock bool IsValidMovementTrace(CGameMovement pThis, CGameTrace tr) CGameTrace stuck = CGameTrace(); - TracePlayerBBox(pThis, tr.endpos, tr.endpos, MASK_PLAYERSOLID, COLLISION_GROUP_PLAYER_MOVEMENT, stuck) + TracePlayerBBox(pThis, tr.endpos, tr.endpos, MASK_PLAYERSOLID, COLLISION_GROUP_PLAYER_MOVEMENT, stuck); if(stuck.startsolid || !CloseEnoughFloat(stuck.fraction, 1.0)) { stuck.Free(); @@ -742,25 +719,4 @@ stock void UTIL_TraceRay(Ray_t ray, int mask, CGameMovement gm, int collisionGro filter.Free(); } -} - -//Faster then native StoreToAddress by ~45 times. -stock void StoreToAddressFast(Address addr, any data) -{ - ASSERT(gStoreToAddressFast); - - int ret = SDKCall(gStoreToAddressFast, addr, data); - ASSERT(ret == data); -} - -stock void StoreToAddressCustom(Address addr, any data, NumberType type) -{ - if (gStoreToAddressFast && type == NumberType_Int32) - { - StoreToAddressFast(addr, data); - } - else - { - StoreToAddress(addr, view_as(data), type); - } } \ No newline at end of file diff --git a/addons/sourcemod/scripting/gokz-saveloc.sp b/addons/sourcemod/scripting/gokz-saveloc.sp index 820ead46..111e3fe9 100644 --- a/addons/sourcemod/scripting/gokz-saveloc.sp +++ b/addons/sourcemod/scripting/gokz-saveloc.sp @@ -23,7 +23,7 @@ public Plugin myinfo = }; #define UPDATER_URL GOKZ_UPDATER_BASE_URL..."gokz-saveloc.txt" - +#define LOADLOC_INVALIDATE_DURATION 1.0 #define MAX_LOCATION_NAME_LENGTH 32 enum struct Location { @@ -58,6 +58,7 @@ enum struct Location { float waterJumpTime; bool hasWalkMovedSinceLastJump; float ignoreLadderJumpTimeOffset; + float lastPositionAtFullCrouchSpeed[2]; void Create(int client, int target) { @@ -81,7 +82,8 @@ enum struct Location { this.waterJumpTime = GetEntPropFloat(target, Prop_Data, "m_flWaterJumpTime"); this.hasWalkMovedSinceLastJump = !!GetEntProp(target, Prop_Data, "m_bHasWalkMovedSinceLastJump"); this.ignoreLadderJumpTimeOffset = GetEntPropFloat(target, Prop_Data, "m_ignoreLadderJumpTime") - GetGameTime(); - + GetLastPositionAtFullCrouchSpeed(target, this.lastPositionAtFullCrouchSpeed); + if (GOKZ_GetTimerRunning(target)) { this.currentTime = GOKZ_GetTime(target); @@ -134,6 +136,7 @@ enum struct Location { SetEntPropFloat(client, Prop_Data, "m_flWaterJumpTime", this.waterJumpTime); SetEntProp(client, Prop_Data, "m_bHasWalkMovedSinceLastJump", this.hasWalkMovedSinceLastJump); SetEntPropFloat(client, Prop_Data, "m_ignoreLadderJumpTime", this.ignoreLadderJumpTimeOffset + GetGameTime()); + SetLastPositionAtFullCrouchSpeed(client, this.lastPositionAtFullCrouchSpeed); GOKZ_InvalidateRun(client); return true; @@ -144,6 +147,7 @@ ArrayList gA_Locations; bool gB_LocMenuOpen[MAXPLAYERS + 1]; bool gB_UsedLoc[MAXPLAYERS + 1]; int gI_MostRecentLocation[MAXPLAYERS + 1]; +float gF_LastLoadlocTime[MAXPLAYERS + 1]; bool gB_GOKZHUD; @@ -197,6 +201,11 @@ public void OnMapStart() // =====[ CLIENT EVENTS ]===== +public void OnClientPutInServer(int client) +{ + gF_LastLoadlocTime[client] = 0.0; +} + public void OnPlayerDeath(Event event, const char[] name, bool dontBroadcast) { int client = GetClientOfUserId(event.GetInt("userid")); @@ -219,6 +228,10 @@ public Action GOKZ_OnTimerStart(int client, int course) { CloseLocMenu(client); gB_UsedLoc[client] = false; + if (GetGameTime() < gF_LastLoadlocTime[client] + LOADLOC_INVALIDATE_DURATION) + { + return Plugin_Stop; + } return Plugin_Continue; } @@ -344,7 +357,10 @@ public Action Command_LoadLoc(int client, int args) if (IsValidLocationId(id)) { - LoadLocation(client, id); + if (LoadLocation(client, id)) + { + gF_LastLoadlocTime[client] = GetGameTime(); + } } else { @@ -742,6 +758,21 @@ bool IsClientLocationCreator(int client, int id) return StrEqual(clientName, loc.locationCreator); } +void GetLastPositionAtFullCrouchSpeed(int client, float origin[2]) +{ + // m_vecLastPositionAtFullCrouchSpeed is right after m_flDuckSpeed. + int baseOffset = FindSendPropInfo("CBasePlayer", "m_flDuckSpeed"); + origin[0] = GetEntDataFloat(client, baseOffset + 4); + origin[1] = GetEntDataFloat(client, baseOffset + 8); +} + +void SetLastPositionAtFullCrouchSpeed(int client, float origin[2]) +{ + int baseOffset = FindSendPropInfo("CBasePlayer", "m_flDuckSpeed"); + SetEntDataFloat(client, baseOffset + 4, origin[0]); + SetEntDataFloat(client, baseOffset + 8, origin[1]); +} + // ====[ PRIVATE ]==== static void PrintEndTimeString_SaveLoc(int client, int course, float time) @@ -788,4 +819,4 @@ static void PrintEndTimeString_SaveLoc(int client, int course, float time) } } } -} \ No newline at end of file +} diff --git a/addons/sourcemod/scripting/include/glib/addressutils.inc b/addons/sourcemod/scripting/include/glib/addressutils.inc new file mode 100644 index 00000000..bbe8f149 --- /dev/null +++ b/addons/sourcemod/scripting/include/glib/addressutils.inc @@ -0,0 +1,54 @@ +#if defined _addressutils_included +#endinput +#endif +#define _addressutils_included + +methodmap AddressBase +{ + property Address Address + { + public get() { return view_as
(this); } + } +} + +//-==Operator overloadings +stock Address operator+(Address l, int r) +{ + return l + view_as
(r); +} + +stock Address operator+(int l, Address r) +{ + return view_as
(l) + r; +} + +stock Address operator-(Address l, int r) +{ + return l - view_as
(r); +} + +stock Address operator-(int l, Address r) +{ + return view_as
(l) - r; +} + +stock Address operator*(Address l, int r) +{ + return l * view_as
(r); +} + +stock Address operator*(int l, Address r) +{ + return view_as
(l) * r; +} + +stock Address operator/(Address l, int r) +{ + return l / view_as
(r); +} + +stock Address operator/(int l, Address r) +{ + return view_as
(l) / r; +} +//Operator overloadings==- \ No newline at end of file diff --git a/addons/sourcemod/scripting/include/glib/assertutils.inc b/addons/sourcemod/scripting/include/glib/assertutils.inc new file mode 100644 index 00000000..83cd90d9 --- /dev/null +++ b/addons/sourcemod/scripting/include/glib/assertutils.inc @@ -0,0 +1,61 @@ +#if defined _assertutils_included +#endinput +#endif +#define _assertutils_included + +/* Compile time settings for this include. Should be defined before including this file. +* #define ASSERTUTILS_DISABLE //Disables all assertions +* #define ASSERTUTILS_FAILSTATE_FUNC //Define the name of the function that should be called when assertion is hit +*/ + +#if !defined SNAME +#define __SNAME "" +#else +#define __SNAME SNAME +#endif + +#define ASSERT_FMT_STRING_LEN 512 + +#if defined ASSERTUTILS_DISABLE + +#define ASSERT(%1)%2; +#define ASSERT_MSG(%1,%2)%3; +#define ASSERT_FMT(%1,%2)%3; +#define ASSERT_FINAL(%1)%2; +#define ASSERT_FINAL_MSG(%1,%2)%3; + +#elseif defined ASSERTUTILS_FAILSTATE_FUNC + +#define ASSERT(%1) if(!(%1)) ASSERTUTILS_FAILSTATE_FUNC(__SNAME..."Assertion failed: \""...#%1..."\"") +#define ASSERT_MSG(%1,%2) if(!(%1)) ASSERTUTILS_FAILSTATE_FUNC(__SNAME...%2) +#define ASSERT_FMT(%1,%2) if(!(%1)) ASSERTUTILS_FAILSTATE_FUNC(__SNAME...%2) +#define ASSERT_FINAL(%1) if(!(%1)) SetFailState(__SNAME..."Assertion failed: \""...#%1..."\"") +#define ASSERT_FINAL_MSG(%1,%2) if(!(%1)) SetFailState(__SNAME...%2) + +#else + +#define ASSERT(%1) if(!(%1)) SetFailState(__SNAME..."Assertion failed: \""...#%1..."\"") +#define ASSERT_MSG(%1,%2) if(!(%1)) SetFailState(__SNAME...%2) +#define ASSERT_FMT(%1,%2) if(!(%1)) SetFailState(__SNAME...%2) +#define ASSERT_FINAL(%1) ASSERT(%1) +#define ASSERT_FINAL_MSG(%1,%2) ASSERT_MSG(%1,%2) + +#endif + +// Might be redundant as default ASSERT_MSG accept format arguments just fine. +#if 0 +stock void ASSERT_FMT(bool result, char[] fmt, any ...) +{ +#if !defined ASSERTUTILS_DISABLE + if(!result) + { + char buff[ASSERT_FMT_STRING_LEN]; + VFormat(buff, sizeof(buff), fmt, 3); + + SetFailState(__SNAME..."%s", buff); + } +#endif +} +#endif + +#undef ASSERT_FMT_STRING_LEN \ No newline at end of file diff --git a/addons/sourcemod/scripting/include/glib/memutils.inc b/addons/sourcemod/scripting/include/glib/memutils.inc index 6ee5d0c1..5813d927 100644 --- a/addons/sourcemod/scripting/include/glib/memutils.inc +++ b/addons/sourcemod/scripting/include/glib/memutils.inc @@ -3,94 +3,19 @@ #endif #define _memutils_included -#if !defined SNAME -#define __SNAME "" -#else -#define __SNAME SNAME -#endif - -#define MEM_LEN_SAFE_THRESHOLD 2000 - -//-==ASSERTS -#define ASSERT_FMT_STRING_LEN 512 +#include "glib/assertutils" +#include "glib/addressutils" -#if defined DISABLE_ASSERTION -#define ASSERT(%1)%2; -#define ASSERT_MSG(%1,%2)%3; -#define ASSERT_FINAL(%1)%2; -#define ASSERT_FINAL_MSG(%1,%2)%3; -#elseif defined CUSTOM_ASSERTION_FAILSTATE && defined FAILSTATE_FUNC -#define ASSERT(%1) if(!(%1)) FAILSTATE_FUNC(__SNAME..."Assertion failed: \""...#%1..."\"") -#define ASSERT_MSG(%1,%2) if(!(%1)) FAILSTATE_FUNC(__SNAME...%2) -#define ASSERT_FINAL(%1) if(!(%1)) SetFailState(__SNAME..."Assertion failed: \""...#%1..."\"") -#define ASSERT_FINAL_MSG(%1,%2) if(!(%1)) SetFailState(__SNAME...%2) -#else -#define ASSERT(%1) if(!(%1)) SetFailState(__SNAME..."Assertion failed: \""...#%1..."\"") -#define ASSERT_MSG(%1,%2) if(!(%1)) SetFailState(__SNAME...%2) -#define ASSERT_FINAL(%1) ASSERT(%1) -#define ASSERT_FINAL_MSG(%1,%2) ASSERT_MSG(%1,%2) -#endif - -stock void ASSERT_FMT(bool result, char[] fmt, any ...) -{ -#if !defined DISABLE_ASSERTION - if(!result) - { - char buff[ASSERT_FMT_STRING_LEN]; - VFormat(buff, sizeof(buff), fmt, 3); - - SetFailState(__SNAME..."%s", buff); - } -#endif -} -//ASSERS END==- - -//-==Operator overloadings -stock Address operator+(Address l, int r) -{ - return l + view_as
(r); -} +/* Compile time settings for this include. Should be defined before including this file. +* #define MEMUTILS_PLUGINENDCALL //This should be defined if main plugin has OnPluginEnd() forward used. +*/ -stock Address operator+(int l, Address r) -{ - return view_as
(l) + r; -} - -stock Address operator-(Address l, int r) -{ - return l - view_as
(r); -} - -stock Address operator-(int l, Address r) -{ - return view_as
(l) - r; -} - -stock Address operator*(Address l, int r) -{ - return l * view_as
(r); -} - -stock Address operator*(int l, Address r) -{ - return view_as
(l) * r; -} - -stock Address operator/(Address l, int r) -{ - return l / view_as
(r); -} - -stock Address operator/(int l, Address r) -{ - return view_as
(l) / r; -} -//Operator overloadings==- +#define MEM_LEN_SAFE_THRESHOLD 2000 //-==PatchHandling methodmap static StringMap gPatchStack; -methodmap PatchHandler +methodmap PatchHandler < AddressBase { public PatchHandler(Address addr) { @@ -102,11 +27,6 @@ methodmap PatchHandler return view_as(addr); } - property Address Address - { - public get() { return view_as
(this); } - } - property any Any { public get() { return view_as(this); } @@ -151,6 +71,27 @@ methodmap PatchHandler gPatchStack.SetArray(buff, arr, len); } + public void PatchNSaveSeq(const char[] data, int len) + { + ASSERT(gPatchStack); + ASSERT(len > 0 && len < MEM_LEN_SAFE_THRESHOLD); + + len++; + + int[] arr = new int[len]; + arr[0] = len; + + for(int i = 0; i < len - 1; i++) + { + arr[i + 1] = LoadFromAddress(this.Address + i, NumberType_Int8); + StoreToAddress(this.Address + i, data[i], NumberType_Int8); + } + + char buff[32]; + IntToString(this.Any, buff, sizeof(buff)); + gPatchStack.SetArray(buff, arr, len); + } + public void Restore() { if(!gPatchStack) @@ -191,15 +132,28 @@ public void OnPluginEnd() } } -#if !defined MEMUTILS_NOPLENDCALL +#if defined MEMUTILS_PLUGINENDCALL OnPluginEnd_MemUtilsRedefined(); #endif } #undef OnPluginEnd +#if defined MEMUTILS_PLUGINENDCALL #define OnPluginEnd OnPluginEnd_MemUtilsRedefined +#else +#define OnPluginEnd OnPluginEnd_Redifined(){}\ +void MEMUTILS_INCLUDE_WARNING_OnPluginEnd_REDIFINITION +#endif //PatchHandling methodmap==- //-==Other util functions +stock int LoadStringFromAddress(Address addr, char[] buff, int length) +{ + int i; + for(i = 0; i < length && (buff[i] = LoadFromAddress(addr + i, NumberType_Int8)) != '\0'; i++) { } + buff[i == length ? i - 1 : i] = '\0'; + return i; +} + stock void DumpOnAddress(Address addr, int len, int columns = 10) { char buff[128], buff2[128]; diff --git a/addons/sourcemod/scripting/momsurffix/baseplayer.sp b/addons/sourcemod/scripting/momsurffix/baseplayer.sp index f2f79cf9..c638773e 100644 --- a/addons/sourcemod/scripting/momsurffix/baseplayer.sp +++ b/addons/sourcemod/scripting/momsurffix/baseplayer.sp @@ -119,7 +119,7 @@ stock bool InitBasePlayer(GameData gd) { //g_pEntityList g_pEntityList = view_as(gd.GetAddress("g_pEntityList")); - ASSERT_MSG(g_pEntityList.Address != Address_Null, "Can't get \"g_pEntityList\" address from gamedata."); + ASSERT_MSG(g_pEntityList.Address != Address_Null, "Can't get \"g_pEntityList\" address from gamedata. Gamedata needs an update."); //CBaseEntityList ASSERT_FMT(gd.GetKeyValue("CBaseEntityList::m_EntPtrArray", buff, sizeof(buff)), "Can't get \"CBaseEntityList::m_EntPtrArray\" offset from gamedata."); diff --git a/addons/sourcemod/scripting/momsurffix/gamemovement.sp b/addons/sourcemod/scripting/momsurffix/gamemovement.sp index 9fd8ed8c..a51beebe 100644 --- a/addons/sourcemod/scripting/momsurffix/gamemovement.sp +++ b/addons/sourcemod/scripting/momsurffix/gamemovement.sp @@ -67,7 +67,7 @@ methodmap CGameMovement < AddressBase property int m_nTraceCount { public get() { return LoadFromAddress(this.Address + offsets.cgmoffsets.m_nTraceCount, NumberType_Int32); } - public set(int _tracecount) { StoreToAddressCustom(this.Address + offsets.cgmoffsets.m_nTraceCount, _tracecount, NumberType_Int32); } + public set(int _tracecount) { StoreToAddress(this.Address + offsets.cgmoffsets.m_nTraceCount, _tracecount, NumberType_Int32, false); } } } @@ -146,7 +146,7 @@ stock void InitGameMovement(GameData gd) { //sm_pSingleton sm_pSingleton = view_as(gd.GetAddress("sm_pSingleton")); - ASSERT_MSG(sm_pSingleton.Address != Address_Null, "Can't get \"sm_pSingleton\" address from gamedata."); + ASSERT_MSG(sm_pSingleton.Address != Address_Null, "Can't get \"sm_pSingleton\" address from gamedata. Gamedata needs an update."); } else { @@ -155,8 +155,8 @@ stock void InitGameMovement(GameData gd) //CMoveHelperServer::CMoveHelperServer Handle dhook = DHookCreateDetour(Address_Null, CallConv_CDECL, ReturnType_Int, ThisPointer_Ignore); - ASSERT_MSG(DHookSetFromConf(dhook, gd, SDKConf_Signature, "CMoveHelperServer::CMoveHelperServer"), "Failed to get \"CMoveHelperServer::CMoveHelperServer\" signature."); - DHookAddParam(dhook, HookParamType_Int, .flag = DHookPass_ByRef); + ASSERT_MSG(DHookSetFromConf(dhook, gd, SDKConf_Signature, "CMoveHelperServer::CMoveHelperServer"), "Failed to get \"CMoveHelperServer::CMoveHelperServer\" signature. Gamedata needs an update."); + DHookAddParam(dhook, HookParamType_Int); DHookEnableDetour(dhook, true, CMoveHelperServer_Dhook); } @@ -214,7 +214,7 @@ stock void InitGameMovement(GameData gd) //ClipVelocity StartPrepSDKCall(SDKCall_Static); - ASSERT_MSG(PrepSDKCall_SetFromConf(gd, SDKConf_Signature, "CGameMovement::ClipVelocity"), "Failed to get \"CGameMovement::ClipVelocity\" signature."); + ASSERT_MSG(PrepSDKCall_SetFromConf(gd, SDKConf_Signature, "CGameMovement::ClipVelocity"), "Failed to get \"CGameMovement::ClipVelocity\" signature. Gamedata needs an update."); PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); @@ -258,7 +258,7 @@ stock void InitGameMovement(GameData gd) //GetPlayerMins StartPrepSDKCall(SDKCall_Static); - ASSERT_MSG(PrepSDKCall_SetFromConf(gd, SDKConf_Signature, "CGameMovement::GetPlayerMins"), "Failed to get \"CGameMovement::GetPlayerMins\" signature."); + ASSERT_MSG(PrepSDKCall_SetFromConf(gd, SDKConf_Signature, "CGameMovement::GetPlayerMins"), "Failed to get \"CGameMovement::GetPlayerMins\" signature. Gamedata needs an update."); PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); @@ -269,7 +269,7 @@ stock void InitGameMovement(GameData gd) //GetPlayerMaxs StartPrepSDKCall(SDKCall_Static); - ASSERT_MSG(PrepSDKCall_SetFromConf(gd, SDKConf_Signature, "CGameMovement::GetPlayerMaxs"), "Failed to get \"CGameMovement::GetPlayerMaxs\" signature."); + ASSERT_MSG(PrepSDKCall_SetFromConf(gd, SDKConf_Signature, "CGameMovement::GetPlayerMaxs"), "Failed to get \"CGameMovement::GetPlayerMaxs\" signature. Gamedata needs an update."); PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); @@ -301,7 +301,7 @@ public MRESReturn CMoveHelperServer_Dhook(Handle hReturn, Handle hParams) GameData gd = new GameData(GAME_DATA_FILE); sm_pSingleton = view_as(gd.GetAddress("sm_pSingleton")); - ASSERT_MSG(sm_pSingleton.Address != Address_Null, "Can't get \"sm_pSingleton\" address from gamedata."); + ASSERT_MSG(sm_pSingleton.Address != Address_Null, "Can't get \"sm_pSingleton\" address from gamedata. Gamedata needs an update."); delete gd; } diff --git a/addons/sourcemod/scripting/momsurffix/gametrace.sp b/addons/sourcemod/scripting/momsurffix/gametrace.sp index a72bc1af..25d7892a 100644 --- a/addons/sourcemod/scripting/momsurffix/gametrace.sp +++ b/addons/sourcemod/scripting/momsurffix/gametrace.sp @@ -220,19 +220,19 @@ methodmap Ray_t < AllocatableBase property Address m_pWorldAxisTransform { public get() { return view_as
(LoadFromAddress(this.Address + offsets.rtoffsets.m_pWorldAxisTransform, NumberType_Int32)); } - public set(Address _worldaxistransform) { StoreToAddressCustom(this.Address + offsets.rtoffsets.m_pWorldAxisTransform, view_as(_worldaxistransform), NumberType_Int32); } + public set(Address _worldaxistransform) { StoreToAddress(this.Address + offsets.rtoffsets.m_pWorldAxisTransform, view_as(_worldaxistransform), NumberType_Int32, false); } } property bool m_IsRay { public get() { return view_as(LoadFromAddress(this.Address + offsets.rtoffsets.m_IsRay, NumberType_Int8)); } - public set(bool _isray) { StoreToAddressCustom(this.Address + offsets.rtoffsets.m_IsRay, _isray, NumberType_Int8); } + public set(bool _isray) { StoreToAddress(this.Address + offsets.rtoffsets.m_IsRay, _isray, NumberType_Int8, false); } } property bool m_IsSwept { public get() { return view_as(LoadFromAddress(this.Address + offsets.rtoffsets.m_IsSwept, NumberType_Int8)); } - public set(bool _isswept) { StoreToAddressCustom(this.Address + offsets.rtoffsets.m_IsSwept, _isswept, NumberType_Int8); } + public set(bool _isswept) { StoreToAddress(this.Address + offsets.rtoffsets.m_IsSwept, _isswept, NumberType_Int8, false); } } public Ray_t() @@ -279,25 +279,25 @@ methodmap CTraceFilterSimple < AllocatableBase property Address vptr { public get() { return view_as
(LoadFromAddress(this.Address + offsets.ctfsoffsets.vptr, NumberType_Int32)); } - public set(Address _vtbladdr) { StoreToAddressCustom(this.Address + offsets.ctfsoffsets.vptr, view_as(_vtbladdr), NumberType_Int32); } + public set(Address _vtbladdr) { StoreToAddress(this.Address + offsets.ctfsoffsets.vptr, view_as(_vtbladdr), NumberType_Int32, false); } } property CBaseHandle m_pPassEnt { public get() { return view_as(LoadFromAddress(this.Address + offsets.ctfsoffsets.m_pPassEnt, NumberType_Int32)); } - public set(CBaseHandle _passent) { StoreToAddressCustom(this.Address + offsets.ctfsoffsets.m_pPassEnt, view_as(_passent), NumberType_Int32); } + public set(CBaseHandle _passent) { StoreToAddress(this.Address + offsets.ctfsoffsets.m_pPassEnt, view_as(_passent), NumberType_Int32, false); } } property int m_collisionGroup { public get() { return LoadFromAddress(this.Address + offsets.ctfsoffsets.m_collisionGroup, NumberType_Int32); } - public set(int _collisiongroup) { StoreToAddressCustom(this.Address + offsets.ctfsoffsets.m_collisionGroup, _collisiongroup, NumberType_Int32); } + public set(int _collisiongroup) { StoreToAddress(this.Address + offsets.ctfsoffsets.m_collisionGroup, _collisiongroup, NumberType_Int32, false); } } property Address m_pExtraShouldHitCheckFunction { public get() { return view_as
(LoadFromAddress(this.Address + offsets.ctfsoffsets.m_pExtraShouldHitCheckFunction, NumberType_Int32)); } - public set(Address _checkfnc) { StoreToAddressCustom(this.Address + offsets.ctfsoffsets.m_pExtraShouldHitCheckFunction, view_as(_checkfnc), NumberType_Int32); } + public set(Address _checkfnc) { StoreToAddress(this.Address + offsets.ctfsoffsets.m_pExtraShouldHitCheckFunction, view_as(_checkfnc), NumberType_Int32), false; } } public CTraceFilterSimple() @@ -421,7 +421,7 @@ stock void InitGameTrace(GameData gd) if(gEngineVersion == Engine_CSS) { offsets.ctfsoffsets.vtable = gd.GetAddress("CTraceFilterSimple::vtable"); - ASSERT_MSG(offsets.ctfsoffsets.vtable != Address_Null, "Can't get \"CTraceFilterSimple::vtable\" address from gamedata."); + ASSERT_MSG(offsets.ctfsoffsets.vtable != Address_Null, "Can't get \"CTraceFilterSimple::vtable\" address from gamedata. Gamedata needs an update."); } //enginetrace diff --git a/addons/sourcemod/scripting/momsurffix/utils.sp b/addons/sourcemod/scripting/momsurffix/utils.sp index 3ce2cc79..e68e342b 100644 --- a/addons/sourcemod/scripting/momsurffix/utils.sp +++ b/addons/sourcemod/scripting/momsurffix/utils.sp @@ -7,14 +7,6 @@ enum struct MemoryPoolEntry char name[MEMORYPOOL_NAME_MAX]; } -methodmap AddressBase -{ - property Address Address - { - public get() { return view_as
(this); } - } -} - methodmap AllocatableBase < AddressBase { public static Address _malloc(int size, const char[] name) @@ -71,19 +63,19 @@ methodmap Vector < AllocatableBase property float x { - public set(float _x) { StoreToAddressCustom(this.Address, view_as(_x), NumberType_Int32); } + public set(float _x) { StoreToAddress(this.Address, view_as(_x), NumberType_Int32, false); } public get() { return view_as(LoadFromAddress(this.Address, NumberType_Int32)); } } property float y { - public set(float _y) { StoreToAddressCustom(this.Address + 4, view_as(_y), NumberType_Int32); } + public set(float _y) { StoreToAddress(this.Address + 4, view_as(_y), NumberType_Int32, false); } public get() { return view_as(LoadFromAddress(this.Address + 4, NumberType_Int32)); } } property float z { - public set(float _z) { StoreToAddressCustom(this.Address + 8, view_as(_z), NumberType_Int32); } + public set(float _z) { StoreToAddress(this.Address + 8, view_as(_z), NumberType_Int32, false); } public get() { return view_as(LoadFromAddress(this.Address + 8, NumberType_Int32)); } } @@ -135,7 +127,7 @@ stock void InitUtils(GameData gd) //CreateInterface StartPrepSDKCall(SDKCall_Static); - ASSERT_MSG(PrepSDKCall_SetFromConf(gd, SDKConf_Signature, "CreateInterface"), "Failed to get \"CreateInterface\" signature."); + ASSERT_MSG(PrepSDKCall_SetFromConf(gd, SDKConf_Signature, "CreateInterface"), "Failed to get \"CreateInterface\" signature. Gamedata needs an update."); PrepSDKCall_AddParameter(SDKType_String, SDKPass_Pointer); PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); @@ -149,7 +141,7 @@ stock void InitUtils(GameData gd) { //g_pMemAlloc g_pMemAlloc = gd.GetAddress("g_pMemAlloc"); - ASSERT_MSG(g_pMemAlloc != Address_Null, "Can't get \"g_pMemAlloc\" address from gamedata."); + ASSERT_MSG(g_pMemAlloc != Address_Null, "Can't get \"g_pMemAlloc\" address from gamedata. Gamedata needs an update."); //Malloc StartPrepSDKCall(SDKCall_Raw); @@ -176,7 +168,7 @@ stock void InitUtils(GameData gd) { //Malloc StartPrepSDKCall(SDKCall_Static); - ASSERT_MSG(PrepSDKCall_SetFromConf(gd, SDKConf_Signature, "malloc"), "Failed to get \"malloc\" signature."); + ASSERT_MSG(PrepSDKCall_SetFromConf(gd, SDKConf_Signature, "malloc"), "Failed to get \"malloc\" signature. Gamedata needs an update."); PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); @@ -188,7 +180,7 @@ stock void InitUtils(GameData gd) //Free StartPrepSDKCall(SDKCall_Static); - ASSERT_MSG(PrepSDKCall_SetFromConf(gd, SDKConf_Signature, "free"), "Failed to get \"free\" signature."); + ASSERT_MSG(PrepSDKCall_SetFromConf(gd, SDKConf_Signature, "free"), "Failed to get \"free\" signature. Gamedata needs an update."); PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain); PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);