Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to use latest version of ZAPD #777

Merged
merged 10 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ build/src/overlays/actors/%.o: CC := python3 tools/asm_processor/build.py $(CC)
build/src/overlays/effects/%.o: CC := python3 tools/asm_processor/build.py $(CC) -- $(AS) $(ASFLAGS) --
build/src/overlays/gamestates/%.o: CC := python3 tools/asm_processor/build.py $(CC) -- $(AS) $(ASFLAGS) --

build/assets/%.o: CC := python3 tools/asm_processor/build.py $(CC) -- $(AS) $(ASFLAGS) --

#### Main Targets ###

all: $(ROM)
Expand Down Expand Up @@ -232,7 +234,7 @@ build/src/overlays/%.o: src/overlays/%.c

build/src/%.o: src/%.c
$(CC) -c $(CFLAGS) $(MIPS_VERSION) $(OPTFLAGS) -o $@ $^
$(CC_CHECK) $^
#$(CC_CHECK) $^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for this change?

Copy link
Contributor Author

@NEstelami NEstelami Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that was done by accident or as part of some test I didn't revert afterwards. I'll undo it.

Copy link
Contributor

@louist103 louist103 Apr 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I might have been the one who did it but thanks for fixing it for me. I remember turning it off for something.

@$(OBJDUMP) -d $@ > $(@:.o=.s)

build/src/libultra_boot_O1/ll.o: src/libultra_boot_O1/ll.c
Expand Down
4 changes: 3 additions & 1 deletion assets/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.bin
*.c
*.h
*.cfg
*.cfg
*.vtx.inc
*.dlist.inc
19 changes: 10 additions & 9 deletions extract_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@
from multiprocessing import Pool
from multiprocessing import cpu_count

def Extract(xmlPath, outputPath):
ExtractFile(xmlPath, outputPath, 1, 0)
def Extract(xmlPath, outputPath, outputSourcePath):
ExtractFile(xmlPath, outputPath, outputSourcePath, 1, 0)

def ExtractScene(xmlPath, outputPath):
ExtractFile(xmlPath, outputPath, 1, 1)
def ExtractScene(xmlPath, outputPath, outputSourcePath):
ExtractFile(xmlPath, outputPath, outputSourcePath, 1, 1)

def ExtractFile(xmlPath, outputPath, genSrcFile, incFilePrefix):
execStr = "tools/ZAPD/ZAPD.out e -eh -i %s -b baserom/ -o %s -gsf %i -ifp %i -sm tools/ZAPD/SymbolMap_OoTMqDbg.txt" % (xmlPath, outputPath, genSrcFile, incFilePrefix)
def ExtractFile(xmlPath, outputPath, outputSourcePath, genSrcFile, incFilePrefix):
NEstelami marked this conversation as resolved.
Show resolved Hide resolved
execStr = "tools/ZAPD/ZAPD.out e -eh -i %s -b baserom/ -o %s -osf %s -gsf %i -ifp %i -rconf tools/ZAPDConfigs/MqDbg/Config.xml" % (xmlPath, outputPath, outputSourcePath, genSrcFile, incFilePrefix)

print(execStr)
os.system(execStr)

def ExtractFunc(fullPath):
outPath = ("assets/" + fullPath.split("assets/xml/")[1]).split(".xml")[0]
outSourcePath = ("assets/" + fullPath.split("assets/xml/")[1]).split(".xml")[0]

if (fullPath.startswith("assets/xml/scenes/")):
ExtractScene(fullPath, outPath)
ExtractScene(fullPath, outPath, outSourcePath)
else:
Extract(fullPath, outPath)
Extract(fullPath, outPath, outSourcePath)

def main():
parser = argparse.ArgumentParser(description="baserom asset extractor")
Expand All @@ -35,7 +36,7 @@ def main():
if asset_path is not None:
if asset_path.endswith("/"):
asset_path = asset_path[0:-1]
Extract(f"assets/xml/{asset_path}.xml", f"assets/{asset_path}/")
Extract(f"assets/xml/{asset_path}.xml", f"assets/{asset_path}/", f"assets/{asset_path}/")
else:
xmlFiles = []
for currentPath, folders, files in os.walk("assets"):
Expand Down
4 changes: 2 additions & 2 deletions tools/ZAPD/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/zeldaret/ZAPD.git
branch = master
commit = c4773301a17a5a9f9c964a3e7ba6dfbf0730a94b
parent = 97f80eeb3f79bafac383fa6dd17765ae291e05d7
commit = 179af7d11fd27b046edfb1bbadade865033583d7
parent = cb808e56e50864759113538bb98ac7d7cff483df
method = merge
cmdver = 0.4.3
27 changes: 22 additions & 5 deletions tools/ZAPD/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
OPTIMIZATION_ON ?= 1

