Skip to content

Commit

Permalink
Merge pull request #304 from KZGlobalTeam/dev
Browse files Browse the repository at this point in the history
3.2.1
  • Loading branch information
zealain authored Apr 3, 2022
2 parents 7f98d4b + a22ea4e commit bcaf8f3
Show file tree
Hide file tree
Showing 18 changed files with 508 additions and 158 deletions.
6 changes: 6 additions & 0 deletions addons/sourcemod/scripting/gokz-core.sp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ public void OnMapStart()
OnMapStart_FixMissingSpawns();
OnMapStart_Checkpoints();
OnMapStart_TeamNumber();
OnMapStart_Demofix();
}

public void OnMapEnd()
{
OnMapEnd_Demofix();
}

public void OnGameFrame()
Expand Down
22 changes: 22 additions & 0 deletions addons/sourcemod/scripting/gokz-core/demofix.sp
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
static ConVar CV_EnableDemofix;
static Handle H_DemofixTimer;
static bool mapRunning;

void OnPluginStart_Demofix()
{
AddCommandListener(Command_Demorestart, "demorestart");
CV_EnableDemofix = AutoExecConfig_CreateConVar("gokz_demofix", "1", "Whether GOKZ applies demo record fix to server. (0 = Disabled, 1 = Update warmup period once, 2 = Regularly reset warmup period)", _, true, 0.0, true, 2.0);
CV_EnableDemofix.AddChangeHook(OnDemofixConVarChanged);
// If the map is tweaking the warmup value, we need to rerun the fix again.
FindConVar("mp_warmuptime").AddChangeHook(OnDemofixConVarChanged);
// We assume that the map is already loaded on late load.
if (gB_LateLoad)
{
mapRunning = true;
}
}

void OnMapStart_Demofix()
{
mapRunning = true;
}

void OnMapEnd_Demofix()
{
mapRunning = false;
}

