From b9aa184516ce19f56d584bb3cd74e8c99b43c6b4 Mon Sep 17 00:00:00 2001 From: TiredHobgoblin <46323898+TiredHobgoblin@users.noreply.github.com> Date: Thu, 24 Jun 2021 20:12:42 -0400 Subject: [PATCH] Shader JSON export * Shaders export as JSON * Shader format modified for ease of use --- api.cpp | 69 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/api.cpp b/api.cpp index 31a67f5..7755c13 100644 --- a/api.cpp +++ b/api.cpp @@ -21,26 +21,26 @@ std::unordered_map channelNames = std::vector dataNames = { - "Detail Diffuse Transform", - "Detail Normal Transform", + "\"detail_diffuse_transform\"", + "\"detail_normal_transform\"", "\"spec_aa_transform\"", - "Primary Color", + "\"primary_albedo_tint\"", "\"primary_emissive_tint_color_and_intensity_bias\"", "\"primary_material_params\"", "\"primary_material_advanced_params\"", - "Primary Roughness Remap", - "Primary Wear Color", - "Primary Wear Remap", - "Primary Worn Roughness Remap", + "\"primary_roughness_remap\"", + "\"primary_worn_albedo_tint\"", + "\"primary_wear_remap\"", + "\"primary_worn_roughness_remap\"", "\"primary_worn_material_parameters\"", - "Secondary Color", + "\"secondary_albedo_tint\"", "\"secondary_emissive_tint_color_and_intensity_bias\"", "\"secondary_material_params\"", "\"secondary_material_advanced_params\"", - "Secondary Roughness Remap", - "Secondary Wear Color", - "Secondary Wear Remap", - "Secondary Worn Roughness Remap", + "\"secondary_roughness_remap\"", + "\"secondary_worn_albedo_tint\"", + "\"secondary_wear_remap\"", + "\"secondary_worn_roughness_remap\"", "\"secondary_worn_material_parameters\"", }; @@ -180,6 +180,7 @@ void getAPIShader(uint32_t apiHash, std::string outputPath, std::string packages std::string dyeFileHash; File* finalDyeFile = nullptr; std::string channelName; + std::string channelNameHash; // For each pair, find the channel hash to pair it with a name + find the dye file std::unordered_map>> defaultDyes; @@ -200,6 +201,7 @@ void getAPIShader(uint32_t apiHash, std::string outputPath, std::string packages // Get channel name memcpy((char*)&channelHash, channelTable->data + 0x30 + 4 * it.first, 4); channelName = channelNames[channelHash]; + channelNameHash = std::to_string(channelHash); // Get dye file memcpy((char*)&dyeManifestHash, dyeManifestTable->data + 0x30 + 8 * it.second + 4, 4); @@ -292,17 +294,17 @@ void getAPIShader(uint32_t apiHash, std::string outputPath, std::string packages if (q == 0) { - defaultDyes[channelName] = dyeData; + defaultDyes[channelNameHash] = dyeData; texData["Diffuse"] = diffuseName; texData["Normal"] = normalName; - defaultTextures[channelName] = texData; + defaultTextures[channelNameHash] = texData; } else { - customDyes[channelName] = dyeData; + customDyes[channelNameHash] = dyeData; texData["Diffuse"] = diffuseName; texData["Normal"] = normalName; - customTextures[channelName] = texData; + customTextures[channelNameHash] = texData; } } } @@ -316,29 +318,38 @@ void getAPIShader(uint32_t apiHash, std::string outputPath, std::string packages void writeShader(std::unordered_map>> dyes, std::unordered_map> textures, bool bCustom, std::string outputPath) { - std::string stringFactoryShader = ""; - if (!bCustom) stringFactoryShader += "Default dyes:\n"; - else stringFactoryShader += "Custom dyes:\n"; + std::string stringFactoryShader = "{\n"; + if (!bCustom) stringFactoryShader += " \"custom_dyes\": [],\n \"locked_dyes\": [],\n \"default_dyes\": [\n"; + else stringFactoryShader += " \"default_dyes\": [],\n \"locked_dyes\": [],\n \"custom_dyes\": [\n"; + std::string propertiesString = ""; for (auto& it : dyes) { - stringFactoryShader += " " + it.first + ":\n"; - if (it.first.find("Cloth", 0) != std::string::npos) stringFactoryShader += " Is cloth: True\n"; - else stringFactoryShader += " Is cloth: False\n"; - stringFactoryShader += " Properties:\n"; + //propertiesString += " " + it.first + ":\n"; + propertiesString += " {\n"; + propertiesString += " \"investment_hash\": " + it.first + ",\n"; + if (it.first.find("Cloth", 0) != std::string::npos) propertiesString += " \"cloth\": true,\n"; + else propertiesString += " \"cloth\": false,\n"; + propertiesString += " \"material_properties\": {\n"; + std::string valuesString = ""; for (auto& it2 : it.second) { - if (it.first.find("Diffuse", 0) != std::string::npos) break; + if (it.first.find("diffuse", 0) != std::string::npos) break; std::string floatString = "["; for (auto& flt : it2.second) floatString += std::to_string(flt) + ", "; - stringFactoryShader += " " + it2.first + ": " + floatString.substr(0, floatString.size()-2) + "]\n"; + //stringFactoryShader += " " + it2.first + ": " + floatString.substr(0, floatString.size()-2) + "],\n"; + valuesString += " " + it2.first + ": " + floatString.substr(0, floatString.size()-2) + "],\n"; } - stringFactoryShader += " Diffuse: " + textures[it.first]["Diffuse"] + "\n"; - stringFactoryShader += " Normal: " + textures[it.first]["Normal"] + "\n"; + propertiesString += valuesString.substr(0, valuesString.size()-2) + "\n },\n"; + propertiesString += " \"textures\": {\n"; + propertiesString += " \"diffuse\": {\n \"name\": \"" + textures[it.first]["Diffuse"] + "\"\n },\n"; + propertiesString += " \"normal\": {\n \"name\": \"" + textures[it.first]["Normal"] + "\"\n }\n"; + propertiesString += " }\n },\n"; } - stringFactoryShader += "\n"; + stringFactoryShader += propertiesString.substr(0, propertiesString.size()-2) + "\n ]\n}"; + //stringFactoryShader += "\n"; FILE* shaderFile; - std::string path = outputPath + "/shader.txt"; + std::string path = outputPath + "/shader.json"; fopen_s(&shaderFile, path.c_str(), "w"); fwrite(stringFactoryShader.c_str(), stringFactoryShader.size(), 1, shaderFile); fclose(shaderFile);