diff --git a/File_Format_Library/FileFormats/Shader/SHARC.cs b/File_Format_Library/FileFormats/Shader/SHARC/SHARC.cs similarity index 68% rename from File_Format_Library/FileFormats/Shader/SHARC.cs rename to File_Format_Library/FileFormats/Shader/SHARC/SHARC.cs index e04d0e0b..4c488ef1 100644 --- a/File_Format_Library/FileFormats/Shader/SHARC.cs +++ b/File_Format_Library/FileFormats/Shader/SHARC/SHARC.cs @@ -44,6 +44,8 @@ namespace FirstPlugin public void Load(System.IO.Stream stream) { + CanSave = true; + header = new Header(); header.Read(new FileReader(stream)); @@ -67,8 +69,8 @@ namespace FirstPlugin } - public void Save(System.IO.Stream stream) - { + public void Save(System.IO.Stream stream) { + header.Write(new FileWriter(stream)); } //Docs https://github.com/Kinnay/Wii-U-File-Formats/wiki/SHARCFB-File-Format @@ -87,7 +89,7 @@ namespace FirstPlugin uint FileSize = reader.ReadUInt32(); uint bom = reader.ReadUInt32(); uint FileLength = reader.ReadUInt32(); - Name = reader.ReadString((int)FileLength); + Name = reader.ReadString((int)FileLength, true); var pos = reader.Position; @@ -113,9 +115,37 @@ namespace FirstPlugin SourceDatas.Add(source); } } - public void Write(FileWriter reader) - { + public void Write(FileWriter writer) + { + writer.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian; + writer.WriteSignature("AAHS"); + writer.Write(Version); + writer.Write(uint.MaxValue); //fileSize + writer.Write(1); + writer.Write(Name.Length); + writer.WriteString(Name); + Console.WriteLine("pos " + writer.Position); + long sourceArrayPos = writer.Position; + writer.Write(uint.MaxValue); + writer.Write(ShaderPrograms.Count); + + for (int i = 0; i < ShaderPrograms.Count; i++) { + long pos = writer.Position; + ShaderPrograms[i].Write(writer, this); + SharcCommon.WriteSectionSize(writer, pos); + } + + writer.WriteUint32Offset(sourceArrayPos); + for (int i = 0; i < SourceDatas.Count; i++) { + long pos = writer.Position; + SourceDatas[i].Write(writer, this); + SharcCommon.WriteSectionSize(writer, pos); + } + + using (writer.TemporarySeek(8, System.IO.SeekOrigin.Begin)) { + writer.Write((uint)writer.BaseStream.Length); + }; } } @@ -143,6 +173,10 @@ namespace FirstPlugin public ShaderSymbolData SamplerVariables; public ShaderSymbolData AttributeVariables; + public int VertexShaderIndex; + public int FragmentShaderIndex; + public int GeoemetryShaderIndex; + public override void OnClick(TreeView treeview) { ShaderEditor editor = (ShaderEditor)LibraryGUI.GetActiveContent(typeof(ShaderEditor)); @@ -166,9 +200,9 @@ namespace FirstPlugin if (header.Version >= 13) { - ushort vertexUnk1 = reader.ReadUInt16(); - ushort fragmentUnk1 = reader.ReadUInt16(); - ushort geometryUnk1 = reader.ReadUInt16(); + VertexShaderIndex = reader.ReadInt32(); + FragmentShaderIndex = reader.ReadInt32(); + GeoemetryShaderIndex = reader.ReadInt32(); ushort computeUnk1 = reader.ReadUInt16(); ushort vertexUnk2 = reader.ReadUInt16(); ushort fragmentUnk2 = reader.ReadUInt16(); @@ -177,12 +211,11 @@ namespace FirstPlugin } else { - uint vertexUnk1 = reader.ReadUInt32(); - uint fragmentUnk1 = reader.ReadUInt32(); - uint geometryUnk1 = reader.ReadUInt32(); + VertexShaderIndex = reader.ReadInt32(); + FragmentShaderIndex = reader.ReadInt32(); + GeoemetryShaderIndex = reader.ReadInt32(); } - - Text = reader.ReadString((int)NameLength); + Text = reader.ReadString((int)NameLength, true); variationVertexMacroData = new VariationMacroData(); variationFragmenMacroData = new VariationMacroData(); @@ -224,6 +257,39 @@ namespace FirstPlugin reader.Seek(SectionSize + pos, System.IO.SeekOrigin.Begin); } + + public void Write(FileWriter writer, SHARC.Header header) + { + writer.Write(uint.MaxValue); + writer.Write(Text.Length); + writer.Write(VertexShaderIndex); + writer.Write(FragmentShaderIndex); + writer.Write(GeoemetryShaderIndex); + + variationVertexMacroData.Write(writer, header.Version); + variationFragmenMacroData.Write(writer, header.Version); + variationGeometryMacroData.Write(writer, header.Version); + + if (header.Version >= 13) + { + variationComputeMacroData.Write(writer, header.Version); + } + + variationSymbolData.Write(writer); + variationSymbolDataFull.Write(writer); + + if (header.Version <= 12) + { + UniformVariables.Write(writer); + + if (header.Version >= 11) { + UniformBlocks.Write(writer, header.Version); + } + + SamplerVariables.Write(writer); + AttributeVariables.Write(writer); + } + } } public class SourceData : TreeNodeCustom @@ -253,15 +319,21 @@ namespace FirstPlugin uint CodeLength = reader.ReadUInt32(); uint CodeLength2 = reader.ReadUInt32(); //????? Text = reader.ReadString((int)FileNameLength); - // Code = reader.ReadString((int)CodeLength, Encoding.UTF32); - byte[] CodeData = reader.ReadBytes((int)CodeLength); - Code = Encoding.GetEncoding(932).GetString(CodeData); + byte[] data = reader.ReadBytes((int)CodeLength); + Code = Encoding.GetEncoding("shift_jis").GetString(data); reader.Seek(SectioSize + pos, System.IO.SeekOrigin.Begin); } - public void Write(FileWriter reader) - { + public void Write(FileWriter writer, SHARC.Header header) + { + var data = Encoding.GetEncoding("shift_jis").GetBytes(Code); + writer.Write(uint.MaxValue); + writer.Write(Name.Length); + writer.Write(data.Length); + writer.Write(data.Length); + writer.WriteString(Name); + writer.Write(data); } } } diff --git a/File_Format_Library/FileFormats/Shader/SHARCFB.cs b/File_Format_Library/FileFormats/Shader/SHARC/SHARCFB.cs similarity index 88% rename from File_Format_Library/FileFormats/Shader/SHARCFB.cs rename to File_Format_Library/FileFormats/Shader/SHARC/SHARCFB.cs index d21ebe45..4e278bdd 100644 --- a/File_Format_Library/FileFormats/Shader/SHARCFB.cs +++ b/File_Format_Library/FileFormats/Shader/SHARC/SHARCFB.cs @@ -139,7 +139,6 @@ namespace FirstPlugin Name = reader.ReadString((int)NameLength); - var pos = reader.Position; uint BinarySectionSize = reader.ReadUInt32(); uint BinaryFileCount = reader.ReadUInt32(); @@ -167,6 +166,7 @@ namespace FirstPlugin } } + public class ShaderProgram : TreeNodeCustom { public enum ShaderType @@ -309,7 +309,20 @@ namespace FirstPlugin } reader.Seek(SectionPos + SectionSize, System.IO.SeekOrigin.Begin); } + + public void Write(FileWriter writer, uint Version = 12) + { + long pos = writer.Position; + writer.Write(uint.MaxValue); + writer.Write(macros.Count); + + for (int i = 0; i < macros.Count; i++) + macros[i].Write(writer, Version); + + SharcCommon.WriteSectionSize(writer, pos); + } } + public class VariationMacro { public string Name { get; set; } @@ -334,6 +347,17 @@ namespace FirstPlugin reader.Seek(pos + SectionSize, System.IO.SeekOrigin.Begin); } + + public void Write(FileWriter writer, uint Version) + { + var pos = writer.Position; + writer.Write(uint.MaxValue); + writer.Write(Name.Length); + writer.Write(Value.Length); + writer.WriteString(Name); + writer.WriteString(Value); + SharcCommon.WriteSectionSize(writer, pos); + } } public class VariationSymbolData @@ -353,6 +377,17 @@ namespace FirstPlugin } reader.Seek(SectionPos + SectionSize, System.IO.SeekOrigin.Begin); } + + public void Write(FileWriter writer) + { + var pos = writer.Position; + writer.Write(uint.MaxValue); + writer.Write(symbols.Count); + for (int i = 0; i < symbols.Count; i++) + symbols[i].Write(writer); + + SharcCommon.WriteSectionSize(writer, pos); + } } public class VariationSymbol { @@ -379,6 +414,18 @@ namespace FirstPlugin reader.Seek(pos + SectionSize, System.IO.SeekOrigin.Begin); } + + public void Write(FileWriter writer) + { + var pos = writer.Position; + writer.Write(Name.Length); + writer.Write(DefaultValue.Length); + writer.Write(SymbolName.Length); + writer.WriteString(Name); + writer.WriteString(DefaultValue); + writer.WriteString(SymbolName); + SharcCommon.WriteSectionSize(writer, pos); + } } public class ShaderSymbolData @@ -402,6 +449,17 @@ namespace FirstPlugin reader.Seek(SectionPos + SectionSize, System.IO.SeekOrigin.Begin); } + + public void Write(FileWriter writer, uint Version = 12) + { + var pos = writer.Position; + writer.Write(uint.MaxValue); + writer.Write(symbols.Count); + for (int i = 0; i < symbols.Count; i++) + symbols[i].Write(writer); + + SharcCommon.WriteSectionSize(writer, pos); + } } public class ShaderSymbol @@ -516,6 +574,20 @@ namespace FirstPlugin reader.Seek(pos + SectionSize, System.IO.SeekOrigin.Begin); } + public void Write(FileWriter writer) + { + var pos = writer.Position; + writer.Write(0); + writer.Write(Name.Length); + writer.Write(SymbolName.Length); + writer.Write(DefaultValue.Length); + writer.Write(0); + writer.WriteString(Name); + writer.Write(DefaultValue); + writer.WriteString(SymbolName); + SharcCommon.WriteSectionSize(writer, pos); + } + public class SharcNXValue { public string Name { get; set; } diff --git a/File_Format_Library/FileFormats/Shader/SHARCFBNX.cs b/File_Format_Library/FileFormats/Shader/SHARC/SHARCFBNX.cs similarity index 100% rename from File_Format_Library/FileFormats/Shader/SHARCFBNX.cs rename to File_Format_Library/FileFormats/Shader/SHARC/SHARCFBNX.cs diff --git a/File_Format_Library/FileFormats/Shader/SHARC/SharcCommon.cs b/File_Format_Library/FileFormats/Shader/SHARC/SharcCommon.cs new file mode 100644 index 00000000..7c5dbce1 --- /dev/null +++ b/File_Format_Library/FileFormats/Shader/SHARC/SharcCommon.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Toolbox.Library.IO; + +namespace FirstPlugin +{ + public class SharcCommon + { + public static void WriteSectionSize(FileWriter writer, long startPos) + { + long endPos = writer.Position; + using (writer.TemporarySeek(startPos, System.IO.SeekOrigin.Begin)) { + writer.Write((uint)(endPos - startPos)); + }; + } + } +} diff --git a/File_Format_Library/File_Format_Library.csproj b/File_Format_Library/File_Format_Library.csproj index a8e52894..23d41c0e 100644 --- a/File_Format_Library/File_Format_Library.csproj +++ b/File_Format_Library/File_Format_Library.csproj @@ -143,6 +143,12 @@ ..\Toolbox\Lib\SharpYaml.dll + + ..\Toolbox\Lib\SPICA.dll + + + ..\Toolbox\Lib\SPICA.Rendering.dll + ..\Toolbox\Lib\SuperBMDLib.dll False @@ -216,6 +222,16 @@ + + + + + + + + + + @@ -288,15 +304,6 @@ - - - - - - - - - @@ -379,6 +386,7 @@ + @@ -387,6 +395,8 @@ + + @@ -397,12 +407,91 @@ + + UserControl + + + BCHMeshEditor.cs + + + UserControl + + + BCHModelEditor.cs + + + UserControl + + + BCHBoneEditor.cs + + + UserControl + + + BCHMaterialGeneralEditor.cs + + + UserControl + + + BCHMaterialShaderParamEditor.cs + + + UserControl + + + BCHMaterialEditor.cs + + + UserControl + + + BCHMaterialColorEditor.cs + + + UserControl + + + BCHMaterialBlendingEditor.cs + + + UserControl + + + BCHMaterialFragmentEditor.cs + + + UserControl + + + BCHTextureMapEditor.cs + + + + UserControl + + + UserDataEditor.cs + + + Form + + + UserDataParser.cs + UserControl PaneAnimationController.cs + + UserControl + + + RenderStateEditor.cs + UserControl @@ -708,7 +797,7 @@ - + @@ -718,7 +807,6 @@ - @@ -734,7 +822,7 @@ - + @@ -856,18 +944,6 @@ - - UserControl - - - BcresEditor.cs - - - UserControl - - - SamplerEditorSimple.cs - UserControl @@ -1306,7 +1382,7 @@ - + @@ -1316,7 +1392,7 @@ - + UserControl @@ -1453,8 +1529,8 @@ - + @@ -1471,9 +1547,51 @@ AttributeEditor.cs + + BCHMeshEditor.cs + + + BCHModelEditor.cs + + + BCHBoneEditor.cs + + + BCHMaterialGeneralEditor.cs + + + BCHMaterialBlendingEditor.cs + + + BCHMaterialColorEditor.cs + + + BCHMaterialEditor.cs + + + BCHMaterialFragmentEditor.cs + + + BCHMaterialShaderParamEditor.cs + + + BCHTextureMapEditor.cs + + + UserDataEditor.cs + + + UserDataParser.cs + PaneAnimationController.cs + + RenderStateEditor.cs + + + TexSrtPanel2D.cs + GFLXMaterialEditor.cs @@ -1492,12 +1610,6 @@ ViewportEditor.cs - - BcresEditor.cs - - - SamplerEditorSimple.cs - BffntEditor.cs @@ -2028,4 +2140,4 @@ - + \ No newline at end of file diff --git a/File_Format_Library/GUI/BCH/BCHMeshEditor.cs b/File_Format_Library/GUI/BCH/BCHMeshEditor.cs new file mode 100644 index 00000000..3b8ab358 --- /dev/null +++ b/File_Format_Library/GUI/BCH/BCHMeshEditor.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using SPICA.Formats.CtrH3D.Model.Mesh; +using Toolbox.Library.Forms; + +namespace FirstPlugin.CtrLibrary.Forms +{ + public partial class BCHMeshEditor : UserControl + { + public H3DMeshWrapper MeshWrapper; + public H3DMesh ActiveMesh => MeshWrapper.Mesh; + + public BCHMeshEditor() + { + InitializeComponent(); + + stTabControl1.myBackColor = FormThemes.BaseTheme.FormBackColor; + } + + public void LoadMesh(H3DMeshWrapper mesh) { + MeshWrapper = mesh; + + if (ActiveMesh.MetaData != null) + bchUserDataEditor1.LoadUserData(ActiveMesh.MetaData); + } + } +} diff --git a/File_Format_Library/GUI/BCH/Material/BCHMaterialFragmentEditor.cs b/File_Format_Library/GUI/BCH/Material/BCHMaterialFragmentEditor.cs index 67b81d60..2eff2229 100644 --- a/File_Format_Library/GUI/BCH/Material/BCHMaterialFragmentEditor.cs +++ b/File_Format_Library/GUI/BCH/Material/BCHMaterialFragmentEditor.cs @@ -368,7 +368,7 @@ namespace FirstPlugin.CtrLibrary.Forms if (index == -1 || !(comboBox.SelectedItem is PICATextureCombinerSource)) return; - switch ((PICATextureCombinerSource)comboBox.SelectedItem) + /* switch ((PICATextureCombinerSource)comboBox.SelectedItem) { case PICATextureCombinerSource.Texture0: if (CombinerImages.ContainsKey("Texture0")) @@ -382,7 +382,7 @@ namespace FirstPlugin.CtrLibrary.Forms if (CombinerImages.ContainsKey("Texture2")) comboBox.Items[index].Image = CombinerImages["Texture2"]; break; - } + }*/ } private void layerCB_SelectedIndexChanged(object sender, EventArgs e) { diff --git a/Switch_Toolbox_Library/Compression/Formats/BPE.cs b/Switch_Toolbox_Library/Compression/Formats/BPE.cs new file mode 100644 index 00000000..8e9c4eaa --- /dev/null +++ b/Switch_Toolbox_Library/Compression/Formats/BPE.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Toolbox.Library.Compression.Formats +{ + class BPE + { + } +} diff --git a/Switch_Toolbox_Library/FileFormats/DAE/ColladaWriter.cs b/Switch_Toolbox_Library/FileFormats/DAE/ColladaWriter.cs index c4358e91..ee5dfb55 100644 --- a/Switch_Toolbox_Library/FileFormats/DAE/ColladaWriter.cs +++ b/Switch_Toolbox_Library/FileFormats/DAE/ColladaWriter.cs @@ -793,11 +793,10 @@ namespace Toolbox.Library.Collada Writer.WriteStartElement("instance_material"); Writer.WriteAttributeString("symbol", mat); Writer.WriteAttributeString("target", "#" + mat); - Writer.WriteEndElement(); - WriteChannel(0); WriteChannel(1); WriteChannel(2); + Writer.WriteEndElement(); } Writer.WriteEndElement(); Writer.WriteEndElement(); diff --git a/Switch_Toolbox_Library/FileFormats/DAE/DAE.cs b/Switch_Toolbox_Library/FileFormats/DAE/DAE.cs index 246ab7a7..8838e8a4 100644 --- a/Switch_Toolbox_Library/FileFormats/DAE/DAE.cs +++ b/Switch_Toolbox_Library/FileFormats/DAE/DAE.cs @@ -95,7 +95,8 @@ namespace Toolbox.Library List textureNames = new List(); for (int i = 0; i < Textures?.Count; i++) { - textureNames.Add(Textures[i].Text); + if (!textureNames.Contains(Textures[i].Text)) + textureNames.Add(Textures[i].Text); if (settings.ExportTextures) { @@ -176,7 +177,7 @@ namespace Toolbox.Library //If no textures are saved, still keep images references //So the user can still dump textures after - if (Textures?.Count == 0) + if (Textures?.Count == 0 && !textureNames.Contains(texMap.Name)) textureNames.Add($"{texMap.Name}"); material.Textures.Add(texMap); diff --git a/Switch_Toolbox_Library/FileFormats/DDSCompressor.cs b/Switch_Toolbox_Library/FileFormats/DDSCompressor.cs index 0ff1f8b5..036e0330 100644 --- a/Switch_Toolbox_Library/FileFormats/DDSCompressor.cs +++ b/Switch_Toolbox_Library/FileFormats/DDSCompressor.cs @@ -554,6 +554,7 @@ namespace Toolbox.Library return Convert(data, width, height, DXGI_FORMAT.R8G8B8A8_UNORM, (DXGI_FORMAT)format); } + public static unsafe byte[] Convert(Byte[] data, int width, int height, DXGI_FORMAT inputFormat, DXGI_FORMAT outputFormat) { long inputRowPitch; diff --git a/Switch_Toolbox_Library/Format Managers/FileManager.cs b/Switch_Toolbox_Library/Format Managers/FileManager.cs index 485b3f21..1315fe6d 100644 --- a/Switch_Toolbox_Library/Format Managers/FileManager.cs +++ b/Switch_Toolbox_Library/Format Managers/FileManager.cs @@ -102,8 +102,7 @@ namespace Toolbox.Library if (GenericPluginLoader._Plugins == null) GenericPluginLoader.LoadPlugin(); - foreach (var plugin in GenericPluginLoader._Plugins) - { + foreach (var plugin in GenericPluginLoader._Plugins) { LoadCompressionFormats(plugin.Value.Types, types); } diff --git a/Switch_Toolbox_Library/Forms/Color/ColorSelector.cs b/Switch_Toolbox_Library/Forms/Color/ColorSelector.cs index a8b7eff1..65d8821e 100644 --- a/Switch_Toolbox_Library/Forms/Color/ColorSelector.cs +++ b/Switch_Toolbox_Library/Forms/Color/ColorSelector.cs @@ -310,13 +310,13 @@ namespace Toolbox.Library.Forms if (!huePanel.Enabled) { - for (int i = 0; i < _mainBrush.SurroundColors.Length; i++) - _mainBrush.SurroundColors[i] = _mainBrush.SurroundColors[i].Darken(190); + _boxColors[0] = _boxColors[4] = new HSVPixel(_hsv.H, 0, 50).ToRGBA(); + _mainBrush.SurroundColors = _boxColors; + _mainBrush.CenterColor = new HSVPixel(_hsv.H, 0, 50).ToRGBA(); } g.FillRectangle(_mainBrush, r); - //Draw indicator int x = (int)(_hsv.V / 100.0f * colorSquare.Width); int y = (int)((100 - _hsv.S) / 100.0f * colorSquare.Height); diff --git a/Switch_Toolbox_Library/Forms/Custom/ComboBox/ImagedComboBox.cs b/Switch_Toolbox_Library/Forms/Custom/ComboBox/ImagedComboBox.cs new file mode 100644 index 00000000..1dcb002b --- /dev/null +++ b/Switch_Toolbox_Library/Forms/Custom/ComboBox/ImagedComboBox.cs @@ -0,0 +1,13 @@ +using System; +using System.ComponentModel; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; + +namespace Toolbox.Library.Forms +{ + public class ImagedComboBox : STComboBox + { + + } +} diff --git a/Switch_Toolbox_Library/Interfaces/FileFormatting/IArchiveFile.cs b/Switch_Toolbox_Library/Interfaces/FileFormatting/IArchiveFile.cs index 9eb703fa..a37b2646 100644 --- a/Switch_Toolbox_Library/Interfaces/FileFormatting/IArchiveFile.cs +++ b/Switch_Toolbox_Library/Interfaces/FileFormatting/IArchiveFile.cs @@ -970,6 +970,7 @@ namespace Toolbox.Library { var prevNode = (TreeNode)ArchiveFileInfo.FileFormat; var parent = prevNode.Parent; + if (parent == null) return; var index = parent.Nodes.IndexOf(prevNode); parent.Nodes.RemoveAt(index); diff --git a/Switch_Toolbox_Library/Toolbox_Library.csproj b/Switch_Toolbox_Library/Toolbox_Library.csproj index 1ded5e45..15cbb455 100644 --- a/Switch_Toolbox_Library/Toolbox_Library.csproj +++ b/Switch_Toolbox_Library/Toolbox_Library.csproj @@ -227,6 +227,7 @@ + @@ -283,12 +284,21 @@ AlphaSelectorHorizontalPanel.cs + + UserControl + + + STColorControl.cs + Component Component + + Component + UserControl @@ -959,6 +969,9 @@ ColorSelector.cs + + STColorControl.cs + STCollapsePanelButton.cs diff --git a/Toolbox/Lib/SPICA.Rendering.dll b/Toolbox/Lib/SPICA.Rendering.dll index 4681f5fb..39e037c3 100644 Binary files a/Toolbox/Lib/SPICA.Rendering.dll and b/Toolbox/Lib/SPICA.Rendering.dll differ diff --git a/Toolbox/Lib/SPICA.Rendering.pdb b/Toolbox/Lib/SPICA.Rendering.pdb index f913a3e0..cb67fe85 100644 Binary files a/Toolbox/Lib/SPICA.Rendering.pdb and b/Toolbox/Lib/SPICA.Rendering.pdb differ diff --git a/Toolbox/Lib/SPICA.dll b/Toolbox/Lib/SPICA.dll index 545b3cf4..434e7fa8 100644 Binary files a/Toolbox/Lib/SPICA.dll and b/Toolbox/Lib/SPICA.dll differ diff --git a/Toolbox/Lib/SPICA.pdb b/Toolbox/Lib/SPICA.pdb index 1f15f7a5..db019fe8 100644 Binary files a/Toolbox/Lib/SPICA.pdb and b/Toolbox/Lib/SPICA.pdb differ