mirror of
https://github.com/zeldaret/oot.git
synced 2025-07-03 06:24:30 +00:00
Update ZAPD (#1001)
* remove fake match * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "3e9ed72e2" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "3e9ed72e2" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * new extraction script and a hack to make clear tag work * fix clear tag again * remove static from clear tag DLists * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "e7a8a48cf" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "e7a8a48cf" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "e243634e5" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "e243634e5" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * git subrepo pull --force tools/ZAPD subrepo: subdir: "tools/ZAPD" merged: "d0cd6b397" upstream: origin: "https://github.com/zeldaret/ZAPD.git" branch: "master" commit: "d0cd6b397" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo.git" commit: "2f68596" * Update ovl_En_Clear_Tag.xml
This commit is contained in:
parent
ed487b4bb8
commit
750c0cab35
272 changed files with 7790 additions and 58414 deletions
|
@ -20,6 +20,10 @@ def ExtractFile(xmlPath, outputPath, outputSourcePath):
|
|||
return
|
||||
|
||||
execStr = "tools/ZAPD/ZAPD.out e -eh -i %s -b baserom/ -o %s -osf %s -gsf 1 -rconf tools/ZAPDConfigs/MqDbg/Config.xml" % (xmlPath, outputPath, outputSourcePath)
|
||||
|
||||
if "overlays" in xmlPath:
|
||||
execStr += " --static"
|
||||
|
||||
if globalUnaccounted:
|
||||
execStr += " -wu"
|
||||
|
||||
|
|
6
tools/ZAPD/.gitignore
vendored
6
tools/ZAPD/.gitignore
vendored
|
@ -333,5 +333,9 @@ ASALocalRun/
|
|||
*.o
|
||||
*.d
|
||||
lib/libgfxd/libgfxd.a
|
||||
ExporterTest/ExporterTest.a
|
||||
ZAPDUtils/ZAPDUtils.a
|
||||
.vscode/
|
||||
ZAPD/BuildInfo.h
|
||||
build/
|
||||
ZAPDUtils/build/
|
||||
ZAPD/BuildInfo.h
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
[subrepo]
|
||||
remote = https://github.com/zeldaret/ZAPD.git
|
||||
branch = master
|
||||
commit = 6be9af65d39a1608ef854efbaf0bf9399aac5da1
|
||||
parent = 913b88b160c735d81f2d4f1d14717de8c7ba8dee
|
||||
commit = d0cd6b3974706fc4d89c9b6545b8c17dd424b664
|
||||
parent = c0e02913038e871221b2fcfc8be65b8dc281aa4a
|
||||
method = merge
|
||||
cmdver = 0.4.3
|
||||
|
|
74
tools/ZAPD/ExporterTest/CollisionExporter.cpp
Normal file
74
tools/ZAPD/ExporterTest/CollisionExporter.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
#include "CollisionExporter.h"
|
||||
|
||||
void ExporterExample_Collision::Save(ZResource* res, [[maybe_unused]] fs::path outPath,
|
||||
BinaryWriter* writer)
|
||||
{
|
||||
ZCollisionHeader* col = (ZCollisionHeader*)res;
|
||||
|
||||
writer->Write(col->absMinX);
|
||||
writer->Write(col->absMinY);
|
||||
writer->Write(col->absMinZ);
|
||||
|
||||
writer->Write(col->absMaxX);
|
||||
writer->Write(col->absMaxY);
|
||||
writer->Write(col->absMaxZ);
|
||||
|
||||
writer->Write(col->numVerts);
|
||||
writer->Write(col->vtxAddress);
|
||||
|
||||
writer->Write(col->numPolygons);
|
||||
writer->Write(col->polyAddress);
|
||||
writer->Write(col->polyTypeDefAddress);
|
||||
writer->Write(col->camDataAddress);
|
||||
|
||||
writer->Write(col->numWaterBoxes);
|
||||
writer->Write(col->waterBoxAddress);
|
||||
|
||||
writer->Write(col->vtxSegmentOffset);
|
||||
writer->Write(col->polySegmentOffset);
|
||||
writer->Write(col->polyTypeDefSegmentOffset);
|
||||
writer->Write(col->camDataSegmentOffset);
|
||||
writer->Write(col->waterBoxSegmentOffset);
|
||||
|
||||
uint32_t oldOffset = writer->GetBaseAddress();
|
||||
|
||||
writer->Seek(col->vtxSegmentOffset, SeekOffsetType::Start);
|
||||
|
||||
for (uint16_t i = 0; i < col->vertices.size(); i++)
|
||||
{
|
||||
for (uint32_t j = 0; j < col->vertices[i].dimensions; j++)
|
||||
{
|
||||
writer->Write(col->vertices[i].scalars[j].scalarData.s16);
|
||||
}
|
||||
}
|
||||
|
||||
writer->Seek(col->polySegmentOffset, SeekOffsetType::Start);
|
||||
|
||||
for (uint16_t i = 0; i < col->polygons.size(); i++)
|
||||
{
|
||||
writer->Write(col->polygons[i].type);
|
||||
writer->Write(col->polygons[i].vtxA);
|
||||
writer->Write(col->polygons[i].vtxB);
|
||||
writer->Write(col->polygons[i].vtxC);
|
||||
writer->Write(col->polygons[i].a);
|
||||
writer->Write(col->polygons[i].b);
|
||||
writer->Write(col->polygons[i].c);
|
||||
writer->Write(col->polygons[i].d);
|
||||
}
|
||||
|
||||
writer->Seek(col->polyTypeDefSegmentOffset, SeekOffsetType::Start);
|
||||
|
||||
for (uint16_t i = 0; i < col->polygonTypes.size(); i++)
|
||||
writer->Write(col->polygonTypes[i]);
|
||||
|
||||
writer->Seek(col->camDataSegmentOffset, SeekOffsetType::Start);
|
||||
|
||||
for (auto entry : col->camData->entries)
|
||||
{
|
||||
writer->Write(entry->cameraSType);
|
||||
writer->Write(entry->numData);
|
||||
writer->Write(entry->cameraPosDataSeg);
|
||||
}
|
||||
|
||||
writer->Seek(oldOffset, SeekOffsetType::Start);
|
||||
}
|
10
tools/ZAPD/ExporterTest/CollisionExporter.h
Normal file
10
tools/ZAPD/ExporterTest/CollisionExporter.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "ZCollision.h"
|
||||
#include "ZResource.h"
|
||||
|
||||
class ExporterExample_Collision : public ZResourceExporter
|
||||
{
|
||||
public:
|
||||
void Save(ZResource* res, fs::path outPath, BinaryWriter* writer) override;
|
||||
};
|
159
tools/ZAPD/ExporterTest/ExporterTest.vcxproj
Normal file
159
tools/ZAPD/ExporterTest/ExporterTest.vcxproj
Normal file
|
@ -0,0 +1,159 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{65608eb0-1a47-45ad-ab66-192fb64c762c}</ProjectGuid>
|
||||
<RootNamespace>ExporterTest</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<ProjectName>ExporterExample</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>$(SolutionDir)\ZAPD\;$(SolutionDir)ZAPDUtils;$(SolutionDir)lib\tinyxml2;$(SolutionDir)lib\libgfxd;$(SolutionDir)lib\elfio;$(SolutionDir)lib\stb;$(ProjectDir);$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CollisionExporter.h" />
|
||||
<ClInclude Include="TextureExporter.h" />
|
||||
<ClInclude Include="RoomExporter.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CollisionExporter.cpp" />
|
||||
<ClCompile Include="TextureExporter.cpp" />
|
||||
<ClCompile Include="Main.cpp" />
|
||||
<ClCompile Include="RoomExporter.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
42
tools/ZAPD/ExporterTest/ExporterTest.vcxproj.filters
Normal file
42
tools/ZAPD/ExporterTest/ExporterTest.vcxproj.filters
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="TextureExporter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="RoomExporter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CollisionExporter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="TextureExporter.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="RoomExporter.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CollisionExporter.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
79
tools/ZAPD/ExporterTest/Main.cpp
Normal file
79
tools/ZAPD/ExporterTest/Main.cpp
Normal file
|
@ -0,0 +1,79 @@
|
|||
#include <CollisionExporter.h>
|
||||
#include <Globals.h>
|
||||
#include <RoomExporter.h>
|
||||
#include <TextureExporter.h>
|
||||
|
||||
enum class ExporterFileMode
|
||||
{
|
||||
ModeExample1 = (int)ZFileMode::Custom + 1,
|
||||
ModeExample2 = (int)ZFileMode::Custom + 2,
|
||||
ModeExample3 = (int)ZFileMode::Custom + 3,
|
||||
};
|
||||
|
||||
static void ExporterParseFileMode(const std::string& buildMode, ZFileMode& fileMode)
|
||||
{
|
||||
if (buildMode == "me1")
|
||||
fileMode = (ZFileMode)ExporterFileMode::ModeExample1;
|
||||
else if (buildMode == "me2")
|
||||
fileMode = (ZFileMode)ExporterFileMode::ModeExample2;
|
||||
else if (buildMode == "me3")
|
||||
fileMode = (ZFileMode)ExporterFileMode::ModeExample3;
|
||||
}
|
||||
|
||||
static void ExporterParseArgs([[maybe_unused]] int argc, char* argv[], int& i)
|
||||
{
|
||||
std::string arg = argv[i];
|
||||
|
||||
if (arg == "--do-x")
|
||||
{
|
||||
}
|
||||
else if (arg == "--do-y")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
static bool ExporterProcessFileMode(ZFileMode fileMode)
|
||||
{
|
||||
// Do whatever work is associated with these custom file modes...
|
||||
// Return true to indicate one of our own file modes is being processed
|
||||
if (fileMode == (ZFileMode)ExporterFileMode::ModeExample1)
|
||||
return true;
|
||||
else if (fileMode == (ZFileMode)ExporterFileMode::ModeExample2)
|
||||
return true;
|
||||
else if (fileMode == (ZFileMode)ExporterFileMode::ModeExample3)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void ExporterFileBegin(ZFile* file)
|
||||
{
|
||||
printf("ExporterFileBegin() called on ZFile %s.\n", file->GetName().c_str());
|
||||
}
|
||||
|
||||
static void ExporterFileEnd(ZFile* file)
|
||||
{
|
||||
printf("ExporterFileEnd() called on ZFile %s.\n", file->GetName().c_str());
|
||||
}
|
||||
|
||||
static void ImportExporters()
|
||||
{
|
||||
// In this example we set up a new exporter called "EXAMPLE".
|
||||
// By running ZAPD with the argument -se EXAMPLE, we tell it that we want to use this exporter
|
||||
// for our resources.
|
||||
ExporterSet* exporterSet = new ExporterSet();
|
||||
exporterSet->processFileModeFunc = ExporterProcessFileMode;
|
||||
exporterSet->parseFileModeFunc = ExporterParseFileMode;
|
||||
exporterSet->parseArgsFunc = ExporterParseArgs;
|
||||
exporterSet->beginFileFunc = ExporterFileBegin;
|
||||
exporterSet->endFileFunc = ExporterFileEnd;
|
||||
exporterSet->exporters[ZResourceType::Texture] = new ExporterExample_Texture();
|
||||
exporterSet->exporters[ZResourceType::Room] = new ExporterExample_Room();
|
||||
exporterSet->exporters[ZResourceType::CollisionHeader] = new ExporterExample_Collision();
|
||||
|
||||
Globals::AddExporter("EXAMPLE", exporterSet);
|
||||
}
|
||||
|
||||
// When ZAPD starts up, it will automatically call the below function, which in turn sets up our
|
||||
// exporters.
|
||||
REGISTER_EXPORTER(ImportExporters)
|
28
tools/ZAPD/ExporterTest/Makefile
Normal file
28
tools/ZAPD/ExporterTest/Makefile
Normal file
|
@ -0,0 +1,28 @@
|
|||
# Only used for standalone compilation, usually inherits these from the main makefile
|
||||
CXXFLAGS ?= -Wall -Wextra -O2 -g -std=c++17
|
||||
|
||||
SRC_DIRS := $(shell find -type d -not -path "*build*")
|
||||
CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
|
||||
H_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))
|
||||
|
||||
O_FILES := $(foreach f,$(CPP_FILES:.cpp=.o),build/$f)
|
||||
LIB := ExporterTest.a
|
||||
|
||||
# create build directories
|
||||
$(shell mkdir -p $(foreach dir,$(SRC_DIRS),build/$(dir)))
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
clean:
|
||||
rm -rf build $(LIB)
|
||||
|
||||
format:
|
||||
clang-format-11 -i $(CPP_FILES) $(H_FILES)
|
||||
|
||||
.PHONY: all clean format
|
||||
|
||||
build/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) $(OPTFLAGS) -I ./ -I ../ZAPD -I ../ZAPDUtils -I ../lib/tinyxml2 -c $(OUTPUT_OPTION) $<
|
||||
|
||||
$(LIB): $(O_FILES)
|
||||
$(AR) rcs $@ $^
|
372
tools/ZAPD/ExporterTest/RoomExporter.cpp
Normal file
372
tools/ZAPD/ExporterTest/RoomExporter.cpp
Normal file
|
@ -0,0 +1,372 @@
|
|||
#include "RoomExporter.h"
|
||||
#include <CollisionExporter.h>
|
||||
#include <Utils/BinaryWriter.h>
|
||||
#include <Utils/File.h>
|
||||
#include <Utils/MemoryStream.h>
|
||||
#include <ZRoom/Commands/SetCameraSettings.h>
|
||||
#include <ZRoom/Commands/SetCollisionHeader.h>
|
||||
#include <ZRoom/Commands/SetCsCamera.h>
|
||||
#include <ZRoom/Commands/SetEchoSettings.h>
|
||||
#include <ZRoom/Commands/SetEntranceList.h>
|
||||
#include <ZRoom/Commands/SetLightingSettings.h>
|
||||
#include <ZRoom/Commands/SetMesh.h>
|
||||
#include <ZRoom/Commands/SetRoomBehavior.h>
|
||||
#include <ZRoom/Commands/SetRoomList.h>
|
||||
#include <ZRoom/Commands/SetSkyboxModifier.h>
|
||||
#include <ZRoom/Commands/SetSkyboxSettings.h>
|
||||
#include <ZRoom/Commands/SetSoundSettings.h>
|
||||
#include <ZRoom/Commands/SetSpecialObjects.h>
|
||||
#include <ZRoom/Commands/SetStartPositionList.h>
|
||||
#include <ZRoom/Commands/SetTimeSettings.h>
|
||||
#include <ZRoom/Commands/SetWind.h>
|
||||
|
||||
void ExporterExample_Room::Save(ZResource* res, fs::path outPath, BinaryWriter* writer)
|
||||
{
|
||||
ZRoom* room = dynamic_cast<ZRoom*>(res);
|
||||
|
||||
// MemoryStream* memStream = new MemoryStream();
|
||||
// BinaryWriter* writer = new BinaryWriter(memStream);
|
||||
|
||||
for (size_t i = 0; i < room->commands.size() * 8; i++)
|
||||
writer->Write((uint8_t)0);
|
||||
|
||||
for (size_t i = 0; i < room->commands.size(); i++)
|
||||
{
|
||||
ZRoomCommand* cmd = room->commands[i];
|
||||
|
||||
writer->Seek(i * 8, SeekOffsetType::Start);
|
||||
|
||||
writer->Write((uint8_t)cmd->cmdID);
|
||||
|
||||
switch (cmd->cmdID)
|
||||
{
|
||||
case RoomCommand::SetWind:
|
||||
{
|
||||
SetWind* cmdSetWind = (SetWind*)cmd;
|
||||
|
||||
writer->Write((uint8_t)0); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
|
||||
writer->Write(cmdSetWind->windWest); // 0x04
|
||||
writer->Write(cmdSetWind->windVertical); // 0x05
|
||||
writer->Write(cmdSetWind->windSouth); // 0x06
|
||||
writer->Write(cmdSetWind->clothFlappingStrength); // 0x07
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetTimeSettings:
|
||||
{
|
||||
SetTimeSettings* cmdTime = (SetTimeSettings*)cmd;
|
||||
|
||||
writer->Write((uint8_t)0); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
|
||||
writer->Write(cmdTime->hour); // 0x04
|
||||
writer->Write(cmdTime->min); // 0x05
|
||||
writer->Write(cmdTime->unk); // 0x06
|
||||
writer->Write((uint8_t)0); // 0x07
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetSkyboxModifier:
|
||||
{
|
||||
SetSkyboxModifier* cmdSkybox = (SetSkyboxModifier*)cmd;
|
||||
|
||||
writer->Write((uint8_t)0); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
|
||||
writer->Write(cmdSkybox->disableSky); // 0x04
|
||||
writer->Write(cmdSkybox->disableSunMoon); // 0x05
|
||||
writer->Write((uint8_t)0); // 0x06
|
||||
writer->Write((uint8_t)0); // 0x07
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetEchoSettings:
|
||||
{
|
||||
SetEchoSettings* cmdEcho = (SetEchoSettings*)cmd;
|
||||
|
||||
writer->Write((uint8_t)0); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
writer->Write((uint8_t)0); // 0x04
|
||||
writer->Write((uint8_t)0); // 0x05
|
||||
writer->Write((uint8_t)0); // 0x06
|
||||
writer->Write((uint8_t)cmdEcho->echo); // 0x07
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetSoundSettings:
|
||||
{
|
||||
SetSoundSettings* cmdSound = (SetSoundSettings*)cmd;
|
||||
|
||||
writer->Write((uint8_t)cmdSound->reverb); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
writer->Write((uint8_t)0); // 0x04
|
||||
writer->Write((uint8_t)0); // 0x05
|
||||
|
||||
writer->Write(cmdSound->nightTimeSFX); // 0x06
|
||||
writer->Write(cmdSound->musicSequence); // 0x07
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetSkyboxSettings:
|
||||
{
|
||||
SetSkyboxSettings* cmdSkybox = (SetSkyboxSettings*)cmd;
|
||||
|
||||
writer->Write((uint8_t)cmdSkybox->unk1); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
writer->Write((uint8_t)cmdSkybox->skyboxNumber); // 0x04
|
||||
writer->Write((uint8_t)cmdSkybox->cloudsType); // 0x05
|
||||
writer->Write((uint8_t)cmdSkybox->isIndoors); // 0x06
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetRoomBehavior:
|
||||
{
|
||||
SetRoomBehavior* cmdRoom = (SetRoomBehavior*)cmd;
|
||||
|
||||
writer->Write((uint8_t)cmdRoom->gameplayFlags); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
writer->Write(cmdRoom->gameplayFlags2); // 0x04
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetCsCamera:
|
||||
{
|
||||
SetCsCamera* cmdCsCam = (SetCsCamera*)cmd;
|
||||
|
||||
writer->Write((uint8_t)cmdCsCam->cameras.size()); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
|
||||
writer->Write(cmdCsCam->segmentOffset); // 0x04
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetMesh:
|
||||
{
|
||||
SetMesh* cmdMesh = (SetMesh*)cmd;
|
||||
|
||||
int baseStreamEnd = writer->GetStream().get()->GetLength();
|
||||
|
||||
writer->Write((uint8_t)cmdMesh->data); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
|
||||
writer->Write(baseStreamEnd); // 0x04
|
||||
|
||||
uint32_t oldOffset = writer->GetBaseAddress();
|
||||
writer->Seek(baseStreamEnd, SeekOffsetType::Start);
|
||||
|
||||
// TODO: NOT DONE
|
||||
|
||||
writer->Write(cmdMesh->meshHeaderType);
|
||||
|
||||
if (cmdMesh->meshHeaderType == 0)
|
||||
{
|
||||
// writer->Write(cmdMesh->)
|
||||
}
|
||||
else if (cmdMesh->meshHeaderType == 1)
|
||||
{
|
||||
}
|
||||
else if (cmdMesh->meshHeaderType == 2)
|
||||
{
|
||||
}
|
||||
|
||||
writer->Seek(oldOffset, SeekOffsetType::Start);
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetCameraSettings:
|
||||
{
|
||||
SetCameraSettings* cmdCam = (SetCameraSettings*)cmd;
|
||||
|
||||
writer->Write((uint8_t)cmdCam->cameraMovement); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
writer->Write(cmdCam->mapHighlight); // 0x04
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetLightingSettings:
|
||||
{
|
||||
SetLightingSettings* cmdLight = (SetLightingSettings*)cmd;
|
||||
|
||||
writer->Write((uint8_t)cmdLight->settings.size()); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
writer->Write(cmdLight->segmentOffset); // 0x04
|
||||
|
||||
uint32_t oldOffset = writer->GetBaseAddress();
|
||||
writer->Seek(cmdLight->segmentOffset, SeekOffsetType::Start);
|
||||
|
||||
for (LightingSettings setting : cmdLight->settings)
|
||||
{
|
||||
writer->Write(setting.ambientClrR);
|
||||
writer->Write(setting.ambientClrG);
|
||||
writer->Write(setting.ambientClrB);
|
||||
|
||||
writer->Write(setting.diffuseClrA_R);
|
||||
writer->Write(setting.diffuseClrA_G);
|
||||
writer->Write(setting.diffuseClrA_B);
|
||||
|
||||
writer->Write(setting.diffuseDirA_X);
|
||||
writer->Write(setting.diffuseDirA_Y);
|
||||
writer->Write(setting.diffuseDirA_Z);
|
||||
|
||||
writer->Write(setting.diffuseClrB_R);
|
||||
writer->Write(setting.diffuseClrB_G);
|
||||
writer->Write(setting.diffuseClrB_B);
|
||||
|
||||
writer->Write(setting.diffuseDirB_X);
|
||||
writer->Write(setting.diffuseDirB_Y);
|
||||
writer->Write(setting.diffuseDirB_Z);
|
||||
|
||||
writer->Write(setting.fogClrR);
|
||||
writer->Write(setting.fogClrG);
|
||||
writer->Write(setting.fogClrB);
|
||||
|
||||
writer->Write(setting.unk);
|
||||
writer->Write(setting.drawDistance);
|
||||
}
|
||||
|
||||
writer->Seek(oldOffset, SeekOffsetType::Start);
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetRoomList:
|
||||
{
|
||||
SetRoomList* cmdRoom = (SetRoomList*)cmd;
|
||||
|
||||
writer->Write((uint8_t)cmdRoom->romfile->rooms.size()); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
|
||||
auto baseStreamEnd = writer->GetLength();
|
||||
writer->Write(baseStreamEnd); // 0x04
|
||||
|
||||
uint32_t oldOffset = writer->GetBaseAddress();
|
||||
writer->Seek(baseStreamEnd, SeekOffsetType::Start);
|
||||
|
||||
for (const auto& entry : cmdRoom->romfile->rooms)
|
||||
{
|
||||
writer->Write(entry.virtualAddressStart);
|
||||
writer->Write(entry.virtualAddressEnd);
|
||||
}
|
||||
|
||||
writer->Seek(oldOffset, SeekOffsetType::Start);
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetCollisionHeader:
|
||||
{
|
||||
SetCollisionHeader* cmdCollHeader = (SetCollisionHeader*)cmd;
|
||||
|
||||
int streamEnd = writer->GetStream().get()->GetLength();
|
||||
|
||||
writer->Write((uint8_t)0); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
writer->Write(streamEnd); // 0x04
|
||||
|
||||
// TODO: NOT DONE
|
||||
|
||||
uint32_t oldOffset = writer->GetBaseAddress();
|
||||
writer->Seek(streamEnd, SeekOffsetType::Start);
|
||||
|
||||
ExporterExample_Collision colExp = ExporterExample_Collision();
|
||||
|
||||
colExp.Save(cmdCollHeader->collisionHeader, outPath, writer);
|
||||
|
||||
writer->Seek(oldOffset, SeekOffsetType::Start);
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetEntranceList:
|
||||
{
|
||||
SetEntranceList* cmdEntrance = (SetEntranceList*)cmd;
|
||||
|
||||
uint32_t baseStreamEnd = writer->GetStream().get()->GetLength();
|
||||
|
||||
writer->Write((uint8_t)0); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
writer->Write(baseStreamEnd); // 0x04
|
||||
|
||||
uint32_t oldOffset = writer->GetBaseAddress();
|
||||
writer->Seek(baseStreamEnd, SeekOffsetType::Start);
|
||||
|
||||
for (EntranceEntry entry : cmdEntrance->entrances)
|
||||
{
|
||||
writer->Write((uint8_t)entry.startPositionIndex);
|
||||
writer->Write((uint8_t)entry.roomToLoad);
|
||||
}
|
||||
|
||||
writer->Seek(oldOffset, SeekOffsetType::Start);
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetSpecialObjects:
|
||||
{
|
||||
SetSpecialObjects* cmdSpecObj = (SetSpecialObjects*)cmd;
|
||||
|
||||
writer->Write((uint8_t)cmdSpecObj->elfMessage); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
writer->Write((uint8_t)0); // 0x04
|
||||
writer->Write((uint8_t)0); // 0x05
|
||||
writer->Write((uint16_t)cmdSpecObj->globalObject); // 0x06
|
||||
}
|
||||
break;
|
||||
case RoomCommand::SetStartPositionList:
|
||||
{
|
||||
SetStartPositionList* cmdStartPos = (SetStartPositionList*)cmd;
|
||||
|
||||
uint32_t baseStreamEnd = writer->GetStream().get()->GetLength();
|
||||
|
||||
writer->Write((uint8_t)cmdStartPos->actors.size()); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
writer->Write(baseStreamEnd); // 0x04
|
||||
|
||||
uint32_t oldOffset = writer->GetBaseAddress();
|
||||
writer->Seek(baseStreamEnd, SeekOffsetType::Start);
|
||||
|
||||
for (ActorSpawnEntry entry : cmdStartPos->actors)
|
||||
{
|
||||
writer->Write(entry.actorNum);
|
||||
writer->Write(entry.posX);
|
||||
writer->Write(entry.posY);
|
||||
writer->Write(entry.posZ);
|
||||
writer->Write(entry.rotX);
|
||||
writer->Write(entry.rotY);
|
||||
writer->Write(entry.rotZ);
|
||||
writer->Write(entry.initVar);
|
||||
}
|
||||
|
||||
writer->Seek(oldOffset, SeekOffsetType::Start);
|
||||
}
|
||||
break;
|
||||
case RoomCommand::EndMarker:
|
||||
{
|
||||
writer->Write((uint8_t)0); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
writer->Write((uint8_t)0); // 0x04
|
||||
writer->Write((uint8_t)0); // 0x05
|
||||
writer->Write((uint8_t)0); // 0x06
|
||||
writer->Write((uint8_t)0); // 0x07
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("UNIMPLEMENTED COMMAND: %i\n", (int)cmd->cmdID);
|
||||
|
||||
writer->Write((uint8_t)0); // 0x01
|
||||
writer->Write((uint8_t)0); // 0x02
|
||||
writer->Write((uint8_t)0); // 0x03
|
||||
writer->Write((uint8_t)0); // 0x04
|
||||
writer->Write((uint8_t)0); // 0x05
|
||||
writer->Write((uint8_t)0); // 0x06
|
||||
writer->Write((uint8_t)0); // 0x07
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// writer->Close();
|
||||
// File::WriteAllBytes(StringHelper::Sprintf("%s", res->GetName().c_str()),
|
||||
// memStream->ToVector());
|
||||
}
|
10
tools/ZAPD/ExporterTest/RoomExporter.h
Normal file
10
tools/ZAPD/ExporterTest/RoomExporter.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "ZResource.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
class ExporterExample_Room : public ZResourceExporter
|
||||
{
|
||||
public:
|
||||
void Save(ZResource* res, fs::path outPath, BinaryWriter* writer) override;
|
||||
};
|
14
tools/ZAPD/ExporterTest/TextureExporter.cpp
Normal file
14
tools/ZAPD/ExporterTest/TextureExporter.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include "TextureExporter.h"
|
||||
#include "../ZAPD/ZFile.h"
|
||||
|
||||
void ExporterExample_Texture::Save(ZResource* res, [[maybe_unused]] fs::path outPath,
|
||||
BinaryWriter* writer)
|
||||
{
|
||||
ZTexture* tex = (ZTexture*)res;
|
||||
|
||||
auto data = tex->parent->GetRawData();
|
||||
|
||||
for (offset_t i = tex->GetRawDataIndex(); i < tex->GetRawDataIndex() + tex->GetRawDataSize();
|
||||
i++)
|
||||
writer->Write(data[i]);
|
||||
}
|
11
tools/ZAPD/ExporterTest/TextureExporter.h
Normal file
11
tools/ZAPD/ExporterTest/TextureExporter.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <Utils/BinaryWriter.h>
|
||||
#include "ZResource.h"
|
||||
#include "ZTexture.h"
|
||||
|
||||
class ExporterExample_Texture : public ZResourceExporter
|
||||
{
|
||||
public:
|
||||
void Save(ZResource* res, fs::path outPath, BinaryWriter* writer) override;
|
||||
};
|
114
tools/ZAPD/Jenkinsfile
vendored
114
tools/ZAPD/Jenkinsfile
vendored
|
@ -1,70 +1,90 @@
|
|||
pipeline {
|
||||
agent {
|
||||
label "ZAPD"
|
||||
label 'ZAPD'
|
||||
}
|
||||
|
||||
stages {
|
||||
// Non-parallel ZAPD stage
|
||||
stage('Build ZAPD') {
|
||||
steps {
|
||||
sh 'make -j'
|
||||
}
|
||||
}
|
||||
stage('Checkout oot') {
|
||||
steps {
|
||||
dir('oot') {
|
||||
git url: 'https://github.com/zeldaret/oot.git'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Set up oot') {
|
||||
steps {
|
||||
dir('oot') {
|
||||
sh 'cp /usr/local/etc/roms/baserom_oot.z64 baserom_original.z64'
|
||||
|
||||
// Identical to `make setup` except for copying our newer ZAPD.out into oot
|
||||
sh 'git submodule update --init --recursive'
|
||||
sh 'make -C tools'
|
||||
sh 'cp ../ZAPD.out tools/ZAPD/'
|
||||
sh 'python3 fixbaserom.py'
|
||||
sh 'python3 extract_baserom.py'
|
||||
sh 'python3 extract_assets.py'
|
||||
// CHECKOUT THE REPOS
|
||||
stage('Checkout Repos') {
|
||||
parallel {
|
||||
stage('Checkout oot') {
|
||||
steps {
|
||||
dir('oot') {
|
||||
git url: 'https://github.com/zeldaret/oot.git'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Build oot') {
|
||||
steps {
|
||||
dir('oot') {
|
||||
sh 'make -j'
|
||||
|
||||
stage('Checkout mm') {
|
||||
steps{
|
||||
dir('mm') {
|
||||
git url: 'https://github.com/zeldaret/mm.git'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Checkout mm') {
|
||||
steps {
|
||||
dir('mm') {
|
||||
git url: 'https://github.com/zeldaret/mm.git'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Set up mm') {
|
||||
steps {
|
||||
dir('mm') {
|
||||
sh 'cp /usr/local/etc/roms/mm.us.rev1.z64 baserom.mm.us.rev1.z64'
|
||||
// SETUP THE REPOS
|
||||
stage('Set up repos') {
|
||||
parallel {
|
||||
stage('Setup OOT') {
|
||||
steps {
|
||||
dir('oot') {
|
||||
sh 'cp /usr/local/etc/roms/baserom_oot.z64 baserom_original.z64'
|
||||
|
||||
// Identical to `make setup` except for copying our newer ZAPD.out into mm
|
||||
sh 'git submodule update --init --recursive'
|
||||
sh 'make -C tools'
|
||||
sh 'cp ../ZAPD.out tools/ZAPD/'
|
||||
sh 'python3 tools/extract_rom.py baserom.mm.us.rev1.z64'
|
||||
sh 'python3 extract_assets.py'
|
||||
// Identical to `make setup` except for copying our newer ZAPD.out into oot
|
||||
sh 'git submodule update --init --recursive'
|
||||
sh 'make -C tools'
|
||||
sh 'cp ../ZAPD.out tools/ZAPD/'
|
||||
sh 'python3 fixbaserom.py'
|
||||
sh 'python3 extract_baserom.py'
|
||||
sh 'python3 extract_assets.py'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Setup MM') {
|
||||
steps {
|
||||
dir('mm') {
|
||||
sh 'cp /usr/local/etc/roms/mm.us.rev1.z64 baserom.mm.us.rev1.z64'
|
||||
|
||||
// Identical to `make setup` except for copying our newer ZAPD.out into mm
|
||||
sh 'make -C tools'
|
||||
sh 'cp ../ZAPD.out tools/ZAPD/'
|
||||
sh 'python3 tools/fixbaserom.py'
|
||||
sh 'python3 tools/extract_baserom.py'
|
||||
sh 'python3 extract_assets.py -t 4'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Build mm') {
|
||||
steps {
|
||||
dir('mm') {
|
||||
sh 'make assembly -j'
|
||||
sh 'make -j'
|
||||
|
||||
// BUILD THE REPOS
|
||||
stage('Build repos') {
|
||||
parallel {
|
||||
stage('Build oot') {
|
||||
steps {
|
||||
dir('oot') {
|
||||
sh 'make -j'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Build mm') {
|
||||
steps {
|
||||
dir('mm') {
|
||||
sh 'make -j disasm'
|
||||
sh 'make -j all'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,78 +1,118 @@
|
|||
# use variables in submakes
|
||||
export
|
||||
OPTIMIZATION_ON ?= 1
|
||||
ASAN ?= 0
|
||||
DEPRECATION_ON ?= 1
|
||||
DEBUG ?= 0
|
||||
CXXFLAGS ?=
|
||||
COPYCHECK_ARGS ?=
|
||||
COPYCHECK_ARGS ?=
|
||||
LLD ?= 0
|
||||
|
||||
CXX := g++
|
||||
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
|
||||
CXXFLAGS += -fpic -std=c++17 -Wall -fno-omit-frame-pointer
|
||||
# Use clang++ if available, else use g++
|
||||
ifeq ($(shell command -v clang++ >/dev/null 2>&1; echo $$?),0)
|
||||
CXX := clang++
|
||||
else
|
||||
CXX := g++
|
||||
endif
|
||||
|
||||
INC := -I ZAPD -I lib/elfio -I lib/libgfxd -I lib/tinyxml2 -I ZAPDUtils
|
||||
CXXFLAGS := -fpic -std=c++17 -Wall -Wextra -fno-omit-frame-pointer
|
||||
OPTFLAGS :=
|
||||
|
||||
ifneq ($(DEBUG),0)
|
||||
OPTIMIZATION_ON = 0
|
||||
DEPRECATION_OFF = 1
|
||||
CXXFLAGS += -g3 -DDEVELOPMENT
|
||||
CXXFLAGS += -g3 -DDEVELOPMENT -D_DEBUG
|
||||
COPYCHECK_ARGS += --devel
|
||||
DEPRECATION_ON = 0
|
||||
else
|
||||
CXXFLAGS += -Werror
|
||||
endif
|
||||
|
||||
ifeq ($(OPTIMIZATION_ON),0)
|
||||
CXXFLAGS += -O0
|
||||
OPTFLAGS := -O0
|
||||
else
|
||||
CXXFLAGS += -O2 -march=native -mtune=native
|
||||
OPTFLAGS := -O2 -march=native -mtune=native
|
||||
endif
|
||||
|
||||
ifneq ($(ASAN),0)
|
||||
CXXFLAGS += -fsanitize=address
|
||||
CXXFLAGS += -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined
|
||||
endif
|
||||
ifneq ($(DEPRECATION_ON),0)
|
||||
CXXFLAGS += -DDEPRECATION_ON
|
||||
endif
|
||||
# CXXFLAGS += -DTEXTURE_DEBUG
|
||||
|
||||
LDFLAGS := -lstdc++ -lm -ldl -lpng
|
||||
LDFLAGS := -lm -ldl -lpng
|
||||
|
||||
# Use LLD if available. Set LLD=0 to not use it
|
||||
ifeq ($(shell command -v ld.lld >/dev/null 2>&1; echo $$?),0)
|
||||
LLD := 1
|
||||
endif
|
||||
|
||||
ifneq ($(LLD),0)
|
||||
LDFLAGS += -fuse-ld=lld
|
||||
endif
|
||||
|
||||
UNAME := $(shell uname)
|
||||
ifneq ($(UNAME), Darwin)
|
||||
LDFLAGS += -Wl,-export-dynamic -lstdc++fs
|
||||
endif
|
||||
|
||||
SRC_DIRS := ZAPD ZAPD/ZRoom ZAPD/ZRoom/Commands ZAPD/Overlays ZAPD/HighLevel
|
||||
ZAPD_SRC_DIRS := $(shell find ZAPD -type d)
|
||||
SRC_DIRS = $(ZAPD_SRC_DIRS) lib/tinyxml2
|
||||
|
||||
ZAPD_CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
|
||||
ZAPD_H_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))
|
||||
ZAPD_CPP_FILES := $(foreach dir,$(ZAPD_SRC_DIRS),$(wildcard $(dir)/*.cpp))
|
||||
ZAPD_H_FILES := $(foreach dir,$(ZAPD_SRC_DIRS),$(wildcard $(dir)/*.h))
|
||||
|
||||
CPP_FILES += $(ZAPD_CPP_FILES) lib/tinyxml2/tinyxml2.cpp
|
||||
O_FILES := $(CPP_FILES:.cpp=.o)
|
||||
O_FILES := $(foreach f,$(CPP_FILES:.cpp=.o),build/$f)
|
||||
O_FILES += build/ZAPD/BuildInfo.o
|
||||
|
||||
# create build directories
|
||||
$(shell mkdir -p $(foreach dir,$(SRC_DIRS),build/$(dir)))
|
||||
|
||||
|
||||
# Main targets
|
||||
all: ZAPD.out copycheck
|
||||
|
||||
genbuildinfo:
|
||||
build/ZAPD/BuildInfo.o:
|
||||
python3 ZAPD/genbuildinfo.py $(COPYCHECK_ARGS)
|
||||
$(CXX) $(CXXFLAGS) $(OPTFLAGS) $(INC) -c $(OUTPUT_OPTION) build/ZAPD/BuildInfo.cpp
|
||||
|
||||
copycheck: ZAPD.out
|
||||
python3 copycheck.py
|
||||
|
||||
clean:
|
||||
rm -f $(O_FILES) ZAPD.out
|
||||
rm -rf build ZAPD.out
|
||||
$(MAKE) -C lib/libgfxd clean
|
||||
$(MAKE) -C ZAPDUtils clean
|
||||
$(MAKE) -C ExporterTest clean
|
||||
|
||||
rebuild: clean all
|
||||
|
||||
format:
|
||||
clang-format-11 -i $(ZAPD_CPP_FILES) $(ZAPD_H_FILES)
|
||||
$(MAKE) -C ZAPDUtils format
|
||||
$(MAKE) -C ExporterTest format
|
||||
|
||||
.PHONY: all genbuildinfo copycheck clean rebuild format
|
||||
.PHONY: all build/ZAPD/BuildInfo.o copycheck clean rebuild format
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) $(INC) -c $< -o $@
|
||||
build/%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) $(OPTFLAGS) $(INC) -c $(OUTPUT_OPTION) $<
|
||||
|
||||
ZAPD/Main.o: genbuildinfo ZAPD/Main.cpp
|
||||
$(CXX) $(CXXFLAGS) $(INC) -c ZAPD/Main.cpp -o $@
|
||||
|
||||
# Submakes
|
||||
lib/libgfxd/libgfxd.a:
|
||||
$(MAKE) -C lib/libgfxd
|
||||
|
||||
ZAPD.out: $(O_FILES) lib/libgfxd/libgfxd.a
|
||||
$(CXX) $(CXXFLAGS) $(INC) $(O_FILES) lib/libgfxd/libgfxd.a -o $@ $(FS_INC) $(LDFLAGS)
|
||||
.PHONY: ExporterTest
|
||||
ExporterTest:
|
||||
$(MAKE) -C ExporterTest
|
||||
|
||||
.PHONY: ZAPDUtils
|
||||
ZAPDUtils:
|
||||
$(MAKE) -C ZAPDUtils
|
||||
|
||||
|
||||
# Linking
|
||||
ZAPD.out: $(O_FILES) lib/libgfxd/libgfxd.a ExporterTest ZAPDUtils
|
||||
$(CXX) $(CXXFLAGS) $(O_FILES) lib/libgfxd/libgfxd.a ZAPDUtils/ZAPDUtils.a -Wl,--whole-archive ExporterTest/ExporterTest.a -Wl,--no-whole-archive $(LDFLAGS) $(OUTPUT_OPTION)
|
||||
|
|
|
@ -30,7 +30,8 @@ You can configure a bit your ZAPD build with the following options:
|
|||
- `DEBUG`: If non-zero, ZAPD will be compiled in _development mode_. This implies the following:
|
||||
- Debugging symbols enabled (`-g3`). They are disabled by default.
|
||||
- `OPTIMIZATION_ON=0`: Disables optimizations (`-O0`).
|
||||
- `DEPRECATION_OFF=1`: Disables deprecation warnings.
|
||||
- `DEPRECATION_ON=0`: Disables deprecation warnings.
|
||||
- `LLD=1`: builds with the LLVM linker `ld.lld` instead of the system default.
|
||||
|
||||
As an example, if you want to build ZAPD with optimizations disabled and use the address sanitizer, you could use the following command:
|
||||
|
||||
|
@ -109,6 +110,10 @@ ZAPD also accepts the following list of extra parameters:
|
|||
- Can be used only in `e` or `bsf` modes.
|
||||
- `-tm MODE`: Test Mode (enables certain experimental features). To enable it, set `MODE` to `1`.
|
||||
- `-wno` / `--warn-no-offsets` : Enable warnings for nodes that dont have offsets specified. Takes priority over `-eno`/ `--error-no-offsets`.
|
||||
- `-eno`/ `--error-no-offsets` : Enable errors for nodes that dont have offsets specified.
|
||||
- `-eno` / `--error-no-offsets` : Enable errors for nodes that dont have offsets specified.
|
||||
- `-se` / `--set-exporter` : Sets which exporter to use.
|
||||
- `--gcc-compat` : Enables GCC compatible mode. Slower.
|
||||
- `-s` / `--static` : Mark every asset as `static`.
|
||||
- This behaviour can be overridden per asset using `Static=` in the respective XML node.
|
||||
|
||||
Additionally, you can pass the flag `--version` to see the current ZAPD version. If that flag is passed, ZAPD will ignore any other parameter passed.
|
||||
|
|
|
@ -5,6 +5,10 @@ VisualStudioVersion = 16.0.30320.27
|
|||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZAPD", "ZAPD\ZAPD.vcxproj", "{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExporterExample", "ExporterTest\ExporterTest.vcxproj", "{65608EB0-1A47-45AD-AB66-192FB64C762C}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZAPDUtils", "ZAPDUtils\ZAPDUtils.vcxproj", "{A2E01C3E-D647-45D1-9788-043DEBC1A908}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
|
@ -33,6 +37,38 @@ Global
|
|||
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.RelWithDebInfo|x64.Build.0 = Release|x64
|
||||
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
|
||||
{B53F9E5B-0A58-4BAE-9AFE-856C8CBB8D36}.RelWithDebInfo|x86.Build.0 = Release|Win32
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Debug|x64.Build.0 = Debug|x64
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Debug|x86.Build.0 = Debug|Win32
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.MinSizeRel|x64.ActiveCfg = Debug|x64
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.MinSizeRel|x64.Build.0 = Debug|x64
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.MinSizeRel|x86.ActiveCfg = Debug|Win32
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.MinSizeRel|x86.Build.0 = Debug|Win32
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Release|x64.ActiveCfg = Release|x64
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Release|x64.Build.0 = Release|x64
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Release|x86.ActiveCfg = Release|Win32
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.Release|x86.Build.0 = Release|Win32
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.RelWithDebInfo|x64.ActiveCfg = Release|x64
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.RelWithDebInfo|x64.Build.0 = Release|x64
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
|
||||
{65608EB0-1A47-45AD-AB66-192FB64C762C}.RelWithDebInfo|x86.Build.0 = Release|Win32
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x64.Build.0 = Debug|x64
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Debug|x86.Build.0 = Debug|Win32
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.MinSizeRel|x64.ActiveCfg = Debug|x64
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.MinSizeRel|x64.Build.0 = Debug|x64
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.MinSizeRel|x86.ActiveCfg = Debug|Win32
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.MinSizeRel|x86.Build.0 = Debug|Win32
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x64.ActiveCfg = Release|x64
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x64.Build.0 = Release|x64
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x86.ActiveCfg = Release|Win32
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.Release|x86.Build.0 = Release|Win32
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.RelWithDebInfo|x64.ActiveCfg = Release|x64
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.RelWithDebInfo|x64.Build.0 = Release|x64
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
|
||||
{A2E01C3E-D647-45D1-9788-043DEBC1A908}.RelWithDebInfo|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -1,37 +1,31 @@
|
|||
#include "Declaration.h"
|
||||
|
||||
Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
|
||||
std::string nText)
|
||||
#include "Globals.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
|
||||
Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
|
||||
const std::string& nText)
|
||||
{
|
||||
address = nAddress;
|
||||
alignment = nAlignment;
|
||||
padding = nPadding;
|
||||
size = nSize;
|
||||
text = nText;
|
||||
}
|
||||
|
||||
Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
|
||||
std::string nVarName, bool nIsArray, std::string nText)
|
||||
: Declaration(nAlignment, DeclarationPadding::None, nSize, nText)
|
||||
Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
|
||||
const std::string& nVarType, const std::string& nVarName, bool nIsArray,
|
||||
const std::string& nText)
|
||||
: Declaration(nAddress, nAlignment, nSize, nText)
|
||||
{
|
||||
varType = nVarType;
|
||||
varName = nVarName;
|
||||
isArray = nIsArray;
|
||||
}
|
||||
|
||||
Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
|
||||
std::string nVarType, std::string nVarName, bool nIsArray,
|
||||
std::string nText)
|
||||
: Declaration(nAlignment, nPadding, nSize, nText)
|
||||
{
|
||||
varType = nVarType;
|
||||
varName = nVarName;
|
||||
isArray = nIsArray;
|
||||
}
|
||||
|
||||
Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
|
||||
std::string nVarName, bool nIsArray, size_t nArrayItemCnt,
|
||||
std::string nText)
|
||||
: Declaration(nAlignment, DeclarationPadding::None, nSize, nText)
|
||||
Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
|
||||
const std::string& nVarType, const std::string& nVarName, bool nIsArray,
|
||||
size_t nArrayItemCnt, const std::string& nText)
|
||||
: Declaration(nAddress, nAlignment, nSize, nText)
|
||||
{
|
||||
varType = nVarType;
|
||||
varName = nVarName;
|
||||
|
@ -39,10 +33,10 @@ Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, std::str
|
|||
arrayItemCnt = nArrayItemCnt;
|
||||
}
|
||||
|
||||
Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
|
||||
std::string nVarName, bool nIsArray, std::string nArrayItemCntStr,
|
||||
std::string nText)
|
||||
: Declaration(nAlignment, DeclarationPadding::None, nSize, nText)
|
||||
Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
|
||||
const std::string& nVarType, const std::string& nVarName, bool nIsArray,
|
||||
const std::string& nArrayItemCntStr, const std::string& nText)
|
||||
: Declaration(nAddress, nAlignment, nSize, nText)
|
||||
{
|
||||
varType = nVarType;
|
||||
varName = nVarName;
|
||||
|
@ -50,30 +44,179 @@ Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, std::str
|
|||
arrayItemCntStr = nArrayItemCntStr;
|
||||
}
|
||||
|
||||
Declaration::Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
|
||||
std::string nVarName, bool nIsArray, size_t nArrayItemCnt,
|
||||
std::string nText, bool nIsExternal)
|
||||
: Declaration(nAlignment, nSize, nVarType, nVarName, nIsArray, nArrayItemCnt, nText)
|
||||
Declaration::Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
|
||||
const std::string& nVarType, const std::string& nVarName, bool nIsArray,
|
||||
size_t nArrayItemCnt, const std::string& nText, bool nIsExternal)
|
||||
: Declaration(nAddress, nAlignment, nSize, nVarType, nVarName, nIsArray, nArrayItemCnt, nText)
|
||||
{
|
||||
isExternal = nIsExternal;
|
||||
}
|
||||
|
||||
Declaration::Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
|
||||
std::string nVarType, std::string nVarName, bool nIsArray,
|
||||
size_t nArrayItemCnt, std::string nText)
|
||||
: Declaration(nAlignment, nPadding, nSize, nText)
|
||||
{
|
||||
varType = nVarType;
|
||||
varName = nVarName;
|
||||
isArray = nIsArray;
|
||||
arrayItemCnt = nArrayItemCnt;
|
||||
}
|
||||
|
||||
Declaration::Declaration(std::string nIncludePath, size_t nSize, std::string nVarType,
|
||||
std::string nVarName)
|
||||
: Declaration(DeclarationAlignment::None, DeclarationPadding::None, nSize, "")
|
||||
Declaration::Declaration(offset_t nAddress, const std::string& nIncludePath, size_t nSize,
|
||||
const std::string& nVarType, const std::string& nVarName)
|
||||
: Declaration(nAddress, DeclarationAlignment::Align4, nSize, "")
|
||||
{
|
||||
includePath = nIncludePath;
|
||||
varType = nVarType;
|
||||
varName = nVarName;
|
||||
}
|
||||
|
||||
bool Declaration::IsStatic() const
|
||||
{
|
||||
switch (staticConf)
|
||||
{
|
||||
case StaticConfig::Off:
|
||||
return false;
|
||||
|
||||
case StaticConfig::Global:
|
||||
return Globals::Instance->forceStatic;
|
||||
|
||||
case StaticConfig::On:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string Declaration::GetNormalDeclarationStr() const
|
||||
{
|
||||
std::string output;
|
||||
|
||||
if (preText != "")
|
||||
output += preText + "\n";
|
||||
|
||||
if (IsStatic())
|
||||
{
|
||||
output += "static ";
|
||||
}
|
||||
|
||||
if (isArray)
|
||||
{
|
||||
if (arrayItemCntStr != "")
|
||||
{
|
||||
output += StringHelper::Sprintf("%s %s[%s];\n", varType.c_str(), varName.c_str(),
|
||||
arrayItemCntStr.c_str());
|
||||
}
|
||||
else if (arrayItemCnt == 0)
|
||||
{
|
||||
output += StringHelper::Sprintf("%s %s[] = {\n", varType.c_str(), varName.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
output += StringHelper::Sprintf("%s %s[%i] = {\n", varType.c_str(), varName.c_str(),
|
||||
arrayItemCnt);
|
||||
}
|
||||
|
||||
output += text + "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
output += StringHelper::Sprintf("%s %s = { ", varType.c_str(), varName.c_str());
|
||||
output += text;
|
||||
}
|
||||
|
||||
if (output.back() == '\n')
|
||||
output += "};";
|
||||
else
|
||||
output += " };";
|
||||
|
||||
if (rightText != "")
|
||||
output += " " + rightText + "";
|
||||
|
||||
output += "\n";
|
||||
|
||||
if (postText != "")
|
||||
output += postText + "\n";
|
||||
|
||||
output += "\n";
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string Declaration::GetExternalDeclarationStr() const
|
||||
{
|
||||
std::string output;
|
||||
|
||||
if (preText != "")
|
||||
output += preText + "\n";
|
||||
|
||||
if (IsStatic())
|
||||
{
|
||||
output += "static ";
|
||||
}
|
||||
|
||||
if (arrayItemCntStr != "")
|
||||
output +=
|
||||
StringHelper::Sprintf("%s %s[%s] = {\n#include \"%s\"\n};", varType.c_str(),
|
||||
varName.c_str(), arrayItemCntStr.c_str(), includePath.c_str());
|
||||
else if (arrayItemCnt != 0)
|
||||
output += StringHelper::Sprintf("%s %s[%i] = {\n#include \"%s\"\n};", varType.c_str(),
|
||||
varName.c_str(), arrayItemCnt, includePath.c_str());
|
||||
else
|
||||
output += StringHelper::Sprintf("%s %s[] = {\n#include \"%s\"\n};", varType.c_str(),
|
||||
varName.c_str(), includePath.c_str());
|
||||
|
||||
if (rightText != "")
|
||||
output += " " + rightText + "";
|
||||
|
||||
output += "\n";
|
||||
|
||||
if (postText != "")
|
||||
output += postText + "\n";
|
||||
|
||||
output += "\n";
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string Declaration::GetExternStr() const
|
||||
{
|
||||
if (IsStatic() || varType == "")
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
if (isArray)
|
||||
{
|
||||
if (arrayItemCntStr != "")
|
||||
{
|
||||
return StringHelper::Sprintf("extern %s %s[%s];\n", varType.c_str(), varName.c_str(),
|
||||
arrayItemCntStr.c_str());
|
||||
}
|
||||
else if (arrayItemCnt != 0)
|
||||
return StringHelper::Sprintf("extern %s %s[%i];\n", varType.c_str(), varName.c_str(),
|
||||
arrayItemCnt);
|
||||
else
|
||||
return StringHelper::Sprintf("extern %s %s[];\n", varType.c_str(), varName.c_str());
|
||||
}
|
||||
|
||||
return StringHelper::Sprintf("extern %s %s;\n", varType.c_str(), varName.c_str());
|
||||
}
|
||||
|
||||
std::string Declaration::GetStaticForwardDeclarationStr() const
|
||||
{
|
||||
if (!IsStatic() || isUnaccounted)
|
||||
return "";
|
||||
|
||||
if (isArray)
|
||||
{
|
||||
if (arrayItemCntStr == "" && arrayItemCnt == 0)
|
||||
{
|
||||
// Forward declaring static arrays without specifying the size is not allowed.
|
||||
return "";
|
||||
}
|
||||
|
||||
if (arrayItemCntStr != "")
|
||||
{
|
||||
return StringHelper::Sprintf("static %s %s[%s];\n", varType.c_str(), varName.c_str(),
|
||||
arrayItemCntStr.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
return StringHelper::Sprintf("static %s %s[%i];\n", varType.c_str(), varName.c_str(),
|
||||
arrayItemCnt);
|
||||
}
|
||||
}
|
||||
|
||||
return StringHelper::Sprintf("static %s %s;\n", varType.c_str(), varName.c_str());
|
||||
}
|
||||
|
|
|
@ -3,28 +3,32 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// TODO: should we drop the `_t` suffix because of UNIX compliance?
|
||||
typedef uint32_t segptr_t;
|
||||
typedef uint32_t offset_t;
|
||||
|
||||
#define SEGMENTED_NULL ((segptr_t)0)
|
||||
|
||||
enum class DeclarationAlignment
|
||||
{
|
||||
None,
|
||||
Align4,
|
||||
Align8,
|
||||
Align16
|
||||
};
|
||||
|
||||
enum class DeclarationPadding
|
||||
enum class StaticConfig
|
||||
{
|
||||
None,
|
||||
Pad4,
|
||||
Pad8,
|
||||
Pad16
|
||||
Off,
|
||||
Global,
|
||||
On
|
||||
};
|
||||
|
||||
class Declaration
|
||||
{
|
||||
public:
|
||||
offset_t address;
|
||||
DeclarationAlignment alignment;
|
||||
DeclarationPadding padding;
|
||||
size_t size = 0;
|
||||
size_t size;
|
||||
std::string preText;
|
||||
std::string text;
|
||||
std::string rightText;
|
||||
|
@ -38,28 +42,38 @@ public:
|
|||
bool isArray = false;
|
||||
size_t arrayItemCnt = 0;
|
||||
std::string arrayItemCntStr;
|
||||
std::vector<uint32_t> references;
|
||||
std::vector<segptr_t> references;
|
||||
bool isUnaccounted = false;
|
||||
bool isPlaceholder = false;
|
||||
bool declaredInXml = false;
|
||||
StaticConfig staticConf = StaticConfig::Global;
|
||||
|
||||
Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
|
||||
std::string nVarName, bool nIsArray, std::string nText);
|
||||
Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
|
||||
std::string nVarType, std::string nVarName, bool nIsArray, std::string nText);
|
||||
Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
|
||||
std::string nVarName, bool nIsArray, size_t nArrayItemCnt, std::string nText);
|
||||
Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
|
||||
std::string nVarName, bool nIsArray, std::string nArrayItemCntStr,
|
||||
std::string nText);
|
||||
Declaration(DeclarationAlignment nAlignment, size_t nSize, std::string nVarType,
|
||||
std::string nVarName, bool nIsArray, size_t nArrayItemCnt, std::string nText,
|
||||
bool nIsExternal);
|
||||
Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
|
||||
std::string nVarType, std::string nVarName, bool nIsArray, size_t nArrayItemCnt,
|
||||
std::string nText);
|
||||
Declaration(std::string nIncludePath, size_t nSize, std::string nVarType, std::string nVarName);
|
||||
Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
|
||||
const std::string& nVarType, const std::string& nVarName, bool nIsArray,
|
||||
const std::string& nText);
|
||||
Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
|
||||
const std::string& nVarType, const std::string& nVarName, bool nIsArray,
|
||||
size_t nArrayItemCnt, const std::string& nText);
|
||||
Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
|
||||
const std::string& nVarType, const std::string& nVarName, bool nIsArray,
|
||||
const std::string& nArrayItemCntStr, const std::string& nText);
|
||||
Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
|
||||
const std::string& nVarType, const std::string& nVarName, bool nIsArray,
|
||||
size_t nArrayItemCnt, const std::string& nText, bool nIsExternal);
|
||||
|
||||
Declaration(offset_t nAddress, const std::string& nIncludePath, size_t nSize,
|
||||
const std::string& nVarType, const std::string& nVarName);
|
||||
|
||||
bool IsStatic() const;
|
||||
|
||||
std::string GetNormalDeclarationStr() const;
|
||||
std::string GetExternalDeclarationStr() const;
|
||||
|
||||
std::string GetExternStr() const;
|
||||
|
||||
std::string GetStaticForwardDeclarationStr() const;
|
||||
|
||||
protected:
|
||||
Declaration(DeclarationAlignment nAlignment, DeclarationPadding nPadding, size_t nSize,
|
||||
std::string nText);
|
||||
Declaration(offset_t nAddress, DeclarationAlignment nAlignment, size_t nSize,
|
||||
const std::string& nText);
|
||||
};
|
||||
|
|
184
tools/ZAPD/ZAPD/GameConfig.cpp
Normal file
184
tools/ZAPD/ZAPD/GameConfig.cpp
Normal file
|
@ -0,0 +1,184 @@
|
|||
#include "GameConfig.h"
|
||||
|
||||
#include <functional>
|
||||
#include <string_view>
|
||||
|
||||
#include "Utils/Directory.h"
|
||||
#include "Utils/File.h"
|
||||
#include "Utils/Path.h"
|
||||
#include "ZFile.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
using ConfigFunc = void (GameConfig::*)(const tinyxml2::XMLElement&);
|
||||
|
||||
GameConfig::~GameConfig()
|
||||
{
|
||||
for (auto& declPair : segmentRefFiles)
|
||||
{
|
||||
for (auto& file : declPair.second)
|
||||
{
|
||||
delete file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameConfig::ReadTexturePool(const fs::path& texturePoolXmlPath)
|
||||
{
|
||||
tinyxml2::XMLDocument doc;
|
||||
tinyxml2::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;
|
||||
}
|
||||
|
||||
tinyxml2::XMLNode* root = doc.FirstChild();
|
||||
|
||||
if (root == nullptr)
|
||||
return;
|
||||
|
||||
for (tinyxml2::XMLElement* child = root->FirstChildElement(); child != nullptr;
|
||||
child = child->NextSiblingElement())
|
||||
{
|
||||
if (std::string_view(child->Name()) == "Texture")
|
||||
{
|
||||
std::string crcStr = child->Attribute("CRC");
|
||||
fs::path texPath = child->Attribute("Path");
|
||||
std::string texName;
|
||||
|
||||
uint32_t crc = strtoul(crcStr.c_str(), nullptr, 16);
|
||||
|
||||
texturePool[crc].path = texPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameConfig::GenSymbolMap(const fs::path& symbolMapPath)
|
||||
{
|
||||
auto symbolLines = File::ReadAllLines(symbolMapPath);
|
||||
|
||||
for (std::string& symbolLine : symbolLines)
|
||||
{
|
||||
auto split = StringHelper::Split(symbolLine, " ");
|
||||
uint32_t addr = strtoul(split[0].c_str(), nullptr, 16);
|
||||
std::string symbolName = split[1];
|
||||
|
||||
symbolMap[addr] = std::move(symbolName);
|
||||
}
|
||||
}
|
||||
|
||||
void GameConfig::ConfigFunc_SymbolMap(const tinyxml2::XMLElement& element)
|
||||
{
|
||||
std::string fileName = element.Attribute("File");
|
||||
GenSymbolMap(Path::GetDirectoryName(configFilePath) / fileName);
|
||||
}
|
||||
|
||||
void GameConfig::ConfigFunc_ActorList(const tinyxml2::XMLElement& element)
|
||||
{
|
||||
std::string fileName = element.Attribute("File");
|
||||
std::vector<std::string> lines =
|
||||
File::ReadAllLines(Path::GetDirectoryName(configFilePath) / fileName);
|
||||
|
||||
for (auto& line : lines)
|
||||
actorList.emplace_back(std::move(line));
|
||||
}
|
||||
|
||||
void GameConfig::ConfigFunc_ObjectList(const tinyxml2::XMLElement& element)
|
||||
{
|
||||
std::string fileName = element.Attribute("File");
|
||||
std::vector<std::string> lines =
|
||||
File::ReadAllLines(Path::GetDirectoryName(configFilePath) / fileName);
|
||||
|
||||
for (auto& line : lines)
|
||||
objectList.emplace_back(std::move(line));
|
||||
}
|
||||
|
||||
void GameConfig::ConfigFunc_TexturePool(const tinyxml2::XMLElement& element)
|
||||
{
|
||||
std::string fileName = element.Attribute("File");
|
||||
ReadTexturePool(Path::GetDirectoryName(configFilePath) / fileName);
|
||||
}
|
||||
|
||||
void GameConfig::ConfigFunc_BGConfig(const tinyxml2::XMLElement& element)
|
||||
{
|
||||
bgScreenWidth = element.IntAttribute("ScreenWidth", 320);
|
||||
bgScreenHeight = element.IntAttribute("ScreenHeight", 240);
|
||||
}
|
||||
|
||||
void GameConfig::ConfigFunc_ExternalXMLFolder(const tinyxml2::XMLElement& element)
|
||||
{
|
||||
const char* pathValue = element.Attribute("Path");
|
||||
if (pathValue == nullptr)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("Parse: Fatal error in configuration file.\n"
|
||||
"\t Missing 'Path' attribute in `ExternalXMLFolder` element.\n"));
|
||||
}
|
||||
if (externalXmlFolder != "")
|
||||
{
|
||||
throw std::runtime_error(StringHelper::Sprintf("Parse: Fatal error in configuration file.\n"
|
||||
"\t `ExternalXMLFolder` is duplicated.\n"));
|
||||
}
|
||||
externalXmlFolder = pathValue;
|
||||
}
|
||||
|
||||
void GameConfig::ConfigFunc_ExternalFile(const tinyxml2::XMLElement& element)
|
||||
{
|
||||
const char* xmlPathValue = element.Attribute("XmlPath");
|
||||
if (xmlPathValue == nullptr)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("Parse: Fatal error in configuration file.\n"
|
||||
"\t Missing 'XmlPath' attribute in `ExternalFile` element.\n"));
|
||||
}
|
||||
const char* outPathValue = element.Attribute("OutPath");
|
||||
if (outPathValue == nullptr)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("Parse: Fatal error in configuration file.\n"
|
||||
"\t Missing 'OutPath' attribute in `ExternalFile` element.\n"));
|
||||
}
|
||||
|
||||
externalFiles.push_back(ExternalFile(fs::path(xmlPathValue), fs::path(outPathValue)));
|
||||
}
|
||||
|
||||
void GameConfig::ReadConfigFile(const fs::path& argConfigFilePath)
|
||||
{
|
||||
static const std::map<std::string, ConfigFunc> ConfigFuncDictionary = {
|
||||
{"SymbolMap", &GameConfig::ConfigFunc_SymbolMap},
|
||||
{"ActorList", &GameConfig::ConfigFunc_ActorList},
|
||||
{"ObjectList", &GameConfig::ConfigFunc_ObjectList},
|
||||
{"TexturePool", &GameConfig::ConfigFunc_TexturePool},
|
||||
{"BGConfig", &GameConfig::ConfigFunc_BGConfig},
|
||||
{"ExternalXMLFolder", &GameConfig::ConfigFunc_ExternalXMLFolder},
|
||||
{"ExternalFile", &GameConfig::ConfigFunc_ExternalFile},
|
||||
};
|
||||
|
||||
configFilePath = argConfigFilePath;
|
||||
tinyxml2::XMLDocument doc;
|
||||
tinyxml2::XMLError eResult = doc.LoadFile(configFilePath.c_str());
|
||||
|
||||
if (eResult != tinyxml2::XML_SUCCESS)
|
||||
{
|
||||
throw std::runtime_error("Error: Unable to read config file.");
|
||||
}
|
||||
|
||||
tinyxml2::XMLNode* root = doc.FirstChild();
|
||||
|
||||
if (root == nullptr)
|
||||
return;
|
||||
|
||||
for (tinyxml2::XMLElement* child = root->FirstChildElement(); child != nullptr;
|
||||
child = child->NextSiblingElement())
|
||||
{
|
||||
auto it = ConfigFuncDictionary.find(child->Name());
|
||||
if (it == ConfigFuncDictionary.end())
|
||||
{
|
||||
fprintf(stderr, "Unsupported configuration variable: %s\n", child->Name());
|
||||
continue;
|
||||
}
|
||||
|
||||
std::invoke(it->second, *this, *child);
|
||||
}
|
||||
}
|
58
tools/ZAPD/ZAPD/GameConfig.h
Normal file
58
tools/ZAPD/ZAPD/GameConfig.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Utils/Directory.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
struct TexturePoolEntry
|
||||
{
|
||||
fs::path path = ""; // Path to Shared Texture
|
||||
};
|
||||
|
||||
class ExternalFile
|
||||
{
|
||||
public:
|
||||
fs::path xmlPath, outPath;
|
||||
|
||||
ExternalFile(fs::path nXmlPath, fs::path nOutPath);
|
||||
};
|
||||
|
||||
class ZFile;
|
||||
|
||||
class GameConfig
|
||||
{
|
||||
public:
|
||||
std::string configFilePath;
|
||||
std::map<int32_t, std::vector<ZFile*>> segmentRefFiles;
|
||||
std::map<uint32_t, std::string> symbolMap;
|
||||
std::vector<std::string> actorList;
|
||||
std::vector<std::string> objectList;
|
||||
std::map<uint32_t, TexturePoolEntry> texturePool; // Key = CRC
|
||||
|
||||
// ZBackground
|
||||
uint32_t bgScreenWidth = 320, bgScreenHeight = 240;
|
||||
|
||||
// ExternalFile
|
||||
fs::path externalXmlFolder;
|
||||
std::vector<ExternalFile> externalFiles;
|
||||
|
||||
GameConfig() = default;
|
||||
~GameConfig();
|
||||
|
||||
void ReadTexturePool(const fs::path& texturePoolXmlPath);
|
||||
void GenSymbolMap(const fs::path& symbolMapPath);
|
||||
|
||||
void ConfigFunc_SymbolMap(const tinyxml2::XMLElement& element);
|
||||
void ConfigFunc_ActorList(const tinyxml2::XMLElement& element);
|
||||
void ConfigFunc_ObjectList(const tinyxml2::XMLElement& element);
|
||||
void ConfigFunc_TexturePool(const tinyxml2::XMLElement& element);
|
||||
void ConfigFunc_BGConfig(const tinyxml2::XMLElement& element);
|
||||
void ConfigFunc_ExternalXMLFolder(const tinyxml2::XMLElement& element);
|
||||
void ConfigFunc_ExternalFile(const tinyxml2::XMLElement& element);
|
||||
|
||||
void ReadConfigFile(const fs::path& configFilePath);
|
||||
};
|
|
@ -1,10 +1,11 @@
|
|||
#include "Globals.h"
|
||||
#include <algorithm>
|
||||
#include "File.h"
|
||||
#include "Path.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
using namespace tinyxml2;
|
||||
#include <algorithm>
|
||||
#include <string_view>
|
||||
|
||||
#include <Utils/File.h>
|
||||
#include <Utils/Path.h>
|
||||
#include "tinyxml2.h"
|
||||
|
||||
Globals* Globals::Instance;
|
||||
|
||||
|
@ -12,176 +13,183 @@ Globals::Globals()
|
|||
{
|
||||
Instance = this;
|
||||
|
||||
files = std::vector<ZFile*>();
|
||||
segments = std::vector<int32_t>();
|
||||
symbolMap = std::map<uint32_t, std::string>();
|
||||
segmentRefs = std::map<int32_t, std::string>();
|
||||
segmentRefFiles = std::map<int32_t, ZFile*>();
|
||||
game = ZGame::OOT_RETAIL;
|
||||
genSourceFile = true;
|
||||
testMode = false;
|
||||
profile = false;
|
||||
useLegacyZDList = false;
|
||||
useExternalResources = true;
|
||||
lastScene = nullptr;
|
||||
verbosity = VerbosityLevel::VERBOSITY_SILENT;
|
||||
outputPath = Directory::GetCurrentDirectory();
|
||||
}
|
||||
|
||||
std::string Globals::FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress)
|
||||
{
|
||||
if (segmentRefs.find(segNumber) != segmentRefs.end())
|
||||
{
|
||||
if (segmentRefFiles.find(segNumber) == segmentRefFiles.end())
|
||||
{
|
||||
XMLDocument doc;
|
||||
std::string filePath = segmentRefs[segNumber];
|
||||
XMLError eResult = doc.LoadFile(filePath.c_str());
|
||||
|
||||
if (eResult != tinyxml2::XML_SUCCESS)
|
||||
return "ERROR";
|
||||
|
||||
XMLNode* root = doc.FirstChild();
|
||||
|
||||
if (root == nullptr)
|
||||
return "ERROR";
|
||||
|
||||
for (XMLElement* child = root->FirstChildElement(); child != NULL;
|
||||
child = child->NextSiblingElement())
|
||||
{
|
||||
if (std::string(child->Name()) == "File")
|
||||
{
|
||||
ZFile* file = new ZFile(fileMode, child, "", "", filePath, true);
|
||||
file->GeneratePlaceholderDeclarations();
|
||||
segmentRefFiles[segNumber] = file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return segmentRefFiles[segNumber]->GetDeclarationName(symbolAddress, "ERROR");
|
||||
}
|
||||
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
void Globals::ReadConfigFile(const std::string& configFilePath)
|
||||
{
|
||||
XMLDocument doc;
|
||||
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();
|
||||
|
||||
if (root == nullptr)
|
||||
return;
|
||||
|
||||
for (XMLElement* child = root->FirstChildElement(); child != NULL;
|
||||
child = child->NextSiblingElement())
|
||||
{
|
||||
if (std::string(child->Name()) == "SymbolMap")
|
||||
{
|
||||
std::string fileName = std::string(child->Attribute("File"));
|
||||
GenSymbolMap(Path::GetDirectoryName(configFilePath) + "/" + fileName);
|
||||
}
|
||||
else if (std::string(child->Name()) == "Segment")
|
||||
{
|
||||
std::string fileName = std::string(child->Attribute("File"));
|
||||
int32_t segNumber = child->IntAttribute("Number");
|
||||
segmentRefs[segNumber] = fileName;
|
||||
}
|
||||
else if (std::string(child->Name()) == "ActorList")
|
||||
{
|
||||
std::string fileName = std::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 (std::string(child->Name()) == "ObjectList")
|
||||
{
|
||||
std::string fileName = std::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 (std::string(child->Name()) == "TexturePool")
|
||||
{
|
||||
std::string fileName = std::string(child->Attribute("File"));
|
||||
ReadTexturePool(Path::GetDirectoryName(configFilePath) + "/" + fileName);
|
||||
}
|
||||
else if (std::string(child->Name()) == "BGConfig")
|
||||
{
|
||||
cfg.bgScreenWidth = child->IntAttribute("ScreenWidth", 320);
|
||||
cfg.bgScreenHeight = child->IntAttribute("ScreenHeight", 240);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 (std::string(child->Name()) == "Texture")
|
||||
{
|
||||
std::string crcStr = std::string(child->Attribute("CRC"));
|
||||
fs::path texPath = std::string(child->Attribute("Path"));
|
||||
std::string texName = "";
|
||||
|
||||
uint32_t crc = strtoul(crcStr.c_str(), NULL, 16);
|
||||
|
||||
cfg.texturePool[crc].path = texPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Globals::GenSymbolMap(const std::string& symbolMapPath)
|
||||
{
|
||||
auto symbolLines = File::ReadAllLines(symbolMapPath);
|
||||
|
||||
for (std::string symbolLine : symbolLines)
|
||||
{
|
||||
auto split = StringHelper::Split(symbolLine, " ");
|
||||
uint32_t addr = strtoul(split[0].c_str(), NULL, 16);
|
||||
std::string symbolName = split[1];
|
||||
|
||||
symbolMap[addr] = symbolName;
|
||||
}
|
||||
}
|
||||
|
||||
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*>();
|
||||
|
||||
segmentRefs[segment] = file->GetXmlFilePath();
|
||||
segmentRefFiles[segment] = file;
|
||||
cfg.segmentRefFiles[segment].push_back(file);
|
||||
}
|
||||
|
||||
bool Globals::HasSegment(int32_t segment)
|
||||
{
|
||||
return std::find(segments.begin(), segments.end(), segment) != segments.end();
|
||||
}
|
||||
|
||||
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->symbolMap.find(segAddress);
|
||||
if (symbolFromMap != Globals::Instance->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}
|
||||
{
|
||||
}
|
||||
|
|
|
@ -3,9 +3,10 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "GameConfig.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
#include "ZTexture.h"
|
||||
|
||||
class ZRoom;
|
||||
|
||||
enum class VerbosityLevel
|
||||
{
|
||||
|
@ -14,25 +15,23 @@ enum class VerbosityLevel
|
|||
VERBOSITY_DEBUG
|
||||
};
|
||||
|
||||
struct TexturePoolEntry
|
||||
{
|
||||
fs::path path = ""; // Path to Shared Texture
|
||||
};
|
||||
typedef void (*ExporterSetFunc)(ZFile*);
|
||||
typedef bool (*ExporterSetFuncBool)(ZFileMode fileMode);
|
||||
typedef void (*ExporterSetFuncVoid)(int argc, char* argv[], int& i);
|
||||
typedef void (*ExporterSetFuncVoid2)(const std::string& buildMode, ZFileMode& fileMode);
|
||||
typedef void (*ExporterSetFuncVoid3)();
|
||||
|
||||
class GameConfig
|
||||
class ExporterSet
|
||||
{
|
||||
public:
|
||||
std::map<int32_t, std::string> segmentRefs;
|
||||
std::map<int32_t, ZFile*> segmentRefFiles;
|
||||
std::map<uint32_t, std::string> symbolMap;
|
||||
std::vector<std::string> actorList;
|
||||
std::vector<std::string> objectList;
|
||||
std::map<uint32_t, TexturePoolEntry> texturePool; // Key = CRC
|
||||
|
||||
// ZBackground
|
||||
uint32_t bgScreenWidth = 320, bgScreenHeight = 240;
|
||||
|
||||
GameConfig() = default;
|
||||
std::map<ZResourceType, ZResourceExporter*> exporters;
|
||||
ExporterSetFuncVoid parseArgsFunc = nullptr;
|
||||
ExporterSetFuncVoid2 parseFileModeFunc = nullptr;
|
||||
ExporterSetFuncBool processFileModeFunc = nullptr;
|
||||
ExporterSetFunc beginFileFunc = nullptr;
|
||||
ExporterSetFunc endFileFunc = nullptr;
|
||||
ExporterSetFuncVoid3 beginXMLFunc = nullptr;
|
||||
ExporterSetFuncVoid3 endXMLFunc = nullptr;
|
||||
};
|
||||
|
||||
class Globals
|
||||
|
@ -56,35 +55,37 @@ public:
|
|||
bool warnNoOffset = false;
|
||||
bool errorNoOffset = false;
|
||||
bool verboseUnaccounted = false;
|
||||
bool gccCompat = false;
|
||||
bool forceStatic = false;
|
||||
|
||||
std::vector<ZFile*> files;
|
||||
std::vector<ZFile*> externalFiles;
|
||||
std::vector<int32_t> segments;
|
||||
std::map<int32_t, std::string> segmentRefs;
|
||||
std::map<int32_t, ZFile*> segmentRefFiles;
|
||||
ZRoom* lastScene;
|
||||
std::map<uint32_t, std::string> symbolMap;
|
||||
|
||||
std::string currentExporter;
|
||||
static std::map<std::string, ExporterSet*>* GetExporterMap();
|
||||
static void AddExporter(std::string exporterName, ExporterSet* exporterSet);
|
||||
|
||||
Globals();
|
||||
std::string FindSymbolSegRef(int32_t segNumber, uint32_t symbolAddress);
|
||||
void ReadConfigFile(const std::string& configFilePath);
|
||||
void ReadTexturePool(const std::string& texturePoolXmlPath);
|
||||
void GenSymbolMap(const std::string& symbolMapPath);
|
||||
|
||||
void AddSegment(int32_t segment, ZFile* file);
|
||||
bool HasSegment(int32_t segment);
|
||||
};
|
||||
|
||||
/*
|
||||
* Note: In being able to track references across files, there are a few major files that make use
|
||||
* of segments...
|
||||
* Segment 1: nintendo_rogo_static/title_static
|
||||
* Segment 2: parameter_static
|
||||
* Segment 4: gameplay_keep
|
||||
* Segment 5: gameplay_field_keep, gameplay_dangeon_keep
|
||||
* Segment 7: link_animetion
|
||||
* Segment 8: icon_item_static
|
||||
* Segment 9: icon_item_24_static
|
||||
* Segment 12: icon_item_field_static, icon_item_dungeon_static
|
||||
* Segment 13: icon_item_nes_static
|
||||
*
|
||||
* I'm thinking a config file could be usable, but I'll have to experiment...
|
||||
*/
|
||||
ZResourceExporter* GetExporter(ZResourceType resType);
|
||||
ExporterSet* GetExporterSet();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
bool GetSegmentedArrayIndexedName(segptr_t segAddress, size_t elementSize, ZFile* currentFile,
|
||||
const std::string& expectedType, std::string& declName);
|
||||
};
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* The high level format for animations.
|
||||
*/
|
||||
|
||||
class HLAnimation
|
||||
{
|
||||
public:
|
||||
};
|
|
@ -1,110 +0,0 @@
|
|||
#include "HLAnimationIntermediette.h"
|
||||
|
||||
using namespace tinyxml2;
|
||||
|
||||
HLAnimationIntermediette::HLAnimationIntermediette()
|
||||
{
|
||||
limit = 0;
|
||||
limbCount = 0;
|
||||
frameCount = 0;
|
||||
rotationValues = std::vector<uint16_t>();
|
||||
rotationIndices = std::vector<RotationIndex>();
|
||||
}
|
||||
|
||||
HLAnimationIntermediette::~HLAnimationIntermediette()
|
||||
{
|
||||
}
|
||||
|
||||
HLAnimationIntermediette* HLAnimationIntermediette::FromXML(std::string xmlPath)
|
||||
{
|
||||
HLAnimationIntermediette* anim = new HLAnimationIntermediette();
|
||||
XMLDocument doc;
|
||||
|
||||
doc.LoadFile(xmlPath.c_str());
|
||||
|
||||
XMLElement* root = doc.RootElement();
|
||||
|
||||
anim->limit = root->IntAttribute("Limit");
|
||||
anim->limbCount = root->IntAttribute("LimbCount");
|
||||
anim->frameCount = root->IntAttribute("FrameCount");
|
||||
|
||||
for (XMLElement* child = root->FirstChildElement(); child != NULL;
|
||||
child = child->NextSiblingElement())
|
||||
{
|
||||
if (std::string(child->Name()) == "RotationValues")
|
||||
{
|
||||
for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL;
|
||||
child2 = child2->NextSiblingElement())
|
||||
{
|
||||
std::string value = child2->GetText();
|
||||
anim->rotationValues.push_back(atoi(value.c_str()));
|
||||
}
|
||||
}
|
||||
else if (std::string(child->Name()) == "RotationIndices")
|
||||
{
|
||||
for (XMLElement* child2 = child->FirstChildElement(); child2 != NULL;
|
||||
child2 = child2->NextSiblingElement())
|
||||
anim->rotationIndices.push_back(RotationIndex(child2->IntAttribute("X"),
|
||||
child2->IntAttribute("Y"),
|
||||
child2->IntAttribute("Z")));
|
||||
}
|
||||
}
|
||||
|
||||
return anim;
|
||||
}
|
||||
|
||||
HLAnimationIntermediette* HLAnimationIntermediette::FromZAnimation(ZAnimation* zAnim)
|
||||
{
|
||||
HLAnimationIntermediette* anim = new HLAnimationIntermediette();
|
||||
|
||||
return anim;
|
||||
}
|
||||
|
||||
ZAnimation* HLAnimationIntermediette::ToZAnimation()
|
||||
{
|
||||
ZAnimation* zAnim = new ZNormalAnimation(nullptr);
|
||||
|
||||
return zAnim;
|
||||
}
|
||||
|
||||
std::string HLAnimationIntermediette::OutputXML()
|
||||
{
|
||||
std::string output = "";
|
||||
XMLDocument doc;
|
||||
|
||||
XMLElement* root = doc.NewElement("HLAnimationIntermediette");
|
||||
root->SetAttribute("Limit", limit);
|
||||
root->SetAttribute("LimbCount", limbCount);
|
||||
root->SetAttribute("FrameCount", frameCount);
|
||||
|
||||
doc.InsertFirstChild(root);
|
||||
|
||||
XMLElement* rotValues = doc.NewElement("RotationValues");
|
||||
|
||||
for (size_t i = 0; i < rotationValues.size(); i++)
|
||||
{
|
||||
XMLElement* rotValue = doc.NewElement("Value");
|
||||
rotValue->SetText(rotationValues[i]);
|
||||
rotValues->InsertEndChild(rotValue);
|
||||
}
|
||||
|
||||
root->InsertEndChild(rotValues);
|
||||
|
||||
XMLElement* rotIndices = doc.NewElement("RotationIndices");
|
||||
|
||||
for (size_t i = 0; i < rotationIndices.size(); i++)
|
||||
{
|
||||
XMLElement* rotIndex = doc.NewElement("Value");
|
||||
rotIndex->SetAttribute("X", rotationIndices[i].x);
|
||||
rotIndex->SetAttribute("Y", rotationIndices[i].y);
|
||||
rotIndex->SetAttribute("Z", rotationIndices[i].z);
|
||||
rotIndices->InsertEndChild(rotIndex);
|
||||
}
|
||||
|
||||
root->InsertEndChild(rotIndices);
|
||||
|
||||
XMLPrinter printer;
|
||||
|
||||
doc.Accept(&printer);
|
||||
return printer.CStr();
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "../ZAnimation.h"
|
||||
#include "HLFileIntermediette.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
/*
|
||||
* An intermediette format for animations. Going to use XML.
|
||||
* Goes from FBX->XML->C
|
||||
* Note: At the moment this is a very direct representation of the output format.
|
||||
* Optimally we can determine where the keyframes are and remove redundant information.
|
||||
*/
|
||||
|
||||
class HLAnimationIntermediette
|
||||
{
|
||||
public:
|
||||
int16_t frameCount;
|
||||
int16_t limit;
|
||||
int16_t limbCount;
|
||||
std::vector<uint16_t> rotationValues;
|
||||
std::vector<RotationIndex> rotationIndices;
|
||||
|
||||
HLAnimationIntermediette();
|
||||
~HLAnimationIntermediette();
|
||||
|
||||
std::string OutputXML();
|
||||
ZAnimation* ToZAnimation();
|
||||
|
||||
static HLAnimationIntermediette* FromXML(std::string xmlPath);
|
||||
static HLAnimationIntermediette* FromZAnimation(ZAnimation* zAnim);
|
||||
};
|
|
@ -1,5 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
class HLFileIntermediette
|
||||
{
|
||||
};
|
File diff suppressed because it is too large
Load diff
|
@ -1,312 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <Vec3s.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../ZDisplayList.h"
|
||||
#include "../ZSkeleton.h"
|
||||
#include "HLFileIntermediette.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
/*
|
||||
* An intermediette format for models. Goes from FBX<-->Intermediette<-->Display List C Code.
|
||||
*/
|
||||
|
||||
class HLModelIntermediette;
|
||||
|
||||
class HLIntermediette
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
HLModelIntermediette* parent;
|
||||
|
||||
HLIntermediette();
|
||||
~HLIntermediette();
|
||||
|
||||
virtual std::string OutputCode();
|
||||
virtual std::string OutputOBJ();
|
||||
virtual void OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts);
|
||||
virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root);
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
};
|
||||
|
||||
class HLModelObj
|
||||
{
|
||||
public:
|
||||
Vec3s pos;
|
||||
Vec3s rot;
|
||||
std::vector<aiVector3D> vertices;
|
||||
std::vector<int32_t> indices;
|
||||
|
||||
HLModelObj() = default;
|
||||
HLModelObj(Vec3s nPos, Vec3s nRot, std::vector<aiVector3D> nVerts,
|
||||
std::vector<int32_t> nIndices);
|
||||
};
|
||||
|
||||
class HLModelIntermediette : public HLFileIntermediette
|
||||
{
|
||||
public:
|
||||
std::vector<HLIntermediette*> blocks;
|
||||
std::vector<Vec3s> meshTranslations;
|
||||
std::vector<HLModelObj*> objects;
|
||||
Vec3s lastTrans;
|
||||
|
||||
bool hasSkeleton;
|
||||
|
||||
bool startsWithPipeSync;
|
||||
bool startsWithClearGeometryMode;
|
||||
bool lerpBeforeTextureBlock;
|
||||
|
||||
uint32_t startIndex;
|
||||
uint32_t meshStartIndex;
|
||||
|
||||
HLModelIntermediette();
|
||||
~HLModelIntermediette();
|
||||
|
||||
static HLModelIntermediette* FromXML(tinyxml2::XMLElement* root);
|
||||
static void FromZDisplayList(HLModelIntermediette* model, ZDisplayList* zDisplayList);
|
||||
static void FromZSkeleton(HLModelIntermediette* model, ZSkeleton* zSkeleton);
|
||||
static void ProcessZSkeletonLimb(HLModelIntermediette* model, ZSkeleton* zSkeleton,
|
||||
ZLimb* limb);
|
||||
std::string ToOBJFile();
|
||||
std::string ToAssimpFile();
|
||||
|
||||
std::string OutputCode();
|
||||
std::string OutputXML();
|
||||
|
||||
template <typename T>
|
||||
T* FindByName(std::string name);
|
||||
|
||||
template <typename T>
|
||||
T* FindByType();
|
||||
};
|
||||
|
||||
class HLTextureIntermediette : public HLIntermediette
|
||||
{
|
||||
public:
|
||||
ZTexture* tex;
|
||||
std::string fileName;
|
||||
|
||||
HLTextureIntermediette();
|
||||
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
virtual std::string OutputCode();
|
||||
virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root);
|
||||
};
|
||||
|
||||
class HLSetTranslation : public HLIntermediette
|
||||
{
|
||||
public:
|
||||
float transX, transY, transZ;
|
||||
|
||||
HLSetTranslation();
|
||||
HLSetTranslation(float nTransX, float nTransY, float nTransZ);
|
||||
|
||||
virtual void OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts);
|
||||
};
|
||||
|
||||
class HLTerminator : public HLIntermediette
|
||||
{
|
||||
public:
|
||||
HLTerminator();
|
||||
~HLTerminator();
|
||||
|
||||
virtual void OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts);
|
||||
};
|
||||
|
||||
enum class HLMaterialCmt
|
||||
{
|
||||
Wrap,
|
||||
Mirror,
|
||||
Clamp
|
||||
};
|
||||
|
||||
class HLMaterialIntermediette : public HLIntermediette
|
||||
{
|
||||
public:
|
||||
std::string textureName;
|
||||
// int32_t repeatH, repeatV;
|
||||
uint8_t clrR, clrG, clrB, clrA, clrM, clrL;
|
||||
// bool clampH, clampV;
|
||||
// bool mirrorH, mirrorV;
|
||||
HLMaterialCmt cmtH, cmtV;
|
||||
|
||||
// TODO: Remember to add lerp params here...
|
||||
|
||||
HLMaterialIntermediette();
|
||||
|
||||
virtual std::string OutputCode();
|
||||
virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* parent);
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
};
|
||||
|
||||
class HLMeshCommand
|
||||
{
|
||||
public:
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
virtual std::string OutputCode(HLModelIntermediette* parent);
|
||||
virtual std::string OutputOBJ(HLModelIntermediette* parent);
|
||||
virtual void OutputAssimp(HLModelIntermediette* parent, aiScene* scene, aiMesh* mesh);
|
||||
|
||||
virtual void OutputXML(tinyxml2::XMLElement* parent);
|
||||
};
|
||||
|
||||
class HLVerticesIntermediette : public HLIntermediette
|
||||
{
|
||||
public:
|
||||
std::vector<ZVtx> vertices;
|
||||
|
||||
HLVerticesIntermediette();
|
||||
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* verticesElement);
|
||||
void InitFromVertices(std::vector<ZVtx> dispListVertices);
|
||||
virtual std::string OutputCode(HLModelIntermediette* parent);
|
||||
virtual std::string OutputOBJ();
|
||||
virtual void OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts);
|
||||
virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root);
|
||||
};
|
||||
|
||||
class HLMeshCmdTriangle1 : public HLMeshCommand
|
||||
{
|
||||
public:
|
||||
int32_t v0, v1, v2, flag;
|
||||
|
||||
HLMeshCmdTriangle1();
|
||||
HLMeshCmdTriangle1(int32_t nV0, int32_t nV1, int32_t nV2, int32_t nFlag);
|
||||
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
virtual std::string OutputCode(HLModelIntermediette* parent);
|
||||
virtual void OutputAssimp(HLModelIntermediette* parent, aiScene* scene, aiMesh* mesh);
|
||||
virtual void OutputXML(tinyxml2::XMLElement* parent);
|
||||
};
|
||||
|
||||
class HLMeshCmdTriangle2 : public HLMeshCommand
|
||||
{
|
||||
public:
|
||||
int32_t v0, v1, v2, flag0, v10, v11, v12, flag1;
|
||||
|
||||
HLMeshCmdTriangle2();
|
||||
HLMeshCmdTriangle2(int32_t nV0, int32_t nV1, int32_t nV2, int32_t nFlag0, int32_t nV10,
|
||||
int32_t nV11, int32_t nV12, int32_t nFlag1);
|
||||
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
virtual std::string OutputCode(HLModelIntermediette* parent);
|
||||
virtual std::string OutputOBJ(HLModelIntermediette* parent);
|
||||
virtual void OutputAssimp(HLModelIntermediette* parent, aiScene* scene, aiMesh* mesh);
|
||||
virtual void OutputXML(tinyxml2::XMLElement* parent);
|
||||
};
|
||||
|
||||
class HLMeshCmdLoadVertices : public HLMeshCommand
|
||||
{
|
||||
public:
|
||||
uint8_t numVerts;
|
||||
uint8_t startIndex;
|
||||
|
||||
HLMeshCmdLoadVertices();
|
||||
HLMeshCmdLoadVertices(uint8_t nNumVerts, uint8_t nStartIndex);
|
||||
|
||||
virtual void OutputXML(tinyxml2::XMLElement* parent);
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
virtual std::string OutputOBJ(HLModelIntermediette* parent);
|
||||
virtual void OutputAssimp(HLModelIntermediette* parent, aiScene* scene, aiMesh* mesh);
|
||||
virtual std::string OutputCode(HLModelIntermediette* parent);
|
||||
};
|
||||
|
||||
class HLMeshCmdCull : public HLMeshCommand
|
||||
{
|
||||
public:
|
||||
uint8_t indexStart;
|
||||
uint8_t indexEnd;
|
||||
|
||||
HLMeshCmdCull();
|
||||
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
virtual std::string OutputCode(HLModelIntermediette* parent);
|
||||
};
|
||||
|
||||
class HLMeshCmdGeoSettings : public HLMeshCommand
|
||||
{
|
||||
public:
|
||||
std::string on, off;
|
||||
|
||||
HLMeshCmdGeoSettings();
|
||||
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
virtual std::string OutputCode(HLModelIntermediette* parent);
|
||||
};
|
||||
|
||||
class HLMeshIntermediette : public HLIntermediette
|
||||
{
|
||||
public:
|
||||
std::vector<HLMeshCommand*> commands;
|
||||
|
||||
HLMeshIntermediette();
|
||||
|
||||
void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
std::string OutputCode(std::string materialName);
|
||||
virtual std::string OutputOBJ();
|
||||
virtual void OutputAssimp(aiScene* scene, std::vector<aiVector3D>* verts);
|
||||
virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root);
|
||||
};
|
||||
|
||||
class HLDisplayListCommand
|
||||
{
|
||||
public:
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
virtual std::string OutputCode();
|
||||
};
|
||||
|
||||
class HLDisplayListCmdDrawMesh : public HLDisplayListCommand
|
||||
{
|
||||
public:
|
||||
std::string meshName, materialName;
|
||||
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
virtual std::string OutputCode();
|
||||
};
|
||||
|
||||
class HLDisplayListCmdPipeSync : public HLDisplayListCommand
|
||||
{
|
||||
public:
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
virtual std::string OutputCode();
|
||||
};
|
||||
|
||||
class HLDisplayListIntermediette : public HLIntermediette
|
||||
{
|
||||
public:
|
||||
std::vector<HLDisplayListCommand*> commands;
|
||||
uint32_t address;
|
||||
|
||||
HLDisplayListIntermediette();
|
||||
|
||||
virtual std::string OutputCode();
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
};
|
||||
|
||||
class HLLimbCommand
|
||||
{
|
||||
public:
|
||||
std::string meshName, materialName;
|
||||
|
||||
HLLimbCommand();
|
||||
HLLimbCommand(std::string nMeshName, std::string nMaterialName);
|
||||
|
||||
virtual void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
virtual void OutputXML(tinyxml2::XMLElement* parent);
|
||||
virtual std::string OutputCode(HLModelIntermediette* parent);
|
||||
};
|
||||
|
||||
class HLLimbIntermediette : public HLIntermediette
|
||||
{
|
||||
public:
|
||||
std::vector<HLLimbCommand*> commands;
|
||||
|
||||
HLLimbIntermediette();
|
||||
|
||||
void InitFromXML(tinyxml2::XMLElement* xmlElement);
|
||||
std::string OutputCode();
|
||||
virtual void OutputXML(tinyxml2::XMLDocument* doc, tinyxml2::XMLElement* root);
|
||||
};
|
|
@ -1,13 +0,0 @@
|
|||
#include "HLTexture.h"
|
||||
#include "../StringHelper.h"
|
||||
|
||||
HLTexture* HLTexture::FromPNG(std::string pngFilePath, HLTextureType texType)
|
||||
{
|
||||
// int32_t comp;
|
||||
HLTexture* tex = new HLTexture();
|
||||
tex->type = texType;
|
||||
// tex->bmpRgba = (uint8_t*)stbi_load((pngFilePath).c_str(), (int32_t*)&tex->width,
|
||||
// (int32_t*)&tex->height, &comp, STBI_rgb_alpha);
|
||||
|
||||
return tex;
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// TODO: This was duplicated from ZTexture. It's probably going to be modified to differentiate from
|
||||
// ZTexture but if not, we're going to need to have the two share an enum.
|
||||
enum class HLTextureType
|
||||
{
|
||||
RGBA32bpp,
|
||||
RGBA16bpp,
|
||||
Palette4bpp,
|
||||
Palette8bpp,
|
||||
Grayscale4bpp,
|
||||
Grayscale8bpp,
|
||||
GrayscaleAlpha4bpp,
|
||||
GrayscaleAlpha8bpp,
|
||||
GrayscaleAlpha16bpp,
|
||||
Error
|
||||
};
|
||||
|
||||
class HLTexture
|
||||
{
|
||||
public:
|
||||
static HLTexture* FromPNG(std::string pngFilePath, HLTextureType texType);
|
||||
|
||||
HLTextureType type;
|
||||
uint32_t width, height;
|
||||
uint8_t* bmpRgba;
|
||||
};
|
|
@ -5,7 +5,7 @@
|
|||
#include <png.h>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
|
||||
/* ImageBackend */
|
||||
|
||||
|
@ -216,7 +216,9 @@ void ImageBackend::WritePng(const char* filename)
|
|||
|
||||
void ImageBackend::WritePng(const fs::path& filename)
|
||||
{
|
||||
WritePng(filename.c_str());
|
||||
// Note: The .string() is necessary for MSVC, due to the implementation of std::filesystem
|
||||
// differing from GCC. Do not remove!
|
||||
WritePng(filename.string().c_str());
|
||||
}
|
||||
|
||||
void ImageBackend::SetTextureData(const std::vector<std::vector<RGBAPixel>>& texData,
|
||||
|
@ -385,11 +387,22 @@ void ImageBackend::SetPalette(const ImageBackend& pal)
|
|||
{
|
||||
for (size_t x = 0; x < pal.width; x++)
|
||||
{
|
||||
size_t index = y * pal.width + x;
|
||||
if (index >= paletteSize)
|
||||
{
|
||||
/*
|
||||
* Some TLUTs are bigger than 256 colors.
|
||||
* For those cases, we will only take the first 256
|
||||
* to colorize this CI texture.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t r = pal.pixelMatrix[y][x * bytePerPixel + 0];
|
||||
uint8_t g = pal.pixelMatrix[y][x * bytePerPixel + 1];
|
||||
uint8_t b = pal.pixelMatrix[y][x * bytePerPixel + 2];
|
||||
uint8_t a = pal.pixelMatrix[y][x * bytePerPixel + 3];
|
||||
SetPaletteIndex(y * pal.width + x, r, g, b, a);
|
||||
SetPaletteIndex(index, r, g, b, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "Directory.h"
|
||||
#include "Utils/Directory.h"
|
||||
|
||||
class RGBAPixel
|
||||
{
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
#include "BuildInfo.h"
|
||||
#include "Directory.h"
|
||||
#include "File.h"
|
||||
#include <Utils/Directory.h>
|
||||
#include <Utils/File.h>
|
||||
#include <Utils/Path.h>
|
||||
#include "Globals.h"
|
||||
#include "HighLevel/HLAnimationIntermediette.h"
|
||||
#include "HighLevel/HLModelIntermediette.h"
|
||||
#include "Overlays/ZOverlay.h"
|
||||
#include "Path.h"
|
||||
#include "ZAnimation.h"
|
||||
#include "ZBackground.h"
|
||||
#include "ZBlob.h"
|
||||
|
@ -23,17 +20,17 @@
|
|||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include "tinyxml2.h"
|
||||
|
||||
using namespace tinyxml2;
|
||||
extern const char gBuildHash[];
|
||||
|
||||
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, ZFileMode fileMode);
|
||||
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath,
|
||||
ZFileMode fileMode);
|
||||
|
||||
void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const fs::path& outPath);
|
||||
void BuildAssetBackground(const fs::path& imageFilePath, const fs::path& outPath);
|
||||
void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath);
|
||||
void BuildAssetModelIntermediette(const fs::path& outPath);
|
||||
void BuildAssetAnimationIntermediette(const fs::path& animPath, const fs::path& outPath);
|
||||
|
||||
#if !defined(_MSC_VER) && !defined(__CYGWIN__)
|
||||
#define ARRAY_COUNT(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
|
@ -116,34 +113,7 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
}
|
||||
|
||||
Globals* g = new Globals();
|
||||
|
||||
// Parse File Mode
|
||||
std::string buildMode = argv[1];
|
||||
ZFileMode fileMode = ZFileMode::Invalid;
|
||||
|
||||
if (buildMode == "btex")
|
||||
fileMode = ZFileMode::BuildTexture;
|
||||
else if (buildMode == "bren")
|
||||
fileMode = ZFileMode::BuildBackground;
|
||||
else if (buildMode == "bovl")
|
||||
fileMode = ZFileMode::BuildOverlay;
|
||||
else if (buildMode == "bsf")
|
||||
fileMode = ZFileMode::BuildSourceFile;
|
||||
else if (buildMode == "bblb")
|
||||
fileMode = ZFileMode::BuildBlob;
|
||||
else if (buildMode == "bmdlintr")
|
||||
fileMode = ZFileMode::BuildModelIntermediette;
|
||||
else if (buildMode == "bamnintr")
|
||||
fileMode = ZFileMode::BuildAnimationIntermediette;
|
||||
else if (buildMode == "e")
|
||||
fileMode = ZFileMode::Extract;
|
||||
|
||||
if (fileMode == ZFileMode::Invalid)
|
||||
{
|
||||
printf("Error: Invalid file mode '%s'\n", buildMode.c_str());
|
||||
return 1;
|
||||
}
|
||||
Globals* g = new Globals;
|
||||
|
||||
// Parse other "commands"
|
||||
for (int32_t i = 2; i < argc; i++)
|
||||
|
@ -152,76 +122,63 @@ int main(int argc, char* argv[])
|
|||
|
||||
if (arg == "-o" || arg == "--outputpath") // Set output path
|
||||
{
|
||||
Globals::Instance->outputPath = argv[i + 1];
|
||||
Globals::Instance->outputPath = argv[++i];
|
||||
|
||||
if (Globals::Instance->sourceOutputPath == "")
|
||||
Globals::Instance->sourceOutputPath = Globals::Instance->outputPath;
|
||||
|
||||
i++;
|
||||
}
|
||||
else if (arg == "-i" || arg == "--inputpath") // Set input path
|
||||
{
|
||||
Globals::Instance->inputPath = argv[i + 1];
|
||||
i++;
|
||||
Globals::Instance->inputPath = argv[++i];
|
||||
}
|
||||
else if (arg == "-b" || arg == "--baserompath") // Set baserom path
|
||||
{
|
||||
Globals::Instance->baseRomPath = argv[i + 1];
|
||||
i++;
|
||||
Globals::Instance->baseRomPath = argv[++i];
|
||||
}
|
||||
else if (arg == "-osf") // Set source output path
|
||||
{
|
||||
Globals::Instance->sourceOutputPath = argv[i + 1];
|
||||
i++;
|
||||
Globals::Instance->sourceOutputPath = argv[++i];
|
||||
}
|
||||
else if (arg == "-gsf") // Generate source file during extraction
|
||||
{
|
||||
Globals::Instance->genSourceFile = std::string(argv[i + 1]) == "1";
|
||||
i++;
|
||||
Globals::Instance->genSourceFile = std::string_view(argv[++i]) == "1";
|
||||
}
|
||||
else if (arg == "-tm") // Test Mode (enables certain experimental features)
|
||||
{
|
||||
Globals::Instance->testMode = std::string(argv[i + 1]) == "1";
|
||||
i++;
|
||||
Globals::Instance->testMode = std::string_view(argv[++i]) == "1";
|
||||
}
|
||||
else if (arg == "-crc" ||
|
||||
arg == "--output-crc") // Outputs a CRC file for each extracted texture.
|
||||
{
|
||||
Globals::Instance->outputCrc = true;
|
||||
Globals::Instance->testMode = std::string_view(argv[++i]) == "1";
|
||||
}
|
||||
else if (arg == "-ulzdl") // Use Legacy ZDisplay List
|
||||
{
|
||||
Globals::Instance->useLegacyZDList = std::string(argv[i + 1]) == "1";
|
||||
i++;
|
||||
Globals::Instance->useLegacyZDList = std::string_view(argv[++i]) == "1";
|
||||
}
|
||||
else if (arg == "-profile") // Enable profiling
|
||||
{
|
||||
Globals::Instance->profile = std::string(argv[i + 1]) == "1";
|
||||
i++;
|
||||
Globals::Instance->profile = std::string_view(argv[++i]) == "1";
|
||||
}
|
||||
else if (arg ==
|
||||
"-uer") // Split resources into their individual components (enabled by default)
|
||||
// TODO: We may wish to make this a part of the config file...
|
||||
{
|
||||
Globals::Instance->useExternalResources = std::string(argv[i + 1]) == "1";
|
||||
i++;
|
||||
Globals::Instance->useExternalResources = std::string_view(argv[++i]) == "1";
|
||||
}
|
||||
else if (arg == "-tt") // Set texture type
|
||||
{
|
||||
Globals::Instance->texType = ZTexture::GetTextureTypeFromString(argv[i + 1]);
|
||||
i++;
|
||||
Globals::Instance->texType = ZTexture::GetTextureTypeFromString(argv[++i]);
|
||||
}
|
||||
else if (arg == "-cfg") // Set cfg path (for overlays)
|
||||
// TODO: Change the name of this to something else so it doesn't
|
||||
// get confused with XML config files.
|
||||
{
|
||||
Globals::Instance->cfgPath = argv[i + 1];
|
||||
i++;
|
||||
Globals::Instance->cfgPath = argv[++i];
|
||||
}
|
||||
else if (arg == "-rconf") // Read Config File
|
||||
{
|
||||
Globals::Instance->ReadConfigFile(argv[i + 1]);
|
||||
i++;
|
||||
Globals::Instance->cfg.ReadConfigFile(argv[++i]);
|
||||
}
|
||||
else if (arg == "-eh") // Enable Error Handler
|
||||
{
|
||||
|
@ -253,18 +210,93 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
Globals::Instance->verboseUnaccounted = true;
|
||||
}
|
||||
else if (arg == "-se" || arg == "--set-exporter") // Set Current Exporter
|
||||
{
|
||||
Globals::Instance->currentExporter = argv[++i];
|
||||
}
|
||||
else if (arg == "--gcc-compat") // GCC compatibility
|
||||
{
|
||||
Globals::Instance->gccCompat = true;
|
||||
}
|
||||
else if (arg == "-s" || arg == "--static")
|
||||
{
|
||||
Globals::Instance->forceStatic = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Parse File Mode
|
||||
ExporterSet* exporterSet = Globals::Instance->GetExporterSet();
|
||||
std::string buildMode = argv[1];
|
||||
ZFileMode fileMode = ZFileMode::Invalid;
|
||||
|
||||
if (buildMode == "btex")
|
||||
fileMode = ZFileMode::BuildTexture;
|
||||
else if (buildMode == "bren")
|
||||
fileMode = ZFileMode::BuildBackground;
|
||||
else if (buildMode == "bovl")
|
||||
fileMode = ZFileMode::BuildOverlay;
|
||||
else if (buildMode == "bsf")
|
||||
fileMode = ZFileMode::BuildSourceFile;
|
||||
else if (buildMode == "bblb")
|
||||
fileMode = ZFileMode::BuildBlob;
|
||||
else if (buildMode == "e")
|
||||
fileMode = ZFileMode::Extract;
|
||||
else if (exporterSet != nullptr && exporterSet->parseFileModeFunc != nullptr)
|
||||
exporterSet->parseFileModeFunc(buildMode, fileMode);
|
||||
|
||||
if (fileMode == ZFileMode::Invalid)
|
||||
{
|
||||
printf("Error: Invalid file mode '%s'\n", buildMode.c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
// We've parsed through our commands once. If an exporter exists, it's been set by now.
|
||||
// Now we'll parse through them again but pass them on to our exporter if one is available.
|
||||
|
||||
if (exporterSet != nullptr && exporterSet->parseArgsFunc != nullptr)
|
||||
{
|
||||
for (int32_t i = 2; i < argc; i++)
|
||||
exporterSet->parseArgsFunc(argc, argv, i);
|
||||
}
|
||||
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
|
||||
printf("ZAPD: Zelda Asset Processor For Decomp: %s\n", gBuildHash);
|
||||
|
||||
// TODO: switch
|
||||
if (fileMode == ZFileMode::Extract || fileMode == ZFileMode::BuildSourceFile)
|
||||
{
|
||||
bool parseSuccessful =
|
||||
Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath, fileMode);
|
||||
bool procFileModeSuccess = false;
|
||||
|
||||
if (!parseSuccessful)
|
||||
return 1;
|
||||
if (exporterSet != nullptr && exporterSet->processFileModeFunc != nullptr)
|
||||
procFileModeSuccess = exporterSet->processFileModeFunc(fileMode);
|
||||
|
||||
if (!procFileModeSuccess)
|
||||
{
|
||||
bool parseSuccessful;
|
||||
|
||||
for (auto& extFile : Globals::Instance->cfg.externalFiles)
|
||||
{
|
||||
fs::path externalXmlFilePath =
|
||||
Globals::Instance->cfg.externalXmlFolder / extFile.xmlPath;
|
||||
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
|
||||
{
|
||||
printf("Parsing external file from config: '%s'\n",
|
||||
externalXmlFilePath.c_str());
|
||||
}
|
||||
|
||||
parseSuccessful = Parse(externalXmlFilePath, Globals::Instance->baseRomPath,
|
||||
extFile.outPath, ZFileMode::ExternalFile);
|
||||
|
||||
if (!parseSuccessful)
|
||||
return 1;
|
||||
}
|
||||
|
||||
parseSuccessful = Parse(Globals::Instance->inputPath, Globals::Instance->baseRomPath,
|
||||
Globals::Instance->outputPath, fileMode);
|
||||
if (!parseSuccessful)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (fileMode == ZFileMode::BuildTexture)
|
||||
{
|
||||
|
@ -279,33 +311,26 @@ int main(int argc, char* argv[])
|
|||
{
|
||||
BuildAssetBlob(Globals::Instance->inputPath, Globals::Instance->outputPath);
|
||||
}
|
||||
else if (fileMode == ZFileMode::BuildModelIntermediette)
|
||||
{
|
||||
BuildAssetModelIntermediette(Globals::Instance->outputPath);
|
||||
}
|
||||
else if (fileMode == ZFileMode::BuildAnimationIntermediette)
|
||||
{
|
||||
BuildAssetAnimationIntermediette(Globals::Instance->inputPath,
|
||||
Globals::Instance->outputPath);
|
||||
}
|
||||
else if (fileMode == ZFileMode::BuildOverlay)
|
||||
{
|
||||
ZOverlay* overlay =
|
||||
ZOverlay::FromBuild(Path::GetDirectoryName(Globals::Instance->inputPath),
|
||||
Path::GetDirectoryName(Globals::Instance->cfgPath));
|
||||
|
||||
if (overlay)
|
||||
if (overlay != nullptr)
|
||||
File::WriteAllText(Globals::Instance->outputPath.string(),
|
||||
overlay->GetSourceOutputCode(""));
|
||||
}
|
||||
|
||||
delete g;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, ZFileMode fileMode)
|
||||
bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, const fs::path& outPath,
|
||||
ZFileMode fileMode)
|
||||
{
|
||||
XMLDocument doc;
|
||||
XMLError eResult = doc.LoadFile(xmlFilePath.string().c_str());
|
||||
tinyxml2::XMLDocument doc;
|
||||
tinyxml2::XMLError eResult = doc.LoadFile(xmlFilePath.string().c_str());
|
||||
|
||||
if (eResult != tinyxml2::XML_SUCCESS)
|
||||
{
|
||||
|
@ -313,7 +338,7 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, ZFileMode file
|
|||
return false;
|
||||
}
|
||||
|
||||
XMLNode* root = doc.FirstChild();
|
||||
tinyxml2::XMLNode* root = doc.FirstChild();
|
||||
|
||||
if (root == nullptr)
|
||||
{
|
||||
|
@ -321,37 +346,78 @@ bool Parse(const fs::path& xmlFilePath, const fs::path& basePath, ZFileMode file
|
|||
return false;
|
||||
}
|
||||
|
||||
for (XMLElement* child = root->FirstChildElement(); child != NULL;
|
||||
for (tinyxml2::XMLElement* child = root->FirstChildElement(); child != NULL;
|
||||
child = child->NextSiblingElement())
|
||||
{
|
||||
if (std::string(child->Name()) == "File")
|
||||
if (std::string_view(child->Name()) == "File")
|
||||
{
|
||||
ZFile* file = new ZFile(fileMode, child, basePath, "", xmlFilePath, false);
|
||||
ZFile* file = new ZFile(fileMode, child, basePath, outPath, "", xmlFilePath);
|
||||
Globals::Instance->files.push_back(file);
|
||||
if (fileMode == ZFileMode::ExternalFile)
|
||||
{
|
||||
Globals::Instance->externalFiles.push_back(file);
|
||||
file->isExternalFile = true;
|
||||
}
|
||||
}
|
||||
else if (std::string(child->Name()) == "ExternalFile")
|
||||
{
|
||||
const char* xmlPathValue = child->Attribute("XmlPath");
|
||||
if (xmlPathValue == nullptr)
|
||||
{
|
||||
throw std::runtime_error(StringHelper::Sprintf(
|
||||
"Parse: Fatal error in '%s'.\n"
|
||||
"\t Missing 'XmlPath' attribute in `ExternalFile` element.\n",
|
||||
xmlFilePath.c_str()));
|
||||
}
|
||||
const char* outPathValue = child->Attribute("OutPath");
|
||||
if (outPathValue == nullptr)
|
||||
{
|
||||
throw std::runtime_error(StringHelper::Sprintf(
|
||||
"Parse: Fatal error in '%s'.\n"
|
||||
"\t Missing 'OutPath' attribute in `ExternalFile` element.\n",
|
||||
xmlFilePath.c_str()));
|
||||
}
|
||||
|
||||
fs::path externalXmlFilePath =
|
||||
Globals::Instance->cfg.externalXmlFolder / fs::path(xmlPathValue);
|
||||
fs::path externalOutFilePath = fs::path(outPathValue);
|
||||
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_INFO)
|
||||
{
|
||||
printf("Parsing external file: '%s'\n", externalXmlFilePath.c_str());
|
||||
}
|
||||
|
||||
// Recursion. What can go wrong?
|
||||
Parse(externalXmlFilePath, basePath, externalOutFilePath, ZFileMode::ExternalFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("Parse: Fatal error in '%s'.\n\t Found a resource outside of "
|
||||
"a File element: '%s'\n",
|
||||
xmlFilePath.c_str(), child->Name()));
|
||||
throw std::runtime_error(StringHelper::Sprintf(
|
||||
"Parse: Fatal error in '%s'.\n\t A resource was found outside of "
|
||||
"a File element: '%s'\n",
|
||||
xmlFilePath.c_str(), child->Name()));
|
||||
}
|
||||
}
|
||||
|
||||
for (ZFile* file : Globals::Instance->files)
|
||||
if (fileMode != ZFileMode::ExternalFile)
|
||||
{
|
||||
if (fileMode == ZFileMode::BuildSourceFile)
|
||||
file->BuildSourceFile();
|
||||
else
|
||||
file->ExtractResources();
|
||||
ExporterSet* exporterSet = Globals::Instance->GetExporterSet();
|
||||
|
||||
if (exporterSet != nullptr && exporterSet->beginXMLFunc != nullptr)
|
||||
exporterSet->beginXMLFunc();
|
||||
|
||||
for (ZFile* file : Globals::Instance->files)
|
||||
{
|
||||
if (fileMode == ZFileMode::BuildSourceFile)
|
||||
file->BuildSourceFile();
|
||||
else
|
||||
file->ExtractResources();
|
||||
}
|
||||
|
||||
if (exporterSet != nullptr && exporterSet->endXMLFunc != nullptr)
|
||||
exporterSet->endXMLFunc();
|
||||
}
|
||||
|
||||
// All done, free files
|
||||
for (ZFile* file : Globals::Instance->files)
|
||||
delete file;
|
||||
|
||||
Globals::Instance->files.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -360,7 +426,7 @@ void BuildAssetTexture(const fs::path& pngFilePath, TextureType texType, const f
|
|||
std::string name = outPath.stem().string();
|
||||
|
||||
ZTexture tex(nullptr);
|
||||
tex.FromPNG(pngFilePath, texType);
|
||||
tex.FromPNG(pngFilePath.string(), texType);
|
||||
std::string cfgPath = StringHelper::Split(pngFilePath.string(), ".")[0] + ".cfg";
|
||||
|
||||
if (File::Exists(cfgPath))
|
||||
|
@ -384,43 +450,9 @@ void BuildAssetBlob(const fs::path& blobFilePath, const fs::path& outPath)
|
|||
ZBlob* blob = ZBlob::FromFile(blobFilePath.string());
|
||||
std::string name = outPath.stem().string(); // filename without extension
|
||||
|
||||
std::string src = blob->GetSourceOutputCode(name);
|
||||
std::string src = blob->GetBodySourceCode();
|
||||
|
||||
File::WriteAllText(outPath.string(), src);
|
||||
|
||||
delete blob;
|
||||
}
|
||||
|
||||
void BuildAssetModelIntermediette(const fs::path& outPath)
|
||||
{
|
||||
XMLDocument doc;
|
||||
|
||||
HLModelIntermediette* mdl = HLModelIntermediette::FromXML(doc.RootElement());
|
||||
std::string output = mdl->OutputCode();
|
||||
|
||||
File::WriteAllText(outPath.string(), output);
|
||||
|
||||
delete mdl;
|
||||
}
|
||||
|
||||
void BuildAssetAnimationIntermediette(const fs::path& animPath, const fs::path& outPath)
|
||||
{
|
||||
std::vector<std::string> split = StringHelper::Split(outPath.string(), "/");
|
||||
ZFile* file = new ZFile(split[split.size() - 2]);
|
||||
HLAnimationIntermediette* anim = HLAnimationIntermediette::FromXML(animPath.string());
|
||||
ZAnimation* zAnim = anim->ToZAnimation();
|
||||
zAnim->SetName(Path::GetFileNameWithoutExtension(split[split.size() - 1]));
|
||||
zAnim->parent = file;
|
||||
|
||||
zAnim->GetSourceOutputCode(split[split.size() - 2]);
|
||||
std::string output = "";
|
||||
|
||||
output += file->declarations[2]->text + "\n";
|
||||
output += file->declarations[1]->text + "\n";
|
||||
output += file->declarations[0]->text + "\n";
|
||||
|
||||
File::WriteAllText(outPath.string(), output);
|
||||
|
||||
delete zAnim;
|
||||
delete file;
|
||||
}
|
||||
|
|
341
tools/ZAPD/ZAPD/OtherStructs/SkinLimbStructs.cpp
Normal file
341
tools/ZAPD/ZAPD/OtherStructs/SkinLimbStructs.cpp
Normal file
|
@ -0,0 +1,341 @@
|
|||
#include "SkinLimbStructs.h"
|
||||
|
||||
#include "Globals.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZDisplayList.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
/* Struct_800A57C0 */
|
||||
|
||||
Struct_800A57C0::Struct_800A57C0(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
void Struct_800A57C0::ParseRawData()
|
||||
{
|
||||
const auto& rawData = parent->GetRawData();
|
||||
|
||||
unk_0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00);
|
||||
unk_2 = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x02);
|
||||
unk_4 = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x04);
|
||||
unk_6 = BitConverter::ToInt8BE(rawData, rawDataIndex + 0x06);
|
||||
unk_7 = BitConverter::ToInt8BE(rawData, rawDataIndex + 0x07);
|
||||
unk_8 = BitConverter::ToInt8BE(rawData, rawDataIndex + 0x08);
|
||||
unk_9 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x09);
|
||||
}
|
||||
|
||||
std::string Struct_800A57C0::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("0x%02X, %i, %i, %i, %i, %i, 0x%02X", unk_0, unk_2, unk_4, unk_6,
|
||||
unk_7, unk_8, unk_9);
|
||||
}
|
||||
|
||||
std::string Struct_800A57C0::GetSourceTypeName() const
|
||||
{
|
||||
return "Struct_800A57C0";
|
||||
}
|
||||
|
||||
ZResourceType Struct_800A57C0::GetResourceType() const
|
||||
{
|
||||
// TODO
|
||||
return ZResourceType::Error;
|
||||
}
|
||||
|
||||
size_t Struct_800A57C0::GetRawDataSize() const
|
||||
{
|
||||
return 0x0A;
|
||||
}
|
||||
|
||||
/* Struct_800A598C_2 */
|
||||
|
||||
Struct_800A598C_2::Struct_800A598C_2(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
void Struct_800A598C_2::ParseRawData()
|
||||
{
|
||||
const auto& rawData = parent->GetRawData();
|
||||
|
||||
unk_0 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x00);
|
||||
x = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x02);
|
||||
y = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x04);
|
||||
z = BitConverter::ToInt16BE(rawData, rawDataIndex + 0x06);
|
||||
unk_8 = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0x08);
|
||||
}
|
||||
|
||||
std::string Struct_800A598C_2::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("0x%02X, %i, %i, %i, 0x%02X", unk_0, x, y, z, unk_8);
|
||||
}
|
||||
|
||||
std::string Struct_800A598C_2::GetSourceTypeName() const
|
||||
{
|
||||
return "Struct_800A598C_2";
|
||||
}
|
||||
|
||||
ZResourceType Struct_800A598C_2::GetResourceType() const
|
||||
{
|
||||
// TODO
|
||||
return ZResourceType::Error;
|
||||
}
|
||||
|
||||
size_t Struct_800A598C_2::GetRawDataSize() const
|
||||
{
|
||||
return 0x0A;
|
||||
}
|
||||
|
||||
/* Struct_800A598C */
|
||||
|
||||
Struct_800A598C::Struct_800A598C(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
void Struct_800A598C::ParseRawData()
|
||||
{
|
||||
const auto& rawData = parent->GetRawData();
|
||||
|
||||
unk_0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00);
|
||||
unk_2 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x02);
|
||||
unk_4 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x04);
|
||||
unk_8 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x08);
|
||||
unk_C = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x0C);
|
||||
|
||||
if (unk_8 != 0 && GETSEGNUM(unk_8) == parent->segment)
|
||||
{
|
||||
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
|
||||
for (size_t i = 0; i < unk_0; i++)
|
||||
{
|
||||
Struct_800A57C0 unk8_data(parent);
|
||||
unk8_data.ExtractFromFile(unk_8_Offset);
|
||||
unk_8_arr.push_back(unk8_data);
|
||||
|
||||
unk_8_Offset += unk8_data.GetRawDataSize();
|
||||
}
|
||||
}
|
||||
|
||||
if (unk_C != 0 && GETSEGNUM(unk_8) == parent->segment)
|
||||
{
|
||||
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
|
||||
for (size_t i = 0; i < unk_2; i++)
|
||||
{
|
||||
Struct_800A598C_2 unkC_data(parent);
|
||||
unkC_data.ExtractFromFile(unk_C_Offset);
|
||||
unk_C_arr.push_back(unkC_data);
|
||||
|
||||
unk_C_Offset += unkC_data.GetRawDataSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Struct_800A598C::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
std::string varPrefix = prefix;
|
||||
if (name != "")
|
||||
varPrefix = name;
|
||||
|
||||
if (unk_8 != 0 && GETSEGNUM(unk_8) == parent->segment)
|
||||
{
|
||||
const auto& res = unk_8_arr.at(0);
|
||||
std::string unk_8_Str = res.GetDefaultName(varPrefix);
|
||||
|
||||
size_t arrayItemCnt = unk_8_arr.size();
|
||||
std::string entryStr = "";
|
||||
|
||||
for (size_t i = 0; i < arrayItemCnt; i++)
|
||||
{
|
||||
auto& child = unk_8_arr[i];
|
||||
child.DeclareReferences(varPrefix);
|
||||
entryStr += StringHelper::Sprintf("\t{ %s },", child.GetBodySourceCode().c_str());
|
||||
|
||||
if (i < arrayItemCnt - 1)
|
||||
entryStr += "\n";
|
||||
}
|
||||
|
||||
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
|
||||
Declaration* decl = parent->GetDeclaration(unk_8_Offset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclarationArray(unk_8_Offset, res.GetDeclarationAlignment(),
|
||||
arrayItemCnt * res.GetRawDataSize(),
|
||||
res.GetSourceTypeName(), unk_8_Str, arrayItemCnt, entryStr);
|
||||
}
|
||||
else
|
||||
decl->text = entryStr;
|
||||
}
|
||||
|
||||
if (unk_C != 0 && GETSEGNUM(unk_C) == parent->segment)
|
||||
{
|
||||
const auto& res = unk_C_arr.at(0);
|
||||
std::string unk_C_Str = res.GetDefaultName(varPrefix);
|
||||
|
||||
size_t arrayItemCnt = unk_C_arr.size();
|
||||
std::string entryStr = "";
|
||||
|
||||
for (size_t i = 0; i < arrayItemCnt; i++)
|
||||
{
|
||||
auto& child = unk_C_arr[i];
|
||||
child.DeclareReferences(varPrefix);
|
||||
entryStr += StringHelper::Sprintf("\t{ %s },", child.GetBodySourceCode().c_str());
|
||||
|
||||
if (i < arrayItemCnt - 1)
|
||||
entryStr += "\n";
|
||||
}
|
||||
|
||||
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
|
||||
Declaration* decl = parent->GetDeclaration(unk_C_Offset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclarationArray(unk_C_Offset, res.GetDeclarationAlignment(),
|
||||
arrayItemCnt * res.GetRawDataSize(),
|
||||
res.GetSourceTypeName(), unk_C_Str, arrayItemCnt, entryStr);
|
||||
}
|
||||
else
|
||||
decl->text = entryStr;
|
||||
}
|
||||
}
|
||||
|
||||
std::string Struct_800A598C::GetBodySourceCode() const
|
||||
{
|
||||
std::string unk_8_Str;
|
||||
std::string unk_C_Str;
|
||||
Globals::Instance->GetSegmentedPtrName(unk_8, parent, "Struct_800A57C0", unk_8_Str);
|
||||
Globals::Instance->GetSegmentedPtrName(unk_C, parent, "Struct_800A598C_2", unk_C_Str);
|
||||
|
||||
std::string entryStr = StringHelper::Sprintf("\n\t\tARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n",
|
||||
unk_8_Str.c_str(), unk_C_Str.c_str());
|
||||
entryStr +=
|
||||
StringHelper::Sprintf("\t\t%i, %s, %s\n\t", unk_4, unk_8_Str.c_str(), unk_C_Str.c_str());
|
||||
|
||||
return entryStr;
|
||||
}
|
||||
|
||||
std::string Struct_800A598C::GetSourceTypeName() const
|
||||
{
|
||||
return "Struct_800A598C";
|
||||
}
|
||||
|
||||
ZResourceType Struct_800A598C::GetResourceType() const
|
||||
{
|
||||
// TODO
|
||||
return ZResourceType::Error;
|
||||
}
|
||||
|
||||
size_t Struct_800A598C::GetRawDataSize() const
|
||||
{
|
||||
return 0x10;
|
||||
}
|
||||
|
||||
/* Struct_800A5E28 */
|
||||
|
||||
Struct_800A5E28::Struct_800A5E28(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
void Struct_800A5E28::ParseRawData()
|
||||
{
|
||||
const auto& rawData = parent->GetRawData();
|
||||
|
||||
unk_0 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x00);
|
||||
unk_2 = BitConverter::ToUInt16BE(rawData, rawDataIndex + 0x02);
|
||||
unk_4 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x04);
|
||||
unk_8 = BitConverter::ToUInt32BE(rawData, rawDataIndex + 0x08);
|
||||
|
||||
if (unk_4 != 0 && GETSEGNUM(unk_4) == parent->segment)
|
||||
{
|
||||
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
|
||||
for (size_t i = 0; i < unk_2; i++)
|
||||
{
|
||||
Struct_800A598C unk_4_data(parent);
|
||||
unk_4_data.ExtractFromFile(unk_4_Offset);
|
||||
unk_4_arr.push_back(unk_4_data);
|
||||
|
||||
unk_4_Offset += unk_4_data.GetRawDataSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Struct_800A5E28::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
std::string varPrefix = prefix;
|
||||
if (name != "")
|
||||
varPrefix = name;
|
||||
|
||||
ZResource::DeclareReferences(varPrefix);
|
||||
|
||||
if (unk_4 != 0 && GETSEGNUM(unk_4) == parent->segment)
|
||||
{
|
||||
const auto& res = unk_4_arr.at(0);
|
||||
std::string unk_4_Str = res.GetDefaultName(varPrefix);
|
||||
|
||||
size_t arrayItemCnt = unk_4_arr.size();
|
||||
std::string entryStr = "";
|
||||
|
||||
for (size_t i = 0; i < arrayItemCnt; i++)
|
||||
{
|
||||
auto& child = unk_4_arr[i];
|
||||
child.DeclareReferences(varPrefix);
|
||||
entryStr += StringHelper::Sprintf("\t{ %s },", child.GetBodySourceCode().c_str());
|
||||
|
||||
if (i < arrayItemCnt - 1)
|
||||
entryStr += "\n";
|
||||
}
|
||||
|
||||
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
|
||||
Declaration* decl = parent->GetDeclaration(unk_4_Offset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclarationArray(unk_4_Offset, res.GetDeclarationAlignment(),
|
||||
arrayItemCnt * res.GetRawDataSize(),
|
||||
res.GetSourceTypeName(), unk_4_Str, arrayItemCnt, entryStr);
|
||||
}
|
||||
else
|
||||
decl->text = entryStr;
|
||||
}
|
||||
|
||||
if (unk_8 != 0 && GETSEGNUM(unk_8) == parent->segment)
|
||||
{
|
||||
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
|
||||
|
||||
int32_t dlistLength = ZDisplayList::GetDListLength(
|
||||
parent->GetRawData(), unk_8_Offset,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
ZDisplayList* unk_8_dlist = new ZDisplayList(parent);
|
||||
unk_8_dlist->ExtractFromBinary(unk_8_Offset, dlistLength);
|
||||
|
||||
std::string dListStr =
|
||||
StringHelper::Sprintf("%sSkinLimbDL_%06X", varPrefix.c_str(), unk_8_Offset);
|
||||
unk_8_dlist->SetName(dListStr);
|
||||
parent->AddResource(unk_8_dlist);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Struct_800A5E28::GetBodySourceCode() const
|
||||
{
|
||||
std::string unk_4_Str;
|
||||
std::string unk_8_Str;
|
||||
Globals::Instance->GetSegmentedPtrName(unk_4, parent, "Struct_800A598C", unk_4_Str);
|
||||
Globals::Instance->GetSegmentedPtrName(unk_8, parent, "Gfx", unk_8_Str);
|
||||
|
||||
std::string entryStr = "\n";
|
||||
entryStr += StringHelper::Sprintf("\t%i, ARRAY_COUNTU(%s),\n", unk_0, unk_4_Str.c_str());
|
||||
entryStr += StringHelper::Sprintf("\t%s, %s\n", unk_4_Str.c_str(), unk_8_Str.c_str());
|
||||
|
||||
return entryStr;
|
||||
}
|
||||
|
||||
std::string Struct_800A5E28::GetSourceTypeName() const
|
||||
{
|
||||
return "Struct_800A5E28";
|
||||
}
|
||||
|
||||
ZResourceType Struct_800A5E28::GetResourceType() const
|
||||
{
|
||||
// TODO
|
||||
return ZResourceType::Error;
|
||||
}
|
||||
|
||||
size_t Struct_800A5E28::GetRawDataSize() const
|
||||
{
|
||||
return 0x0C;
|
||||
}
|
113
tools/ZAPD/ZAPD/OtherStructs/SkinLimbStructs.h
Normal file
113
tools/ZAPD/ZAPD/OtherStructs/SkinLimbStructs.h
Normal file
|
@ -0,0 +1,113 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ZResource.h"
|
||||
|
||||
// TODO: check if more types exists
|
||||
enum class ZLimbSkinType
|
||||
{
|
||||
SkinType_0, // Segment = 0
|
||||
SkinType_4 = 4, // Segment = segmented address // Struct_800A5E28
|
||||
SkinType_5 = 5, // Segment = 0
|
||||
SkinType_DList = 11, // Segment = DList address
|
||||
};
|
||||
|
||||
class Struct_800A57C0 : public ZResource
|
||||
{
|
||||
public:
|
||||
Struct_800A57C0(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
protected:
|
||||
uint16_t unk_0;
|
||||
int16_t unk_2;
|
||||
int16_t unk_4;
|
||||
int8_t unk_6;
|
||||
int8_t unk_7;
|
||||
int8_t unk_8;
|
||||
uint8_t unk_9;
|
||||
};
|
||||
|
||||
class Struct_800A598C_2 : public ZResource
|
||||
{
|
||||
public:
|
||||
Struct_800A598C_2(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
protected:
|
||||
uint8_t unk_0;
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
uint8_t unk_8;
|
||||
};
|
||||
|
||||
class Struct_800A598C : public ZResource
|
||||
{
|
||||
public:
|
||||
Struct_800A598C(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
protected:
|
||||
uint16_t unk_0; // Length of unk_8
|
||||
uint16_t unk_2; // Length of unk_C
|
||||
uint16_t unk_4; // 0 or 1 // Used as an index for unk_C
|
||||
segptr_t unk_8; // Struct_800A57C0*
|
||||
segptr_t unk_C; // Struct_800A598C_2*
|
||||
|
||||
std::vector<Struct_800A57C0> unk_8_arr;
|
||||
std::vector<Struct_800A598C_2> unk_C_arr;
|
||||
};
|
||||
|
||||
class Struct_800A5E28 : public ZResource
|
||||
{
|
||||
public:
|
||||
Struct_800A5E28(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
protected:
|
||||
uint16_t unk_0; // Vtx count
|
||||
uint16_t unk_2; // Length of unk_4
|
||||
segptr_t unk_4; // Struct_800A598C*
|
||||
segptr_t unk_8; // Gfx*
|
||||
|
||||
std::vector<Struct_800A598C> unk_4_arr;
|
||||
// ZDisplayList* unk_8_dlist = nullptr;
|
||||
};
|
|
@ -101,10 +101,9 @@ int (*OutputFormatter::StaticWriter())(const char* buf, int count)
|
|||
return &WriteStatic;
|
||||
}
|
||||
|
||||
OutputFormatter::OutputFormatter(uint32_t tabSize, uint32_t defaultIndent, uint32_t lineLimit)
|
||||
: tabSize{tabSize}, defaultIndent{defaultIndent}, lineLimit{lineLimit}, col{0}, nest{0},
|
||||
nestIndent{defaultIndent}, currentIndent{defaultIndent},
|
||||
wordNests(0), wordP{word}, spaceP{space}
|
||||
OutputFormatter::OutputFormatter(uint32_t tabSize, uint32_t indentation, uint32_t lineLimit)
|
||||
: tabSize{tabSize}, lineLimit{lineLimit}, col{0}, nest{0}, nestIndent{indentation},
|
||||
currentIndent{indentation}, wordNests(0), wordP{word}, spaceP{space}
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ class OutputFormatter
|
|||
{
|
||||
private:
|
||||
const uint32_t tabSize;
|
||||
const uint32_t defaultIndent;
|
||||
const uint32_t lineLimit;
|
||||
|
||||
uint32_t col;
|
||||
|
@ -30,7 +29,7 @@ private:
|
|||
static int WriteStatic(const char* buf, int count);
|
||||
|
||||
public:
|
||||
OutputFormatter(uint32_t tabSize = 4, uint32_t defaultIndent = 4, uint32_t lineLimit = 120);
|
||||
OutputFormatter(uint32_t tabSize = 4, uint32_t indentation = 4, uint32_t lineLimit = 120);
|
||||
|
||||
int (*StaticWriter())(const char* buf, int count); // Must be `int` due to libgfxd
|
||||
|
||||
|
@ -38,4 +37,4 @@ public:
|
|||
int Write(const std::string& buf);
|
||||
|
||||
std::string GetOutput();
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,18 +1,57 @@
|
|||
#include "ZOverlay.h"
|
||||
#include "../Directory.h"
|
||||
#include "../File.h"
|
||||
#include "../Path.h"
|
||||
#include "../StringHelper.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <Utils/Directory.h>
|
||||
#include <Utils/File.h>
|
||||
#include <Utils/Path.h>
|
||||
#include <Utils/StringHelper.h>
|
||||
#include "Globals.h"
|
||||
|
||||
using namespace ELFIO;
|
||||
|
||||
const char* RelocationEntry::GetSectionName() const
|
||||
{
|
||||
switch (sectionType)
|
||||
{
|
||||
case SectionType::Text:
|
||||
return ".text";
|
||||
case SectionType::Data:
|
||||
return ".data";
|
||||
case SectionType::RoData:
|
||||
return ".rodata";
|
||||
case SectionType::Bss:
|
||||
return ".bss";
|
||||
case SectionType::ERROR:
|
||||
return ".ERROR";
|
||||
}
|
||||
assert(!"Oh no :c");
|
||||
}
|
||||
|
||||
const char* RelocationEntry::GetRelocTypeName() const
|
||||
{
|
||||
switch (relocationType)
|
||||
{
|
||||
case RelocationType::R_MIPS_32:
|
||||
return "R_MIPS_32";
|
||||
case RelocationType::R_MIPS_26:
|
||||
return "R_MIPS_26";
|
||||
case RelocationType::R_MIPS_HI16:
|
||||
return "R_MIPS_HI16";
|
||||
case RelocationType::R_MIPS_LO16:
|
||||
return "R_MIPS_LO16";
|
||||
}
|
||||
assert(!"Oh no :c");
|
||||
}
|
||||
|
||||
ZOverlay::ZOverlay()
|
||||
{
|
||||
name = "";
|
||||
entries = std::vector<RelocationEntry*>();
|
||||
}
|
||||
|
||||
ZOverlay::ZOverlay(std::string nName) : ZOverlay()
|
||||
ZOverlay::ZOverlay(const std::string& nName) : ZOverlay()
|
||||
{
|
||||
name = nName;
|
||||
}
|
||||
|
@ -25,15 +64,22 @@ ZOverlay::~ZOverlay()
|
|||
entries.clear();
|
||||
}
|
||||
|
||||
ZOverlay* ZOverlay::FromBuild(std::string buildPath, std::string cfgFolderPath)
|
||||
static const std::unordered_set<std::string> sRelSections = {
|
||||
".rel.text",
|
||||
".rel.data",
|
||||
".rel.rodata",
|
||||
};
|
||||
static const std::unordered_set<std::string> sSections = {
|
||||
".text", ".data", ".symtab", ".rodata", ".rodata.str1.4", ".rodata.cst4", ".rodata.cst8",
|
||||
};
|
||||
|
||||
ZOverlay* ZOverlay::FromBuild(fs::path buildPath, fs::path cfgFolderPath)
|
||||
{
|
||||
std::string cfgText = File::ReadAllText(cfgFolderPath + "/overlay.cfg");
|
||||
std::string cfgText = File::ReadAllText(cfgFolderPath / "overlay.cfg");
|
||||
std::vector<std::string> cfgLines = StringHelper::Split(cfgText, "\n");
|
||||
|
||||
ZOverlay* ovl = new ZOverlay(StringHelper::Strip(cfgLines[0], "\r"));
|
||||
|
||||
std::vector<std::string> relSections = {".rel.text", ".rel.data", ".rel.rodata"};
|
||||
std::vector<std::string> sections = {".text", ".data", ".rodata"};
|
||||
ovl->cfgLines = cfgLines;
|
||||
|
||||
int32_t sectionOffs[5] = {0};
|
||||
std::vector<RelocationEntry*> textRelocs;
|
||||
|
@ -44,8 +90,7 @@ ZOverlay* ZOverlay::FromBuild(std::string buildPath, std::string cfgFolderPath)
|
|||
std::vector<elfio*> readers;
|
||||
for (size_t i = 1; i < cfgLines.size(); i++)
|
||||
{
|
||||
std::string elfPath =
|
||||
buildPath + "/" + cfgLines[i].substr(0, cfgLines[i].size() - 2) + ".o";
|
||||
std::string elfPath = buildPath / (cfgLines[i].substr(0, cfgLines[i].size() - 2) + ".o");
|
||||
elfio* reader = new elfio();
|
||||
|
||||
if (!reader->load(elfPath))
|
||||
|
@ -62,102 +107,119 @@ ZOverlay* ZOverlay::FromBuild(std::string buildPath, std::string cfgFolderPath)
|
|||
readers.push_back(reader);
|
||||
}
|
||||
|
||||
for (auto curReader : readers)
|
||||
for (size_t curReaderId = 0; curReaderId < readers.size(); curReaderId++)
|
||||
{
|
||||
auto& curReader = readers[curReaderId];
|
||||
|
||||
Elf_Half sec_num = curReader->sections.size();
|
||||
for (int32_t i = 0; i < sec_num; i++)
|
||||
{
|
||||
section* pSec = curReader->sections[i];
|
||||
|
||||
if (pSec->get_type() == SHT_REL && std::find(relSections.begin(), relSections.end(),
|
||||
pSec->get_name()) != relSections.end())
|
||||
if (pSec->get_type() != SHT_REL ||
|
||||
sRelSections.find(pSec->get_name()) == sRelSections.end())
|
||||
{
|
||||
SectionType sectionType = GetSectionTypeFromStr(pSec->get_name());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sectionType == SectionType::ERROR)
|
||||
fprintf(stderr, "WARNING: One of the section types returned ERROR\n");
|
||||
symbol_section_accessor currentSymbols(*curReader,
|
||||
curReader->sections[(Elf_Half)pSec->get_link()]);
|
||||
|
||||
relocation_section_accessor relocs(*curReader, pSec);
|
||||
for (Elf_Xword j = 0; j < relocs.get_entries_num(); j++)
|
||||
SectionType sectionType = GetSectionTypeFromStr(pSec->get_name());
|
||||
|
||||
if (sectionType == SectionType::ERROR)
|
||||
fprintf(stderr, "WARNING: One of the section types returned ERROR\n");
|
||||
|
||||
relocation_section_accessor relocs(*curReader, pSec);
|
||||
for (Elf_Xword j = 0; j < relocs.get_entries_num(); j++)
|
||||
{
|
||||
Elf64_Addr offset = 0;
|
||||
Elf_Word symbol = 0;
|
||||
Elf_Word type = 0;
|
||||
{
|
||||
Elf64_Addr offset = 0;
|
||||
Elf_Word symbol = 0;
|
||||
Elf_Word type = 0;
|
||||
Elf_Sxword addend = 0;
|
||||
relocs.get_entry(j, offset, symbol, type, addend);
|
||||
}
|
||||
|
||||
std::string curSymName;
|
||||
Elf_Half curSymShndx = SHN_UNDEF;
|
||||
{
|
||||
Elf64_Addr value;
|
||||
Elf_Xword size;
|
||||
unsigned char bind;
|
||||
unsigned char type;
|
||||
unsigned char other;
|
||||
currentSymbols.get_symbol(symbol, curSymName, value, size, bind, type,
|
||||
curSymShndx, other);
|
||||
}
|
||||
|
||||
// check symbols outside the elf but within the overlay
|
||||
if (curSymShndx == SHN_UNDEF)
|
||||
{
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG)
|
||||
{
|
||||
Elf_Sxword addend = 0;
|
||||
relocs.get_entry(j, offset, symbol, type, addend);
|
||||
printf("Symbol '%s' doesn't exist in current .o file (%s). Searching...\n",
|
||||
curSymName.c_str(), cfgLines[curReaderId + 1].c_str());
|
||||
}
|
||||
|
||||
std::string curSymName;
|
||||
Elf_Half curSymShndx = SHN_UNDEF;
|
||||
for (size_t readerId = 0; readerId < readers.size(); readerId++)
|
||||
{
|
||||
symbol_section_accessor symbols(
|
||||
*curReader, curReader->sections[(Elf_Half)pSec->get_link()]);
|
||||
Elf64_Addr value;
|
||||
Elf_Xword size;
|
||||
unsigned char bind;
|
||||
unsigned char type;
|
||||
unsigned char other;
|
||||
symbols.get_symbol(symbol, curSymName, value, size, bind, type, curSymShndx,
|
||||
other);
|
||||
}
|
||||
auto& reader = readers[readerId];
|
||||
|
||||
// check symbols outside the elf but within the overlay
|
||||
if (curSymShndx == SHN_UNDEF)
|
||||
{
|
||||
for (auto reader : readers)
|
||||
if (curSymShndx != SHN_UNDEF)
|
||||
break;
|
||||
|
||||
if (reader == curReader)
|
||||
continue;
|
||||
|
||||
auto sectionData = reader->sections[(Elf_Half)pSec->get_link()];
|
||||
curSymShndx =
|
||||
ovl->FindSymbolInSection(curSymName, sectionData, *reader, readerId);
|
||||
if (curSymShndx != SHN_UNDEF)
|
||||
break;
|
||||
|
||||
if (Globals::Instance->gccCompat)
|
||||
{
|
||||
if (curSymShndx != SHN_UNDEF)
|
||||
break;
|
||||
|
||||
if (reader == curReader)
|
||||
continue;
|
||||
|
||||
auto sectionData = reader->sections[(Elf_Half)pSec->get_link()];
|
||||
|
||||
if (sectionData == nullptr)
|
||||
continue;
|
||||
|
||||
symbol_section_accessor symbols(*reader, sectionData);
|
||||
|
||||
for (Elf_Xword symIdx = 0; symIdx < symbols.get_symbols_num(); symIdx++)
|
||||
// Symbol wasn't found, try checking every section
|
||||
Elf_Half sec_num = reader->sections.size();
|
||||
for (int32_t otherSectionIdx = 0; otherSectionIdx < sec_num;
|
||||
otherSectionIdx++)
|
||||
{
|
||||
Elf_Half shndx = SHN_UNDEF;
|
||||
Elf64_Addr value;
|
||||
std::string name;
|
||||
Elf_Xword size;
|
||||
unsigned char bind;
|
||||
unsigned char type;
|
||||
unsigned char other;
|
||||
|
||||
symbols.get_symbol(symIdx, name, value, size, bind, type, shndx,
|
||||
other);
|
||||
|
||||
if (name == curSymName)
|
||||
if (curSymShndx != SHN_UNDEF)
|
||||
{
|
||||
curSymShndx = shndx;
|
||||
break;
|
||||
}
|
||||
|
||||
auto sectionDataIter = reader->sections[otherSectionIdx];
|
||||
|
||||
curSymShndx = ovl->FindSymbolInSection(curSymName, sectionDataIter,
|
||||
*reader, readerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (curSymShndx != SHN_UNDEF)
|
||||
if (curSymShndx != SHN_UNDEF)
|
||||
{
|
||||
RelocationType typeConverted = (RelocationType)type;
|
||||
offset += sectionOffs[static_cast<size_t>(sectionType)];
|
||||
|
||||
RelocationEntry* reloc =
|
||||
new RelocationEntry(sectionType, typeConverted, offset);
|
||||
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG)
|
||||
{
|
||||
RelocationType typeConverted = (RelocationType)type;
|
||||
offset += sectionOffs[sectionType];
|
||||
|
||||
RelocationEntry* reloc =
|
||||
new RelocationEntry(sectionType, typeConverted, offset);
|
||||
|
||||
// this is to keep the correct reloc entry order
|
||||
if (sectionType == SectionType::Text)
|
||||
textRelocs.push_back(reloc);
|
||||
if (sectionType == SectionType::Data)
|
||||
dataRelocs.push_back(reloc);
|
||||
if (sectionType == SectionType::RoData)
|
||||
rodataRelocs.push_back(reloc);
|
||||
printf(".word 0x%08X # %s %s 0x%04X\n", reloc->CalcRelocationWord(),
|
||||
reloc->GetSectionName(), reloc->GetRelocTypeName(), reloc->offset);
|
||||
}
|
||||
|
||||
// this is to keep the correct reloc entry order
|
||||
if (sectionType == SectionType::Text)
|
||||
textRelocs.push_back(reloc);
|
||||
if (sectionType == SectionType::Data)
|
||||
dataRelocs.push_back(reloc);
|
||||
if (sectionType == SectionType::RoData)
|
||||
rodataRelocs.push_back(reloc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -167,20 +229,18 @@ ZOverlay* ZOverlay::FromBuild(std::string buildPath, std::string cfgFolderPath)
|
|||
{
|
||||
section* pSec = curReader->sections[i];
|
||||
if (pSec->get_type() == SHT_PROGBITS &&
|
||||
std::find(sections.begin(), sections.end(), pSec->get_name()) != sections.end())
|
||||
sSections.find(pSec->get_name()) != sSections.end())
|
||||
{
|
||||
SectionType sectionType = GetSectionTypeFromStr(pSec->get_name());
|
||||
sectionOffs[sectionType] += pSec->get_size();
|
||||
sectionOffs[static_cast<size_t>(sectionType)] += pSec->get_size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto reloc : textRelocs)
|
||||
ovl->entries.push_back(reloc);
|
||||
for (auto reloc : dataRelocs)
|
||||
ovl->entries.push_back(reloc);
|
||||
for (auto reloc : rodataRelocs)
|
||||
ovl->entries.push_back(reloc);
|
||||
ovl->entries.reserve(textRelocs.size() + dataRelocs.size() + rodataRelocs.size());
|
||||
ovl->entries.insert(ovl->entries.end(), textRelocs.begin(), textRelocs.end());
|
||||
ovl->entries.insert(ovl->entries.end(), dataRelocs.begin(), dataRelocs.end());
|
||||
ovl->entries.insert(ovl->entries.end(), rodataRelocs.begin(), rodataRelocs.end());
|
||||
|
||||
for (auto r : readers)
|
||||
delete r;
|
||||
|
@ -189,23 +249,27 @@ ZOverlay* ZOverlay::FromBuild(std::string buildPath, std::string cfgFolderPath)
|
|||
return ovl;
|
||||
}
|
||||
|
||||
std::string ZOverlay::GetSourceOutputCode(const std::string& prefix)
|
||||
std::string ZOverlay::GetSourceOutputCode([[maybe_unused]] const std::string& prefix)
|
||||
{
|
||||
std::string output = "";
|
||||
std::string output;
|
||||
|
||||
output += ".section .ovl\n";
|
||||
|
||||
output += StringHelper::Sprintf("# %sOverlayInfo\n", name.c_str());
|
||||
output += StringHelper::Sprintf(".word _%sSegmentTextSize\n", name.c_str());
|
||||
output += StringHelper::Sprintf(".word _%sSegmentDataSize\n", name.c_str());
|
||||
output += StringHelper::Sprintf(".word _%sSegmentRoDataSize\n", name.c_str());
|
||||
output += StringHelper::Sprintf(".word _%sSegmentBssSize\n", name.c_str());
|
||||
output += "\n";
|
||||
|
||||
output += StringHelper::Sprintf(".word %i\n", entries.size());
|
||||
output += StringHelper::Sprintf(".word %i # reloc_count\n", entries.size());
|
||||
|
||||
for (size_t i = 0; i < entries.size(); i++)
|
||||
{
|
||||
RelocationEntry* reloc = entries[i];
|
||||
output += StringHelper::Sprintf(".word 0x%08X\n", reloc->CalcRelocationWord());
|
||||
output += StringHelper::Sprintf(".word 0x%08X # %s %s 0x%04X\n",
|
||||
reloc->CalcRelocationWord(), reloc->GetSectionName(),
|
||||
reloc->GetRelocTypeName(), reloc->offset);
|
||||
}
|
||||
|
||||
size_t offset = (entries.size() * 4) + 20;
|
||||
|
@ -216,11 +280,13 @@ std::string ZOverlay::GetSourceOutputCode(const std::string& prefix)
|
|||
offset += 4;
|
||||
}
|
||||
|
||||
output += StringHelper::Sprintf(".word 0x%08X\n", offset + 4);
|
||||
output += "\n";
|
||||
output +=
|
||||
StringHelper::Sprintf(".word 0x%08X # %sOverlayInfoOffset\n", offset + 4, name.c_str());
|
||||
return output;
|
||||
}
|
||||
|
||||
SectionType ZOverlay::GetSectionTypeFromStr(std::string sectionName)
|
||||
SectionType ZOverlay::GetSectionTypeFromStr(const std::string& sectionName)
|
||||
{
|
||||
if (sectionName == ".rel.text" || sectionName == ".text")
|
||||
return SectionType::Text;
|
||||
|
@ -234,3 +300,50 @@ SectionType ZOverlay::GetSectionTypeFromStr(std::string sectionName)
|
|||
|
||||
return SectionType::ERROR;
|
||||
}
|
||||
|
||||
ELFIO::Elf_Half ZOverlay::FindSymbolInSection(const std::string& curSymName,
|
||||
ELFIO::section* sectionData, ELFIO::elfio& reader,
|
||||
size_t readerId)
|
||||
{
|
||||
if (sectionData == nullptr)
|
||||
return SHN_UNDEF;
|
||||
|
||||
auto sectionDataName = sectionData->get_name();
|
||||
if (sSections.find(sectionDataName) == sSections.end())
|
||||
return SHN_UNDEF;
|
||||
|
||||
#ifdef DEVELOPMENT
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG)
|
||||
{
|
||||
printf("\t File '%s' section: %s \n", cfgLines[readerId + 1].c_str(),
|
||||
sectionDataName.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
symbol_section_accessor symbols(reader, sectionData);
|
||||
|
||||
Elf_Xword symbolNum = symbols.get_symbols_num();
|
||||
for (Elf_Xword symIdx = 0; symIdx < symbolNum; symIdx++)
|
||||
{
|
||||
Elf_Half shndx = SHN_UNDEF;
|
||||
Elf64_Addr value;
|
||||
std::string name;
|
||||
Elf_Xword size;
|
||||
unsigned char bind;
|
||||
unsigned char type;
|
||||
unsigned char other;
|
||||
|
||||
symbols.get_symbol(symIdx, name, value, size, bind, type, shndx, other);
|
||||
|
||||
if (name == curSymName)
|
||||
{
|
||||
if (Globals::Instance->verbosity >= VerbosityLevel::VERBOSITY_DEBUG)
|
||||
{
|
||||
printf("\t Symbol '%s' found in '%s' '%s' \n", curSymName.c_str(),
|
||||
cfgLines[readerId + 1].c_str(), sectionDataName.c_str());
|
||||
}
|
||||
return shndx;
|
||||
}
|
||||
}
|
||||
return SHN_UNDEF;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <elfio/elfio.hpp>
|
||||
#include "../ZResource.h"
|
||||
#include "Utils/Directory.h"
|
||||
#include "ZResource.h"
|
||||
#include "elfio/elfio.hpp"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
enum SectionType
|
||||
enum class SectionType
|
||||
{
|
||||
Text = 1,
|
||||
Data = 2,
|
||||
|
@ -13,7 +14,7 @@ enum SectionType
|
|||
ERROR = 255
|
||||
};
|
||||
|
||||
enum RelocationType
|
||||
enum class RelocationType
|
||||
{
|
||||
R_MIPS_32 = 2,
|
||||
R_MIPS_26 = 4,
|
||||
|
@ -39,12 +40,15 @@ public:
|
|||
{
|
||||
uint32_t relocationWord = 0;
|
||||
|
||||
relocationWord |= sectionType << 30;
|
||||
relocationWord |= relocationType << 24;
|
||||
relocationWord |= static_cast<uint32_t>(sectionType) << 30;
|
||||
relocationWord |= static_cast<uint32_t>(relocationType) << 24;
|
||||
relocationWord |= offset;
|
||||
|
||||
return relocationWord;
|
||||
}
|
||||
|
||||
const char* GetSectionName() const;
|
||||
const char* GetRelocTypeName() const;
|
||||
};
|
||||
|
||||
class ZOverlay
|
||||
|
@ -52,16 +56,20 @@ class ZOverlay
|
|||
public:
|
||||
std::string name;
|
||||
|
||||
ZOverlay(std::string nName);
|
||||
ZOverlay(const std::string& nName);
|
||||
~ZOverlay();
|
||||
static ZOverlay* FromBuild(std::string buildPath, std::string cfgFolderPath);
|
||||
static ZOverlay* FromBuild(fs::path buildPath, fs::path cfgFolderPath);
|
||||
std::string GetSourceOutputCode(const std::string& prefix);
|
||||
|
||||
private:
|
||||
std::vector<RelocationEntry*> entries;
|
||||
std::vector<std::string> cfgLines;
|
||||
|
||||
ZOverlay();
|
||||
|
||||
static SectionType GetSectionTypeFromStr(std::string sectionName);
|
||||
static SectionType GetSectionTypeFromStr(const std::string& sectionName);
|
||||
// static std::string GetOverlayNameFromElf(ELFIO::elfio& reader);
|
||||
|
||||
ELFIO::Elf_Half FindSymbolInSection(const std::string& curSymName, ELFIO::section* sectionData,
|
||||
ELFIO::elfio& reader, size_t readerId);
|
||||
};
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "StringHelper.h"
|
||||
|
||||
#if __has_include(<filesystem>)
|
||||
#include <filesystem>
|
||||
namespace fs = std::filesystem;
|
||||
#else
|
||||
#include <experimental/filesystem>
|
||||
namespace fs = std::experimental::filesystem;
|
||||
#endif
|
||||
|
||||
class Path
|
||||
{
|
||||
public:
|
||||
static std::string GetFileName(const std::string& input)
|
||||
{
|
||||
std::vector<std::string> split = StringHelper::Split(input, "/");
|
||||
return split[split.size() - 1];
|
||||
};
|
||||
|
||||
static std::string GetFileNameWithoutExtension(const std::string& input)
|
||||
{
|
||||
std::vector<std::string> split = StringHelper::Split(input, "/");
|
||||
return split[split.size() - 1].substr(0, split[split.size() - 1].find_last_of("."));
|
||||
};
|
||||
|
||||
static std::string GetFileNameExtension(const std::string& input)
|
||||
{
|
||||
return input.substr(input.find_last_of("."), input.length());
|
||||
};
|
||||
|
||||
static std::string GetPath(const std::string& input)
|
||||
{
|
||||
std::vector<std::string> split = StringHelper::Split(input, "/");
|
||||
std::string output = "";
|
||||
|
||||
for (std::string str : split)
|
||||
{
|
||||
if (str.find_last_of(".") == std::string::npos)
|
||||
output += str + "/";
|
||||
}
|
||||
|
||||
return output;
|
||||
};
|
||||
|
||||
static std::string GetDirectoryName(const fs::path& path)
|
||||
{
|
||||
return path.parent_path().u8string();
|
||||
};
|
||||
};
|
|
@ -71,12 +71,16 @@
|
|||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<IncludePath>$(SolutionDir)lib\tinyxml2;$(SolutionDir)lib\libgfxd;$(SolutionDir)lib\elfio;$(SolutionDir)lib\assimp\include;$(SolutionDir)lib\stb;$(ProjectDir);$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)lib\libgfxd;$(SolutionDir)lib\assimp-built;$(LibraryPath)</LibraryPath>
|
||||
<LibraryPath>$(SolutionDir)lib\libgfxd;$(SolutionDir)x64\Debug;$(SolutionDir)packages\libpng.1.6.28.1\build\native\lib\x64\v140\dynamic\Debug;$(LibraryPath)</LibraryPath>
|
||||
<IncludePath>$(SolutionDir)ZAPDUtils;$(SolutionDir)lib\tinyxml2;$(SolutionDir)lib\libgfxd;$(SolutionDir)lib\elfio;$(SolutionDir)lib\stb;$(ProjectDir);$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IncludePath>$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<IncludePath>$(SolutionDir)ZAPD\lib\tinyxml2;$(SolutionDir)ZAPD\lib\libgfxd;$(SolutionDir)ZAPD\lib\elfio;$(SolutionDir)ZAPD\lib\stb;$(ProjectDir);$(IncludePath)</IncludePath>
|
||||
<LibraryPath>$(SolutionDir)ZAPD\lib\libgfxd;$(SolutionDir)x64\Debug;$(SolutionDir)packages\libpng.1.6.28.1\build\native\lib\x64\v140\dynamic\Debug;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
|
@ -84,6 +88,8 @@
|
|||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<Profile>true</Profile>
|
||||
|
@ -96,13 +102,13 @@
|
|||
<SDLCheck>true</SDLCheck>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;USE_ASSIMP;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<LanguageStandard_C>stdc11</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<Profile>true</Profile>
|
||||
<AdditionalDependencies>assimp-vc142-mt.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalDependencies>libpng16.lib;ZAPDUtils.lib;/WHOLEARCHIVE:ExporterExample.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>cd ..
|
||||
|
@ -148,10 +154,9 @@ python3 ZAPD/genbuildinfo.py</Command>
|
|||
<ClCompile Include="..\lib\libgfxd\uc_f3dex2.c" />
|
||||
<ClCompile Include="..\lib\libgfxd\uc_f3dexb.c" />
|
||||
<ClCompile Include="..\lib\tinyxml2\tinyxml2.cpp" />
|
||||
<ClCompile Include="Declaration.cpp" />
|
||||
<ClCompile Include="Globals.cpp" />
|
||||
<ClCompile Include="HighLevel\HLAnimationIntermediette.cpp" />
|
||||
<ClCompile Include="HighLevel\HLModelIntermediette.cpp" />
|
||||
<ClCompile Include="HighLevel\HLTexture.cpp" />
|
||||
<ClCompile Include="ImageBackend.cpp" />
|
||||
<ClCompile Include="Main.cpp" />
|
||||
<ClCompile Include="OutputFormatter.cpp" />
|
||||
<ClCompile Include="Overlays\ZOverlay.cpp" />
|
||||
|
@ -160,8 +165,9 @@ python3 ZAPD/genbuildinfo.py</Command>
|
|||
<ClCompile Include="ZCutsceneMM.cpp" />
|
||||
<ClCompile Include="ZLimb.cpp" />
|
||||
<ClCompile Include="ZMtx.cpp" />
|
||||
<ClCompile Include="ZPath.cpp" />
|
||||
<ClCompile Include="ZRoom\Commands\SetActorCutsceneList.cpp" />
|
||||
<ClCompile Include="ZRoom\Commands\SetAnimatedTextureList.cpp" />
|
||||
<ClCompile Include="ZRoom\Commands\SetAnimatedMaterialList.cpp" />
|
||||
<ClCompile Include="ZRoom\Commands\SetCsCamera.cpp" />
|
||||
<ClCompile Include="ZRoom\Commands\SetMinimapChests.cpp" />
|
||||
<ClCompile Include="ZRoom\Commands\SetMinimapList.cpp" />
|
||||
|
@ -204,6 +210,7 @@ python3 ZAPD/genbuildinfo.py</Command>
|
|||
<ClCompile Include="ZRoom\Commands\ZRoomCommandUnk.cpp" />
|
||||
<ClCompile Include="ZRoom\ZRoom.cpp" />
|
||||
<ClCompile Include="ZRoom\ZRoomCommand.cpp" />
|
||||
<ClCompile Include="ZString.cpp" />
|
||||
<ClCompile Include="ZSymbol.cpp" />
|
||||
<ClCompile Include="ZTexture.cpp" />
|
||||
<ClCompile Include="ZVector.cpp" />
|
||||
|
@ -222,29 +229,18 @@ python3 ZAPD/genbuildinfo.py</Command>
|
|||
<ClInclude Include="..\lib\elfio\elfio\elfio_symbols.hpp" />
|
||||
<ClInclude Include="..\lib\elfio\elfio\elfio_utils.hpp" />
|
||||
<ClInclude Include="..\lib\elfio\elfio\elf_types.hpp" />
|
||||
<ClInclude Include="..\lib\json\include\nlohmann\json.hpp" />
|
||||
<ClInclude Include="..\lib\libgfxd\gbi.h" />
|
||||
<ClInclude Include="..\lib\libgfxd\gfxd.h" />
|
||||
<ClInclude Include="..\lib\libgfxd\priv.h" />
|
||||
<ClInclude Include="..\lib\stb\stb_image.h" />
|
||||
<ClInclude Include="..\lib\stb\stb_image_write.h" />
|
||||
<ClInclude Include="..\lib\stb\tinyxml2.h" />
|
||||
<ClInclude Include="..\lib\tinygtlf\tiny_gltf.h" />
|
||||
<ClInclude Include="BitConverter.h" />
|
||||
<ClInclude Include="CRC32.h" />
|
||||
<ClInclude Include="Directory.h" />
|
||||
<ClInclude Include="File.h" />
|
||||
<ClInclude Include="Declaration.h" />
|
||||
<ClInclude Include="Globals.h" />
|
||||
<ClInclude Include="HighLevel\HLAnimation.h" />
|
||||
<ClInclude Include="HighLevel\HLAnimationIntermediette.h" />
|
||||
<ClInclude Include="HighLevel\HLFileIntermediette.h" />
|
||||
<ClInclude Include="HighLevel\HLModelIntermediette.h" />
|
||||
<ClInclude Include="HighLevel\HLTexture.h" />
|
||||
<ClInclude Include="ImageBackend.h" />
|
||||
<ClInclude Include="OutputFormatter.h" />
|
||||
<ClInclude Include="Overlays\ZOverlay.h" />
|
||||
<ClInclude Include="Path.h" />
|
||||
<ClInclude Include="StringHelper.h" />
|
||||
<ClInclude Include="Vec3s.h" />
|
||||
<ClInclude Include="ZAnimation.h" />
|
||||
<ClInclude Include="ZArray.h" />
|
||||
<ClInclude Include="ZBackground.h" />
|
||||
|
@ -256,8 +252,9 @@ python3 ZAPD/genbuildinfo.py</Command>
|
|||
<ClInclude Include="ZFile.h" />
|
||||
<ClInclude Include="ZLimb.h" />
|
||||
<ClInclude Include="ZMtx.h" />
|
||||
<ClInclude Include="ZPath.h" />
|
||||
<ClInclude Include="ZRoom\Commands\SetActorCutsceneList.h" />
|
||||
<ClInclude Include="ZRoom\Commands\SetAnimatedTextureList.h" />
|
||||
<ClInclude Include="ZRoom\Commands\SetAnimatedMaterialList.h" />
|
||||
<ClInclude Include="ZRoom\Commands\SetCsCamera.h" />
|
||||
<ClInclude Include="ZRoom\Commands\SetMinimapChests.h" />
|
||||
<ClInclude Include="ZRoom\Commands\SetMinimapList.h" />
|
||||
|
@ -266,7 +263,6 @@ python3 ZAPD/genbuildinfo.py</Command>
|
|||
<ClInclude Include="ZScalar.h" />
|
||||
<ClInclude Include="ZSkeleton.h" />
|
||||
<ClInclude Include="ZResource.h" />
|
||||
<ClInclude Include="ZRoom\ActorList.h" />
|
||||
<ClInclude Include="ZRoom\Commands\EndMarker.h" />
|
||||
<ClInclude Include="ZRoom\Commands\SetActorList.h" />
|
||||
<ClInclude Include="ZRoom\Commands\SetAlternateHeaders.h" />
|
||||
|
@ -293,9 +289,9 @@ python3 ZAPD/genbuildinfo.py</Command>
|
|||
<ClInclude Include="ZRoom\Commands\SetWind.h" />
|
||||
<ClInclude Include="ZRoom\Commands\Unused09.h" />
|
||||
<ClInclude Include="ZRoom\Commands\ZRoomCommandUnk.h" />
|
||||
<ClInclude Include="ZRoom\ObjectList.h" />
|
||||
<ClInclude Include="ZRoom\ZRoom.h" />
|
||||
<ClInclude Include="ZRoom\ZRoomCommand.h" />
|
||||
<ClInclude Include="ZString.h" />
|
||||
<ClInclude Include="ZSymbol.h" />
|
||||
<ClInclude Include="ZTexture.h" />
|
||||
<ClInclude Include="ZVector.h" />
|
||||
|
@ -307,10 +303,22 @@ python3 ZAPD/genbuildinfo.py</Command>
|
|||
</Text>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CopyFileToFolders Include="..\lib\assimp-built\assimp-vc142-mt.dll">
|
||||
<FileType>Document</FileType>
|
||||
</CopyFileToFolders>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
<Import Project="..\packages\libpng.redist.1.6.28.1\build\native\libpng.redist.targets" Condition="Exists('..\packages\libpng.redist.1.6.28.1\build\native\libpng.redist.targets')" />
|
||||
<Import Project="..\packages\zlib.v120.windesktop.msvcstl.dyn.rt-dyn.1.2.8.8\build\native\zlib.v120.windesktop.msvcstl.dyn.rt-dyn.targets" Condition="Exists('..\packages\zlib.v120.windesktop.msvcstl.dyn.rt-dyn.1.2.8.8\build\native\zlib.v120.windesktop.msvcstl.dyn.rt-dyn.targets')" />
|
||||
<Import Project="..\packages\zlib.v140.windesktop.msvcstl.dyn.rt-dyn.1.2.8.8\build\native\zlib.v140.windesktop.msvcstl.dyn.rt-dyn.targets" Condition="Exists('..\packages\zlib.v140.windesktop.msvcstl.dyn.rt-dyn.1.2.8.8\build\native\zlib.v140.windesktop.msvcstl.dyn.rt-dyn.targets')" />
|
||||
<Import Project="..\packages\libpng.1.6.28.1\build\native\libpng.targets" Condition="Exists('..\packages\libpng.1.6.28.1\build\native\libpng.targets')" />
|
||||
</ImportGroup>
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\libpng.redist.1.6.28.1\build\native\libpng.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\libpng.redist.1.6.28.1\build\native\libpng.redist.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\zlib.v120.windesktop.msvcstl.dyn.rt-dyn.1.2.8.8\build\native\zlib.v120.windesktop.msvcstl.dyn.rt-dyn.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\zlib.v120.windesktop.msvcstl.dyn.rt-dyn.1.2.8.8\build\native\zlib.v120.windesktop.msvcstl.dyn.rt-dyn.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\zlib.v140.windesktop.msvcstl.dyn.rt-dyn.1.2.8.8\build\native\zlib.v140.windesktop.msvcstl.dyn.rt-dyn.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\zlib.v140.windesktop.msvcstl.dyn.rt-dyn.1.2.8.8\build\native\zlib.v140.windesktop.msvcstl.dyn.rt-dyn.targets'))" />
|
||||
<Error Condition="!Exists('..\packages\libpng.1.6.28.1\build\native\libpng.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\libpng.1.6.28.1\build\native\libpng.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
|
@ -40,18 +40,6 @@
|
|||
<Filter Include="Header Files\Z64\ZRoom\Commands">
|
||||
<UniqueIdentifier>{73db0879-6df8-4f6a-8cc2-a1f836e9e796}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\HighLevel">
|
||||
<UniqueIdentifier>{9464ff21-96af-4b7d-a57b-f62bd9b7389a}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\HighLevel\Model">
|
||||
<UniqueIdentifier>{e9865c34-fd69-413c-8cce-3f51331c3503}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\HighLevel">
|
||||
<UniqueIdentifier>{0f9980bb-ae46-4891-a39e-275bf255f010}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\HighLevel\Room">
|
||||
<UniqueIdentifier>{11dbd8e6-d97a-42a5-b40c-e1350389544d}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Libraries\fbx">
|
||||
<UniqueIdentifier>{be9a5be0-ec6a-4200-8e39-bb58c7da7aa8}</UniqueIdentifier>
|
||||
</Filter>
|
||||
|
@ -174,15 +162,6 @@
|
|||
<ClCompile Include="Overlays\ZOverlay.cpp">
|
||||
<Filter>Source Files\Z64</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="HighLevel\HLAnimationIntermediette.cpp">
|
||||
<Filter>Source Files\HighLevel</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="HighLevel\HLModelIntermediette.cpp">
|
||||
<Filter>Source Files\HighLevel</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="HighLevel\HLTexture.cpp">
|
||||
<Filter>Source Files\HighLevel</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ZSkeleton.cpp">
|
||||
<Filter>Source Files\Z64</Filter>
|
||||
</ClCompile>
|
||||
|
@ -249,9 +228,6 @@
|
|||
<ClCompile Include="ZRoom\Commands\SetActorCutsceneList.cpp">
|
||||
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ZRoom\Commands\SetAnimatedTextureList.cpp">
|
||||
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ZRoom\Commands\SetCsCamera.cpp">
|
||||
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClCompile>
|
||||
|
@ -267,17 +243,23 @@
|
|||
<ClCompile Include="ZBackground.cpp">
|
||||
<Filter>Source Files\Z64</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ZRoom\Commands\SetAnimatedMaterialList.cpp">
|
||||
<Filter>Source Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ZPath.cpp">
|
||||
<Filter>Source Files\Z64</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Declaration.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ImageBackend.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ZString.cpp">
|
||||
<Filter>Source Files\Z64</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Path.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="File.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Directory.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZRoom\ZRoom.h">
|
||||
<Filter>Header Files\Z64\ZRoom</Filter>
|
||||
</ClInclude>
|
||||
|
@ -296,9 +278,6 @@
|
|||
<ClInclude Include="ZRoom\Commands\SetTimeSettings.h">
|
||||
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="BitConverter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZRoom\Commands\SetSpecialObjects.h">
|
||||
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClInclude>
|
||||
|
@ -359,9 +338,6 @@
|
|||
<ClInclude Include="..\lib\elfio\elfio\elfio_utils.hpp">
|
||||
<Filter>Header Files\Libraries\elfio</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="StringHelper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Globals.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -389,12 +365,6 @@
|
|||
<ClInclude Include="ZRoom\Commands\Unused09.h">
|
||||
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZRoom\ObjectList.h">
|
||||
<Filter>Header Files\Z64\ZRoom</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZRoom\ActorList.h">
|
||||
<Filter>Header Files\Z64\ZRoom</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZRoom\Commands\SetLightingSettings.h">
|
||||
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClInclude>
|
||||
|
@ -407,21 +377,12 @@
|
|||
<ClInclude Include="ZRoom\Commands\SetCutscenes.h">
|
||||
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Vec3s.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\lib\json\include\nlohmann\json.hpp">
|
||||
<Filter>Header Files\Libraries</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\lib\stb\stb_image.h">
|
||||
<Filter>Header Files\Libraries</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\lib\stb\stb_image_write.h">
|
||||
<Filter>Header Files\Libraries</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\lib\tinygtlf\tiny_gltf.h">
|
||||
<Filter>Header Files\Libraries</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Overlays\ZOverlay.h">
|
||||
<Filter>Header Files\Z64</Filter>
|
||||
</ClInclude>
|
||||
|
@ -446,24 +407,9 @@
|
|||
<ClInclude Include="ZResource.h">
|
||||
<Filter>Header Files\Z64</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="HighLevel\HLTexture.h">
|
||||
<Filter>Header Files\HighLevel</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="HighLevel\HLAnimation.h">
|
||||
<Filter>Header Files\HighLevel</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="HighLevel\HLAnimationIntermediette.h">
|
||||
<Filter>Header Files\HighLevel</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="HighLevel\HLModelIntermediette.h">
|
||||
<Filter>Header Files\HighLevel</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZSkeleton.h">
|
||||
<Filter>Header Files\Z64</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="HighLevel\HLFileIntermediette.h">
|
||||
<Filter>Header Files\HighLevel</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZRoom\Commands\SetLightList.h">
|
||||
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClInclude>
|
||||
|
@ -521,9 +467,6 @@
|
|||
<ClInclude Include="ZRoom\Commands\Unused1D.h">
|
||||
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZRoom\Commands\SetAnimatedTextureList.h">
|
||||
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZRoom\Commands\SetCsCamera.h">
|
||||
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClInclude>
|
||||
|
@ -539,6 +482,21 @@
|
|||
<ClInclude Include="ZBackground.h">
|
||||
<Filter>Header Files\Z64</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZRoom\Commands\SetAnimatedMaterialList.h">
|
||||
<Filter>Header Files\Z64\ZRoom\Commands</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ImageBackend.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZPath.h">
|
||||
<Filter>Header Files\Z64</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Declaration.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ZString.h">
|
||||
<Filter>Header Files\Z64</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\SymbolMap_OoTMqDbg.txt">
|
||||
|
@ -546,8 +504,6 @@
|
|||
</Text>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CopyFileToFolders Include="..\lib\assimp-built\assimp-vc142-mt.dll">
|
||||
<Filter>Resource Files</Filter>
|
||||
</CopyFileToFolders>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -1,10 +1,11 @@
|
|||
#include "ZAnimation.h"
|
||||
|
||||
#include <utility>
|
||||
#include "BitConverter.h"
|
||||
#include "File.h"
|
||||
|
||||
#include "Globals.h"
|
||||
#include "HighLevel/HLAnimationIntermediette.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/File.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
REGISTER_ZFILENODE(Animation, ZNormalAnimation);
|
||||
|
@ -24,85 +25,15 @@ void ZAnimation::ParseRawData()
|
|||
frameCount = BitConverter::ToInt16BE(parent->GetRawData(), rawDataIndex + 0);
|
||||
}
|
||||
|
||||
void ZAnimation::Save(const fs::path& outFolder)
|
||||
{
|
||||
if (Globals::Instance->testMode)
|
||||
{
|
||||
HLAnimationIntermediette* anim = HLAnimationIntermediette::FromZAnimation(this);
|
||||
std::string xml = anim->OutputXML();
|
||||
File::WriteAllText(outFolder / (name + ".anmi"), xml);
|
||||
|
||||
delete anim;
|
||||
}
|
||||
}
|
||||
|
||||
std::string ZAnimation::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
ZResourceType ZAnimation::GetResourceType() const
|
||||
{
|
||||
return ZResourceType::Animation;
|
||||
}
|
||||
|
||||
/* ZNormalAnimation */
|
||||
|
||||
ZNormalAnimation::ZNormalAnimation(ZFile* nParent) : ZAnimation(nParent)
|
||||
{
|
||||
rotationValues = std::vector<uint16_t>();
|
||||
rotationIndices = std::vector<RotationIndex>();
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
std::string ZNormalAnimation::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
if (parent != nullptr)
|
||||
{
|
||||
std::string defaultPrefix = name.c_str();
|
||||
defaultPrefix.replace(0, 1, "s"); // replace g prefix with s for local variables
|
||||
|
||||
std::string headerStr = StringHelper::Sprintf("\n\t{ %i },\n", frameCount);
|
||||
headerStr += StringHelper::Sprintf("\t%sFrameData,\n", defaultPrefix.c_str());
|
||||
headerStr += StringHelper::Sprintf("\t%sJointIndices,\n", defaultPrefix.c_str());
|
||||
headerStr += StringHelper::Sprintf("\t%i\n", limit);
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
|
||||
GetSourceTypeName(), StringHelper::Sprintf("%s", name.c_str()),
|
||||
headerStr);
|
||||
|
||||
std::string indicesStr = "";
|
||||
std::string valuesStr = " ";
|
||||
const uint8_t lineLength = 14;
|
||||
const uint8_t offset = 0;
|
||||
|
||||
for (size_t i = 0; i < rotationValues.size(); i++)
|
||||
{
|
||||
valuesStr += StringHelper::Sprintf("0x%04X, ", rotationValues[i]);
|
||||
|
||||
if ((i - offset + 1) % lineLength == 0)
|
||||
valuesStr += "\n ";
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < rotationIndices.size(); i++)
|
||||
{
|
||||
indicesStr +=
|
||||
StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X },", rotationIndices[i].x,
|
||||
rotationIndices[i].y, rotationIndices[i].z);
|
||||
|
||||
if (i != (rotationIndices.size() - 1))
|
||||
indicesStr += "\n";
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(rotationValuesSeg, DeclarationAlignment::Align16,
|
||||
rotationValues.size() * 2, "static s16",
|
||||
StringHelper::Sprintf("%sFrameData", defaultPrefix.c_str()),
|
||||
rotationValues.size(), valuesStr);
|
||||
|
||||
parent->AddDeclarationArray(rotationIndicesSeg, DeclarationAlignment::Align16,
|
||||
rotationIndices.size() * 6, "static JointIndex",
|
||||
StringHelper::Sprintf("%sJointIndices", defaultPrefix.c_str()),
|
||||
rotationIndices.size(), indicesStr);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t ZNormalAnimation::GetRawDataSize() const
|
||||
|
@ -121,23 +52,26 @@ void ZNormalAnimation::ParseRawData()
|
|||
|
||||
const uint8_t* data = parent->GetRawData().data();
|
||||
|
||||
rotationValuesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 4) & 0x00FFFFFF;
|
||||
rotationIndicesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 8) & 0x00FFFFFF;
|
||||
rotationValuesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 4);
|
||||
rotationIndicesSeg = BitConverter::ToInt32BE(data, rawDataIndex + 8);
|
||||
limit = BitConverter::ToInt16BE(data, rawDataIndex + 12);
|
||||
|
||||
uint32_t currentPtr = rotationValuesSeg;
|
||||
rotationValuesOffset = Seg2Filespace(rotationValuesSeg, parent->baseAddress);
|
||||
rotationIndicesOffset = Seg2Filespace(rotationIndicesSeg, parent->baseAddress);
|
||||
|
||||
uint32_t currentPtr = rotationValuesOffset;
|
||||
|
||||
// Read the Rotation Values
|
||||
for (uint32_t i = 0; i < ((rotationIndicesSeg - rotationValuesSeg) / 2); i++)
|
||||
for (uint32_t i = 0; i < ((rotationIndicesOffset - rotationValuesOffset) / 2); i++)
|
||||
{
|
||||
rotationValues.push_back(BitConverter::ToInt16BE(data, currentPtr));
|
||||
currentPtr += 2;
|
||||
}
|
||||
|
||||
currentPtr = rotationIndicesSeg;
|
||||
currentPtr = rotationIndicesOffset;
|
||||
|
||||
// Read the Rotation Indices
|
||||
for (uint32_t i = 0; i < ((rawDataIndex - rotationIndicesSeg) / 6); i++)
|
||||
for (uint32_t i = 0; i < ((rawDataIndex - rotationIndicesOffset) / 6); i++)
|
||||
{
|
||||
rotationIndices.push_back(RotationIndex(BitConverter::ToInt16BE(data, currentPtr),
|
||||
BitConverter::ToInt16BE(data, currentPtr + 2),
|
||||
|
@ -146,31 +80,71 @@ void ZNormalAnimation::ParseRawData()
|
|||
}
|
||||
}
|
||||
|
||||
void ZNormalAnimation::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
std::string defaultPrefix = prefix.c_str();
|
||||
if (name != "")
|
||||
defaultPrefix = name;
|
||||
|
||||
// replace g prefix with s for local variables
|
||||
if (defaultPrefix.at(0) == 'g')
|
||||
defaultPrefix.replace(0, 1, "s");
|
||||
|
||||
std::string indicesStr = "";
|
||||
std::string valuesStr = " ";
|
||||
const uint8_t lineLength = 14;
|
||||
const uint8_t offset = 0;
|
||||
|
||||
for (size_t i = 0; i < rotationValues.size(); i++)
|
||||
{
|
||||
valuesStr += StringHelper::Sprintf("0x%04X, ", rotationValues[i]);
|
||||
|
||||
if ((i - offset + 1) % lineLength == 0)
|
||||
valuesStr += "\n ";
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(rotationValuesOffset, DeclarationAlignment::Align16,
|
||||
rotationValues.size() * 2, "s16",
|
||||
StringHelper::Sprintf("%sFrameData", defaultPrefix.c_str()),
|
||||
rotationValues.size(), valuesStr);
|
||||
|
||||
for (size_t i = 0; i < rotationIndices.size(); i++)
|
||||
{
|
||||
indicesStr += StringHelper::Sprintf(" { 0x%04X, 0x%04X, 0x%04X },", rotationIndices[i].x,
|
||||
rotationIndices[i].y, rotationIndices[i].z);
|
||||
|
||||
if (i != (rotationIndices.size() - 1))
|
||||
indicesStr += "\n";
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(rotationIndicesOffset, DeclarationAlignment::Align16,
|
||||
rotationIndices.size() * 6, "JointIndex",
|
||||
StringHelper::Sprintf("%sJointIndices", defaultPrefix.c_str()),
|
||||
rotationIndices.size(), indicesStr);
|
||||
}
|
||||
|
||||
std::string ZNormalAnimation::GetBodySourceCode() const
|
||||
{
|
||||
std::string frameDataName;
|
||||
Globals::Instance->GetSegmentedPtrName(rotationValuesSeg, parent, "s16", frameDataName);
|
||||
std::string jointIndicesName;
|
||||
Globals::Instance->GetSegmentedPtrName(rotationIndicesSeg, parent, "JointIndex",
|
||||
jointIndicesName);
|
||||
|
||||
std::string headerStr =
|
||||
StringHelper::Sprintf("\n\t{ %i }, %s,\n", frameCount, frameDataName.c_str());
|
||||
headerStr += StringHelper::Sprintf("\t%s, %i\n", jointIndicesName.c_str(), limit);
|
||||
|
||||
return headerStr;
|
||||
}
|
||||
|
||||
/* ZLinkAnimation */
|
||||
|
||||
ZLinkAnimation::ZLinkAnimation(ZFile* nParent) : ZAnimation(nParent)
|
||||
{
|
||||
segmentAddress = 0;
|
||||
}
|
||||
|
||||
std::string ZLinkAnimation::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
if (parent != nullptr)
|
||||
{
|
||||
std::string segSymbol =
|
||||
segmentAddress == 0 ?
|
||||
"NULL" :
|
||||
parent->GetDeclarationName(
|
||||
segmentAddress,
|
||||
StringHelper::Sprintf("%sSeg%06X", name.c_str(), segmentAddress));
|
||||
std::string headerStr =
|
||||
StringHelper::Sprintf("\n\t{ %i },\n\t0x%08X\n", frameCount, segmentAddress);
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
|
||||
GetSourceTypeName(), StringHelper::Sprintf("%s", name.c_str()),
|
||||
headerStr);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t ZLinkAnimation::GetRawDataSize() const
|
||||
{
|
||||
return 8;
|
||||
|
@ -185,8 +159,16 @@ void ZLinkAnimation::ParseRawData()
|
|||
{
|
||||
ZAnimation::ParseRawData();
|
||||
|
||||
const uint8_t* data = parent->GetRawData().data();
|
||||
segmentAddress = (BitConverter::ToInt32BE(data, rawDataIndex + 4));
|
||||
const auto& rawData = parent->GetRawData();
|
||||
segmentAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
|
||||
}
|
||||
|
||||
std::string ZLinkAnimation::GetBodySourceCode() const
|
||||
{
|
||||
std::string segSymbol;
|
||||
Globals::Instance->GetSegmentedPtrName(segmentAddress, parent, "", segSymbol);
|
||||
|
||||
return StringHelper::Sprintf("\n\t{ %i }, %s\n", frameCount, segSymbol.c_str());
|
||||
}
|
||||
|
||||
/* ZCurveAnimation */
|
||||
|
@ -208,7 +190,7 @@ TransformData::TransformData(ZFile* parent, const std::vector<uint8_t>& rawData,
|
|||
{
|
||||
}
|
||||
|
||||
std::string TransformData::GetBody(const std::string& prefix) const
|
||||
std::string TransformData::GetBody([[maybe_unused]] const std::string& prefix) const
|
||||
{
|
||||
return StringHelper::Sprintf("0x%04X, 0x%04X, %i, %i, %ff", unk_00, unk_02, unk_04, unk_06,
|
||||
unk_08);
|
||||
|
@ -256,8 +238,8 @@ void ZCurveAnimation::ParseRawData()
|
|||
unk_0C = BitConverter::ToInt16BE(rawData, rawDataIndex + 12);
|
||||
unk_10 = BitConverter::ToInt16BE(rawData, rawDataIndex + 14);
|
||||
|
||||
limbCount =
|
||||
BitConverter::ToUInt8BE(rawData, Seg2Filespace(skelOffset, parent->baseAddress) + 4);
|
||||
uint32_t limbCountAddress = Seg2Filespace(skelOffset, parent->baseAddress) + 4;
|
||||
limbCount = BitConverter::ToUInt8BE(rawData, limbCountAddress);
|
||||
|
||||
size_t transformDataSize = 0;
|
||||
size_t copyValuesSize = 0;
|
||||
|
@ -293,14 +275,6 @@ void ZCurveAnimation::ParseRawData()
|
|||
}
|
||||
}
|
||||
|
||||
void ZCurveAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align16, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, "");
|
||||
}
|
||||
|
||||
void ZCurveAnimation::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
if (refIndex != 0)
|
||||
|
@ -321,7 +295,7 @@ void ZCurveAnimation::DeclareReferences(const std::string& prefix)
|
|||
Declaration* decl = parent->GetDeclaration(refIndexOffset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclarationArray(refIndexOffset, DeclarationAlignment::None,
|
||||
parent->AddDeclarationArray(refIndexOffset, DeclarationAlignment::Align4,
|
||||
arrayItemCnt * 1, "u8", refIndexStr, arrayItemCnt,
|
||||
entryStr);
|
||||
}
|
||||
|
@ -338,7 +312,7 @@ void ZCurveAnimation::DeclareReferences(const std::string& prefix)
|
|||
"%sCurveAnime_%s_%06X", prefix.c_str(),
|
||||
transformDataArr.at(0).GetSourceTypeName().c_str(), transformDataOffset);
|
||||
|
||||
std::string entryStr = "";
|
||||
std::string entryStr;
|
||||
uint16_t arrayItemCnt = transformDataArr.size();
|
||||
|
||||
size_t i = 0;
|
||||
|
@ -351,7 +325,7 @@ void ZCurveAnimation::DeclareReferences(const std::string& prefix)
|
|||
Declaration* decl = parent->GetDeclaration(transformDataOffset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclarationArray(transformDataOffset, DeclarationAlignment::None,
|
||||
parent->AddDeclarationArray(transformDataOffset, DeclarationAlignment::Align4,
|
||||
arrayItemCnt * transformDataArr.at(0).GetRawDataSize(),
|
||||
transformDataArr.at(0).GetSourceTypeName(),
|
||||
transformDataStr, arrayItemCnt, entryStr);
|
||||
|
@ -380,7 +354,7 @@ void ZCurveAnimation::DeclareReferences(const std::string& prefix)
|
|||
Declaration* decl = parent->GetDeclaration(copyValuesOffset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclarationArray(copyValuesOffset, DeclarationAlignment::None,
|
||||
parent->AddDeclarationArray(copyValuesOffset, DeclarationAlignment::Align4,
|
||||
arrayItemCnt * 2, "s16", copyValuesStr, arrayItemCnt,
|
||||
entryStr);
|
||||
}
|
||||
|
@ -391,81 +365,28 @@ void ZCurveAnimation::DeclareReferences(const std::string& prefix)
|
|||
}
|
||||
}
|
||||
|
||||
std::string ZCurveAnimation::GetBodySourceCode() const
|
||||
{
|
||||
std::string refIndexStr;
|
||||
Globals::Instance->GetSegmentedPtrName(refIndex, parent, "u8", refIndexStr);
|
||||
std::string transformDataStr;
|
||||
Globals::Instance->GetSegmentedPtrName(transformData, parent, "TransformData",
|
||||
transformDataStr);
|
||||
std::string copyValuesStr;
|
||||
Globals::Instance->GetSegmentedPtrName(copyValues, parent, "s16", copyValuesStr);
|
||||
|
||||
return StringHelper::Sprintf("\n\t%s,\n\t%s,\n\t%s,\n\t%i, %i\n", refIndexStr.c_str(),
|
||||
transformDataStr.c_str(), copyValuesStr.c_str(), unk_0C, unk_10);
|
||||
}
|
||||
|
||||
size_t ZCurveAnimation::GetRawDataSize() const
|
||||
{
|
||||
return 0x10;
|
||||
}
|
||||
|
||||
std::string ZCurveAnimation::GetSourceOutputCode(const std::string& prefix)
|
||||
DeclarationAlignment ZCurveAnimation::GetDeclarationAlignment() const
|
||||
{
|
||||
std::string bodyStr = "";
|
||||
uint32_t address = Seg2Filespace(rawDataIndex, parent->baseAddress);
|
||||
|
||||
std::string refIndexStr = "NULL";
|
||||
if (refIndex != 0)
|
||||
{
|
||||
uint32_t refIndexOffset = Seg2Filespace(refIndex, parent->baseAddress);
|
||||
Declaration* decl = parent->GetDeclaration(refIndexOffset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
refIndexStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Ref",
|
||||
refIndexOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
refIndexStr = decl->varName;
|
||||
}
|
||||
}
|
||||
|
||||
std::string transformDataStr = "NULL";
|
||||
if (transformData != 0)
|
||||
{
|
||||
uint32_t transformDataOffset = Seg2Filespace(transformData, parent->baseAddress);
|
||||
Declaration* decl = parent->GetDeclaration(transformDataOffset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
transformDataStr = StringHelper::Sprintf(
|
||||
"%sCurveAnime_%s_%06X", prefix.c_str(),
|
||||
transformDataArr.at(0).GetSourceTypeName().c_str(), transformDataOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
transformDataStr = decl->varName;
|
||||
}
|
||||
}
|
||||
|
||||
std::string copyValuesStr = "NULL";
|
||||
if (copyValues != 0)
|
||||
{
|
||||
uint32_t copyValuesOffset = Seg2Filespace(copyValues, parent->baseAddress);
|
||||
Declaration* decl = parent->GetDeclaration(copyValuesOffset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
copyValuesStr = StringHelper::Sprintf("%sCurveAnime_%s_%06X", prefix.c_str(), "Copy",
|
||||
copyValuesOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
copyValuesStr = decl->varName;
|
||||
}
|
||||
}
|
||||
|
||||
bodyStr =
|
||||
StringHelper::Sprintf("\n %s,\n %s,\n %s,\n %i, %i\n", refIndexStr.c_str(),
|
||||
transformDataStr.c_str(), copyValuesStr.c_str(), unk_0C, unk_10);
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(address);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclaration(address, DeclarationAlignment::None, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, bodyStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
decl->text = bodyStr;
|
||||
}
|
||||
|
||||
return "";
|
||||
return DeclarationAlignment::Align16;
|
||||
}
|
||||
|
||||
std::string ZCurveAnimation::GetSourceTypeName() const
|
||||
|
@ -479,14 +400,6 @@ ZLegacyAnimation::ZLegacyAnimation(ZFile* nParent) : ZAnimation(nParent)
|
|||
{
|
||||
}
|
||||
|
||||
void ZLegacyAnimation::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZAnimation::ExtractFromXML(reader, nRawDataIndex);
|
||||
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, "");
|
||||
}
|
||||
|
||||
void ZLegacyAnimation::ParseRawData()
|
||||
{
|
||||
ZAnimation::ParseRawData();
|
||||
|
@ -556,7 +469,7 @@ void ZLegacyAnimation::DeclareReferences(const std::string& prefix)
|
|||
if (GETSEGNUM(jointKey) == parent->segment && !parent->HasDeclaration(jointKeyOffset))
|
||||
{
|
||||
const auto res = jointKeyArray.at(0);
|
||||
std::string jointKeyBody = "";
|
||||
std::string jointKeyBody;
|
||||
|
||||
for (size_t i = 0; i < jointKeyArray.size(); i++)
|
||||
{
|
||||
|
@ -580,8 +493,10 @@ std::string ZLegacyAnimation::GetBodySourceCode() const
|
|||
{
|
||||
std::string body = "\n";
|
||||
|
||||
std::string frameDataName = parent->GetDeclarationPtrName(frameData);
|
||||
std::string jointKeyName = parent->GetDeclarationPtrName(jointKey);
|
||||
std::string frameDataName;
|
||||
std::string jointKeyName;
|
||||
Globals::Instance->GetSegmentedPtrName(frameData, parent, "s16", frameDataName);
|
||||
Globals::Instance->GetSegmentedPtrName(jointKey, parent, "JointKey", jointKeyName);
|
||||
|
||||
body += StringHelper::Sprintf("\t%i, %i,\n", frameCount, limbCount);
|
||||
body += StringHelper::Sprintf("\t%s,\n", frameDataName.c_str());
|
||||
|
@ -590,20 +505,6 @@ std::string ZLegacyAnimation::GetBodySourceCode() const
|
|||
return body;
|
||||
}
|
||||
|
||||
std::string ZLegacyAnimation::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
std::string body = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
if (decl == nullptr || decl->isPlaceholder)
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, body);
|
||||
else
|
||||
decl->text = body;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string ZLegacyAnimation::GetSourceTypeName() const
|
||||
{
|
||||
return "LegacyAnimationHeader";
|
||||
|
|
|
@ -13,12 +13,7 @@ struct RotationIndex
|
|||
// uint16_t transX, transY, transZ;
|
||||
uint16_t x, y, z;
|
||||
|
||||
RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ)
|
||||
{
|
||||
x = nX;
|
||||
y = nY;
|
||||
z = nZ;
|
||||
};
|
||||
RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ) : x(nX), y(nY), z(nZ) {}
|
||||
};
|
||||
|
||||
class ZAnimation : public ZResource
|
||||
|
@ -28,12 +23,10 @@ public:
|
|||
|
||||
ZAnimation(ZFile* nParent);
|
||||
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
protected:
|
||||
void ParseRawData() override;
|
||||
void Save(const fs::path& outFolder) override;
|
||||
};
|
||||
|
||||
class ZNormalAnimation : public ZAnimation
|
||||
|
@ -41,18 +34,22 @@ class ZNormalAnimation : public ZAnimation
|
|||
public:
|
||||
std::vector<uint16_t> rotationValues;
|
||||
std::vector<RotationIndex> rotationIndices;
|
||||
uint32_t rotationValuesSeg;
|
||||
uint32_t rotationIndicesSeg;
|
||||
int16_t limit;
|
||||
segptr_t rotationValuesSeg = 0;
|
||||
segptr_t rotationIndicesSeg = 0;
|
||||
offset_t rotationValuesOffset = 0;
|
||||
offset_t rotationIndicesOffset = 0;
|
||||
int16_t limit = 0;
|
||||
|
||||
ZNormalAnimation(ZFile* nParent);
|
||||
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetSourceTypeName() const override;
|
||||
|
||||
protected:
|
||||
virtual void ParseRawData() override;
|
||||
void ParseRawData() override;
|
||||
};
|
||||
|
||||
class ZLinkAnimation : public ZAnimation
|
||||
|
@ -62,12 +59,12 @@ public:
|
|||
|
||||
ZLinkAnimation(ZFile* nParent);
|
||||
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetSourceTypeName() const override;
|
||||
|
||||
protected:
|
||||
virtual void ParseRawData() override;
|
||||
void ParseRawData() override;
|
||||
};
|
||||
|
||||
class TransformData
|
||||
|
@ -121,16 +118,17 @@ protected:
|
|||
std::vector<int16_t> copyValuesArr;
|
||||
|
||||
public:
|
||||
ZCurveAnimation();
|
||||
ZCurveAnimation(ZFile* nParent);
|
||||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
void ParseRawData() override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
DeclarationAlignment GetDeclarationAlignment() const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
};
|
||||
|
@ -162,13 +160,10 @@ class ZLegacyAnimation : public ZAnimation
|
|||
public:
|
||||
ZLegacyAnimation(ZFile* nParent);
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include "ZArray.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
REGISTER_ZFILENODE(Array, ZArray);
|
||||
|
@ -53,23 +55,56 @@ void ZArray::ParseXML(tinyxml2::XMLElement* reader)
|
|||
}
|
||||
}
|
||||
|
||||
std::string ZArray::GetSourceOutputCode(const std::string& prefix)
|
||||
Declaration* ZArray::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
{
|
||||
std::string output = "";
|
||||
std::string auxName = name;
|
||||
|
||||
if (name == "")
|
||||
auxName = GetDefaultName(prefix);
|
||||
|
||||
ZResource* res = resList.at(0);
|
||||
Declaration* decl;
|
||||
if (res->IsExternalResource())
|
||||
{
|
||||
auto filepath = Globals::Instance->outputPath / name;
|
||||
std::string includePath = StringHelper::Sprintf("%s.%s.inc", filepath.c_str(),
|
||||
res->GetExternalExtension().c_str());
|
||||
decl = parent->AddDeclarationIncludeArray(rawDataIndex, includePath, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, arrayCnt);
|
||||
decl->text = bodyStr;
|
||||
decl->isExternal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
decl =
|
||||
parent->AddDeclarationArray(rawDataIndex, GetDeclarationAlignment(), GetRawDataSize(),
|
||||
GetSourceTypeName(), name, arrayCnt, bodyStr);
|
||||
}
|
||||
|
||||
decl->staticConf = staticConf;
|
||||
return decl;
|
||||
}
|
||||
|
||||
std::string ZArray::GetBodySourceCode() const
|
||||
{
|
||||
std::string output;
|
||||
|
||||
for (size_t i = 0; i < arrayCnt; i++)
|
||||
{
|
||||
output += resList.at(i)->GetBodySourceCode();
|
||||
const auto& res = resList[i];
|
||||
output += "\t";
|
||||
|
||||
if (i < arrayCnt - 1)
|
||||
if (res->GetResourceType() == ZResourceType::Scalar ||
|
||||
res->GetResourceType() == ZResourceType::Vertex)
|
||||
output += resList.at(i)->GetBodySourceCode();
|
||||
else
|
||||
output += StringHelper::Sprintf("{ %s }", resList.at(i)->GetBodySourceCode().c_str());
|
||||
|
||||
if (i < arrayCnt - 1 || res->IsExternalResource())
|
||||
output += ",\n";
|
||||
}
|
||||
|
||||
if (parent != nullptr)
|
||||
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::None, GetRawDataSize(),
|
||||
resList.at(0)->GetSourceTypeName(), name, arrayCnt, output);
|
||||
|
||||
return "";
|
||||
return output;
|
||||
}
|
||||
|
||||
size_t ZArray::GetRawDataSize() const
|
||||
|
@ -80,7 +115,21 @@ size_t ZArray::GetRawDataSize() const
|
|||
return size;
|
||||
}
|
||||
|
||||
std::string ZArray::GetSourceTypeName() const
|
||||
{
|
||||
return resList.at(0)->GetSourceTypeName();
|
||||
}
|
||||
|
||||
ZResourceType ZArray::GetResourceType() const
|
||||
{
|
||||
return ZResourceType::Array;
|
||||
}
|
||||
|
||||
DeclarationAlignment ZArray::GetDeclarationAlignment() const
|
||||
{
|
||||
if (resList.size() == 0)
|
||||
{
|
||||
return DeclarationAlignment::Align4;
|
||||
}
|
||||
return resList.at(0)->GetDeclarationAlignment();
|
||||
}
|
||||
|
|
|
@ -14,11 +14,16 @@ public:
|
|||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
DeclarationAlignment GetDeclarationAlignment() const override;
|
||||
|
||||
protected:
|
||||
size_t arrayCnt;
|
||||
std::string childName;
|
||||
|
|
|
@ -1,30 +1,22 @@
|
|||
#include "ZBackground.h"
|
||||
#include "BitConverter.h"
|
||||
#include "File.h"
|
||||
|
||||
#include "Globals.h"
|
||||
#include "Path.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/File.h"
|
||||
#include "Utils/Path.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
REGISTER_ZFILENODE(Background, ZBackground);
|
||||
|
||||
#define JPEG_MARKER 0xFFD8FFE0
|
||||
#define MARKER_DQT 0xFFDB
|
||||
#define MARKER_EOI 0xFFD9
|
||||
|
||||
ZBackground::ZBackground(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
ZBackground::ZBackground(const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent)
|
||||
: ZResource(nParent)
|
||||
{
|
||||
rawDataIndex = nRawDataIndex;
|
||||
name = GetDefaultName(prefix.c_str(), rawDataIndex);
|
||||
outName = name;
|
||||
|
||||
ParseRawData();
|
||||
}
|
||||
|
||||
void ZBackground::ParseRawData()
|
||||
{
|
||||
ZResource::ParseRawData();
|
||||
|
@ -36,7 +28,7 @@ void ZBackground::ParseRawData()
|
|||
uint8_t val = rawData.at(rawDataIndex + i);
|
||||
data.push_back(val);
|
||||
|
||||
if (BitConverter::ToUInt16BE(rawData, rawDataIndex + i) == 0xFFD9)
|
||||
if (BitConverter::ToUInt16BE(rawData, rawDataIndex + i) == MARKER_EOI)
|
||||
{
|
||||
data.push_back(rawData.at(rawDataIndex + i + 1));
|
||||
break;
|
||||
|
@ -60,12 +52,6 @@ void ZBackground::ParseBinaryFile(const std::string& inFolder, bool appendOutNam
|
|||
CheckValidJpeg(filepath.generic_string());
|
||||
}
|
||||
|
||||
void ZBackground::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
DeclareVar("", "");
|
||||
}
|
||||
|
||||
void ZBackground::CheckValidJpeg(const std::string& filepath)
|
||||
{
|
||||
std::string filename = outName;
|
||||
|
@ -132,16 +118,28 @@ size_t ZBackground::GetRawDataSize() const
|
|||
return Globals::Instance->cfg.bgScreenHeight * Globals::Instance->cfg.bgScreenWidth * 2;
|
||||
}
|
||||
|
||||
void ZBackground::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
|
||||
Declaration* ZBackground::DeclareVar(const std::string& prefix,
|
||||
[[maybe_unused]] const std::string& bodyStr)
|
||||
{
|
||||
std::string auxName = name;
|
||||
std::string auxOutName = outName;
|
||||
|
||||
if (name == "")
|
||||
auxName = GetDefaultName(prefix, rawDataIndex);
|
||||
if (auxName == "")
|
||||
auxName = GetDefaultName(prefix);
|
||||
|
||||
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(),
|
||||
GetSourceTypeName(), auxName, "SCREEN_WIDTH * SCREEN_HEIGHT / 4",
|
||||
bodyStr);
|
||||
if (auxOutName == "")
|
||||
auxOutName = GetDefaultName(prefix);
|
||||
|
||||
auto filepath = Globals::Instance->outputPath / fs::path(auxOutName).stem();
|
||||
|
||||
std::string incStr =
|
||||
StringHelper::Sprintf("%s.%s.inc.c", filepath.c_str(), GetExternalExtension().c_str());
|
||||
|
||||
Declaration* decl = parent->AddDeclarationIncludeArray(rawDataIndex, incStr, GetRawDataSize(),
|
||||
GetSourceTypeName(), auxName, 0);
|
||||
decl->arrayItemCntStr = "SCREEN_WIDTH * SCREEN_HEIGHT / 4";
|
||||
decl->staticConf = staticConf;
|
||||
return decl;
|
||||
}
|
||||
|
||||
bool ZBackground::IsExternalResource() const
|
||||
|
@ -160,7 +158,7 @@ void ZBackground::Save(const fs::path& outFolder)
|
|||
File::WriteAllBytes(filepath.string(), data);
|
||||
}
|
||||
|
||||
std::string ZBackground::GetBodySourceCode()
|
||||
std::string ZBackground::GetBodySourceCode() const
|
||||
{
|
||||
std::string bodyStr = " ";
|
||||
|
||||
|
@ -177,23 +175,9 @@ std::string ZBackground::GetBodySourceCode()
|
|||
return bodyStr;
|
||||
}
|
||||
|
||||
std::string ZBackground::GetSourceOutputCode(const std::string& prefix)
|
||||
std::string ZBackground::GetDefaultName(const std::string& prefix) const
|
||||
{
|
||||
std::string bodyStr = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
|
||||
if (decl == nullptr)
|
||||
DeclareVar(prefix, bodyStr);
|
||||
else
|
||||
decl->text = bodyStr;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string ZBackground::GetDefaultName(const std::string& prefix, uint32_t address)
|
||||
{
|
||||
return StringHelper::Sprintf("%sBackground_%06X", prefix.c_str(), address);
|
||||
return StringHelper::Sprintf("%sBackground_%06X", prefix.c_str(), rawDataIndex);
|
||||
}
|
||||
|
||||
std::string ZBackground::GetSourceTypeName() const
|
||||
|
@ -205,3 +189,8 @@ ZResourceType ZBackground::GetResourceType() const
|
|||
{
|
||||
return ZResourceType::Background;
|
||||
}
|
||||
|
||||
DeclarationAlignment ZBackground::GetDeclarationAlignment() const
|
||||
{
|
||||
return DeclarationAlignment::Align8;
|
||||
}
|
||||
|
|
|
@ -11,25 +11,24 @@ protected:
|
|||
|
||||
public:
|
||||
ZBackground(ZFile* nParent);
|
||||
ZBackground(const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent);
|
||||
|
||||
void ParseBinaryFile(const std::string& inFolder, bool appendOutName);
|
||||
|
||||
void ParseRawData() override;
|
||||
void ParseBinaryFile(const std::string& inFolder, bool appendOutName);
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
void CheckValidJpeg(const std::string& filepath);
|
||||
Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
std::string GetDefaultName(const std::string& prefix) const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
void DeclareVar(const std::string& prefix, const std::string& bodyStr) const;
|
||||
void Save(const fs::path& outFolder) override;
|
||||
|
||||
bool IsExternalResource() const override;
|
||||
std::string GetExternalExtension() const override;
|
||||
void Save(const fs::path& outFolder) override;
|
||||
std::string GetBodySourceCode();
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
static std::string GetDefaultName(const std::string& prefix, uint32_t address);
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
std::string GetExternalExtension() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
DeclarationAlignment GetDeclarationAlignment() const override;
|
||||
|
||||
void CheckValidJpeg(const std::string& filepath);
|
||||
};
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "ZBlob.h"
|
||||
#include "BitConverter.h"
|
||||
#include "File.h"
|
||||
#include "Path.h"
|
||||
#include "StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
using namespace tinyxml2;
|
||||
#include "Globals.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/File.h"
|
||||
#include "Utils/Path.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
REGISTER_ZFILENODE(Blob, ZBlob);
|
||||
|
||||
|
@ -14,19 +14,6 @@ ZBlob::ZBlob(ZFile* nParent) : ZResource(nParent)
|
|||
RegisterRequiredAttribute("Size");
|
||||
}
|
||||
|
||||
// Build Source File Mode
|
||||
ZBlob* ZBlob::BuildFromXML(XMLElement* reader, const std::string& inFolder, bool readFile)
|
||||
{
|
||||
ZBlob* blob = new ZBlob(nullptr);
|
||||
|
||||
blob->ParseXML(reader);
|
||||
|
||||
if (readFile)
|
||||
blob->blobData = File::ReadAllBytes(inFolder + "/" + blob->name + ".bin");
|
||||
|
||||
return blob;
|
||||
}
|
||||
|
||||
ZBlob* ZBlob::FromFile(const std::string& filePath)
|
||||
{
|
||||
ZBlob* blob = new ZBlob(nullptr);
|
||||
|
@ -49,14 +36,38 @@ void ZBlob::ParseRawData()
|
|||
parent->GetRawData().begin() + rawDataIndex + blobSize);
|
||||
}
|
||||
|
||||
std::string ZBlob::GetSourceOutputCode(const std::string& prefix)
|
||||
Declaration* ZBlob::DeclareVar(const std::string& prefix,
|
||||
[[maybe_unused]] const std::string& bodyStr)
|
||||
{
|
||||
sourceOutput = "";
|
||||
std::string auxName = name;
|
||||
std::string auxOutName = outName;
|
||||
|
||||
if (auxName == "")
|
||||
auxName = GetDefaultName(prefix);
|
||||
|
||||
if (auxOutName == "")
|
||||
auxOutName = GetDefaultName(prefix);
|
||||
|
||||
std::string path = Path::GetFileNameWithoutExtension(auxOutName);
|
||||
|
||||
std::string assetOutDir =
|
||||
(Globals::Instance->outputPath / Path::GetFileNameWithoutExtension(GetOutName())).string();
|
||||
|
||||
std::string incStr =
|
||||
StringHelper::Sprintf("%s.%s.inc.c", assetOutDir.c_str(), GetExternalExtension().c_str());
|
||||
|
||||
return parent->AddDeclarationIncludeArray(rawDataIndex, incStr, GetRawDataSize(),
|
||||
GetSourceTypeName(), auxName, blobData.size());
|
||||
}
|
||||
|
||||
std::string ZBlob::GetBodySourceCode() const
|
||||
{
|
||||
std::string sourceOutput;
|
||||
|
||||
for (size_t i = 0; i < blobData.size(); i += 1)
|
||||
{
|
||||
if (i % 16 == 0)
|
||||
sourceOutput += " ";
|
||||
sourceOutput += "\t";
|
||||
|
||||
sourceOutput += StringHelper::Sprintf("0x%02X, ", blobData[i]);
|
||||
|
||||
|
@ -72,14 +83,14 @@ std::string ZBlob::GetSourceOutputCode(const std::string& prefix)
|
|||
return sourceOutput;
|
||||
}
|
||||
|
||||
std::string ZBlob::GetSourceOutputHeader(const std::string& prefix)
|
||||
std::string ZBlob::GetSourceOutputHeader([[maybe_unused]] const std::string& prefix)
|
||||
{
|
||||
return StringHelper::Sprintf("extern u8 %s[];\n", name.c_str());
|
||||
}
|
||||
|
||||
void ZBlob::Save(const fs::path& outFolder)
|
||||
{
|
||||
File::WriteAllBytes(outFolder / (name + ".bin"), blobData);
|
||||
File::WriteAllBytes((outFolder / (name + ".bin")).string(), blobData);
|
||||
}
|
||||
|
||||
bool ZBlob::IsExternalResource() const
|
||||
|
|
|
@ -8,13 +8,14 @@ class ZBlob : public ZResource
|
|||
public:
|
||||
ZBlob(ZFile* nParent);
|
||||
|
||||
static ZBlob* BuildFromXML(tinyxml2::XMLElement* reader, const std::string& inFolder,
|
||||
bool readFile);
|
||||
static ZBlob* FromFile(const std::string& filePath);
|
||||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
void ParseRawData() override;
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
|
||||
Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceOutputHeader(const std::string& prefix) override;
|
||||
void Save(const fs::path& outFolder) override;
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#include "ZCollision.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include "BitConverter.h"
|
||||
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
|
||||
REGISTER_ZFILENODE(Collision, ZCollisionHeader);
|
||||
|
||||
|
@ -13,9 +15,6 @@ ZCollisionHeader::ZCollisionHeader(ZFile* nParent) : ZResource(nParent)
|
|||
|
||||
ZCollisionHeader::~ZCollisionHeader()
|
||||
{
|
||||
for (WaterBoxHeader* waterBox : waterBoxes)
|
||||
delete waterBox;
|
||||
|
||||
delete camData;
|
||||
}
|
||||
|
||||
|
@ -51,8 +50,16 @@ void ZCollisionHeader::ParseRawData()
|
|||
vertices.reserve(numVerts);
|
||||
polygons.reserve(numPolygons);
|
||||
|
||||
uint32_t currentPtr = vtxSegmentOffset;
|
||||
|
||||
for (uint16_t i = 0; i < numVerts; i++)
|
||||
vertices.push_back(VertexEntry(rawData, vtxSegmentOffset + (i * 6)));
|
||||
{
|
||||
ZVector vec(parent);
|
||||
vec.ExtractFromBinary(currentPtr, ZScalarType::ZSCALAR_S16, 3);
|
||||
|
||||
currentPtr += vec.GetRawDataSize();
|
||||
vertices.push_back(vec);
|
||||
}
|
||||
|
||||
for (uint16_t i = 0; i < numPolygons; i++)
|
||||
polygons.push_back(PolygonEntry(rawData, polySegmentOffset + (i * 16)));
|
||||
|
@ -74,34 +81,38 @@ void ZCollisionHeader::ParseRawData()
|
|||
polyTypeDefSegmentOffset, polygonTypes.size());
|
||||
|
||||
for (uint16_t i = 0; i < numWaterBoxes; i++)
|
||||
waterBoxes.push_back(new WaterBoxHeader(
|
||||
waterBoxes.push_back(WaterBoxHeader(
|
||||
rawData,
|
||||
waterBoxSegmentOffset + (i * (Globals::Instance->game == ZGame::OOT_SW97 ? 12 : 16))));
|
||||
}
|
||||
|
||||
std::string declaration = "";
|
||||
void ZCollisionHeader::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
std::string declaration;
|
||||
std::string auxName = name;
|
||||
|
||||
if (name == "")
|
||||
auxName = GetDefaultName(prefix);
|
||||
|
||||
if (waterBoxes.size() > 0)
|
||||
{
|
||||
for (size_t i = 0; i < waterBoxes.size(); i++)
|
||||
{
|
||||
declaration += StringHelper::Sprintf("\t{ %i, %i, %i, %i, %i, 0x%08X },",
|
||||
waterBoxes[i]->xMin, waterBoxes[i]->ySurface,
|
||||
waterBoxes[i]->zMin, waterBoxes[i]->xLength,
|
||||
waterBoxes[i]->zLength, waterBoxes[i]->properties);
|
||||
declaration +=
|
||||
StringHelper::Sprintf("\t{ %s },", waterBoxes[i].GetBodySourceCode().c_str());
|
||||
if (i + 1 < waterBoxes.size())
|
||||
declaration += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (waterBoxAddress != 0)
|
||||
parent->AddDeclarationArray(
|
||||
waterBoxSegmentOffset, DeclarationAlignment::None, 16 * waterBoxes.size(), "WaterBox",
|
||||
StringHelper::Sprintf("%s_waterBoxes_%06X", name.c_str(), waterBoxSegmentOffset), 0,
|
||||
declaration);
|
||||
waterBoxSegmentOffset, DeclarationAlignment::Align4, 16 * waterBoxes.size(), "WaterBox",
|
||||
StringHelper::Sprintf("%s_waterBoxes_%06X", auxName.c_str(), waterBoxSegmentOffset),
|
||||
waterBoxes.size(), declaration);
|
||||
}
|
||||
|
||||
if (polygons.size() > 0)
|
||||
{
|
||||
declaration = "";
|
||||
declaration.clear();
|
||||
|
||||
for (size_t i = 0; i < polygons.size(); i++)
|
||||
{
|
||||
|
@ -113,17 +124,13 @@ void ZCollisionHeader::ParseRawData()
|
|||
declaration += "\n";
|
||||
}
|
||||
|
||||
if (polyAddress != 0)
|
||||
{
|
||||
parent->AddDeclarationArray(
|
||||
polySegmentOffset, DeclarationAlignment::None, polygons.size() * 16,
|
||||
"CollisionPoly",
|
||||
StringHelper::Sprintf("%s_polygons_%08X", name.c_str(), polySegmentOffset), 0,
|
||||
declaration);
|
||||
}
|
||||
parent->AddDeclarationArray(
|
||||
polySegmentOffset, DeclarationAlignment::Align4, polygons.size() * 16, "CollisionPoly",
|
||||
StringHelper::Sprintf("%s_polygons_%08X", auxName.c_str(), polySegmentOffset),
|
||||
polygons.size(), declaration);
|
||||
}
|
||||
|
||||
declaration = "";
|
||||
declaration.clear();
|
||||
for (size_t i = 0; i < polygonTypes.size(); i++)
|
||||
{
|
||||
declaration += StringHelper::Sprintf("\t{ 0x%08lX, 0x%08lX },", polygonTypes[i] >> 32,
|
||||
|
@ -135,58 +142,76 @@ void ZCollisionHeader::ParseRawData()
|
|||
|
||||
if (polyTypeDefAddress != 0)
|
||||
parent->AddDeclarationArray(
|
||||
polyTypeDefSegmentOffset, DeclarationAlignment::None, polygonTypes.size() * 8,
|
||||
polyTypeDefSegmentOffset, DeclarationAlignment::Align4, polygonTypes.size() * 8,
|
||||
"SurfaceType",
|
||||
StringHelper::Sprintf("%s_surfaceType_%08X", name.c_str(), polyTypeDefSegmentOffset), 0,
|
||||
declaration);
|
||||
StringHelper::Sprintf("%s_surfaceType_%08X", auxName.c_str(), polyTypeDefSegmentOffset),
|
||||
polygonTypes.size(), declaration);
|
||||
|
||||
declaration = "";
|
||||
declaration.clear();
|
||||
|
||||
if (vertices.size() > 0)
|
||||
{
|
||||
declaration = "";
|
||||
declaration.clear();
|
||||
|
||||
for (size_t i = 0; i < vertices.size(); i++)
|
||||
{
|
||||
declaration += StringHelper::Sprintf("\t{ %6i, %6i, %6i },", vertices[i].x,
|
||||
vertices[i].y, vertices[i].z);
|
||||
declaration +=
|
||||
StringHelper::Sprintf("\t{ %s },", vertices[i].GetBodySourceCode().c_str());
|
||||
|
||||
if (i < vertices.size() - 1)
|
||||
declaration += "\n";
|
||||
}
|
||||
|
||||
const auto& first = vertices.front();
|
||||
if (vtxAddress != 0)
|
||||
parent->AddDeclarationArray(
|
||||
vtxSegmentOffset, DeclarationAlignment::None, vertices.size() * 6, "Vec3s",
|
||||
StringHelper::Sprintf("%s_vtx_%08X", name.c_str(), vtxSegmentOffset), 0,
|
||||
declaration);
|
||||
|
||||
declaration = "";
|
||||
vtxSegmentOffset, first.GetDeclarationAlignment(),
|
||||
vertices.size() * first.GetRawDataSize(), first.GetSourceTypeName(),
|
||||
StringHelper::Sprintf("%s_vtx_%08X", auxName.c_str(), vtxSegmentOffset),
|
||||
vertices.size(), declaration);
|
||||
}
|
||||
}
|
||||
|
||||
declaration = "";
|
||||
char waterBoxStr[2048];
|
||||
|
||||
if (waterBoxAddress != 0)
|
||||
sprintf(waterBoxStr, "%s_waterBoxes_%06X", name.c_str(), waterBoxSegmentOffset);
|
||||
else
|
||||
sprintf(waterBoxStr, "NULL");
|
||||
std::string ZCollisionHeader::GetBodySourceCode() const
|
||||
{
|
||||
std::string declaration;
|
||||
|
||||
declaration += "\n";
|
||||
|
||||
declaration += StringHelper::Sprintf(" { %i, %i, %i },\n { %i, %i, %i },\n", absMinX,
|
||||
absMinY, absMinZ, absMaxX, absMaxY, absMaxZ);
|
||||
declaration += StringHelper::Sprintf("\t{ %i, %i, %i },\n", absMinX, absMinY, absMinZ);
|
||||
declaration += StringHelper::Sprintf("\t{ %i, %i, %i },\n", absMaxX, absMaxY, absMaxZ);
|
||||
|
||||
declaration += StringHelper::Sprintf(
|
||||
" %i,\n %s_vtx_%08X,\n %i,\n %s_polygons_%08X,\n %s_surfaceType_%08X,\n "
|
||||
"%s_camDataList_%08X,\n %i,\n %s\n",
|
||||
numVerts, name.c_str(), vtxSegmentOffset, numPolygons, name.c_str(), polySegmentOffset,
|
||||
name.c_str(), polyTypeDefSegmentOffset, name.c_str(), camDataSegmentOffset, numWaterBoxes,
|
||||
waterBoxStr);
|
||||
std::string vtxName;
|
||||
Globals::Instance->GetSegmentedPtrName(vtxAddress, parent, "Vec3s", vtxName);
|
||||
declaration += StringHelper::Sprintf("\t%i,\n\t%s,\n", numVerts, vtxName.c_str());
|
||||
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::None, DeclarationPadding::Pad16,
|
||||
GetRawDataSize(), "CollisionHeader",
|
||||
StringHelper::Sprintf("%s", name.c_str(), rawDataIndex), declaration);
|
||||
std::string polyName;
|
||||
Globals::Instance->GetSegmentedPtrName(polyAddress, parent, "CollisionPoly", polyName);
|
||||
declaration += StringHelper::Sprintf("\t%i,\n\t%s,\n", numPolygons, polyName.c_str());
|
||||
|
||||
std::string surfaceName;
|
||||
Globals::Instance->GetSegmentedPtrName(polyTypeDefAddress, parent, "SurfaceType", surfaceName);
|
||||
declaration += StringHelper::Sprintf("\t%s,\n", surfaceName.c_str());
|
||||
|
||||
std::string camName;
|
||||
Globals::Instance->GetSegmentedPtrName(camDataAddress, parent, "CamData", camName);
|
||||
declaration += StringHelper::Sprintf("\t%s,\n", camName.c_str());
|
||||
|
||||
std::string waterBoxName;
|
||||
Globals::Instance->GetSegmentedPtrName(waterBoxAddress, parent, "WaterBox", waterBoxName);
|
||||
declaration += StringHelper::Sprintf("\t%i,\n\t%s\n", numWaterBoxes, waterBoxName.c_str());
|
||||
|
||||
return declaration;
|
||||
}
|
||||
|
||||
std::string ZCollisionHeader::GetDefaultName(const std::string& prefix) const
|
||||
{
|
||||
return StringHelper::Sprintf("%sCol_%06X", prefix.c_str(), rawDataIndex);
|
||||
}
|
||||
|
||||
std::string ZCollisionHeader::GetSourceTypeName() const
|
||||
{
|
||||
return "CollisionHeader";
|
||||
}
|
||||
|
||||
ZResourceType ZCollisionHeader::GetResourceType() const
|
||||
|
@ -213,15 +238,6 @@ PolygonEntry::PolygonEntry(const std::vector<uint8_t>& rawData, uint32_t rawData
|
|||
d = BitConverter::ToUInt16BE(data, rawDataIndex + 14);
|
||||
}
|
||||
|
||||
VertexEntry::VertexEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
{
|
||||
const uint8_t* data = rawData.data();
|
||||
|
||||
x = BitConverter::ToInt16BE(data, rawDataIndex + 0);
|
||||
y = BitConverter::ToInt16BE(data, rawDataIndex + 2);
|
||||
z = BitConverter::ToInt16BE(data, rawDataIndex + 4);
|
||||
}
|
||||
|
||||
WaterBoxHeader::WaterBoxHeader(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
{
|
||||
const uint8_t* data = rawData.data();
|
||||
|
@ -238,11 +254,18 @@ WaterBoxHeader::WaterBoxHeader(const std::vector<uint8_t>& rawData, uint32_t raw
|
|||
properties = BitConverter::ToInt32BE(data, rawDataIndex + 12);
|
||||
}
|
||||
|
||||
std::string WaterBoxHeader::GetBodySourceCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("%i, %i, %i, %i, %i, 0x%08X", xMin, ySurface, zMin, xLength,
|
||||
zLength, properties);
|
||||
}
|
||||
|
||||
CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix,
|
||||
const std::vector<uint8_t>& rawData, uint32_t rawDataIndex,
|
||||
uint32_t polyTypeDefSegmentOffset, uint32_t polygonTypesCnt)
|
||||
uint32_t polyTypeDefSegmentOffset,
|
||||
[[maybe_unused]] uint32_t polygonTypesCnt)
|
||||
{
|
||||
std::string declaration = "";
|
||||
std::string declaration;
|
||||
|
||||
// Parse CameraDataEntries
|
||||
int32_t numElements = (polyTypeDefSegmentOffset - rawDataIndex) / 8;
|
||||
|
@ -257,7 +280,7 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix,
|
|||
entry->cameraPosDataSeg =
|
||||
BitConverter::ToInt32BE(rawData, rawDataIndex + (entries.size() * 8) + 4);
|
||||
|
||||
if (entry->cameraPosDataSeg != 0 && GETSEGNUM(entry->cameraPosDataSeg) != 2)
|
||||
if (entry->cameraPosDataSeg != 0 && GETSEGNUM(entry->cameraPosDataSeg) != SEGMENT_SCENE)
|
||||
{
|
||||
cameraPosDataSeg = rawDataIndex + (entries.size() * 8);
|
||||
break;
|
||||
|
@ -294,7 +317,7 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix,
|
|||
}
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
rawDataIndex, DeclarationAlignment::None, entries.size() * 8, "CamData",
|
||||
rawDataIndex, DeclarationAlignment::Align4, entries.size() * 8, "CamData",
|
||||
StringHelper::Sprintf("%s_camDataList_%08X", prefix.c_str(), rawDataIndex), entries.size(),
|
||||
declaration);
|
||||
|
||||
|
@ -302,7 +325,7 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix,
|
|||
|
||||
if (numDataTotal > 0)
|
||||
{
|
||||
declaration = "";
|
||||
declaration.clear();
|
||||
for (uint32_t i = 0; i < numDataTotal; i++)
|
||||
{
|
||||
CameraPositionData* data =
|
||||
|
@ -317,12 +340,21 @@ CameraDataList::CameraDataList(ZFile* parent, const std::string& prefix,
|
|||
int32_t cameraPosDataIndex = GETSEGOFFSET(cameraPosDataSeg);
|
||||
uint32_t entrySize = numDataTotal * 0x6;
|
||||
parent->AddDeclarationArray(
|
||||
cameraPosDataIndex, DeclarationAlignment::None, entrySize, "Vec3s",
|
||||
cameraPosDataIndex, DeclarationAlignment::Align4, entrySize, "Vec3s",
|
||||
StringHelper::Sprintf("%s_camPosData_%08X", prefix.c_str(), cameraPosDataIndex),
|
||||
numDataTotal, declaration);
|
||||
}
|
||||
}
|
||||
|
||||
CameraDataList::~CameraDataList()
|
||||
{
|
||||
for (auto entry : entries)
|
||||
delete entry;
|
||||
|
||||
for (auto camPosData : cameraPositionData)
|
||||
delete camPosData;
|
||||
}
|
||||
|
||||
CameraPositionData::CameraPositionData(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
{
|
||||
x = BitConverter::ToInt16BE(rawData, rawDataIndex + 0);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "ZFile.h"
|
||||
#include "ZResource.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
#include "ZVector.h"
|
||||
|
||||
class PolygonEntry
|
||||
{
|
||||
|
@ -14,17 +15,14 @@ public:
|
|||
PolygonEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
};
|
||||
|
||||
class VertexEntry
|
||||
{
|
||||
public:
|
||||
int16_t x, y, z;
|
||||
|
||||
VertexEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
};
|
||||
|
||||
class WaterBoxHeader
|
||||
{
|
||||
public:
|
||||
WaterBoxHeader(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
|
||||
protected:
|
||||
int16_t xMin;
|
||||
int16_t ySurface;
|
||||
int16_t zMin;
|
||||
|
@ -32,8 +30,6 @@ public:
|
|||
int16_t zLength;
|
||||
int16_t pad;
|
||||
int32_t properties;
|
||||
|
||||
WaterBoxHeader(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
};
|
||||
|
||||
class CameraPositionData
|
||||
|
@ -61,6 +57,7 @@ public:
|
|||
CameraDataList(ZFile* parent, const std::string& prefix, const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex, uint32_t polyTypeDefSegmentOffset,
|
||||
uint32_t polygonTypesCnt);
|
||||
~CameraDataList();
|
||||
};
|
||||
|
||||
class ZCollisionHeader : public ZResource
|
||||
|
@ -81,17 +78,22 @@ public:
|
|||
uint32_t vtxSegmentOffset, polySegmentOffset, polyTypeDefSegmentOffset, camDataSegmentOffset,
|
||||
waterBoxSegmentOffset;
|
||||
|
||||
std::vector<VertexEntry> vertices;
|
||||
std::vector<ZVector> vertices;
|
||||
std::vector<PolygonEntry> polygons;
|
||||
std::vector<uint64_t> polygonTypes;
|
||||
std::vector<WaterBoxHeader*> waterBoxes;
|
||||
std::vector<WaterBoxHeader> waterBoxes;
|
||||
CameraDataList* camData;
|
||||
|
||||
ZCollisionHeader(ZFile* nParent);
|
||||
~ZCollisionHeader();
|
||||
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
std::string GetDefaultName(const std::string& prefix) const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "ZCutscene.h"
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZResource.h"
|
||||
|
||||
REGISTER_ZFILENODE(Cutscene, ZCutscene);
|
||||
|
@ -84,10 +85,9 @@ CutsceneCommandSceneTransFX::~CutsceneCommandSceneTransFX()
|
|||
{
|
||||
}
|
||||
|
||||
std::string ZCutscene::GetBodySourceCode()
|
||||
std::string ZCutscene::GetBodySourceCode() const
|
||||
{
|
||||
std::string output = "";
|
||||
size_t size = 0;
|
||||
std::string output;
|
||||
uint32_t curPtr = 0;
|
||||
|
||||
output += StringHelper::Sprintf(" CS_BEGIN_CUTSCENE(%i, %i),\n", commands.size(), endFrame);
|
||||
|
@ -97,7 +97,6 @@ std::string ZCutscene::GetBodySourceCode()
|
|||
CutsceneCommand* cmd = commands[i];
|
||||
output += " " + cmd->GenerateSourceCode(curPtr);
|
||||
curPtr += cmd->GetCommandSize();
|
||||
size += cmd->GetCommandSize();
|
||||
}
|
||||
|
||||
output += StringHelper::Sprintf(" CS_END(),\n", commands.size(), endFrame);
|
||||
|
@ -105,32 +104,6 @@ std::string ZCutscene::GetBodySourceCode()
|
|||
return output;
|
||||
}
|
||||
|
||||
std::string ZCutscene::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
std::string bodyStr = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
|
||||
if (decl == nullptr)
|
||||
DeclareVar(prefix, bodyStr);
|
||||
else
|
||||
decl->text = bodyStr;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void ZCutscene::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
|
||||
{
|
||||
std::string auxName = name;
|
||||
|
||||
if (auxName == "")
|
||||
auxName = StringHelper::Sprintf("%sCutsceneData0x%06X", prefix.c_str(), rawDataIndex);
|
||||
|
||||
parent->AddDeclarationArray(getSegmentOffset(), DeclarationAlignment::Align4,
|
||||
DeclarationPadding::Pad16, GetRawDataSize(), "s32", auxName, 0,
|
||||
bodyStr);
|
||||
}
|
||||
|
||||
size_t ZCutscene::GetRawDataSize() const
|
||||
{
|
||||
size_t size = 0;
|
||||
|
@ -151,12 +124,6 @@ size_t ZCutscene::GetRawDataSize() const
|
|||
return size;
|
||||
}
|
||||
|
||||
void ZCutscene::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
DeclareVar(parent->GetName(), "");
|
||||
}
|
||||
|
||||
void ZCutscene::ParseRawData()
|
||||
{
|
||||
ZResource::ParseRawData();
|
||||
|
@ -447,7 +414,8 @@ ZResourceType ZCutscene::GetResourceType() const
|
|||
return ZResourceType::Cutscene;
|
||||
}
|
||||
|
||||
CutsceneCommand::CutsceneCommand(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
CutsceneCommand::CutsceneCommand([[maybe_unused]] const std::vector<uint8_t>& rawData,
|
||||
[[maybe_unused]] uint32_t rawDataIndex)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -478,7 +446,7 @@ CutsceneCameraPoint::CutsceneCameraPoint(const std::vector<uint8_t>& rawData, ui
|
|||
continueFlag = data[rawDataIndex + 0];
|
||||
cameraRoll = data[rawDataIndex + 1];
|
||||
nextPointFrame = BitConverter::ToInt16BE(data, rawDataIndex + 2);
|
||||
viewAngle = BitConverter::ToInt32BE(data, rawDataIndex + 4);
|
||||
viewAngle = BitConverter::ToFloatBE(data, rawDataIndex + 4);
|
||||
|
||||
posX = BitConverter::ToInt16BE(data, rawDataIndex + 8);
|
||||
posY = BitConverter::ToInt16BE(data, rawDataIndex + 10);
|
||||
|
@ -522,12 +490,12 @@ std::string CutsceneCommandSetCameraPos::GetCName()
|
|||
return "";
|
||||
}
|
||||
|
||||
std::string CutsceneCommandSetCameraPos::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandSetCameraPos::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
|
||||
std::string listStr = "";
|
||||
std::string posStr = "";
|
||||
std::string listStr;
|
||||
std::string posStr;
|
||||
|
||||
if (commandID == (int32_t)CutsceneCommands::SetCameraFocus)
|
||||
{
|
||||
|
@ -554,11 +522,14 @@ std::string CutsceneCommandSetCameraPos::GenerateSourceCode(uint32_t baseAddress
|
|||
|
||||
for (size_t i = 0; i < entries.size(); i++)
|
||||
{
|
||||
result += StringHelper::Sprintf(" %s(%i, %i, %i, 0x%06X, %i, %i, %i, %i),\n",
|
||||
posStr.c_str(), entries[i]->continueFlag,
|
||||
std::string continueMacro = "CS_CMD_CONTINUE";
|
||||
if (entries[i]->continueFlag != 0)
|
||||
continueMacro = "CS_CMD_STOP";
|
||||
result += StringHelper::Sprintf(" %s(%s, 0x%02X, %i, %ff, %i, %i, %i, 0x%04X),\n",
|
||||
posStr.c_str(), continueMacro.c_str(),
|
||||
entries[i]->cameraRoll, entries[i]->nextPointFrame,
|
||||
*(uint32_t*)&entries[i]->viewAngle, entries[i]->posX,
|
||||
entries[i]->posY, entries[i]->posZ, entries[i]->unused);
|
||||
entries[i]->viewAngle, entries[i]->posX, entries[i]->posY,
|
||||
entries[i]->posZ, entries[i]->unused);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -610,9 +581,9 @@ std::string CutsceneCommandFadeBGM::GetCName()
|
|||
return "CsCmdMusicFade";
|
||||
}
|
||||
|
||||
std::string CutsceneCommandFadeBGM::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandFadeBGM::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
|
||||
result += StringHelper::Sprintf("CS_FADE_BGM_LIST(%i),\n", entries.size());
|
||||
|
||||
|
@ -663,9 +634,9 @@ CutsceneCommandPlayBGM::CutsceneCommandPlayBGM(const std::vector<uint8_t>& rawDa
|
|||
}
|
||||
}
|
||||
|
||||
std::string CutsceneCommandPlayBGM::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandPlayBGM::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
|
||||
result += StringHelper::Sprintf("CS_PLAY_BGM_LIST(%i),\n", entries.size());
|
||||
|
||||
|
@ -706,9 +677,9 @@ CutsceneCommandStopBGM::CutsceneCommandStopBGM(const std::vector<uint8_t>& rawDa
|
|||
}
|
||||
}
|
||||
|
||||
std::string CutsceneCommandStopBGM::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandStopBGM::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
|
||||
result += StringHelper::Sprintf("CS_STOP_BGM_LIST(%i),\n", entries.size());
|
||||
|
||||
|
@ -764,9 +735,9 @@ CutsceneCommandEnvLighting::CutsceneCommandEnvLighting(const std::vector<uint8_t
|
|||
}
|
||||
}
|
||||
|
||||
std::string CutsceneCommandEnvLighting::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandEnvLighting::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
|
||||
result += StringHelper::Sprintf("CS_LIGHTING_LIST(%i),\n", entries.size());
|
||||
|
||||
|
@ -820,9 +791,9 @@ CutsceneCommandUnknown9::CutsceneCommandUnknown9(const std::vector<uint8_t>& raw
|
|||
}
|
||||
}
|
||||
|
||||
std::string CutsceneCommandUnknown9::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandUnknown9::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
|
||||
result += StringHelper::Sprintf("CS_CMD_09_LIST(%i),\n", entries.size());
|
||||
|
||||
|
@ -878,9 +849,9 @@ CutsceneCommandUnknown::CutsceneCommandUnknown(const std::vector<uint8_t>& rawDa
|
|||
}
|
||||
}
|
||||
|
||||
std::string CutsceneCommandUnknown::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandUnknown::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
|
||||
result += StringHelper::Sprintf("CS_UNK_DATA_LIST(0x%02X, %i),\n", commandID, entries.size());
|
||||
|
||||
|
@ -936,9 +907,9 @@ std::string CutsceneCommandDayTime::GetCName()
|
|||
return "CsCmdDayTime";
|
||||
}
|
||||
|
||||
std::string CutsceneCommandDayTime::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandDayTime::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
|
||||
result += StringHelper::Sprintf("CS_TIME_LIST(%i),\n", entries.size());
|
||||
|
||||
|
@ -987,9 +958,9 @@ std::string CutsceneCommandTextbox::GetCName()
|
|||
return "CsCmdTextbox";
|
||||
}
|
||||
|
||||
std::string CutsceneCommandTextbox::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandTextbox::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
|
||||
result += StringHelper::Sprintf("CS_TEXT_LIST(%i),\n", entries.size());
|
||||
|
||||
|
@ -1033,9 +1004,9 @@ ActorAction::ActorAction(const std::vector<uint8_t>& rawData, uint32_t rawDataIn
|
|||
endPosX = BitConverter::ToInt32BE(data, rawDataIndex + 24);
|
||||
endPosY = BitConverter::ToInt32BE(data, rawDataIndex + 28);
|
||||
endPosZ = BitConverter::ToInt32BE(data, rawDataIndex + 32);
|
||||
normalX = BitConverter::ToInt32BE(data, rawDataIndex + 36);
|
||||
normalY = BitConverter::ToInt32BE(data, rawDataIndex + 40);
|
||||
normalZ = BitConverter::ToInt32BE(data, rawDataIndex + 44);
|
||||
normalX = BitConverter::ToFloatBE(data, rawDataIndex + 36);
|
||||
normalY = BitConverter::ToFloatBE(data, rawDataIndex + 40);
|
||||
normalZ = BitConverter::ToFloatBE(data, rawDataIndex + 44);
|
||||
}
|
||||
|
||||
CutsceneCommandActorAction::CutsceneCommandActorAction(const std::vector<uint8_t>& rawData,
|
||||
|
@ -1053,10 +1024,10 @@ CutsceneCommandActorAction::CutsceneCommandActorAction(const std::vector<uint8_t
|
|||
}
|
||||
}
|
||||
|
||||
std::string CutsceneCommandActorAction::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandActorAction::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string subCommand = "";
|
||||
std::string result;
|
||||
std::string subCommand;
|
||||
|
||||
if (commandID == 10)
|
||||
{
|
||||
|
@ -1072,13 +1043,12 @@ std::string CutsceneCommandActorAction::GenerateSourceCode(uint32_t baseAddress)
|
|||
for (size_t i = 0; i < entries.size(); i++)
|
||||
{
|
||||
result += StringHelper::Sprintf(
|
||||
" CS_NPC_ACTION(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %i, "
|
||||
"%i, %i),\n",
|
||||
entries[i]->action, entries[i]->startFrame, entries[i]->endFrame, entries[i]->rotX,
|
||||
entries[i]->rotY, entries[i]->rotZ, entries[i]->startPosX, entries[i]->startPosY,
|
||||
entries[i]->startPosZ, entries[i]->endPosX, entries[i]->endPosY, entries[i]->endPosZ,
|
||||
*(int32_t*)&entries[i]->normalX, *(int32_t*)&entries[i]->normalY,
|
||||
*(int32_t*)&entries[i]->normalZ);
|
||||
"\t\t%s(0x%04X, %i, %i, 0x%04X, 0x%04X, 0x%04X, %i, %i, %i, %i, %i, %i, %.11ef, "
|
||||
"%.11ef, %.11ef),\n",
|
||||
subCommand.c_str(), entries[i]->action, entries[i]->startFrame, entries[i]->endFrame,
|
||||
entries[i]->rotX, entries[i]->rotY, entries[i]->rotZ, entries[i]->startPosX,
|
||||
entries[i]->startPosY, entries[i]->startPosZ, entries[i]->endPosX, entries[i]->endPosY,
|
||||
entries[i]->endPosZ, entries[i]->normalX, entries[i]->normalY, entries[i]->normalZ);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -1111,9 +1081,9 @@ std::string CutsceneCommandTerminator::GetCName()
|
|||
return "CsCmdBase";
|
||||
}
|
||||
|
||||
std::string CutsceneCommandTerminator::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandTerminator::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
|
||||
result += StringHelper::Sprintf("CS_TERMINATOR(0x%04X, %i, %i),\n", base, startFrame, endFrame);
|
||||
|
||||
|
@ -1133,9 +1103,9 @@ CutsceneCommandEnd::CutsceneCommandEnd(const std::vector<uint8_t>& rawData, uint
|
|||
endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
|
||||
}
|
||||
|
||||
std::string CutsceneCommandEnd::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandEnd::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
|
||||
result += StringHelper::Sprintf("CS_END(),\n");
|
||||
|
||||
|
@ -1187,9 +1157,9 @@ CutsceneCommandSpecialAction::CutsceneCommandSpecialAction(const std::vector<uin
|
|||
}
|
||||
}
|
||||
|
||||
std::string CutsceneCommandSpecialAction::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandSpecialAction::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
std::string result = "";
|
||||
std::string result;
|
||||
|
||||
result += StringHelper::Sprintf("CS_MISC_LIST(%i),\n", entries.size());
|
||||
|
||||
|
@ -1246,7 +1216,7 @@ CutsceneCommandSceneTransFX::CutsceneCommandSceneTransFX(const std::vector<uint8
|
|||
endFrame = (uint16_t)BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
|
||||
}
|
||||
|
||||
std::string CutsceneCommandSceneTransFX::GenerateSourceCode(uint32_t baseAddress)
|
||||
std::string CutsceneCommandSceneTransFX::GenerateSourceCode([[maybe_unused]] uint32_t baseAddress)
|
||||
{
|
||||
return StringHelper::Sprintf("CS_SCENE_TRANS_FX(%i, %i, %i),\n", base, startFrame, endFrame);
|
||||
}
|
||||
|
@ -1264,3 +1234,22 @@ size_t CutsceneCommandSceneTransFX::GetCommandSize()
|
|||
ZCutsceneBase::ZCutsceneBase(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
Declaration* ZCutsceneBase::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
{
|
||||
std::string auxName = name;
|
||||
|
||||
if (auxName == "")
|
||||
auxName = GetDefaultName(prefix);
|
||||
|
||||
Declaration* decl =
|
||||
parent->AddDeclarationArray(rawDataIndex, GetDeclarationAlignment(), GetRawDataSize(),
|
||||
GetSourceTypeName(), auxName, 0, bodyStr);
|
||||
decl->staticConf = staticConf;
|
||||
return decl;
|
||||
}
|
||||
|
||||
std::string ZCutsceneBase::GetSourceTypeName() const
|
||||
{
|
||||
return "CutsceneData";
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
int8_t continueFlag;
|
||||
int8_t cameraRoll;
|
||||
int16_t nextPointFrame;
|
||||
uint32_t viewAngle;
|
||||
float viewAngle;
|
||||
int16_t posX, posY, posZ;
|
||||
int16_t unused;
|
||||
|
||||
|
@ -352,7 +352,7 @@ public:
|
|||
int16_t rotX, rotY, rotZ;
|
||||
int32_t startPosX, startPosY, startPosZ;
|
||||
int32_t endPosX, endPosY, endPosZ;
|
||||
int32_t normalX, normalY, normalZ;
|
||||
float normalX, normalY, normalZ;
|
||||
|
||||
ActorAction(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
};
|
||||
|
@ -412,9 +412,10 @@ class ZCutsceneBase : public ZResource
|
|||
{
|
||||
public:
|
||||
ZCutsceneBase(ZFile* nParent);
|
||||
virtual std::string GetBodySourceCode() = 0;
|
||||
virtual void DeclareVar(const std::string& prefix, const std::string& bodyStr) const = 0;
|
||||
virtual uint32_t getSegmentOffset() const = 0;
|
||||
|
||||
Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
};
|
||||
|
||||
class ZCutscene : public ZCutsceneBase
|
||||
|
@ -425,18 +426,14 @@ public:
|
|||
|
||||
void ParseRawData() override;
|
||||
|
||||
std::string GetBodySourceCode() override;
|
||||
void DeclareVar(const std::string& prefix, const std::string& bodyStr) const override;
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
CutsceneCommands GetCommandFromID(int32_t id);
|
||||
uint32_t getSegmentOffset() const override { return rawDataIndex; }
|
||||
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
CutsceneCommands GetCommandFromID(int32_t id);
|
||||
|
||||
protected:
|
||||
int32_t numCommands;
|
||||
int32_t endFrame;
|
||||
std::vector<CutsceneCommand*> commands;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "ZCutsceneMM.h"
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
|
||||
ZCutsceneMM::ZCutsceneMM(ZFile* nParent) : ZCutsceneBase(nParent)
|
||||
{
|
||||
|
@ -12,9 +13,9 @@ ZCutsceneMM::~ZCutsceneMM()
|
|||
delete cmd;
|
||||
}
|
||||
|
||||
std::string ZCutsceneMM::GetBodySourceCode()
|
||||
std::string ZCutsceneMM::GetBodySourceCode() const
|
||||
{
|
||||
std::string output = "";
|
||||
std::string output;
|
||||
|
||||
output += StringHelper::Sprintf(" CS_BEGIN_CUTSCENE(%i, %i),", numCommands, endFrame);
|
||||
|
||||
|
@ -22,51 +23,19 @@ std::string ZCutsceneMM::GetBodySourceCode()
|
|||
{
|
||||
if ((i % 4) == 0)
|
||||
output += "\n ";
|
||||
output += StringHelper::Sprintf("0x%08X,", data[i]);
|
||||
output += StringHelper::Sprintf("0x%08X, ", data[i]);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string ZCutsceneMM::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
std::string bodyStr = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
|
||||
if (decl == nullptr)
|
||||
DeclareVar(prefix, bodyStr);
|
||||
else
|
||||
decl->text = bodyStr;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void ZCutsceneMM::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
|
||||
{
|
||||
std::string auxName = name;
|
||||
|
||||
if (auxName == "")
|
||||
auxName = StringHelper::Sprintf("%sCutsceneData0x%06X", prefix.c_str(), rawDataIndex);
|
||||
|
||||
parent->AddDeclarationArray(getSegmentOffset(), DeclarationAlignment::Align4, GetRawDataSize(),
|
||||
"s32", auxName, 0, bodyStr);
|
||||
}
|
||||
|
||||
size_t ZCutsceneMM::GetRawDataSize() const
|
||||
{
|
||||
return 8 + data.size() * 4;
|
||||
}
|
||||
|
||||
void ZCutsceneMM::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
DeclareVar(parent->GetName(), "");
|
||||
}
|
||||
|
||||
void ZCutsceneMM::ParseRawData()
|
||||
{
|
||||
segmentOffset = rawDataIndex;
|
||||
const auto& rawData = parent->GetRawData();
|
||||
|
||||
numCommands = BitConverter::ToInt32BE(rawData, rawDataIndex + 0);
|
||||
|
|
|
@ -10,22 +10,16 @@
|
|||
class ZCutsceneMM : public ZCutsceneBase
|
||||
{
|
||||
public:
|
||||
uint32_t segmentOffset;
|
||||
|
||||
ZCutsceneMM(ZFile* nParent);
|
||||
virtual ~ZCutsceneMM();
|
||||
|
||||
std::string GetBodySourceCode() override;
|
||||
void DeclareVar(const std::string& prefix, const std::string& bodyStr) const override;
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
uint32_t getSegmentOffset() const override { return segmentOffset; }
|
||||
|
||||
void ParseRawData() override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
protected:
|
||||
int32_t numCommands;
|
||||
int32_t endFrame;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -288,14 +288,15 @@ class ZDisplayList : public ZResource
|
|||
protected:
|
||||
static TextureType TexFormatToTexType(F3DZEXTexFormats fmt, F3DZEXTexSizes siz);
|
||||
|
||||
void ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int32_t i, std::string prefix, char* line);
|
||||
void ParseF3DEX(F3DEXOpcode opcode, uint64_t data, std::string prefix, char* line);
|
||||
void ParseF3DZEX(F3DZEXOpcode opcode, uint64_t data, int32_t i, const std::string& prefix,
|
||||
char* line);
|
||||
void ParseF3DEX(F3DEXOpcode opcode, uint64_t data, const std::string& prefix, char* line);
|
||||
|
||||
// Various Instruction Optimizations
|
||||
bool SequenceCheck(std::vector<F3DZEXOpcode> sequence, int32_t startIndex);
|
||||
int32_t OptimizationChecks(int32_t startIndex, std::string& output, std::string prefix);
|
||||
int32_t OptimizationChecks(int32_t startIndex, std::string& output, const std::string& prefix);
|
||||
int32_t OptimizationCheck_LoadTextureBlock(int32_t startIndex, std::string& output,
|
||||
std::string prefix);
|
||||
const std::string& prefix);
|
||||
// int32_t OptimizationCheck_LoadMultiBlock(int32_t startIndex, std::string& output, std::string
|
||||
// prefix);
|
||||
|
||||
|
@ -303,7 +304,7 @@ protected:
|
|||
void Opcode_F3DEX_G_SETOTHERMODE_L(uint64_t data, char* line);
|
||||
|
||||
// Shared Opcodes between F3DZEX and F3DEX
|
||||
void Opcode_G_DL(uint64_t data, std::string prefix, char* line);
|
||||
void Opcode_G_DL(uint64_t data, const std::string& prefix, char* line);
|
||||
void Opcode_G_MODIFYVTX(uint64_t data, char* line);
|
||||
void Opcode_G_CULLDL(uint64_t data, char* line);
|
||||
void Opcode_G_TRI1(uint64_t data, char* line);
|
||||
|
@ -311,22 +312,19 @@ protected:
|
|||
void Opcode_G_MTX(uint64_t data, char* line);
|
||||
void Opcode_G_VTX(uint64_t data, char* line);
|
||||
void Opcode_G_TEXTURE(uint64_t data, char* line);
|
||||
void Opcode_G_SETTIMG(uint64_t data, std::string prefix, char* line);
|
||||
void Opcode_G_SETTIMG(uint64_t data, const std::string& prefix, char* line);
|
||||
void Opcode_G_SETTILE(uint64_t data, char* line);
|
||||
void Opcode_G_SETTILESIZE(uint64_t data, std::string prefix, char* line);
|
||||
void Opcode_G_SETTILESIZE(uint64_t data, const std::string& prefix, char* line);
|
||||
void Opcode_G_LOADBLOCK(uint64_t data, char* line);
|
||||
void Opcode_G_SETCOMBINE(uint64_t data, char* line);
|
||||
void Opcode_G_SETPRIMCOLOR(uint64_t data, char* line);
|
||||
void Opcode_G_SETOTHERMODE_L(uint64_t data, char* line);
|
||||
void Opcode_G_SETOTHERMODE_H(uint64_t data, char* line);
|
||||
void Opcode_G_LOADTLUT(uint64_t data, std::string prefix, char* line);
|
||||
void Opcode_G_ENDDL(std::string prefix, char* line);
|
||||
void Opcode_G_LOADTLUT(uint64_t data, const std::string& prefix, char* line);
|
||||
void Opcode_G_ENDDL(const std::string& prefix, char* line);
|
||||
|
||||
public:
|
||||
std::string sceneSegName;
|
||||
ZRoom* scene;
|
||||
std::vector<uint64_t> instructions;
|
||||
std::string curPrefix;
|
||||
|
||||
int32_t lastTexWidth, lastTexHeight, lastTexAddr, lastTexSeg;
|
||||
F3DZEXTexFormats lastTexFmt;
|
||||
|
@ -337,44 +335,41 @@ public:
|
|||
DListType dListType;
|
||||
|
||||
std::map<uint32_t, std::vector<ZVtx>> vertices;
|
||||
std::map<uint32_t, std::string> vtxDeclarations;
|
||||
std::vector<ZDisplayList*> otherDLists;
|
||||
|
||||
ZTexture* lastTexture = nullptr;
|
||||
ZTexture* lastTlut = nullptr;
|
||||
|
||||
std::vector<uint32_t> references;
|
||||
|
||||
std::string defines; // Hack for special cases where vertex arrays intersect...
|
||||
std::vector<segptr_t> references;
|
||||
std::vector<ZMtx> mtxList;
|
||||
|
||||
ZDisplayList(ZFile* nParent);
|
||||
ZDisplayList(uint32_t rawDataIndex, int32_t rawDataSize, ZFile* nParent);
|
||||
~ZDisplayList();
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
void ExtractFromBinary(uint32_t nRawDataIndex, int32_t rawDataSize);
|
||||
|
||||
void ParseRawData() override;
|
||||
|
||||
Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr);
|
||||
Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
|
||||
std::string GetDefaultName(const std::string& prefix) const override;
|
||||
|
||||
void TextureGenCheck(std::string prefix);
|
||||
static bool TextureGenCheck(ZRoom* scene, ZFile* parent, std::string prefix, int32_t texWidth,
|
||||
int32_t texHeight, uint32_t texAddr, uint32_t texSeg,
|
||||
F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz, bool texLoaded,
|
||||
bool texIsPalette, ZDisplayList* self);
|
||||
void TextureGenCheck();
|
||||
static bool TextureGenCheck(int32_t texWidth, int32_t texHeight, uint32_t texAddr,
|
||||
uint32_t texSeg, F3DZEXTexFormats texFmt, F3DZEXTexSizes texSiz,
|
||||
bool texLoaded, bool texIsPalette, ZDisplayList* self);
|
||||
static int32_t GetDListLength(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex,
|
||||
DListType dListType);
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
DeclarationAlignment GetDeclarationAlignment() const override;
|
||||
std::string GetSourceOutputHeader(const std::string& prefix) override;
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
std::string ProcessLegacy(const std::string& prefix);
|
||||
std::string ProcessGfxDis(const std::string& prefix);
|
||||
|
||||
virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile) override;
|
||||
bool IsExternalResource() const override;
|
||||
virtual std::string GetExternalExtension() const override;
|
||||
std::string GetExternalExtension() const override;
|
||||
std::string GetSourceTypeName() const override;
|
||||
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <Utils/Directory.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Directory.h"
|
||||
#include "ZResource.h"
|
||||
|
||||
#include "ZSymbol.h"
|
||||
#include "ZTexture.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
|
@ -11,13 +12,13 @@ enum class ZFileMode
|
|||
{
|
||||
BuildTexture,
|
||||
BuildOverlay,
|
||||
BuildModelIntermediette,
|
||||
BuildAnimationIntermediette,
|
||||
BuildBlob,
|
||||
BuildSourceFile,
|
||||
BuildBackground,
|
||||
Extract,
|
||||
Invalid
|
||||
ExternalFile,
|
||||
Invalid,
|
||||
Custom = 1000, // Used for exporter file modes
|
||||
};
|
||||
|
||||
enum class ZGame
|
||||
|
@ -30,19 +31,20 @@ enum class ZGame
|
|||
class ZFile
|
||||
{
|
||||
public:
|
||||
std::map<uint32_t, Declaration*> declarations;
|
||||
std::map<offset_t, Declaration*> declarations;
|
||||
std::string defines;
|
||||
std::vector<ZResource*> resources;
|
||||
uint32_t segment;
|
||||
uint32_t baseAddress, rangeStart, rangeEnd;
|
||||
bool isExternalFile = false;
|
||||
|
||||
ZFile(std::string nName);
|
||||
ZFile(ZFileMode mode, tinyxml2::XMLElement* reader, const fs::path& nBasePath,
|
||||
std::string filename, const fs::path& nXmlFilePath, bool placeholderMode);
|
||||
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);
|
||||
~ZFile();
|
||||
|
||||
std::string GetVarName(uint32_t address);
|
||||
std::string GetName() const;
|
||||
ZFileMode GetMode() const;
|
||||
const fs::path& GetXmlFilePath() const;
|
||||
const std::vector<uint8_t>& GetRawData() const;
|
||||
void ExtractResources();
|
||||
|
@ -51,45 +53,54 @@ public:
|
|||
ZResource* FindResource(uint32_t rawDataIndex);
|
||||
std::vector<ZResource*> GetResourcesOfType(ZResourceType resType);
|
||||
|
||||
Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment, size_t size,
|
||||
std::string varType, std::string varName, std::string body);
|
||||
Declaration* AddDeclaration(uint32_t address, DeclarationAlignment alignment,
|
||||
DeclarationPadding padding, size_t size, std::string varType,
|
||||
std::string varName, std::string body);
|
||||
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, size_t size,
|
||||
std::string varType, std::string varName, size_t arrayItemCnt,
|
||||
std::string body);
|
||||
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, size_t size,
|
||||
std::string varType, std::string varName, size_t arrayItemCnt,
|
||||
std::string body, bool isExternal);
|
||||
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment, size_t size,
|
||||
std::string varType, std::string varName,
|
||||
std::string arrayItemCntStr, std::string body);
|
||||
Declaration* AddDeclarationArray(uint32_t address, DeclarationAlignment alignment,
|
||||
DeclarationPadding padding, size_t size, std::string varType,
|
||||
std::string varName, size_t arrayItemCnt, std::string body);
|
||||
Declaration* AddDeclarationPlaceholder(uint32_t address);
|
||||
Declaration* AddDeclarationPlaceholder(uint32_t address, std::string varName);
|
||||
Declaration* AddDeclarationInclude(uint32_t address, std::string includePath, size_t size,
|
||||
std::string varType, std::string varName);
|
||||
Declaration* AddDeclarationIncludeArray(uint32_t address, std::string includePath, size_t size,
|
||||
std::string varType, std::string varName,
|
||||
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);
|
||||
std::string GetDeclarationName(uint32_t address) const;
|
||||
std::string GetDeclarationName(uint32_t address, std::string defaultResult) const;
|
||||
std::string GetDeclarationPtrName(segptr_t segAddress) const;
|
||||
|
||||
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(uint32_t address) const;
|
||||
Declaration* GetDeclarationRanged(uint32_t address) const;
|
||||
uint32_t GetDeclarationRangedAddress(uint32_t address) const;
|
||||
bool HasDeclaration(uint32_t address);
|
||||
std::string GetHeaderInclude();
|
||||
|
||||
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);
|
||||
|
||||
|
@ -98,23 +109,27 @@ protected:
|
|||
std::string name;
|
||||
fs::path outName = "";
|
||||
fs::path basePath;
|
||||
fs::path outputPath;
|
||||
fs::path xmlFilePath;
|
||||
|
||||
// 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(ZFileMode mode, tinyxml2::XMLElement* reader, std::string filename,
|
||||
bool placeholderMode);
|
||||
void ParseXML(tinyxml2::XMLElement* reader, const std::string& filename);
|
||||
void DeclareResourceSubReferences();
|
||||
void GenerateSourceFiles(fs::path outputDir);
|
||||
void GenerateSourceFiles();
|
||||
void GenerateSourceHeaderFiles();
|
||||
void GenerateHLIntermediette();
|
||||
void AddDeclarationDebugChecks(uint32_t address);
|
||||
bool AddDeclarationChecks(uint32_t address, const std::string& varName);
|
||||
std::string ProcessDeclarations();
|
||||
void ProcessDeclarationText(Declaration* decl);
|
||||
std::string ProcessExterns();
|
||||
|
||||
std::string ProcessTextureIntersections(std::string prefix);
|
||||
std::string ProcessTextureIntersections(const std::string& prefix);
|
||||
void HandleUnaccountedData();
|
||||
bool HandleUnaccountedAddress(uint32_t currentAddress, uint32_t lastAddr, uint32_t& lastSize);
|
||||
};
|
||||
|
|
|
@ -1,379 +1,31 @@
|
|||
#include "ZLimb.h"
|
||||
|
||||
#include <cassert>
|
||||
#include "BitConverter.h"
|
||||
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
|
||||
REGISTER_ZFILENODE(Limb, ZLimb);
|
||||
|
||||
Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset)
|
||||
ZLimb::ZLimb(ZFile* nParent) : ZResource(nParent), segmentStruct(nParent)
|
||||
{
|
||||
unk_0 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x00);
|
||||
unk_2 = BitConverter::ToInt16BE(rawData, fileOffset + 0x02);
|
||||
unk_4 = BitConverter::ToInt16BE(rawData, fileOffset + 0x04);
|
||||
unk_6 = BitConverter::ToInt8BE(rawData, fileOffset + 0x06);
|
||||
unk_7 = BitConverter::ToInt8BE(rawData, fileOffset + 0x07);
|
||||
unk_8 = BitConverter::ToInt8BE(rawData, fileOffset + 0x08);
|
||||
unk_9 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x09);
|
||||
}
|
||||
Struct_800A57C0::Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset,
|
||||
size_t index)
|
||||
: Struct_800A57C0(rawData, fileOffset + index * GetRawDataSize())
|
||||
{
|
||||
}
|
||||
|
||||
std::string Struct_800A57C0::GetSourceOutputCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("0x%02X, %i, %i, %i, %i, %i, 0x%02X", unk_0, unk_2, unk_4, unk_6,
|
||||
unk_7, unk_8, unk_9);
|
||||
}
|
||||
|
||||
size_t Struct_800A57C0::GetRawDataSize()
|
||||
{
|
||||
return 0x0A;
|
||||
}
|
||||
|
||||
std::string Struct_800A57C0::GetSourceTypeName()
|
||||
{
|
||||
return "Struct_800A57C0";
|
||||
}
|
||||
|
||||
Struct_800A598C_2::Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset)
|
||||
{
|
||||
unk_0 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x00);
|
||||
x = BitConverter::ToInt16BE(rawData, fileOffset + 0x02);
|
||||
y = BitConverter::ToInt16BE(rawData, fileOffset + 0x04);
|
||||
z = BitConverter::ToInt16BE(rawData, fileOffset + 0x06);
|
||||
unk_8 = BitConverter::ToUInt8BE(rawData, fileOffset + 0x08);
|
||||
}
|
||||
Struct_800A598C_2::Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset,
|
||||
size_t index)
|
||||
: Struct_800A598C_2(rawData, fileOffset + index * GetRawDataSize())
|
||||
{
|
||||
}
|
||||
|
||||
std::string Struct_800A598C_2::GetSourceOutputCode() const
|
||||
{
|
||||
return StringHelper::Sprintf("0x%02X, %i, %i, %i, 0x%02X", unk_0, x, y, z, unk_8);
|
||||
}
|
||||
|
||||
size_t Struct_800A598C_2::GetRawDataSize()
|
||||
{
|
||||
return 0x0A;
|
||||
}
|
||||
|
||||
std::string Struct_800A598C_2::GetSourceTypeName()
|
||||
{
|
||||
return "Struct_800A598C_2";
|
||||
}
|
||||
|
||||
Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData,
|
||||
uint32_t fileOffset)
|
||||
: parent(parent)
|
||||
{
|
||||
unk_0 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x00);
|
||||
unk_2 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x02);
|
||||
unk_4 = BitConverter::ToUInt16BE(rawData, fileOffset + 0x04);
|
||||
unk_8 = BitConverter::ToUInt32BE(rawData, fileOffset + 0x08);
|
||||
unk_C = BitConverter::ToUInt32BE(rawData, fileOffset + 0x0C);
|
||||
|
||||
if (unk_8 != 0)
|
||||
{
|
||||
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
|
||||
for (size_t i = 0; i < unk_0; i++)
|
||||
{
|
||||
unk_8_arr.emplace_back(rawData, unk_8_Offset, i);
|
||||
}
|
||||
}
|
||||
|
||||
if (unk_C != 0)
|
||||
{
|
||||
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
|
||||
for (size_t i = 0; i < unk_2; i++)
|
||||
{
|
||||
unk_C_arr.emplace_back(rawData, unk_C_Offset, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
Struct_800A598C::Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData,
|
||||
uint32_t fileOffset, size_t index)
|
||||
: Struct_800A598C(parent, rawData, fileOffset + index * GetRawDataSize())
|
||||
{
|
||||
}
|
||||
|
||||
void Struct_800A598C::PreGenSourceFiles(const std::string& prefix)
|
||||
{
|
||||
std::string entryStr;
|
||||
|
||||
if (unk_8 != 0)
|
||||
{
|
||||
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
|
||||
std::string unk_8_Str =
|
||||
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
|
||||
Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
|
||||
|
||||
size_t arrayItemCnt = unk_8_arr.size();
|
||||
entryStr = "";
|
||||
size_t i = 0;
|
||||
|
||||
for (auto& child : unk_8_arr)
|
||||
{
|
||||
entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode().c_str(),
|
||||
(++i < arrayItemCnt) ? "\n" : "");
|
||||
}
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(unk_8_Offset);
|
||||
|
||||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclarationArray(unk_8_Offset, DeclarationAlignment::None,
|
||||
arrayItemCnt * Struct_800A57C0::GetRawDataSize(),
|
||||
Struct_800A57C0::GetSourceTypeName(), unk_8_Str,
|
||||
arrayItemCnt, entryStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
decl->text = entryStr;
|
||||
}
|
||||
}
|
||||
|
||||
if (unk_C != 0)
|
||||
{
|
||||
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
|
||||
std::string unk_C_Str =
|
||||
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
|
||||
Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset);
|
||||
|
||||
size_t arrayItemCnt = unk_C_arr.size();
|
||||
entryStr = "";
|
||||
size_t i = 0;
|
||||
|
||||
for (auto& child : unk_C_arr)
|
||||
{
|
||||
entryStr += StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode().c_str(),
|
||||
(++i < arrayItemCnt) ? "\n" : "");
|
||||
}
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(unk_C_Offset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclarationArray(unk_C_Offset, DeclarationAlignment::None,
|
||||
arrayItemCnt * Struct_800A598C_2::GetRawDataSize(),
|
||||
Struct_800A598C_2::GetSourceTypeName(), unk_C_Str,
|
||||
arrayItemCnt, entryStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
decl->text = entryStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string Struct_800A598C::GetSourceOutputCode(const std::string& prefix) const
|
||||
{
|
||||
std::string entryStr;
|
||||
|
||||
std::string unk_8_Str = "NULL";
|
||||
|
||||
if (unk_8 != 0)
|
||||
{
|
||||
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
|
||||
unk_8_Str =
|
||||
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
|
||||
Struct_800A57C0::GetSourceTypeName().c_str(), unk_8_Offset);
|
||||
}
|
||||
|
||||
std::string unk_C_Str = "NULL";
|
||||
|
||||
if (unk_C != 0)
|
||||
{
|
||||
uint32_t unk_C_Offset = Seg2Filespace(unk_C, parent->baseAddress);
|
||||
unk_C_Str =
|
||||
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
|
||||
Struct_800A598C_2::GetSourceTypeName().c_str(), unk_C_Offset);
|
||||
}
|
||||
|
||||
entryStr = StringHelper::Sprintf("\n ARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n",
|
||||
unk_8_Str.c_str(), unk_C_Str.c_str());
|
||||
entryStr += StringHelper::Sprintf(" %i, %s, %s\n ", unk_4, unk_8_Str.c_str(),
|
||||
unk_C_Str.c_str());
|
||||
entryStr = StringHelper::Sprintf("\n ARRAY_COUNTU(%s), ARRAY_COUNTU(%s),\n",
|
||||
unk_8_Str.c_str(), unk_C_Str.c_str());
|
||||
entryStr += StringHelper::Sprintf(" %i, %s, %s\n ", unk_4, unk_8_Str.c_str(),
|
||||
unk_C_Str.c_str());
|
||||
|
||||
return entryStr;
|
||||
}
|
||||
|
||||
size_t Struct_800A598C::GetRawDataSize()
|
||||
{
|
||||
return 0x10;
|
||||
}
|
||||
|
||||
std::string Struct_800A598C::GetSourceTypeName()
|
||||
{
|
||||
return "Struct_800A598C";
|
||||
}
|
||||
|
||||
Struct_800A5E28::Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t fileOffset)
|
||||
: parent(parent)
|
||||
{
|
||||
unk_0 = BitConverter::ToUInt16BE(nRawData, fileOffset + 0x00);
|
||||
unk_2 = BitConverter::ToUInt16BE(nRawData, fileOffset + 0x02);
|
||||
unk_4 = BitConverter::ToUInt32BE(nRawData, fileOffset + 0x04);
|
||||
unk_8 = BitConverter::ToUInt32BE(nRawData, fileOffset + 0x08);
|
||||
|
||||
if (unk_4 != 0)
|
||||
{
|
||||
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
|
||||
|
||||
for (size_t i = 0; i < unk_2; i++)
|
||||
{
|
||||
unk_4_arr.emplace_back(parent, nRawData, unk_4_Offset, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Struct_800A5E28::~Struct_800A5E28()
|
||||
{
|
||||
delete unk_8_dlist;
|
||||
}
|
||||
|
||||
void Struct_800A5E28::PreGenSourceFiles(const std::string& prefix)
|
||||
{
|
||||
if (unk_4 != 0)
|
||||
{
|
||||
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
|
||||
std::string unk_4_Str =
|
||||
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
|
||||
Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset);
|
||||
|
||||
std::string entryStr = "";
|
||||
uint16_t arrayItemCnt = unk_4_arr.size();
|
||||
|
||||
size_t i = 0;
|
||||
|
||||
for (auto& child : unk_4_arr)
|
||||
{
|
||||
child.PreGenSourceFiles(prefix);
|
||||
entryStr +=
|
||||
StringHelper::Sprintf(" { %s },%s", child.GetSourceOutputCode(prefix).c_str(),
|
||||
(++i < arrayItemCnt) ? "\n" : "");
|
||||
}
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(unk_4_Offset);
|
||||
|
||||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclarationArray(unk_4_Offset, DeclarationAlignment::None,
|
||||
arrayItemCnt * Struct_800A598C::GetRawDataSize(),
|
||||
Struct_800A598C::GetSourceTypeName(), unk_4_Str,
|
||||
arrayItemCnt, entryStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
decl->text = entryStr;
|
||||
}
|
||||
}
|
||||
|
||||
if (unk_8 != 0)
|
||||
{
|
||||
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
|
||||
|
||||
int32_t dlistLength = ZDisplayList::GetDListLength(
|
||||
parent->GetRawData(), unk_8_Offset,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
unk_8_dlist = new ZDisplayList(unk_8_Offset, dlistLength, parent);
|
||||
|
||||
std::string dListStr =
|
||||
StringHelper::Sprintf("%sSkinLimbDL_%06X", prefix.c_str(), unk_8_Offset);
|
||||
unk_8_dlist->SetName(dListStr);
|
||||
unk_8_dlist->GetSourceOutputCode(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Struct_800A5E28::GetSourceOutputCode(const std::string& prefix) const
|
||||
{
|
||||
std::string entryStr = "";
|
||||
|
||||
std::string unk_4_Str = "NULL";
|
||||
|
||||
if (unk_4 != 0)
|
||||
{
|
||||
uint32_t unk_4_Offset = Seg2Filespace(unk_4, parent->baseAddress);
|
||||
Declaration* decl = parent->GetDeclaration(unk_4_Offset);
|
||||
|
||||
if (decl == nullptr)
|
||||
{
|
||||
unk_4_Str =
|
||||
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
|
||||
Struct_800A598C::GetSourceTypeName().c_str(), unk_4_Offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
unk_4_Str = decl->varName;
|
||||
}
|
||||
}
|
||||
|
||||
std::string unk_8_Str = "NULL";
|
||||
if (unk_8 != 0)
|
||||
{
|
||||
uint32_t unk_8_Offset = Seg2Filespace(unk_8, parent->baseAddress);
|
||||
Declaration* decl = parent->GetDeclaration(unk_8_Offset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
// Something went wrong...
|
||||
unk_8_Str = StringHelper::Sprintf("0x%08X", unk_8);
|
||||
}
|
||||
else
|
||||
{
|
||||
unk_8_Str = decl->varName;
|
||||
}
|
||||
}
|
||||
|
||||
return StringHelper::Sprintf("\n %i, ARRAY_COUNTU(%s),\n %s, %s\n", unk_0,
|
||||
unk_4_Str.c_str(), unk_4_Str.c_str(), unk_8_Str.c_str());
|
||||
}
|
||||
|
||||
size_t Struct_800A5E28::GetRawDataSize()
|
||||
{
|
||||
return 0x0C;
|
||||
}
|
||||
|
||||
std::string Struct_800A5E28::GetSourceTypeName()
|
||||
{
|
||||
return "Struct_800A5E28";
|
||||
}
|
||||
|
||||
ZLimb::ZLimb(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
dListPtr = 0;
|
||||
dList2Ptr = 0;
|
||||
RegisterOptionalAttribute("LimbType");
|
||||
RegisterOptionalAttribute("Type");
|
||||
}
|
||||
|
||||
ZLimb::ZLimb(ZLimbType limbType, const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent)
|
||||
: ZLimb(nParent)
|
||||
void ZLimb::ExtractFromBinary(uint32_t nRawDataIndex, ZLimbType nType)
|
||||
{
|
||||
rawDataIndex = nRawDataIndex;
|
||||
parent = nParent;
|
||||
type = limbType;
|
||||
type = nType;
|
||||
|
||||
name = StringHelper::Sprintf("%sLimb_%06X", prefix.c_str(), GetFileAddress());
|
||||
// Don't parse raw data of external files
|
||||
if (parent->GetMode() == ZFileMode::ExternalFile)
|
||||
return;
|
||||
|
||||
ParseRawData();
|
||||
}
|
||||
|
||||
void ZLimb::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
|
||||
parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, "");
|
||||
}
|
||||
|
||||
void ZLimb::ParseXML(tinyxml2::XMLElement* reader)
|
||||
{
|
||||
ZResource::ParseXML(reader);
|
||||
|
@ -385,37 +37,29 @@ void ZLimb::ParseXML(tinyxml2::XMLElement* reader)
|
|||
|
||||
if (limbType == "")
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ZLimb::ParseXML: Warning in '%s'.\n"
|
||||
"\t Missing 'LimbType' attribute in xml.\n"
|
||||
"\t Defaulting to 'Standard'.\n",
|
||||
name.c_str());
|
||||
type = ZLimbType::Standard;
|
||||
throw std::runtime_error(StringHelper::Sprintf("ZLimb::ParseXML: Error in '%s'.\n"
|
||||
"\t Missing 'LimbType' attribute in xml.\n",
|
||||
name.c_str()));
|
||||
}
|
||||
else
|
||||
|
||||
type = GetTypeByAttributeName(limbType);
|
||||
if (type == ZLimbType::Invalid)
|
||||
{
|
||||
type = GetTypeByAttributeName(limbType);
|
||||
if (type == ZLimbType::Invalid)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"ZLimb::ParseXML: Warning in '%s'.\n"
|
||||
"\t Invalid LimbType found: '%s'.\n"
|
||||
"\t Defaulting to 'Standard'.\n",
|
||||
name.c_str(), limbType.c_str());
|
||||
type = ZLimbType::Standard;
|
||||
}
|
||||
throw std::runtime_error(StringHelper::Sprintf("ZLimb::ParseXML: Error in '%s'.\n"
|
||||
"\t Invalid 'LimbType' found: '%s'.\n",
|
||||
name.c_str(), limbType.c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
void ZLimb::ParseRawData()
|
||||
{
|
||||
ZResource::ParseRawData();
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
|
||||
if (type == ZLimbType::Curve)
|
||||
{
|
||||
childIndex = rawData.at(rawDataIndex + 0);
|
||||
siblingIndex = rawData.at(rawDataIndex + 1);
|
||||
childIndex = BitConverter::ToUInt8BE(rawData, rawDataIndex + 0);
|
||||
siblingIndex = BitConverter::ToUInt8BE(rawData, rawDataIndex + 1);
|
||||
|
||||
dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 4);
|
||||
dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
|
||||
|
@ -446,7 +90,7 @@ void ZLimb::ParseRawData()
|
|||
{
|
||||
case ZLimbType::LOD:
|
||||
dList2Ptr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12);
|
||||
// Intended fallthrough
|
||||
[[fallthrough]];
|
||||
case ZLimbType::Standard:
|
||||
dListPtr = BitConverter::ToUInt32BE(rawData, rawDataIndex + 8);
|
||||
break;
|
||||
|
@ -455,12 +99,16 @@ void ZLimb::ParseRawData()
|
|||
skinSegmentType =
|
||||
static_cast<ZLimbSkinType>(BitConverter::ToInt32BE(rawData, rawDataIndex + 8));
|
||||
skinSegment = BitConverter::ToUInt32BE(rawData, rawDataIndex + 12);
|
||||
if (skinSegmentType == ZLimbSkinType::SkinType_4 && skinSegment != 0)
|
||||
if (skinSegmentType == ZLimbSkinType::SkinType_4)
|
||||
{
|
||||
uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress);
|
||||
segmentStruct = Struct_800A5E28(parent, rawData, skinSegmentOffset);
|
||||
if (skinSegment != 0 && GETSEGNUM(skinSegment) == parent->segment)
|
||||
{
|
||||
uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress);
|
||||
segmentStruct.ExtractFromFile(skinSegmentOffset);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::runtime_error("Invalid ZLimb type");
|
||||
break;
|
||||
|
@ -469,8 +117,13 @@ void ZLimb::ParseRawData()
|
|||
|
||||
void ZLimb::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
ZResource::DeclareReferences(prefix);
|
||||
std::string varPrefix = name;
|
||||
if (varPrefix == "")
|
||||
varPrefix = prefix;
|
||||
|
||||
ZResource::DeclareReferences(varPrefix);
|
||||
|
||||
std::string suffix;
|
||||
switch (type)
|
||||
{
|
||||
case ZLimbType::Legacy:
|
||||
|
@ -479,8 +132,10 @@ void ZLimb::DeclareReferences(const std::string& prefix)
|
|||
uint32_t childOffset = Seg2Filespace(childPtr, parent->baseAddress);
|
||||
if (!parent->HasDeclaration(childOffset))
|
||||
{
|
||||
ZLimb* child = new ZLimb(ZLimbType::Legacy, prefix, childOffset, parent);
|
||||
child->GetSourceOutputCode(prefix);
|
||||
ZLimb* child = new ZLimb(parent);
|
||||
child->ExtractFromBinary(childOffset, ZLimbType::Legacy);
|
||||
child->DeclareVar(varPrefix, "");
|
||||
child->DeclareReferences(varPrefix);
|
||||
parent->AddResource(child);
|
||||
}
|
||||
}
|
||||
|
@ -489,18 +144,47 @@ void ZLimb::DeclareReferences(const std::string& prefix)
|
|||
uint32_t siblingdOffset = Seg2Filespace(siblingPtr, parent->baseAddress);
|
||||
if (!parent->HasDeclaration(siblingdOffset))
|
||||
{
|
||||
ZLimb* sibling = new ZLimb(ZLimbType::Legacy, prefix, siblingdOffset, parent);
|
||||
sibling->GetSourceOutputCode(prefix);
|
||||
ZLimb* sibling = new ZLimb(parent);
|
||||
sibling->ExtractFromBinary(siblingdOffset, ZLimbType::Legacy);
|
||||
sibling->DeclareVar(varPrefix, "");
|
||||
sibling->DeclareReferences(varPrefix);
|
||||
parent->AddResource(sibling);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// TODO
|
||||
case ZLimbType::Standard:
|
||||
case ZLimbType::LOD:
|
||||
case ZLimbType::Skin:
|
||||
case ZLimbType::Curve:
|
||||
case ZLimbType::LOD:
|
||||
suffix = "Far";
|
||||
if (type == ZLimbType::Curve)
|
||||
suffix = "Curve2";
|
||||
DeclareDList(dList2Ptr, varPrefix, suffix);
|
||||
[[fallthrough]];
|
||||
case ZLimbType::Standard:
|
||||
suffix = "";
|
||||
if (type == ZLimbType::Curve)
|
||||
suffix = "Curve";
|
||||
DeclareDList(dListPtr, varPrefix, suffix);
|
||||
break;
|
||||
|
||||
case ZLimbType::Skin:
|
||||
switch (skinSegmentType)
|
||||
{
|
||||
case ZLimbSkinType::SkinType_4:
|
||||
if (skinSegment != 0 && GETSEGNUM(skinSegment) == parent->segment)
|
||||
{
|
||||
segmentStruct.DeclareReferences(varPrefix);
|
||||
segmentStruct.GetSourceOutputCode(varPrefix);
|
||||
}
|
||||
break;
|
||||
|
||||
case ZLimbSkinType::SkinType_DList:
|
||||
DeclareDList(skinSegment, varPrefix, "");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ZLimbType::Invalid:
|
||||
|
@ -530,18 +214,20 @@ size_t ZLimb::GetRawDataSize() const
|
|||
return 0x0C;
|
||||
}
|
||||
|
||||
std::string ZLimb::GetSourceOutputCode(const std::string& prefix)
|
||||
std::string ZLimb::GetBodySourceCode() const
|
||||
{
|
||||
std::string limbPrefix = type == ZLimbType::Curve ? "Curve" : "";
|
||||
std::string dListStr = GetLimbDListSourceOutputCode(prefix, limbPrefix, dListPtr);
|
||||
limbPrefix = type == ZLimbType::Curve ? "Curve" : "Far";
|
||||
std::string dListStr2 = GetLimbDListSourceOutputCode(prefix, limbPrefix, dList2Ptr);
|
||||
std::string dListStr;
|
||||
std::string dListStr2;
|
||||
Globals::Instance->GetSegmentedArrayIndexedName(dListPtr, 8, parent, "Gfx", dListStr);
|
||||
Globals::Instance->GetSegmentedArrayIndexedName(dList2Ptr, 8, parent, "Gfx", dListStr2);
|
||||
|
||||
std::string entryStr = "\n\t";
|
||||
if (type == ZLimbType::Legacy)
|
||||
{
|
||||
std::string childName = parent->GetDeclarationPtrName(childPtr);
|
||||
std::string siblingName = parent->GetDeclarationPtrName(siblingPtr);
|
||||
std::string childName;
|
||||
std::string siblingName;
|
||||
Globals::Instance->GetSegmentedPtrName(childPtr, parent, "Gfx", childName);
|
||||
Globals::Instance->GetSegmentedPtrName(siblingPtr, parent, "Gfx", siblingName);
|
||||
|
||||
entryStr += StringHelper::Sprintf("%s,\n", dListStr.c_str());
|
||||
entryStr +=
|
||||
|
@ -556,24 +242,28 @@ std::string ZLimb::GetSourceOutputCode(const std::string& prefix)
|
|||
{
|
||||
entryStr += StringHelper::Sprintf("{ %i, %i, %i }, ", transX, transY, transZ);
|
||||
}
|
||||
|
||||
entryStr += StringHelper::Sprintf("0x%02X, 0x%02X,\n", childIndex, siblingIndex);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ZLimbType::Standard:
|
||||
entryStr += StringHelper::Sprintf(" %s\n", dListStr.c_str());
|
||||
entryStr += StringHelper::Sprintf("\t%s\n", dListStr.c_str());
|
||||
break;
|
||||
|
||||
case ZLimbType::LOD:
|
||||
case ZLimbType::Curve:
|
||||
entryStr +=
|
||||
StringHelper::Sprintf(" { %s, %s }\n", dListStr.c_str(), dListStr2.c_str());
|
||||
StringHelper::Sprintf("\t{ %s, %s }\n", dListStr.c_str(), dListStr2.c_str());
|
||||
break;
|
||||
|
||||
case ZLimbType::Skin:
|
||||
entryStr += GetSourceOutputCodeSkin(prefix);
|
||||
break;
|
||||
{
|
||||
std::string skinSegmentStr;
|
||||
Globals::Instance->GetSegmentedPtrName(skinSegment, parent, "", skinSegmentStr);
|
||||
entryStr +=
|
||||
StringHelper::Sprintf("\t0x%02X, %s\n", skinSegmentType, skinSegmentStr.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
case ZLimbType::Legacy:
|
||||
break;
|
||||
|
@ -583,15 +273,12 @@ std::string ZLimb::GetSourceOutputCode(const std::string& prefix)
|
|||
}
|
||||
}
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(GetFileAddress());
|
||||
return entryStr;
|
||||
}
|
||||
|
||||
if (decl == nullptr)
|
||||
parent->AddDeclaration(GetFileAddress(), DeclarationAlignment::None, GetRawDataSize(),
|
||||
GetSourceTypeName(), name, entryStr);
|
||||
else
|
||||
decl->text = entryStr;
|
||||
|
||||
return "";
|
||||
std::string ZLimb::GetDefaultName(const std::string& prefix) const
|
||||
{
|
||||
return StringHelper::Sprintf("%sLimb_%06X", prefix.c_str(), rawDataIndex);
|
||||
}
|
||||
|
||||
std::string ZLimb::GetSourceTypeName() const
|
||||
|
@ -663,126 +350,34 @@ ZLimbType ZLimb::GetTypeByAttributeName(const std::string& attrName)
|
|||
return ZLimbType::Invalid;
|
||||
}
|
||||
|
||||
uint32_t ZLimb::GetFileAddress()
|
||||
void ZLimb::DeclareDList(segptr_t dListSegmentedPtr, const std::string& prefix,
|
||||
const std::string& limbSuffix)
|
||||
{
|
||||
return Seg2Filespace(rawDataIndex, parent->baseAddress);
|
||||
}
|
||||
if (dListSegmentedPtr == 0 || GETSEGNUM(dListSegmentedPtr) != parent->segment)
|
||||
return;
|
||||
|
||||
// Returns the ptrname of a dlist. Declares it if it has not been declared yet.
|
||||
std::string ZLimb::GetLimbDListSourceOutputCode(const std::string& prefix,
|
||||
const std::string& limbPrefix, segptr_t dListPtr)
|
||||
{
|
||||
if (dListPtr == 0)
|
||||
return "NULL";
|
||||
uint32_t dlistOffset = Seg2Filespace(dListSegmentedPtr, parent->baseAddress);
|
||||
if (parent->HasDeclaration(dlistOffset))
|
||||
return;
|
||||
|
||||
uint32_t dListOffset = Seg2Filespace(dListPtr, parent->baseAddress);
|
||||
if (!parent->IsOffsetInFileRange(dlistOffset) || dlistOffset >= parent->GetRawData().size())
|
||||
return;
|
||||
|
||||
// Check if pointing past the object's size
|
||||
if (dListOffset > parent->GetRawData().size())
|
||||
return StringHelper::Sprintf("0x%08X", dListPtr);
|
||||
|
||||
// Check if it is already declared
|
||||
Declaration* decl = parent->GetDeclaration(dListOffset);
|
||||
if (decl != nullptr)
|
||||
return decl->varName;
|
||||
|
||||
// Check if it points to the middle of a DList
|
||||
decl = parent->GetDeclarationRanged(dListOffset);
|
||||
if (decl != nullptr)
|
||||
{
|
||||
// TODO: Figure out a way to not hardcode the "Gfx" type.
|
||||
if (decl->varType == "Gfx")
|
||||
{
|
||||
uint32_t declAddress = parent->GetDeclarationRangedAddress(dListOffset);
|
||||
if (dListOffset < declAddress + decl->size)
|
||||
{
|
||||
uint32_t index = (dListOffset - declAddress) / 8;
|
||||
return StringHelper::Sprintf("&%s[%u]", decl->varName.c_str(), index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create the DList
|
||||
std::string dListStr =
|
||||
StringHelper::Sprintf("%s%sLimbDL_%06X", prefix.c_str(), limbPrefix.c_str(), dListOffset);
|
||||
std::string dlistName;
|
||||
bool declFound = Globals::Instance->GetSegmentedArrayIndexedName(dListSegmentedPtr, 8, parent,
|
||||
"Gfx", dlistName);
|
||||
if (declFound)
|
||||
return;
|
||||
|
||||
int32_t dlistLength = ZDisplayList::GetDListLength(
|
||||
parent->GetRawData(), dListOffset,
|
||||
parent->GetRawData(), dlistOffset,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
auto dList = new ZDisplayList(dListOffset, dlistLength, parent);
|
||||
dList->SetName(dListStr);
|
||||
dList->GetSourceOutputCode(prefix);
|
||||
return dListStr;
|
||||
}
|
||||
|
||||
std::string ZLimb::GetSourceOutputCodeSkin_Type_4(const std::string& prefix)
|
||||
{
|
||||
assert(type == ZLimbType::Skin);
|
||||
assert(skinSegmentType == ZLimbSkinType::SkinType_4);
|
||||
|
||||
if (skinSegment == 0)
|
||||
return "NULL";
|
||||
|
||||
uint32_t skinSegmentOffset = Seg2Filespace(skinSegment, parent->baseAddress);
|
||||
|
||||
std::string struct_800A5E28_Str;
|
||||
Declaration* decl = parent->GetDeclaration(skinSegmentOffset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
struct_800A5E28_Str =
|
||||
StringHelper::Sprintf("%sSkinLimb_%s_%06X", prefix.c_str(),
|
||||
Struct_800A5E28::GetSourceTypeName().c_str(), skinSegmentOffset);
|
||||
|
||||
segmentStruct.PreGenSourceFiles(prefix);
|
||||
std::string entryStr = segmentStruct.GetSourceOutputCode(prefix);
|
||||
|
||||
parent->AddDeclaration(skinSegmentOffset, DeclarationAlignment::None,
|
||||
Struct_800A5E28::GetRawDataSize(),
|
||||
Struct_800A5E28::GetSourceTypeName(), struct_800A5E28_Str, entryStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
struct_800A5E28_Str = decl->varName;
|
||||
}
|
||||
|
||||
return struct_800A5E28_Str;
|
||||
}
|
||||
|
||||
std::string ZLimb::GetSourceOutputCodeSkin(const std::string& prefix)
|
||||
{
|
||||
assert(type == ZLimbType::Skin);
|
||||
|
||||
std::string skinSegmentStr = "NULL";
|
||||
|
||||
if (skinSegment != 0)
|
||||
{
|
||||
switch (skinSegmentType)
|
||||
{
|
||||
case ZLimbSkinType::SkinType_4:
|
||||
skinSegmentStr = "&" + GetSourceOutputCodeSkin_Type_4(prefix);
|
||||
break;
|
||||
case ZLimbSkinType::SkinType_DList:
|
||||
skinSegmentStr = GetLimbDListSourceOutputCode(prefix, "Skin", skinSegment);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Unknown segment type "
|
||||
"for SkinLimb: '%i'. \n\tPlease report this.\n",
|
||||
name.c_str(), static_cast<int32_t>(skinSegmentType));
|
||||
break;
|
||||
case ZLimbSkinType::SkinType_0:
|
||||
case ZLimbSkinType::SkinType_5:
|
||||
fprintf(stderr,
|
||||
"ZLimb::GetSourceOutputCodeSkinType: Error in '%s'.\n\t Segment type for "
|
||||
"SkinLimb not implemented: '%i'.\n",
|
||||
name.c_str(), static_cast<int32_t>(skinSegmentType));
|
||||
skinSegmentStr = StringHelper::Sprintf("0x%08X", skinSegment);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string entryStr =
|
||||
StringHelper::Sprintf(" 0x%02X, %s\n", skinSegmentType, skinSegmentStr.c_str());
|
||||
|
||||
return entryStr;
|
||||
ZDisplayList* dlist = new ZDisplayList(parent);
|
||||
dlist->ExtractFromBinary(dlistOffset, dlistLength);
|
||||
|
||||
std::string dListStr =
|
||||
StringHelper::Sprintf("%s%sDL_%06X", prefix.c_str(), limbSuffix.c_str(), dlistOffset);
|
||||
dlist->SetName(dListStr);
|
||||
dlist->DeclareVar(prefix, "");
|
||||
parent->AddResource(dlist);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "OtherStructs/SkinLimbStructs.h"
|
||||
#include "ZDisplayList.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
|
@ -16,117 +18,14 @@ enum class ZLimbType
|
|||
Legacy,
|
||||
};
|
||||
|
||||
// TODO: check if more types exists
|
||||
enum class ZLimbSkinType
|
||||
{
|
||||
SkinType_0, // Segment = 0
|
||||
SkinType_4 = 4, // Segment = segmented address // Struct_800A5E28
|
||||
SkinType_5 = 5, // Segment = 0
|
||||
SkinType_DList = 11, // Segment = DList address
|
||||
};
|
||||
|
||||
class Struct_800A57C0
|
||||
{
|
||||
protected:
|
||||
uint16_t unk_0;
|
||||
int16_t unk_2;
|
||||
int16_t unk_4;
|
||||
int8_t unk_6;
|
||||
int8_t unk_7;
|
||||
int8_t unk_8;
|
||||
uint8_t unk_9;
|
||||
|
||||
public:
|
||||
Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset);
|
||||
Struct_800A57C0(const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index);
|
||||
|
||||
[[nodiscard]] std::string GetSourceOutputCode() const;
|
||||
|
||||
static size_t GetRawDataSize();
|
||||
static std::string GetSourceTypeName();
|
||||
};
|
||||
|
||||
class Struct_800A598C_2
|
||||
{
|
||||
protected:
|
||||
uint8_t unk_0;
|
||||
int16_t x;
|
||||
int16_t y;
|
||||
int16_t z;
|
||||
uint8_t unk_8;
|
||||
|
||||
public:
|
||||
Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset);
|
||||
Struct_800A598C_2(const std::vector<uint8_t>& rawData, uint32_t fileOffset, size_t index);
|
||||
|
||||
[[nodiscard]] std::string GetSourceOutputCode() const;
|
||||
|
||||
static size_t GetRawDataSize();
|
||||
static std::string GetSourceTypeName();
|
||||
};
|
||||
|
||||
class Struct_800A598C
|
||||
{
|
||||
protected:
|
||||
ZFile* parent;
|
||||
|
||||
uint16_t unk_0; // Length of unk_8
|
||||
uint16_t unk_2; // Length of unk_C
|
||||
uint16_t unk_4; // 0 or 1 // Used as an index for unk_C
|
||||
segptr_t unk_8; // Struct_800A57C0*
|
||||
segptr_t unk_C; // Struct_800A598C_2*
|
||||
|
||||
std::vector<Struct_800A57C0> unk_8_arr;
|
||||
std::vector<Struct_800A598C_2> unk_C_arr;
|
||||
|
||||
public:
|
||||
Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset);
|
||||
Struct_800A598C(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset,
|
||||
size_t index);
|
||||
|
||||
void PreGenSourceFiles(const std::string& prefix);
|
||||
[[nodiscard]] std::string GetSourceOutputCode(const std::string& prefix) const;
|
||||
|
||||
static size_t GetRawDataSize();
|
||||
static std::string GetSourceTypeName();
|
||||
};
|
||||
|
||||
class Struct_800A5E28
|
||||
{
|
||||
protected:
|
||||
ZFile* parent;
|
||||
|
||||
uint16_t unk_0; // Vtx count
|
||||
uint16_t unk_2; // Length of unk_4
|
||||
segptr_t unk_4; // Struct_800A598C*
|
||||
segptr_t unk_8; // Gfx*
|
||||
|
||||
std::vector<Struct_800A598C> unk_4_arr;
|
||||
ZDisplayList* unk_8_dlist = nullptr;
|
||||
|
||||
public:
|
||||
Struct_800A5E28() = default;
|
||||
Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset);
|
||||
Struct_800A5E28(ZFile* parent, const std::vector<uint8_t>& rawData, uint32_t fileOffset,
|
||||
size_t index);
|
||||
~Struct_800A5E28();
|
||||
|
||||
void PreGenSourceFiles(const std::string& prefix);
|
||||
[[nodiscard]] std::string GetSourceOutputCode(const std::string& prefix) const;
|
||||
|
||||
static size_t GetRawDataSize();
|
||||
static std::string GetSourceTypeName();
|
||||
};
|
||||
|
||||
class ZLimb : public ZResource
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
ZLimbType type = ZLimbType::Standard;
|
||||
|
||||
ZLimbSkinType skinSegmentType = ZLimbSkinType::SkinType_0; // Skin only
|
||||
segptr_t skinSegment = 0; // Skin only
|
||||
Struct_800A5E28 segmentStruct; // Skin only
|
||||
segptr_t dList2Ptr; // LOD and Curve Only
|
||||
|
||||
// Legacy only
|
||||
float legTransX, legTransY, legTransZ; // Vec3f
|
||||
|
@ -134,29 +33,24 @@ protected:
|
|||
segptr_t childPtr; // LegacyLimb*
|
||||
segptr_t siblingPtr; // LegacyLimb*
|
||||
|
||||
std::string GetLimbDListSourceOutputCode(const std::string& prefix,
|
||||
const std::string& limbPrefix, segptr_t dListPtr);
|
||||
|
||||
std::string GetSourceOutputCodeSkin(const std::string& prefix);
|
||||
std::string GetSourceOutputCodeSkin_Type_4(const std::string& prefix);
|
||||
|
||||
public:
|
||||
segptr_t dListPtr = 0;
|
||||
segptr_t farDListPtr = 0; // LOD only
|
||||
segptr_t dList2Ptr = 0; // LOD and Curve Only
|
||||
|
||||
int16_t transX, transY, transZ;
|
||||
uint8_t childIndex, siblingIndex;
|
||||
|
||||
ZLimb(ZFile* nParent);
|
||||
ZLimb(ZLimbType limbType, const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent);
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
void ExtractFromBinary(uint32_t nRawDataIndex, ZLimbType nType);
|
||||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
std::string GetDefaultName(const std::string& prefix) const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
|
@ -165,6 +59,7 @@ public:
|
|||
static const char* GetSourceTypeName(ZLimbType limbType);
|
||||
static ZLimbType GetTypeByAttributeName(const std::string& attrName);
|
||||
|
||||
uint32_t GetFileAddress();
|
||||
void SetFileAddress(uint32_t nAddress);
|
||||
protected:
|
||||
void DeclareDList(segptr_t dListSegmentedPtr, const std::string& prefix,
|
||||
const std::string& limbSuffix);
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "ZMtx.h"
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
REGISTER_ZFILENODE(Mtx, ZMtx);
|
||||
|
@ -9,13 +10,6 @@ ZMtx::ZMtx(ZFile* nParent) : ZResource(nParent)
|
|||
{
|
||||
}
|
||||
|
||||
ZMtx::ZMtx(const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
name = GetDefaultName(prefix.c_str(), rawDataIndex);
|
||||
ExtractFromFile(nRawDataIndex);
|
||||
DeclareVar("", "");
|
||||
}
|
||||
|
||||
void ZMtx::ParseRawData()
|
||||
{
|
||||
ZResource::ParseRawData();
|
||||
|
@ -26,29 +20,12 @@ void ZMtx::ParseRawData()
|
|||
mtx[i][j] = BitConverter::ToInt32BE(rawData, rawDataIndex + (i * 4 + j) * 4);
|
||||
}
|
||||
|
||||
void ZMtx::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
DeclareVar("", "");
|
||||
}
|
||||
|
||||
size_t ZMtx::GetRawDataSize() const
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
void ZMtx::DeclareVar(const std::string& prefix, const std::string& bodyStr) const
|
||||
{
|
||||
std::string auxName = name;
|
||||
|
||||
if (name == "")
|
||||
auxName = GetDefaultName(prefix, rawDataIndex);
|
||||
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align8, GetRawDataSize(),
|
||||
GetSourceTypeName(), auxName, bodyStr);
|
||||
}
|
||||
|
||||
std::string ZMtx::GetBodySourceCode()
|
||||
std::string ZMtx::GetBodySourceCode() const
|
||||
{
|
||||
std::string bodyStr = "\n";
|
||||
|
||||
|
@ -65,25 +42,6 @@ std::string ZMtx::GetBodySourceCode()
|
|||
return bodyStr;
|
||||
}
|
||||
|
||||
std::string ZMtx::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
std::string bodyStr = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
|
||||
if (decl == nullptr)
|
||||
DeclareVar(prefix, bodyStr);
|
||||
else
|
||||
decl->text = bodyStr;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string ZMtx::GetDefaultName(const std::string& prefix, uint32_t address)
|
||||
{
|
||||
return StringHelper::Sprintf("%sMtx_%06X", prefix.c_str(), address);
|
||||
}
|
||||
|
||||
std::string ZMtx::GetSourceTypeName() const
|
||||
{
|
||||
return "Mtx";
|
||||
|
@ -93,3 +51,8 @@ ZResourceType ZMtx::GetResourceType() const
|
|||
{
|
||||
return ZResourceType::Mtx;
|
||||
}
|
||||
|
||||
DeclarationAlignment ZMtx::GetDeclarationAlignment() const
|
||||
{
|
||||
return DeclarationAlignment::Align8;
|
||||
}
|
||||
|
|
|
@ -8,22 +8,17 @@ class ZMtx : public ZResource
|
|||
{
|
||||
public:
|
||||
ZMtx(ZFile* nParent);
|
||||
ZMtx(const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex) override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
void DeclareVar(const std::string& prefix, const std::string& bodyStr) const;
|
||||
|
||||
std::string GetBodySourceCode();
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
static std::string GetDefaultName(const std::string& prefix, uint32_t address);
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
DeclarationAlignment GetDeclarationAlignment() const override;
|
||||
|
||||
protected:
|
||||
std::array<std::array<int32_t, 4>, 4> mtx;
|
||||
};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "ZPath.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
REGISTER_ZFILENODE(Path, ZPath);
|
||||
|
@ -13,14 +13,6 @@ ZPath::ZPath(ZFile* nParent) : ZResource(nParent)
|
|||
RegisterOptionalAttribute("NumPaths", "1");
|
||||
}
|
||||
|
||||
void ZPath::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
{
|
||||
ZResource::ExtractFromXML(reader, nRawDataIndex);
|
||||
|
||||
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, pathways.size() * 8,
|
||||
GetSourceTypeName(), name, pathways.size(), "");
|
||||
}
|
||||
|
||||
void ZPath::ParseXML(tinyxml2::XMLElement* reader)
|
||||
{
|
||||
ZResource::ParseXML(reader);
|
||||
|
@ -43,8 +35,7 @@ void ZPath::ParseRawData()
|
|||
for (size_t pathIndex = 0; pathIndex < numPaths; pathIndex++)
|
||||
{
|
||||
PathwayEntry path(parent);
|
||||
path.SetRawDataIndex(currentPtr);
|
||||
path.ParseRawData();
|
||||
path.ExtractFromFile(currentPtr);
|
||||
|
||||
if (path.GetListAddress() == 0)
|
||||
break;
|
||||
|
@ -62,9 +53,23 @@ void ZPath::DeclareReferences(const std::string& prefix)
|
|||
entry.DeclareReferences(prefix);
|
||||
}
|
||||
|
||||
Declaration* ZPath::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
{
|
||||
std::string auxName = name;
|
||||
|
||||
if (name == "")
|
||||
auxName = GetDefaultName(prefix);
|
||||
|
||||
Declaration* decl =
|
||||
parent->AddDeclarationArray(rawDataIndex, GetDeclarationAlignment(), GetRawDataSize(),
|
||||
GetSourceTypeName(), name, pathways.size(), bodyStr);
|
||||
decl->staticConf = staticConf;
|
||||
return decl;
|
||||
}
|
||||
|
||||
std::string ZPath::GetBodySourceCode() const
|
||||
{
|
||||
std::string declaration = "";
|
||||
std::string declaration;
|
||||
|
||||
size_t index = 0;
|
||||
for (const auto& entry : pathways)
|
||||
|
@ -80,20 +85,6 @@ std::string ZPath::GetBodySourceCode() const
|
|||
return declaration;
|
||||
}
|
||||
|
||||
std::string ZPath::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
std::string declaration = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
if (decl == nullptr || decl->isPlaceholder)
|
||||
parent->AddDeclarationArray(rawDataIndex, DeclarationAlignment::Align4, pathways.size() * 8,
|
||||
GetSourceTypeName(), name, pathways.size(), declaration);
|
||||
else
|
||||
decl->text = declaration;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string ZPath::GetSourceTypeName() const
|
||||
{
|
||||
return "Path";
|
||||
|
@ -134,10 +125,7 @@ void PathwayEntry::ParseRawData()
|
|||
for (int32_t i = 0; i < numPoints; i++)
|
||||
{
|
||||
ZVector vec(parent);
|
||||
vec.SetRawDataIndex(currentPtr);
|
||||
vec.SetScalarType(ZScalarType::ZSCALAR_S16);
|
||||
vec.SetDimensions(3);
|
||||
vec.ParseRawData();
|
||||
vec.ExtractFromBinary(currentPtr, ZScalarType::ZSCALAR_S16, 3);
|
||||
|
||||
currentPtr += vec.GetRawDataSize();
|
||||
points.push_back(vec);
|
||||
|
@ -150,12 +138,18 @@ void PathwayEntry::DeclareReferences(const std::string& prefix)
|
|||
if (points.empty())
|
||||
return;
|
||||
|
||||
std::string declaration = "";
|
||||
std::string pointsName;
|
||||
bool addressFound =
|
||||
Globals::Instance->GetSegmentedPtrName(listSegmentAddress, parent, "Vec3s", pointsName);
|
||||
if (addressFound)
|
||||
return;
|
||||
|
||||
std::string declaration;
|
||||
|
||||
size_t index = 0;
|
||||
for (const auto& point : points)
|
||||
{
|
||||
declaration += StringHelper::Sprintf("\t%s,", point.GetBodySourceCode().c_str());
|
||||
declaration += StringHelper::Sprintf("\t{ %s },", point.GetBodySourceCode().c_str());
|
||||
|
||||
if (index < points.size() - 1)
|
||||
declaration += "\n";
|
||||
|
@ -163,14 +157,13 @@ void PathwayEntry::DeclareReferences(const std::string& prefix)
|
|||
index++;
|
||||
}
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(GETSEGOFFSET(listSegmentAddress));
|
||||
uint32_t pointsOffset = Seg2Filespace(listSegmentAddress, parent->baseAddress);
|
||||
Declaration* decl = parent->GetDeclaration(pointsOffset);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclarationArray(GETSEGOFFSET(listSegmentAddress), DeclarationAlignment::Align4,
|
||||
DeclarationPadding::Pad4, points.size() * 6,
|
||||
points.at(0).GetSourceTypeName(),
|
||||
StringHelper::Sprintf("%sPathwayList0x%06X", prefix.c_str(),
|
||||
GETSEGOFFSET(listSegmentAddress)),
|
||||
pointsName = StringHelper::Sprintf("%sPathwayList_%06X", prefix.c_str(), pointsOffset);
|
||||
parent->AddDeclarationArray(pointsOffset, points.at(0).GetDeclarationAlignment(),
|
||||
points.size() * 6, points.at(0).GetSourceTypeName(), pointsName,
|
||||
points.size(), declaration);
|
||||
}
|
||||
else
|
||||
|
@ -179,8 +172,9 @@ void PathwayEntry::DeclareReferences(const std::string& prefix)
|
|||
|
||||
std::string PathwayEntry::GetBodySourceCode() const
|
||||
{
|
||||
std::string declaration = "";
|
||||
std::string listName = parent->GetDeclarationPtrName(listSegmentAddress);
|
||||
std::string declaration;
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(listSegmentAddress, parent, "Vec3s", listName);
|
||||
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
declaration +=
|
||||
|
|
|
@ -11,12 +11,12 @@ public:
|
|||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const;
|
||||
size_t GetRawDataSize() const override;
|
||||
segptr_t GetListAddress() const;
|
||||
|
||||
protected:
|
||||
|
@ -32,14 +32,12 @@ class ZPath : public ZResource
|
|||
public:
|
||||
ZPath(ZFile* nParent);
|
||||
|
||||
void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex);
|
||||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
|
97
tools/ZAPD/ZAPD/ZPlayerAnimationData.cpp
Normal file
97
tools/ZAPD/ZAPD/ZPlayerAnimationData.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
#include "ZPlayerAnimationData.h"
|
||||
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
REGISTER_ZFILENODE(PlayerAnimationData, ZPlayerAnimationData);
|
||||
|
||||
ZPlayerAnimationData::ZPlayerAnimationData(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
RegisterRequiredAttribute("FrameCount");
|
||||
}
|
||||
|
||||
void ZPlayerAnimationData::ParseXML(tinyxml2::XMLElement* reader)
|
||||
{
|
||||
ZResource::ParseXML(reader);
|
||||
|
||||
std::string& frameCountXml = registeredAttributes.at("FrameCount").value;
|
||||
|
||||
frameCount = StringHelper::StrToL(frameCountXml);
|
||||
}
|
||||
|
||||
void ZPlayerAnimationData::ParseRawData()
|
||||
{
|
||||
ZResource::ParseRawData();
|
||||
|
||||
const auto& rawData = parent->GetRawData();
|
||||
|
||||
size_t totalSize = GetRawDataSize();
|
||||
// Divided by 2 because each value is an s16
|
||||
limbRotData.reserve(totalSize * frameCount / 2);
|
||||
|
||||
for (size_t i = 0; i < totalSize; i += 2)
|
||||
{
|
||||
limbRotData.push_back(BitConverter::ToUInt16BE(rawData, rawDataIndex + i));
|
||||
}
|
||||
}
|
||||
|
||||
Declaration* ZPlayerAnimationData::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
{
|
||||
std::string auxName = name;
|
||||
|
||||
if (auxName == "")
|
||||
auxName = GetDefaultName(prefix);
|
||||
|
||||
Declaration* decl =
|
||||
parent->AddDeclarationArray(rawDataIndex, GetDeclarationAlignment(), GetRawDataSize(),
|
||||
GetSourceTypeName(), name, limbRotData.size(), bodyStr);
|
||||
decl->staticConf = staticConf;
|
||||
return decl;
|
||||
}
|
||||
|
||||
std::string ZPlayerAnimationData::GetBodySourceCode() const
|
||||
{
|
||||
std::string declaration = "";
|
||||
|
||||
size_t index = 0;
|
||||
for (const auto& entry : limbRotData)
|
||||
{
|
||||
if (index % 8 == 0)
|
||||
{
|
||||
declaration += "\t";
|
||||
}
|
||||
|
||||
declaration += StringHelper::Sprintf("0x%04X, ", entry);
|
||||
|
||||
if ((index + 1) % 8 == 0)
|
||||
{
|
||||
declaration += "\n";
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return declaration;
|
||||
}
|
||||
|
||||
std::string ZPlayerAnimationData::GetDefaultName(const std::string& prefix) const
|
||||
{
|
||||
return StringHelper::Sprintf("%sPlayerAnimationData_%06X", prefix.c_str(), rawDataIndex);
|
||||
}
|
||||
|
||||
std::string ZPlayerAnimationData::GetSourceTypeName() const
|
||||
{
|
||||
return "s16";
|
||||
}
|
||||
|
||||
ZResourceType ZPlayerAnimationData::GetResourceType() const
|
||||
{
|
||||
return ZResourceType::PlayerAnimationData;
|
||||
}
|
||||
|
||||
size_t ZPlayerAnimationData::GetRawDataSize() const
|
||||
{
|
||||
// (sizeof(Vec3s) * limbCount + 2) * frameCount
|
||||
return (6 * 22 + 2) * frameCount;
|
||||
}
|
28
tools/ZAPD/ZAPD/ZPlayerAnimationData.h
Normal file
28
tools/ZAPD/ZAPD/ZPlayerAnimationData.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "ZResource.h"
|
||||
|
||||
class ZPlayerAnimationData : public ZResource
|
||||
{
|
||||
public:
|
||||
int16_t frameCount = 0;
|
||||
std::vector<uint16_t> limbRotData;
|
||||
|
||||
ZPlayerAnimationData(ZFile* nParent);
|
||||
|
||||
void ParseXML(tinyxml2::XMLElement* reader) override;
|
||||
void ParseRawData() override;
|
||||
|
||||
Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
std::string GetDefaultName(const std::string& prefix) const override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
};
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
#include <cassert>
|
||||
#include <regex>
|
||||
#include "StringHelper.h"
|
||||
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
ZResource::ZResource(ZFile* nParent)
|
||||
|
@ -19,23 +20,43 @@ ZResource::ZResource(ZFile* nParent)
|
|||
RegisterOptionalAttribute("OutName");
|
||||
RegisterOptionalAttribute("Offset");
|
||||
RegisterOptionalAttribute("Custom");
|
||||
RegisterOptionalAttribute("Static", "Global");
|
||||
}
|
||||
|
||||
void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex)
|
||||
void ZResource::ExtractFromXML(tinyxml2::XMLElement* reader, offset_t nRawDataIndex)
|
||||
{
|
||||
rawDataIndex = nRawDataIndex;
|
||||
declaredInXml = true;
|
||||
|
||||
if (reader != nullptr)
|
||||
ParseXML(reader);
|
||||
|
||||
ParseRawData();
|
||||
CalcHash();
|
||||
// Don't parse raw data of external files
|
||||
if (parent->GetMode() != ZFileMode::ExternalFile)
|
||||
{
|
||||
ParseRawData();
|
||||
CalcHash();
|
||||
}
|
||||
|
||||
if (!isInner)
|
||||
{
|
||||
Declaration* decl = DeclareVar(parent->GetName(), "");
|
||||
if (decl != nullptr)
|
||||
{
|
||||
decl->declaredInXml = true;
|
||||
decl->staticConf = staticConf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ZResource::ExtractFromFile(uint32_t nRawDataIndex)
|
||||
void ZResource::ExtractFromFile(offset_t nRawDataIndex)
|
||||
{
|
||||
rawDataIndex = nRawDataIndex;
|
||||
|
||||
// Don't parse raw data of external files
|
||||
if (parent->GetMode() == ZFileMode::ExternalFile)
|
||||
return;
|
||||
|
||||
ParseRawData();
|
||||
CalcHash();
|
||||
}
|
||||
|
@ -110,15 +131,59 @@ void ZResource::ParseXML(tinyxml2::XMLElement* reader)
|
|||
|
||||
isCustomAsset = registeredAttributes["Custom"].wasSet;
|
||||
|
||||
std::string& staticXml = registeredAttributes["Static"].value;
|
||||
if (staticXml == "Global")
|
||||
{
|
||||
staticConf = StaticConfig::Global;
|
||||
}
|
||||
else if (staticXml == "On")
|
||||
{
|
||||
staticConf = StaticConfig::On;
|
||||
}
|
||||
else if (staticXml == "Off")
|
||||
{
|
||||
staticConf = StaticConfig::Off;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Invalid value for 'Static' attribute.");
|
||||
}
|
||||
|
||||
declaredInXml = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ZResource::Save(const fs::path& outFolder)
|
||||
void ZResource::ParseRawData()
|
||||
{
|
||||
}
|
||||
|
||||
void ZResource::PreGenSourceFiles()
|
||||
void ZResource::DeclareReferences([[maybe_unused]] const std::string& prefix)
|
||||
{
|
||||
}
|
||||
|
||||
void ZResource::ParseRawDataLate()
|
||||
{
|
||||
}
|
||||
|
||||
void ZResource::DeclareReferencesLate([[maybe_unused]] const std::string& prefix)
|
||||
{
|
||||
}
|
||||
|
||||
Declaration* ZResource::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
{
|
||||
std::string auxName = name;
|
||||
|
||||
if (name == "")
|
||||
auxName = GetDefaultName(prefix);
|
||||
|
||||
Declaration* decl =
|
||||
parent->AddDeclaration(rawDataIndex, GetDeclarationAlignment(), GetRawDataSize(),
|
||||
GetSourceTypeName(), auxName, bodyStr);
|
||||
decl->staticConf = staticConf;
|
||||
return decl;
|
||||
}
|
||||
|
||||
void ZResource::Save([[maybe_unused]] const fs::path& outFolder)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -157,19 +222,24 @@ std::string ZResource::GetExternalExtension() const
|
|||
return "";
|
||||
}
|
||||
|
||||
DeclarationAlignment ZResource::GetDeclarationAlignment() const
|
||||
{
|
||||
return DeclarationAlignment::Align4;
|
||||
}
|
||||
|
||||
bool ZResource::WasDeclaredInXml() const
|
||||
{
|
||||
return declaredInXml;
|
||||
}
|
||||
|
||||
uint32_t ZResource::GetRawDataIndex() const
|
||||
StaticConfig ZResource::GetStaticConf() const
|
||||
{
|
||||
return rawDataIndex;
|
||||
return staticConf;
|
||||
}
|
||||
|
||||
void ZResource::SetRawDataIndex(uint32_t value)
|
||||
offset_t ZResource::GetRawDataIndex() const
|
||||
{
|
||||
rawDataIndex = value;
|
||||
return rawDataIndex;
|
||||
}
|
||||
|
||||
std::string ZResource::GetBodySourceCode() const
|
||||
|
@ -177,33 +247,31 @@ std::string ZResource::GetBodySourceCode() const
|
|||
return "ERROR";
|
||||
}
|
||||
|
||||
std::string ZResource::GetSourceOutputCode(const std::string& prefix)
|
||||
std::string ZResource::GetDefaultName(const std::string& prefix) const
|
||||
{
|
||||
return StringHelper::Sprintf("%s%s_%06X", prefix.c_str(), GetSourceTypeName().c_str(),
|
||||
rawDataIndex);
|
||||
}
|
||||
|
||||
std::string ZResource::GetSourceOutputCode([[maybe_unused]] const std::string& prefix)
|
||||
{
|
||||
std::string bodyStr = GetBodySourceCode();
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
if (decl == nullptr || decl->isPlaceholder)
|
||||
decl = DeclareVar(prefix, bodyStr);
|
||||
else
|
||||
decl->text = bodyStr;
|
||||
decl->staticConf = staticConf;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string ZResource::GetSourceOutputHeader(const std::string& prefix)
|
||||
std::string ZResource::GetSourceOutputHeader([[maybe_unused]] const std::string& prefix)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void ZResource::ParseRawData()
|
||||
{
|
||||
}
|
||||
|
||||
void ZResource::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
}
|
||||
|
||||
void ZResource::GenerateHLIntermediette(HLFileIntermediette& hlFile)
|
||||
{
|
||||
}
|
||||
|
||||
std::string ZResource::GetSourceTypeName() const
|
||||
{
|
||||
return "u8";
|
||||
}
|
||||
|
||||
ZResourceType ZResource::GetResourceType() const
|
||||
{
|
||||
return ZResourceType::Error;
|
||||
|
@ -235,12 +303,24 @@ void ZResource::RegisterOptionalAttribute(const std::string& attr, const std::st
|
|||
registeredAttributes[attr] = resAtrr;
|
||||
}
|
||||
|
||||
uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress)
|
||||
offset_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress)
|
||||
{
|
||||
uint32_t currentPtr = GETSEGOFFSET(segmentedAddress);
|
||||
offset_t currentPtr = GETSEGOFFSET(segmentedAddress);
|
||||
|
||||
if (GETSEGNUM(segmentedAddress) == 0x80) // Is defined in code?
|
||||
currentPtr -= GETSEGOFFSET(parentBaseAddress);
|
||||
{
|
||||
uint32_t parentBaseOffset = GETSEGOFFSET(parentBaseAddress);
|
||||
if (parentBaseOffset > currentPtr)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("\nSeg2Filespace: Segmented address is smaller than "
|
||||
"'BaseAddress'. Maybe your 'BaseAddress' is wrong?\n"
|
||||
"\t SegmentedAddress: 0x%08X\n"
|
||||
"\t BaseAddress: 0x%08X\n",
|
||||
segmentedAddress, parentBaseAddress));
|
||||
}
|
||||
currentPtr -= parentBaseOffset;
|
||||
}
|
||||
|
||||
return currentPtr;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <Utils/BinaryWriter.h>
|
||||
#include <map>
|
||||
#include <stdexcept>
|
||||
#include <stdint.h>
|
||||
|
@ -8,7 +9,7 @@
|
|||
#include "Declaration.h"
|
||||
#include "tinyxml2.h"
|
||||
|
||||
#include "Directory.h"
|
||||
#include <Utils/Directory.h>
|
||||
|
||||
#define SEGMENT_SCENE 2
|
||||
#define SEGMENT_ROOM 3
|
||||
|
@ -20,16 +21,14 @@
|
|||
#define GETSEGOFFSET(x) (x & 0x00FFFFFF)
|
||||
#define GETSEGNUM(x) ((x >> 24) & 0xFF)
|
||||
|
||||
typedef uint32_t segptr_t;
|
||||
|
||||
class ZFile;
|
||||
class HLFileIntermediette;
|
||||
|
||||
enum class ZResourceType
|
||||
{
|
||||
Error,
|
||||
Animation,
|
||||
Array,
|
||||
AltHeader,
|
||||
Background,
|
||||
Blob,
|
||||
CollisionHeader,
|
||||
|
@ -39,13 +38,17 @@ enum class ZResourceType
|
|||
LimbTable,
|
||||
Mtx,
|
||||
Path,
|
||||
PlayerAnimationData,
|
||||
Room,
|
||||
RoomCommand,
|
||||
Scalar,
|
||||
Scene,
|
||||
Skeleton,
|
||||
String,
|
||||
Symbol,
|
||||
Texture,
|
||||
TextureAnimation,
|
||||
TextureAnimationParams,
|
||||
Vector,
|
||||
Vertex,
|
||||
};
|
||||
|
@ -53,8 +56,8 @@ enum class ZResourceType
|
|||
class ResourceAttribute
|
||||
{
|
||||
public:
|
||||
std::string key = "";
|
||||
std::string value = "";
|
||||
std::string key;
|
||||
std::string value;
|
||||
bool isRequired = false;
|
||||
bool wasSet = false;
|
||||
};
|
||||
|
@ -66,54 +69,127 @@ public:
|
|||
bool outputDeclaration = true;
|
||||
uint32_t hash = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Child classes should not declare any other constructor besides this one
|
||||
*/
|
||||
ZResource(ZFile* nParent);
|
||||
virtual ~ZResource() = default;
|
||||
|
||||
// Parsing from File
|
||||
virtual void ExtractFromXML(tinyxml2::XMLElement* reader, uint32_t nRawDataIndex);
|
||||
virtual void ExtractFromFile(uint32_t nRawDataIndex);
|
||||
virtual void ExtractFromXML(tinyxml2::XMLElement* reader, offset_t nRawDataIndex);
|
||||
virtual void ExtractFromFile(offset_t nRawDataIndex);
|
||||
|
||||
// Misc
|
||||
/**
|
||||
* Parses additional attributes of the XML node.
|
||||
* Extra attritbutes have to be registered using `RegisterRequiredAttribute` or
|
||||
* `RegisterOptionalAttribute` in the constructor of the ZResource
|
||||
*/
|
||||
virtual void ParseXML(tinyxml2::XMLElement* reader);
|
||||
/**
|
||||
* Extracts data from the binary file
|
||||
*/
|
||||
virtual void ParseRawData();
|
||||
/**
|
||||
* Declares any data pointed by this resource that has not been declared already.
|
||||
* For example, a Vtx referenced by a Dlist should be declared here if it wasn't
|
||||
* declared previously by something else
|
||||
*/
|
||||
virtual void DeclareReferences(const std::string& prefix);
|
||||
virtual std::string GetBodySourceCode() const;
|
||||
virtual void ParseRawDataLate();
|
||||
virtual void DeclareReferencesLate(const std::string& prefix);
|
||||
|
||||
/**
|
||||
* Adds this resource as a Declaration of its parent ZFile
|
||||
*/
|
||||
virtual Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr);
|
||||
/**
|
||||
* Returns the body of the variable of the extracted resource, without any side-effect
|
||||
*/
|
||||
[[nodiscard]] virtual std::string GetBodySourceCode() const;
|
||||
/**
|
||||
* Creates an automatically generated variable name for the current resource
|
||||
*/
|
||||
[[nodiscard]] virtual std::string GetDefaultName(const std::string& prefix) const;
|
||||
|
||||
virtual std::string GetSourceOutputCode(const std::string& prefix);
|
||||
virtual std::string GetSourceOutputHeader(const std::string& prefix);
|
||||
virtual void PreGenSourceFiles();
|
||||
virtual void GenerateHLIntermediette(HLFileIntermediette& hlFile);
|
||||
virtual void CalcHash();
|
||||
/**
|
||||
* Exports the resource to binary format
|
||||
*/
|
||||
virtual void Save(const fs::path& outFolder);
|
||||
|
||||
// Properties
|
||||
/**
|
||||
* Returns true if the resource will be externalized, and included back to the C file using
|
||||
* `#include`s
|
||||
*/
|
||||
virtual bool IsExternalResource() const;
|
||||
virtual bool DoesSupportArray() const; // Can this type be wrapped in an <Array> node?
|
||||
virtual std::string GetSourceTypeName() const;
|
||||
virtual ZResourceType GetResourceType() const = 0;
|
||||
virtual std::string GetExternalExtension() const;
|
||||
/**
|
||||
* Can this type be wrapped in an <Array> node?
|
||||
*/
|
||||
virtual bool DoesSupportArray() const;
|
||||
/**
|
||||
* The type of the resource as a C struct
|
||||
*/
|
||||
[[nodiscard]] virtual std::string GetSourceTypeName() const = 0;
|
||||
/**
|
||||
* The type in the ZResource enum
|
||||
*/
|
||||
[[nodiscard]] virtual ZResourceType GetResourceType() const = 0;
|
||||
/**
|
||||
* The filename extension for assets extracted as standalone files
|
||||
*/
|
||||
[[nodiscard]] virtual std::string GetExternalExtension() const;
|
||||
|
||||
// Getters/Setters
|
||||
const std::string& GetName() const;
|
||||
[[nodiscard]] const std::string& GetName() const;
|
||||
void SetName(const std::string& nName);
|
||||
const std::string& GetOutName() const;
|
||||
[[nodiscard]] const std::string& GetOutName() const;
|
||||
void SetOutName(const std::string& nName);
|
||||
virtual uint32_t GetRawDataIndex() const;
|
||||
virtual void SetRawDataIndex(uint32_t value);
|
||||
virtual size_t GetRawDataSize() const = 0;
|
||||
[[nodiscard]] offset_t GetRawDataIndex() const;
|
||||
/**
|
||||
* The size of the current struct being extracted, not counting data referenced by it
|
||||
*/
|
||||
[[nodiscard]] virtual size_t GetRawDataSize() const = 0;
|
||||
/**
|
||||
* The alignment of the extracted struct
|
||||
*/
|
||||
[[nodiscard]] virtual DeclarationAlignment GetDeclarationAlignment() const;
|
||||
void SetInnerNode(bool inner);
|
||||
bool WasDeclaredInXml() const;
|
||||
/**
|
||||
* Returns `true` if this ZResource was declared using an XML node,
|
||||
* `false` otherwise (for example, a Vtx extracted indirectly by a DList)
|
||||
*/
|
||||
[[nodiscard]] bool WasDeclaredInXml() const;
|
||||
[[nodiscard]] StaticConfig GetStaticConf() const;
|
||||
|
||||
protected:
|
||||
std::string name;
|
||||
std::string outName;
|
||||
uint32_t rawDataIndex;
|
||||
offset_t rawDataIndex;
|
||||
std::string sourceOutput;
|
||||
bool isInner = false; // Is this resource an inner node of another resource? inside of <Array>
|
||||
bool canHaveInner = false; // Can this type have an inner node?
|
||||
bool isCustomAsset; // If set to true, create a reference for the asset in the file, but don't
|
||||
// actually try to extract it from the file
|
||||
|
||||
// Inner is used mostly for <Array> nodes
|
||||
/**
|
||||
* Is this resource an inner node of another resource?
|
||||
* (namely inside an <Array>)
|
||||
*/
|
||||
bool isInner = false;
|
||||
/**
|
||||
* Can this type have an inner node?
|
||||
*/
|
||||
bool canHaveInner = false;
|
||||
|
||||
/**
|
||||
* If set to true, create a reference for the asset in the file, but don't
|
||||
* actually try to extract it from the file
|
||||
*/
|
||||
bool isCustomAsset;
|
||||
bool declaredInXml = false;
|
||||
StaticConfig staticConf = StaticConfig::Global;
|
||||
|
||||
// Reading from this XMLs attributes should be performed in the overrided `ParseXML` method.
|
||||
std::map<std::string, ResourceAttribute> registeredAttributes;
|
||||
|
@ -129,7 +205,15 @@ protected:
|
|||
void RegisterOptionalAttribute(const std::string& attr, const std::string& defaultValue = "");
|
||||
};
|
||||
|
||||
uint32_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress);
|
||||
class ZResourceExporter
|
||||
{
|
||||
public:
|
||||
ZResourceExporter() = default;
|
||||
|
||||
virtual void Save(ZResource* res, fs::path outPath, BinaryWriter* writer) = 0;
|
||||
};
|
||||
|
||||
offset_t Seg2Filespace(segptr_t segmentedAddress, uint32_t parentBaseAddress);
|
||||
|
||||
typedef ZResource*(ZResourceFactoryFunc)(ZFile* nParent);
|
||||
|
||||
|
@ -148,3 +232,11 @@ typedef ZResource*(ZResourceFactoryFunc)(ZFile* nParent);
|
|||
} \
|
||||
}; \
|
||||
static ZRes_##nodeName inst_ZRes_##nodeName
|
||||
|
||||
#define REGISTER_EXPORTER(expFunc) \
|
||||
class ZResExp_##expFunc \
|
||||
{ \
|
||||
public: \
|
||||
ZResExp_##expFunc() { expFunc(); } \
|
||||
}; \
|
||||
static ZResExp_##expFunc inst_ZResExp_##expFunc;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "SetActorCutsceneList.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
|
@ -29,7 +29,7 @@ void SetActorCutsceneList::DeclareReferences(const std::string& prefix)
|
|||
{
|
||||
if (cutscenes.size() > 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
std::string declaration;
|
||||
|
||||
for (size_t i = 0; i < cutscenes.size(); i++)
|
||||
{
|
||||
|
@ -45,24 +45,20 @@ void SetActorCutsceneList::DeclareReferences(const std::string& prefix)
|
|||
std::string typeName = cutscenes.at(0).GetSourceTypeName();
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::Align4, cutscenes.size() * 16, typeName,
|
||||
segmentOffset, GetDeclarationAlignment(), cutscenes.size() * 16, typeName,
|
||||
StringHelper::Sprintf("%s%sList_%06X", prefix.c_str(), typeName.c_str(), segmentOffset),
|
||||
0, declaration);
|
||||
cutscenes.size(), declaration);
|
||||
}
|
||||
}
|
||||
|
||||
std::string SetActorCutsceneList::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "ActorCutscene", listName);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_LIST(%i, %s)", cutscenes.size(),
|
||||
listName.c_str());
|
||||
}
|
||||
|
||||
size_t SetActorCutsceneList::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize() + (cutscenes.size() * 16);
|
||||
}
|
||||
|
||||
std::string SetActorCutsceneList::GetCommandCName() const
|
||||
{
|
||||
return "SCmdCutsceneActorList";
|
||||
|
|
|
@ -26,6 +26,8 @@ public:
|
|||
class SetActorCutsceneList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
std::vector<ActorCutsceneEntry> cutscenes;
|
||||
|
||||
SetActorCutsceneList(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
|
@ -35,8 +37,6 @@ public:
|
|||
|
||||
std::string GetCommandCName() const override;
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
private:
|
||||
std::vector<ActorCutsceneEntry> cutscenes;
|
||||
};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "SetActorList.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZNames.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
@ -15,10 +15,26 @@ void SetActorList::ParseRawData()
|
|||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
numActors = cmdArg1;
|
||||
}
|
||||
|
||||
void SetActorList::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
if (numActors != 0 && cmdArg2 != 0)
|
||||
{
|
||||
std::string varName =
|
||||
StringHelper::Sprintf("%sActorList_%06X", prefix.c_str(), segmentOffset);
|
||||
parent->AddDeclarationPlaceholder(segmentOffset, varName);
|
||||
}
|
||||
}
|
||||
|
||||
void SetActorList::ParseRawDataLate()
|
||||
{
|
||||
ZRoomCommand::ParseRawDataLate();
|
||||
size_t actorsAmount = zRoom->GetDeclarationSizeFromNeighbor(segmentOffset) / 0x10;
|
||||
|
||||
uint32_t currentPtr = segmentOffset;
|
||||
|
||||
for (size_t i = 0; i < numActors; i++)
|
||||
for (size_t i = 0; i < actorsAmount; i++)
|
||||
{
|
||||
ActorSpawnEntry entry(parent->GetRawData(), currentPtr);
|
||||
|
||||
|
@ -27,50 +43,53 @@ void SetActorList::ParseRawData()
|
|||
}
|
||||
}
|
||||
|
||||
void SetActorList::DeclareReferences(const std::string& prefix)
|
||||
void SetActorList::DeclareReferencesLate(const std::string& prefix)
|
||||
{
|
||||
if (!actors.empty())
|
||||
if (actors.empty())
|
||||
return;
|
||||
|
||||
std::string declaration;
|
||||
|
||||
size_t largestlength = 0;
|
||||
for (const auto& entry : actors)
|
||||
{
|
||||
std::string declaration = "";
|
||||
|
||||
size_t index = 0;
|
||||
for (const auto& entry : actors)
|
||||
{
|
||||
declaration +=
|
||||
StringHelper::Sprintf("\t{ %s }, // 0x%06X", entry.GetBodySourceCode().c_str(),
|
||||
segmentOffset + (index * 16));
|
||||
|
||||
if (index < actors.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
const auto& entry = actors.front();
|
||||
|
||||
DeclarationPadding padding = DeclarationPadding::Pad16;
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
padding = DeclarationPadding::None;
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::Align4, padding,
|
||||
actors.size() * entry.GetRawDataSize(), entry.GetSourceTypeName(),
|
||||
StringHelper::Sprintf("%sActorList_%06X", prefix.c_str(), segmentOffset),
|
||||
GetActorListArraySize(), declaration);
|
||||
size_t actorNameLength = ZNames::GetActorName(entry.GetActorId()).size();
|
||||
if (actorNameLength > largestlength)
|
||||
largestlength = actorNameLength;
|
||||
}
|
||||
|
||||
size_t index = 0;
|
||||
for (auto& entry : actors)
|
||||
{
|
||||
entry.SetLargestActorName(largestlength);
|
||||
declaration += StringHelper::Sprintf("\t{ %s },", entry.GetBodySourceCode().c_str());
|
||||
|
||||
if (index < actors.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
const auto& entry = actors.front();
|
||||
|
||||
std::string varName = StringHelper::Sprintf("%sActorList_%06X", prefix.c_str(), segmentOffset);
|
||||
parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4,
|
||||
actors.size() * entry.GetRawDataSize(), entry.GetSourceTypeName(),
|
||||
varName, GetActorListArraySize(), declaration);
|
||||
}
|
||||
|
||||
std::string SetActorList::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "ActorEntry", listName);
|
||||
if (numActors != actors.size())
|
||||
{
|
||||
printf("%s: numActors(%i) ~ actors(%li)\n", parent->GetName().c_str(), numActors,
|
||||
actors.size());
|
||||
}
|
||||
return StringHelper::Sprintf("SCENE_CMD_ACTOR_LIST(%i, %s)", numActors, listName.c_str());
|
||||
}
|
||||
|
||||
size_t SetActorList::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize() + ((int32_t)actors.size() * 16);
|
||||
}
|
||||
|
||||
size_t SetActorList::GetActorListArraySize() const
|
||||
{
|
||||
size_t actorCount = 0;
|
||||
|
@ -110,27 +129,31 @@ ActorSpawnEntry::ActorSpawnEntry(const std::vector<uint8_t>& rawData, uint32_t r
|
|||
posX = BitConverter::ToInt16BE(rawData, rawDataIndex + 2);
|
||||
posY = BitConverter::ToInt16BE(rawData, rawDataIndex + 4);
|
||||
posZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 6);
|
||||
rotX = BitConverter::ToInt16BE(rawData, rawDataIndex + 8);
|
||||
rotY = BitConverter::ToInt16BE(rawData, rawDataIndex + 10);
|
||||
rotZ = BitConverter::ToInt16BE(rawData, rawDataIndex + 12);
|
||||
rotX = BitConverter::ToUInt16BE(rawData, rawDataIndex + 8);
|
||||
rotY = BitConverter::ToUInt16BE(rawData, rawDataIndex + 10);
|
||||
rotZ = BitConverter::ToUInt16BE(rawData, rawDataIndex + 12);
|
||||
initVar = BitConverter::ToInt16BE(rawData, rawDataIndex + 14);
|
||||
}
|
||||
|
||||
std::string ActorSpawnEntry::GetBodySourceCode() const
|
||||
{
|
||||
std::string body = "\n";
|
||||
std::string body;
|
||||
|
||||
body += "\t\t" + ZNames::GetActorName(actorNum) + ",\n";
|
||||
body += StringHelper::Sprintf("\t\t{ %6i, %6i, %6i },\n", posX, posY, posZ);
|
||||
std::string actorNameFmt = StringHelper::Sprintf("%%-%zus ", largestActorName + 1);
|
||||
body =
|
||||
StringHelper::Sprintf(actorNameFmt.c_str(), (ZNames::GetActorName(actorNum) + ",").c_str());
|
||||
|
||||
body += StringHelper::Sprintf("{ %6i, %6i, %6i }, ", posX, posY, posZ);
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
body += StringHelper::Sprintf("\t\t{ SPAWN_ROT_FLAGS(%i, 0x%04X), SPAWN_ROT_FLAGS(%i, "
|
||||
"0x%04X), SPAWN_ROT_FLAGS(%i, 0x%04X)},\n",
|
||||
body += StringHelper::Sprintf("{ SPAWN_ROT_FLAGS(%#5hX, 0x%04X)"
|
||||
", SPAWN_ROT_FLAGS(%#5hX, 0x%04X)"
|
||||
", SPAWN_ROT_FLAGS(%#5hX, 0x%04X) }, ",
|
||||
(rotX >> 7) & 0b111111111, rotX & 0b1111111,
|
||||
(rotY >> 7) & 0b111111111, rotY & 0b1111111,
|
||||
(rotZ >> 7) & 0b111111111, rotZ & 0b1111111);
|
||||
else
|
||||
body += StringHelper::Sprintf("\t\t{ %6i, %6i, %6i },\n", rotX, rotY, rotZ);
|
||||
body += StringHelper::Sprintf("\t\t0x%04X\n ", initVar);
|
||||
body += StringHelper::Sprintf("{ %#6hX, %#6hX, %#6hX }, ", rotX, rotY, rotZ);
|
||||
body += StringHelper::Sprintf("0x%04X", initVar);
|
||||
|
||||
return body;
|
||||
}
|
||||
|
@ -149,3 +172,8 @@ uint16_t ActorSpawnEntry::GetActorId() const
|
|||
{
|
||||
return actorNum;
|
||||
}
|
||||
|
||||
void ActorSpawnEntry::SetLargestActorName(size_t nameSize)
|
||||
{
|
||||
largestActorName = nameSize;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,16 @@
|
|||
class ActorSpawnEntry
|
||||
{
|
||||
public:
|
||||
uint16_t actorNum;
|
||||
int16_t posX;
|
||||
int16_t posY;
|
||||
int16_t posZ;
|
||||
uint16_t rotX;
|
||||
uint16_t rotY;
|
||||
uint16_t rotZ;
|
||||
uint16_t initVar;
|
||||
size_t largestActorName = 16;
|
||||
|
||||
ActorSpawnEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
|
@ -13,35 +23,28 @@ public:
|
|||
int32_t GetRawDataSize() const;
|
||||
|
||||
uint16_t GetActorId() const;
|
||||
|
||||
protected:
|
||||
uint16_t actorNum;
|
||||
int16_t posX;
|
||||
int16_t posY;
|
||||
int16_t posZ;
|
||||
int16_t rotX;
|
||||
int16_t rotY;
|
||||
int16_t rotZ;
|
||||
uint16_t initVar;
|
||||
void SetLargestActorName(size_t nameSize);
|
||||
};
|
||||
|
||||
class SetActorList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
uint8_t numActors;
|
||||
std::vector<ActorSpawnEntry> actors;
|
||||
|
||||
SetActorList(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
void ParseRawDataLate() override;
|
||||
void DeclareReferencesLate(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
protected:
|
||||
size_t GetActorListArraySize() const;
|
||||
|
||||
uint8_t numActors;
|
||||
std::vector<ActorSpawnEntry> actors;
|
||||
};
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
#include "SetAlternateHeaders.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Globals.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
|
||||
SetAlternateHeaders::SetAlternateHeaders(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
void SetAlternateHeaders::DeclareReferences(const std::string& prefix)
|
||||
void SetAlternateHeaders::DeclareReferences([[maybe_unused]] const std::string& prefix)
|
||||
{
|
||||
if (segmentOffset != 0)
|
||||
parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
if (cmdArg2 != 0)
|
||||
{
|
||||
std::string varName =
|
||||
StringHelper::Sprintf("%sAlternateHeaders0x%06X", prefix.c_str(), segmentOffset);
|
||||
parent->AddDeclarationPlaceholder(segmentOffset, varName);
|
||||
}
|
||||
}
|
||||
|
||||
void SetAlternateHeaders::ParseRawDataLate()
|
||||
|
@ -23,8 +28,14 @@ void SetAlternateHeaders::ParseRawDataLate()
|
|||
int32_t address = BitConverter::ToInt32BE(parent->GetRawData(), segmentOffset + (i * 4));
|
||||
headers.push_back(address);
|
||||
|
||||
if (address != 0)
|
||||
zRoom->commandSets.push_back(CommandSet(address));
|
||||
if (address != 0 && parent->GetDeclaration(GETSEGOFFSET(address)) == nullptr)
|
||||
{
|
||||
ZRoom* altheader = new ZRoom(parent);
|
||||
altheader->ExtractFromBinary(GETSEGOFFSET(address), zRoom->GetResourceType());
|
||||
altheader->DeclareReferences(parent->GetName());
|
||||
|
||||
parent->resources.push_back(altheader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,30 +43,30 @@ void SetAlternateHeaders::DeclareReferencesLate(const std::string& prefix)
|
|||
{
|
||||
if (!headers.empty())
|
||||
{
|
||||
std::string declaration = "";
|
||||
std::string declaration;
|
||||
|
||||
for (size_t i = 0; i < headers.size(); i++)
|
||||
{
|
||||
if (headers.at(i) == 0)
|
||||
declaration += StringHelper::Sprintf("\tNULL,");
|
||||
else
|
||||
declaration +=
|
||||
StringHelper::Sprintf("\t%sSet%04X,", prefix.c_str(), GETSEGOFFSET(headers[i]));
|
||||
std::string altHeaderName;
|
||||
Globals::Instance->GetSegmentedPtrName(headers.at(i), parent, "", altHeaderName);
|
||||
|
||||
declaration += StringHelper::Sprintf("\t%s,", altHeaderName.c_str());
|
||||
|
||||
if (i + 1 < headers.size())
|
||||
declaration += "\n";
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, headers.size() * 4, "SCmdBase*",
|
||||
StringHelper::Sprintf("%sAlternateHeaders0x%06X", prefix.c_str(), segmentOffset), 0,
|
||||
declaration);
|
||||
std::string varName =
|
||||
StringHelper::Sprintf("%sAlternateHeaders0x%06X", prefix.c_str(), segmentOffset);
|
||||
parent->AddDeclarationArray(segmentOffset, GetDeclarationAlignment(), headers.size() * 4,
|
||||
"SceneCmd*", varName, headers.size(), declaration);
|
||||
}
|
||||
}
|
||||
|
||||
std::string SetAlternateHeaders::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "SceneCmd*", listName);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ALTERNATE_HEADER_LIST(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
class SetAlternateHeaders : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
std::vector<uint32_t> headers;
|
||||
|
||||
SetAlternateHeaders(ZFile* nParent);
|
||||
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
@ -18,5 +20,4 @@ public:
|
|||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<uint32_t> headers;
|
||||
};
|
||||
|
|
|
@ -1,137 +1,42 @@
|
|||
/**
|
||||
* File: SetAnimatedMaterialList.cpp
|
||||
* Description: Defines a class SetAnimatedMaterialList to enable ZRoom to declare
|
||||
* ZTextureAnimations, using that ZResource to do the work.
|
||||
*/
|
||||
#include "SetAnimatedMaterialList.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
#include "ZTextureAnimation.h"
|
||||
|
||||
SetAnimatedMaterialList::SetAnimatedMaterialList(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
SetAnimatedMaterialList::SetAnimatedMaterialList(ZFile* nParent)
|
||||
: ZRoomCommand(nParent), textureAnimation(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
void SetAnimatedMaterialList::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
int32_t currentPtr = segmentOffset;
|
||||
bool keepGoing = true;
|
||||
|
||||
do
|
||||
{
|
||||
AnimatedMaterial lastTexture(parent->GetRawData(), currentPtr);
|
||||
keepGoing = (lastTexture.segment != 0) && (lastTexture.segment > -1);
|
||||
currentPtr += 8;
|
||||
textures.push_back(lastTexture);
|
||||
} while (keepGoing);
|
||||
textureAnimation.ExtractFromFile(segmentOffset);
|
||||
}
|
||||
|
||||
void SetAnimatedMaterialList::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
std::string nameStr =
|
||||
StringHelper::Sprintf("%sAnimatedMaterialList0x%06X", prefix.c_str(), segmentOffset);
|
||||
|
||||
for (auto& texture : textures)
|
||||
{
|
||||
size_t declSize = 0;
|
||||
std::string declTypeName = "";
|
||||
std::string declName = StringHelper::Sprintf("%sAnimatedMaterialParams0x%06X",
|
||||
prefix.c_str(), texture.segmentOffset);
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
switch (texture.type)
|
||||
{
|
||||
case 0:
|
||||
case 1:
|
||||
for (const auto& param : texture.params)
|
||||
{
|
||||
declaration += param->GenerateSourceCode(zRoom, texture.segmentOffset);
|
||||
|
||||
if (index < texture.params.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
declSize = texture.params.size() * 4;
|
||||
declTypeName = "AnimatedMatTexScrollParams";
|
||||
|
||||
parent->AddDeclarationArray(texture.segmentOffset, DeclarationAlignment::Align4,
|
||||
declSize, declTypeName, declName, texture.params.size(),
|
||||
declaration);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
declSize = texture.params.at(0)->GetParamsSize();
|
||||
declTypeName = "AnimatedMatColorParams";
|
||||
declaration = texture.params.at(0)->GenerateSourceCode(zRoom, texture.segmentOffset);
|
||||
|
||||
parent->AddDeclaration(texture.segmentOffset, DeclarationAlignment::Align4, declSize,
|
||||
declTypeName, declName,
|
||||
StringHelper::Sprintf("\n\t%s\n", declaration.c_str()));
|
||||
break;
|
||||
case 5:
|
||||
declSize = texture.params.at(0)->GetParamsSize();
|
||||
declTypeName = "AnimatedMatTexCycleParams";
|
||||
declaration = texture.params.at(0)->GenerateSourceCode(zRoom, texture.segmentOffset);
|
||||
|
||||
parent->AddDeclaration(texture.segmentOffset, DeclarationAlignment::Align4, declSize,
|
||||
declTypeName, declName,
|
||||
StringHelper::Sprintf("\n\t%s\n", declaration.c_str()));
|
||||
break;
|
||||
case 6:
|
||||
continue;
|
||||
|
||||
default:
|
||||
throw std::runtime_error(
|
||||
StringHelper::Sprintf("Error in SetAnimatedMaterialList::DeclareReferences (%s)\n"
|
||||
"\t Unknown texture.type: %i\n",
|
||||
nameStr.c_str(), texture.type));
|
||||
}
|
||||
}
|
||||
|
||||
if (!textures.empty())
|
||||
{
|
||||
std::string declaration = "";
|
||||
|
||||
for (size_t i = 0; i < textures.size(); i++)
|
||||
{
|
||||
std::string textureName = parent->GetDeclarationPtrName(textures.at(i).segmentAddress);
|
||||
|
||||
declaration += StringHelper::Sprintf("\t{ %2i, %2i, %s },", textures.at(i).segment,
|
||||
textures.at(i).type, textureName.c_str());
|
||||
|
||||
if (i + 1 < textures.size())
|
||||
declaration += "\n";
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4,
|
||||
DeclarationPadding::Pad16, textures.size() * 8,
|
||||
"AnimatedMaterial", nameStr, textures.size(), declaration);
|
||||
}
|
||||
textureAnimation.SetName(textureAnimation.GetDefaultName(prefix.c_str()));
|
||||
textureAnimation.DeclareReferences(prefix);
|
||||
textureAnimation.GetSourceOutputCode(prefix);
|
||||
}
|
||||
|
||||
std::string SetAnimatedMaterialList::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "AnimatedMaterial", listName);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ANIMATED_MATERIAL_LIST(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
size_t SetAnimatedMaterialList::GetRawDataSize() const
|
||||
{
|
||||
size_t paramsSize = 0;
|
||||
for (const auto& texture : textures)
|
||||
{
|
||||
for (const auto& param : texture.params)
|
||||
{
|
||||
paramsSize += param->GetParamsSize();
|
||||
}
|
||||
}
|
||||
|
||||
return ZRoomCommand::GetRawDataSize() + paramsSize;
|
||||
}
|
||||
|
||||
std::string SetAnimatedMaterialList::GetCommandCName() const
|
||||
{
|
||||
return "SCmdTextureAnimations";
|
||||
|
@ -141,273 +46,3 @@ RoomCommand SetAnimatedMaterialList::GetRoomCommand() const
|
|||
{
|
||||
return RoomCommand::SetAnimatedMaterialList;
|
||||
}
|
||||
|
||||
AnimatedMaterial::AnimatedMaterial(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: segment(rawData.at(rawDataIndex)), type(BitConverter::ToInt16BE(rawData, rawDataIndex + 2))
|
||||
{
|
||||
segmentAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
|
||||
segmentOffset = GETSEGOFFSET(segmentAddress);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 0:
|
||||
params.push_back(std::make_shared<ScrollingTexture>(rawData, segmentOffset));
|
||||
break;
|
||||
case 1:
|
||||
params.push_back(std::make_shared<ScrollingTexture>(rawData, segmentOffset));
|
||||
params.push_back(std::make_shared<ScrollingTexture>(rawData, segmentOffset + 4));
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
params.push_back(std::make_shared<FlashingTexture>(rawData, segmentOffset, type));
|
||||
break;
|
||||
case 5:
|
||||
params.push_back(std::make_shared<AnimatedMatTexCycleParams>(rawData, segmentOffset));
|
||||
break;
|
||||
case 6: // Some terminator when there are no animated textures?
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ScrollingTexture::ScrollingTexture(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: xStep(rawData.at(rawDataIndex + 0)), yStep(rawData.at(rawDataIndex + 1)),
|
||||
width(rawData.at(rawDataIndex + 2)), height(rawData.at(rawDataIndex + 3))
|
||||
{
|
||||
}
|
||||
|
||||
std::string ScrollingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress)
|
||||
{
|
||||
return StringHelper::Sprintf(" { %i, %i, 0x%02X, 0x%02X },", xStep, yStep, width, height);
|
||||
}
|
||||
|
||||
size_t ScrollingTexture::GetParamsSize()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
F3DPrimColor::F3DPrimColor(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: r(rawData.at(rawDataIndex + 0)), g(rawData.at(rawDataIndex + 1)),
|
||||
b(rawData.at(rawDataIndex + 2)), a(rawData.at(rawDataIndex + 3)),
|
||||
lodFrac(rawData.at(rawDataIndex + 4))
|
||||
{
|
||||
}
|
||||
|
||||
FlashingTextureEnvColor::FlashingTextureEnvColor(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: r(rawData.at(rawDataIndex + 0)), g(rawData.at(rawDataIndex + 1)),
|
||||
b(rawData.at(rawDataIndex + 2)), a(rawData.at(rawDataIndex + 3))
|
||||
{
|
||||
}
|
||||
|
||||
FlashingTexture::FlashingTexture(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex,
|
||||
int32_t type)
|
||||
: cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)),
|
||||
numKeyFrames(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2))
|
||||
{
|
||||
uint16_t length = (type == 2) ? cycleLength : numKeyFrames;
|
||||
|
||||
primColorSegmentAddr = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
|
||||
envColorSegmentAddr = BitConverter::ToInt32BE(rawData, rawDataIndex + 8);
|
||||
keyFrameSegmentAddr = BitConverter::ToInt32BE(rawData, rawDataIndex + 12);
|
||||
|
||||
primColorSegmentOffset = GETSEGOFFSET(primColorSegmentAddr);
|
||||
envColorSegmentOffset = GETSEGOFFSET(envColorSegmentAddr);
|
||||
keyFrameSegmentOffset = GETSEGOFFSET(keyFrameSegmentAddr);
|
||||
|
||||
int32_t currentPtr = primColorSegmentOffset;
|
||||
for (uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
primColors.push_back(F3DPrimColor(rawData, currentPtr));
|
||||
currentPtr += 5;
|
||||
}
|
||||
|
||||
currentPtr = envColorSegmentOffset;
|
||||
for (uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
envColors.push_back(FlashingTextureEnvColor(rawData, currentPtr));
|
||||
currentPtr += 4;
|
||||
}
|
||||
|
||||
currentPtr = keyFrameSegmentOffset;
|
||||
for (uint16_t i = 0; i < length; i++)
|
||||
{
|
||||
keyFrames.push_back(BitConverter::ToUInt16BE(rawData, currentPtr));
|
||||
currentPtr += 2;
|
||||
}
|
||||
}
|
||||
|
||||
std::string FlashingTexture::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress)
|
||||
{
|
||||
if (primColorSegmentOffset != 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (F3DPrimColor& color : primColors)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X },",
|
||||
color.r, color.g, color.b, color.a, color.lodFrac);
|
||||
|
||||
if (index < primColors.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(primColorSegmentOffset, DeclarationAlignment::Align4,
|
||||
primColors.size() * 5, "F3DPrimColor",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialPrimColor_%06X",
|
||||
zRoom->GetName().c_str(),
|
||||
primColorSegmentOffset),
|
||||
primColors.size(), declaration);
|
||||
}
|
||||
|
||||
if (envColorSegmentOffset != 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (FlashingTextureEnvColor& color : envColors)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" { 0x%02X, 0x%02X, 0x%02X, 0x%02X },", color.r,
|
||||
color.g, color.b, color.a);
|
||||
|
||||
if (index < envColors.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
envColorSegmentOffset, DeclarationAlignment::Align4, envColors.size() * 4,
|
||||
"F3DEnvColor",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialEnvColors0x%06X", zRoom->GetName().c_str(),
|
||||
envColorSegmentOffset),
|
||||
envColors.size(), declaration);
|
||||
}
|
||||
|
||||
if (keyFrameSegmentOffset != 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (uint16_t keyFrame : keyFrames)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" 0x%02X,", keyFrame);
|
||||
|
||||
if (index < keyFrames.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
keyFrameSegmentOffset, DeclarationAlignment::Align4, keyFrames.size() * 2, "u16",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialKeyFrames0x%06X", zRoom->GetName().c_str(),
|
||||
keyFrameSegmentOffset),
|
||||
keyFrames.size(), declaration);
|
||||
}
|
||||
|
||||
std::string primName = zRoom->parent->GetDeclarationPtrName(primColorSegmentAddr);
|
||||
std::string envName = zRoom->parent->GetDeclarationPtrName(envColorSegmentAddr);
|
||||
std::string keyName = zRoom->parent->GetDeclarationPtrName(keyFrameSegmentAddr);
|
||||
|
||||
return StringHelper::Sprintf("%i, %i, %s, %s, %s", cycleLength, numKeyFrames, primName.c_str(),
|
||||
envName.c_str(), keyName.c_str());
|
||||
}
|
||||
|
||||
size_t FlashingTexture::GetParamsSize()
|
||||
{
|
||||
return 16;
|
||||
}
|
||||
|
||||
AnimatedMatTexCycleParams::AnimatedMatTexCycleParams(const std::vector<uint8_t>& rawData,
|
||||
uint32_t rawDataIndex)
|
||||
: cycleLength(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0))
|
||||
{
|
||||
textureSegmentOffsetsSegmentAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 4);
|
||||
textureIndicesSegmentAddress = BitConverter::ToInt32BE(rawData, rawDataIndex + 8);
|
||||
|
||||
textureSegmentOffsetsSegmentOffset = GETSEGOFFSET(textureSegmentOffsetsSegmentAddress);
|
||||
textureIndicesSegmentOffset = GETSEGOFFSET(textureIndicesSegmentAddress);
|
||||
|
||||
int32_t currentPtr = textureIndicesSegmentOffset;
|
||||
int32_t maxIndex = 0;
|
||||
|
||||
for (uint16_t i = 0; i < cycleLength; i++)
|
||||
{
|
||||
uint8_t newIndex = rawData.at(currentPtr);
|
||||
textureIndices.push_back(newIndex);
|
||||
currentPtr++;
|
||||
if (newIndex > maxIndex)
|
||||
maxIndex = newIndex;
|
||||
}
|
||||
|
||||
currentPtr = textureSegmentOffsetsSegmentOffset;
|
||||
for (int32_t i = 0; i < maxIndex + 1; i++)
|
||||
{
|
||||
textureSegmentOffsets.push_back(GETSEGOFFSET(BitConverter::ToInt32BE(rawData, currentPtr)));
|
||||
currentPtr += 4;
|
||||
}
|
||||
}
|
||||
|
||||
std::string AnimatedMatTexCycleParams::GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress)
|
||||
{
|
||||
if (textureSegmentOffsetsSegmentOffset != 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (uint32_t offset : textureSegmentOffsets)
|
||||
{
|
||||
declaration +=
|
||||
StringHelper::Sprintf(" %sTex_%06X,", zRoom->GetName().c_str(), offset);
|
||||
|
||||
if (index < textureSegmentOffsets.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
textureSegmentOffsetsSegmentOffset, DeclarationAlignment::Align4,
|
||||
textureSegmentOffsets.size() * 4, "u64*",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialTexSegOffsets0x%06X", zRoom->GetName().c_str(),
|
||||
textureSegmentOffsetsSegmentOffset),
|
||||
textureSegmentOffsets.size(), declaration);
|
||||
}
|
||||
|
||||
if (textureIndicesSegmentOffset != 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
size_t index = 0;
|
||||
|
||||
for (uint8_t textureIndex : textureIndices)
|
||||
{
|
||||
declaration += StringHelper::Sprintf(" 0x%02X,", textureIndex);
|
||||
|
||||
if (index < textureIndices.size() - 1)
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
zRoom->parent->AddDeclarationArray(
|
||||
textureIndicesSegmentOffset, DeclarationAlignment::Align4, textureIndices.size(), "u8",
|
||||
StringHelper::Sprintf("%sAnimatedMaterialTexIndices0x%06X", zRoom->GetName().c_str(),
|
||||
textureIndicesSegmentOffset),
|
||||
textureIndices.size(), declaration);
|
||||
}
|
||||
|
||||
std::string segmName =
|
||||
zRoom->parent->GetDeclarationPtrName(textureSegmentOffsetsSegmentAddress);
|
||||
std::string indexesName = zRoom->parent->GetDeclarationPtrName(textureIndicesSegmentAddress);
|
||||
|
||||
return StringHelper::Sprintf("%i, %s, %s", cycleLength, segmName.c_str(), indexesName.c_str());
|
||||
}
|
||||
|
||||
size_t AnimatedMatTexCycleParams::GetParamsSize()
|
||||
{
|
||||
return 12;
|
||||
}
|
||||
|
|
|
@ -1,104 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
// TODO move into header and add all types
|
||||
class AnitmatedTextureParams
|
||||
{
|
||||
public:
|
||||
virtual std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) = 0;
|
||||
virtual size_t GetParamsSize() = 0;
|
||||
};
|
||||
|
||||
class ScrollingTexture : public AnitmatedTextureParams
|
||||
{
|
||||
public:
|
||||
ScrollingTexture(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override;
|
||||
size_t GetParamsSize() override;
|
||||
|
||||
int8_t xStep;
|
||||
int8_t yStep;
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
};
|
||||
|
||||
class F3DPrimColor
|
||||
{
|
||||
public:
|
||||
F3DPrimColor(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t a;
|
||||
uint8_t lodFrac;
|
||||
};
|
||||
|
||||
class FlashingTextureEnvColor
|
||||
{
|
||||
public:
|
||||
FlashingTextureEnvColor(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t a;
|
||||
};
|
||||
|
||||
class FlashingTexture : public AnitmatedTextureParams
|
||||
{
|
||||
public:
|
||||
FlashingTexture(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex, int32_t type);
|
||||
std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override;
|
||||
size_t GetParamsSize() override;
|
||||
|
||||
uint16_t cycleLength;
|
||||
uint16_t numKeyFrames;
|
||||
|
||||
segptr_t primColorSegmentAddr;
|
||||
segptr_t envColorSegmentAddr;
|
||||
segptr_t keyFrameSegmentAddr;
|
||||
|
||||
uint32_t primColorSegmentOffset;
|
||||
uint32_t envColorSegmentOffset;
|
||||
uint32_t keyFrameSegmentOffset;
|
||||
|
||||
std::vector<F3DPrimColor> primColors;
|
||||
std::vector<FlashingTextureEnvColor> envColors;
|
||||
std::vector<uint16_t> keyFrames;
|
||||
};
|
||||
|
||||
class AnimatedMatTexCycleParams : public AnitmatedTextureParams
|
||||
{
|
||||
public:
|
||||
AnimatedMatTexCycleParams(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
std::string GenerateSourceCode(ZRoom* zRoom, uint32_t baseAddress) override;
|
||||
size_t GetParamsSize() override;
|
||||
|
||||
uint16_t cycleLength;
|
||||
|
||||
segptr_t textureSegmentOffsetsSegmentAddress;
|
||||
segptr_t textureIndicesSegmentAddress;
|
||||
uint32_t textureSegmentOffsetsSegmentOffset;
|
||||
uint32_t textureIndicesSegmentOffset;
|
||||
|
||||
std::vector<uint32_t> textureSegmentOffsets;
|
||||
std::vector<uint8_t> textureIndices;
|
||||
};
|
||||
|
||||
class AnimatedMaterial
|
||||
{
|
||||
public:
|
||||
AnimatedMaterial(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
int8_t segment;
|
||||
int16_t type;
|
||||
segptr_t segmentAddress;
|
||||
uint32_t segmentOffset;
|
||||
std::vector<std::shared_ptr<AnitmatedTextureParams>> params;
|
||||
};
|
||||
#include "ZTextureAnimation.h"
|
||||
|
||||
class SetAnimatedMaterialList : public ZRoomCommand
|
||||
{
|
||||
|
@ -111,9 +14,8 @@ public:
|
|||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<AnimatedMaterial> textures;
|
||||
ZTextureAnimation textureAnimation;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "SetCameraSettings.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
|
||||
SetCameraSettings::SetCameraSettings(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
class SetCameraSettings : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
uint8_t cameraMovement;
|
||||
uint32_t mapHighlight;
|
||||
|
||||
SetCameraSettings(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
|
@ -15,6 +18,4 @@ public:
|
|||
RoomCommand GetRoomCommand() const override;
|
||||
|
||||
private:
|
||||
uint8_t cameraMovement;
|
||||
uint32_t mapHighlight;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include "SetCollisionHeader.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Globals.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
|
@ -12,21 +13,23 @@ SetCollisionHeader::SetCollisionHeader(ZFile* nParent) : ZRoomCommand(nParent)
|
|||
void SetCollisionHeader::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
|
||||
collisionHeader = new ZCollisionHeader(parent);
|
||||
collisionHeader->SetRawDataIndex(segmentOffset);
|
||||
collisionHeader->SetName(
|
||||
StringHelper::Sprintf("%sCollisionHeader_%06X", parent->GetName().c_str(), segmentOffset));
|
||||
collisionHeader->ParseRawData();
|
||||
collisionHeader->ExtractFromFile(segmentOffset);
|
||||
parent->AddResource(collisionHeader);
|
||||
}
|
||||
|
||||
SetCollisionHeader::~SetCollisionHeader()
|
||||
void SetCollisionHeader::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
delete collisionHeader;
|
||||
collisionHeader->DeclareVar(prefix, "");
|
||||
}
|
||||
|
||||
std::string SetCollisionHeader::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CollisionHeader", listName);
|
||||
return StringHelper::Sprintf("SCENE_CMD_COL_HEADER(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -6,16 +6,15 @@
|
|||
class SetCollisionHeader : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
ZCollisionHeader* collisionHeader;
|
||||
|
||||
SetCollisionHeader(ZFile* nParent);
|
||||
~SetCollisionHeader();
|
||||
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetCommandCName() const override;
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
|
||||
private:
|
||||
ZCollisionHeader* collisionHeader;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include "SetCsCamera.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Globals.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
|
@ -33,31 +34,23 @@ void SetCsCamera::ParseRawData()
|
|||
for (int32_t i = 0; i < numPoints; i++)
|
||||
{
|
||||
ZVector vec(parent);
|
||||
vec.SetRawDataIndex(currentPtr);
|
||||
vec.SetScalarType(ZScalarType::ZSCALAR_S16);
|
||||
vec.SetDimensions(3);
|
||||
vec.ParseRawData();
|
||||
vec.ExtractFromBinary(currentPtr, ZScalarType::ZSCALAR_S16, 3);
|
||||
|
||||
currentPtr += vec.GetRawDataSize();
|
||||
points.push_back(vec);
|
||||
}
|
||||
}
|
||||
|
||||
if (segmentOffset != 0)
|
||||
parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
}
|
||||
|
||||
void SetCsCamera::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
if (points.size() > 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
std::string declaration;
|
||||
size_t index = 0;
|
||||
for (auto& point : points)
|
||||
{
|
||||
declaration +=
|
||||
StringHelper::Sprintf("\t%s, //0x%06X", point.GetBodySourceCode().c_str(),
|
||||
cameras.at(0).segmentOffset + (index * 6));
|
||||
declaration += StringHelper::Sprintf("\t{ %s },", point.GetBodySourceCode().c_str());
|
||||
|
||||
if (index < points.size() - 1)
|
||||
declaration += "\n";
|
||||
|
@ -76,8 +69,10 @@ void SetCsCamera::DeclareReferences(const std::string& prefix)
|
|||
|
||||
if (!cameras.empty())
|
||||
{
|
||||
std::string camPointsName = parent->GetDeclarationName(cameras.at(0).GetSegmentOffset());
|
||||
std::string declaration = "";
|
||||
std::string camPointsName;
|
||||
Globals::Instance->GetSegmentedPtrName(cameras.at(0).GetCamAddress(), parent, "Vec3s",
|
||||
camPointsName);
|
||||
std::string declaration;
|
||||
|
||||
size_t index = 0;
|
||||
size_t pointsIndex = 0;
|
||||
|
@ -98,8 +93,8 @@ void SetCsCamera::DeclareReferences(const std::string& prefix)
|
|||
std::string camTypename = entry.GetSourceTypeName();
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::Align4, DeclarationPadding::Pad16,
|
||||
cameras.size() * entry.GetRawDataSize(), camTypename,
|
||||
segmentOffset, DeclarationAlignment::Align4, cameras.size() * entry.GetRawDataSize(),
|
||||
camTypename,
|
||||
StringHelper::Sprintf("%s%s_%06X", prefix.c_str(), camTypename.c_str(), segmentOffset),
|
||||
cameras.size(), declaration);
|
||||
}
|
||||
|
@ -107,16 +102,12 @@ void SetCsCamera::DeclareReferences(const std::string& prefix)
|
|||
|
||||
std::string SetCsCamera::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CsCameraEntry", listName);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ACTOR_CUTSCENE_CAM_LIST(%i, %s)", cameras.size(),
|
||||
listName.c_str());
|
||||
}
|
||||
|
||||
size_t SetCsCamera::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize() + (cameras.size() * 8) + (points.size() * 6);
|
||||
}
|
||||
|
||||
std::string SetCsCamera::GetCommandCName() const
|
||||
{
|
||||
return "SCmdCsCameraList";
|
||||
|
|
|
@ -25,6 +25,9 @@ public:
|
|||
class SetCsCamera : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
std::vector<CsCameraEntry> cameras;
|
||||
std::vector<ZVector> points;
|
||||
|
||||
SetCsCamera(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
|
@ -33,10 +36,5 @@ public:
|
|||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<CsCameraEntry> cameras;
|
||||
std::vector<ZVector> points;
|
||||
};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "SetCutscenes.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
|
@ -10,10 +10,16 @@ SetCutscenes::SetCutscenes(ZFile* nParent) : ZRoomCommand(nParent)
|
|||
{
|
||||
}
|
||||
|
||||
SetCutscenes::~SetCutscenes()
|
||||
{
|
||||
for (ZCutsceneBase* cutscene : cutscenes)
|
||||
delete cutscene;
|
||||
}
|
||||
|
||||
void SetCutscenes::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
std::string output = "";
|
||||
std::string output;
|
||||
|
||||
numCutscenes = cmdArg1;
|
||||
if (Globals::Instance->game == ZGame::OOT_RETAIL || Globals::Instance->game == ZGame::OOT_SW97)
|
||||
|
@ -32,7 +38,7 @@ void SetCutscenes::ParseRawData()
|
|||
else
|
||||
{
|
||||
int32_t currentPtr = segmentOffset;
|
||||
std::string declaration = "";
|
||||
std::string declaration;
|
||||
|
||||
for (uint8_t i = 0; i < numCutscenes; i++)
|
||||
{
|
||||
|
@ -40,8 +46,9 @@ void SetCutscenes::ParseRawData()
|
|||
cutsceneEntries.push_back(entry);
|
||||
currentPtr += 8;
|
||||
|
||||
// TODO: don't hardcode %sCutsceneData_%06X, look up for the declared name instead
|
||||
declaration += StringHelper::Sprintf(
|
||||
" { %sCutsceneData0x%06X, 0x%04X, 0x%02X, 0x%02X },", zRoom->GetName().c_str(),
|
||||
" { %sCutsceneData_%06X, 0x%04X, 0x%02X, 0x%02X },", zRoom->GetName().c_str(),
|
||||
entry.segmentOffset, entry.exit, entry.entrance, entry.flag);
|
||||
|
||||
if (i < numCutscenes - 1)
|
||||
|
@ -61,9 +68,9 @@ void SetCutscenes::ParseRawData()
|
|||
|
||||
for (ZCutsceneBase* cutscene : cutscenes)
|
||||
{
|
||||
if (cutscene->getSegmentOffset() != 0)
|
||||
if (cutscene->GetRawDataIndex() != 0)
|
||||
{
|
||||
Declaration* decl = parent->GetDeclaration(cutscene->getSegmentOffset());
|
||||
Declaration* decl = parent->GetDeclaration(cutscene->GetRawDataIndex());
|
||||
if (decl == nullptr)
|
||||
{
|
||||
cutscene->GetSourceOutputCode(zRoom->GetName());
|
||||
|
@ -76,15 +83,10 @@ void SetCutscenes::ParseRawData()
|
|||
}
|
||||
}
|
||||
|
||||
SetCutscenes::~SetCutscenes()
|
||||
{
|
||||
for (ZCutsceneBase* cutscene : cutscenes)
|
||||
delete cutscene;
|
||||
}
|
||||
|
||||
std::string SetCutscenes::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "CutsceneData", listName);
|
||||
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_LIST(%i, %s)", numCutscenes,
|
||||
|
@ -92,11 +94,6 @@ std::string SetCutscenes::GetBodySourceCode() const
|
|||
return StringHelper::Sprintf("SCENE_CMD_CUTSCENE_DATA(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
size_t SetCutscenes::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize();
|
||||
}
|
||||
|
||||
std::string SetCutscenes::GetCommandCName() const
|
||||
{
|
||||
return "SCmdCutsceneData";
|
||||
|
|
|
@ -18,6 +18,10 @@ public:
|
|||
class SetCutscenes : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
std::vector<ZCutsceneBase*> cutscenes;
|
||||
std::vector<CutsceneEntry> cutsceneEntries; // (MM Only)
|
||||
uint8_t numCutscenes; // (MM Only)
|
||||
|
||||
SetCutscenes(ZFile* nParent);
|
||||
~SetCutscenes();
|
||||
|
||||
|
@ -26,11 +30,5 @@ public:
|
|||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<ZCutsceneBase*> cutscenes;
|
||||
std::vector<CutsceneEntry> cutsceneEntries; // (MM Only)
|
||||
uint8_t numCutscenes; // (MM Only)
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "SetEchoSettings.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
|
||||
SetEchoSettings::SetEchoSettings(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
class SetEchoSettings : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
uint8_t echo;
|
||||
|
||||
SetEchoSettings(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
|
@ -13,7 +15,4 @@ public:
|
|||
|
||||
std::string GetCommandCName() const override;
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
|
||||
private:
|
||||
uint8_t echo;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include "SetEntranceList.h"
|
||||
#include "BitConverter.h"
|
||||
|
||||
#include "Globals.h"
|
||||
#include "SetStartPositionList.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
|
@ -9,10 +11,14 @@ SetEntranceList::SetEntranceList(ZFile* nParent) : ZRoomCommand(nParent)
|
|||
{
|
||||
}
|
||||
|
||||
void SetEntranceList::DeclareReferences(const std::string& prefix)
|
||||
void SetEntranceList::DeclareReferences([[maybe_unused]] const std::string& prefix)
|
||||
{
|
||||
if (segmentOffset != 0)
|
||||
parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
{
|
||||
std::string varName =
|
||||
StringHelper::Sprintf("%sEntranceList0x%06X", prefix.c_str(), segmentOffset);
|
||||
parent->AddDeclarationPlaceholder(segmentOffset, varName);
|
||||
}
|
||||
}
|
||||
|
||||
void SetEntranceList::ParseRawDataLate()
|
||||
|
@ -30,34 +36,34 @@ void SetEntranceList::ParseRawDataLate()
|
|||
}
|
||||
}
|
||||
|
||||
void SetEntranceList::DeclareReferencesLate(const std::string& prefix)
|
||||
void SetEntranceList::DeclareReferencesLate([[maybe_unused]] const std::string& prefix)
|
||||
{
|
||||
if (!entrances.empty())
|
||||
{
|
||||
std::string declaration = "";
|
||||
std::string declaration;
|
||||
|
||||
size_t index = 0;
|
||||
for (const auto& entry : entrances)
|
||||
{
|
||||
declaration +=
|
||||
StringHelper::Sprintf(" { %s }, //0x%06X", entry.GetBodySourceCode().c_str(),
|
||||
segmentOffset + (index * 2));
|
||||
declaration += StringHelper::Sprintf(" { %s },", entry.GetBodySourceCode().c_str());
|
||||
if (index + 1 < entrances.size())
|
||||
declaration += "\n";
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, entrances.size() * 2, "EntranceEntry",
|
||||
StringHelper::Sprintf("%sEntranceList0x%06X", zRoom->GetName().c_str(), segmentOffset),
|
||||
entrances.size(), declaration);
|
||||
std::string varName =
|
||||
StringHelper::Sprintf("%sEntranceList0x%06X", prefix.c_str(), segmentOffset);
|
||||
parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4,
|
||||
entrances.size() * 2, "EntranceEntry", varName,
|
||||
entrances.size(), declaration);
|
||||
}
|
||||
}
|
||||
|
||||
std::string SetEntranceList::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "EntranceEntry", listName);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ENTRANCE_LIST(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -5,18 +5,19 @@
|
|||
class EntranceEntry
|
||||
{
|
||||
public:
|
||||
uint8_t startPositionIndex;
|
||||
uint8_t roomToLoad;
|
||||
|
||||
EntranceEntry(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
|
||||
protected:
|
||||
uint8_t startPositionIndex;
|
||||
uint8_t roomToLoad;
|
||||
};
|
||||
|
||||
class SetEntranceList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
std::vector<EntranceEntry> entrances;
|
||||
|
||||
SetEntranceList(ZFile* nParent);
|
||||
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
@ -27,7 +28,4 @@ public:
|
|||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<EntranceEntry> entrances;
|
||||
};
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#include "SetExitList.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Globals.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
|
@ -9,10 +10,14 @@ SetExitList::SetExitList(ZFile* nParent) : ZRoomCommand(nParent)
|
|||
{
|
||||
}
|
||||
|
||||
void SetExitList::DeclareReferences(const std::string& prefix)
|
||||
void SetExitList::DeclareReferences([[maybe_unused]] const std::string& prefix)
|
||||
{
|
||||
if (segmentOffset != 0)
|
||||
parent->AddDeclarationPlaceholder(segmentOffset);
|
||||
{
|
||||
std::string varName =
|
||||
StringHelper::Sprintf("%sExitList_%06X", prefix.c_str(), segmentOffset);
|
||||
parent->AddDeclarationPlaceholder(segmentOffset, varName);
|
||||
}
|
||||
}
|
||||
|
||||
void SetExitList::ParseRawDataLate()
|
||||
|
@ -30,11 +35,11 @@ void SetExitList::ParseRawDataLate()
|
|||
}
|
||||
}
|
||||
|
||||
void SetExitList::DeclareReferencesLate(const std::string& prefix)
|
||||
void SetExitList::DeclareReferencesLate([[maybe_unused]] const std::string& prefix)
|
||||
{
|
||||
if (!exits.empty())
|
||||
{
|
||||
std::string declaration = "";
|
||||
std::string declaration;
|
||||
|
||||
for (size_t i = 0; i < exits.size(); i++)
|
||||
{
|
||||
|
@ -43,16 +48,17 @@ void SetExitList::DeclareReferencesLate(const std::string& prefix)
|
|||
declaration += "\n";
|
||||
}
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::Align4, exits.size() * 2, "u16",
|
||||
StringHelper::Sprintf("%sExitList_%06X", zRoom->GetName().c_str(), segmentOffset),
|
||||
exits.size(), declaration);
|
||||
std::string varName =
|
||||
StringHelper::Sprintf("%sExitList_%06X", prefix.c_str(), segmentOffset);
|
||||
parent->AddDeclarationArray(segmentOffset, DeclarationAlignment::Align4, exits.size() * 2,
|
||||
"u16", varName, exits.size(), declaration);
|
||||
}
|
||||
}
|
||||
|
||||
std::string SetExitList::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "u16", listName);
|
||||
return StringHelper::Sprintf("SCENE_CMD_EXIT_LIST(%s)", listName.c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
class SetExitList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
std::vector<uint16_t> exits;
|
||||
|
||||
SetExitList(ZFile* nParent);
|
||||
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
@ -15,7 +17,4 @@ public:
|
|||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<uint16_t> exits;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "SetLightList.h"
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
#include "Globals.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
|
||||
SetLightList::SetLightList(ZFile* nParent) : ZRoomCommand(nParent)
|
||||
{
|
||||
|
@ -9,7 +11,7 @@ SetLightList::SetLightList(ZFile* nParent) : ZRoomCommand(nParent)
|
|||
void SetLightList::ParseRawData()
|
||||
{
|
||||
ZRoomCommand::ParseRawData();
|
||||
std::string declarations = "";
|
||||
std::string declarations;
|
||||
|
||||
numLights = cmdArg1;
|
||||
int32_t currentPtr = segmentOffset;
|
||||
|
@ -26,7 +28,7 @@ void SetLightList::DeclareReferences(const std::string& prefix)
|
|||
{
|
||||
if (!lights.empty())
|
||||
{
|
||||
std::string declarations = "";
|
||||
std::string declarations;
|
||||
|
||||
for (size_t i = 0; i < lights.size(); i++)
|
||||
{
|
||||
|
@ -40,7 +42,7 @@ void SetLightList::DeclareReferences(const std::string& prefix)
|
|||
const auto& light = lights.front();
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, lights.size() * light.GetRawDataSize(),
|
||||
segmentOffset, DeclarationAlignment::Align4, lights.size() * light.GetRawDataSize(),
|
||||
light.GetSourceTypeName(),
|
||||
StringHelper::Sprintf("%sLightInfo0x%06X", prefix.c_str(), segmentOffset),
|
||||
lights.size(), declarations);
|
||||
|
@ -49,7 +51,8 @@ void SetLightList::DeclareReferences(const std::string& prefix)
|
|||
|
||||
std::string SetLightList::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "LightInfo", listName);
|
||||
return StringHelper::Sprintf("SCENE_CMD_LIGHT_LIST(%i, %s)", numLights, listName.c_str());
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,9 @@ protected:
|
|||
class SetLightList : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
uint8_t numLights;
|
||||
std::vector<LightInfo> lights;
|
||||
|
||||
SetLightList(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
|
@ -36,8 +39,4 @@ public:
|
|||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
uint8_t numLights;
|
||||
std::vector<LightInfo> lights;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "SetLightingSettings.h"
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
#include "Globals.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
|
@ -21,13 +23,12 @@ void SetLightingSettings::DeclareReferences(const std::string& prefix)
|
|||
{
|
||||
if (settings.size() > 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
std::string declaration;
|
||||
|
||||
for (size_t i = 0; i < settings.size(); i++)
|
||||
{
|
||||
declaration += StringHelper::Sprintf("\t{ %s }, // 0x%06X",
|
||||
settings.at(i).GetBodySourceCode().c_str(),
|
||||
segmentOffset + (i * 22));
|
||||
declaration +=
|
||||
StringHelper::Sprintf("\t{ %s },", settings.at(i).GetBodySourceCode().c_str());
|
||||
if (i + 1 < settings.size())
|
||||
declaration += "\n";
|
||||
}
|
||||
|
@ -42,7 +43,8 @@ void SetLightingSettings::DeclareReferences(const std::string& prefix)
|
|||
|
||||
std::string SetLightingSettings::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "LightSettings", listName);
|
||||
return StringHelper::Sprintf("SCENE_CMD_ENV_LIGHT_SETTINGS(%i, %s)", settings.size(),
|
||||
listName.c_str());
|
||||
}
|
||||
|
|
|
@ -5,13 +5,6 @@
|
|||
class LightingSettings
|
||||
{
|
||||
public:
|
||||
LightingSettings(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
|
||||
size_t GetRawDataSize() const;
|
||||
|
||||
protected:
|
||||
uint8_t ambientClrR, ambientClrG, ambientClrB;
|
||||
uint8_t diffuseClrA_R, diffuseClrA_G, diffuseClrA_B;
|
||||
uint8_t diffuseDirA_X, diffuseDirA_Y, diffuseDirA_Z;
|
||||
|
@ -20,11 +13,19 @@ protected:
|
|||
uint8_t fogClrR, fogClrG, fogClrB;
|
||||
uint16_t unk;
|
||||
uint16_t drawDistance;
|
||||
|
||||
LightingSettings(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex);
|
||||
|
||||
std::string GetBodySourceCode() const;
|
||||
|
||||
size_t GetRawDataSize() const;
|
||||
};
|
||||
|
||||
class SetLightingSettings : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
std::vector<LightingSettings> settings;
|
||||
|
||||
SetLightingSettings(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
|
@ -34,7 +35,4 @@ public:
|
|||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
std::vector<LightingSettings> settings;
|
||||
};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "SetMesh.h"
|
||||
#include <Globals.h>
|
||||
#include <Path.h>
|
||||
#include "BitConverter.h"
|
||||
#include "StringHelper.h"
|
||||
#include <Utils/Path.h>
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZBackground.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
@ -22,15 +22,15 @@ void SetMesh::ParseRawData()
|
|||
switch (meshHeaderType)
|
||||
{
|
||||
case 0:
|
||||
polyType = std::make_shared<PolygonType2>(parent, parentRawData, segmentOffset, zRoom);
|
||||
polyType = std::make_shared<PolygonType2>(parent, segmentOffset, zRoom);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
polyType = std::make_shared<PolygonType1>(parent, parentRawData, segmentOffset, zRoom);
|
||||
polyType = std::make_shared<PolygonType1>(parent, segmentOffset, zRoom);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
polyType = std::make_shared<PolygonType2>(parent, parentRawData, segmentOffset, zRoom);
|
||||
polyType = std::make_shared<PolygonType2>(parent, segmentOffset, zRoom);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -49,37 +49,23 @@ void SetMesh::DeclareReferences(const std::string& prefix)
|
|||
polyType->DeclareAndGenerateOutputCode(prefix);
|
||||
}
|
||||
|
||||
// TODO: is this really needed?
|
||||
void GenDListDeclarations(ZRoom* zRoom, ZFile* parent, ZDisplayList* dList)
|
||||
{
|
||||
if (dList == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::string srcVarName =
|
||||
StringHelper::Sprintf("%s%s", zRoom->GetName().c_str(), dList->GetName().c_str());
|
||||
|
||||
dList->SetName(srcVarName);
|
||||
dList->scene = zRoom->scene;
|
||||
std::string sourceOutput = dList->GetSourceOutputCode(zRoom->GetName());
|
||||
|
||||
for (ZDisplayList* otherDList : dList->otherDLists)
|
||||
GenDListDeclarations(zRoom, parent, otherDList);
|
||||
|
||||
for (const auto& vtxEntry : dList->vtxDeclarations)
|
||||
{
|
||||
DeclarationAlignment alignment = DeclarationAlignment::Align4;
|
||||
if (Globals::Instance->game == ZGame::MM_RETAIL)
|
||||
alignment = DeclarationAlignment::None;
|
||||
parent->AddDeclarationArray(
|
||||
vtxEntry.first, alignment, dList->vertices[vtxEntry.first].size() * 16, "static Vtx",
|
||||
StringHelper::Sprintf("%sVtx_%06X", zRoom->GetName().c_str(), vtxEntry.first),
|
||||
dList->vertices[vtxEntry.first].size(), vtxEntry.second);
|
||||
}
|
||||
}
|
||||
|
||||
std::string SetMesh::GenDListExterns(ZDisplayList* dList)
|
||||
{
|
||||
std::string sourceOutput = "";
|
||||
std::string sourceOutput;
|
||||
|
||||
sourceOutput += StringHelper::Sprintf("extern Gfx %sDL_%06X[];\n", zRoom->GetName().c_str(),
|
||||
dList->GetRawDataIndex());
|
||||
|
@ -87,22 +73,16 @@ std::string SetMesh::GenDListExterns(ZDisplayList* dList)
|
|||
for (ZDisplayList* otherDList : dList->otherDLists)
|
||||
sourceOutput += GenDListExterns(otherDList);
|
||||
|
||||
sourceOutput += dList->defines;
|
||||
|
||||
return sourceOutput;
|
||||
}
|
||||
|
||||
std::string SetMesh::GetBodySourceCode() const
|
||||
{
|
||||
std::string list = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string list;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "", list);
|
||||
return StringHelper::Sprintf("SCENE_CMD_MESH(%s)", list.c_str());
|
||||
}
|
||||
|
||||
size_t SetMesh::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize();
|
||||
}
|
||||
|
||||
std::string SetMesh::GetCommandCName() const
|
||||
{
|
||||
return "SCmdMesh";
|
||||
|
@ -113,14 +93,8 @@ RoomCommand SetMesh::GetRoomCommand() const
|
|||
return RoomCommand::SetMesh;
|
||||
}
|
||||
|
||||
PolygonDlist::PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom)
|
||||
PolygonDlist::PolygonDlist(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
rawDataIndex = nRawDataIndex;
|
||||
parent = nParent;
|
||||
zRoom = nRoom;
|
||||
|
||||
name = GetDefaultName(prefix.c_str(), rawDataIndex);
|
||||
}
|
||||
|
||||
void PolygonDlist::ParseRawData()
|
||||
|
@ -151,22 +125,57 @@ void PolygonDlist::DeclareReferences(const std::string& prefix)
|
|||
xluDList = MakeDlist(xlu, prefix);
|
||||
}
|
||||
|
||||
ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, const std::string& prefix)
|
||||
std::string PolygonDlist::GetBodySourceCode() const
|
||||
{
|
||||
if (ptr == 0)
|
||||
std::string bodyStr;
|
||||
std::string opaStr;
|
||||
std::string xluStr;
|
||||
Globals::Instance->GetSegmentedPtrName(opa, parent, "Gfx", opaStr);
|
||||
Globals::Instance->GetSegmentedPtrName(xlu, parent, "Gfx", xluStr);
|
||||
|
||||
if (polyType == 2)
|
||||
{
|
||||
return nullptr;
|
||||
bodyStr += StringHelper::Sprintf("{ %6i, %6i, %6i }, %6i, ", x, y, z, unk_06);
|
||||
}
|
||||
|
||||
uint32_t dlistAddress = Seg2Filespace(ptr, parent->baseAddress);
|
||||
bodyStr += StringHelper::Sprintf("%s, %s", opaStr.c_str(), xluStr.c_str());
|
||||
|
||||
int32_t dlistLength = ZDisplayList::GetDListLength(
|
||||
parent->GetRawData(), dlistAddress,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
ZDisplayList* dlist = new ZDisplayList(dlistAddress, dlistLength, parent);
|
||||
GenDListDeclarations(zRoom, parent, dlist);
|
||||
return bodyStr;
|
||||
}
|
||||
|
||||
return dlist;
|
||||
std::string PolygonDlist::GetSourceOutputCode(const std::string& prefix)
|
||||
{
|
||||
std::string bodyStr = StringHelper::Sprintf("\n\t%s\n", GetBodySourceCode().c_str());
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
DeclareVar(prefix, bodyStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
decl->text = bodyStr;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string PolygonDlist::GetSourceTypeName() const
|
||||
{
|
||||
switch (polyType)
|
||||
{
|
||||
case 2:
|
||||
return "PolygonDlist2";
|
||||
|
||||
default:
|
||||
return "PolygonDlist";
|
||||
}
|
||||
}
|
||||
|
||||
ZResourceType PolygonDlist::GetResourceType() const
|
||||
{
|
||||
// TODO
|
||||
return ZResourceType::Error;
|
||||
}
|
||||
|
||||
size_t PolygonDlist::GetRawDataSize() const
|
||||
|
@ -186,96 +195,41 @@ void PolygonDlist::SetPolyType(uint8_t nPolyType)
|
|||
polyType = nPolyType;
|
||||
}
|
||||
|
||||
void PolygonDlist::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
ZDisplayList* PolygonDlist::MakeDlist(segptr_t ptr, [[maybe_unused]] const std::string& prefix)
|
||||
{
|
||||
std::string auxName = name;
|
||||
if (name == "")
|
||||
if (ptr == 0)
|
||||
{
|
||||
auxName = GetDefaultName(prefix, rawDataIndex);
|
||||
return nullptr;
|
||||
}
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
|
||||
GetSourceTypeName(), auxName, bodyStr);
|
||||
|
||||
uint32_t dlistAddress = Seg2Filespace(ptr, parent->baseAddress);
|
||||
|
||||
int32_t dlistLength = ZDisplayList::GetDListLength(
|
||||
parent->GetRawData(), dlistAddress,
|
||||
Globals::Instance->game == ZGame::OOT_SW97 ? DListType::F3DEX : DListType::F3DZEX);
|
||||
ZDisplayList* dlist = new ZDisplayList(parent);
|
||||
dlist->ExtractFromBinary(dlistAddress, dlistLength);
|
||||
dlist->SetName(dlist->GetDefaultName(prefix));
|
||||
GenDListDeclarations(zRoom, parent, dlist);
|
||||
|
||||
return dlist;
|
||||
}
|
||||
|
||||
std::string PolygonDlist::GetBodySourceCode(bool arrayElement)
|
||||
/* BgImage */
|
||||
|
||||
BgImage::BgImage(ZFile* nParent) : ZResource(nParent)
|
||||
{
|
||||
std::string bodyStr = "";
|
||||
std::string opaStr = parent->GetDeclarationPtrName(opa);
|
||||
std::string xluStr = parent->GetDeclarationPtrName(xlu);
|
||||
if (arrayElement)
|
||||
{
|
||||
bodyStr += " { ";
|
||||
}
|
||||
else
|
||||
{
|
||||
bodyStr += "\n ";
|
||||
}
|
||||
|
||||
if (polyType == 2)
|
||||
{
|
||||
bodyStr += StringHelper::Sprintf("{ %6i, %6i, %6i }, %6i, ", x, y, z, unk_06);
|
||||
}
|
||||
|
||||
bodyStr += StringHelper::Sprintf("%s, ", opaStr.c_str());
|
||||
bodyStr += StringHelper::Sprintf("%s", xluStr.c_str());
|
||||
|
||||
if (arrayElement)
|
||||
{
|
||||
bodyStr += " },";
|
||||
}
|
||||
else
|
||||
{
|
||||
bodyStr += "\n";
|
||||
}
|
||||
|
||||
return bodyStr;
|
||||
}
|
||||
|
||||
void PolygonDlist::DeclareAndGenerateOutputCode()
|
||||
{
|
||||
std::string bodyStr = GetBodySourceCode(false);
|
||||
|
||||
Declaration* decl = parent->GetDeclaration(rawDataIndex);
|
||||
if (decl == nullptr)
|
||||
{
|
||||
DeclareVar("", bodyStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
decl->text = bodyStr;
|
||||
}
|
||||
}
|
||||
|
||||
std::string PolygonDlist::GetDefaultName(const std::string& prefix, uint32_t address)
|
||||
{
|
||||
return StringHelper::Sprintf("%sPolyDlist_%06X", prefix.c_str(), address);
|
||||
}
|
||||
|
||||
std::string PolygonDlist::GetSourceTypeName()
|
||||
{
|
||||
switch (polyType)
|
||||
{
|
||||
case 2:
|
||||
return "PolygonDlist2";
|
||||
|
||||
default:
|
||||
return "PolygonDlist";
|
||||
}
|
||||
}
|
||||
|
||||
std::string PolygonDlist::GetName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
BgImage::BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent)
|
||||
BgImage::BgImage(bool nIsSubStruct, const std::string& prefix, uint32_t nRawDataIndex,
|
||||
ZFile* nParent)
|
||||
: BgImage(nParent)
|
||||
{
|
||||
rawDataIndex = nRawDataIndex;
|
||||
parent = nParent;
|
||||
isSubStruct = nIsSubStruct;
|
||||
|
||||
name = GetDefaultName(prefix.c_str(), rawDataIndex);
|
||||
name = GetDefaultName(prefix);
|
||||
|
||||
ParseRawData();
|
||||
sourceBackground = MakeBackground(source, prefix);
|
||||
|
@ -306,28 +260,32 @@ void BgImage::ParseRawData()
|
|||
ZBackground* BgImage::MakeBackground(segptr_t ptr, const std::string& prefix)
|
||||
{
|
||||
if (ptr == 0)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint32_t backAddress = Seg2Filespace(ptr, parent->baseAddress);
|
||||
|
||||
ZBackground* background = new ZBackground(prefix, backAddress, parent);
|
||||
ZBackground* background = new ZBackground(parent);
|
||||
background->ExtractFromFile(backAddress);
|
||||
|
||||
std::string defaultName = background->GetDefaultName(prefix);
|
||||
background->SetName(defaultName);
|
||||
background->SetOutName(defaultName);
|
||||
|
||||
background->DeclareVar(prefix, "");
|
||||
parent->resources.push_back(background);
|
||||
|
||||
return background;
|
||||
}
|
||||
|
||||
size_t BgImage::GetRawDataSize()
|
||||
size_t BgImage::GetRawDataSize() const
|
||||
{
|
||||
return 0x1C;
|
||||
}
|
||||
|
||||
std::string BgImage::GetBodySourceCode(bool arrayElement) const
|
||||
std::string BgImage::GetBodySourceCode() const
|
||||
{
|
||||
std::string bodyStr = " ";
|
||||
if (arrayElement)
|
||||
if (!isSubStruct)
|
||||
{
|
||||
bodyStr += "{ \n ";
|
||||
}
|
||||
|
@ -337,16 +295,14 @@ std::string BgImage::GetBodySourceCode(bool arrayElement) const
|
|||
bodyStr += StringHelper::Sprintf("0x%04X, ", unk_00);
|
||||
bodyStr += StringHelper::Sprintf("%i, ", id);
|
||||
bodyStr += "\n ";
|
||||
if (arrayElement)
|
||||
{
|
||||
bodyStr += " ";
|
||||
}
|
||||
bodyStr += " ";
|
||||
}
|
||||
|
||||
std::string backgroundName = parent->GetDeclarationPtrName(source);
|
||||
std::string backgroundName;
|
||||
Globals::Instance->GetSegmentedPtrName(source, parent, "", backgroundName);
|
||||
bodyStr += StringHelper::Sprintf("%s, ", backgroundName.c_str());
|
||||
bodyStr += "\n ";
|
||||
if (arrayElement)
|
||||
if (!isSubStruct)
|
||||
{
|
||||
bodyStr += " ";
|
||||
}
|
||||
|
@ -354,7 +310,7 @@ std::string BgImage::GetBodySourceCode(bool arrayElement) const
|
|||
bodyStr += StringHelper::Sprintf("0x%08X, ", unk_0C);
|
||||
bodyStr += StringHelper::Sprintf("0x%08X, ", tlut);
|
||||
bodyStr += "\n ";
|
||||
if (arrayElement)
|
||||
if (!isSubStruct)
|
||||
{
|
||||
bodyStr += " ";
|
||||
}
|
||||
|
@ -362,7 +318,7 @@ std::string BgImage::GetBodySourceCode(bool arrayElement) const
|
|||
bodyStr += StringHelper::Sprintf("%i, ", width);
|
||||
bodyStr += StringHelper::Sprintf("%i, ", height);
|
||||
bodyStr += "\n ";
|
||||
if (arrayElement)
|
||||
if (!isSubStruct)
|
||||
{
|
||||
bodyStr += " ";
|
||||
}
|
||||
|
@ -370,14 +326,14 @@ std::string BgImage::GetBodySourceCode(bool arrayElement) const
|
|||
bodyStr += StringHelper::Sprintf("%i, ", fmt);
|
||||
bodyStr += StringHelper::Sprintf("%i, ", siz);
|
||||
bodyStr += "\n ";
|
||||
if (arrayElement)
|
||||
if (!isSubStruct)
|
||||
{
|
||||
bodyStr += " ";
|
||||
}
|
||||
|
||||
bodyStr += StringHelper::Sprintf("0x%04X, ", mode0);
|
||||
bodyStr += StringHelper::Sprintf("0x%04X, ", tlutCount);
|
||||
if (arrayElement)
|
||||
if (!isSubStruct)
|
||||
{
|
||||
bodyStr += " \n }, ";
|
||||
}
|
||||
|
@ -389,40 +345,26 @@ std::string BgImage::GetBodySourceCode(bool arrayElement) const
|
|||
return bodyStr;
|
||||
}
|
||||
|
||||
std::string BgImage::GetDefaultName(const std::string& prefix, uint32_t address)
|
||||
{
|
||||
return StringHelper::Sprintf("%sBgImage_%06X", prefix.c_str(), address);
|
||||
}
|
||||
|
||||
std::string BgImage::GetSourceTypeName()
|
||||
std::string BgImage::GetSourceTypeName() const
|
||||
{
|
||||
return "BgImage";
|
||||
}
|
||||
|
||||
std::string BgImage::GetName()
|
||||
ZResourceType BgImage::GetResourceType() const
|
||||
{
|
||||
return name;
|
||||
// TODO
|
||||
return ZResourceType::Error;
|
||||
}
|
||||
|
||||
/* PolygonType section */
|
||||
|
||||
PolygonTypeBase::PolygonTypeBase(ZFile* nParent, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZRoom* nRoom)
|
||||
: rawDataIndex{nRawDataIndex}, parent{nParent}, zRoom{nRoom}
|
||||
PolygonTypeBase::PolygonTypeBase(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom)
|
||||
: ZResource(nParent), zRoom{nRoom}
|
||||
{
|
||||
rawDataIndex = nRawDataIndex;
|
||||
type = BitConverter::ToUInt8BE(parent->GetRawData(), rawDataIndex);
|
||||
}
|
||||
|
||||
void PolygonTypeBase::DeclareVar(const std::string& prefix, const std::string& bodyStr)
|
||||
{
|
||||
std::string auxName = name;
|
||||
if (name == "")
|
||||
auxName = GetDefaultName(prefix);
|
||||
|
||||
parent->AddDeclaration(rawDataIndex, DeclarationAlignment::Align4, GetRawDataSize(),
|
||||
GetSourceTypeName(), auxName, bodyStr);
|
||||
}
|
||||
|
||||
void PolygonTypeBase::DeclareAndGenerateOutputCode(const std::string& prefix)
|
||||
{
|
||||
std::string bodyStr = GetBodySourceCode();
|
||||
|
@ -453,25 +395,14 @@ std::string PolygonTypeBase::GetSourceTypeName() const
|
|||
}
|
||||
}
|
||||
|
||||
std::string PolygonTypeBase::GetName() const
|
||||
ZResourceType PolygonTypeBase::GetResourceType() const
|
||||
{
|
||||
return name;
|
||||
// TODO
|
||||
return ZResourceType::Error;
|
||||
}
|
||||
|
||||
void PolygonTypeBase::SetName(const std::string& newName)
|
||||
{
|
||||
name = newName;
|
||||
}
|
||||
|
||||
std::string PolygonTypeBase::GetDefaultName(const std::string& prefix) const
|
||||
{
|
||||
return StringHelper::Sprintf("%s%s_%06X", prefix.c_str(), GetSourceTypeName().c_str(),
|
||||
rawDataIndex);
|
||||
}
|
||||
|
||||
PolygonType1::PolygonType1(ZFile* nParent, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZRoom* nRoom)
|
||||
: PolygonTypeBase(nParent, nRawData, nRawDataIndex, nRoom)
|
||||
PolygonType1::PolygonType1(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom)
|
||||
: PolygonTypeBase(nParent, nRawDataIndex, nRoom), single(nParent)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -490,10 +421,10 @@ void PolygonType1::ParseRawData()
|
|||
|
||||
if (dlist != 0)
|
||||
{
|
||||
PolygonDlist polyGfxList(zRoom->GetName(), rawData,
|
||||
Seg2Filespace(dlist, parent->baseAddress), parent, zRoom);
|
||||
PolygonDlist polyGfxList(parent);
|
||||
polyGfxList.zRoom = zRoom;
|
||||
polyGfxList.SetPolyType(type);
|
||||
polyGfxList.ParseRawData();
|
||||
polyGfxList.ExtractFromFile(Seg2Filespace(dlist, parent->baseAddress));
|
||||
polyGfxList.DeclareReferences(zRoom->GetName());
|
||||
polyDLists.push_back(polyGfxList);
|
||||
}
|
||||
|
@ -501,26 +432,27 @@ void PolygonType1::ParseRawData()
|
|||
|
||||
void PolygonType1::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
polyDLists.at(0).DeclareAndGenerateOutputCode();
|
||||
polyDLists.at(0).GetSourceOutputCode(prefix);
|
||||
|
||||
uint32_t listAddress;
|
||||
std::string bgImageArrayBody = "";
|
||||
std::string bgImageArrayBody;
|
||||
switch (format)
|
||||
{
|
||||
case 1:
|
||||
single = BgImage(true, prefix, parent->GetRawData(), rawDataIndex + 0x08, parent);
|
||||
single = BgImage(true, prefix, rawDataIndex + 0x08, parent);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (list != 0)
|
||||
{
|
||||
listAddress = Seg2Filespace(list, parent->baseAddress);
|
||||
uint32_t auxPtr = listAddress;
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
BgImage bg(false, prefix, parent->GetRawData(),
|
||||
listAddress + i * BgImage::GetRawDataSize(), parent);
|
||||
BgImage bg(false, prefix, auxPtr, parent);
|
||||
multiList.push_back(bg);
|
||||
bgImageArrayBody += bg.GetBodySourceCode(true);
|
||||
auxPtr += bg.GetRawDataSize();
|
||||
bgImageArrayBody += bg.GetBodySourceCode();
|
||||
if (i + 1 < count)
|
||||
{
|
||||
bgImageArrayBody += "\n";
|
||||
|
@ -531,9 +463,9 @@ void PolygonType1::DeclareReferences(const std::string& prefix)
|
|||
if (decl == nullptr)
|
||||
{
|
||||
parent->AddDeclarationArray(
|
||||
listAddress, DeclarationAlignment::Align4, count * BgImage::GetRawDataSize(),
|
||||
BgImage::GetSourceTypeName(), multiList.at(0).GetName().c_str(), count,
|
||||
bgImageArrayBody);
|
||||
listAddress, DeclarationAlignment::Align4,
|
||||
count * multiList.at(0).GetRawDataSize(), multiList.at(0).GetSourceTypeName(),
|
||||
multiList.at(0).GetName().c_str(), count, bgImageArrayBody);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -565,26 +497,26 @@ std::string PolygonType1::GetBodySourceCode() const
|
|||
bodyStr += "{ ";
|
||||
bodyStr += StringHelper::Sprintf("%i, %i, ", type, format);
|
||||
|
||||
std::string dlistStr = parent->GetDeclarationPtrName(dlist);
|
||||
std::string dlistStr;
|
||||
Globals::Instance->GetSegmentedPtrName(dlist, parent, "", dlistStr);
|
||||
|
||||
bodyStr += StringHelper::Sprintf("%s, ", dlistStr.c_str());
|
||||
bodyStr += "}, \n";
|
||||
|
||||
std::string listStr = "NULL";
|
||||
// bodyStr += " { \n";
|
||||
switch (format)
|
||||
{
|
||||
case 1:
|
||||
bodyStr += single.GetBodySourceCode(false);
|
||||
bodyStr += single.GetBodySourceCode();
|
||||
break;
|
||||
case 2:
|
||||
listStr = parent->GetDeclarationPtrName(list);
|
||||
Globals::Instance->GetSegmentedPtrName(list, parent, "BgImage", listStr);
|
||||
bodyStr += StringHelper::Sprintf(" %i, %s, \n", count, listStr.c_str());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// bodyStr += " } \n";
|
||||
|
||||
return bodyStr;
|
||||
}
|
||||
|
@ -603,9 +535,8 @@ std::string PolygonType1::GetSourceTypeName() const
|
|||
// return "PolygonType1";
|
||||
}
|
||||
|
||||
PolygonType2::PolygonType2(ZFile* nParent, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZRoom* nRoom)
|
||||
: PolygonTypeBase(nParent, nRawData, nRawDataIndex, nRoom)
|
||||
PolygonType2::PolygonType2(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom)
|
||||
: PolygonTypeBase(nParent, nRawDataIndex, nRoom)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -621,9 +552,10 @@ void PolygonType2::ParseRawData()
|
|||
uint32_t currentPtr = GETSEGOFFSET(start);
|
||||
for (size_t i = 0; i < num; i++)
|
||||
{
|
||||
PolygonDlist entry(zRoom->GetName(), rawData, currentPtr, parent, zRoom);
|
||||
PolygonDlist entry(parent);
|
||||
entry.zRoom = zRoom;
|
||||
entry.SetPolyType(type);
|
||||
entry.ParseRawData();
|
||||
entry.ExtractFromFile(currentPtr);
|
||||
entry.DeclareReferences(zRoom->GetName());
|
||||
polyDLists.push_back(entry);
|
||||
currentPtr += entry.GetRawDataSize();
|
||||
|
@ -634,17 +566,18 @@ void PolygonType2::DeclareReferences(const std::string& prefix)
|
|||
{
|
||||
if (num > 0)
|
||||
{
|
||||
std::string declaration = "";
|
||||
std::string declaration;
|
||||
|
||||
for (size_t i = 0; i < polyDLists.size(); i++)
|
||||
{
|
||||
declaration += polyDLists.at(i).GetBodySourceCode(true);
|
||||
declaration +=
|
||||
StringHelper::Sprintf("\t{ %s },", polyDLists.at(i).GetBodySourceCode().c_str());
|
||||
if (i + 1 < polyDLists.size())
|
||||
declaration += "\n";
|
||||
}
|
||||
|
||||
std::string polyDlistType = polyDLists.at(0).GetSourceTypeName();
|
||||
std::string polyDListName = "";
|
||||
std::string polyDListName;
|
||||
polyDListName = StringHelper::Sprintf("%s%s_%06X", prefix.c_str(), polyDlistType.c_str(),
|
||||
GETSEGOFFSET(start));
|
||||
|
||||
|
@ -653,14 +586,16 @@ void PolygonType2::DeclareReferences(const std::string& prefix)
|
|||
polyDlistType, polyDListName, polyDLists.size(), declaration);
|
||||
}
|
||||
|
||||
parent->AddDeclaration(GETSEGOFFSET(end), DeclarationAlignment::Align4,
|
||||
DeclarationPadding::Pad16, 4, "static s32", "terminatorMaybe",
|
||||
parent->AddDeclaration(GETSEGOFFSET(end), DeclarationAlignment::Align4, 4, "s32",
|
||||
StringHelper::Sprintf("%s_terminatorMaybe_%06X",
|
||||
parent->GetName().c_str(), GETSEGOFFSET(end)),
|
||||
"0x01000000");
|
||||
}
|
||||
|
||||
std::string PolygonType2::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(start);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(start, parent, "", listName);
|
||||
|
||||
std::string body = StringHelper::Sprintf("\n %i, %i,\n", type, polyDLists.size());
|
||||
body += StringHelper::Sprintf(" %s,\n", listName.c_str());
|
||||
|
@ -673,3 +608,8 @@ size_t PolygonType2::GetRawDataSize() const
|
|||
{
|
||||
return 0x0C;
|
||||
}
|
||||
|
||||
DeclarationAlignment PolygonType2::GetDeclarationAlignment() const
|
||||
{
|
||||
return DeclarationAlignment::Align4;
|
||||
}
|
||||
|
|
|
@ -5,51 +5,45 @@
|
|||
#include "ZDisplayList.h"
|
||||
#include "ZRoom/ZRoomCommand.h"
|
||||
|
||||
class PolygonDlist
|
||||
class PolygonDlist : public ZResource
|
||||
{
|
||||
public:
|
||||
PolygonDlist() = default;
|
||||
PolygonDlist(const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent, ZRoom* nRoom);
|
||||
ZRoom* zRoom;
|
||||
|
||||
void ParseRawData();
|
||||
void DeclareReferences(const std::string& prefix);
|
||||
uint8_t polyType;
|
||||
|
||||
size_t GetRawDataSize() const;
|
||||
void SetPolyType(uint8_t nPolyType);
|
||||
|
||||
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
|
||||
|
||||
std::string GetBodySourceCode(bool arrayElement);
|
||||
void DeclareAndGenerateOutputCode();
|
||||
|
||||
static std::string GetDefaultName(const std::string& prefix, uint32_t address);
|
||||
std::string GetSourceTypeName();
|
||||
std::string GetName();
|
||||
|
||||
protected:
|
||||
int16_t x, y, z; // polyType == 2
|
||||
int16_t unk_06; // polyType == 2
|
||||
|
||||
segptr_t opa = 0; // Gfx*
|
||||
segptr_t xlu = 0; // Gfx*
|
||||
|
||||
uint8_t polyType;
|
||||
|
||||
ZDisplayList* opaDList = nullptr; // Gfx*
|
||||
ZDisplayList* xluDList = nullptr; // Gfx*
|
||||
|
||||
uint32_t rawDataIndex;
|
||||
ZFile* parent;
|
||||
ZRoom* zRoom;
|
||||
std::string name;
|
||||
PolygonDlist(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetSourceOutputCode(const std::string& prefix) override;
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
void SetPolyType(uint8_t nPolyType);
|
||||
|
||||
protected:
|
||||
ZDisplayList* MakeDlist(segptr_t ptr, const std::string& prefix);
|
||||
};
|
||||
|
||||
class BgImage
|
||||
class BgImage : public ZResource
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
uint16_t unk_00;
|
||||
uint8_t id;
|
||||
segptr_t source;
|
||||
|
@ -64,63 +58,44 @@ protected:
|
|||
|
||||
ZBackground* sourceBackground;
|
||||
|
||||
uint32_t rawDataIndex;
|
||||
ZFile* parent;
|
||||
std::string name;
|
||||
bool isSubStruct;
|
||||
|
||||
void ParseRawData();
|
||||
ZBackground* MakeBackground(segptr_t ptr, const std::string& prefix);
|
||||
BgImage(ZFile* nParent);
|
||||
BgImage(bool nIsSubStruct, const std::string& prefix, uint32_t nRawDataIndex, ZFile* nParent);
|
||||
|
||||
public:
|
||||
BgImage() = default;
|
||||
BgImage(bool nIsSubStruct, const std::string& prefix, const std::vector<uint8_t>& nRawData,
|
||||
uint32_t nRawDataIndex, ZFile* nParent);
|
||||
void ParseRawData() override;
|
||||
|
||||
static size_t GetRawDataSize();
|
||||
std::string GetBodySourceCode() const override;
|
||||
|
||||
std::string GetBodySourceCode(bool arrayElement) const;
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
static std::string GetDefaultName(const std::string& prefix, uint32_t address);
|
||||
static std::string GetSourceTypeName();
|
||||
std::string GetName();
|
||||
};
|
||||
|
||||
class PolygonTypeBase
|
||||
{
|
||||
public:
|
||||
PolygonTypeBase(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
ZRoom* nRoom);
|
||||
|
||||
virtual void ParseRawData() = 0;
|
||||
virtual void DeclareReferences(const std::string& prefix) = 0;
|
||||
|
||||
virtual std::string GetBodySourceCode() const = 0;
|
||||
void DeclareVar(const std::string& prefix, const std::string& bodyStr);
|
||||
void DeclareAndGenerateOutputCode(const std::string& prefix);
|
||||
|
||||
virtual std::string GetSourceTypeName() const;
|
||||
|
||||
std::string GetName() const;
|
||||
void SetName(const std::string& newName);
|
||||
virtual size_t GetRawDataSize() const = 0;
|
||||
|
||||
std::string GetDefaultName(const std::string& prefix) const;
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
protected:
|
||||
uint8_t type;
|
||||
ZBackground* MakeBackground(segptr_t ptr, const std::string& prefix);
|
||||
};
|
||||
|
||||
class PolygonTypeBase : public ZResource
|
||||
{
|
||||
public:
|
||||
uint8_t type;
|
||||
std::vector<PolygonDlist> polyDLists;
|
||||
|
||||
uint32_t rawDataIndex;
|
||||
ZFile* parent;
|
||||
PolygonTypeBase(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom);
|
||||
|
||||
void DeclareAndGenerateOutputCode(const std::string& prefix);
|
||||
|
||||
std::string GetSourceTypeName() const override;
|
||||
ZResourceType GetResourceType() const override;
|
||||
|
||||
protected:
|
||||
ZRoom* zRoom;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class PolygonType1 : public PolygonTypeBase
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
uint8_t format;
|
||||
segptr_t dlist;
|
||||
|
||||
|
@ -132,9 +107,7 @@ protected:
|
|||
segptr_t list; // BgImage*
|
||||
std::vector<BgImage> multiList;
|
||||
|
||||
public:
|
||||
PolygonType1(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
ZRoom* nRoom);
|
||||
PolygonType1(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom);
|
||||
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
@ -149,8 +122,11 @@ public:
|
|||
class PolygonType2 : public PolygonTypeBase
|
||||
{
|
||||
public:
|
||||
PolygonType2(ZFile* nParent, const std::vector<uint8_t>& nRawData, uint32_t nRawDataIndex,
|
||||
ZRoom* nRoom);
|
||||
uint8_t num;
|
||||
segptr_t start;
|
||||
segptr_t end;
|
||||
|
||||
PolygonType2(ZFile* nParent, uint32_t nRawDataIndex, ZRoom* nRoom);
|
||||
|
||||
void ParseRawData() override;
|
||||
void DeclareReferences(const std::string& prefix) override;
|
||||
|
@ -158,16 +134,16 @@ public:
|
|||
std::string GetBodySourceCode() const override;
|
||||
|
||||
size_t GetRawDataSize() const override;
|
||||
|
||||
protected:
|
||||
uint8_t num;
|
||||
segptr_t start;
|
||||
segptr_t end;
|
||||
DeclarationAlignment GetDeclarationAlignment() const override;
|
||||
};
|
||||
|
||||
class SetMesh : public ZRoomCommand
|
||||
{
|
||||
public:
|
||||
uint8_t data;
|
||||
uint8_t meshHeaderType;
|
||||
std::shared_ptr<PolygonTypeBase> polyType;
|
||||
|
||||
SetMesh(ZFile* nParent);
|
||||
|
||||
void ParseRawData() override;
|
||||
|
@ -176,12 +152,8 @@ public:
|
|||
std::string GetBodySourceCode() const override;
|
||||
|
||||
RoomCommand GetRoomCommand() const override;
|
||||
size_t GetRawDataSize() const override;
|
||||
std::string GetCommandCName() const override;
|
||||
|
||||
private:
|
||||
uint8_t meshHeaderType;
|
||||
std::shared_ptr<PolygonTypeBase> polyType;
|
||||
|
||||
std::string GenDListExterns(ZDisplayList* dList);
|
||||
};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#include "SetMinimapChests.h"
|
||||
|
||||
#include "BitConverter.h"
|
||||
#include "Globals.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Utils/BitConverter.h"
|
||||
#include "Utils/StringHelper.h"
|
||||
#include "ZFile.h"
|
||||
#include "ZRoom/ZRoom.h"
|
||||
|
||||
|
@ -28,7 +28,7 @@ void SetMinimapChests::ParseRawData()
|
|||
|
||||
void SetMinimapChests::DeclareReferences(const std::string& prefix)
|
||||
{
|
||||
std::string declaration = "";
|
||||
std::string declaration;
|
||||
|
||||
size_t index = 0;
|
||||
for (const auto& chest : chests)
|
||||
|
@ -42,14 +42,15 @@ void SetMinimapChests::DeclareReferences(const std::string& prefix)
|
|||
}
|
||||
|
||||
parent->AddDeclarationArray(
|
||||
segmentOffset, DeclarationAlignment::None, chests.size() * 10, "MinimapChest",
|
||||
segmentOffset, DeclarationAlignment::Align4, chests.size() * 10, "MinimapChest",
|
||||
StringHelper::Sprintf("%sMinimapChests0x%06X", prefix.c_str(), segmentOffset),
|
||||
chests.size(), declaration);
|
||||
}
|
||||
|
||||
std::string SetMinimapChests::GetBodySourceCode() const
|
||||
{
|
||||
std::string listName = parent->GetDeclarationPtrName(cmdArg2);
|
||||
std::string listName;
|
||||
Globals::Instance->GetSegmentedPtrName(cmdArg2, parent, "MinimapChest", listName);
|
||||
return StringHelper::Sprintf("SCENE_CMD_MINIMAP_COMPASS_ICON_INFO(0x%02X, %s)", chests.size(),
|
||||
listName.c_str());
|
||||
}
|
||||
|
@ -64,11 +65,6 @@ RoomCommand SetMinimapChests::GetRoomCommand() const
|
|||
return RoomCommand::SetMinimapChests;
|
||||
}
|
||||
|
||||
size_t SetMinimapChests::GetRawDataSize() const
|
||||
{
|
||||
return ZRoomCommand::GetRawDataSize() + (chests.size() * 10);
|
||||
}
|
||||
|
||||
MinimapChest::MinimapChest(const std::vector<uint8_t>& rawData, uint32_t rawDataIndex)
|
||||
: unk0(BitConverter::ToUInt16BE(rawData, rawDataIndex + 0)),
|
||||
unk2(BitConverter::ToUInt16BE(rawData, rawDataIndex + 2)),
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue