Compare commits

...

5 Commits

Author SHA1 Message Date
Scott Thomas
af04340315
Update README.md 2021-07-30 21:35:22 -06:00
kidfearless
4be595269c
Merge pull request #3 from hermansimensen/master
Support for CSS
2020-10-06 10:54:47 -06:00
hermansimensen
54f3d26fd2 css support 2020-10-06 18:44:57 +02:00
KiD Fearless
153e7b10ce Potential memory leak fix 2019-12-24 09:23:08 -07:00
KiD Fearless
3ca6c6dc54 INCLUDE_VERSION 2
Added preprocessor compiler error if the plugin is compiled on an outdated version of the include.

Attempted to transfer ownership of native handles again.

Don't save empty entities.

Added extra safe guards for possible memory leak locations.
2019-12-18 08:02:33 -07:00
3 changed files with 67 additions and 19 deletions

View File

@ -1,3 +1,5 @@
# WARNING DOES NOT WORK ANYMORE AFTER THIS COMMIT https://github.com/alliedmodders/sourcemod/pull/1534
# Output Info Plugin
Output Info Plugin is a mostly extension free alternative to slidybat's [OutputInfo extension](https://github.com/SlidyBat/sm-ext-outputinfo). Output Info Plugin takes the map entities string from `OnLevelInit` and stores the relevant information in enum structs. The plugin will create it's own implementation of the OutputInfo natives if none can be found. As long as the plugin calling the natives doesn't have OutputInfo as a required extension then Output Info Plugin can handle them.

View File

