Fix Wii U model imports crashing

This commit is contained in:
KillzXGaming 2019-03-26 21:08:52 -04:00
parent 1e0ea5660e
commit d28a032b24
11 changed files with 16 additions and 19 deletions

Binary file not shown.

View file

@ -683,7 +683,7 @@ namespace Bfres.Structs
{
FMAT fmat = new FMAT();
if (resFileU != null)
if (IsWiiU)
{
fmat.MaterialU = new ResU.Material();
fmat.MaterialU.Import(settings.ExternalMaterialPath, resFileU);
@ -696,7 +696,6 @@ namespace Bfres.Structs
fmat.ReadMaterial(fmat.Material);
}
fmat.Text = mat.Text;
//Setup placeholder textures
//Note we can't add/remove samplers so we must fill these slots
@ -761,7 +760,7 @@ namespace Bfres.Structs
}
}
}
if (PluginRuntime.ftexContainers.Count > 0)
if (PluginRuntime.ftexContainers.Count > 0 && Parent != null)
{
foreach (var node in Parent.Parent.Nodes)
{
@ -804,10 +803,10 @@ namespace Bfres.Structs
List<string> keyList = new List<string>(materials.Keys);
fmat.Text = Utils.RenameDuplicateString(keyList, fmat.Text);
if (resFileU != null)
if (IsWiiU)
{
fmat.MaterialU.Name = Text;
fmat.SetMaterial(fmat.MaterialU);
fmat.SetMaterial(fmat.MaterialU, resFileU);
}
else
{
@ -842,7 +841,7 @@ namespace Bfres.Structs
materials.Add(fmat.Text, fmat);
Nodes["FmatFolder"].Nodes.Add(fmat);
if (resFileU != null)
if (IsWiiU)
{
fmat.MaterialU = new ResU.Material();
fmat.MaterialU.Name = "NewMaterial";

View file

@ -90,7 +90,7 @@ namespace FirstPlugin
foreach (FMAT mat in fmdl.materials.Values)
{
SetMaterial(mat, mat.MaterialU);
SetMaterial(mat, mat.MaterialU, fmdl.GetResFileU());
model.Materials.Add(mat.Text, mat.MaterialU);
}
return model;
@ -396,15 +396,7 @@ namespace FirstPlugin
indx++;
}
}
public static void CreateNewMaterial(string Name)
{
FMAT mat = new FMAT();
mat.Text = Name;
mat.MaterialU = new Material();
SetMaterial(mat, mat.MaterialU);
}
public static void SetMaterial(this FMAT m, Material mat)
public static void SetMaterial(this FMAT m, Material mat, ResFile ResFile)
{
mat.Name = m.Text;
@ -424,7 +416,7 @@ namespace FirstPlugin
mat.ShaderParamData = ParamData;
WriteRenderInfo(m, mat);
WriteTextureRefs(m, mat);
WriteTextureRefs(m, mat, ResFile);
WriteShaderAssign(m.shaderassign, mat);
}
public static void ReadMaterial(this FMAT m, Material mat)
@ -715,7 +707,7 @@ namespace FirstPlugin
m.renderinfo.Add(r);
}
}
public static void WriteTextureRefs(this FMAT m, Material mat)
public static void WriteTextureRefs(this FMAT m, Material mat, ResFile resFile)
{
mat.TextureRefs = new List<TextureRef>();
mat.TextureRefs.Clear();
@ -737,7 +729,7 @@ namespace FirstPlugin
mat.Samplers.Add(textu.SamplerName, sampler);
Texture texMapped = new Texture();
m.GetResFileU().Textures.TryGetValue(textu.Name, out texMapped);
resFile.Textures.TryGetValue(textu.Name, out texMapped);
texref.Texture = texMapped;
mat.TextureRefs.Add(texref);

View file

@ -76,6 +76,8 @@ namespace Switch_Toolbox.Library.IO
public void CompressData(CompressionType CompressionType, byte[] data)
{
MessageBox.Show(data.Length.ToString());
switch (CompressionType)
{
case CompressionType.Yaz0:

View file

@ -452,7 +452,11 @@ namespace Switch_Toolbox.Library.IO
var stream = new MemoryStream();
using (var writer = new FileWriter(stream))
{
writer.Write(data.Length);
MessageBox.Show(data.Length.ToString());
byte[] buffer = LZ4.Frame.LZ4Frame.Compress(new MemoryStream(data), LZ4.Frame.LZ4MaxBlockSize.Auto, true, true, false, false, true);
writer.Write(buffer, 0, buffer.Length);
}