mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-24 13:55:36 +03:00
committed changes for new file format
This commit is contained in:
parent
ef5437fec3
commit
dc9350fcc5
@ -11,9 +11,10 @@ namespace BinLogReader
|
||||
public class BinLog
|
||||
{
|
||||
private static uint BINLOG_MAGIC = 0x414D424C;
|
||||
private static short BINLOG_VERSION = 0x0100;
|
||||
private static short BINLOG_VERSION = 0x0200;
|
||||
|
||||
private ArrayList oplist;
|
||||
private PluginDb plugdb;
|
||||
|
||||
public ArrayList OpList
|
||||
{
|
||||
@ -28,7 +29,12 @@ public ArrayList OpList
|
||||
oplist = new ArrayList(init_size);
|
||||
}
|
||||
|
||||
public static BinLog FromFile(string filename, PluginDb db)
|
||||
public PluginDb GetPluginDB()
|
||||
{
|
||||
return plugdb;
|
||||
}
|
||||
|
||||
public static BinLog FromFile(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
return null;
|
||||
@ -68,6 +74,12 @@ public static BinLog FromFile(string filename, PluginDb db)
|
||||
else
|
||||
bl = new BinLog( (int)(fi.Length / 6) );
|
||||
|
||||
bl.plugdb = PluginDb.FromFile(br);
|
||||
PluginDb db = bl.plugdb;
|
||||
|
||||
if (db == null)
|
||||
throw new Exception("Plugin database read failure");
|
||||
|
||||
do
|
||||
{
|
||||
opcode = (BinLogOp)br.ReadByte();
|
||||
@ -246,14 +258,18 @@ public static BinLog FromFile(string filename, PluginDb db)
|
||||
} while (opcode != BinLogOp.BinLog_End);
|
||||
opcode =BinLogOp.BinLog_End;
|
||||
}
|
||||
catch
|
||||
catch (Exception e)
|
||||
{
|
||||
if (bl != null)
|
||||
if (bl != null && bl.plugdb != null)
|
||||
{
|
||||
BinLogSimple bs = new BinLogSimple(BinLogOp.BinLog_Invalid, gametime, realtime, pl);
|
||||
bl.oplist.Add(bs);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
br.Close();
|
||||
|
Binary file not shown.
@ -5,7 +5,6 @@
|
||||
using System.Windows.Forms;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace BinLogReader
|
||||
{
|
||||
@ -61,7 +60,6 @@ protected override void Dispose( bool disposing )
|
||||
base.Dispose( disposing );
|
||||
}
|
||||
|
||||
private PluginDb plugdb;
|
||||
private BinLog binlog;
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
@ -250,7 +248,6 @@ static void Main()
|
||||
|
||||
private void Form1_Load(object sender, System.EventArgs e)
|
||||
{
|
||||
plugdb = null;
|
||||
binlog = null;
|
||||
g_UpdateViews = ViewAreas.Update_All;
|
||||
}
|
||||
@ -281,8 +278,9 @@ private void UpdateViews(ViewAreas v, BinLogFlags b)
|
||||
|
||||
if (v == ViewAreas.Update_All ||
|
||||
((v & ViewAreas.Update_Plugins) == ViewAreas.Update_Plugins)
|
||||
&& (plugdb != null))
|
||||
&& (binlog.GetPluginDB() != null))
|
||||
{
|
||||
PluginDb plugdb = binlog.GetPluginDB();
|
||||
PluginList.View = View.Details;
|
||||
PluginList.Columns.Add("Number", 60, HorizontalAlignment.Left);
|
||||
PluginList.Columns.Add("File", 100, HorizontalAlignment.Left);
|
||||
@ -333,25 +331,7 @@ private void MenuFileOpen_Click(object sender, System.EventArgs e)
|
||||
|
||||
try
|
||||
{
|
||||
/* try to open the accompanying database file */
|
||||
Regex r = new Regex(@"binlog(\d+)\.blg");
|
||||
Match m = r.Match(ofd.FileName);
|
||||
if (!m.Success)
|
||||
{
|
||||
throw new Exception("Failed to find binary database, filename unrecognized!");
|
||||
}
|
||||
Group g = m.Groups[1];
|
||||
CaptureCollection cc = g.Captures;
|
||||
Capture c = cc[0];
|
||||
string dbfile = r.Replace(ofd.FileName, "bindb" + c.ToString() + ".bdb", 1);
|
||||
|
||||
plugdb = PluginDb.FromFile(dbfile);
|
||||
if (plugdb == null)
|
||||
{
|
||||
throw new Exception("Stream failure in database file");
|
||||
}
|
||||
|
||||
binlog = BinLog.FromFile(ofd.FileName, plugdb);
|
||||
binlog = BinLog.FromFile(ofd.FileName);
|
||||
if (binlog == null)
|
||||
{
|
||||
throw new Exception("Stream failure in log file");
|
||||
|
@ -10,8 +10,6 @@ namespace BinLogReader
|
||||
/// </summary>
|
||||
public class PluginDb
|
||||
{
|
||||
private static uint BINDB_MAGIC = 0x414D4244;
|
||||
private static short BINDB_VERSION = 0x0100;
|
||||
private ArrayList PluginList;
|
||||
|
||||
public int Count
|
||||
@ -40,72 +38,38 @@ public Plugin GetPluginById(int id)
|
||||
return (Plugin)PluginList[id];
|
||||
}
|
||||
|
||||
public static PluginDb FromFile(string filename)
|
||||
public static PluginDb FromFile(BinaryReader br)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
return null;
|
||||
|
||||
System.IO.FileStream stream = File.Open(filename, System.IO.FileMode.Open);
|
||||
if (stream == null)
|
||||
return null;
|
||||
BinaryReader br = new BinaryReader(stream);
|
||||
if (br == null)
|
||||
return null;
|
||||
|
||||
PluginDb db;
|
||||
|
||||
try
|
||||
//read plugins
|
||||
uint plugins = br.ReadUInt32();
|
||||
PluginDb db = new PluginDb(plugins);
|
||||
for (uint i=0; i<plugins; i++)
|
||||
{
|
||||
//check header
|
||||
uint magic = br.ReadUInt32();
|
||||
if (magic != BINDB_MAGIC)
|
||||
throw new Exception("Invalid magic DB number");
|
||||
//check version
|
||||
ushort vers = br.ReadUInt16();
|
||||
if (vers > BINDB_VERSION)
|
||||
throw new Exception("Unknown DB version");
|
||||
//read plugins
|
||||
uint plugins = br.ReadUInt32();
|
||||
db = new PluginDb(plugins);
|
||||
for (uint i=0; i<plugins; i++)
|
||||
byte status = br.ReadByte();
|
||||
byte length = br.ReadByte();
|
||||
byte [] name = br.ReadBytes(length + 1);
|
||||
uint natives = br.ReadUInt32();
|
||||
uint publics = br.ReadUInt32();
|
||||
int id = db.CreatePlugin(
|
||||
Encoding.ASCII.GetString(name, 0, length),
|
||||
(int)natives,
|
||||
(int)publics,
|
||||
status,
|
||||
(int)i);
|
||||
Plugin pl = db.GetPluginById(id);
|
||||
for (uint j=0; j<natives; j++)
|
||||
{
|
||||
byte status = br.ReadByte();
|
||||
byte length = br.ReadByte();
|
||||
byte [] name = br.ReadBytes(length + 1);
|
||||
uint natives = br.ReadUInt32();
|
||||
uint publics = br.ReadUInt32();
|
||||
int id = db.CreatePlugin(
|
||||
Encoding.ASCII.GetString(name, 0, length),
|
||||
(int)natives,
|
||||
(int)publics,
|
||||
status,
|
||||
(int)i);
|
||||
Plugin pl = db.GetPluginById(id);
|
||||
for (uint j=0; j<natives; j++)
|
||||
{
|
||||
length = br.ReadByte();
|
||||
name = br.ReadBytes(length + 1);
|
||||
pl.AddNative(Encoding.ASCII.GetString(name, 0, length));
|
||||
}
|
||||
for (uint j=0; j<publics; j++)
|
||||
{
|
||||
length = br.ReadByte();
|
||||
name = br.ReadBytes(length + 1);
|
||||
pl.AddPublic(Encoding.ASCII.GetString(name, 0, length));
|
||||
}
|
||||
length = br.ReadByte();
|
||||
name = br.ReadBytes(length + 1);
|
||||
pl.AddNative(Encoding.ASCII.GetString(name, 0, length));
|
||||
}
|
||||
for (uint j=0; j<publics; j++)
|
||||
{
|
||||
length = br.ReadByte();
|
||||
name = br.ReadBytes(length + 1);
|
||||
pl.AddPublic(Encoding.ASCII.GetString(name, 0, length));
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
db = null;
|
||||
throw new Exception("DB file is corrupt");
|
||||
}
|
||||
finally
|
||||
{
|
||||
br.Close();
|
||||
stream.Close();
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
return db;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user