forked from thuskey/D2O-Reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD2OReader.cpp
84 lines (64 loc) · 1.95 KB
/
D2OReader.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "D2OReader.h"
D2OReader::D2OReader(const char* filePath)
{
char* binary;
ifstream d2oFile(filePath, ios::in | ios::binary | ios::ate);
if(d2oFile.is_open())
{
int size = d2oFile.tellg();
binary = new char[size];
d2oFile.seekg(0, ios::beg);
d2oFile.read(binary, size);
d2oFile.close();
}
reader = new MessageReader(binary);
datacenter.Register();
initialize();
}
void D2OReader::initialize()
{
char* headers = reader->ReadBytes(3);
if(strcmp(headers, "D2O") != 0)
throw "Header doesn't equal the string 'D2O' : Corrupted file";
readIndexTable();
readClassesTable();
}
void D2OReader::readIndexTable()
{
headerOffset = reader->ReadUInt();
reader->setPosition(headerOffset);
indexTableLen = reader->ReadUInt();
for(int i = 0; i < indexTableLen; i += 8)
{
indexTable.insert(pair<int, int>(reader->ReadUInt(), reader->ReadUInt()));
}
}
void D2OReader::readClassesTable()
{
classCount = reader->ReadUInt();
for(int i = 0; i < classCount; i++)
{
int classId = reader->ReadUInt();
char* classMemberName = reader->ReadUTF();
char* classPackageName = reader->ReadUTF();
IDataCenter* currentClass = datacenter.get(classMemberName);
if(currentClass == 0)
throw "No data class found";
//currentClass->getModuleName();
int fieldsCount = reader->ReadInt();
for(int j = 0; j < fieldsCount; j++)
{
char* fieldName = reader->ReadUTF();
D2OFieldType fieldType = (D2OFieldType)reader->ReadUInt();
cout << fieldName << endl;
if(fieldType == Vector)
{
addVectorType:
char* name = reader->ReadUTF();
D2OFieldType id = (D2OFieldType)reader->ReadUInt();
if(id == Vector)
goto addVectorType;
}
}
}
}