mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-06 16:37:42 +00:00
Make unlinker open a gdt file if not raw specified
This commit is contained in:
parent
aa972614e5
commit
fc59a09d02
@ -0,0 +1,6 @@
|
|||||||
|
#include "AssetDumpingContext.h"
|
||||||
|
|
||||||
|
AssetDumpingContext::AssetDumpingContext()
|
||||||
|
: m_zone(nullptr)
|
||||||
|
{
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "Obj/Gdt/GdtStream.h"
|
||||||
#include "Zone/Zone.h"
|
#include "Zone/Zone.h"
|
||||||
|
|
||||||
class AssetDumpingContext
|
class AssetDumpingContext
|
||||||
@ -9,4 +10,7 @@ class AssetDumpingContext
|
|||||||
public:
|
public:
|
||||||
Zone* m_zone;
|
Zone* m_zone;
|
||||||
std::string m_base_path;
|
std::string m_base_path;
|
||||||
|
std::unique_ptr<GdtOutputStream> m_gdt;
|
||||||
|
|
||||||
|
AssetDumpingContext();
|
||||||
};
|
};
|
||||||
|
@ -183,6 +183,22 @@ class Unlinker::Impl
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool OpenGdtFile(Zone* zone, const fs::path& zoneDefinitionFileFolder, std::ofstream& stream)
|
||||||
|
{
|
||||||
|
auto gdtFilePath(zoneDefinitionFileFolder);
|
||||||
|
gdtFilePath.append(zone->m_name);
|
||||||
|
gdtFilePath.replace_extension(".gdt");
|
||||||
|
|
||||||
|
stream = std::ofstream(gdtFilePath, std::fstream::out | std::fstream::binary);
|
||||||
|
if (!stream.is_open())
|
||||||
|
{
|
||||||
|
printf("Failed to open file for zone definition file of zone \"%s\".\n", zone->m_name.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Performs the tasks specified by the command line arguments on the specified zone.
|
* \brief Performs the tasks specified by the command line arguments on the specified zone.
|
||||||
* \param zone The zone to handle.
|
* \param zone The zone to handle.
|
||||||
@ -204,12 +220,31 @@ class Unlinker::Impl
|
|||||||
zoneDefinitionFileFolder.append("zone_source");
|
zoneDefinitionFileFolder.append("zone_source");
|
||||||
fs::create_directories(zoneDefinitionFileFolder);
|
fs::create_directories(zoneDefinitionFileFolder);
|
||||||
|
|
||||||
WriteZoneDefinitionFile(zone, zoneDefinitionFileFolder);
|
if (!WriteZoneDefinitionFile(zone, zoneDefinitionFileFolder))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::ofstream gdtStream;
|
||||||
AssetDumpingContext context;
|
AssetDumpingContext context;
|
||||||
context.m_zone = zone;
|
context.m_zone = zone;
|
||||||
context.m_base_path = outputFolderPath;
|
context.m_base_path = outputFolderPath;
|
||||||
|
|
||||||
|
if(!m_args.m_raw)
|
||||||
|
{
|
||||||
|
if (!OpenGdtFile(zone, zoneDefinitionFileFolder, gdtStream))
|
||||||
|
return false;
|
||||||
|
auto gdt = std::make_unique<GdtOutputStream>(gdtStream);
|
||||||
|
gdt->BeginStream();
|
||||||
|
gdt->WriteVersion(GdtVersion(zone->m_game->GetName(), 1));
|
||||||
|
context.m_gdt = std::move(gdt);
|
||||||
|
}
|
||||||
|
|
||||||
ObjWriting::DumpZone(context);
|
ObjWriting::DumpZone(context);
|
||||||
|
|
||||||
|
if(!m_args.m_raw)
|
||||||
|
{
|
||||||
|
context.m_gdt->EndStream();
|
||||||
|
gdtStream.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -7,54 +7,62 @@
|
|||||||
#include "ObjLoading.h"
|
#include "ObjLoading.h"
|
||||||
#include "ObjWriting.h"
|
#include "ObjWriting.h"
|
||||||
|
|
||||||
const CommandLineOption* const OPTION_HELP = CommandLineOption::Builder::Create()
|
const CommandLineOption* const OPTION_HELP =
|
||||||
|
CommandLineOption::Builder::Create()
|
||||||
.WithShortName("?")
|
.WithShortName("?")
|
||||||
.WithLongName("help")
|
.WithLongName("help")
|
||||||
.WithDescription("Displays usage information.")
|
.WithDescription("Displays usage information.")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
const CommandLineOption* const OPTION_VERBOSE = CommandLineOption::Builder::Create()
|
const CommandLineOption* const OPTION_VERBOSE =
|
||||||
.WithShortName("v")
|
CommandLineOption::Builder::Create()
|
||||||
.WithLongName("verbose")
|
.WithShortName("v")
|
||||||
.WithDescription("Outputs a lot more and more detailed messages.")
|
.WithLongName("verbose")
|
||||||
.Build();
|
.WithDescription("Outputs a lot more and more detailed messages.")
|
||||||
|
|
||||||
const CommandLineOption* const OPTION_MINIMAL_ZONE_FILE = CommandLineOption::Builder::Create()
|
|
||||||
.WithShortName("min")
|
|
||||||
.WithLongName("minimal-zone")
|
|
||||||
.WithDescription(
|
|
||||||
"Minimizes the size of the zone file output by only including assets that are not a dependency of another asset.")
|
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
const CommandLineOption* const OPTION_LIST = CommandLineOption::Builder::Create()
|
const CommandLineOption* const OPTION_MINIMAL_ZONE_FILE =
|
||||||
.WithShortName("l")
|
CommandLineOption::Builder::Create()
|
||||||
.WithLongName("list")
|
.WithShortName("min")
|
||||||
.WithDescription(
|
.WithLongName("minimal-zone")
|
||||||
"Lists the contents of a zone instead of writing them to the disk.")
|
.WithDescription("Minimizes the size of the zone file output by only including assets that are not a dependency of another asset.")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
const CommandLineOption* const OPTION_OUTPUT_FOLDER = CommandLineOption::Builder::Create()
|
const CommandLineOption* const OPTION_LIST =
|
||||||
.WithShortName("o")
|
CommandLineOption::Builder::Create()
|
||||||
.WithLongName("output-folder")
|
.WithShortName("l")
|
||||||
.WithDescription(
|
.WithLongName("list")
|
||||||
"Specifies the output folder containing the contents of the unlinked zones. Defaults to ./%zoneName%")
|
.WithDescription("Lists the contents of a zone instead of writing them to the disk.")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
const CommandLineOption* const OPTION_OUTPUT_FOLDER =
|
||||||
|
CommandLineOption::Builder::Create()
|
||||||
|
.WithShortName("o")
|
||||||
|
.WithLongName("output-folder")
|
||||||
|
.WithDescription("Specifies the output folder containing the contents of the unlinked zones. Defaults to ./%zoneName%")
|
||||||
.WithParameter("outputFolderPath")
|
.WithParameter("outputFolderPath")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
const CommandLineOption* const OPTION_SEARCH_PATH = CommandLineOption::Builder::Create()
|
const CommandLineOption* const OPTION_SEARCH_PATH =
|
||||||
.WithLongName("search-path")
|
CommandLineOption::Builder::Create()
|
||||||
.WithDescription(
|
.WithLongName("search-path")
|
||||||
"Specifies a semi-colon separated list of paths to search for additional game files.")
|
.WithDescription("Specifies a semi-colon separated list of paths to search for additional game files.")
|
||||||
.WithParameter("searchPathString")
|
.WithParameter("searchPathString")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
const CommandLineOption* const OPTION_IMAGE_FORMAT = CommandLineOption::Builder::Create()
|
const CommandLineOption* const OPTION_IMAGE_FORMAT =
|
||||||
.WithLongName("image-format")
|
CommandLineOption::Builder::Create()
|
||||||
.WithDescription(
|
.WithLongName("image-format")
|
||||||
"Specifies the format of dumped image files. Valid values are: DDS, IWI")
|
.WithDescription("Specifies the format of dumped image files. Valid values are: DDS, IWI")
|
||||||
.WithParameter("imageFormatValue")
|
.WithParameter("imageFormatValue")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
const CommandLineOption* const OPTION_RAW =
|
||||||
|
CommandLineOption::Builder::Create()
|
||||||
|
.WithLongName("raw")
|
||||||
|
.WithDescription("Prevents generation of a GDT and dumps assets as raw whenever possible.")
|
||||||
|
.Build();
|
||||||
|
|
||||||
const CommandLineOption* const COMMAND_LINE_OPTIONS[]
|
const CommandLineOption* const COMMAND_LINE_OPTIONS[]
|
||||||
{
|
{
|
||||||
OPTION_HELP,
|
OPTION_HELP,
|
||||||
@ -63,7 +71,8 @@ const CommandLineOption* const COMMAND_LINE_OPTIONS[]
|
|||||||
OPTION_LIST,
|
OPTION_LIST,
|
||||||
OPTION_OUTPUT_FOLDER,
|
OPTION_OUTPUT_FOLDER,
|
||||||
OPTION_SEARCH_PATH,
|
OPTION_SEARCH_PATH,
|
||||||
OPTION_IMAGE_FORMAT
|
OPTION_IMAGE_FORMAT,
|
||||||
|
OPTION_RAW
|
||||||
};
|
};
|
||||||
|
|
||||||
UnlinkerArgs::UnlinkerArgs()
|
UnlinkerArgs::UnlinkerArgs()
|
||||||
@ -163,13 +172,13 @@ bool UnlinkerArgs::SetImageDumpingMode()
|
|||||||
for (auto& c : specifiedValue)
|
for (auto& c : specifiedValue)
|
||||||
c = tolower(c);
|
c = tolower(c);
|
||||||
|
|
||||||
if(specifiedValue == "dds")
|
if (specifiedValue == "dds")
|
||||||
{
|
{
|
||||||
ObjWriting::Configuration.ImageOutputFormat = ObjWriting::Configuration_t::ImageOutputFormat_e::DDS;
|
ObjWriting::Configuration.ImageOutputFormat = ObjWriting::Configuration_t::ImageOutputFormat_e::DDS;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(specifiedValue == "iwi")
|
if (specifiedValue == "iwi")
|
||||||
{
|
{
|
||||||
ObjWriting::Configuration.ImageOutputFormat = ObjWriting::Configuration_t::ImageOutputFormat_e::IWI;
|
ObjWriting::Configuration.ImageOutputFormat = ObjWriting::Configuration_t::ImageOutputFormat_e::IWI;
|
||||||
return true;
|
return true;
|
||||||
@ -229,7 +238,7 @@ bool UnlinkerArgs::ParseArgs(const int argc, const char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --image-format
|
// --image-format
|
||||||
if(m_argument_parser.IsOptionSpecified(OPTION_IMAGE_FORMAT))
|
if (m_argument_parser.IsOptionSpecified(OPTION_IMAGE_FORMAT))
|
||||||
{
|
{
|
||||||
if (!SetImageDumpingMode())
|
if (!SetImageDumpingMode())
|
||||||
{
|
{
|
||||||
@ -237,6 +246,9 @@ bool UnlinkerArgs::ParseArgs(const int argc, const char** argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --raw
|
||||||
|
m_raw = m_argument_parser.IsOptionSpecified(OPTION_RAW);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ public:
|
|||||||
std::string m_output_folder;
|
std::string m_output_folder;
|
||||||
bool m_minimal_zone_def;
|
bool m_minimal_zone_def;
|
||||||
|
|
||||||
|
bool m_raw;
|
||||||
|
|
||||||
bool m_verbose;
|
bool m_verbose;
|
||||||
|
|
||||||
UnlinkerArgs();
|
UnlinkerArgs();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user