mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Add function to replace all skin materials.
This commit is contained in:
parent
c3454f1d16
commit
5d77cd5514
1 changed files with 13 additions and 5 deletions
|
|
@ -3,6 +3,7 @@ using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using Dalamud.Logging;
|
using Dalamud.Logging;
|
||||||
using Penumbra.GameData.ByteString;
|
using Penumbra.GameData.ByteString;
|
||||||
using Penumbra.GameData.Files;
|
using Penumbra.GameData.Files;
|
||||||
|
|
@ -12,7 +13,9 @@ namespace Penumbra.Util;
|
||||||
|
|
||||||
public static class ModelChanger
|
public static class ModelChanger
|
||||||
{
|
{
|
||||||
public const string MaterialFormat = "/mt_c0201b0001_{0}.mtrl";
|
public const string MaterialFormat = "/mt_c0201b0001_{0}.mtrl";
|
||||||
|
public static readonly Regex MaterialRegex = new(@"/mt_c0201b0001_.*?\.mtrl", RegexOptions.Compiled);
|
||||||
|
|
||||||
|
|
||||||
public static bool ValidStrings( string from, string to )
|
public static bool ValidStrings( string from, string to )
|
||||||
=> from.Length != 0
|
=> from.Length != 0
|
||||||
|
|
@ -39,15 +42,20 @@ public static class ModelChanger
|
||||||
{
|
{
|
||||||
var data = File.ReadAllBytes( file.FullName );
|
var data = File.ReadAllBytes( file.FullName );
|
||||||
var mdlFile = new MdlFile( data );
|
var mdlFile = new MdlFile( data );
|
||||||
from = string.Format( MaterialFormat, from );
|
Func< string, bool > compare = MaterialRegex.IsMatch;
|
||||||
to = string.Format( MaterialFormat, to );
|
if( from.Length > 0 )
|
||||||
|
{
|
||||||
|
from = string.Format( MaterialFormat, from );
|
||||||
|
compare = s => s == from;
|
||||||
|
}
|
||||||
|
|
||||||
|
to = string.Format( MaterialFormat, to );
|
||||||
var replaced = 0;
|
var replaced = 0;
|
||||||
for( var i = 0; i < mdlFile.Materials.Length; ++i )
|
for( var i = 0; i < mdlFile.Materials.Length; ++i )
|
||||||
{
|
{
|
||||||
if( mdlFile.Materials[ i ] == @from )
|
if( compare(mdlFile.Materials[i]) )
|
||||||
{
|
{
|
||||||
mdlFile.Materials[ i ] = to;
|
mdlFile.Materials[i] = to;
|
||||||
++replaced;
|
++replaced;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue