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
|
#pragma once
#define NO_GDI
#define WIN32_LEAN_AND_MEAN
#include <string>
#include <vector>
#include "ZSymbol.h"
#include "ZTexture.h"
#include "tinyxml2.h"
#undef FindResource
enum class ZFileMode
{
BuildTexture,
BuildOverlay,
BuildBlob,
BuildSourceFile,
BuildBackground,
Extract,
ExternalFile,
ExtractDirectory,
Invalid,
Custom = 1000, // Used for exporter file modes
};
enum class ZGame
{
OOT_RETAIL,
OOT_SW97,
MM_RETAIL
};
class ZFile
{
public:
std::map<offset_t, Declaration*> declarations;
std::vector<ZResource*> resources;
std::string defines;
int workerID;
bool isCompilable = false;
// Default to using virtual addresses
uint32_t segment = 0x80;
uint32_t baseAddress, rangeStart, rangeEnd;
bool isExternalFile = false;
// Whether to make defines for texture dimensions, and possibly more in future
bool makeDefines = false;
ZFile(const fs::path& nOutPath, const std::string& nName);
ZFile(ZFileMode nMode, tinyxml2::XMLElement* reader, const fs::path& nBasePath,
const fs::path& nOutPath, const std::string& filename, const fs::path& nXmlFilePath, int nWorkerID);
~ZFile();
std::string GetName() const;
std::string GetOutName() const;
ZFileMode GetMode() const;
const fs::path& GetXmlFilePath() const;
const std::vector<uint8_t>& GetRawData() const;
void ExtractResources();
void BuildSourceFile();
void AddResource(ZResource* res);
ZResource* FindResource(offset_t rawDataIndex);
std::vector<ZResource*> GetResourcesOfType(ZResourceType resType);
Declaration* AddDeclaration(offset_t address, DeclarationAlignment alignment, size_t size,
const std::string& varType, const std::string& varName,
const std::string& body);
Declaration* AddDeclarationArray(offset_t address, DeclarationAlignment alignment, size_t size,
const std::string& varType, const std::string& varName,
size_t arrayItemCnt, const std::string& body);
Declaration* AddDeclarationArray(offset_t address, DeclarationAlignment alignment, size_t size,
const std::string& varType, const std::string& varName,
const std::string& arrayItemCntStr, const std::string& body);
Declaration* AddDeclarationPlaceholder(offset_t address, const std::string& varName);
Declaration* AddDeclarationInclude(offset_t address, const std::string& includePath,
size_t size, const std::string& varType,
const std::string& varName);
Declaration* AddDeclarationIncludeArray(offset_t address, std::string& includePath, size_t size,
const std::string& varType, const std::string& varName,
size_t arrayItemCnt);
Declaration* AddDeclarationIncludeArray(offset_t address, std::string& includePath, size_t size,
const std::string& varType, const std::string& varName,
const std::string& defines, size_t arrayItemCnt);
bool GetDeclarationPtrName(segptr_t segAddress, const std::string& expectedType,
std::string& declName) const;
bool GetDeclarationArrayIndexedName(segptr_t segAddress, size_t elementSize,
const std::string& expectedType,
std::string& declName) const;
Declaration* GetDeclaration(offset_t address) const;
Declaration* GetDeclarationRanged(offset_t address) const;
bool HasDeclaration(offset_t address);
size_t GetDeclarationSizeFromNeighbor(uint32_t declarationAddress);
std::string GetHeaderInclude() const;
std::string GetZRoomHeaderInclude() const;
std::string GetExternalFileHeaderInclude() const;
void GeneratePlaceholderDeclarations();
void AddTextureResource(uint32_t offset, ZTexture* tex);
ZTexture* GetTextureResource(uint32_t offset) const;
void AddSymbolResource(uint32_t offset, ZSymbol* sym);
ZSymbol* GetSymbolResource(uint32_t offset) const;
ZSymbol* GetSymbolResourceRanged(uint32_t offset) const;
fs::path GetSourceOutputFolderPath() const;
bool IsOffsetInFileRange(uint32_t offset) const;
bool IsSegmentedInFilespaceRange(segptr_t segAddress) const;
static std::map<std::string, ZResourceFactoryFunc*>* GetNodeMap();
static void RegisterNode(std::string nodeName, ZResourceFactoryFunc* nodeFunc);
protected:
std::string name;
fs::path outName = "";
fs::path basePath;
fs::path outputPath;
fs::path xmlFilePath;
std::vector<uint8_t> rawData;
// Keep track of every texture of this ZFile.
// The pointers declared here are "borrowed" (somebody else is the owner),
// so ZFile shouldn't delete/free those textures.
std::map<uint32_t, ZTexture*> texturesResources;
std::map<uint32_t, ZSymbol*> symbolResources;
ZFileMode mode = ZFileMode::Invalid;
ZFile();
void ParseXML(tinyxml2::XMLElement* reader, const std::string& filename);
void DeclareResourceSubReferences();
void GenerateSourceFiles();
void GenerateSourceHeaderFiles();
bool DeclarationSanityChecks(uint32_t address, const std::string& varName);
std::string ProcessDeclarations();
void MergeNeighboringDeclarations();
void ProcessDeclarationText(Declaration* decl);
std::string ProcessExterns();
std::string ProcessTextureIntersections(const std::string& prefix);
void HandleUnaccountedData();
bool HandleUnaccountedAddress(offset_t currentAddress, offset_t lastAddr, uint32_t& lastSize);
};
|