mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-08-20 21:33:40 -07:00
git subrepo clone https://github.com/HarbourMasters/ZAPDTR.git
subrepo: subdir: "ZAPDTR" merged: "a53a53ea4" upstream: origin: "https://github.com/HarbourMasters/ZAPDTR.git" branch: "master" commit: "a53a53ea4" git-subrepo: version: "0.4.1" origin: "???" commit: "???"
This commit is contained in:
parent
f52a2a6406
commit
5dda5762ba
217 changed files with 47152 additions and 0 deletions
225
ZAPDTR/ZAPD/Globals.cpp
Normal file
225
ZAPDTR/ZAPD/Globals.cpp
Normal file
|
@ -0,0 +1,225 @@
|
|||
#include "Globals.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
|
||||
#include "Utils/File.h"
|
||||
#include "Utils/Path.h"
|
||||
#include "WarningHandler.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
Globals* Globals::Instance;
|
||||
|
||||
Globals::Globals()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
game = ZGame::OOT_RETAIL;
|
||||
genSourceFile = true;
|
||||
testMode = false;
|
||||
profile = false;
|
||||
useLegacyZDList = false;
|
||||
useExternalResources = true;
|
||||
verbosity = VerbosityLevel::VERBOSITY_SILENT;
|
||||
outputPath = Directory::GetCurrentDirectory();
|
||||
}
|
||||
|
||||
Globals::~Globals()
|
||||
{
|
||||
auto& exporters = GetExporterMap();
|
||||
|
||||
for (auto& it : exporters)
|
||||
{
|
||||
delete it.second;
|
||||
}
|
||||
}
|
||||
|
||||
void Globals::AddSegment(int32_t segment, ZFile* file)
|
||||
{
|
||||
if (std::find(segments.begin(), segments.end(), segment) == segments.end())
|
||||
segments.push_back(segment);
|
||||
if (cfg.segmentRefFiles.find(segment) == cfg.segmentRefFiles.end())
|
||||
cfg.segmentRefFiles[segment] = std::vector<ZFile*>();
|
||||
|
||||
cfg.segmentRefFiles[segment].push_back(file);
|
||||
}
|
||||
|
||||
bool Globals::HasSegment(int32_t segment)
|
||||
{
|
||||
return std::find(segments.begin(), segments.end(), segment) != segments.end();
|
||||
}
|
||||
|
||||
ZFile* Globals::GetSegment(int32_t segment)
|
||||
{
|
||||
if (HasSegment(segment))
|
||||
{
|
||||
int idx = std::find(segments.begin(), segments.end(), segment) - segments.begin();
|
||||
return files[idx];
|
||||
}
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::map<std::string, ExporterSet*>& Globals::GetExporterMap()
|
||||
{
|
||||
static std::map<std::string, ExporterSet*> exporters;
|
||||
return exporters;
|
||||
}
|
||||
|
||||
void Globals::AddExporter(std::string exporterName, ExporterSet* exporterSet)
|
||||
{
|
||||
auto& exporters = GetExporterMap();
|
||||
exporters[exporterName] = exporterSet;
|
||||
}
|
||||
|
||||
ZResourceExporter* Globals::GetExporter(ZResourceType resType)
|
||||
{
|
||||
auto& exporters = GetExporterMap();
|
||||
|
||||
if (currentExporter != "" && exporters[currentExporter]->exporters.find(resType) !=
|
||||
exporters[currentExporter]->exporters.end())
|
||||
return exporters[currentExporter]->exporters[resType];
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ExporterSet* Globals::GetExporterSet()
|
||||
{
|
||||
auto& exporters = GetExporterMap();
|
||||
|
||||
if (currentExporter != "")
|
||||
return exporters[currentExporter];
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Globals::GetSegmentedPtrName(segptr_t segAddress, ZFile* currentFile,
|
||||
const std::string& expectedType, std::string& declName)
|
||||
{
|
||||
if (segAddress == 0)
|
||||
{
|
||||
declName = "NULL";
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t segment = GETSEGNUM(segAddress);
|
||||
uint32_t offset = Seg2Filespace(segAddress, currentFile->baseAddress);
|
||||
ZSymbol* sym;
|
||||
|
||||
sym = currentFile->GetSymbolResource(offset);
|
||||
if (sym != nullptr)
|
||||
{
|
||||
if (expectedType == "" || expectedType == sym->GetSourceTypeName())
|
||||
{
|
||||
declName = sym->GetName();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
sym = currentFile->GetSymbolResource(segAddress);
|
||||
if (sym != nullptr)
|
||||
{
|
||||
if (expectedType == "" || expectedType == sym->GetSourceTypeName())
|
||||
{
|
||||
declName = sym->GetName();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentFile->IsSegmentedInFilespaceRange(segAddress))
|
||||
{
|
||||
if (currentFile->GetDeclarationPtrName(segAddress, expectedType, declName))
|
||||
return true;
|
||||
}
|
||||
else if (HasSegment(segment))
|
||||
{
|
||||
for (auto file : cfg.segmentRefFiles[segment])
|
||||
{
|
||||
offset = Seg2Filespace(segAddress, file->baseAddress);
|
||||
|
||||
sym = file->GetSymbolResource(offset);
|
||||
if (sym != nullptr)
|
||||
{
|
||||
if (expectedType == "" || expectedType == sym->GetSourceTypeName())
|
||||
{
|
||||
declName = sym->GetName();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
sym = file->GetSymbolResource(segAddress);
|
||||
if (sym != nullptr)
|
||||
{
|
||||
if (expectedType == "" || expectedType == sym->GetSourceTypeName())
|
||||
{
|
||||
declName = sym->GetName();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (file->IsSegmentedInFilespaceRange(segAddress))
|
||||
{
|
||||
if (file->GetDeclarationPtrName(segAddress, expectedType, declName))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const auto& symbolFromMap = Globals::Instance->cfg.symbolMap.find(segAddress);
|
||||
if (symbolFromMap != Globals::Instance->cfg.symbolMap.end())
|
||||
{
|
||||
declName = "&" + symbolFromMap->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
declName = StringHelper::Sprintf("0x%08X", segAddress);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Globals::GetSegmentedArrayIndexedName(segptr_t segAddress, size_t elementSize,
|
||||
ZFile* currentFile, const std::string& expectedType,
|
||||
std::string& declName)
|
||||
{
|
||||
if (segAddress == 0)
|
||||
{
|
||||
declName = "NULL";
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t segment = GETSEGNUM(segAddress);
|
||||
|
||||
if (currentFile->IsSegmentedInFilespaceRange(segAddress))
|
||||
{
|
||||
bool addressFound = currentFile->GetDeclarationArrayIndexedName(segAddress, elementSize,
|
||||
expectedType, declName);
|
||||
if (addressFound)
|
||||
return true;
|
||||
}
|
||||
else if (HasSegment(segment))
|
||||
{
|
||||
for (auto file : cfg.segmentRefFiles[segment])
|
||||
{
|
||||
if (file->IsSegmentedInFilespaceRange(segAddress))
|
||||
{
|
||||
bool addressFound = file->GetDeclarationArrayIndexedName(segAddress, elementSize,
|
||||
expectedType, declName);
|
||||
if (addressFound)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declName = StringHelper::Sprintf("0x%08X", segAddress);
|
||||
return false;
|
||||
}
|
||||
|
||||
ExternalFile::ExternalFile(fs::path nXmlPath, fs::path nOutPath)
|
||||
: xmlPath{nXmlPath}, outPath{nOutPath}
|
||||
{
|
||||
}
|
||||
|
||||
ExporterSet::~ExporterSet()
|
||||
{
|
||||
for (auto& it : exporters)
|
||||
{
|
||||
delete it.second;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue