8 changes: 3 additions & 5 deletions src/karyuu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@
#define CS_SLOT_UTILITY 12 /* Slot for tablet */
#endif

#include <karyuu/defines>

#include <karyuu/variable/strings>
#include <karyuu/variable/bit>
#include <karyuu/variable/convert>
#include <karyuu/variable/datetime>
#include <karyuu/variable/float>
#include <karyuu/variable/gamedata>
#include <karyuu/variable/handles>
#include <karyuu/variable/int>
#include <karyuu/variable/random>
#include <karyuu/variable/strings>

#include <karyuu/game/team>
#include <karyuu/game/game>
Expand All @@ -57,7 +56,6 @@
#include <karyuu/prop>
#include <karyuu/offset>
#include <karyuu/entity>
#include <karyuu/dump>
#include <karyuu/client>
#include <karyuu/weapon>
#include <karyuu/menu>
Expand Down
33 changes: 14 additions & 19 deletions src/karyuu/client.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
#endif
#define _KARYUU_MODULE_CLIENT_INCLUDED_

#define MAX_AUTH_LENGTH 21
#define MAX_IP_LENGTH 23

#define KARYUU_LOOP_CLIENTS(%1) for (int %1 = 1; %1 <= MaxClients; %1++) if (IsClientInGame(%1))
#define KARYUU_LOOP_PLAYERS(%1) for (int %1 = 1; %1 <= MaxClients; %1++) if (IsClientInGame(%1) && !IsFakeClient(%1))

enum WaterLevel
{
WL_NotInWater = 0,
Expand Down Expand Up @@ -62,12 +56,12 @@ stock bool Karyuu_IsClientInVehicle(int iClient)

stock bool Karyuu_IsClientCrouching(int iClient)
{
return GetEntityFlags(iClient) & FL_DUCKING;
return view_as<bool>(GetEntityFlags(iClient) & FL_DUCKING);
}

stock bool Karyuu_IsClientOnGround(int iClient)
{
return GetEntityFlags(iClient) & FL_ONGROUND;
return view_as<bool>(GetEntityFlags(iClient) & FL_ONGROUND);
}

stock bool Karyuu_IsClientOnLadder(int iClient)
Expand Down Expand Up @@ -351,11 +345,11 @@ stock void Karyuu_SetThirdPerson(int iClient)
SetEntPropEnt(iClient, Prop_Send, "m_hObserverTarget", 0);
SetEntProp(iClient, Prop_Send, "m_iObserverMode", 1);
SetEntProp(iClient, Prop_Send, "m_bDrawViewmodel", 0);
SetEntProp(clieiClientnt, Prop_Send, "m_iFOV", 120);
SetEntProp(iClient, Prop_Send, "m_iFOV", 120);
}
}