void OnRoundStart_Demofix()
Expand Down Expand Up @@ -76,6 +94,10 @@ static void EnableDemoRecord()
{
// Enable warmup to allow demo recording
// m_fWarmupPeriodEnd is set in the past to hide the timer UI
if (!mapRunning)
{
return;
}
GameRules_SetProp("m_bWarmupPeriod", 1);
GameRules_SetPropFloat("m_fWarmupPeriodStart", GetGameTime() - 1.0);
GameRules_SetPropFloat("m_fWarmupPeriodEnd", GetGameTime() - 1.0);
Expand Down
52 changes: 32 additions & 20 deletions addons/sourcemod/scripting/gokz-core/misc.sp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void ToggleNoclip(int client)

void EnableNoclip(int client)
{
if (IsPlayerAlive(client))
if (IsValidClient(client) && IsPlayerAlive(client))
{
Movement_SetMovetype(client, MOVETYPE_NOCLIP);
GOKZ_StopTimer(client);
Expand All @@ -61,7 +61,7 @@ void EnableNoclip(int client)

void DisableNoclip(int client)
{
if (IsPlayerAlive(client) && Movement_GetMovetype(client) == MOVETYPE_NOCLIP)
if (IsValidClient(client) && IsPlayerAlive(client) && Movement_GetMovetype(client) == MOVETYPE_NOCLIP)
{
noclipReleaseTime[client] = GetGameTickCount();
Movement_SetMovetype(client, MOVETYPE_WALK);
Expand All @@ -86,7 +86,7 @@ void ToggleNoclipNotrigger(int client)

void EnableNoclipNotrigger(int client)
{
if (IsPlayerAlive(client))
if (IsValidClient(client) && IsPlayerAlive(client))
{
Movement_SetMovetype(client, MOVETYPE_NOCLIP);
SetEntProp(client, Prop_Send, "m_CollisionGroup", GOKZ_COLLISION_GROUP_NOTRIGGER);
Expand All @@ -96,7 +96,7 @@ void EnableNoclipNotrigger(int client)

void DisableNoclipNotrigger(int client)
{
if (IsPlayerAlive(client) && Movement_GetMovetype(client) == MOVETYPE_NOCLIP)
if (IsValidClient(client) && IsPlayerAlive(client) && Movement_GetMovetype(client) == MOVETYPE_NOCLIP)
{
noclipReleaseTime[client] = GetGameTickCount();
Movement_SetMovetype(client, MOVETYPE_WALK);
Expand Down Expand Up @@ -211,15 +211,29 @@ static bool savedOnLadder[MAXPLAYERS + 1];

void OnClientPutInServer_JoinTeam(int client)
{
// After OnClientPutInServer, player is moved to the origin of a point_viewcontrol entity.
// We need to wait one tick before assign the player's team and teleport them to a valid spawn.
if (!IsFakeClient(client))
{
RequestFrame(AutoJoinTeam, client);
}
// Automatically put the player on a team if he doesn't choose one.
// The mp_force_pick_time convar is the built in way to do this, but that obviously
// does not call GOKZ_JoinTeam which includes a fix for spawning in the void when
// there is no valid spawns available.
CreateTimer(12.0, Timer_ForceJoinTeam, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);

hasSavedPosition[client] = false;
}

public Action Timer_ForceJoinTeam(Handle timer, int userid)
{
int client = GetClientOfUserId(userid);
if (IsValidClient(client))
{
int team = GetClientTeam(client);
if (team == CS_TEAM_NONE)
{
GOKZ_JoinTeam(client, CS_TEAM_SPECTATOR, false);
}
}
return Plugin_Stop;
}

void OnTimerStart_JoinTeam(int client)
{
hasSavedPosition[client] = false;
Expand All @@ -238,10 +252,14 @@ void JoinTeam(int client, int newTeam, bool restorePos)

if (newTeam == CS_TEAM_SPECTATOR && currentTeam != CS_TEAM_SPECTATOR)
{
player.GetOrigin(savedOrigin[client]);
player.GetEyeAngles(savedAngles[client]);
savedOnLadder[client] = player.Movetype == MOVETYPE_LADDER;
hasSavedPosition[client] = true;
if (currentTeam != CS_TEAM_NONE)
{
player.GetOrigin(savedOrigin[client]);
player.GetEyeAngles(savedAngles[client]);
savedOnLadder[client] = player.Movetype == MOVETYPE_LADDER;
hasSavedPosition[client] = true;
}

if (!player.Paused && !player.CanPause)
{
player.StopTimer();
Expand Down Expand Up @@ -511,9 +529,3 @@ void OnMapStart_FixMissingSpawns()
}
}
}

static void AutoJoinTeam(int client)
{
int team = GetRandomInt(CS_TEAM_T, CS_TEAM_CT);
JoinTeam(client, team, false);
}
10 changes: 5 additions & 5 deletions addons/sourcemod/scripting/gokz-core/natives.sp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public int Native_SetTeleportCount(Handle plugin, int numParams)

public int Native_RegisterOption(Handle plugin, int numParams)
{
char name[30];
char name[GOKZ_OPTION_MAX_NAME_LENGTH];
GetNativeString(1, name, sizeof(name));
char description[255];
GetNativeString(2, description, sizeof(description));
Expand All @@ -478,7 +478,7 @@ public int Native_RegisterOption(Handle plugin, int numParams)

public int Native_GetOptionProp(Handle plugin, int numParams)
{
char option[30];
char option[GOKZ_OPTION_MAX_NAME_LENGTH];
GetNativeString(1, option, sizeof(option));
OptionProp prop = GetNativeCell(2);
any value = GetOptionProp(option, prop);
Expand All @@ -494,22 +494,22 @@ public int Native_GetOptionProp(Handle plugin, int numParams)

public int Native_SetOptionProp(Handle plugin, int numParams)
{
char option[30];
char option[GOKZ_OPTION_MAX_NAME_LENGTH];
GetNativeString(1, option, sizeof(option));
OptionProp prop = GetNativeCell(2);
return SetOptionProp(option, prop, GetNativeCell(3));
}

public int Native_GetOption(Handle plugin, int numParams)
{
char option[30];
char option[GOKZ_OPTION_MAX_NAME_LENGTH];
GetNativeString(2, option, sizeof(option));
return view_as<int>(GetOption(GetNativeCell(1), option));
}

public int Native_SetOption(Handle plugin, int numParams)
{
char option[30];
char option[GOKZ_OPTION_MAX_NAME_LENGTH];
GetNativeString(2, option, sizeof(option));
return view_as<int>(SetOption(GetNativeCell(1), option, GetNativeCell(3)));
}
Expand Down
24 changes: 12 additions & 12 deletions addons/sourcemod/scripting/gokz-global.sp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool gB_APIKeyCheck;
bool gB_ModeCheck[MODE_COUNT];
bool gB_BannedCommandsCheck;
char gC_CurrentMap[64];
char gC_CurrentMapPath[PLATFORM_MAX_PATH];
int gI_CurrentMapFileSize;
bool gB_InValidRun[MAXPLAYERS + 1];
bool gB_GloballyVerified[MAXPLAYERS + 1];
bool gB_EnforcerOnFreshMap;
Expand All @@ -50,7 +50,7 @@ int gI_FPSMax[MAXPLAYERS + 1];
bool gB_waitingForFPSKick[MAXPLAYERS + 1];
bool gB_MapValidated;
int gI_MapID;
int gI_MapFilesize;
int gI_MapFileSize;
int gI_MapTier;

ConVar gCV_gokz_settings_enforcer;
Expand Down Expand Up @@ -89,7 +89,7 @@ public void OnPluginStart()
gB_APIKeyCheck = false;
gB_MapValidated = false;
gI_MapID = -1;
gI_MapFilesize = -1;
gI_MapFileSize = -1;
gI_MapTier = -1;

for (int mode = 0; mode < MODE_COUNT; mode++)
Expand Down Expand Up @@ -194,7 +194,7 @@ public void FPSCheck(QueryCookie cookie, int client, ConVarQueryResult result, c
if (!gB_waitingForFPSKick[client])
{
gB_waitingForFPSKick[client] = true;
CreateTimer(GL_FPS_MAX_KICK_TIMEOUT, FPSKickPlayer, client, TIMER_FLAG_NO_MAPCHANGE);
CreateTimer(GL_FPS_MAX_KICK_TIMEOUT, FPSKickPlayer, GetClientUserId(client), TIMER_FLAG_NO_MAPCHANGE);
GOKZ_PrintToChat(client, true, "%t", "Warn Player fps_max");
if (GOKZ_GetTimerRunning(client))
{
Expand All @@ -221,8 +221,9 @@ public void MYAWCheck(QueryCookie cookie, int client, ConVarQueryResult result,
}
}

Action FPSKickPlayer(Handle timer, int client)
Action FPSKickPlayer(Handle timer, int userid)
{
int client = GetClientOfUserId(userid);
if (IsValidClient(client) && !IsFakeClient(client) && gB_waitingForFPSKick[client])
{
KickClient(client, "%T", "Kick Player fps_max", client);
Expand Down Expand Up @@ -310,6 +311,9 @@ public void OnMapStart()
{
LoadSounds();

GetCurrentMapDisplayName(gC_CurrentMap, sizeof(gC_CurrentMap));
gI_CurrentMapFileSize = GetCurrentMapFileSize();

gB_BannedCommandsCheck = true;

// Prevent just reloading the plugin after messing with the map
Expand Down Expand Up @@ -381,7 +385,7 @@ bool MapCheck()
{
return gB_MapValidated
&& gI_MapID > 0
&& gI_MapFilesize == FileSize(gC_CurrentMapPath);
&& gI_MapFileSize == gI_CurrentMapFileSize;
}

void PrintGlobalCheckToChat(int client)
Expand Down Expand Up @@ -562,10 +566,6 @@ public void OnEnforcedConVarChanged(ConVar convar, const char[] oldValue, const

static void SetupAPI()
{
GetCurrentMap(gC_CurrentMap, sizeof(gC_CurrentMap));
GetMapDisplayName(gC_CurrentMap, gC_CurrentMap, sizeof(gC_CurrentMap));
GetMapFullPath(gC_CurrentMapPath, sizeof(gC_CurrentMapPath));

GlobalAPI_GetAuthStatus(GetAuthStatusCallback);
GlobalAPI_GetModes(GetModeInfoCallback);
GlobalAPI_GetMapByName(GetMapCallback, _, gC_CurrentMap);
Expand Down Expand Up @@ -645,7 +645,7 @@ public int GetMapCallback(JSON_Object map_json, GlobalAPIRequestData request)

gB_MapValidated = map.IsValidated;
gI_MapID = map.Id;
gI_MapFilesize = map.Filesize;
gI_MapFileSize = map.Filesize;
gI_MapTier = map.Difficulty;

// We don't do that earlier cause we need the map ID
Expand Down Expand Up @@ -708,4 +708,4 @@ static void LoadSounds()
FormatEx(downloadPath, sizeof(downloadPath), "sound/%s", GL_SOUND_NEW_RECORD);
AddFileToDownloadsTable(downloadPath);
PrecacheSound(GL_SOUND_NEW_RECORD, true);
}
}
30 changes: 30 additions & 0 deletions addons/sourcemod/scripting/gokz-global/api.sp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ void CreateNatives()
CreateNative("GOKZ_GL_GetRankPoints", Native_GetRankPoints);
CreateNative("GOKZ_GL_GetFinishes", Native_GetFinishes);
CreateNative("GOKZ_GL_UpdatePoints", Native_UpdatePoints);
CreateNative("GOKZ_GL_GetAPIKeyValid", Native_GetAPIKeyValid);
CreateNative("GOKZ_GL_GetPluginsValid", Native_GetPluginsValid);
CreateNative("GOKZ_GL_GetSettingsEnforcerValid", Native_GetSettingsEnforcerValid);
CreateNative("GOKZ_GL_GetMapValid", Native_GetMapValid);
CreateNative("GOKZ_GL_GetPlayerValid", Native_GetPlayerValid);
}

public int Native_PrintRecords(Handle plugin, int numParams)
Expand Down Expand Up @@ -107,3 +112,28 @@ public int Native_UpdatePoints(Handle plugin, int numParams)
// We're gonna always force an update here, cause otherwise the call doesn't really make sense
UpdatePoints(GetNativeCell(1), true, GetNativeCell(2));
}

public int Native_GetAPIKeyValid(Handle plugin, int numParams)
{
return view_as<int>(gB_APIKeyCheck);
}

public int Native_GetPluginsValid(Handle plugin, int numParams)
{
return view_as<int>(gB_BannedCommandsCheck);
}

public int Native_GetSettingsEnforcerValid(Handle plugin, int numParams)
{
return view_as<int>(gCV_gokz_settings_enforcer.BoolValue && gB_EnforcerOnFreshMap);
}

public int Native_GetMapValid(Handle plugin, int numParams)
{
return view_as<int>(MapCheck());
}

public int Native_GetPlayerValid(Handle plugin, int numParams)
{
return view_as<int>(gB_GloballyVerified[GetNativeCell(1)]);
}
10 changes: 9 additions & 1 deletion addons/sourcemod/scripting/gokz-jumpstats/jump_tracking.sp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,15 @@ enum struct JumpTracker
}
else
{
return JumpType_LadderJump;
// Check for ladder gliding.
if (GetClientButtons(this.jumper) & IN_JUMP)
{
return JumpType_Invalid;
}
else
{
return JumpType_LadderJump;
}
}
}
else if (!jumped)
Expand Down
5 changes: 4 additions & 1 deletion addons/sourcemod/scripting/gokz-localranks/db/js_top.sp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ public int MenuHandler_JumpTopList(Menu menu, MenuAction action, int param1, int
RP_DIRECTORY_JUMPS, jumpInfo[param1][param2][0], RP_DIRECTORY_BLOCKJUMPS, jumpTopType[param1], blockNums[param1][param2], gC_ModeNamesShort[jumpInfo[param1][param2][2]], gC_StyleNamesShort[0], RP_FILE_EXTENSION);
}

GOKZ_RP_LoadJumpReplay(param1, path);
if (GOKZ_RP_LoadJumpReplay(param1, path) == -1)
{
GOKZ_PrintToChat(param1, true, "%t", "No Replay for Jump");
}
}

if (action == MenuAction_Cancel && param2 == MenuCancel_Exit)
Expand Down
Loading

0 comments on commit bcaf8f3

Please sign in to comment.