Decompiled 2 functions & hopefully fix build issue.

This commit is contained in:
David Benepe
2022-04-10 14:39:01 -04:00
parent 9f2b74d051
commit 05f080ca44
11 changed files with 422 additions and 286 deletions
+21
View File
@@ -1,5 +1,8 @@
/**
* This tool handles everything assets-related including extracting and building.
*
* TODO: This file needs a refactor at some point. It is a bit of a mess.
*
*/
#include <iostream>
@@ -19,6 +22,7 @@ void print_usage() {
std::cout << "---- Usages -------------------------------------------------------------" << std::endl;
std::cout << "Extracting assets: ./dkr_assets_tool -e <version> <configs path> <baseroms path> <output path>" << std::endl;
std::cout << "Building an asset: ./dkr_assets_tool -b <version> <assets path> <source path> <output path>" << std::endl;
std::cout << "Build enums cache: ./dkr_assets_tool -bc <version> <enums.h path>" << std::endl;
std::cout << "Creating includes: ./dkr_assets_tool -i <version> <assets path> <include directory> <build directory> <asm output directory>" << std::endl;
std::cout << "Compiling assets: ./dkr_assets_tool -c <version> <assets path>" << std::endl;
std::cout << "Compress file: ./dkr_assets_tool -fc <input_filename> <output_filename>" << std::endl;
@@ -36,6 +40,7 @@ typedef enum _ToolType {
TT_ASSET_COMPILE,
TT_ASSET_COMPRESS_FILE,
TT_ASSET_DECOMPRESS_FILE,
TT_BUILD_ENUMS_CACHE,
} ToolType;
typedef struct _CmdArgOptions {
@@ -56,6 +61,7 @@ std::string get_cmd_from_parse_option(ToolType type) {
switch(type) {
case TT_EXTRACT: return "-e";
case TT_BUILD: return "-b";
case TT_BUILD_ENUMS_CACHE: return "-bc";
case TT_ASSET_INCLUDES: return "-i";
case TT_ASSET_COMPILE: return "-c";
case TT_ASSET_COMPRESS_FILE: return "-fc";
@@ -112,6 +118,11 @@ bool parse_options(int argc, char *argv[]) {
curOptionState = 6;
options.type = TT_ASSET_DECOMPRESS_FILE;
parsingCmd = true;
} else if(args[i] == "-bc") {
curOption = PO_TYPE;
curOptionState = 7;
options.type = TT_BUILD_ENUMS_CACHE;
parsingCmd = true;
} else if(args[i] == "-h") {
return false;
} else {
@@ -177,6 +188,7 @@ bool parse_options(int argc, char *argv[]) {
case 4: // Compile assets
case 5: // Compress file
case 6: // Decompress file
case 7: // Build enums cache.
switch(curOptionArgs) {
case 0: // Assets directory / Input filename
options.paths.push_back(args[i]);
@@ -242,6 +254,15 @@ int main(int argc, char *argv[]) {
Builder builder(sourcePath, outputPath);
}
break;
case TT_BUILD_ENUMS_CACHE:
{
std::string version = options.paths[0]; // us_1.0
std::string enumsHeaderPath = options.paths[1]; // <root>/include/enums.h
set_version(version);
generate_enums_cache(enumsHeaderPath);
}
break;
case TT_ASSET_INCLUDES:
{
std::string version = options.paths[0]; // us_1.0
@@ -8,6 +8,12 @@ bool hasLoadedEnums = false;
std::map<std::string, int> enums;
std::map<std::string, std::vector<std::string>> enumKeys;
std::string ENUMS_CACHE_PATH = "";
void set_enums_cache_path() {
ENUMS_CACHE_PATH = "./build/" + get_version() + "/enumsCache.bin";
}
int evalulate_enum(std::string &enumValue) {
int attempts = 0;
std::regex enumNameRegex("([^0-9|^&~+\\-\\/*\\s]+)");
@@ -123,30 +129,32 @@ void load_enums_cache() {
}
}
void generate_enums_cache(std::string enumsHeaderPath) {
set_enums_cache_path();
// Generate enums map
path_must_exist(enumsHeaderPath);
std::string enumsIncludeText = read_text_file(enumsHeaderPath);
std::regex enumRegex("enum ([^\\s{]+)\\s*[{]((?:.*\\n)*?)[}]");
std::smatch sm;
std::string text = enumsIncludeText;
while (regex_search(text, sm, enumRegex)) {
std::string enumName = sm[1];
std::string enumValuesText = sm[2];
get_enum_values(enumName, enumValuesText);
text = sm.suffix();
}
save_enums_cache();
}
std::mutex enumsMutex;
void make_sure_enums_are_loaded() {
enumsMutex.lock();
if(!hasLoadedEnums) {
std::string assetsFolderPath = get_asset_folder_path();
ensure_that_path_exists("build/"); // Make sure build folder exists
if(path_exists(ENUMS_CACHE_PATH)) {
load_enums_cache();
} else {
// Generate enums map
path_must_exist("include/enums.h");
std::string enumsIncludeText = read_text_file("include/enums.h");
std::regex enumRegex("enum ([^\\s{]+)\\s*[{]((?:.*\\n)*?)[}]");
std::smatch sm;
std::string text = enumsIncludeText;
while (regex_search(text, sm, enumRegex)) {
std::string enumName = sm[1];
std::string enumValuesText = sm[2];
get_enum_values(enumName, enumValuesText);
text = sm.suffix();
}
save_enums_cache();
if(ENUMS_CACHE_PATH == "") {
set_enums_cache_path();
}
load_enums_cache();
hasLoadedEnums = true;
}
enumsMutex.unlock();
@@ -15,8 +15,7 @@
#include "fileHelper.h"
#define ENUMS_PATH "../../../../include/enums.h"
#define ENUMS_CACHE_PATH "./build/enums_cache"
void generate_enums_cache(std::string enumsHeaderPath);
std::string get_enum_string_from_value(std::string enumName, int value);
int get_enum_value_from_string(std::string enumName, std::string value);