Skip to content

Commit

Permalink
Merge pull request #393 from KZGlobalTeam/dev
Browse files Browse the repository at this point in the history
GOKZ v3.4.1
  • Loading branch information
zealain authored Oct 23, 2022
2 parents 928b433 + bba9eef commit 0ffc0b4
Show file tree
Hide file tree
Showing 13 changed files with 276 additions and 229 deletions.
18 changes: 1 addition & 17 deletions addons/sourcemod/gamedata/gokz-momsurffix.games.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,6 @@
"CTraceFilterSimple::size" "16"
}

"Addresses"
{
"CGameMovement::TryPlayerMove_Start"
{
"windows"
{
"signature" "CGameMovement::TryPlayerMove"
}
"linux"
{
"signature" "CGameMovement::TryPlayerMove"
}
"offset" "0"
}
}

"Offsets"
{
"OSType"
Expand Down Expand Up @@ -340,7 +324,7 @@
"windows"
{
"signature" "CGameMovement::TryPlayerMove"
"read" "700"
"read" "718"
}
"linux"
{
Expand Down
7 changes: 7 additions & 0 deletions addons/sourcemod/scripting/gokz-core.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/gokz-global/send_run.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 13 additions & 5 deletions addons/sourcemod/scripting/gokz-jumpstats/jump_tracking.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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))
Expand All @@ -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;
}

Expand Down
120 changes: 38 additions & 82 deletions addons/sourcemod/scripting/gokz-momsurffix.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -100,7 +107,6 @@ public void OnPluginStart()
InitGameMovement(gd);

SetupDhooks(gd);
SetupASMOptimizations(gd);

delete gd;
}
Expand Down Expand Up @@ -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<OSType>(gd.GetOffset("OSType"));
Expand Down Expand Up @@ -345,7 +309,13 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace
VectorCopy(view_as<float>({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++)
Expand Down Expand Up @@ -413,7 +383,6 @@ int TryPlayerMove(CGameMovement pThis, Vector pFirstDest, CGameTrace pFirstTrace
}
}
}
ray.Free();

if(valid_planes != 0 && !CloseEnough(valid_plane, view_as<float>({0.0, 0.0, 0.0})))
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<int>(data), type);
}
}
Loading

0 comments on commit 0ffc0b4

Please sign in to comment.