Senior Member
|
12-30-2012
, 13:21
[TF2] Glow Plugin Rebuild Help
|
#1
|
G'day. I am looking to get some help in rebuilding an old plugin someone created for our servers a few years ago. The author isn't very active and thus can't provide any support in future changes to our servers.
I am looking to get the dependency of the menu removed as well as a double check on coding accuracy. We were not provided the source code for compiling it ourselves so all I can provide is a badly decompiled version of the source. This was decompiled using the Lysis online decompiler and thus might have errors. I have tried editing the code myself (only removing the requirement of the donatormenu.smx) and it seems decompiling it just produced too many issues. Is there anyone who could help me clean this code up as this is a gorgeous glow plugin and I'm sure others could benefit from it if it was cleaned up. I have my own menu I am looking to add this command into but without the old menu dependency being removed, am unable to do so.
Below is the coding after being decompiled.
Code:
public PlVers:__version =
{
version = 5,
filevers = "1.2.1-dev",
date = "09/12/2009",
time = "19:20:01"
};
new Float:NULL_VECTOR[3];
new String:NULL_STRING[1];
public Extension:__ext_core =
{
name = "Core",
file = "core",
autoload = 0,
required = 0,
};
new MaxClients;
public Extension:__ext_tf2 =
{
name = "TF2 Tools",
file = "game.tf2.ext",
autoload = 1,
required = 1,
};
public Extension:__ext_sdktools =
{
name = "SDKTools",
file = "sdktools.ext",
autoload = 1,
required = 1,
};
new String:TFResourceNames[18][0];
public Extension:__ext_topmenus =
{
name = "TopMenus",
file = "topmenus.ext",
autoload = 1,
required = 1,
};
public Plugin:myinfo =
{
name = "Donator Plugin: Glow",
description = "Grants donators glow effect",
author = "Wazz",
version = "1.0.0.0",
url = ""
};
new clientList[65];
new clientEnt[65];
new Handle:db;
public __ext_core_SetNTVOptional()
{
VerifyCoreVersion();
return 0;
}
Float:operator+(Float:,_:)(Float:oper1, oper2)
{
return oper1 + float(oper2);
}
bool:StrEqual(String:str1[], String:str2[], bool:caseSensitive)
{
return strcmp(str1, str2, caseSensitive) == 0;
}
GetEntSendPropOffs(ent, String:prop[], bool:actual)
{
decl String:cls[64];
if (!GetEntityNetClass(ent, cls, 64))
{
return -1;
}
if (actual)
{
return FindSendPropInfo(cls, prop, 0, 0, 0);
}
return FindSendPropOffs(cls, prop);
}
SetEntityRenderMode(entity, RenderMode:mode)
{
static bool:gotconfig;
static String:prop[8];
if (!gotconfig)
{
new Handle:gc = LoadGameConfigFile("core.games");
new bool:exists = GameConfGetKeyValue(gc, "m_nRenderMode", "", 32);
CloseHandle(gc);
if (!exists)
{
strcopy("", 32, "m_nRenderMode");
}
gotconfig = 1;
}
SetEntProp(entity, PropType:0, "", mode, 1);
return 0;
}
SetEntityRenderColor(entity, r, g, b, a)
{
static bool:gotconfig;
static String:prop[8];
if (!gotconfig)
{
new Handle:gc = LoadGameConfigFile("core.games");
new bool:exists = GameConfGetKeyValue(gc, "m_clrRender", "", 32);
CloseHandle(gc);
if (!exists)
{
strcopy("", 32, "m_clrRender");
}
gotconfig = 1;
}
new offset = GetEntSendPropOffs(entity, "", false);
if (0 >= offset)
{
ThrowError("SetEntityRenderColor not supported by this mod");
}
SetEntData(entity, offset, r, 1, true);
SetEntData(entity, offset + 1, g, 1, true);
SetEntData(entity, offset + 2, b, 1, true);
SetEntData(entity, offset + 3, a, 1, true);
return 0;
}
TFClassType:TF2_GetPlayerClass(client)
{
return GetEntProp(client, PropType:0, TFResourceNames, 4);
}
bool:isDonator(Client)
{
new AdminId:adminId = GetUserAdmin(Client);
if (GetAdminFlag(adminId, AdminFlag:15, AdmAccessMode:1))
{
return true;
}
return false;
}
public DB_OnPluginStart()
{
CreateDBConnection();
CreateDBTables();
return 0;
}
SaveSetting(Client)
{
decl String:query[128];
decl String:ConUsrSteamID[60];
GetClientAuthString(Client, ConUsrSteamID, 60);
if (clientList[Client][0][0])
{
var1 = 1;
}
else
{
var1 = 0;
}
Format(query, 128, "UPDATE Glow SET ONOFF = %i WHERE STEAMID = '%s'", var1, ConUsrSteamID);
SQL_TQuery(db, SQLErrorCheckCallback, query, any:0, DBPriority:1);
return 0;
}
GetSavedSetting(Client)
{
decl String:ConUsrSteamID[60];
decl String:query[128];
GetClientAuthString(Client, ConUsrSteamID, 60);
Format(query, 128, "SELECT ONOFF FROM `Glow` WHERE STEAMID = '%s'", ConUsrSteamID);
SQL_TQuery(db, T_GetSavedColor, query, Client, DBPriority:1);
return 0;
}
public T_GetSavedColor(Handle:owner, Handle:hndl, String:error[], Client)
{
if (!IsClientInGame(Client))
{
return 0;
}
if (hndl)
{
while (SQL_FetchRow(hndl))
{
clientList[Client] = SQL_FetchInt(hndl, 0, 0);
}
}
else
{
LogError("Query failed [#002]! %s", error);
}
return 0;
}
CreateDBConnection()
{
if (SQL_CheckConfig("donator"))
{
decl String:error[256];
db = SQL_Connect("donator", true, error, 256);
if (db)
{
LogMessage("DatabaseInit (CONNECTED) with donator config");
decl String:query[256];
Format(query, 256, "SET NAMES 'utf8'");
if (!SQL_FastQuery(db, query, -1))
{
LogError("Can't select character set (%s)", query);
}
}
else
{
SetFailState("Failed to connect: %s", error);
}
}
else
{
if (SQL_CheckConfig("default"))
{
decl String:error[256];
db = SQL_Connect("default", true, error, 256);
if (db)
{
LogMessage("DatabaseInit (CONNECTED) with default config");
decl String:query[256];
Format(query, 256, "SET NAMES 'utf8'");
if (!SQL_FastQuery(db, query, -1))
{
LogError("Can't select character set (%s)", query);
}
}
else
{
SetFailState("Failed to connect: %s", error);
}
}
SetFailState("Failed to connect: Cannot find any configuration in databases.cfg");
}
return 0;
}
CreateDBTables()
{
new len = 0;
decl String:query[192];
len = Format(query[len], 192 - len, "CREATE TABLE IF NOT EXISTS `Data`") + len;
len = Format(query[len], 192 - len, "(`name` TEXT, `datatxt` TEXT, `dataint` INTEGER);") + len;
SQL_TQuery(db, T_CheckDBUptodate1, query, any:0, DBPriority:1);
return 0;
}
public T_CheckDBUptodate1(Handle:owner, Handle:hndl, String:error[], data)
{
if (hndl)
{
decl String:buffer[64];
Format(buffer, 64, "SELECT dataint FROM `Data` where `name` = 'dbversion'");
SQL_TQuery(db, T_CheckDBUptodate2, buffer, any:0, DBPriority:1);
}
else
{
LogError("Query failed [#007]! %s", error);
}
return 0;
}
public T_CheckDBUptodate2(Handle:owner, Handle:hndl, String:error[], data)
{
if (hndl)
{
CreateDBGlow();
if (!SQL_GetRowCount(hndl))
{
decl String:buffer[96];
Format(buffer, 96, "INSERT INTO Data (`name`,`dataint`) VALUES ('dbversion', %i)", 10);
SQL_TQuery(db, SQLErrorCheckCallback, buffer, any:0, DBPriority:1);
}
new Client = 1;
while (Client <= MaxClients)
{
if (IsClientInGame(Client))
{
InitializeClientOnDB(Client);
Client++;
}
Client++;
}
}
else
{
LogError("Query failed [#008]! %s", error);
}
return 0;
}
InitializeClientOnDB(Client)
{
if (!isDonator(Client))
{
return 0;
}
decl String:ConUsrSteamID[60];
decl String:buffer[96];
GetClientAuthString(Client, ConUsrSteamID, 60);
Format(buffer, 96, "SELECT STEAMID FROM `Glow` WHERE STEAMID = '%s'", ConUsrSteamID);
SQL_TQuery(db, T_CheckConnectingUsr, buffer, Client, DBPriority:1);
return 0;
}
public T_CheckConnectingUsr(Handle:owner, Handle:hndl, String:error[], Client)
{
if (!IsClientInGame(Client))
{
return 0;
}
if (hndl)
{
decl String:ClientSteamID[60];
GetClientAuthString(Client, ClientSteamID, 60);
decl String:buffer[128];
if (!SQL_GetRowCount(hndl))
{
Format(buffer, 128, "INSERT INTO Glow (`STEAMID`) VALUES ('%s')", ClientSteamID);
SQL_TQuery(db, SQLErrorCheckCallback, buffer, any:0, DBPriority:1);
}
decl String:name[60];
GetClientName(Client, name, 60);
ReplaceString(name, 60, "'", "", true);
ReplaceString(name, 60, "<?", "", true);
ReplaceString(name, 60, "?>", "", true);
ReplaceString(name, 60, "\"", "", true);
Format(buffer, 128, "UPDATE Glow SET NAME = '%s' WHERE STEAMID = '%s'", name, ClientSteamID);
SQL_TQuery(db, SQLErrorCheckCallback, buffer, any:0, DBPriority:1);
GetSavedSetting(Client);
}
else
{
LogError("Query failed [#009]! %s", error);
}
return 0;
}
public SQLErrorCheckCallback(Handle:owner, Handle:hndl, String:error[], data)
{
if (!StrEqual("", error, true))
{
ResetPack(data, false);
decl String:query[256];
ReadPackString(data, query, 255);
LogError("SQL Error: %s", error);
LogError("Query: %s", query);
}
return 0;
}
CreateDBGlow()
{
new len = 0;
decl String:query[1000];
len = Format(query[len], 1000 - len, "CREATE TABLE IF NOT EXISTS `Glow` (") + len;
len = Format(query[len], 1000 - len, "`STEAMID` varchar(25) NOT NULL,") + len;
len = Format(query[len], 1000 - len, "`NAME` varchar(64) NOT NULL ,") + len;
len = Format(query[len], 1000 - len, "`ONOFF` int(1) NOT NULL default '0',") + len;
len = Format(query[len], 1000 - len, "PRIMARY KEY (`STEAMID`)") + len;
len = Format(query[len], 1000 - len, ") ENGINE=MyISAM DEFAULT CHARSET=utf8;") + len;
SQL_FastQuery(db, query, -1);
return 0;
}
public OnPluginStart()
{
DB_OnPluginStart();
RegAdminCmd("sm_glow", donatorGlow, 32768, "Sets a glow on self", "", 0);
HookEvent("player_changeclass", Event_changeClass, EventHookMode:1);
HookEvent("player_death", Event_playerDeath, EventHookMode:1);
HookEvent("player_spawn", Event_playerSpawn, EventHookMode:1);
HookEvent("teamplay_round_win", Event_winRound, EventHookMode:2);
return 0;
}
public OnClientPostAdminCheck(Client)
{
InitializeClientOnDB(Client);
return 0;
}
public OnClientDisconnect(Client)
{
if (isDonator(Client))
{
SaveSetting(Client);
}
clientList[Client] = 0;
clientEnt[Client] = 0;
return 0;
}
public Action:donatorGlow(client, args)
{
if (!IsClientInGame(client))
{
return Action:3;
}
if (!clientList[client][0][0])
{
new TFClassType:class = TF2_GetPlayerClass(client);
if (class == TFClassType:8)
{
PrintToChat(client, "\x04[Donator]:");
return Action:3;
}
new team = GetClientTeam(client);
if (team == 3)
{
AttachParticle(client, "teleporter_blue_entrance_level1");
SetEntityRenderMode(client, RenderMode:1);
SetEntityRenderColor(client, 0, 0, 255, 255);
}
if (team == 2)
{
AttachParticle(client, "teleporter_red_entrance_level1");
SetEntityRenderMode(client, RenderMode:1);
SetEntityRenderColor(client, 255, 0, 0, 255);
}
PrintToChat(client, "\x04[Donator]:");
}
else
{
DeleteParticle(clientEnt[client][0][0]);
clientList[client] = 0;
clientEnt[client] = 0;
SetEntityRenderMode(client, RenderMode:1);
SetEntityRenderColor(client, 255, 255, 255, 255);
PrintToChat(client, "\x04[Donator]:");
}
return Action:3;
}
AttachParticle(client, String:particleType[])
{
DeleteParticle(clientEnt[client][0][0]);
new particle = CreateEntityByName("info_particle_system", -1);
decl String:tName[128];
if (IsValidEdict(particle))
{
decl Float:pos[3];
GetEntPropVector(client, PropType:0, "m_vecOrigin", pos);
pos[2] += 10;
TeleportEntity(particle, pos, NULL_VECTOR, NULL_VECTOR);
Format(tName, 128, "target%i", client);
DispatchKeyValue(client, "targetname", tName);
DispatchKeyValue(particle, "targetname", "tf2particle");
DispatchKeyValue(particle, "parentname", tName);
DispatchKeyValue(particle, "effect_name", particleType);
DispatchSpawn(particle);
SetVariantString(tName);
AcceptEntityInput(particle, "SetParent", particle, particle, 0);
SetVariantString("head");
AcceptEntityInput(particle, "SetParentAttachment", particle, particle, 0);
ActivateEntity(particle);
AcceptEntityInput(particle, "start", -1, -1, 0);
clientEnt[client] = particle;
clientList[client] = 1;
}
return 0;
}
DeleteParticle(particle)
{
if (IsValidEntity(particle))
{
decl String:classname[256];
GetEdictClassname(particle, classname, 256);
if (StrEqual(classname, "info_particle_system", false))
{
RemoveEdict(particle);
}
}
return 0;
}
public Action:Event_changeClass(Handle:event, String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new class = GetEventInt(event, "class");
if (class == 8)
{
DeleteParticle(clientEnt[client][0][0]);
clientEnt[client] = 0;
SetEntityRenderMode(client, RenderMode:1);
SetEntityRenderColor(client, 255, 255, 255, 255);
PrintToChat(client, "\x04[Donator]:");
}
return Action:0;
}
public Action:Event_playerDeath(Handle:event, String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (clientList[client][0][0] == 1)
{
DeleteParticle(clientEnt[client][0][0]);
clientEnt[client] = 0;
}
return Action:0;
}
public Action:Event_playerSpawn(Handle:event, String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new team = GetClientTeam(client);
if (clientList[client][0][0] == 1)
{
if (team == 3)
{
AttachParticle(client, "teleporter_blue_entrance_level1");
SetEntityRenderMode(client, RenderMode:1);
SetEntityRenderColor(client, 0, 0, 255, 255);
}
if (team == 2)
{
AttachParticle(client, "teleporter_red_entrance_level1");
SetEntityRenderMode(client, RenderMode:1);
SetEntityRenderColor(client, 255, 0, 0, 255);
}
}
return Action:0;
}
public Action:Event_winRound(Handle:event, String:name[], bool:dontBroadcast)
{
new client = 1;
while (client <= MaxClients)
{
if (clientList[client][0][0] == 1)
{
DeleteParticle(clientEnt[client][0][0]);
clientEnt[client] = 0;
SetEntityRenderMode(client, RenderMode:1);
SetEntityRenderColor(client, 255, 255, 255, 255);
client++;
}
client++;
}
return Action:0;
}
So basically: Currently the plugin requires the existence of a donatormenu.smx, which I want to see if the dependency can be removed. I'm trying to get this to be a standalone plugin with no actual interface....just need the command itself to function properly as I have my own menu to add it into. Would like the admin flag checked to be Custom1 or "o" to be exact.
For anyone who is curious what it does or interested in results: This plugin does grant users a glow effect as well as a teleporter type ring particle effect. The effects will stay through death, class change, team change, etc. I forgot if it stays on through map change or not.
Last edited by KiRRA; 12-30-2012 at 13:31.
|
|