Skip to content
Browse files

Added README file

  • Loading branch information...
1 parent 7c110e5 commit ff4dc9f6cbd790760dd79e509519c742dbe0fb02 @LordJZ committed
Showing with 12 additions and 107 deletions.
  1. +3 −105 DBC/DBCReader.cs
  2. +1 −1 Program.cs
  3. +7 −0 README
  4. +1 −1 Util/Time.cs
View
108 DBC/DBCReader.cs
@@ -18,7 +18,7 @@ static class DBCReader
GenericReader reader = new GenericReader(fileName, Encoding.UTF8);
- // Sanity checks
+ // Sanity check
if (reader.BaseStream.Length < 20 || reader.ReadUInt32() != 0x43424457)
throw new Exception(String.Format("Bad DBC file {0}", fileName));
@@ -28,6 +28,7 @@ static class DBCReader
int stringTableSize = reader.ReadInt32();
int sz = Marshal.SizeOf(typeof(T));
+
if(fieldsCount*4 != sz)
throw new Exception(String.Format("\n\nSize of row in DBC file ({0}) != size of DBC struct ({1})\nDBC: {2}\n\n", fieldsCount*4, sz, fileName));
@@ -41,47 +42,18 @@ static class DBCReader
uint key = dataReader.ReadUInt32();
dataReader.BaseStream.Position -= 4;
- /* OLD SYSTEM
-
- List<byte> row = new List<byte>();
-
- int cur_idx = -1;
- int str_idx = 0;
- while (++cur_idx < fmt.Length)
- {
- str_idx = fmt.IndexOf("s", cur_idx);
-
- if (str_idx == -1)
- str_idx = fmt.Length - cur_idx;
- else
- str_idx -= cur_idx;
-
- if (str_idx == 0)
- {
- row.AddRange(Encoding.UTF8.GetBytes(stringsReader.ReadStringDbc(dataReader.ReadInt32())));
- }
- else
- {
- row.AddRange(dataReader.ReadBytes(str_idx*4));
- cur_idx += str_idx-1;
- }
- }*/
-
-
byte[] rawData = dataReader.ReadBytes(sz);
- //System.Windows.Forms.MessageBox.Show(String.Format("rawData size {0}, struct size {1}", row.Count, sz));
GCHandle handle = GCHandle.Alloc(rawData, GCHandleType.Pinned);
T T_entry = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
handle.Free();
- //System.Windows.Forms.MessageBox.Show(String.Format("adding key {0}", key));
dict.Add(key, T_entry);
}
dataReader.Close();
- // Now we read strings
+ // Now we read strings
if (strDict != null)
{
char nullChar = char.MinValue;
@@ -112,74 +84,6 @@ static class DBCReader
return dict;
}
- /*public DBCReader(string fileName, ref Dictionary<int, DbcData> dict, String[][] shem)
- {
- GenericReader reader = new GenericReader(fileName, Encoding.UTF8);
-
- if (reader.BaseStream.Length < 20 || reader.ReadUInt32() != 0x43424457)
- return;
-
- int recordsCount = reader.ReadInt32();
- int fieldsCount = reader.ReadInt32();
- int recordSize = reader.ReadInt32();
- int stringTableSize = reader.ReadInt32();
-
- Program.loadingForm.SetProgressBarSize(0, recordsCount);
-
- GenericReader dataReader = new GenericReader(new MemoryStream(reader.ReadBytes(recordsCount * recordSize)), Encoding.UTF8);
- GenericReader stringsReader = new GenericReader(new MemoryStream(reader.ReadBytes(stringTableSize)), Encoding.UTF8);
-
- reader.Close();
-
- //IDictionary<int, DbcData> dict = new Dictionary<int, SpellEntry>();
- //if (entry == DBCFileEntries.SPELL)
- {
- dict.Add(0, new DbcData());
- // DBC.Spell = Convert.ChangeType(dict, Dictionary<int, SpellEntry>);
- }
-
-
- /*byte[][] m_rows = new byte[recordsCount][];
-
- for (int i = 0; i < recordsCount; i++)
- m_rows[i] = dataReader.ReadBytes(recordSize);
-
- foreach (var field in shem)
- dbcTable.Columns.Add(field[1].ToString());
-
- for (int i = 0; i < recordsCount; ++i)
- {
- GenericReader rowsReader = new GenericReader(new MemoryStream(m_rows[i]), Encoding.UTF8);
- DataRow rows = dbcTable.NewRow();
-
- foreach (var field in shem)
- {
- switch (field[0])
- {
- case "ulong": rows[field[1]] = rowsReader.ReadUInt64();
- break;
- case "int": rows[field[1]] = rowsReader.ReadInt32();
- break;
- case "uint": rows[field[1]] = rowsReader.ReadUInt32();
- break;
- case "float": rows[field[1]] = Regex.Replace(rowsReader.ReadSingle().ToString(), @",", @".");
- break;
- case "string": rows[field[1]] = stringsReader.ReadStringDbc(rowsReader.ReadInt32());
- break;
- case "struct": rows[field[1]] = BinaryReaderExtensions.ReadStruct<SpellEntry>(rowsReader);
- break;
- default:
- break;
- }
- }
- dbcTable.Rows.Add(rows);
- rowsReader.Close();
-
- Program.loadingForm.ProgressBarStep(lThreadId);
- }
- dataReader.Close();
- stringsReader.Close();
- }*/
}
class GenericReader : BinaryReader
@@ -190,14 +94,8 @@ class GenericReader : BinaryReader
public String ReadStringDbc(Int32 offset)
{
- //Byte num;
- //List<Byte> temp = new List<Byte>();
this.BaseStream.Position = offset;
- /*while ((num = this.ReadByte()) != 0)
- temp.Add(num);
-
- return Encoding.UTF8.GetString(temp.ToArray());*/
return this.ReadCString();
}
}
View
2 Program.cs
@@ -28,7 +28,7 @@ static void Main()
// 'loader' must complete it's work to this time
// but user can manually close the window
- // or something ban can happen
+ // or something bad can happen
if (loader != null)
{
loader.Close();
View
7 README
@@ -0,0 +1,7 @@
+SpellWork is a tool originally created by Chestr (also known as DiSlord).
+
+This project is a try to rebuild the application using C#.
+
+Thanks goes to:
+ Chestr - for the idea and released source of original spell_work
+ TOM_RUS - for code samples
View
2 Util/Time.cs
@@ -7,7 +7,7 @@ static class Time
/// <summary>
/// A function to calculate time diff
/// </summary>
- /// <returns>Milliseconds between to timestamps</returns>
+ /// <returns>Milliseconds between two timestamps</returns>
public static Int32 MsDiff(DateTime time1, DateTime time2)
{
return (Int32)(time2 - time1).TotalMilliseconds;

0 comments on commit ff4dc9f

Please sign in to comment.
Something went wrong with that request. Please try again.