diff --git a/plugins/BinLogReader/BinLogOps.cs b/plugins/BinLogReader/BinLogOps.cs index a4964a11..e881029d 100644 --- a/plugins/BinLogReader/BinLogOps.cs +++ b/plugins/BinLogReader/BinLogOps.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using System.Collections; +using System.Text; namespace BinLogReader { @@ -47,45 +48,52 @@ public static bool HasFlag(BinLogFlags a, BinLogFlags b) return ( (a & b) == b ); } - public static string PluginText(Plugin pl, BinLogFlags flags) + public static void PluginText(StringBuilder sb, Plugin pl, BinLogFlags flags) { - string plugintext = ""; if (HasFlag(flags, BinLogFlags.Show_PlugId) && HasFlag(flags, BinLogFlags.Show_PlugFile)) { - plugintext = "\"" + pl.File + "\"" + " (" + pl.Index + ")"; + sb.Append("\""); + sb.Append(pl.File); + sb.Append("\""); + sb.Append(" ("); + sb.Append(pl.Index); + sb.Append(")"); } else if (HasFlag(flags, BinLogFlags.Show_PlugId)) { - plugintext = pl.Index.ToString(); + sb.Append(pl.Index); } else if (HasFlag(flags, BinLogFlags.Show_PlugFile)) { - plugintext = "\"" + pl.File + "\""; + sb.Append("\""); + sb.Append(pl.File); + sb.Append("\""); } - return plugintext; } - public static string BinLogString(BinLogEntry ble, BinLogFlags flags) + public static void BinLogString(StringBuilder sb, BinLogEntry ble, BinLogFlags flags) { - string logtext = ""; + bool realtime = false; if (HasFlag(flags, BinLogFlags.Show_RealTime)) - logtext += ble.realtime.ToString(); + { + sb.Append(ble.realtime.ToString()); + realtime = true; + } if (HasFlag(flags, BinLogFlags.Show_GameTime)) { - if (logtext.Length > 0) + if (realtime) { - logtext += ", " + ble.gametime.ToString(); + sb.Append(", "); + sb.Append(ble.gametime.ToString()); } else { - logtext += ble.gametime.ToString(); + sb.Append(ble.gametime.ToString()); } } - logtext += ": "; - logtext += ble.ToLogString(flags); - - return logtext; + sb.Append(": "); + ble.ToLogString(sb, flags); } public float gametime @@ -116,7 +124,7 @@ public long realtime } public abstract BinLogOp Op(); - public abstract string ToLogString(BinLogFlags flags); + public abstract void ToLogString(StringBuilder sb, BinLogFlags flags); }; public class BinLogSetLine : BinLogEntry @@ -137,12 +145,13 @@ public BinLogSetLine(int _line, float gt, long rt, Plugin _pl) line = _line; } - public override string ToLogString(BinLogFlags flags) + public override void ToLogString(StringBuilder sb, BinLogFlags flags) { - string plugtext = BinLogEntry.PluginText(plugin, flags); - string logtext = "Plugin hit line " + Line + "."; - - return logtext; + sb.Append("Plugin "); + BinLogEntry.PluginText(sb, plugin, flags); + sb.Append(" hit line "); + sb.Append(Line); + sb.Append("."); } public override BinLogOp Op() @@ -169,13 +178,15 @@ public BinLogPublic(int pi, float gt, long rt, Plugin _pl) pubidx = pi; } - public override string ToLogString(BinLogFlags flags) + public override void ToLogString(StringBuilder sb, BinLogFlags flags) { - string plugtext = BinLogEntry.PluginText(plugin, flags); - string logtext = "Plugin " + plugtext + " had public function "; - logtext += "\"" + Public + "\" (" + pubidx + ") called."; - - return logtext; + sb.Append("Plugin "); + BinLogEntry.PluginText(sb, plugin, flags); + sb.Append(" had public function \""); + sb.Append(Public); + sb.Append("\" ("); + sb.Append(pubidx); + sb.Append(") called."); } public override BinLogOp Op() @@ -198,13 +209,17 @@ public BinLogSetString(long addr, int _maxlen, string fmt, float gt, long rt, Pl text = fmt; } - public override string ToLogString(BinLogFlags flags) + public override void ToLogString(StringBuilder sb, BinLogFlags flags) { - string plugtext = BinLogEntry.PluginText(plugin, flags); - string logtext = "Setting string (addr " + address + ") (maxlen " + maxlen + ") from Plugin " + plugtext + ". String:"; - logtext += "\n\t " + text; - - return logtext; + sb.Append("Setting string (addr "); + sb.Append(address); + sb.Append(") (maxlen "); + sb.Append(maxlen); + sb.Append(") from Plugin "); + BinLogEntry.PluginText(sb, plugin, flags); + sb.Append(". String:"); + sb.Append("\n\t "); + sb.Append(text); } public override BinLogOp Op() @@ -225,13 +240,15 @@ public BinLogGetString(long addr, string fmt, float gt, long rt, Plugin _pl) text = fmt; } - public override string ToLogString(BinLogFlags flags) + public override void ToLogString(StringBuilder sb, BinLogFlags flags) { - string plugtext = BinLogEntry.PluginText(plugin, flags); - string logtext = "Retrieving string (addr " + address + ") from Plugin " + plugtext + ". String:"; - logtext += "\n\t " + text; - - return logtext; + sb.Append("Retrieving string (addr "); + sb.AppendFormat("0x{0:X}", address); + sb.Append(") from Plugin "); + BinLogEntry.PluginText(sb, plugin, flags); + sb.Append(". String:"); + sb.Append("\n\t "); + sb.Append(text); } public override BinLogOp Op() @@ -250,9 +267,10 @@ public BinLogNativeRet(long ret, float gt, long rt, Plugin _pl) returnval = ret; } - public override string ToLogString(BinLogFlags flags) + public override void ToLogString(StringBuilder sb, BinLogFlags flags) { - return "Native returned: " + returnval; + sb.Append("Native returned: "); + sb.Append(returnval); } public override BinLogOp Op() @@ -281,14 +299,17 @@ public BinLogNativeCall(int na, int nu, float gt, long rt, Plugin _pl) numparams = nu; } - public override string ToLogString(BinLogFlags flags) + public override void ToLogString(StringBuilder sb, BinLogFlags flags) { - string plugtext = BinLogEntry.PluginText(plugin, flags); - string logtext = "Plugin " + plugtext + " called native "; - logtext += "\"" + Native + "\" (" + nativeidx + ")"; - logtext += " with " + numparams + " parameters."; - - return logtext; + sb.Append("Plugin "); + BinLogEntry.PluginText(sb, plugin, flags); + sb.Append(" called native \""); + sb.Append(Native); + sb.Append("\" ("); + sb.Append(nativeidx); + sb.Append(") with "); + sb.Append(numparams); + sb.Append(" parameters."); } public override BinLogOp Op() @@ -306,25 +327,26 @@ public BinLogSimple(BinLogOp op, float gt, long rt, Plugin _pl) : my_op = op; } - public override string ToLogString(BinLogFlags flags) + public override void ToLogString(StringBuilder sb, BinLogFlags flags) { switch (my_op) { case BinLogOp.BinLog_Start: { - return "Binary log started."; + sb.Append("Binary log started."); + break; } case BinLogOp.BinLog_End: { - return "Binary log ended."; + sb.Append("Binary log ended."); + break; } case BinLogOp.BinLog_Invalid: { - return "Binary log corrupt past this point."; + sb.Append("Binary log corrupt past this point."); + break; } } - - return ""; } public override BinLogOp Op() @@ -359,21 +381,19 @@ public BinLogNativeParams(float gt, long rt, Plugin _pl) { } - public override string ToLogString(BinLogFlags flags) + public override void ToLogString(StringBuilder sb, BinLogFlags flags) { - string logtext = "Native parameters: ("; + sb.Append("Native parameters: ("); if (plist != null) { for (int i=0; i