Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functionality Extension #99

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions addons/sourcemod/configs/influx/tabranks.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"SVG ranks"
{
/*
* Type of icons pack
*
* 0 - MM(1-18)
* 1 - Partners (1-18)
* 2 - DZ(1-15)
* 3 - Custom (1 - ...)
*
*
* If type - custom:
* Filename: skillgroup + number => "skillgroup101"
* Number: num > 100 => 101
* Fill in below: "group" "number - 100" => 100 - const
* Example: "[1LVL]" "1" => if number = 101, then 101 - 100 = 1
*
*/
"IconType" "3"


/*
* Rankname - case-sensitivity
*/
"[Just joined]" "1"
"[Noob]" "2"
"I swear I'm not a bot!" "3"
"It's ok to be gay" "4"
"I only play for the ranks xD xD" "5"
"[Apprentice]" "6"
"[Casual]" "7"
"[Amateur]" "8"
"[Trained]" "9"
"[Skilled]" "10"
"[Experienced]" "11"
"[Pro]" "12"
"[Expert]" "13"
"[Veteran]" "14"
"[1337h@x0r]" "15"
"[bhop_badges is 2 ez]" "16"
"[Forest was never good]" "17"
"[Synki is my bitch]" "18"

}
1 change: 1 addition & 0 deletions addons/sourcemod/scripting/include/influx/core.inc
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ native bool Influx_SetClientMode( int client, int mode );

native int Influx_GetClientStyle( int client );
native bool Influx_SetClientStyle( int client, int style );
native bool Influx_SetClientStyleEx( int client, int style, bool bTele );


// When client's run, mode or style has changed.
Expand Down
58 changes: 58 additions & 0 deletions addons/sourcemod/scripting/include/influx/tabranks.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#if defined _influx_tabranks_included
#endinput
#endif
#define _influx_tabranks_included

/*
* On Client rank name already read
*
* @param iClient Client index
* @param szRankname Client rankname with out colors (fl. copyback)
* @param iSize size of string
*
*
* @noreturn
*/
forward void Influx_trank_OnGetRank(int iClient, char[] szRankname, int iSize);

/*
* Status of send fake rank to client was changed
*
* @param iClient Client index
* @param oldVal old Value
* @param newVal new value
* @param IsNative who changed
*
*
* @noreturn
*/
forward void Influx_trank_SendToClient(int iClient, bool oldVal, bool newVal, bool IsNative);


/*
* Change status of send fake rank to client
*
* @param iClient Client index
* @param value True - send| false - otherwise
*
* @return true - changed success, false - invalid client index
*/
native bool influx_trank_SendToClient(int iClient, bool value);

public SharedPlugin __pl_influx_tabranks =
{
name = "influx_tabranks",
file = "influx_tabranks_csgo.smx",
#if defined REQUIRE_PLUGIN
required = 1
#else
required = 0
#endif
};

#if !defined REQUIRE_PLUGIN
public void __pl_influx_tabranks_SetNTVOptional()
{
MarkNativeAsOptional("influx_trank_SendToClient");
}
#endif
1 change: 1 addition & 0 deletions addons/sourcemod/scripting/influx_core.sp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ public APLRes AskPluginLoad2( Handle hPlugin, bool late, char[] szError, int err

CreateNative( "Influx_GetClientStyle", Native_GetClientStyle );
CreateNative( "Influx_SetClientStyle", Native_SetClientStyle );
CreateNative( "Influx_SetClientStyleEx", Native_SetClientStyleEx );



Expand Down
7 changes: 7 additions & 0 deletions addons/sourcemod/scripting/influx_core/natives.sp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public int Native_SetClientStyle( Handle hPlugin, int nParms )
return SetClientStyle( client, GetNativeCell( 2 ) );
}

public int Native_SetClientStyleEx( Handle hPlugin, int nParms )
{
int client = GetNativeCell( 1 );

return SetClientStyle( client, GetNativeCell( 2 ), view_as<bool>(GetNativeCell(3)) );
}

public int Native_GetRunName( Handle hPlugin, int nParms )
{
int len = GetNativeCell( 3 );
Expand Down
222 changes: 222 additions & 0 deletions addons/sourcemod/scripting/influx_tabranks_csgo.sp
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
#include influx/core
#include influx/simpleranks

#pragma newdecls required

#define MPL MAXPLAYERS+1
#define MNL MAX_NAME_LENGTH // 128
#define CONFIG_PATH "configs/influx/tabranks.ini"

int comp_offset = -1;

bool sendToClient[MPL] = {true, ...};
char clientrank[MPL][MNL];

ArrayList tabranks;

public Plugin myinfo =
{
name = "[Influx] FakeRanks",
author = "nullent?",
description = "...",
version = "1.0",
url = "discord.gg/ChTyPUG"
};


public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
if(GetEngineVersion() != Engine_CSGO)
{
FormatEx(error, err_max, "Game engine is not supported");
return APLRes_Failure;
}

CreateNative("influx_trank_SendToClient", Native_SendToClient);

RegPluginLibrary("influx_tabranks");

return APLRes_Success;
}