CC := g++
CFLAGS := -g -std=c++17 -I ZAPD -I lib/assimp/include -I lib/elfio -I lib/json/include -I lib/stb -I lib/tinygltf -I lib/libgfxd -I lib/tinyxml2 -O2 -rdynamic
INC := -I ZAPD -I lib/assimp/include -I lib/elfio -I lib/json/include -I lib/stb -I lib/tinygltf -I lib/libgfxd -I lib/tinyxml2

CFLAGS := -g -g3 -fpic -Wl,-export-dynamic -std=c++17 -rdynamic
ifeq ($(OPTIMIZATION_ON),1)
CFLAGS += -O2
else
CFLAGS += -O0
endif

LDFLAGS := -ldl
UNAME := $(shell uname)

FS_INC =
Expand All @@ -13,22 +24,28 @@ CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
CPP_FILES += lib/tinyxml2/tinyxml2.cpp
O_FILES := $(CPP_FILES:.cpp=.o)

all: ZAPD.out
all: ZAPD.out copycheck

genbuildinfo:
python3 ZAPD/genbuildinfo.py

copycheck: ZAPD.out
python3 copycheck.py

clean:
rm -f $(O_FILES) ZAPD.out
$(MAKE) -C lib/libgfxd clean

rebuild: clean all

%.o: %.cpp genbuildinfo
$(CC) $(CFLAGS) -c $< -o $@
%.o: %.cpp
$(CC) $(CFLAGS) $(INC) -c $< -o $@ $(LDFLAGS)

ZAPD/Main.o: genbuildinfo ZAPD/Main.cpp
$(CC) $(CFLAGS) $(INC) -c ZAPD/Main.cpp -o $@ $(LDFLAGS)

lib/libgfxd/libgfxd.a:
$(MAKE) -C lib/libgfxd -j

ZAPD.out: $(O_FILES) lib/libgfxd/libgfxd.a
$(CC) $(CFLAGS) $(O_FILES) lib/libgfxd/libgfxd.a -o $@ $(FS_INC)
$(CC) $(CFLAGS) $(INC) $(O_FILES) lib/libgfxd/libgfxd.a -o $@ $(FS_INC) $(LDFLAGS)
23 changes: 23 additions & 0 deletions tools/ZAPD/ZAPD/CRC32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

static uint32_t CRC32B(unsigned char* message, int size)
{
int32_t byte, crc;
int32_t mask;

crc = 0xFFFFFFFF;

for (int i = 0; i < size; i++)
{
byte = message[i];
crc = crc ^ byte;

for (int j = 7; j >= 0; j--)
{
mask = -(crc & 1);
crc = (crc >> 1) ^ (0xEDB88320 & mask);
}
}

return ~(uint32_t)(crc);
}
72 changes: 62 additions & 10 deletions tools/ZAPD/ZAPD/Globals.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Globals.h"
#include <algorithm>
#include "File.h"
#include "Path.h"
#include "tinyxml2.h"

using namespace tinyxml2;
Expand All @@ -22,6 +23,7 @@ Globals::Globals()
testMode = false;
profile = false;
includeFilePrefix = false;
useLegacyZDList = false;
useExternalResources = true;
lastScene = nullptr;
verbosity = VERBOSITY_SILENT;
Expand Down Expand Up @@ -72,7 +74,10 @@ void Globals::ReadConfigFile(const std::string& configFilePath)
XMLError eResult = doc.LoadFile(configFilePath.c_str());

if (eResult != tinyxml2::XML_SUCCESS)
{
throw std::runtime_error("Error: Unable to read config file.");
return;
}

XMLNode* root = doc.FirstChild();

Expand All @@ -85,14 +90,70 @@ void Globals::ReadConfigFile(const std::string& configFilePath)
if (string(child->Name()) == "SymbolMap")
{
string fileName = string(child->Attribute("File"));
GenSymbolMap(fileName);
GenSymbolMap(Path::GetDirectoryName(configFilePath) + "/" + fileName);
}
else if (string(child->Name()) == "Segment")
{
string fileName = string(child->Attribute("File"));
int segNumber = child->IntAttribute("Number");
segmentRefs[segNumber] = fileName;
}
else if (string(child->Name()) == "ActorList")
{
string fileName = string(child->Attribute("File"));
std::vector<std::string> lines =
File::ReadAllLines(Path::GetDirectoryName(configFilePath) + "/" + fileName);

for (std::string line : lines)
{
cfg.actorList.push_back(StringHelper::Strip(line, "\r"));
}
}
else if (string(child->Name()) == "ObjectList")
{
string fileName = string(child->Attribute("File"));
std::vector<std::string> lines =
File::ReadAllLines(Path::GetDirectoryName(configFilePath) + "/" + fileName);

for (std::string line : lines)
{
cfg.objectList.push_back(StringHelper::Strip(line, "\r"));
}
}
else if (string(child->Name()) == "TexturePool")
{
string fileName = string(child->Attribute("File"));
ReadTexturePool(Path::GetDirectoryName(configFilePath) + "/" + fileName);
}
}
}

