mirror of
https://github.com/kidfearless/output-info-plugin.git
synced 2025-12-07 10:28:22 +00:00
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.
This commit is contained in:
parent
c5c8ae1b5e
commit
3ca6c6dc54
@ -5,6 +5,7 @@
|
||||
|
||||
#define OUTPUT_SIZE 2048
|
||||
#define MEMBER_SIZE 128
|
||||
#define INCLUDE_VERSION 2
|
||||
|
||||
// set to 0 to use stocks instead of native
|
||||
#define USE_NATIVES 1
|
||||
@ -139,8 +140,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 +158,12 @@ enum struct Entity
|
||||
StripQuotes(parameters);
|
||||
output.Parse(parameters);
|
||||
|
||||
outputList.PushArray(output);
|
||||
this.OutputList.PushArray(output);
|
||||
}
|
||||
|
||||
|
||||
delete outputMatch;
|
||||
|
||||
this.OutputList = outputList;
|
||||
// #endregion
|
||||
}
|
||||
}
|
||||
@ -173,12 +174,16 @@ 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();
|
||||
|
||||
// shavits method of cloning arraylists
|
||||
ArrayList list = view_as<ArrayList>(CloneHandle(input.OutputList, newOwner));
|
||||
out.OutputList = list.Clone();
|
||||
delete list;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -308,6 +313,7 @@ stock int GetOutputCount(int index, const char[] output = "")
|
||||
Entity ent;
|
||||
if(!GetOutputEntity(index, ent))
|
||||
{
|
||||
ent.CleanUp();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -349,6 +355,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 +406,7 @@ stock bool GetOutputTargetInput(int index, const char[] output, int num, char[]
|
||||
Entity ent;
|
||||
if(!GetOutputEntity(index, ent))
|
||||
{
|
||||
ent.CleanUp();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -450,6 +458,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 +508,7 @@ stock float GetOutputDelay(int index, const char[] output, int num)
|
||||
Entity ent;
|
||||
if(!GetOutputEntity(index, ent))
|
||||
{
|
||||
ent.CleanUp();
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
|
||||
@ -2,12 +2,14 @@
|
||||
#include <regex>
|
||||
#include <output_info_plugin>
|
||||
|
||||
#define PLUGIN_VERSION 2
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "Output Info Plugin",
|
||||
author = "KiD Fearless",
|
||||
description = "Plugin Alternative To Output Info",
|
||||
version = "2.0.1",
|
||||
version = "2.0.2",
|
||||
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,6 +76,18 @@ 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];
|
||||
@ -76,10 +96,17 @@ public Action OnLevelInit(const char[] mapName, char mapEntities[2097152])
|
||||
Entity ent;
|
||||
ent.Parse(entity);
|
||||
|
||||
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;
|
||||
Call_StartForward(gF_OnEntitiesReady);
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user