Skip to content

Commit

Permalink
Update very_good_yes from master (#932)
Browse files Browse the repository at this point in the history
* Add Convar to restrict noclip in start zone

* remove unused translation file

* Require the enum struct size to be passed to natives

This should hopefully prevent Invalid memory access from plugins compiled on older version of the timer. If an enum struct is changed then plugins compiled on older version of the timer will be forced to be recompiled to match the version they are using.

* Fix save states not tracking preframes

Misc. name changes for natives. And a somehow possible exception fixed when getting a record.

* Add hitbox/center mass cvar (#930)

* Add optional cvar for player center of mass/player hitbox for touching zones

* 2.5.7a Final Changes

fix spelling mistake
add missing optional native
tabify spaces

Co-authored-by: Nairda <38843773+Nairdaa@users.noreply.github.com>
  • Loading branch information
kidfearless and Nairdaa authored Jul 7, 2020
1 parent 26c9f03 commit 48f051f
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 47 deletions.
25 changes: 16 additions & 9 deletions addons/sourcemod/scripting/include/shavit.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1389,9 +1389,10 @@ native int Shavit_GetWRCount(int client);
*
* @param style Style index.
* @param StyleSettings Reference to the settings array.
* @param size Size of the StyleSettings buffer, e.g sizeof(stylesettings_t)
* @return SP_ERROR_NONE on success, anything else on failure.
*/
native int Shavit_GetStyleSettings(int style, any StyleSettings[sizeof(stylesettings_t)]);
native int Shavit_GetStyleSettings(int style, any[] StyleSettings, int size = sizeof(stylesettings_t));

/**
* Saves the style related strings on string references.
Expand Down Expand Up @@ -1465,18 +1466,20 @@ native bool Shavit_IsPracticeMode(int client);
*
* @param client Client index.
* @param snapshot Full snapshot of the client's timer.
* @param size Size of the snapshot buffer, e.g sizeof(timer_snapshot_t)
* @noreturn
*/
native void Shavit_SaveSnapshot(int client, any snapshot[sizeof(timer_snapshot_t)]);
native void Shavit_SaveSnapshot(int client, any[] snapshot, int size = sizeof(timer_snapshot_t));

/**
* Restores the client's timer from a snapshot.
*
* @param client Client index.
* @param snapshot Full snapshot of the client's timer.
* @param size Size of the snapshot buffer, e.g sizeof(timer_snapshot_t)
* @noreturn
*/
native void Shavit_LoadSnapshot(int client, any snapshot[sizeof(timer_snapshot_t)]);
native void Shavit_LoadSnapshot(int client, any[] snapshot, int size = sizeof(timer_snapshot_t));

/**
* Sets a player's replay recording frames from a provided ArrayList.
Expand Down Expand Up @@ -1630,22 +1633,25 @@ native void Shavit_LogMessage(const char[] format, any ...);
*
* @param client Client index
* @param index Index of CP to get
* @param cpcache Buffer to store cp data in
* @param cpcache Buffer to store cp data in sizeof(cp_cache_t)
* @param size Size of the cpcache buffer, e.g sizeof(cp_cache_t)
*
* @noreturn
*/
native bool Shavit_GetCheckpoint(int client, int index, any cpcache[sizeof(cp_cache_t)]);
native bool Shavit_GetCheckpoint(int client, int index, any[] cpcache, int size = sizeof(cp_cache_t));

/**
* Sets checkpoint data at the given index for the given client
*
* @param client Client index
* @param index Index of CP to set, or -1 to push cp as last
* @param cpcache Buffer to store cp data in sizeof(cp_cache_t)
* @param size Size of the cpcache buffer, e.g sizeof(cp_cache_t)
* @param cpcache Buffer with cp data
*
* @noreturn
*/
native void Shavit_SetCheckpoint(int client, int index, any cpcache[sizeof(cp_cache_t)]);
native void Shavit_SetCheckpoint(int client, int index, any[] cpcache, int size = sizeof(cp_cache_t));

/**
* Teleports client to the checkpoint at given index
Expand Down Expand Up @@ -1749,7 +1755,7 @@ native int Shavit_GetPlayerPreFrame(int client);
*
* @return Timer preframe count
*/
native int Shavit_GetPlayerTimerframe(int client);
native int Shavit_GetPlayerTimerFrame(int client);

/*
* Sets player's preframe length.
Expand All @@ -1770,7 +1776,7 @@ native void Shavit_SetPlayerPreFrame(int client, int PreFrame);
*
* @noreturn
*/
native void Shavit_SetPlayerTimerPreFrame(int client, int TimerPreFrame);
native void Shavit_SetPlayerTimerFrame(int client, int TimerPreFrame);

// same as Shavit_PrintToChat() but loops through the whole server
// code stolen from the base halflife.inc file
Expand Down Expand Up @@ -1900,8 +1906,9 @@ public void __pl_shavit_SetNTVOptional()
MarkNativeAsOptional("Shavit_GetCurrentCheckpoint");
MarkNativeAsOptional("Shavit_SetCurrentCheckpoint");
MarkNativeAsOptional("Shavit_GetPlayerPreFrame");
MarkNativeAsOptional("Shavit_GetPlayerTimerframe");
MarkNativeAsOptional("Shavit_GetPlayerTimerFrame");
MarkNativeAsOptional("Shavit_SetPlayerPreFrame");
MarkNativeAsOptional("Shavit_GetClosestReplayTime");
MarkNativeAsOptional("Shavit_SetPlayerTimerFrame");
}
#endif
18 changes: 18 additions & 0 deletions addons/sourcemod/scripting/shavit-core.sp
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,11 @@ public int Native_GetStyleCount(Handle handler, int numParams)

public int Native_GetStyleSettings(Handle handler, int numParams)
{
if(GetNativeCell(3) != sizeof(stylesettings_t))
{
return ThrowNativeError(200, "stylesettings_t does not match latest(got %i expected %i). Please update your includes and recompile your plugins",
GetNativeCell(3), sizeof(stylesettings_t));
}
return SetNativeArray(2, gA_StyleSettings[GetNativeCell(1)], sizeof(stylesettings_t));
}

Expand Down Expand Up @@ -1725,6 +1730,12 @@ public int Native_IsPracticeMode(Handle handler, int numParams)

public int Native_SaveSnapshot(Handle handler, int numParams)
{
if(GetNativeCell(3) != sizeof(timer_snapshot_t))
{
return ThrowNativeError(200, "timer_snapshot_t does not match latest(got %i expected %i). Please update your includes and recompile your plugins",
GetNativeCell(3), sizeof(timer_snapshot_t));
}

int client = GetNativeCell(1);

timer_snapshot_t snapshot;
Expand All @@ -1747,6 +1758,11 @@ public int Native_SaveSnapshot(Handle handler, int numParams)

public int Native_LoadSnapshot(Handle handler, int numParams)
{
if(GetNativeCell(3) != sizeof(timer_snapshot_t))
{
return ThrowNativeError(200, "timer_snapshot_t does not match latest(got %i expected %i). Please update your includes and recompile your plugins",
GetNativeCell(3), sizeof(timer_snapshot_t));
}
int client = GetNativeCell(1);

timer_snapshot_t snapshot;
Expand Down Expand Up @@ -1775,6 +1791,8 @@ public int Native_LoadSnapshot(Handle handler, int numParams)
gA_Timers[client].iSHSWCombination = snapshot.iSHSWCombination;
gA_Timers[client].iMeasuredJumps = snapshot.iMeasuredJumps;
gA_Timers[client].iPerfectJumps = snapshot.iPerfectJumps;

return 0;
}

public int Native_LogMessage(Handle plugin, int numParams)
Expand Down
38 changes: 20 additions & 18 deletions addons/sourcemod/scripting/shavit-hud.sp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ Action ShowHUDMenu(int client, int item)
menu.AddItem(sInfo, sHudItem);

FormatEx(sInfo, 16, "@%d", HUD2_TIMEDIFFERENCE);
FormatEx(sHudItem, 64, "%T", "HudTimeDiffText", client);
FormatEx(sHudItem, 64, "%T", "HudTimeDifference", client);
menu.AddItem(sInfo, sHudItem);

FormatEx(sInfo, 16, "@%d", HUD2_SPEED);
Expand Down Expand Up @@ -1881,21 +1881,23 @@ void GetTrackName(int client, int track, char[] output, int size)

void PrintCSGOHUDText(int client, const char[] format, any ...)
{
char buff[MAX_HINT_SIZE];
VFormat(buff, sizeof(buff), format, 3);
Format(buff, sizeof(buff), "</font>%s ", buff);

for(int i = strlen(buff); i < sizeof(buff); i++)
buff[i] = '\n';

Protobuf pb = view_as<Protobuf>(StartMessageOne("TextMsg", client, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS));
pb.SetInt("msg_dst", 4);
pb.AddString("params", "#SFUI_ContractKillStart");
pb.AddString("params", buff);
pb.AddString("params", NULL_STRING);
pb.AddString("params", NULL_STRING);
pb.AddString("params", NULL_STRING);
pb.AddString("params", NULL_STRING);

EndMessage();
char buff[MAX_HINT_SIZE];
VFormat(buff, sizeof(buff), format, 3);
Format(buff, sizeof(buff), "</font>%s ", buff);

for(int i = strlen(buff); i < sizeof(buff); i++)
{
buff[i] = '\n';
}

Protobuf pb = view_as<Protobuf>(StartMessageOne("TextMsg", client, USERMSG_RELIABLE | USERMSG_BLOCKHOOKS));
pb.SetInt("msg_dst", 4);
pb.AddString("params", "#SFUI_ContractKillStart");
pb.AddString("params", buff);
pb.AddString("params", NULL_STRING);
pb.AddString("params", NULL_STRING);
pb.AddString("params", NULL_STRING);
pb.AddString("params", NULL_STRING);

EndMessage();
}
50 changes: 43 additions & 7 deletions addons/sourcemod/scripting/shavit-misc.sp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ bool gB_SaveStates[MAXPLAYERS+1];
char gS_SaveStateTargetname[MAXPLAYERS+1][32];
ArrayList gA_SaveFrames[MAXPLAYERS+1];
ArrayList gA_PersistentData = null;
int gI_SavePreFrames[MAXPLAYERS+1];
int gI_TimerFrames[MAXPLAYERS+1];

// cookies
Handle gH_HideCookie = null;
Expand Down Expand Up @@ -145,6 +147,7 @@ Convar gCV_PersistData = null;
Convar gCV_StopTimerWarning = null;
Convar gCV_WRMessages = null;
Convar gCV_BhopSounds = null;
Convar gCV_RestrictNoclip = null;

// external cvars
ConVar sv_disable_immunity_alpha = null;
Expand Down Expand Up @@ -329,6 +332,7 @@ public void OnPluginStart()
gCV_StopTimerWarning = new Convar("shavit_misc_stoptimerwarning", "900", "Time in seconds to display a warning before stopping the timer with noclip or !stop.\n0 - Disabled");
gCV_WRMessages = new Convar("shavit_misc_wrmessages", "3", "How many \"NEW <style> WR!!!\" messages to print?\n0 - Disabled", 0, true, 0.0, true, 100.0);
gCV_BhopSounds = new Convar("shavit_misc_bhopsounds", "0", "Should bhop (landing and jumping) sounds be muted?\n0 - Disabled\n1 - Blocked while !hide is enabled\n2 - Always blocked", 0, true, 0.0, true, 3.0);
gCV_RestrictNoclip = new Convar("shavit_misc_restrictnoclip", "1", "Should noclip be be restricted\n0 - Disabled\n1 - No vertical velocity while in noclip in start zone\n2 - No noclip in start zone", 0, true, 0.0, true, 2.0);

Convar.AutoExecConfig();

Expand Down Expand Up @@ -1002,17 +1006,35 @@ void RemoveRagdoll(int client)
public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float vel[3], float angles[3], TimerStatus status, int track, int style, stylesettings_t stylesettings)
{
bool bNoclip = (GetEntityMoveType(client) == MOVETYPE_NOCLIP);
bool bInStart = Shavit_InsideZone(client, Zone_Start, track);

// i will not be adding a setting to toggle this off
if(bNoclip && status == Timer_Running)
if(bNoclip)
{
Shavit_StopTimer(client);
if(status == Timer_Running)
{
Shavit_StopTimer(client);
}
if(bInStart && gCV_RestrictNoclip.BoolValue)
{
if(gCV_RestrictNoclip.IntValue == 1)
{
float fSpeed[3];
GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", fSpeed);
fSpeed[2] = 0.0;
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, fSpeed);
}
else if(gCV_RestrictNoclip.IntValue == 2)
{
SetEntityMoveType(client, MOVETYPE_ISOMETRIC);
}
}
}

int iGroundEntity = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity");

// prespeed
if(!bNoclip && gA_StyleSettings[gI_Style[client]].iPrespeed == 0 && Shavit_InsideZone(client, Zone_Start, track))
if(!bNoclip && gA_StyleSettings[gI_Style[client]].iPrespeed == 0 && bInStart)
{
if((gCV_PreSpeed.IntValue == 2 || gCV_PreSpeed.IntValue == 3) && gI_GroundEntity[client] == -1 && iGroundEntity != -1 && (buttons & IN_JUMP) > 0)
{
Expand Down Expand Up @@ -1136,7 +1158,7 @@ void PersistData(int client)
{
aData.aFrames = Shavit_GetReplayData(client);
aData.iPreFrames = Shavit_GetPlayerPreFrame(client);
aData.iTimerPreFrames = Shavit_GetPlayerTimerframe(client);
aData.iTimerPreFrames = Shavit_GetPlayerTimerFrame(client);
}

aData.fDisconnectTime = GetEngineTime();
Expand Down Expand Up @@ -1258,7 +1280,7 @@ public Action Timer_LoadPersistentData(Handle Timer, any data)
{
Shavit_SetReplayData(client, aData.aFrames);
Shavit_SetPlayerPreFrame(client, aData.iPreFrames);
Shavit_SetPlayerTimerPreFrame(client, aData.iTimerPreFrames);
Shavit_SetPlayerTimerFrame(client, aData.iTimerPreFrames);
}

if(aData.bPractice)
Expand Down Expand Up @@ -2351,7 +2373,7 @@ bool SaveCheckpoint(int client, int index, bool overflow = false)
{
cpcache.aFrames = Shavit_GetReplayData(target);
cpcache.iPreFrames = Shavit_GetPlayerPreFrame(target);
cpcache.iTimerPreFrames = Shavit_GetPlayerTimerframe(target);
cpcache.iTimerPreFrames = Shavit_GetPlayerTimerFrame(target);
}

cpcache.bSegmented = true;
Expand Down Expand Up @@ -2565,7 +2587,7 @@ void TeleportToCheckpoint(int client, int index, bool suppressMessage)
{
Shavit_SetReplayData(client, cpcache.aFrames);
Shavit_SetPlayerPreFrame(client, cpcache.iPreFrames);
Shavit_SetPlayerTimerPreFrame(client, cpcache.iTimerPreFrames);
Shavit_SetPlayerTimerFrame(client, cpcache.iTimerPreFrames);
}
}

Expand Down Expand Up @@ -3400,6 +3422,8 @@ void LoadState(int client)
if(gB_Replay && gA_SaveFrames[client] != null)
{
Shavit_SetReplayData(client, gA_SaveFrames[client]);
Shavit_SetPlayerPreFrame(client, gI_SavePreFrames[client]);
Shavit_SetPlayerTimerFrame(client, gI_TimerFrames[client]);
}

delete gA_SaveFrames[client];
Expand All @@ -3425,6 +3449,8 @@ void SaveState(int client)
{
delete gA_SaveFrames[client];
gA_SaveFrames[client] = Shavit_GetReplayData(client);
gI_SavePreFrames[client] = Shavit_GetPlayerPreFrame(client);
gI_TimerFrames[client] = Shavit_GetPlayerTimerFrame(client);
}

gB_SaveStates[client] = true;
Expand Down Expand Up @@ -3466,6 +3492,11 @@ int GetMaxCPs(int client)

public any Native_GetCheckpoint(Handle plugin, int numParams)
{
if(GetNativeCell(4) != sizeof(cp_cache_t))
{
return ThrowNativeError(200, "cp_cache_t does not match latest(got %i expected %i). Please update your includes and recompile your plugins",
GetNativeCell(4), sizeof(cp_cache_t));
}
int client = GetNativeCell(1);
int index = GetNativeCell(2);

Expand All @@ -3481,6 +3512,11 @@ public any Native_GetCheckpoint(Handle plugin, int numParams)

public any Native_SetCheckpoint(Handle plugin, int numParams)
{
if(GetNativeCell(4) != sizeof(cp_cache_t))
{
return ThrowNativeError(200, "cp_cache_t does not match latest(got %i expected %i). Please update your includes and recompile your plugins",
GetNativeCell(4), sizeof(cp_cache_t));
}
int client = GetNativeCell(1);
int position = GetNativeCell(2);

Expand Down
17 changes: 13 additions & 4 deletions addons/sourcemod/scripting/shavit-replay.sp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("Shavit_SetReplayData", Native_SetReplayData);
CreateNative("Shavit_GetPlayerPreFrame", Native_GetPreFrame);
CreateNative("Shavit_SetPlayerPreFrame", Native_SetPreFrame);
CreateNative("Shavit_SetPlayerTimerPreFrame", Native_SetTimerPreFrame);
CreateNative("Shavit_GetPlayerTimerframe", Native_GetTimerFrame);
CreateNative("Shavit_SetPlayerTimerFrame", Native_SetTimerFrame);
CreateNative("Shavit_GetPlayerTimerFrame", Native_GetTimerFrame);
CreateNative("Shavit_GetClosestReplayTime", Native_GetClosestReplayTime);

// registers library, check "bool LibraryExists(const char[] name)" in order to use with other plugins
Expand Down Expand Up @@ -782,7 +782,7 @@ public int Native_SetPreFrame(Handle handler, int numParams)
gI_PlayerPrerunFrames[client] = preframes;
}

public int Native_SetTimerPreFrame(Handle handler, int numParams)
public int Native_SetTimerFrame(Handle handler, int numParams)
{
int client = GetNativeCell(1);
int timerframes = GetNativeCell(2);
Expand Down Expand Up @@ -1271,7 +1271,16 @@ bool SaveReplay(int style, int track, float time, int steamid, char[] name, int
any aWriteData[CELLS_PER_FRAME * FRAMES_PER_WRITE];
int iFramesWritten = 0;

gA_Frames[style][track].Clear();
// How did I trigger this?
if(gA_Frames[style][track] == null)
{
gA_Frames[style][track] = new ArrayList(CELLS_PER_FRAME);
}
else
{
gA_Frames[style][track].Clear();
}


for(int i = preframes; i < iSize; i++)
{
Expand Down
Loading

0 comments on commit 48f051f

Please sign in to comment.