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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
#include "ZPath.h"
#include "Globals.h"
#include "Utils/BitConverter.h"
#include "Utils/StringHelper.h"
#include "WarningHandler.h"
#include "ZFile.h"
REGISTER_ZFILENODE(Path, ZPath); // Old name that is being kept for backwards compatability
REGISTER_ZFILENODE(PathList, ZPath); // New name that may be used in future XMLs
ZPath::ZPath(ZFile* nParent) : ZResource(nParent)
{
numPaths = 1;
RegisterOptionalAttribute("NumPaths", "1");
}
void ZPath::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
numPaths = StringHelper::StrToL(registeredAttributes.at("NumPaths").value);
if (numPaths < 1)
{
HANDLE_ERROR_RESOURCE(
WarningType::InvalidAttributeValue, parent, this, rawDataIndex,
StringHelper::Sprintf("invalid value '%d' found for 'NumPaths' attribute", numPaths),
"Should be at least '1'");
}
}
void ZPath::ParseRawData()
{
ZResource::ParseRawData();
uint32_t currentPtr = rawDataIndex;
pathways.reserve(numPaths);
for (size_t pathIndex = 0; pathIndex < numPaths; pathIndex++)
{
PathwayEntry path(parent);
path.ExtractFromFile(currentPtr);
if (path.GetListAddress() == 0)
break;
currentPtr += path.GetRawDataSize();
pathways.push_back(path);
}
}
void ZPath::DeclareReferences(const std::string& prefix)
{
ZResource::DeclareReferences(prefix);
for (auto& entry : pathways)
entry.DeclareReferences(prefix);
}
Declaration* ZPath::DeclareVar(const std::string& prefix, const std::string& bodyStr)
{
std::string auxName = name;
if (name == "")
auxName = GetDefaultName(prefix);
Declaration* decl =
parent->AddDeclarationArray(rawDataIndex, GetDeclarationAlignment(), GetRawDataSize(),
GetSourceTypeName(), name, pathways.size(), bodyStr);
decl->staticConf = staticConf;
return decl;
}
std::string ZPath::GetBodySourceCode() const
{
std::string declaration;
size_t index = 0;
for (const auto& entry : pathways)
{
declaration += StringHelper::Sprintf("\t{ %s },", entry.GetBodySourceCode().c_str());
if (index < pathways.size() - 1)
declaration += "\n";
index++;
}
return declaration;
}
std::string ZPath::GetSourceTypeName() const
{
return "Path";
}
ZResourceType ZPath::GetResourceType() const
{
return ZResourceType::Path;
}
size_t ZPath::GetRawDataSize() const
{
return pathways.size() * pathways.at(0).GetRawDataSize();
}
void ZPath::SetNumPaths(uint32_t nNumPaths)
{
numPaths = nNumPaths;
}
/* PathwayEntry */
PathwayEntry::PathwayEntry(ZFile* nParent) : ZResource(nParent)
{
}
void PathwayEntry::ParseRawData()
{
ZResource::ParseRawData();
auto parentRawData = parent->GetRawData();
numPoints = parentRawData.at(rawDataIndex + 0);
unk1 = parentRawData.at(rawDataIndex + 1);
unk2 = BitConverter::ToInt16BE(parentRawData, rawDataIndex + 2);
listSegmentAddress = BitConverter::ToInt32BE(parentRawData, rawDataIndex + 4);
uint32_t currentPtr = GETSEGOFFSET(listSegmentAddress);
points.reserve(numPoints);
for (int32_t i = 0; i < numPoints; i++)
{
ZVector vec(parent);
vec.ExtractFromBinary(currentPtr, ZScalarType::ZSCALAR_S16, 3);
currentPtr += vec.GetRawDataSize();
points.push_back(vec);
}
}
void PathwayEntry::DeclareReferences(const std::string& prefix)
{
ZResource::DeclareReferences(prefix);
if (points.empty())
return;
std::string pointsName;
bool addressFound = Globals::Instance->GetSegmentedPtrName(listSegmentAddress, parent, "Vec3s",
pointsName, false, parent->workerID);
if (addressFound)
return;
std::string declaration = "";
size_t index = 0;
for (const auto& point : points)
{
declaration += StringHelper::Sprintf("\t{ %s },", point.GetBodySourceCode().c_str());
if (index < points.size() - 1)
declaration += "\n";
index++;
}
uint32_t pointsOffset = Seg2Filespace(listSegmentAddress, parent->baseAddress);
Declaration* decl = parent->GetDeclaration(pointsOffset);
if (decl == nullptr)
{
pointsName = StringHelper::Sprintf("%sPathwayList_%06X", prefix.c_str(), pointsOffset);
parent->AddDeclarationArray(pointsOffset, points.at(0).GetDeclarationAlignment(),
points.size() * 6, points.at(0).GetSourceTypeName(), pointsName,
points.size(), declaration);
}
else
decl->declBody = declaration;
}
std::string PathwayEntry::GetBodySourceCode() const
{
std::string declaration;
std::string listName;
Globals::Instance->GetSegmentedPtrName(listSegmentAddress, parent, "Vec3s", listName, parent->workerID);
if (Globals::Instance->game == ZGame::MM_RETAIL)
declaration +=
StringHelper::Sprintf("%i, %i, %i, %s", numPoints, unk1, unk2, listName.c_str());
else
{
if (numPoints > 0)
declaration +=
StringHelper::Sprintf("ARRAY_COUNT(%s), %s", listName.c_str(), listName.c_str());
else
declaration += StringHelper::Sprintf("%i, %s", numPoints, listName.c_str());
}
return declaration;
}
std::string PathwayEntry::GetSourceTypeName() const
{
return "Path";
}
ZResourceType PathwayEntry::GetResourceType() const
{
return ZResourceType::Path;
}
size_t PathwayEntry::GetRawDataSize() const
{
return 0x08;
}
segptr_t PathwayEntry::GetListAddress() const
{
return listSegmentAddress;
}
|