Skip to content

Commit 5c52c2e

Browse files
committed
Replace Shaders (Material)
- Clean-up
1 parent c46541c commit 5c52c2e

5 files changed

Lines changed: 174 additions & 4 deletions

File tree

FrostyMeshVariationDbEditor.cs

Lines changed: 174 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public override List<ToolbarItem> RegisterToolbarItems()
4242
toolbarItems.Add(new ToolbarItem("Export", "Export Database", "FrostyEditor;component/Images/Export.png", new RelayCommand((object state) => { ExportButton_Click(this, new RoutedEventArgs()); })));
4343
toolbarItems.Add(new ToolbarItem("Import", "Import Database", "FrostyEditor;component/Images/Import.png", new RelayCommand((object state) => { ImportButton_Click(this, new RoutedEventArgs()); })));
4444
toolbarItems.Add(new ToolbarItem("Replace Shaders (All)", null, "MeshVariationDbPlugin;component/Images/Alpha.png", new RelayCommand((object state) => { AlphaButton_Click(this, new RoutedEventArgs()); })));
45-
toolbarItems.Add(new ToolbarItem("Replace Shaders (Mesh)", null, "MeshVariationDbPlugin;component/Images/AlphaMesh.png", new RelayCommand((object state) => { AlphaMeshButton_Click(this, new RoutedEventArgs()); })));
45+
toolbarItems.Add(new ToolbarItem("Replace Shaders (Mesh)", null, "FrostyEditor;component/Images/Mesh.png", new RelayCommand((object state) => { AlphaMeshButton_Click(this, new RoutedEventArgs()); })));
46+
toolbarItems.Add(new ToolbarItem("Replace Shaders (Material)", null, "FrostyEditor;component/Images/Grid.png", new RelayCommand((object state) => { AlphaMatButton_Click(this, new RoutedEventArgs()); })));
4647
toolbarItems.Add(new ToolbarItem("Find Namehash", null, "MeshVariationDbPlugin;component/Images/Hash.png", new RelayCommand((object state) => { FindHashButton_Click(this, new RoutedEventArgs()); })));
4748

4849
return toolbarItems;
@@ -143,7 +144,7 @@ private void AlphaButton_Click(object sender, RoutedEventArgs e)
143144

144145
if (isAvailable == true)
145146
{
146-
MessageBoxResult result = FrostyMessageBox.Show("Do you wish to replace shaders?", "Replace Shaders", MessageBoxButton.YesNo);
147+
MessageBoxResult result = FrostyMessageBox.Show("Do you wish to replace all shaders?", "Replace Shaders", MessageBoxButton.YesNo);
147148
if (result == MessageBoxResult.Yes)
148149
{
149150
App.AssetManager.ModifyEbx(entry.Name, asset);
@@ -282,6 +283,11 @@ private void AlphaMeshButton_Click(object sender, RoutedEventArgs e)
282283
}
283284
}
284285
}
286+
else if (selectedAssetEntry.Filename.EndsWith("rgz_mesh") == false)
287+
{
288+
FrostyMessageBox.Show("'" + selectedAssetEntry.Filename + "' is not a SkinnedMeshAsset.", "Replace Shaders");
289+
return;
290+
}
285291
}
286292
}
287293

@@ -390,6 +396,171 @@ private void AlphaMeshButton_Click(object sender, RoutedEventArgs e)
390396
}
391397
}
392398

