diff --git a/.vs/Toolbox/v15/.suo b/.vs/Toolbox/v15/.suo index 4aeb3ece..a7b0d587 100644 Binary files a/.vs/Toolbox/v15/.suo and b/.vs/Toolbox/v15/.suo differ diff --git a/File_Format_Library/FileFormats/Archives/LM2/LM2_Model.cs b/File_Format_Library/FileFormats/Archives/LM2/LM2_Model.cs index 0db66647..0c169073 100644 --- a/File_Format_Library/FileFormats/Archives/LM2/LM2_Model.cs +++ b/File_Format_Library/FileFormats/Archives/LM2/LM2_Model.cs @@ -112,11 +112,19 @@ namespace FirstPlugin.LuigisMansion.DarkMoon Console.WriteLine($"Mesh {genericObj.Text} Format {formatInfo.Format} BufferLength {formatInfo.BufferLength}"); uint bufferOffet = BufferStart + VertexBufferPointers[i]; - /* for (int v = 0; v < mesh.VertexCount; v++) - { - reader.SeekBegin(bufferOffet + (v * formatInfo.BufferLength)); - }*/ + using (reader.TemporarySeek(bufferOffet, System.IO.SeekOrigin.Begin)) + { + var bufferNodeDebug = new DebugVisualBytes(reader.ReadBytes((int)formatInfo.BufferLength * mesh.VertexCount)); + bufferNodeDebug.Text = "Buffer"; + genericObj.Nodes.Add(bufferNodeDebug); + } + + /* for (int v = 0; v < mesh.VertexCount; v++) + { + reader.SeekBegin(bufferOffet + (v * formatInfo.BufferLength)); + + }*/ switch (formatInfo.Format) { @@ -134,19 +142,40 @@ namespace FirstPlugin.LuigisMansion.DarkMoon reader.BaseStream.Position += 0x4; vert.pos = Vector3.TransformPosition(vert.pos, Transform); - vert.uv0 = NormalizeUvCoordsToFloat(reader.ReadUInt16(), reader.ReadUInt16()); - /* reader.BaseStream.Position += 8; + Console.WriteLine("vert.uv0 " + vert.uv0); - // vert.uv1 = NormalizeUvCoordsToFloat(reader.ReadUInt16(), reader.ReadUInt16()); - // vert.uv2 = NormalizeUvCoordsToFloat(reader.ReadUInt16(), reader.ReadUInt16()); + if (formatInfo.BufferLength == 22) + { + Console.WriteLine("unk 1 " + reader.ReadUInt16()); + Console.WriteLine("unk 2 " + reader.ReadUInt16()); + Console.WriteLine("unk 3 " + reader.ReadUInt16()); + Console.WriteLine("unk 4 " + reader.ReadUInt16()); - vert.nrm = new Vector3( - UShortToFloatDecode(reader.ReadInt16()), - UShortToFloatDecode(reader.ReadInt16()), - UShortToFloatDecode(reader.ReadInt16()));*/ - } + var vec4 = Set_10_10_10_2_UNorm(reader.ReadUInt32()); + vert.nrm = vec4.Xyz; + } + + + // reader.BaseStream.Position += 0x2; + + /* vert.col = new Vector4( + UShortToFloatDecode(reader.ReadInt16()), + UShortToFloatDecode(reader.ReadInt16()), + UShortToFloatDecode(reader.ReadInt16()), + UShortToFloatDecode(reader.ReadInt16()));*/ + + /* reader.BaseStream.Position += 8; + + // vert.uv1 = NormalizeUvCoordsToFloat(reader.ReadUInt16(), reader.ReadUInt16()); + // vert.uv2 = NormalizeUvCoordsToFloat(reader.ReadUInt16(), reader.ReadUInt16()); + + vert.nrm = new Vector3( + UShortToFloatDecode(reader.ReadInt16()), + UShortToFloatDecode(reader.ReadInt16()), + UShortToFloatDecode(reader.ReadInt16()));*/ + } break; case VertexDataFormat.Float32: for (int v = 0; v < mesh.VertexCount; v++) @@ -183,8 +212,8 @@ namespace FirstPlugin.LuigisMansion.DarkMoon vert.pos = new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); vert.pos = Vector3.TransformPosition(vert.pos, Transform); - - reader.BaseStream.Position += 0x4; + Console.WriteLine("F32_32 unk 1 " + reader.ReadUInt16()); + Console.WriteLine("F32_32 unk 2 " + reader.ReadUInt16()); vert.uv0 = NormalizeUvCoordsToFloat(reader.ReadUInt16(), reader.ReadUInt16()); } break; @@ -197,13 +226,19 @@ namespace FirstPlugin.LuigisMansion.DarkMoon } } - public static Vector2 NormalizeUvCoordsToFloat(ushort inU, ushort inV) + private static Vector4 Set_10_10_10_2_UNorm(uint value) { - //Normalize U coordinate - float U = (float)inU / (float)1024; - //Normalize V coordinate - float V = (float)inV / (float)1024; - return new Vector2(U, V); + return new Vector4( + (value & 0b00000000_00000000_00000011_11111111) / 1023f, + ((value & 0b00000000_00001111_11111100_00000000) >> 10) / 1023f, + ((value & 0b00111111_11110000_00000000_00000000) >> 20) / 1023f, + ((value & 0b11000000_00000000_00000000_00000000) >> 30) / 3f); + } + + + public static Vector2 NormalizeUvCoordsToFloat(ushort U, ushort V) + { + return new Vector2( U / 1024f, V / 1024f); } public static float UShortToFloatDecode(short input) @@ -239,6 +274,49 @@ namespace FirstPlugin.LuigisMansion.DarkMoon public void OnPropertyChanged() { } } + + public class DebugVisualBytes : TreeNodeFile, IContextMenuNode + { + public byte[] Data; + + public DebugVisualBytes(byte[] bytes) + { + Data = bytes; + } + + public override void OnClick(TreeView treeView) + { + HexEditor editor = (HexEditor)LibraryGUI.GetActiveContent(typeof(HexEditor)); + if (editor == null) + { + editor = new HexEditor(); + LibraryGUI.LoadEditor(editor); + } + editor.Text = Text; + editor.Dock = DockStyle.Fill; + editor.LoadData(Data); + } + + public ToolStripItem[] GetContextMenuItems() + { + List Items = new List(); + Items.Add(new STToolStipMenuItem("Export Raw Data", null, Export, Keys.Control | Keys.E)); + return Items.ToArray(); + } + + private void Export(object sender, EventArgs args) + { + SaveFileDialog sfd = new SaveFileDialog(); + sfd.FileName = Text; + sfd.Filter = "Raw Data (*.*)|*.*"; + + if (sfd.ShowDialog() == DialogResult.OK) + { + System.IO.File.WriteAllBytes(sfd.FileName, Data); + } + } + } + public class LM2_IndexList { public short[] UnknownIndices { get; set; } diff --git a/File_Format_Library/FileFormats/Archives/PACx30XL.cs b/File_Format_Library/FileFormats/Archives/PACx30XL.cs new file mode 100644 index 00000000..91a676aa --- /dev/null +++ b/File_Format_Library/FileFormats/Archives/PACx30XL.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Toolbox; +using System.Windows.Forms; +using Toolbox.Library; +using Toolbox.Library.IO; + +namespace FirstPlugin +{ + public class PACx30XL : IArchiveFile, IFileFormat + { + public FileType FileType { get; set; } = FileType.Archive; + + public bool CanSave { get; set; } + public string[] Description { get; set; } = new string[] { "Sonic Forces PAC" }; + public string[] Extension { get; set; } = new string[] { "*.pac" }; + public string FileName { get; set; } + public string FilePath { get; set; } + public IFileInfo IFileInfo { get; set; } + + public bool CanAddFiles { get; set; } + public bool CanRenameFiles { get; set; } + public bool CanReplaceFiles { get; set; } + public bool CanDeleteFiles { get; set; } + + public bool Identify(System.IO.Stream stream) + { + using (var reader = new Toolbox.Library.IO.FileReader(stream, true)) + { + return reader.CheckSignature(8, "PACx301L") || reader.CheckSignature(8, "PACx302L"); + } + } + + public Type[] Types + { + get + { + List types = new List(); + return types.ToArray(); + } + } + + public List files = new List(); + + public IEnumerable Files => files; + + public void ClearFiles() { files.Clear(); } + + public void Load(System.IO.Stream stream) + { + using (var reader = new FileReader(stream)) + { + reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian; + bool IsVersion2 = reader.CheckSignature(8, "PACx302L"); + + + + } + } + + public void Unload() + { + + } + + public byte[] Save() + { + return null; + } + + public bool AddFile(ArchiveFileInfo archiveFileInfo) + { + return false; + } + + public bool DeleteFile(ArchiveFileInfo archiveFileInfo) + { + return false; + } + + public class FileEntry : ArchiveFileInfo + { + public uint Unknown { get; set; } + + internal uint Size; + internal uint Offset; + internal uint NameOffset; + + public void Read(FileReader reader) + { + uint Unknown = reader.ReadUInt32(); + NameOffset = reader.ReadUInt32(); + Offset = reader.ReadUInt32(); + Size = reader.ReadUInt32(); + } + } + } +} diff --git a/File_Format_Library/File_Format_Library.csproj b/File_Format_Library/File_Format_Library.csproj index c40cf5c1..23d39627 100644 --- a/File_Format_Library/File_Format_Library.csproj +++ b/File_Format_Library/File_Format_Library.csproj @@ -213,6 +213,7 @@ + diff --git a/Switch_Toolbox_Library/Generics/GenericTexture.cs b/Switch_Toolbox_Library/Generics/GenericTexture.cs index 4b0bec9d..e6179ae6 100644 --- a/Switch_Toolbox_Library/Generics/GenericTexture.cs +++ b/Switch_Toolbox_Library/Generics/GenericTexture.cs @@ -444,9 +444,9 @@ namespace Toolbox.Library private Bitmap DecodeNotDirectXTex(byte[] data, uint Width, uint Height, TEX_FORMAT Format) { if (Format == TEX_FORMAT.R8G8B8A8_UNORM) - return BitmapExtension.GetBitmap(data, (int)Width, (int)Height); + return BitmapExtension.GetBitmap(ConvertBgraToRgba(data), (int)Width, (int)Height); else if (Format == TEX_FORMAT.R8G8B8A8_UNORM_SRGB) - return BitmapExtension.GetBitmap(data, (int)Width, (int)Height); + return BitmapExtension.GetBitmap(ConvertBgraToRgba(data), (int)Width, (int)Height); else if (Format == TEX_FORMAT.BC1_UNORM) return DDSCompressor.DecompressBC1(data, (int)Width, (int)Height, false); else if (Format == TEX_FORMAT.BC1_UNORM_SRGB)