stock void Karyuu_SetFirstPerson(int client)
stock void Karyuu_SetFirstPerson(int iClient)
{
if (Karyuu_IsValidClient(iClient))
{
Expand All @@ -378,10 +372,11 @@ stock void Karyuu_ToggleThirdPerson(int iClient)

stock void Karyuu_RadarVisibilityToggle(int iClient, bool bStatus)
{
static int iOffset = FindSendPropInfo("CBaseEntity", "m_bSpotted");
int iOffset = FindSendPropInfo("CBaseEntity", "m_bSpotted");

if (iOffset > 0)
{
static Address g_aCanBeSpotted = view_as<Address>(iOffset - 4);
Address g_aCanBeSpotted = view_as<Address>(iOffset - 4);

if (bStatus)
{
Expand All @@ -398,8 +393,8 @@ stock void Karyuu_RadarVisibilityToggle(int iClient, bool bStatus)

stock int Karyuu_FindBySteamId(const char[] szAuth, AuthIdType iType)
{
int iMax = GetMaxClients();
char szTempAuth[MAX_AUTH_LENGTH];
int iMax = MaxClients;
char szTempAuth[Karyuu_MAX_AUTH_LENGTH];

for (int iClient = 0; iClient < iMax; iClient++)
{
Expand Down Expand Up @@ -445,7 +440,7 @@ stock bool Karyuu_GetClientCrosshairOrigin(int iClient, float fOrigin[3], bool b

stock bool Karyuu_TraceEntityFilterPlayer(int iEntity, int iMask, any aData)
{
return iEntity > GetMaxClients() || !iEntity;
return iEntity > MaxClients || !iEntity;
}

stock bool Karyuu_TraceEntityFilterNone(int iEntity, int iMask, any aData)
Expand Down Expand Up @@ -484,7 +479,7 @@ stock int Karyuu_GetObserverTarget(int iClient)
return GetEntPropEnt(iClient, Prop_Send, "m_hObserverTarget");
}

stock int Karyuu_SetObserverTarget(int iClient, int iEntity)
stock void Karyuu_SetObserverTarget(int iClient, int iEntity)
{
SetEntPropEnt(iClient, Prop_Send, "m_hObserverTarget", iEntity);
}
Expand All @@ -494,7 +489,7 @@ stock int Karyuu_GetFOV(int iClient)
return GetEntProp(iClient, Prop_Send, "m_iFOV");
}

stock int Karyuu_SetFOV(int iClient, int iValue)
stock void Karyuu_SetFOV(int iClient, int iValue)
{
SetEntProp(iClient, Prop_Send, "m_iFOV", iValue);
}
Expand All @@ -504,14 +499,14 @@ stock bool Karyuu_IsInThirdPerson(int iClient)
return view_as<bool>(GetEntProp(iClient, Prop_Data, "m_iObserverMode"));
}

stock void Karyuu_LastLocation(int iClient, const char[] sBuffer, int iLength)
stock void Karyuu_LastLocation(int iClient, char[] sBuffer, int iLength)
{
GetEntPropString(iClient, Prop_Send, "m_szLastPlaceName", sBuffer, iLength);
}

stock int Karyuu_GetScore(int iClient)
{
return GetClientFrags(client);
return GetClientFrags(iClient);
}

stock void Karyuu_SetScore(int iClient, int iValue)
Expand Down
46 changes: 46 additions & 0 deletions src/karyuu/defines.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#if defined _KARYUU_MODULE_DEFINES_INCLUDED_
#endinput
#endif
#define _KARYUU_MODULE_DEFINES_INCLUDED_

#define STRING(%1) %1, sizeof(%1)

#define Karyuu_MAX(% 0, % 1) (((% 0) > (% 1)) ? (% 0) : (% 1))

#define Karyuu_MAX_INTEGER_VALUE 2147483647
#define Karyuu_MAX_INTEGER_LENGTH 16
#define Karyuu_MAX_FLOAT_LENGTH 32
#define Karyuu_MAX_QUERY_SIZE 2048
#define Karyuu_MAX_MAP_NAME_LENGTH 64
#define Karyuu_MAX_CONVAR_VALUE_SIZE 256
#define Karyuu_MAX_AUTH_LENGTH 21
#define Karyuu_CONVERT_AUTH_LENGTH 64
#define Karyuu_MAX_IP_LENGTH 23
#define Karyuu_MAX_MESSAGE_LENGTH 512

#define KARYUU_LOOP_CLIENTS(%1) for (int %1 = 1; %1 <= MaxClients; %1++) if (IsClientInGame(%1))
#define KARYUU_LOOP_PLAYERS(%1) for (int %1 = 1; %1 <= MaxClients; %1++) if (IsClientInGame(%1) && !IsFakeClient(%1))

#define Karyuu_MAX_WEAPON_CLASSNAME_LENGTH 24
#define Karyuu_MAX_WEAPON_NAME_LENGTH 48
#define Karyuu_MAX_WEAPON_PREFIX_LENGTH 6
#define Karyuu_MAX_WEAPONS 48

#define Karyuu_HITGROUP_GENERIC 0
#define Karyuu_HITGROUP_HEAD 1
#define Karyuu_HITGROUP_CHEST 2
#define Karyuu_HITGROUP_STOMACH 3
#define Karyuu_HITGROUP_LEFTARM 4
#define Karyuu_HITGROUP_RIGHTARM 5
#define Karyuu_HITGROUP_LEFTLEG 6
#define Karyuu_HITGROUP_RIGHTLEG 7
#define Karyuu_HITGROUP_GEAR 10

#define Karyuu_HEGrenadeOffset 14
#define Karyuu_FlashbangOffset 15
#define Karyuu_SmokegrenadeOffset 16
#define Karyuu_IncGrenadesOffset 17
#define Karyuu_DecoyGrenadeOffset 18
#define Karyuu_HealthShotOffset 21

#define Karyuu_MAX_ENTITY_LIMIT 4097
4 changes: 0 additions & 4 deletions src/karyuu/dump.inc

This file was deleted.

7 changes: 2 additions & 5 deletions src/karyuu/entity.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
#endif
#define _KARYUU_MODULE_ENTITY_INCLUDED_

#define MAX_ENTITY_LIMIT 4096 + 1

stock bool Karyuu_IsValidEntity(int iEntity)
{
if (!iEntity || iEntity < MaxClients || iEntity > MAX_ENTITY_LIMIT)
if (!iEntity || iEntity < MaxClients || iEntity > Karyuu_MAX_ENTITY_LIMIT)
return false;

return IsValidEntity(iEntity);
Expand Down Expand Up @@ -43,7 +41,7 @@ stock bool Karyuu_SetClassName(int iEntity, const char[] cClassName)
return DispatchKeyValue(iEntity, "classname", cClassName);
}

stock bool Karyuu_ClassNameMatches(int iEntity, const char[] cClassName, bool bPartialMatch = false)
stock bool Karyuu_ClassNameMatches(int iEntity, char[] cClassName, bool bPartialMatch = false)
{
char cEntityClassName[64];
Karyuu_GetClassName(iEntity, STRING(cEntityClassName));
Expand Down Expand Up @@ -73,7 +71,6 @@ stock int Karyuu_GetClosestToEntity(int iEntity, bool bOnlyClients = false)
stock int Karyuu_GetClosest(float fOriginVec[3], bool bOnlyClients = false)
{
float fTempVec[3], fSmallestDistance = 0.0, fTempDistance;
float;
int iClosest = INVALID_ENT_REFERENCE;

int iMaxEntities = bOnlyClients ? MaxClients : GetMaxEntities();
Expand Down
8 changes: 4 additions & 4 deletions src/karyuu/game/game.inc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ stock void Karyuu_PauseMatch(int iTime = 0, int iTeam = CS_TEAM_NONE)
{
ServerCommand("mp_pause_match");

if (csTeam == CS_TEAM_T)
if (iTeam == CS_TEAM_T)
{
GameRules_SetProp("m_bTerroristTimeOutActive", true);
GameRules_SetPropFloat("m_flTerroristTimeOutRemaining", float(iTime));
Expand Down Expand Up @@ -131,10 +131,10 @@ stock RoundState Karyuu_GetRoundState()

stock GamePhase Karyuu_GetGamePhase()
{
return Karyuu_GetPropBool("m_gamePhase");
return view_as<GamePhase>(GameRules_GetProp("m_gamePhase"));
}

stock bool Karyuu_IsWarmUpPeriod()
stock bool Karyuu_IsWarmupPeriod()
{
return Karyuu_GetPropBool("m_bWarmupPeriod");
}
Expand Down Expand Up @@ -194,7 +194,7 @@ stock bool Karyuu_IsTVEnabled()

stock int Karyuu_GetTvDelay()
{
return (Karyuu_IsTVEnabled() ? GetCvarIntSafe("tv_delay") : 0);
return (Karyuu_IsTVEnabled() ? Karyuu_GetConVarIntSafe("tv_delay") : 0);
}

stock bool Karyuu_StartRecord(const char[] cDemo)
Expand Down
20 changes: 15 additions & 5 deletions src/karyuu/game/team.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,37 @@ stock int Karyuu_GetTeamIndex(int iTeam)

stock void Karyuu_SetTeamName(int iTeam, const char[] cValue)
{
Karyuu_SetConVarStringSafe(Karyuu_StringBuilder("mp_teamname_%d", Karyuu_GetTeamIndex(iTeam)), cValue);
char sBuffer[64];
FormatEx(STRING(sBuffer), "mp_teamname_%d", Karyuu_GetTeamIndex(iTeam));
Karyuu_SetConVarStringSafe(sBuffer, cValue);
}

stock void Karyuu_SetTeamLogo(int iTeam, const char[] cValue)
{
Karyuu_SetConVarStringSafe(Karyuu_StringBuilder("mp_teamlogo_%d", Karyuu_GetTeamIndex(iTeam)), cValue);
char sBuffer[64];
FormatEx(STRING(sBuffer), "mp_teamlogo_%d", Karyuu_GetTeamIndex(iTeam));
Karyuu_SetConVarStringSafe(sBuffer, cValue);
}

stock void Karyuu_SetTeamFlag(int iTeam, const char[] cValue)
{
Karyuu_SetConVarStringSafe(Karyuu_StringBuilder("mp_teamflag_%d", Karyuu_GetTeamIndex(iTeam)), cValue);
char sBuffer[64];
FormatEx(STRING(sBuffer), "mp_teamlogo_%d", Karyuu_GetTeamIndex(iTeam));
Karyuu_SetConVarStringSafe(sBuffer, cValue);
}

stock void Karyuu_SetTeamScore(int iTeam, int iValue)
{
Karyuu_SetConVarIntSafe(Karyuu_StringBuilder("mp_teamscore_%d", Karyuu_GetTeamIndex(iTeam)), iValue);
char sBuffer[64];
FormatEx(STRING(sBuffer), "mp_teamscore_%d", Karyuu_GetTeamIndex(iTeam));
Karyuu_SetConVarIntSafe(sBuffer, iValue);
}

stock void Karyuu_SetTeamText(int iTeam, const char[] cValue)
{
Karyuu_SetConVarStringSafe(Karyuu_StringBuilder("mp_teammatchstat_%d", Karyuu_GetTeamIndex(iTeam)), cValue);
char sBuffer[64];
FormatEx(STRING(sBuffer), "mp_teammatchstat_%d", Karyuu_GetTeamIndex(iTeam));
Karyuu_SetConVarStringSafe(sBuffer, cValue);
}

stock void Karyuu_SetTeamData(int iTeam, const char[] cName, const char[] cFlag = "", const char[] cLogo = "", const char[] cText = "", int iScore = 0)
Expand Down
13 changes: 3 additions & 10 deletions src/karyuu/menu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@

stock bool Karyuu_ClearClientMenu(int iClient)
{
if (!Karyuu_IsClientIndex(iClient) || IsFakeClient(iClient) || !IsClientInGame(iClient))
if (!IsClientConnected(iClient) || IsFakeClient(iClient))
return false;

CancelClientMenu(iClient);

Panel panel = new Panel();
panel.Send(iClient, __Karyuu_Panel_Void, 1);
delete panel;

return true;
return CancelClientMenu(iClient);
}
public int __Karyuu_Panel_Void(Menu menu, MenuAction action, int param1, int param2) { delete menu; }

stock void Karyuu_Menu_SetTitle(Menu menu, const char[] myString, any...)
{
Expand All @@ -36,7 +29,7 @@ stock void Karyuu_Menu_AddItem(Menu menu, int ItemDraw = ITEMDRAW_DEFAULT, char[
menu.AddItem(id, myFormattedString, ItemDraw);
}

stock char Karyuu_Menu_GetSelect(Menu menu, int iParam)
stock char[] Karyuu_Menu_GetSelect(Menu menu, int iParam)
{
char cBuffer[32];
GetMenuItem(menu, iParam, STRING(cBuffer));
Expand Down
45 changes: 0 additions & 45 deletions src/karyuu/plugin/benchmark.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,6 @@

#include <profiler>

static bool bBenchmarkState;

stock void Karyuu_ToggleProfiling()
{
char sTime[32];

if (!start)
{
delete g_hTimer;

FormatTime(sTime, sizeof(sTime), "%F_%H-%M-%S", GetTime());
FormatEx(g_PathProfilerLog, sizeof(g_PathProfilerLog), "%s_%s.log", g_PathPrefix, sTime);

if (g_bL4D2)
{
g_ptrFile = FileSize(g_PathCosole);
}
else {
SetCvarSilent(g_CVarLogFile, g_PathProfilerLog);
}

ReplyToCommand(client, "\x04[START]\x05 Profiler is started...");
ServerCommand("vprof_on");
ServerExecute();
RequestFrame(OnFrameDelay);
}
else
{
ServerCommand("sm prof stop vprof");
ServerCommand("sm prof dump vprof");
ServerCommand("vprof_off");
ReplyToCommand(client, "\x04[STOP]\x05 Saving profiler log to: %s", g_PathProfilerLog);

// Profiler needs some time for analysis
g_hTimer = CreateTimer(60.0, Timer_RestoreCvar);
}
bBenchmarkState = !bBenchmarkState;
}

stock void OnFrameDelay()
{
ServerCommand("sm prof start vprof");
Expand All @@ -57,12 +18,6 @@ stock void SetCvarSilent(ConVar cvar, char[] value)
cvar.Flags = flags;
}

stock Action Timer_RestoreCvar(Handle timer)
{
SetCvarSilent(g_CVarLogFile, g_PathOrig);
g_hTimer = null;
}

stock void Karyuu_Benchmark(Function func, const char[] name, int iterations)
{
Profiler profile = new Profiler();
Expand Down