@ -5,6 +5,7 @@
#define OUTPUT_SIZE 2048
#define MEMBER_SIZE 128
#define INCLUDE_VERSION 3
// set to 0 to use stocks instead of native
#define USE_NATIVES 1
@ -44,7 +45,14 @@ enum struct Output
{
// Break it up into more managable parts
char entity[OUTPUTSIZE][MEMBER_SIZE];
ExplodeString(buffer, "\e", entity, OUTPUTSIZE, MEMBER_SIZE);
if(GetEngineVersion() == Engine_CSS)
{
ExplodeString(buffer, ",", entity, OUTPUTSIZE, MEMBER_SIZE);
} else
{
ExplodeString(buffer, "\e", entity, OUTPUTSIZE, MEMBER_SIZE);
}
this.Target = entity[TARGETENTITY];
this.Input = entity[OUTPUTNAME];
@ -139,8 +147,9 @@ enum struct Entity
}
// #endregion
// #region outputs
delete this.OutputList;
ArrayList outputList = new ArrayList(sizeof(Output));
this.OutputList = new ArrayList(sizeof(Output));
Regex outputMatch = new Regex("(\"On\\w*\") (\"[^\"]+\")");
for(int i = 0; i < inputLength && outputMatch.Match(input[i]) > 0; i += outputMatch.MatchOffset())
@ -156,13 +165,12 @@ enum struct Entity
StripQuotes(parameters);
output.Parse(parameters);
outputList.PushArray(output);
this.OutputList.PushArray(output);
}
delete outputMatch;
this.OutputList = outputList;
// #endregion
}
}
@ -173,12 +181,15 @@ enum struct Entity
*
* return: noreturn
**/
stock void CloneEntity(const Entity input, Entity out)
stock void CloneEntity(const Entity input, Entity out, Handle newOwner = INVALID_HANDLE)
{
out.HammerID = input.HammerID;
out.Classname = input.Classname;
out.Wait = input.Wait;
out.OutputList = input.OutputList.Clone();
ArrayList list = input.OutputList.Clone();
out.OutputList = view_as<ArrayList>(CloneHandle(list, newOwner));
delete list;
}
/**
@ -308,6 +319,7 @@ stock int GetOutputCount(int index, const char[] output = "")
Entity ent;
if(!GetOutputEntity(index, ent))
{
ent.CleanUp();
return -1;
}
@ -349,6 +361,7 @@ stock bool GetOutputTarget(int index, const char[] output, int num, char[] targe
Entity ent;
if(!GetOutputEntity(index, ent))
{
ent.CleanUp();
return false;
}
@ -399,6 +412,7 @@ stock bool GetOutputTargetInput(int index, const char[] output, int num, char[]
Entity ent;
if(!GetOutputEntity(index, ent))
{
ent.CleanUp();
return false;
}
@ -450,6 +464,7 @@ stock bool GetOutputParameter(int index, const char[] output, int num, char[] pa
Entity ent;
if(!GetOutputEntity(index, ent))
{
ent.CleanUp();
return false;
}
@ -499,6 +514,7 @@ stock float GetOutputDelay(int index, const char[] output, int num)
Entity ent;
if(!GetOutputEntity(index, ent))
{
ent.CleanUp();
return -1.0;
}

View File

@ -2,12 +2,14 @@
#include <regex>
#include <output_info_plugin>
#define PLUGIN_VERSION 3
public Plugin myinfo =
{
name = "Output Info Plugin",
author = "KiD Fearless",
description = "Plugin Alternative To Output Info",
version = "2.0.1",
version = "2.0.3",
url = "https://github.com/kidfearless"
}
@ -20,6 +22,12 @@ GlobalForward gF_OnEntitiesReady;
bool gB_Ready;
#if PLUGIN_VERSION != INCLUDE_VERSION
// Closest thing to a compile time error that we can get
// The include file for this plugin contains code that may need to be updated.
Please__update__your__include__to__match__plugins__version
#endif
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
#if USE_NATIVES == 1
@ -68,17 +76,36 @@ public void OnPluginStart()
public Action OnLevelInit(const char[] mapName, char mapEntities[2097152])
{
gB_Ready = false;
for(int i = 0; i < gA_Entites.Length; ++i)
{
Entity e;
gA_Entites.GetArray(i, e);
e.CleanUp();
}
gA_Entites.Clear();
gSM_EntityList.Clear();
for(int current = 0, next = 0; (next = FindNextKeyChar(mapEntities[current], '}')) != -1; current += next)
{
char[] entity = new char[next+1];
strcopy(entity, next, mapEntities[current]);
Entity ent;
ent.Parse(entity);
// associate the index with the entities hammerid
int index = gA_Entites.PushArray(ent);
gSM_EntityList.SetValue(ent.HammerID, index);
if(ent.OutputList.Length > 0)
{
// associate the index with the entities hammerid
int index = gA_Entites.PushArray(ent);
gSM_EntityList.SetValue(ent.HammerID, index);
}
else
{
ent.CleanUp();
}
}
gB_Ready = true;
@ -121,13 +148,13 @@ bool LocalGetOutputEntity(int index, Entity ent)
int position = -1;
if(!gSM_EntityList.GetValue(id, position))
{
LogError("Could not find entity with the index '%i', hammmerid '%i'.", index, hammer);
// LogError("Could not find entity with the index '%i', hammmerid '%i'.", index, hammer);
return false;
}
if(position >= gA_Entites.Length || position < 0)
{
LogError("List position out of range");
// LogError("List position out of range");
return false;
}
@ -170,7 +197,7 @@ public any Native_GetOutputEntity(Handle plugin, int numParams)
gA_Entites.GetArray(position, temp);
Entity ent;
CloneEntity(temp, ent);
CloneEntity(temp, ent, plugin);
SetNativeArray(2, ent, sizeof(Entity));
return (ent.OutputList != null);
@ -192,18 +219,21 @@ public any Native_GetOutputEntities(Handle plugin, int numParams)
ArrayList temp = new ArrayList(sizeof(Entity));
ArrayList list = view_as<ArrayList>(CloneHandle(temp, plugin));
delete temp;
for(int i = 0; i < gA_Entites.Length; ++i)
{
Entity original;
gA_Entites.GetArray(i, original);
Entity cloned;
CloneEntity(original, cloned);
CloneEntity(original, cloned, plugin);
temp.PushArray(cloned);
list.PushArray(cloned);
}
return temp;
return list;
}
// native bool AreEntitiesReady();
@ -245,7 +275,7 @@ public any Native_GetOutputCount(Handle plugin, int numParams)
strcopy(output, MEMBER_SIZE, buffer);
}
for(int i = 0; i < ent.OutputList. Length; ++i)
for(int i = 0; i < ent.OutputList.Length; ++i)
{
Output out;
ent.OutputList.GetArray(i, out);
@ -359,7 +389,7 @@ public any Native_GetOutputParameter(Handle plugin, int numParams)
Entity ent;
if(!LocalGetOutputEntity(index, ent))
{
LogError("Failed to get local output entity");
// LogError("Failed to get local output entity");
return false;
}