2006-03-16 06:40:18 +00:00
|
|
|
using System;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Collections;
|
2006-03-16 19:29:46 +00:00
|
|
|
using System.Text;
|
2006-03-16 06:40:18 +00:00
|
|
|
|
|
|
|
namespace BinLogReader
|
|
|
|
{
|
|
|
|
public enum BinLogOp
|
|
|
|
{
|
|
|
|
BinLog_Invalid=0,
|
|
|
|
BinLog_Start=1,
|
|
|
|
BinLog_End,
|
|
|
|
BinLog_NativeCall, //<int16_t native id>
|
|
|
|
BinLog_NativeError,
|
|
|
|
BinLog_NativeRet,
|
|
|
|
BinLog_CallPubFunc, //<int16_t public id>
|
|
|
|
BinLog_SetLine, //<int16_t line no#>
|
|
|
|
BinLog_Registered, //<string title> <string version>
|
|
|
|
BinLog_FormatString,
|
|
|
|
BinLog_NativeParams,
|
|
|
|
BinLog_GetString,
|
|
|
|
BinLog_SetString,
|
|
|
|
};
|
|
|
|
|
|
|
|
public enum BinLogFlags
|
|
|
|
{
|
|
|
|
Show_RealTime = (1<<0),
|
|
|
|
Show_GameTime = (1<<1),
|
|
|
|
Show_PlugId = (1<<2),
|
|
|
|
Show_PlugFile = (1<<3),
|
|
|
|
};
|
|
|
|
|
|
|
|
public abstract class BinLogEntry
|
|
|
|
{
|
|
|
|
protected float GameTime;
|
|
|
|
protected long RealTime;
|
|
|
|
protected Plugin pl;
|
|
|
|
|
|
|
|
protected BinLogEntry(float gt, long rt, Plugin _pl)
|
|
|
|
{
|
|
|
|
GameTime = gt;
|
|
|
|
RealTime = rt;
|
|
|
|
pl = _pl;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool HasFlag(BinLogFlags a, BinLogFlags b)
|
|
|
|
{
|
|
|
|
return ( (a & b) == b );
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:29:46 +00:00
|
|
|
public static void PluginText(StringBuilder sb, Plugin pl, BinLogFlags flags)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
|
|
|
if (HasFlag(flags, BinLogFlags.Show_PlugId)
|
|
|
|
&& HasFlag(flags, BinLogFlags.Show_PlugFile))
|
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append("\"");
|
|
|
|
sb.Append(pl.File);
|
|
|
|
sb.Append("\"");
|
|
|
|
sb.Append(" (");
|
|
|
|
sb.Append(pl.Index);
|
|
|
|
sb.Append(")");
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
else if (HasFlag(flags, BinLogFlags.Show_PlugId))
|
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append(pl.Index);
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
else if (HasFlag(flags, BinLogFlags.Show_PlugFile))
|
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append("\"");
|
|
|
|
sb.Append(pl.File);
|
|
|
|
sb.Append("\"");
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:29:46 +00:00
|
|
|
public static void BinLogString(StringBuilder sb, BinLogEntry ble, BinLogFlags flags)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
bool realtime = false;
|
2006-03-16 06:40:18 +00:00
|
|
|
if (HasFlag(flags, BinLogFlags.Show_RealTime))
|
2006-03-16 19:29:46 +00:00
|
|
|
{
|
|
|
|
sb.Append(ble.realtime.ToString());
|
|
|
|
realtime = true;
|
|
|
|
}
|
2006-03-16 06:40:18 +00:00
|
|
|
if (HasFlag(flags, BinLogFlags.Show_GameTime))
|
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
if (realtime)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append(", ");
|
|
|
|
sb.Append(ble.gametime.ToString());
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append(ble.gametime.ToString());
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append(": ");
|
|
|
|
ble.ToLogString(sb, flags);
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public float gametime
|
|
|
|
{
|
|
|
|
[DebuggerStepThrough]
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return GameTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Plugin plugin
|
|
|
|
{
|
|
|
|
[DebuggerStepThrough]
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return pl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public long realtime
|
|
|
|
{
|
|
|
|
[DebuggerStepThrough]
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return RealTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract BinLogOp Op();
|
2006-03-16 19:29:46 +00:00
|
|
|
public abstract void ToLogString(StringBuilder sb, BinLogFlags flags);
|
2006-03-16 06:40:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public class BinLogSetLine : BinLogEntry
|
|
|
|
{
|
|
|
|
private int line;
|
|
|
|
|
|
|
|
public int Line
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public BinLogSetLine(int _line, float gt, long rt, Plugin _pl)
|
|
|
|
: base(gt, rt, _pl)
|
|
|
|
{
|
|
|
|
line = _line;
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:29:46 +00:00
|
|
|
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append("Plugin ");
|
|
|
|
BinLogEntry.PluginText(sb, plugin, flags);
|
|
|
|
sb.Append(" hit line ");
|
|
|
|
sb.Append(Line);
|
|
|
|
sb.Append(".");
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override BinLogOp Op()
|
|
|
|
{
|
|
|
|
return BinLogOp.BinLog_SetLine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BinLogPublic : BinLogEntry
|
|
|
|
{
|
|
|
|
private int pubidx;
|
|
|
|
|
|
|
|
public string Public
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return plugin.FindPublic(pubidx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public BinLogPublic(int pi, float gt, long rt, Plugin _pl)
|
|
|
|
: base(gt, rt, _pl)
|
|
|
|
{
|
|
|
|
pubidx = pi;
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:29:46 +00:00
|
|
|
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append("Plugin ");
|
|
|
|
BinLogEntry.PluginText(sb, plugin, flags);
|
|
|
|
sb.Append(" had public function \"");
|
|
|
|
sb.Append(Public);
|
|
|
|
sb.Append("\" (");
|
|
|
|
sb.Append(pubidx);
|
|
|
|
sb.Append(") called.");
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override BinLogOp Op()
|
|
|
|
{
|
|
|
|
return BinLogOp.BinLog_CallPubFunc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BinLogSetString : BinLogEntry
|
|
|
|
{
|
|
|
|
private long address;
|
|
|
|
private int maxlen;
|
|
|
|
private string text;
|
|
|
|
|
|
|
|
public BinLogSetString(long addr, int _maxlen, string fmt, float gt, long rt, Plugin _pl)
|
|
|
|
: base(gt, rt, _pl)
|
|
|
|
{
|
|
|
|
address = addr;
|
|
|
|
maxlen = _maxlen;
|
|
|
|
text = fmt;
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:29:46 +00:00
|
|
|
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
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);
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override BinLogOp Op()
|
|
|
|
{
|
|
|
|
return BinLogOp.BinLog_GetString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BinLogGetString : BinLogEntry
|
|
|
|
{
|
|
|
|
private long address;
|
|
|
|
private string text;
|
|
|
|
|
|
|
|
public BinLogGetString(long addr, string fmt, float gt, long rt, Plugin _pl)
|
|
|
|
: base(gt, rt, _pl)
|
|
|
|
{
|
|
|
|
address = addr;
|
|
|
|
text = fmt;
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:29:46 +00:00
|
|
|
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
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);
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override BinLogOp Op()
|
|
|
|
{
|
|
|
|
return BinLogOp.BinLog_GetString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BinLogNativeRet : BinLogEntry
|
|
|
|
{
|
|
|
|
private long returnval;
|
|
|
|
|
|
|
|
public BinLogNativeRet(long ret, float gt, long rt, Plugin _pl)
|
|
|
|
: base(gt, rt, _pl)
|
|
|
|
{
|
|
|
|
returnval = ret;
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:29:46 +00:00
|
|
|
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append("Native returned: ");
|
|
|
|
sb.Append(returnval);
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override BinLogOp Op()
|
|
|
|
{
|
|
|
|
return BinLogOp.BinLog_NativeRet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BinLogNativeCall : BinLogEntry
|
|
|
|
{
|
|
|
|
private int nativeidx;
|
|
|
|
private int numparams;
|
|
|
|
|
|
|
|
public string Native
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return plugin.FindNative(nativeidx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public BinLogNativeCall(int na, int nu, float gt, long rt, Plugin _pl)
|
|
|
|
: base(gt, rt, _pl)
|
|
|
|
{
|
|
|
|
nativeidx = na;
|
|
|
|
numparams = nu;
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:29:46 +00:00
|
|
|
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
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.");
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override BinLogOp Op()
|
|
|
|
{
|
|
|
|
return BinLogOp.BinLog_NativeCall;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BinLogSimple : BinLogEntry
|
|
|
|
{
|
|
|
|
private BinLogOp my_op;
|
|
|
|
public BinLogSimple(BinLogOp op, float gt, long rt, Plugin _pl) :
|
|
|
|
base(gt, rt, _pl)
|
|
|
|
{
|
|
|
|
my_op = op;
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:29:46 +00:00
|
|
|
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
|
|
|
switch (my_op)
|
|
|
|
{
|
|
|
|
case BinLogOp.BinLog_Start:
|
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append("Binary log started.");
|
|
|
|
break;
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
case BinLogOp.BinLog_End:
|
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append("Binary log ended.");
|
|
|
|
break;
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
case BinLogOp.BinLog_Invalid:
|
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append("Binary log corrupt past this point.");
|
|
|
|
break;
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override BinLogOp Op()
|
|
|
|
{
|
|
|
|
return my_op;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BinLogNativeParams : BinLogEntry
|
|
|
|
{
|
|
|
|
private ArrayList plist;
|
|
|
|
|
|
|
|
public ArrayList ParamList
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return plist;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
plist = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override BinLogOp Op()
|
|
|
|
{
|
|
|
|
return BinLogOp.BinLog_NativeParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BinLogNativeParams(float gt, long rt, Plugin _pl)
|
|
|
|
: base(gt, rt, _pl)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:29:46 +00:00
|
|
|
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append("Native parameters: (");
|
2006-03-16 06:40:18 +00:00
|
|
|
if (plist != null)
|
|
|
|
{
|
|
|
|
for (int i=0; i<plist.Count; i++)
|
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append(plist[i].ToString());
|
2006-03-16 06:40:18 +00:00
|
|
|
if (i < plist.Count - 1)
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append(", ");
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append(")");
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BinLogFmtString : BinLogEntry
|
|
|
|
{
|
|
|
|
private int parm;
|
|
|
|
private int maxlen;
|
|
|
|
private string text;
|
|
|
|
|
|
|
|
public override BinLogOp Op()
|
|
|
|
{
|
|
|
|
return BinLogOp.BinLog_FormatString;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BinLogFmtString(int pa, int ma, string str, float gt, long rt, Plugin _pl)
|
|
|
|
: base(gt, rt, _pl)
|
|
|
|
{
|
|
|
|
parm = pa;
|
|
|
|
maxlen = ma;
|
|
|
|
text = str;
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:29:46 +00:00
|
|
|
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append("Plugin ");
|
|
|
|
BinLogEntry.PluginText(sb, pl, flags);
|
|
|
|
sb.Append(" formatted parameter ");
|
|
|
|
sb.Append(parm);
|
|
|
|
sb.Append(" (maxlen ");
|
|
|
|
sb.Append(maxlen);
|
|
|
|
sb.Append("), result: \n\t");
|
|
|
|
sb.Append(text);
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class BinLogRegister : BinLogEntry
|
|
|
|
{
|
|
|
|
private string _title;
|
|
|
|
private string _version;
|
|
|
|
|
|
|
|
public string title
|
|
|
|
{
|
|
|
|
[DebuggerStepThrough]
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return _title;
|
|
|
|
}
|
|
|
|
[DebuggerStepThrough]
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_title = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string version
|
|
|
|
{
|
|
|
|
[DebuggerStepThrough]
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return _version;
|
|
|
|
}
|
|
|
|
[DebuggerStepThrough]
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_version = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-16 19:29:46 +00:00
|
|
|
public override void ToLogString(StringBuilder sb, BinLogFlags flags)
|
2006-03-16 06:40:18 +00:00
|
|
|
{
|
2006-03-16 19:29:46 +00:00
|
|
|
sb.Append("Plugin ");
|
|
|
|
BinLogEntry.PluginText(sb, pl, flags);
|
|
|
|
sb.Append(" registered as (\"");
|
|
|
|
sb.Append(_title);
|
|
|
|
sb.Append("\", \"");
|
|
|
|
sb.Append(_version);
|
|
|
|
sb.Append("\")");
|
2006-03-16 06:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public BinLogRegister(float gt, long rt, Plugin _pl) :
|
|
|
|
base(gt, rt, _pl)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public override BinLogOp Op()
|
|
|
|
{
|
|
|
|
return BinLogOp.BinLog_Registered;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|