diff --git a/Launcher/ToolkitInterface/H2AToolkit.cs b/Launcher/ToolkitInterface/H2AToolkit.cs index 8ffe231..bf0656f 100644 --- a/Launcher/ToolkitInterface/H2AToolkit.cs +++ b/Launcher/ToolkitInterface/H2AToolkit.cs @@ -109,7 +109,7 @@ public override async Task ImportModel(string path, ModelCompile importType, boo if (importType.HasFlag(ModelCompile.render)) // Generate shaders if requested - if (genShaders) { if (!AutoShaders.CreateEmptyShadersGen2(BaseDirectory, path, "H2")) { return; }; } + if (genShaders) { if (!AutoShaders.CreateEmptyShaders(BaseDirectory, path, "H2")) { return; }; } await RunTool(ToolType.Tool, new() { "render", path, accurateRender.ToString(), renderPRT.ToString() }); if (importType.HasFlag(ModelCompile.collision)) await RunTool(ToolType.Tool, new() { "collision", path }); diff --git a/Launcher/ToolkitInterface/H3ODSTToolkit.cs b/Launcher/ToolkitInterface/H3ODSTToolkit.cs index 1eb4b73..1dfdcee 100644 --- a/Launcher/ToolkitInterface/H3ODSTToolkit.cs +++ b/Launcher/ToolkitInterface/H3ODSTToolkit.cs @@ -41,7 +41,7 @@ public override async Task ImportModel(string path, ModelCompile importType, boo if (importType.HasFlag(ModelCompile.render)) // Generate shaders if requested - if (genShaders) { if (!AutoShaders.CreateEmptyShadersGen3(BaseDirectory, path, "H3ODST")) { return; }; } + if (genShaders) { if (!AutoShaders.CreateEmptyShaders(BaseDirectory, path, "H3ODST")) { return; }; } if (skyRender) await RunTool(ToolType.Tool, new() { "render-sky", path }); else if (accurateRender) diff --git a/Launcher/ToolkitInterface/H3Toolkit.cs b/Launcher/ToolkitInterface/H3Toolkit.cs index 47d4053..c677779 100644 --- a/Launcher/ToolkitInterface/H3Toolkit.cs +++ b/Launcher/ToolkitInterface/H3Toolkit.cs @@ -205,7 +205,7 @@ public override async Task ImportModel(string path, ModelCompile importType, boo if (importType.HasFlag(ModelCompile.render)) // Generate shaders if requested - if (genShaders) { if (!AutoShaders.CreateEmptyShadersGen3(BaseDirectory, path, "H3")) { return; }; } + if (genShaders) { if (!AutoShaders.CreateEmptyShaders(BaseDirectory, path, "H3")) { return; }; } if (skyRender) await RunTool(ToolType.Tool, new() { "render-sky", path }); else if (accurateRender) diff --git a/Launcher/Utility/AutoShaders.cs b/Launcher/Utility/AutoShaders.cs index 64de307..d8023d3 100644 --- a/Launcher/Utility/AutoShaders.cs +++ b/Launcher/Utility/AutoShaders.cs @@ -8,7 +8,7 @@ internal class AutoShaders { - public static bool CreateEmptyShadersGen3(string BaseDirectory, string path, string gameType) + public static bool CreateEmptyShaders(string BaseDirectory, string path, string gameType) { // Variables string full_jms_path = ""; @@ -62,22 +62,30 @@ public static bool CreateEmptyShadersGen3(string BaseDirectory, string path, str static void shaderGen(string[] shaders, int counter, string full_jms_path, string destinationShadersFolder, string BaseDirectory, string gameType) { + string defaultShaderLocation = ""; + // Create directories Directory.CreateDirectory(destinationShadersFolder); // Make sure default.shader exists, if not, create it - string defaultShaderLocation = BaseDirectory + @"\tags\levels\shared\shaders\simple\default.shader"; + defaultShaderLocation = gameType == "H2" + ? BaseDirectory + @"\tags\shaders\default.shader" + : BaseDirectory + @"\tags\levels\shared\shaders\simple\default.shader"; + if (!File.Exists(defaultShaderLocation)) { if (gameType == "H3") { File.WriteAllBytes(defaultShaderLocation, ToolkitLauncher.Utility.Resources.defaultH3); } - else + else if (gameType == "H3ODST") { File.WriteAllBytes(defaultShaderLocation, ToolkitLauncher.Utility.Resources.defaultODST); } - + else + { + File.WriteAllBytes(defaultShaderLocation, ToolkitLauncher.Utility.Resources.defaultH2); + } } // Write each shader @@ -106,10 +114,14 @@ static void shaderGen(string[] shaders, int counter, string full_jms_path, strin { File.WriteAllBytes(defaultShaderLocation, ToolkitLauncher.Utility.Resources.defaultH3); } - else + else if (gameType == "H3ODST") { File.WriteAllBytes(defaultShaderLocation, ToolkitLauncher.Utility.Resources.defaultODST); } + else + { + File.WriteAllBytes(defaultShaderLocation, ToolkitLauncher.Utility.Resources.defaultH2); + } counter = 0; shaderGen(shaders, counter, full_jms_path, destinationShadersFolder, BaseDirectory, gameType); break; @@ -122,109 +134,7 @@ static void shaderGen(string[] shaders, int counter, string full_jms_path, strin } } } - // Default fall-through - return true; - } - - public static bool CreateEmptyShadersGen2(string BaseDirectory, string path, string gameType) - { - // Variables - string full_jms_path = ""; - int counter = 0; - - //Grabbing full path from drive letter to render folder - string jmsPath = (BaseDirectory + @"\data\" + path + @"\render").Replace("\\\\", "\\"); - - // Get all files in render folder - string[] files = Array.Empty(); - try - { - files = Directory.GetFiles(jmsPath); - } - catch (DirectoryNotFoundException) - { - MessageBox.Show("Unable to find JMS filepath!\nThis usually happens if your filepath contains invalid characters.\nAborting model import and shader generation...", "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - - string destinationShadersFolder = BaseDirectory + @"\tags\" + path + @"\shaders"; - - // Checking if shaders already exist, if so don't re-gen them - try - { - if (!(Directory.GetFiles(destinationShadersFolder) == Array.Empty())) - { - Debug.WriteLine("Shaders already exist!"); - if (MessageBox.Show("Shaders for this model already exist!\nWould you like to generate any missing shaders?", "Shader Gen. Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) - { - string[] shaders = JMSMaterialReader.ReadAllMaterials(files, counter, full_jms_path, BaseDirectory, gameType); - shaderGen(shaders, counter, full_jms_path, destinationShadersFolder, BaseDirectory); - } - else - { - return true; - } - } - else - { - string[] shaders = JMSMaterialReader.ReadAllMaterials(files, counter, full_jms_path, BaseDirectory, gameType); - shaderGen(shaders, counter, full_jms_path, destinationShadersFolder, BaseDirectory); - } - } - catch (DirectoryNotFoundException) - { - Debug.WriteLine("No folders exist, proceeding with shader gen"); - string[] shaders = JMSMaterialReader.ReadAllMaterials(files, counter, full_jms_path, BaseDirectory, gameType); - shaderGen(shaders, counter, full_jms_path, destinationShadersFolder, BaseDirectory); - } - - static void shaderGen(string[] shaders, int counter, string full_jms_path, string destinationShadersFolder, string BaseDirectory) - { - // Create directories - Directory.CreateDirectory(destinationShadersFolder); - // Make sure default.shader exists, if not, create it - string defaultShaderLocation = BaseDirectory + @"\tags\shaders\default.shader"; - if (!File.Exists(defaultShaderLocation)) - { - File.WriteAllBytes(defaultShaderLocation, ToolkitLauncher.Utility.Resources.defaultH2); - } - - // Write each shader - foreach (string shader in shaders) - { - string shaderName = shader + ".shader"; - if (shaderName == ".shader") - { - MessageBox.Show("Detected an invalid (possibly blank) shader name!\nThis shader will not be generated.\nThis won't work well in-game.", "Shader Gen. Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); - try { File.Copy(defaultShaderLocation, Path.Combine(destinationShadersFolder, "im.too.dumb.to.name.my.shader")); } catch { Debug.WriteLine("ah well"); }; - continue; - } - if (!File.Exists(Path.Combine(destinationShadersFolder, shaderName))) - { - try - { - File.Copy(defaultShaderLocation, Path.Combine(destinationShadersFolder, shaderName)); - } - catch (FileNotFoundException) - { - // Will probably only occur if user somehow deletes default.shader after the check for its existence occurs, - // but before shaders are generated - if (MessageBox.Show("Unable to find shader to copy from!\nThis really shouldn't have happened.\nPress OK to try again, or Cancel to skip shader generation.", "Shader Gen. Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) - { - File.WriteAllBytes(defaultShaderLocation, ToolkitLauncher.Utility.Resources.defaultH2); - counter = 0; - shaderGen(shaders, counter, full_jms_path, destinationShadersFolder, BaseDirectory); - break; - } - else - { - break; - } - } - } - } - } // Default fall-through return true; }