void Globals::ReadTexturePool(const std::string& texturePoolXmlPath)
{
XMLDocument doc;
XMLError eResult = doc.LoadFile(texturePoolXmlPath.c_str());

if (eResult != tinyxml2::XML_SUCCESS)
{
fprintf(stderr, "Warning: Unable to read texture pool XML with error code %i\n", eResult);
return;
}

XMLNode* root = doc.FirstChild();

if (root == nullptr)
return;

for (XMLElement* child = root->FirstChildElement(); child != NULL;
child = child->NextSiblingElement())
{
if (string(child->Name()) == "Texture")
{
string crcStr = string(child->Attribute("CRC"));
string texPath = string(child->Attribute("Path"));

cfg.texturePool[strtol(crcStr.c_str(), NULL, 16)] = texPath;
}
}
}

Expand Down Expand Up @@ -120,12 +181,3 @@ bool Globals::HasSegment(int segment)
{
return std::find(segments.begin(), segments.end(), segment) != segments.end();
}

GameConfig::GameConfig()
{
segmentRefs = map<int, string>();
segmentRefFiles = map<int, ZFile*>();
symbolMap = std::map<uint32_t, std::string>();
actorList = std::vector<std::string>();
objectList = std::vector<std::string>();
}
42 changes: 21 additions & 21 deletions tools/ZAPD/ZAPD/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,25 @@
#include "ZRoom/ZRoom.h"
#include "ZTexture.h"

typedef enum VerbosityLevel
enum VerbosityLevel
{
VERBOSITY_SILENT,
VERBOSITY_INFO,
VERBOSITY_DEBUG
} VerbosityLevel;
};

class GameConfig
{
public:
std::map<int, std::string> segmentRefs;
std::map<int, ZFile*> segmentRefFiles;
std::map<uint32_t, std::string> symbolMap;
std::vector<std::string> actorList;
std::vector<std::string> objectList;
std::map<uint32_t, std::string> texturePool; // Key = CRC, Value = Path to Shared Texture

class GameConfig;
GameConfig() = default;
};

class Globals
{
Expand All @@ -23,14 +34,16 @@ class Globals

bool genSourceFile; // Used for extraction
bool useExternalResources;
bool testMode; // Enables certain experimental features
bool profile; // Measure performance of certain operations
bool includeFilePrefix; // Include the file prefix in symbols
bool testMode; // Enables certain experimental features
bool profile; // Measure performance of certain operations
bool includeFilePrefix; // Include the file prefix in symbols
bool useLegacyZDList;
VerbosityLevel verbosity; // ZAPD outputs additional information
ZFileMode fileMode;
std::string baseRomPath, inputPath, outputPath, cfgPath;
std::string baseRomPath, inputPath, outputPath, sourceOutputPath, cfgPath;
TextureType texType;
ZGame game;
GameConfig cfg;

std::vector<ZFile*> files;
std::vector<int> segments;
Expand All @@ -42,25 +55,12 @@ class Globals
Globals();
std::string FindSymbolSegRef(int segNumber, uint32_t symbolAddress);
void ReadConfigFile(const std::string& configFilePath);
void ReadTexturePool(const std::string& texturePoolXmlPath);
void GenSymbolMap(const std::string& symbolMapPath);
void AddSegment(int segment);
bool HasSegment(int segment);
};

class GameConfig
{
public:
std::map<int, std::string> segmentRefs;
std::map<int, ZFile*> segmentRefFiles;
std::map<uint32_t, std::string> symbolMap;
std::vector<std::string> actorList;
std::vector<std::string> objectList;

GameConfig();

private:
};

/*
* Note: In being able to track references across files, there are a few major files that make use
* of segments...
Expand Down
2 changes: 1 addition & 1 deletion tools/ZAPD/ZAPD/HighLevel/HLAnimationIntermediette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ HLAnimationIntermediette* HLAnimationIntermediette::FromZAnimation(ZAnimation* z

ZAnimation* HLAnimationIntermediette::ToZAnimation()
{
ZAnimation* zAnim = new ZAnimation();
ZAnimation* zAnim = new ZAnimation(nullptr);

/*zAnim->limit = limit;
zAnim->frameCount = frameCount;
Expand Down
Loading