From 684a8a3197fcc89f0ad313e8ffdd09d6a82bcf92 Mon Sep 17 00:00:00 2001 From: arookas Date: Wed, 23 Dec 2015 20:17:16 -0500 Subject: [PATCH] Made symbols write their table entries themselves. This will allow for overriding the writing code for specific symbol types. --- ssc/symbol table.cs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/ssc/symbol table.cs b/ssc/symbol table.cs index b647e35..a93ce59 100644 --- a/ssc/symbol table.cs +++ b/ssc/symbol table.cs @@ -29,19 +29,11 @@ namespace arookas int ofs = 0; foreach (var sym in this) { - writer.WriteS32((int)sym.Type); - writer.WriteS32(ofs); - writer.Write32(sym.Data); - - // runtime fields - writer.WriteS32(0); - writer.WriteS32(0); - - ofs += writer.Encoding.GetByteCount(sym.Name) + 1; // include null terminator + ofs += sym.WriteSymbolTable(writer, ofs); } foreach (var sym in this) { - writer.WriteString(sym.Name, aBinaryStringFormat.NullTerminated); + sym.WriteStringTable(writer); } } @@ -61,6 +53,23 @@ namespace arookas { Name = name; } + + public virtual int WriteSymbolTable(aBinaryWriter writer, int ofs) + { + writer.WriteS32((int)Type); + writer.WriteS32(ofs); + writer.Write32(Data); + + // runtime fields + writer.WriteS32(0); + writer.WriteS32(0); + + return writer.Encoding.GetByteCount(Name) + 1; // include null terminator + } + public virtual void WriteStringTable(aBinaryWriter writer) + { + writer.WriteString(Name, aBinaryStringFormat.NullTerminated); + } } abstract class sunCallableSymbol : sunSymbol