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
|
#include "SetRoomList.h"
#include "Globals.h"
#include "Utils/BitConverter.h"
#include "Utils/StringHelper.h"
#include "ZFile.h"
#include "ZRoom/ZRoom.h"
SetRoomList::SetRoomList(ZFile* nParent) : ZRoomCommand(nParent)
{
}
void SetRoomList::ParseRawData()
{
ZRoomCommand::ParseRawData();
int numRooms = cmdArg1;
romfile = new RomFile(parent);
romfile->numRooms = numRooms;
romfile->ExtractFromFile(segmentOffset);
parent->resources.push_back(romfile);
zRoom->roomCount = numRooms;
}
void SetRoomList::DeclareReferences(const std::string& prefix)
{
ZRoomCommand::DeclareReferences(prefix);
romfile->DeclareVar(prefix, "");
}
std::string SetRoomList::GetBodySourceCode() const
{
std::string listName;
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "RomFile", listName, parent->workerID);
return StringHelper::Sprintf("SCENE_CMD_ROOM_LIST(%i, %s)", romfile->rooms.size(),
listName.c_str());
}
std::string SetRoomList::GetCommandCName() const
{
return "SCmdRoomList";
}
RoomCommand SetRoomList::GetRoomCommand() const
{
return RoomCommand::SetRoomList;
}
RomFile::RomFile(ZFile* nParent) : ZResource(nParent)
{
}
void RomFile::ParseXML(tinyxml2::XMLElement* reader)
{
ZResource::ParseXML(reader);
if (reader->Attribute("NumRooms") != nullptr)
{
numRooms = StringHelper::StrToL(std::string(reader->Attribute("NumRooms")));
}
}
void RomFile::ParseRawData()
{
ZResource::ParseRawData();
uint32_t currentPtr = rawDataIndex;
rooms.reserve(numRooms);
for (int32_t i = 0; i < numRooms; i++)
{
RoomEntry entry(parent->GetRawData(), currentPtr);
rooms.push_back(entry);
currentPtr += 8;
}
}
Declaration* RomFile::DeclareVar(const std::string& prefix, const std::string& body)
{
std::string auxName = name;
if (name == "")
auxName = StringHelper::Sprintf("%sRoomList0x%06X", prefix.c_str(), rawDataIndex);
return parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4,
rooms.size() * rooms.at(0).GetRawDataSize(),
GetSourceTypeName(), auxName, rooms.size(), body);
}
std::string RomFile::GetBodySourceCode() const
{
std::string declaration;
bool isFirst = true;
for (ZFile* file : Globals::Instance->files)
{
for (ZResource* res : file->resources)
{
if (res->GetResourceType() == ZResourceType::Room)
{
std::string roomName = res->GetName();
if (!isFirst)
declaration += "\n";
declaration += StringHelper::Sprintf(
"\t{ (uintptr_t)_%sSegmentRomStart, (uintptr_t)_%sSegmentRomEnd },",
roomName.c_str(), roomName.c_str());
isFirst = false;
}
}
}
return declaration;
}
void RomFile::GetSourceOutputCode(const std::string& prefix)
{
DeclareVar(prefix, GetBodySourceCode());
}
std::string RomFile::GetSourceTypeName() const
{
return "RomFile";
}
ZResourceType RomFile::GetResourceType() const
{
// TODO
return ZResourceType::Error;
}
size_t RomFile::GetRawDataSize() const
{
return 8 * rooms.size();
}
RoomEntry::RoomEntry(uint32_t nVAS, uint32_t nVAE)
{
virtualAddressStart = nVAS;
virtualAddressEnd = nVAE;
}
RoomEntry::RoomEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
: RoomEntry(BitConverter::ToInt32BE(rawData, rawDataIndex + 0),
BitConverter::ToInt32BE(rawData, rawDataIndex + 4))
{
}
size_t RoomEntry::GetRawDataSize() const
{
return 0x08;
}
|