summaryrefslogtreecommitdiff
path: root/ZAPD/Globals.h
blob: 72e3793c06438a665a4f4e4da2b1e6d75f9f99f4 (plain)
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
#pragma once

#include <map>
#include <string>
#include <vector>
#include "GameConfig.h"
#include "ZFile.h"
#include "ZRom.h"
#include "FileWorker.h"
#include "ExporterSet.h"

class ZRoom;

enum class VerbosityLevel
{
	VERBOSITY_SILENT,
	VERBOSITY_INFO,
	VERBOSITY_DEBUG
};

enum class XMLModeShift : int 
{
	SoundFont,
	Sample,
	Sequence,
	// Add more as more assets support XML exporting.
};

class Globals
{
public:
	static Globals* Instance;

	bool genSourceFile;  // Used for extraction
	bool useExternalResources;
	bool testMode;  // Enables certain experimental features
	bool outputCrc = false;
	bool profile;  // Measure performance of certain operations
	bool useLegacyZDList;
	bool singleThreaded;
	VerbosityLevel verbosity;  // ZAPD outputs additional information
	ZFileMode fileMode = ZFileMode::Invalid;
	fs::path baseRomPath, inputPath, outputPath, sourceOutputPath, cfgPath, fileListPath;
	TextureType texType;
	ZGame game;
	GameConfig cfg;
	bool verboseUnaccounted = false;
	bool gccCompat = false;
	bool forceStatic = false;
	bool forceUnaccountedStatic = false;
	bool otrMode = true;
	bool buildRawTexture = false;
	bool onlyGenCustomOtr = false;
	uint32_t xmlExtractModes = 0;

	ZRom* rom = nullptr;
	std::vector<ZFile*> files;
	std::vector<ZFile*> externalFiles;
	std::vector<int32_t> segments;
	std::vector<ZFile*> segmentFiles;

	std::map<int, FileWorker*> workerData;

	std::string currentExporter;
	static std::map<std::string, ExporterSet*>& GetExporterMap();
	static void AddExporter(std::string exporterName, ExporterSet* exporterSet);

	Globals();
	~Globals();

	void AddSegment(int32_t segment, ZFile* file, int workerID);
	bool HasSegment(int32_t segment, int workerID);
	ZFile* GetSegment(int32_t segment, int workerID);
	std::map<int32_t, std::vector<ZFile*>> GetSegmentRefFiles(int workerID);
	void AddFile(ZFile* file, int workerID);
	void AddExternalFile(ZFile* file, int workerID);
	void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath);

	ZResourceExporter* GetExporter(ZResourceType resType);
	ExporterSet* GetExporterSet();

	std::vector<uint8_t> GetBaseromFile(std::string fileName);

	/**
	 * Search in every file (and the symbol map) for the `segAddress` passed as parameter.
	 * If the segment of `currentFile` is the same segment of `segAddress`, then that file will be
	 * used only, otherwise, the search will be performed in every other file.
	 * The name of that variable will be stored in the `declName` parameter.
	 * Returns `true` if the address is found. `false` otherwise,
	 * in which case `declName` will be set to the address formatted as a pointer.
	 */
	bool GetSegmentedPtrName(segptr_t segAddress, ZFile* currentFile,
	                         const std::string& expectedType, std::string& declName,
	                         int workerID, bool warnIfNotFound = true);

	bool GetSegmentedArrayIndexedName(segptr_t segAddress, size_t elementSize, ZFile* currentFile,
	                                  const std::string& expectedType, std::string& declName,
	                                  int workerID, bool warnIfNotFound = true);

	// TODO: consider moving to another place
	void WarnHardcodedPointer(segptr_t segAddress, ZFile* currentFile, ZResource* res,
	                          offset_t currentOffset);
};