Fleshed out log and database readers, began basics of GUI
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
|
||||
namespace BinLogReader
|
||||
{
|
||||
@ -8,10 +10,25 @@ namespace BinLogReader
|
||||
/// </summary>
|
||||
public class BinLog
|
||||
{
|
||||
private static uint BINLOG_MAGIC = 0x414D424C
|
||||
private static uint BINLOG_MAGIC = 0x414D424C;
|
||||
private static short BINLOG_VERSION = 0x0100;
|
||||
|
||||
public static BinLog FromFile(string filename)
|
||||
private ArrayList oplist;
|
||||
|
||||
public ArrayList OpList
|
||||
{
|
||||
get
|
||||
{
|
||||
return oplist;
|
||||
}
|
||||
}
|
||||
|
||||
BinLog(int init_size)
|
||||
{
|
||||
oplist = new ArrayList(init_size);
|
||||
}
|
||||
|
||||
public static BinLog FromFile(string filename, PluginDb db)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
return null;
|
||||
@ -23,11 +40,219 @@ namespace BinLogReader
|
||||
if (br == null)
|
||||
return null;
|
||||
|
||||
BinLog bl = null;
|
||||
BinLogOp opcode = BinLogOp.BinLog_Invalid;
|
||||
long realtime = 0;
|
||||
float gametime = 0.0f;
|
||||
int plug_id = -1;
|
||||
Plugin pl = null;
|
||||
|
||||
try
|
||||
{
|
||||
uint magic = br.ReadUInt32();
|
||||
if (magic != BINLOG_MAGIC)
|
||||
throw new Exception("Invalid magic log number");
|
||||
|
||||
ushort version = br.ReadUInt16();
|
||||
if (version > BINLOG_VERSION)
|
||||
throw new Exception("Unknown log version number");
|
||||
|
||||
byte timesize = br.ReadByte();
|
||||
|
||||
bool bits64 = (timesize == 8) ? true : false;
|
||||
|
||||
FileInfo fi = new FileInfo(filename);
|
||||
//guestimate required size
|
||||
if (fi.Length > 500)
|
||||
bl = new BinLog( (int)((fi.Length - 500) / 6) );
|
||||
else
|
||||
bl = new BinLog( (int)(fi.Length / 6) );
|
||||
|
||||
do
|
||||
{
|
||||
opcode = (BinLogOp)br.ReadByte();
|
||||
gametime = br.ReadSingle();
|
||||
if (bits64)
|
||||
realtime = br.ReadInt64();
|
||||
else
|
||||
realtime = (long)br.ReadInt32();
|
||||
plug_id = br.ReadInt32();
|
||||
pl = db.GetPluginById(plug_id);
|
||||
switch (opcode)
|
||||
{
|
||||
case BinLogOp.BinLog_SetString:
|
||||
{
|
||||
long addr;
|
||||
if (bits64)
|
||||
addr = br.ReadInt64();
|
||||
else
|
||||
addr = (long)br.ReadInt32();
|
||||
int maxlen = br.ReadInt32();
|
||||
ushort len = br.ReadUInt16();
|
||||
byte [] str = br.ReadBytes(len+1);
|
||||
string text = Encoding.ASCII.GetString(str, 0, len);
|
||||
BinLogSetString bgs =
|
||||
new BinLogSetString(addr, maxlen, text, gametime, realtime, pl);
|
||||
bl.OpList.Add(bgs);
|
||||
break;
|
||||
}
|
||||
case BinLogOp.BinLog_GetString:
|
||||
{
|
||||
long addr;
|
||||
if (bits64)
|
||||
addr = br.ReadInt64();
|
||||
else
|
||||
addr = (long)br.ReadInt32();
|
||||
ushort len = br.ReadUInt16();
|
||||
byte [] str = br.ReadBytes(len+1);
|
||||
string text = Encoding.ASCII.GetString(str, 0, len);
|
||||
BinLogGetString bgs =
|
||||
new BinLogGetString(addr, text, gametime, realtime, pl);
|
||||
bl.OpList.Add(bgs);
|
||||
break;
|
||||
}
|
||||
case BinLogOp.BinLog_NativeParams:
|
||||
{
|
||||
ArrayList parms;
|
||||
if (bits64)
|
||||
{
|
||||
long num = br.ReadInt64();
|
||||
long p;
|
||||
Int64 i64;
|
||||
parms = new ArrayList((int)num);
|
||||
for (int i=0; i<(int)num; i++)
|
||||
{
|
||||
p = br.ReadInt64();
|
||||
i64 = new Int64();
|
||||
i64 = p;
|
||||
parms.Add(i64);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int num = br.ReadInt32();
|
||||
int p;
|
||||
Int32 i32;
|
||||
parms = new ArrayList(num);
|
||||
for (int i=0; i<num; i++)
|
||||
{
|
||||
p = br.ReadInt32();
|
||||
i32 = new Int32();
|
||||
i32 = p;
|
||||
parms.Add(i32);
|
||||
}
|
||||
}
|
||||
BinLogNativeParams bnp =
|
||||
new BinLogNativeParams(gametime, realtime, pl);
|
||||
bnp.ParamList = parms;
|
||||
bl.OpList.Add(bnp);
|
||||
break;
|
||||
}
|
||||
case BinLogOp.BinLog_FormatString:
|
||||
{
|
||||
int parm = br.ReadInt32();
|
||||
int max = br.ReadInt32();
|
||||
ushort len = br.ReadUInt16();
|
||||
byte [] str = br.ReadBytes(len + 1);
|
||||
string text = Encoding.ASCII.GetString(str, 0, len);
|
||||
BinLogFmtString bfs =
|
||||
new BinLogFmtString(parm, max, text, gametime, realtime, pl);
|
||||
bl.OpList.Add(bfs);
|
||||
break;
|
||||
}
|
||||
case BinLogOp.BinLog_End:
|
||||
{
|
||||
BinLogSimple bs =
|
||||
new BinLogSimple(BinLogOp.BinLog_End, gametime, realtime, pl);
|
||||
bl.OpList.Add(bs);
|
||||
break;
|
||||
}
|
||||
case BinLogOp.BinLog_SetLine:
|
||||
{
|
||||
int line = br.ReadInt32();
|
||||
BinLogSetLine bsl =
|
||||
new BinLogSetLine(line, gametime, realtime, pl);
|
||||
bl.OpList.Add(bsl);
|
||||
break;
|
||||
}
|
||||
case BinLogOp.BinLog_CallPubFunc:
|
||||
{
|
||||
int pubidx = br.ReadInt32();
|
||||
BinLogPublic bp =
|
||||
new BinLogPublic(pubidx,
|
||||
gametime,
|
||||
realtime,
|
||||
pl);
|
||||
bl.OpList.Add(bp);
|
||||
break;
|
||||
}
|
||||
case BinLogOp.BinLog_NativeRet:
|
||||
{
|
||||
long ret;
|
||||
if (bits64)
|
||||
ret = br.ReadInt64();
|
||||
else
|
||||
ret = (long)br.ReadUInt32();
|
||||
BinLogNativeRet bnr =
|
||||
new BinLogNativeRet(ret, gametime, realtime, pl);
|
||||
bl.OpList.Add(bnr);
|
||||
break;
|
||||
}
|
||||
case BinLogOp.BinLog_NativeCall:
|
||||
{
|
||||
int native = br.ReadInt32();
|
||||
int parms = br.ReadInt32();
|
||||
BinLogNativeCall bn =
|
||||
new BinLogNativeCall(native,
|
||||
parms,
|
||||
gametime,
|
||||
realtime,
|
||||
pl);
|
||||
bl.OpList.Add(bn);
|
||||
break;
|
||||
}
|
||||
case BinLogOp.BinLog_Start:
|
||||
{
|
||||
BinLogSimple bs =
|
||||
new BinLogSimple(opcode, gametime, realtime, null);
|
||||
bl.oplist.Add(bs);
|
||||
|
||||
break;
|
||||
}
|
||||
case BinLogOp.BinLog_Registered:
|
||||
{
|
||||
byte length1 = br.ReadByte();
|
||||
byte [] title = br.ReadBytes(length1 + 1);
|
||||
byte length2 = br.ReadByte();
|
||||
byte [] vers = br.ReadBytes(length2 + 1);
|
||||
BinLogRegister be =
|
||||
new BinLogRegister(gametime, realtime, pl);
|
||||
be.title = Encoding.ASCII.GetString(title, 0, length1);
|
||||
be.version = Encoding.ASCII.GetString(vers, 0, length2);
|
||||
bl.oplist.Add(be);
|
||||
pl.Title = be.title;
|
||||
pl.Version = be.version;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
BinLogSimple bs = new BinLogSimple(BinLogOp.BinLog_Invalid, gametime, realtime, pl);
|
||||
bl.oplist.Add(bs);
|
||||
opcode = BinLogOp.BinLog_End;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (opcode != BinLogOp.BinLog_End);
|
||||
opcode =BinLogOp.BinLog_End;
|
||||
}
|
||||
catch
|
||||
catch
|
||||
{
|
||||
if (bl != null)
|
||||
{
|
||||
BinLogSimple bs = new BinLogSimple(BinLogOp.BinLog_Invalid, gametime, realtime, pl);
|
||||
bl.oplist.Add(bs);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
@ -35,6 +260,8 @@ namespace BinLogReader
|
||||
stream.Close();
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
return bl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user