public int Native_SendToClient(Handle hPlugin, int args)
{
int client = GetNativeCell(1);

if(!client || !IsClientInGame(client) || IsFakeClient(client)){
return false;
}

sendToClient[client] = view_as<bool>(GetNativeCell(2));

_local_Influx_ChangeRights(client, !sendToClient[client], sendToClient[client], true);
return true;
}

public void OnClientPutInServer(int client)
{
sendToClient[client] = true;
_local_Influx_ChangeRights(client, !sendToClient[client], sendToClient[client]);

RequestFrame(OnFrameReq, client);
}

public void OnMapStart()
{
char fullpath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, fullpath, sizeof(fullpath), CONFIG_PATH);

if(!FileExists(fullpath)){
SetFailState("Where is my config file: %s ?", fullpath);
}

parseConfig(fullpath);

SDKHook(GetPlayerResourceEntity(), SDKHook_ThinkPost, OnThinkPost);
}

void parseConfig(const char[] config)
{
tabranks.Clear();

SMCParser parser = new SMCParser();
parser.OnKeyValue = OnKeyValueRead;
parser.OnEnd = OnParseEnd;

int iLine;
if(parser.ParseFile(config, iLine) != SMCError_Okay)
LogError("Error on parse settings file: | %s | on | %d | line", config, iLine);
}

int IconType;

public SMCResult OnKeyValueRead(SMCParser SMC, const char[] sKey, const char[] sValue, bool bKey_quotes, bool bValue_quotes)
{
if(!sValue[0] || !sKey[0]){
return SMCParse_Continue;
}

if(!strcmp(sKey, "IconType"))
{
switch(StringToInt(sValue))
{
case 0: IconType = 0;
case 1: IconType = 50;
case 2: IconType = 70;
case 3: IconType = 100;
}

}
else
{
tabranks.PushString(sKey);
tabranks.Push(StringToInt(sValue) + IconType);
}

return SMCParse_Continue;
}

public void OnParseEnd(SMCParser smc, bool halted, bool failed)
{
char buffer[MNL]; int iIndex;

for(int i = 1; i < tabranks.Length; i+=2)
{
iIndex = tabranks.Get(i);
if(iIndex > 100)
{
FormatEx(buffer, sizeof(buffer), "materials/panorama/images/icons/skillgroups/skillgroup%i.svg", iIndex);
AddFileToDownloadsTable(buffer);
}
}
}

public void OnFrameReq(any data)
{
if(IsFakeClient(data)){
return;
}

Influx_GetClientSimpleRank(data, clientrank[data], sizeof(clientrank[]));
}

public void OnThinkPost(int ent)
{
static int i;
i = 0;

while(i++ < MaxClients)
{
if(!IsClientInGame(i) || IsFakeClient(i) || !sendToClient[i] || tabranks.FindString(clientrank[i]) == -1){
continue;
}

SetEntData(ent, comp_offset + i * 4, tabranks.Get(tabranks.FindString(clientrank[i]) + 1));
}
}

public void OnPlayerRunCmdPost(int client, int buttons)
{
static int iOldButtons[MAXPLAYERS+1];

if(buttons & IN_SCORE && !(iOldButtons[client] & IN_SCORE))
{
StartMessageOne("ServerRankRevealAll", client, USERMSG_BLOCKHOOKS);
EndMessage();
}

iOldButtons[client] = buttons;
}

public void OnPluginStart()
{
tabranks = new ArrayList(MNL, 0);
comp_offset = FindSendPropInfo("CCSPlayerResource", "m_iCompetitiveRanking");

CreateTimer(10.0, UpdateClientRank, _, TIMER_REPEAT);
}

public Action UpdateClientRank(Handle timer, any data)
{
static int i;

while(i++ < MaxClients)
{
if(!IsClientInGame(i) || IsFakeClient(i) || !sendToClient[i]){
continue;
}

Influx_GetClientSimpleRank(i, clientrank[i], sizeof(clientrank[]));
Influx_RemoveChatColors(clientrank[i], sizeof(clientrank[]));
_local_Influx_OnRankGetting(i, clientrank[i], sizeof(clientrank[]));
}

i = 0;
}

void _local_Influx_OnRankGetting(int client, char[] rank, int size)
{
static Handle gf;
if(!gf)
gf = CreateGlobalForward("Influx_trank_OnGetRank", ET_Ignore, Param_Cell, Param_String, Param_Cell);

Call_StartForward(gf);
Call_PushCell(client);
Call_PushStringEx(rank, size, SM_PARAM_COPYBACK|SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK);
Call_PushCell(size);
Call_Finish();
}

void _local_Influx_ChangeRights(int client, bool oldVal, bool newVal, bool IsNative = false)
{
static Handle gf;
if(!gf)
gf = CreateGlobalForward("Influx_trank_SendToClient", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell);

Call_StartForward(gf);
Call_PushCell(client);
Call_PushCell(oldVal);
Call_PushCell(newVal);
Call_PushCell(IsNative);
Call_Finish();
}
Loading