Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //AbstractDBC.cs:
- public struct DBC_Header
- {
- public uint Magic;
- public uint RecordCount;
- public uint FieldCount;
- public uint RecordSize;
- public int StringBlockSize;
- };
- public class DBC_Body<RecordMap>
- {
- public RecordMap[] records;
- };
- //SpellDBC.cs:
- DBCReader reader = new DBCReader("DBC/Spell.dbc");
- DBC_Header header = reader.ReadDBCHeader();
- body = new DBC_Body<Spell_DBC_RecordMap>();
- reader.ReadDBCRecords<Spell_DBC_RecordMap, Spell_DBC_Record>(body, Marshal.SizeOf(typeof(Spell_DBC_Record)));
- //DBCReader.cs:
- // RecordContainer =
- /*
- public struct Spell_DBC_RecordMap
- {
- public Spell_DBC_Record record;
- public string[] spellName;
- public string[] spellRank;
- public string[] spellDesc;
- public string[] spellTool;
- };*/
- // RecordStruct = Spell_DBC_Record (3.3.5a struct)
- public void ReadDBCRecords<RecordContainer, RecordStruct>(DBC_Body<RecordContainer> body, int recordSize)
- {
- if (header.RecordSize != recordSize)
- throw new Exception($"This DBC [{ filePath }] is not supported! It's version is not 3.3.5a 12340, expected record size [{ header.RecordSize }] got [{ recordSize }].");
- body.records = new RecordContainer[header.RecordCount];
- byte[] readBuffer;
- using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
- {
- using (BinaryReader reader = new BinaryReader(fileStream))
- {
- reader.BaseStream.Position = filePosition;
- for (uint i = 0; i < header.RecordCount; ++i)
- {
- readBuffer = new byte[recordSize];
- readBuffer = reader.ReadBytes(recordSize);
- // This line does read the data correctly and has all the correct values
- RecordStruct record = ReadStruct<RecordStruct>(reader, readBuffer);
- FieldInfo field = typeof(RecordContainer).GetField("record");
- field.SetValue(body.records[i], record);
- // The above 2 lines do not seem to update the array :(
- }
- filePosition = reader.BaseStream.Position;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment