rgba8 channel fix for non direct x tex

This commit is contained in:
KillzXGaming 2019-07-22 18:26:23 -04:00
parent 2dbee751b2
commit 667ec7c752
5 changed files with 203 additions and 23 deletions

Binary file not shown.

View file

@ -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<ToolStripItem> Items = new List<ToolStripItem>();
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; }

View file

@ -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<Type> types = new List<Type>();
return types.ToArray();
}
}
public List<FileEntry> files = new List<FileEntry>();
public IEnumerable<ArchiveFileInfo> 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();
}
}
}
}

View file

@ -213,6 +213,7 @@
<Compile Include="FileFormats\Archives\ME01.cs" />
<Compile Include="FileFormats\Archives\MKGPDX_PAC.cs" />
<Compile Include="FileFormats\Archives\NXARC.cs" />
<Compile Include="FileFormats\Archives\PACx30XL.cs" />
<Compile Include="FileFormats\Archives\RARC.cs" />
<Compile Include="FileFormats\Archives\SARC_OLD.cs" />
<Compile Include="FileFormats\Archives\Sonic Racing\GameDataToc.cs" />

View file

@ -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)