399+
private void AlphaMatButton_Click(object sender, RoutedEventArgs e)
400+
{
401+
EbxAssetEntry entry = (EbxAssetEntry)AssetEntry;
402+
403+
dynamic varEntriesPre = App.AssetManager.GetEbx(entry).RootObject;
404+
dynamic varEntryPre = varEntriesPre.Entries;
405+
406+
bool isAvailable = false;
407+
408+
Guid clipTextGuidPre = System.Guid.Empty;
409+
410+
int shaderNum = 0;
411+
int shaderMasterNum = 0;
412+
int shaderDecayNum = 0;
413+
int shaderDissolveBBNum = 0;
414+
int shaderFrozenNum = 0;
415+
int shaderDoTMasterNum = 0;
416+
int shaderPetrifyNum = 0;
417+
418+
string shaderMasterText = "Character_Wardrobe_Master_2Sided_Alpha";
419+
420+
if (varEntryPre.Count > 0)
421+
{
422+
for (int i = 0; i < varEntryPre.Count; i++)
423+
{
424+
var entriesPre = varEntryPre[i];
425+
426+
FrostyPropertyGridItemData pointerRefPreGrid = (FrostyPropertyGridItemData)DataContext;
427+
428+
string clipTextPre = Clipboard.GetText();
429+
bool isValid = Guid.TryParse(clipTextPre, out _);
430+
431+
Guid pointerRefGuidPre;
432+
433+
try
434+
{
435+
if (isValid)
436+
{
437+
clipTextGuidPre = Guid.Parse(clipTextPre);
438+
}
439+
else
440+
{
441+
App.Logger.Log("Clipboard must contain a valid Guid.");
442+
return;
443+
}
444+
445+
foreach (var meshVariationMaterialPre in entriesPre.Materials)
446+
{
447+
pointerRefGuidPre = ((PointerRef)meshVariationMaterialPre.Material).External.ClassGuid;
448+
449+
if (pointerRefGuidPre == clipTextGuidPre && meshVariationMaterialPre.SurfaceShaderId == 3024908220) //Master
450+
{
451+
isAvailable = true;
452+
break;
453+
}
454+
}
455+
}
456+
catch
457+
{
458+
App.Logger.Log("Clipboard contents are invalid.");
459+
return;
460+
}
461+
}
462+
}
463+
464+
if (isAvailable == true)
465+
{
466+
MessageBoxResult result = FrostyMessageBox.Show("Do you wish to replace shaders assigned to:" + "\n\n" + "[" + clipTextGuidPre.ToString() + "]?", "Replace Shaders", MessageBoxButton.YesNo);
467+
if (result == MessageBoxResult.Yes)
468+
{
469+
App.AssetManager.ModifyEbx(entry.Name, asset);
470+
471+
dynamic varEntries = App.AssetManager.GetEbx(entry).RootObject;
472+
dynamic varEntry = varEntries.Entries;
473+
474+
if (varEntry.Count > 0)
475+
{
476+
for (int i = 0; i < varEntry.Count; i++)
477+
{
478+
var entries = varEntry[i];
479+
480+
FrostyPropertyGridItemData pointerRefGrid = (FrostyPropertyGridItemData)DataContext;
481+
482+
Guid pointerRefGuid;
483+
Guid clipTextGuid = Guid.Parse(Clipboard.GetText());
484+
485+
foreach (var meshVariationMaterial in entries.Materials)
486+
{
487+
pointerRefGuid = ((PointerRef)meshVariationMaterial.Material).External.ClassGuid;
488+
489+
if (pointerRefGuid == clipTextGuid && meshVariationMaterial.SurfaceShaderId == 3024908220) //Master
490+
{
491+
meshVariationMaterial.SurfaceShaderId = 1748236261;
492+
meshVariationMaterial.SurfaceShaderGuid = Guid.Parse("5c665d88-fe38-4515-b8b1-0713fd6a558f");
493+
494+
shaderNum++;
495+
shaderMasterNum++;
496+
}
497+
else if (pointerRefGuid == clipTextGuid && meshVariationMaterial.SurfaceShaderId == 3366952955) //Decay
498+
{
499+
meshVariationMaterial.SurfaceShaderId = 2989973410;
500+
meshVariationMaterial.SurfaceShaderGuid = Guid.Parse("91b79ab7-1f6a-4e76-a00f-372d9b4f64f0");
501+
502+
shaderNum++;
503+
shaderDecayNum++;
504+
}
505+
else if (pointerRefGuid == clipTextGuid && meshVariationMaterial.SurfaceShaderId == 390866619) //DissolveBB
506+
{
507+
meshVariationMaterial.SurfaceShaderId = 2336327458;
508+
meshVariationMaterial.SurfaceShaderGuid = Guid.Parse("c247f7f5-2bc3-4f16-8459-c5022b851360");
509+
510+
shaderNum++;
511+
shaderDissolveBBNum++;
512+
}
513+
else if (pointerRefGuid == clipTextGuid && meshVariationMaterial.SurfaceShaderId == 1571638619) //Frozen
514+
{
515+
meshVariationMaterial.SurfaceShaderId = 1828819106;
516+
meshVariationMaterial.SurfaceShaderGuid = Guid.Parse("762d48c1-097b-4a5d-bc28-2bb78d2a17a5");
517+
518+
shaderNum++;
519+
shaderFrozenNum++;
520+
}
521+
else if (pointerRefGuid == clipTextGuid && meshVariationMaterial.SurfaceShaderId == 2107662139) //DoTMaster
522+
{
523+
meshVariationMaterial.SurfaceShaderId = 4224110914;
524+
meshVariationMaterial.SurfaceShaderGuid = Guid.Parse("a9e6496a-5bf7-4fb9-af37-36dfc47f7cce");
525+
526+
shaderNum++;
527+
shaderDoTMasterNum++;
528+
}
529+
else if (pointerRefGuid == clipTextGuid && meshVariationMaterial.SurfaceShaderId == 1184284987) //Petrify
530+
{
531+
meshVariationMaterial.SurfaceShaderId = 2534832770;
532+
meshVariationMaterial.SurfaceShaderGuid = Guid.Parse("974e1887-a9da-4f98-a698-178b0d2e4d23");
533+
534+
shaderNum++;
535+
shaderPetrifyNum++;
536+
}
537+
}
538+
}
539+
}
540+
541+
InvokeOnAssetModified();
542+
543+
dataExplorer.RefreshItems();
544+
typeof(MainWindow).InvokeMember("RefreshTabs", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, Application.Current.MainWindow, []);
545+
546+
App.Logger.Log(
547+
shaderNum + " shader(s) assigned to [" + clipTextGuidPre.ToString() + "] have been replaced successfully." + "\n" +
548+
shaderMasterText + ": " + shaderMasterNum + "\n" +
549+
shaderMasterText + "_Decay_VAR: " + shaderDecayNum + "\n" +
550+
shaderMasterText + "_DissolveBB_VAR: " + shaderDissolveBBNum + "\n" +
551+
shaderMasterText + "_Frozen_VAR: " + shaderFrozenNum + "\n" +
552+
shaderMasterText + "_DoTMaster_VAR: " + shaderDoTMasterNum + "\n" +
553+
shaderMasterText + "_Petrify_VAR: " + shaderPetrifyNum);
554+
}
555+
}
556+
557+
if (!isAvailable)
558+
{
559+
FrostyMessageBox.Show("There are no non-alpha shaders assigned to:" + "\n\n" + "[" + clipTextGuidPre.ToString() + "]", "Replace Shaders");
560+
return;
561+
}
562+
}
563+
393564
private void FindHashButton_Click(object sender, RoutedEventArgs e)
394565
{
395566
EbxAssetEntry entry = (EbxAssetEntry)AssetEntry;
@@ -416,7 +587,7 @@ private void FindHashButton_Click(object sender, RoutedEventArgs e)
416587
}
417588
else
418589
{
419-
App.Logger.Log("Clipboard contents must be a number.");
590+
App.Logger.Log("Clipboard must contian a valid namehash value.");
420591
return;
421592
}
422593

Images/Alpha.png

-134 Bytes
Loading

Images/AlphaMesh.png

-847 Bytes
Binary file not shown.

Images/Hash.png

-108 Bytes
Loading

MeshVariationDbPlugin.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676

7777
<ItemGroup>
7878
<Resource Include="Images\Alpha.png" />
79-
<Resource Include="Images\AlphaMesh.png" />
8079
<Resource Include="Images\Hash.png" />
8180
</ItemGroup>
8281
</Project>

0 commit comments

Comments
 (0)