forked from derandark/PhatAC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTurbineData.cpp
More file actions
135 lines (99 loc) · 2.36 KB
/
TurbineData.cpp
File metadata and controls
135 lines (99 loc) · 2.36 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "StdAfx.h"
#include "Globals.h"
//
#include "TurbineData.h"
#include "TurbineObject.h"
TurbineData::TurbineData()
{
m_dwVersion = 0;
m_mFileInfo.clear();
m_mObjects.clear();
m_strPath = csprintf("%s\\Data\\", g_pGlobals->GetGameDirectory());
}
TurbineData::~TurbineData()
{
CloseFile();
}
void TurbineData::FileFoundCallback(void *This, DWORD dwFileID, BTreeEntry *pEntry)
{
((TurbineData *)This)->FileFoundCallbackInternal(dwFileID, pEntry);
}
void TurbineData::FileFoundCallbackInternal(DWORD dwFileID, BTreeEntry *pEntry)
{
FILEINFO info;
info.dwPosition = pEntry->BlockHead;
info.dwLength = pEntry->Length;
m_mFileInfo[dwFileID] = info;
}
void TurbineData::LoadFile(const char* szFile)
{
OutputConsole("Loading %s.. ", szFile);
m_strFile = szFile;
std::string fullpath = m_strPath + "\\" + szFile;
m_pDATDisk = new DATDisk(fullpath.c_str());
if (!m_pDATDisk->Open())
{
OutputConsole("Error loading file %s!\r\n", fullpath.c_str());
SafeDelete(m_pDATDisk);
}
else
{
OutputConsole("mapping.. ");
m_pDATDisk->FindFileIDsWithinRange(0, (DWORD)-1, FileFoundCallback, NULL, this);
OutputConsole("done!\r\n");
#ifdef PRE_TOD_DATA_FILES
#else
OutputConsole("%s: version %u, %u entries.\r\n", szFile, m_pDATDisk->GetHeader()->VersionMinor, m_mFileInfo.size());
#endif
}
}
void TurbineData::CloseFile()
{
SafeDelete(m_pDATDisk);
//clean up object pool
for (OBJECTMAP::iterator i = m_mObjects.begin(); i != m_mObjects.end(); ++i)
SafeDelete(i->second);
m_mObjects.clear();
m_mFileInfo.clear();
}
BOOL TurbineData::FileExists(DWORD dwID)
{
FILEMAP::iterator i = m_mFileInfo.find(dwID);
return (i != m_mFileInfo.end()) ? TRUE : FALSE;
}
TURBINEFILE *TurbineData::GetFile(DWORD dwID)
{
DATEntry entry;
if (m_pDATDisk && m_pDATDisk->GetData(dwID, &entry))
{
return new TurbineFile(dwID, entry.Data, entry.Length);
}
return NULL;
}
DWORD TurbineData::GetFileCount()
{
return (DWORD)m_mFileInfo.size();
}
DWORD TurbineData::GetVersion()
{
return m_dwVersion;
}
FILEMAP *TurbineData::GetFiles()
{
return &m_mFileInfo;
}
void TurbineData::Think()
{
}
void TurbineData::InsertObject(DWORD dwID, TURBINEOBJECT* pObject)
{
m_mObjects[dwID] = pObject;
}
TURBINEOBJECT *TurbineData::FindObject(DWORD dwFileID)
{
OBJECTMAP::iterator it = m_mObjects.find(dwFileID);
if (it != m_mObjects.end())
return it->second;
else
return NULL;
}