fix wrong game detection (#146)

This commit is contained in:
shavitush 2016-08-04 22:32:06 +03:00
parent cf6121eb44
commit f92f286702
9 changed files with 93 additions and 86 deletions

View File

@ -264,7 +264,7 @@ stock void FormatSeconds(float time, char[] newtime, int newtimesize, bool preci
float fSeconds = (iRounded % 60) + fTempTime - iRounded;
char[] sSeconds = new char[8];
FormatEx(sSeconds, 8, precise? "%.03f":"%.01f", fSeconds);
FormatEx(sSeconds, 8, precise? "%s%.03f":"%s%.01f", (fSeconds < 0.0)? "-":"", fSeconds);
if(fTempTime < 60.0)
{

View File

@ -57,7 +57,7 @@ bool gB_RTLer = false;
bool gB_SCP = false;
// game-related
ServerGame gSG_Type = Game_Unknown;
EngineVersion gEV_Type = Engine_Unknown;
ConVar gCV_Deadtalk = null;
public Plugin myinfo =
@ -87,14 +87,6 @@ public void OnAllPluginsLoaded()
SetFailState("shavit-rankings is required for the plugin to work.");
}
// placed here and not in OnPluginStart() as `chat` is coming before `core` if sorted alphabetically
gSG_Type = Shavit_GetGameType();
if(gSG_Type == Game_CSGO)
{
gCV_Deadtalk = FindConVar("sv_deadtalk");
}
// modules
gB_BaseComm = LibraryExists("basecomm");
gB_RTLer = LibraryExists("rtler");
@ -103,6 +95,14 @@ public void OnAllPluginsLoaded()
public void OnPluginStart()
{
// game specific
gEV_Type = GetEngineVersion();
if(gEV_Type == Engine_CSGO)
{
gCV_Deadtalk = FindConVar("sv_deadtalk");
}
// commands
RegAdminCmd("sm_reloadchat", Command_ReloadChat, ADMFLAG_ROOT, "Reload chat config.");
@ -442,7 +442,7 @@ public Action Command_ChatRanks(int client, int args)
FormatVariables(client, sMessage, 255, sMessage, "Example.");
char[] sBuffer = new char[300];
FormatEx(sBuffer, 300, "%s\x04[%s]\x01 %s%s %s %s %s", gSG_Type == Game_CSGO? " ":"", sRankText, strlen(sPrefix) == 0? "\x03":"", sPrefix, sName, gSG_Type == Game_CSGO? ":\x01":"\x01:", sMessage);
FormatEx(sBuffer, 300, "%s\x04[%s]\x01 %s%s %s %s %s", gEV_Type == Engine_CSGO? " ":"", sRankText, strlen(sPrefix) == 0? "\x03":"", sPrefix, sName, gEV_Type == Engine_CSGO? ":\x01":"\x01:", sMessage);
ChatMessage(client, clients, 1, sBuffer);
}
@ -467,7 +467,7 @@ public Action OnChatMessage(int &author, ArrayList recipients, char[] name, char
return Plugin_Continue;
}
if(gB_SCPFormat && GetMessageFlags() & CHATFLAGS_ALL && !IsPlayerAlive(author) && (gSG_Type == Game_CSS || !gCV_Deadtalk.BoolValue))
if(gB_SCPFormat && GetMessageFlags() & CHATFLAGS_ALL && !IsPlayerAlive(author) && (gEV_Type == Engine_CSS || !gCV_Deadtalk.BoolValue))
{
for(int i = 1; i <= MaxClients; i++)
{
@ -524,7 +524,7 @@ public Action OnChatMessage(int &author, ArrayList recipients, char[] name, char
strcopy(sFormattedText, 255, message);
}
FormatEx(name, MAXLENGTH_NAME, "%s%s%s", gSG_Type == Game_CSGO? " ":"", sPrefix, sName);
FormatEx(name, MAXLENGTH_NAME, "%s%s%s", gEV_Type == Engine_CSGO? " ":"", sPrefix, sName);
strcopy(message, MAXLENGTH_MESSAGE, sFormattedText);
return Plugin_Changed;
@ -703,7 +703,7 @@ public void FormatChatLine(int client, const char[] sMessage, bool bAlive, int i
strcopy(sFormattedText, 255, sBuffer);
}
FormatEx(buffer, maxlen, "\x01%s%s%s\x03%s%s %s %s", gSG_Type == Game_CSGO? " ":"", (bAlive || iTeam == CS_TEAM_SPECTATOR)? "":"*DEAD* ", sTeam, sNewPrefix, sNewName, gSG_Type == Game_CSGO? ":\x01":"\x01:", sFormattedText);
FormatEx(buffer, maxlen, "\x01%s%s%s\x03%s%s %s %s", gEV_Type == Engine_CSGO? " ":"", (bAlive || iTeam == CS_TEAM_SPECTATOR)? "":"*DEAD* ", sTeam, sNewPrefix, sNewName, gEV_Type == Engine_CSGO? ":\x01":"\x01:", sFormattedText);
}
public void FormatVariables(int client, char[] buffer, int maxlen, const char[] formattingrules, const char[] message)
@ -716,7 +716,7 @@ public void FormatVariables(int client, char[] buffer, int maxlen, const char[]
ReplaceString(sTempFormattingRules, maxlen, gS_GlobalColorNames[i], gS_GlobalColors[i]);
}
if(gSG_Type == Game_CSS)
if(gEV_Type == Engine_CSS)
{
ReplaceString(sTempFormattingRules, maxlen, "{RGB}", "\x07");
ReplaceString(sTempFormattingRules, maxlen, "{RGBA}", "\x08");
@ -769,7 +769,7 @@ public void ChatMessage(int from, int[] clients, int count, const char[] sMessag
if(hSayText2 != null)
{
if(gSG_Type == Game_CSGO)
if(gEV_Type == Engine_CSGO)
{
PbSetInt(hSayText2, "ent_idx", from);
PbSetBool(hSayText2, "chat", true);

View File

@ -38,7 +38,8 @@
//#define DEBUG
// game type (CS:S/CS:GO)
ServerGame gSG_Type = Game_Unknown;
ServerGame gSG_Type = Game_Unknown; // deperecated and here for backwards compatibility
EngineVersion gEV_Type = Engine_Unknown;
// database handle
Database gH_SQL = null;
@ -154,15 +155,15 @@ public void OnPluginStart()
gH_Forwards_OnStyleChanged = CreateGlobalForward("Shavit_OnStyleChanged", ET_Event, Param_Cell, Param_Cell, Param_Cell);
// game types
EngineVersion evType = GetEngineVersion();
gEV_Type = GetEngineVersion();
if(evType == Engine_CSS)
if(gEV_Type == Engine_CSS)
{
gSG_Type = Game_CSS;
gF_HSW_Requirement = 399.00;
}
else if(evType == Engine_CSGO)
else if(gEV_Type == Engine_CSGO)
{
gSG_Type = Game_CSGO;
gF_HSW_Requirement = 449.00;
@ -706,7 +707,7 @@ public int Native_PrintToChat(Handle handler, int numParams)
char[] buffer = new char[255];
FormatNativeString(0, 2, 3, 255, written, buffer);
PrintToChat(client, "%s%s %s", gSG_Type == Game_CSS? "":" ", PREFIX, buffer);
PrintToChat(client, "%s%s %s", (gEV_Type == Engine_CSS)? "":" ", PREFIX, buffer);
return;
}

View File

@ -46,7 +46,7 @@
#define HUD_DEFAULT (HUD_MASTER|HUD_CENTER|HUD_ZONEHUD|HUD_OBSERVE|HUD_TOPLEFT|HUD_SYNC|HUD_TIMELEFT)
// game type (CS:S/CS:GO)
ServerGame gSG_Type = Game_Unknown;
EngineVersion gEV_Type = Engine_Unknown;
// modules
bool gB_Replay = false;
@ -106,9 +106,9 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
public void OnPluginStart()
{
// game-specific
gSG_Type = Shavit_GetGameType();
gEV_Type = GetEngineVersion();
if(gSG_Type == Game_CSS)
if(gEV_Type == Engine_CSS)
{
gH_HUD = CreateHudSynchronizer();
gI_NameLength = MAX_NAME_LENGTH;
@ -189,7 +189,7 @@ public Action ShowHUDMenu(int client)
IntToString(HUD_HIDEWEAPON, sInfo, 16);
m.AddItem(sInfo, "Hide weapons");
if(gSG_Type == Game_CSS)
if(gEV_Type == Engine_CSS)
{
IntToString(HUD_TOPLEFT, sInfo, 16);
m.AddItem(sInfo, "Top left HUD (WR/PB)");
@ -304,7 +304,7 @@ public void TriggerHUDUpdate(int client)
UpdateHUD(client);
SetEntProp(client, Prop_Data, "m_bDrawViewmodel", gI_HUDSettings[client] & HUD_HIDEWEAPON? 0:1);
if(gSG_Type == Game_CSS)
if(gEV_Type == Engine_CSS)
{
UpdateTopLeftHUD(client, true);
UpdateKeyHint(client);
@ -350,7 +350,7 @@ public void UpdateHUD(int client)
{
if(Shavit_InsideZone(target, Zone_Start))
{
if(gSG_Type == Game_CSGO)
if(gEV_Type == Engine_CSGO)
{
FormatEx(sHintText, 64, "<font size=\"45\" color=\"#%s\">Start Zone</font>", gS_StartColors[gI_Cycle % sizeof(gS_StartColors)]);
}
@ -363,7 +363,7 @@ public void UpdateHUD(int client)
else if(Shavit_InsideZone(target, Zone_End))
{
if(gSG_Type == Game_CSGO)
if(gEV_Type == Engine_CSGO)
{
FormatEx(sHintText, 64, "<font size=\"45\" color=\"#%s\">End Zone</font>", gS_EndColors[gI_Cycle % sizeof(gS_EndColors)]);
}
@ -403,7 +403,7 @@ public void UpdateHUD(int client)
char[] sTime = new char[32];
FormatSeconds(fTime, sTime, 32, false);
if(gSG_Type == Game_CSGO)
if(gEV_Type == Engine_CSGO)
{
strcopy(sHintText, 512, "<font size=\"18\" face=\"Stratum2\">");
@ -521,7 +521,7 @@ public void UpdateHUD(int client)
char[] sWR = new char[32];
FormatSeconds(fWR, sWR, 32, false);
if(gSG_Type == Game_CSGO)
if(gEV_Type == Engine_CSGO)
{
FormatEx(sHintText, 512, "<font face='Stratum2'>");
Format(sHintText, 512, "%s\t<u><font color='#%s'>%s Replay</font></u>", sHintText, gS_StyleHTMLColors[bsStyle], gS_BhopStyles[bsStyle]);

View File

@ -47,7 +47,7 @@
#define SSJ_DEFAULT (SSJ_CSPEED|SSJ_SPEEDD|SSJ_HEIGHT|SSJ_GAIN)
// game specific
ServerGame gSG_Type = Game_Unknown;
EngineVersion gEV_Type = Engine_Unknown;
int gI_Ammo = -1;
char gS_RadioCommands[][] = {"coverme", "takepoint", "holdpos", "regroup", "followme", "takingfire", "go", "fallback", "sticktog",
@ -118,7 +118,7 @@ public void OnAllPluginsLoaded()
public void OnPluginStart()
{
// cache
gSG_Type = Shavit_GetGameType();
gEV_Type = GetEngineVersion();
// spectator list
RegConsoleCmd("sm_specs", Command_Specs, "Show a list of spectators.");
@ -386,7 +386,7 @@ public void UpdateScoreboard(int client)
int iScore = (fPB != 0.0 && fPB < 2000)? -RoundToFloor(fPB):-2000;
if(gSG_Type == Game_CSGO)
if(gEV_Type == Engine_CSGO)
{
CS_SetClientContributionScore(client, iScore);
}
@ -843,7 +843,7 @@ public Action Command_Weapon(int client, int args)
if(StrContains(sCommand, "usp", false) != -1)
{
strcopy(sWeapon, 32, (gSG_Type == Game_CSS)? "weapon_usp":"weapon_usp_silencer");
strcopy(sWeapon, 32, (gEV_Type == Engine_CSS)? "weapon_usp":"weapon_usp_silencer");
}
else if(StrContains(sCommand, "glock", false) != -1)
@ -881,7 +881,7 @@ public void SetWeaponAmmo(int client, int weapon)
int iAmmo = GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoType");
SetEntData(client, gI_Ammo + (iAmmo * 4), 255, 4, true);
if(gSG_Type == Game_CSGO)
if(gEV_Type == Engine_CSGO)
{
SetEntProp(weapon, Prop_Send, "m_iPrimaryReserveAmmoCount", 255);
}
@ -1073,7 +1073,7 @@ public void Shavit_OnWorldRecord(int client, BhopStyle style, float time, int ju
for(int i = 1; i <= 3; i++)
{
Shavit_PrintToChatAll("%sNEW %s WR!!!", gSG_Type == Game_CSGO? "\x02":"\x077D42C9", sUpperCase);
Shavit_PrintToChatAll("%sNEW %s WR!!!", gEV_Type == Engine_CSGO? "\x02":"\x077D42C9", sUpperCase);
}
}
@ -1166,7 +1166,7 @@ public Action RemoveRadar(Handle timer, any data)
return Plugin_Stop;
}
if(gSG_Type == Game_CSGO)
if(gEV_Type == Engine_CSGO)
{
SetEntProp(client, Prop_Send, "m_iHideHUD", GetEntProp(client, Prop_Send, "m_iHideHUD") | (1 << 12)); // disables player radar
}

View File

@ -34,7 +34,7 @@
#pragma newdecls required
// game type
ServerGame gSG_Type = Game_Unknown;
EngineVersion gEV_Type = Engine_Unknown;
// cache
int gI_ReplayTick[MAX_STYLES];
@ -87,13 +87,13 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
return APLRes_Success;
}
public void OnAllPluginsLoaded()
{
gSG_Type = Shavit_GetGameType();
}
public void OnPluginStart()
{
// game specific
gEV_Type = GetEngineVersion();
gF_Tickrate = (1.0 / GetTickInterval());
// late load
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i) && !IsFakeClient(i))
@ -102,8 +102,6 @@ public void OnPluginStart()
}
}
gF_Tickrate = (1.0 / GetTickInterval());
// plugin convars
gCV_Enabled = CreateConVar("shavit_replay_enabled", "1", "Enable replay bot functionality?", 0, true, 0.0, true, 1.0);
gCV_ReplayDelay = CreateConVar("shavit_replay_delay", "5.0", "Time to wait before restarting the replay after it finishes playing.", 0, true, 0.0, true, 10.0);
@ -513,7 +511,7 @@ public void UpdateReplayInfo(int client, BhopStyle style, float time)
int iScore = (gI_FrameCount[style] > 0)? 2000:-2000;
if(gSG_Type == Game_CSGO)
if(gEV_Type == Engine_CSGO)
{
CS_SetClientContributionScore(client, iScore);
}

View File

@ -28,7 +28,7 @@
#pragma dynamic 131072
#pragma newdecls required
ServerGame gSG_Type = Game_Unknown;
EngineVersion gEV_Type = Engine_Unknown;
ArrayList gA_FirstSounds = null;
ArrayList gA_PersonalSounds = null;
@ -54,12 +54,14 @@ public void OnAllPluginsLoaded()
public void OnPluginStart()
{
// game specific
gEV_Type = GetEngineVersion();
// cache
gA_FirstSounds = new ArrayList(PLATFORM_MAX_PATH);
gA_PersonalSounds = new ArrayList(PLATFORM_MAX_PATH);
gA_WorldSounds = new ArrayList(PLATFORM_MAX_PATH);
gSM_RankSounds = new StringMap();
gSG_Type = Shavit_GetGameType();
}
public void OnMapStart()
@ -128,7 +130,7 @@ public void OnMapStart()
// thanks TotallyMehis for this workaround
// make sure to star his amazing StandUp plugin! https://github.com/TotallyMehis/StandUp
if(gSG_Type == Game_CSGO || PrecacheSound(sExploded[1]))
if(gEV_Type == Engine_CSGO || PrecacheSound(sExploded[1]))
{
PrefetchSound(sExploded[1]);
@ -216,7 +218,7 @@ public void PlayEventSound(int client, bool everyone, const char[] sound)
if(count > 0)
{
if(gSG_Type == Game_CSGO)
if(gEV_Type == Engine_CSGO)
{
char[] sPlay = new char[PLATFORM_MAX_PATH+8];
FormatEx(sPlay, PLATFORM_MAX_PATH+8, "play */%s", sound);

View File

@ -151,13 +151,13 @@ public void OnPluginStart()
OnAdminMenuReady(null);
// colors
ServerGame sgType = Shavit_GetGameType();
EngineVersion evType = GetEngineVersion();
strcopy(gS_Color_Time, 16, (sgType == Game_CSS)? "\x07D490CF":"\x07");
strcopy(gS_Color_Rank, 16, (sgType == Game_CSS)? "\x077585E0":"\x05");
strcopy(gS_Color_Sync, 16, (sgType == Game_CSS)? "\x07B590D4":"\x06");
strcopy(gS_Color_Better, 16, (sgType == Game_CSS)? "\x07AD3BA6":"\x0C");
strcopy(gS_Color_Worse, 16, (sgType == Game_CSS)? "\x07CCCCCC":"\x08");
strcopy(gS_Color_Time, 16, (evType == Engine_CSS)? "\x07D490CF":"\x07");
strcopy(gS_Color_Rank, 16, (evType == Engine_CSS)? "\x077585E0":"\x05");
strcopy(gS_Color_Sync, 16, (evType == Engine_CSS)? "\x07B590D4":"\x06");
strcopy(gS_Color_Better, 16, (evType == Engine_CSS)? "\x07AD3BA6":"\x0C");
strcopy(gS_Color_Worse, 16, (evType == Engine_CSS)? "\x07CCCCCC":"\x08");
// mysql
Shavit_GetDB(gH_SQL);
@ -1417,7 +1417,12 @@ public void Shavit_OnFinish(int client, BhopStyle style, float time, int jumps,
UpdateWRCache();
}
float fDifference = (gF_PlayerRecord[client][style] - time) * -1.0;
float fDifference = (gF_PlayerRecord[client][style] - time);
if(fDifference < 0.0)
{
fDifference = -fDifference;
}
char[] sDifference = new char[16];
FormatSeconds(fDifference, sDifference, 16, true);
@ -1448,7 +1453,7 @@ public void Shavit_OnFinish(int client, BhopStyle style, float time, int jumps,
else // update
{
Shavit_PrintToChatAll("\x03%N\x01 finished (%s) in %s%s\x01 (%s#%d\x01) with %d jump%s, %d strafe%s%s\x01. %s(%s)", client, gS_BhopStyles[style], gS_Color_Time, sTime, gS_Color_Rank, iRank, jumps, (jumps != 1)? "s":"", strafes, (strafes != 1)? "s":"", sSync, gS_Color_Better, sDifference);
Shavit_PrintToChatAll("\x03%N\x01 finished (%s) in %s%s\x01 (%s#%d\x01) with %d jump%s, %d strafe%s%s\x01. %s(-%s)", client, gS_BhopStyles[style], gS_Color_Time, sTime, gS_Color_Rank, iRank, jumps, (jumps != 1)? "s":"", strafes, (strafes != 1)? "s":"", sSync, gS_Color_Better, sDifference);
FormatEx(sQuery, 512, "UPDATE %splayertimes SET time = %.03f, jumps = %d, date = %d, strafes = %d, sync = %.02f WHERE map = '%s' AND auth = '%s' AND style = '%d';", gS_MySQLPrefix, time, jumps, GetTime(), strafes, sync, gS_Map, sAuthID, style);
}

View File

@ -32,7 +32,7 @@
#define PLACEHOLDER 32767
ServerGame gSG_Type = Game_Unknown;
EngineVersion gEV_Type = Engine_Unknown;
Database gH_SQL = null;
bool gB_MySQL = false;
@ -149,8 +149,8 @@ public void OnAllPluginsLoaded()
public void OnPluginStart()
{
RegAdminCmd("sm_modifier", Command_Modifier, ADMFLAG_RCON, "Changes the axis modifier for the zone editor. Usage: sm_modifier <number>");
RegAdminCmd("sm_tpzone", Command_TPZone, ADMFLAG_RCON, "Defines the teleport zone so it teleports to the location you are in.");
// game specific
gEV_Type = GetEngineVersion();
// menu
RegAdminCmd("sm_zones", Command_Zones, ADMFLAG_RCON, "Opens the mapzones menu");
@ -159,6 +159,9 @@ public void OnPluginStart()
RegAdminCmd("sm_deletezone", Command_DeleteZone, ADMFLAG_RCON, "Delete a mapzone");
RegAdminCmd("sm_deleteallzones", Command_DeleteAllZones, ADMFLAG_RCON, "Delete all mapzones");
RegAdminCmd("sm_modifier", Command_Modifier, ADMFLAG_RCON, "Changes the axis modifier for the zone editor. Usage: sm_modifier <number>");
RegAdminCmd("sm_tpzone", Command_TPZone, ADMFLAG_RCON, "Defines the teleport zone so it teleports to the location you are in.");
// colors
SetupColors();
@ -331,8 +334,6 @@ public void OnMapStart()
RefreshZones();
}
gSG_Type = Shavit_GetGameType();
if(gCV_UseCustomSprite.BoolValue)
{
char[] sFile = new char[PLATFORM_MAX_PATH];
@ -385,7 +386,7 @@ public void OnMapStart()
else
{
if(gSG_Type == Game_CSS)
if(gEV_Type == Engine_CSS)
{
gI_BeamSprite = PrecacheModel("sprites/laser.vmt", true);
gI_HaloSprite = PrecacheModel("sprites/halo01.vmt", true);
@ -1148,7 +1149,7 @@ public int ZoneAdjuster_Handler(Menu menu, MenuAction action, int param1, int pa
(iPoint == 1? gV_Point1:gV_Point2)[param1][iAxis] += (bIncrease? gF_Modifier[param1]:-gF_Modifier[param1]);
Shavit_PrintToChat(param1, "\x03%c\x01 axis %s(point %d) \x04%s\x01 by \x03%.01f\x01.", sAxis[iAxis], gSG_Type == Game_CSGO? "\x0A":"\x05", iPoint, bIncrease? "increased":"decreased", gF_Modifier[param1]);
Shavit_PrintToChat(param1, "\x03%c\x01 axis %s(point %d) \x04%s\x01 by \x03%.01f\x01.", sAxis[iAxis], (gEV_Type == Engine_CSGO)? "\x0A":"\x05", iPoint, bIncrease? "increased":"decreased", gF_Modifier[param1]);
CreateAdjustMenu(param1, GetMenuSelectionPosition());
}
@ -1370,7 +1371,7 @@ public Action Timer_DrawEverything(Handle Timer, any data)
vPoints[0] = gV_FreestyleZones[j][0];
vPoints[7] = gV_FreestyleZones[j][1];
if(gSG_Type == Game_CSS)
if(gEV_Type == Engine_CSS)
{
vPoints[0][2] += 2.0;
vPoints[7][2] += 2.0;
@ -1407,7 +1408,7 @@ public Action Timer_DrawEverything(Handle Timer, any data)
vPoints[0] = gV_MapZones[i][0];
vPoints[7] = gV_MapZones[i][1];
if(gSG_Type == Game_CSS)
if(gEV_Type == Engine_CSS)
{
vPoints[0][2] += 2.0;
vPoints[7][2] += 2.0;
@ -1459,7 +1460,7 @@ public Action Timer_Draw(Handle Timer, any data)
vPoints[0] = gV_Point1[client];
vPoints[7] = vOrigin;
if(gSG_Type == Game_CSS)
if(gEV_Type == Engine_CSS)
{
vPoints[0][2] += 2.0;
vPoints[7][2] += 2.0;