Skip to content

Commit

Permalink
More path changes but for material dumper tool
Browse files Browse the repository at this point in the history
  • Loading branch information
KillzXGaming committed May 1, 2022
1 parent 98dd72b commit a1d2b2b
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions Plugins/CafeLibrary/Bfres/PresetDumpScript/MaterialPresetDumper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ public static void ExportMaterials(string gamePath)
if (!Directory.Exists(gamePath))
return;

if (!Directory.Exists($"{Toolbox.Core.Runtime.ExecutableDir}\\Presets\\Materials\\"))
Directory.CreateDirectory($"{Toolbox.Core.Runtime.ExecutableDir}\\Presets\\Materials\\");

string dir = Path.Combine(Toolbox.Core.Runtime.ExecutableDir, "Presets", "Materials");
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);

//Just check for a mk8d specific asset
bool isMK8D = File.Exists($"{gamePath}\\RaceCommon\\TS_PolicePackun\\TS_PolicePackun.bfres");
bool isMK8D = File.Exists(Path.Combine(gamePath, "RaceCommon", "TS_PolicePackun", "TS_PolicePackun.bfres"));

string dir = $"{Toolbox.Core.Runtime.ExecutableDir}\\Presets\\Materials";
string game_folder = gamePath;
dir = isMK8D ? $"{dir}\\MK8D" : $"{dir}\\MK8U";
dir = isMK8D ? Path.Combine(dir, "MK8D") : Path.Combine(dir, "MK8U");

if (Directory.Exists(dir))
return;
Expand All @@ -40,7 +39,7 @@ public static void ExportMaterials(string gamePath)
Dictionary<string, List<MaterialEntry>> presets = new Dictionary<string, List<MaterialEntry>>();

//Parse a csv containing material dump info
using (var textReader = new StreamReader($"{Toolbox.Core.Runtime.ExecutableDir}\\Lib\\Presets\\TurboMaterialDumper.csv"))
using (var textReader = new StreamReader(Path.Combine(Toolbox.Core.Runtime.ExecutableDir, "Lib", "Presets", "TurboMaterialDumper.csv")))
{
//Header
textReader.ReadLine();
Expand All @@ -63,7 +62,7 @@ public static void ExportMaterials(string gamePath)
//Save with textures or not
bool keepTextures = args[3].Trim() == "true";

var entry = new MaterialEntry(materialName, $"{dir}\\{presetSavePath}", keepTextures);
var entry = new MaterialEntry(materialName, Path.Combine(dir, presetSavePath), keepTextures);
if (!presets.ContainsKey(fileName))
presets.Add(fileName, new List<MaterialEntry>());

Expand All @@ -73,7 +72,7 @@ public static void ExportMaterials(string gamePath)

//Dump each preset into the preset folder
foreach (var preset in presets)
DumpBfresMaterials($"{game_folder}\\{preset.Key}", preset.Value.ToArray());
DumpBfresMaterials(Path.Combine(game_folder, preset.Key), preset.Value.ToArray());

ProcessLoading.Instance.Update(100, 100, "Dumping game material presets!");
ProcessLoading.Instance.IsLoading = false;
Expand All @@ -89,7 +88,7 @@ private static void DumpAllMaterials(string dir, string filePath)
{
foreach (var mat in model.Materials.Values)
{
var preset = new MaterialEntry(mat.Name, $"{dir}\\{mat.Name}.zip");
var preset = new MaterialEntry(mat.Name, Path.Combine(dir, $"{mat.Name}.zip"));
SaveAsPreset(preset.FilePath, mat, resFile, preset.ExportTextures, preset.ExportAnimations);
}
}
Expand Down Expand Up @@ -142,7 +141,7 @@ public static void SaveAsPreset(string filePath, Material material, ResFile resF
string archiveName = material.ShaderAssign.ShaderArchiveName;
string presetName = Path.GetFileNameWithoutExtension(filePath);
string dir = Path.GetDirectoryName(filePath);
string presetFolder = $"{dir}\\{presetName}";
string presetFolder = Path.Combine(dir, presetName);
string ShaderArchive = material.ShaderAssign.ShaderArchiveName;

if (!Directory.Exists(presetFolder))
Expand All @@ -159,7 +158,7 @@ public static void SaveAsPreset(string filePath, Material material, ResFile resF
//Assign the new shader archive name
material.ShaderAssign.ShaderArchiveName = name;
//Export the shader with a new internal name
SaveShaderPreset(resFile.IsPlatformSwitch, $"{presetFolder}\\{name}.bfsha", file.Value.Data, name);
SaveShaderPreset(resFile.IsPlatformSwitch, Path.Combine(presetName, $"{name}.bfsha"), file.Value.Data, name);
}
}
if (exportTextures)
Expand All @@ -178,18 +177,18 @@ public static void SaveAsPreset(string filePath, Material material, ResFile resF
var bntx = externalFile.LoadedFileData as BntxFile;
var tex = bntx.Textures.FirstOrDefault(x => x.Name == name);
if (tex != null)
tex.Export($"{presetFolder}\\{name}.bftex", bntx);
tex.Export(Path.Combine(presetFolder, $"{name}.bftex"), bntx);
}
else if (textures.ContainsKey(name))
textures[name].Export($"{presetFolder}\\{name}.bftex", resFile);
textures[name].Export(Path.Combine(presetFolder, $"{name}.bftex"), resFile);
}
}
if (exportAnims)
{
void ExportMaterialAnim(MaterialAnim anim, string ext)
{
if (anim.MaterialAnimDataList.Any(x => x.Name == material.Name))
anim.Export($"{presetFolder}\\{anim.Name}{ext}", resFile);
anim.Export(Path.Combine(presetFolder, $"{anim.Name}{ext}"), resFile);
}
foreach (var anim in resFile.ShaderParamAnims.Values)
ExportMaterialAnim(anim, ".bfsp");
Expand All @@ -200,14 +199,14 @@ void ExportMaterialAnim(MaterialAnim anim, string ext)
foreach (var anim in resFile.ColorAnims.Values)
ExportMaterialAnim(anim, ".bfclr");
}
material.Export($"{presetFolder}\\{presetName}.json", resFile);
material.Export(Path.Combine(presetFolder, $"{presetName}.json"), resFile);

//Remove previous preset
if (File.Exists($"{dir}\\{presetName}.zip"))
File.Delete($"{dir}\\{presetName}.zip");
if (File.Exists(Path.Combine(dir, $"{presetName}.zip")))
File.Delete(Path.Combine(dir, $"{presetName}.zip"));

//Package preset
ZipFile.CreateFromDirectory(presetFolder, $"{dir}\\{presetName}.zip");
ZipFile.CreateFromDirectory(presetFolder, Path.Combine( dir, $"{presetName}.zip"));
//Remove directory
foreach (var file in Directory.GetFiles(presetFolder))
File.Delete(file);
Expand Down

0 comments on commit a1d2b2b

Please sign in to comment.