Improve gx2 swizzling
This commit is contained in:
parent
17011aff7c
commit
9b69f7bcad
Binary file not shown.
Binary file not shown.
Binary file not shown.
85
Switch_FileFormatsMain/FileFormats/Archives/ARC.cs
Normal file
85
Switch_FileFormatsMain/FileFormats/Archives/ARC.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Switch_Toolbox;
|
||||
using System.Windows.Forms;
|
||||
using Switch_Toolbox.Library;
|
||||
using Switch_Toolbox.Library.IO;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class ARC : IArchiveFile, IFileFormat
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Archive;
|
||||
|
||||
public bool CanSave { get; set; }
|
||||
public string[] Description { get; set; } = new string[] { "Mario Kart Arcade GP DX Layout Archive (PAC)" };
|
||||
public string[] Extension { get; set; } = new string[] { "*.arc" };
|
||||
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 Switch_Toolbox.Library.IO.FileReader(stream, true))
|
||||
{
|
||||
return reader.ReadInt64() == 0x000000000000;
|
||||
}
|
||||
}
|
||||
|
||||
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 Load(System.IO.Stream stream)
|
||||
{
|
||||
using (var reader = new FileReader(stream))
|
||||
{
|
||||
reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;
|
||||
long Identifier = reader.ReadInt64();
|
||||
ulong ChunkSection1 = reader.ReadUInt64();
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -88,6 +88,8 @@ namespace FirstPlugin
|
||||
for (int dir = 0; dir < DirectoryCount; dir++)
|
||||
Directories[dir] = new DirectoryEntry(this);
|
||||
|
||||
Console.WriteLine($"DirectoryCount {DirectoryCount}");
|
||||
|
||||
reader.SeekBegin(DirectoryOffset + pos);
|
||||
for (int dir = 0; dir < DirectoryCount; dir++)
|
||||
{
|
||||
@ -95,8 +97,7 @@ namespace FirstPlugin
|
||||
uint NamePointer = StringTablOffset + Directories[dir].NameOffset;
|
||||
Directories[dir].Name = ReadStringAtTable(reader, NamePointer);
|
||||
|
||||
Console.WriteLine($"------------------------------------------");
|
||||
Console.WriteLine($"Directories Entry { Directories[dir].Name}");
|
||||
Console.WriteLine($"DirectoryCount {DirectoryCount}");
|
||||
|
||||
long EndDirectoryPos = reader.Position;
|
||||
for (int n = 0; n < Directories[dir].NodeCount; n++)
|
||||
@ -107,16 +108,14 @@ namespace FirstPlugin
|
||||
NamePointer = StringTablOffset + entry.NameOffset;
|
||||
entry.Name = ReadStringAtTable(reader, NamePointer);
|
||||
|
||||
Console.WriteLine($"Node Entry {entry.Name}");
|
||||
Console.WriteLine($"Node Offset {entry.Offset}");
|
||||
Console.WriteLine($"Node FileId {entry.FileId}");
|
||||
|
||||
if (entry.FileId != 0xFFFF)
|
||||
{
|
||||
using (reader.TemporarySeek(pos + DataOffset + entry.Offset, System.IO.SeekOrigin.Begin))
|
||||
{
|
||||
entry.FileData = reader.ReadBytes((int)entry.Size);
|
||||
}
|
||||
entry.FileName = entry.Name;
|
||||
|
||||
Directories[dir].AddNode(entry);
|
||||
}
|
||||
else
|
||||
|
@ -197,6 +197,7 @@
|
||||
<Compile Include="Config.cs" />
|
||||
<Compile Include="FileFormats\AAMP\AAMP.cs" />
|
||||
<Compile Include="FileFormats\Archives\APAK.cs" />
|
||||
<Compile Include="FileFormats\Archives\ARC.cs" />
|
||||
<Compile Include="FileFormats\Archives\IGA_PAK.cs" />
|
||||
<Compile Include="FileFormats\Archives\LZARC.cs" />
|
||||
<Compile Include="FileFormats\Archives\MKGPDX_PAC.cs" />
|
||||
|
@ -73,7 +73,7 @@ namespace FirstPlugin
|
||||
writer.WriteLine($"{paramObj.HashString} : !obj".Indent(IndentAmount));
|
||||
foreach (var entry in paramObj.paramEntries)
|
||||
{
|
||||
writer.WriteLine($"{WriteParamData(entry)}".Indent(IndentAmount + 2));
|
||||
writer.WriteLine($"{entry.HashString}: {WriteParamData(entry)}".Indent(IndentAmount + 2));
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,31 +81,49 @@ namespace FirstPlugin
|
||||
{
|
||||
switch (entry.ParamType)
|
||||
{
|
||||
case Aampv1.ParamType.Boolean: return $"{entry.HashString}: {(bool)entry.Value}";
|
||||
case Aampv1.ParamType.BufferBinary: return $"{entry.HashString}: !BufferBinary [ {WriteBytes((byte[])entry.Value)} ]";
|
||||
case Aampv1.ParamType.BufferFloat: return $"{entry.HashString}: !BufferFloat [ {WriteFloats((float[])entry.Value)} ]";
|
||||
case Aampv1.ParamType.BufferInt: return $"{entry.HashString}: !BufferInt [ {WriteInts((int[])entry.Value)} ]";
|
||||
case Aampv1.ParamType.BufferUint: return $"{entry.HashString}: !BufferUint [ {WriteUints((uint[])entry.Value)} ]";
|
||||
case Aampv1.ParamType.Color4F: return $"{entry.HashString}: {WriteColor4F((Vector4F)entry.Value)}";
|
||||
case Aampv1.ParamType.Vector2F: return $"{entry.HashString}: {WriteVec2F((Vector2F)entry.Value)}";
|
||||
case Aampv1.ParamType.Vector3F: return $"{entry.HashString}: {WriteVec3F((Vector3F)entry.Value)}";
|
||||
case Aampv1.ParamType.Vector4F: return $"{entry.HashString}: {WriteVec4F((Vector4F)entry.Value)}";
|
||||
case Aampv1.ParamType.Uint: return $"{entry.HashString}: {(uint)entry.Value}";
|
||||
case Aampv1.ParamType.Int: return $"{entry.HashString}: {(int)entry.Value}";
|
||||
case Aampv1.ParamType.Float: return $"{entry.HashString}: {(float)entry.Value}";
|
||||
case Aampv1.ParamType.String256: return $"{entry.HashString}: !str256 {((AampCommon.StringEntry)entry.Value).ToString()}";
|
||||
case Aampv1.ParamType.String32: return $"{entry.HashString}: !str32 {((AampCommon.StringEntry)entry.Value).ToString()}";
|
||||
case Aampv1.ParamType.String64: return $"{entry.HashString}: !str64 {((AampCommon.StringEntry)entry.Value).ToString()}";
|
||||
case Aampv1.ParamType.StringRef: return $"{entry.HashString}: !strRef {((AampCommon.StringEntry)entry.Value).ToString()}";
|
||||
case Aampv1.ParamType.Curve1: return $"{entry.HashString}: {WriteCurve((Aampv1.Curve[])entry.Value, 1)}";
|
||||
case Aampv1.ParamType.Curve2: return $"{entry.HashString}: {WriteCurve((Aampv1.Curve[])entry.Value, 2)}";
|
||||
case Aampv1.ParamType.Curve3: return $"{entry.HashString}: {WriteCurve((Aampv1.Curve[])entry.Value, 3)}";
|
||||
case Aampv1.ParamType.Curve4: return $"{entry.HashString}: {WriteCurve((Aampv1.Curve[])entry.Value, 4)}";
|
||||
case Aampv1.ParamType.Boolean: return $"{(bool)entry.Value}";
|
||||
case Aampv1.ParamType.BufferBinary: return $"!BufferBinary [ {WriteBytes((byte[])entry.Value)} ]";
|
||||
case Aampv1.ParamType.BufferFloat: return $"!BufferFloat [ {WriteFloats((float[])entry.Value)} ]";
|
||||
case Aampv1.ParamType.BufferInt: return $"BufferInt [ {WriteInts((int[])entry.Value)} ]";
|
||||
case Aampv1.ParamType.BufferUint: return $"!BufferUint [ {WriteUints((uint[])entry.Value)} ]";
|
||||
case Aampv1.ParamType.Color4F: return $"{WriteColor4F((Vector4F)entry.Value)}";
|
||||
case Aampv1.ParamType.Vector2F: return $"{WriteVec2F((Vector2F)entry.Value)}";
|
||||
case Aampv1.ParamType.Vector3F: return $"{WriteVec3F((Vector3F)entry.Value)}";
|
||||
case Aampv1.ParamType.Vector4F: return $"{WriteVec4F((Vector4F)entry.Value)}";
|
||||
case Aampv1.ParamType.Uint: return $"{(uint)entry.Value}";
|
||||
case Aampv1.ParamType.Int: return $"{(int)entry.Value}";
|
||||
case Aampv1.ParamType.Float: return $"{(float)entry.Value}";
|
||||
case Aampv1.ParamType.String256: return $"!str256 {WriteStringEntry((AampCommon.StringEntry)entry.Value)}";
|
||||
case Aampv1.ParamType.String32: return $"!str32 {WriteStringEntry((AampCommon.StringEntry)entry.Value)}";
|
||||
case Aampv1.ParamType.String64: return $"!str64 {WriteStringEntry((AampCommon.StringEntry)entry.Value)}";
|
||||
case Aampv1.ParamType.StringRef: return $"!strRef {WriteStringEntry((AampCommon.StringEntry)entry.Value)}";
|
||||
case Aampv1.ParamType.Curve1: return $"{WriteCurve((Aampv1.Curve[])entry.Value, 1)}";
|
||||
case Aampv1.ParamType.Curve2: return $"{WriteCurve((Aampv1.Curve[])entry.Value, 2)}";
|
||||
case Aampv1.ParamType.Curve3: return $"{WriteCurve((Aampv1.Curve[])entry.Value, 3)}";
|
||||
case Aampv1.ParamType.Curve4: return $"{WriteCurve((Aampv1.Curve[])entry.Value, 4)}";
|
||||
default:
|
||||
throw new Exception("Unsupported type! " + entry.ParamType);
|
||||
}
|
||||
}
|
||||
|
||||
private static string WriteStringEntry(AampCommon.StringEntry value)
|
||||
{
|
||||
return BytesToStringConverted(value.Data).Replace(" ", string.Empty);
|
||||
// return Encoding.Default.GetString(value.Data).Replace(" ", string.Empty);
|
||||
}
|
||||
|
||||
static string BytesToStringConverted(byte[] bytes)
|
||||
{
|
||||
using (var stream = new MemoryStream(bytes))
|
||||
{
|
||||
using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream))
|
||||
{
|
||||
return reader.ReadZeroTerminatedString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static string WriteCurve(Aampv1.Curve[] curves, int Num)
|
||||
{
|
||||
string curveStr = "";
|
||||
|
Binary file not shown.
Binary file not shown.
@ -2,7 +2,7 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Switch_Toolbox.Library
|
||||
namespace Switch_Toolbox.Library.Old
|
||||
{
|
||||
public class GX2
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Switch_Toolbox.Library.NEW
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
//Todo fix swizzle issues with this one
|
||||
public class GX2
|
||||
@ -685,12 +685,11 @@ namespace Switch_Toolbox.Library.NEW
|
||||
|
||||
mipOffset = (tex.mipOffset[mipLevel - 1]);
|
||||
if (mipLevel == 1)
|
||||
mipOffset -= (uint)surfInfo.surfSize;
|
||||
mipOffset -= (uint)surfInfo.sliceSize;
|
||||
|
||||
surfInfo = getSurfaceInfo((GX2SurfaceFormat)tex.format, tex.width, tex.height, tex.depth, (uint)tex.dim, (uint)tex.tileMode, (uint)tex.aa, mipLevel);
|
||||
data = new byte[surfInfo.surfSize];
|
||||
|
||||
Array.Copy(tex.mipData, (uint)mipOffset, data, 0, surfInfo.surfSize);
|
||||
data = new byte[surfInfo.sliceSize];
|
||||
Array.Copy(tex.mipData, (uint)mipDataOffset + mipOffset, data, 0, surfInfo.sliceSize);
|
||||
}
|
||||
else
|
||||
Array.Copy(tex.data, (uint)dataOffset, data, 0, size);
|
||||
@ -705,8 +704,8 @@ namespace Switch_Toolbox.Library.NEW
|
||||
|
||||
result.Add(mips);
|
||||
|
||||
// dataOffset += ArrayImageize;
|
||||
// mipDataOffset += ArrayMipImageize;
|
||||
dataOffset += ArrayImageize;
|
||||
mipDataOffset += ArrayMipImageize;
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -779,7 +778,7 @@ namespace Switch_Toolbox.Library.NEW
|
||||
|
||||
if (depth > 1)
|
||||
{
|
||||
bankSwizzle = (uint)(slice % 4);
|
||||
// bankSwizzle = (uint)(slice % 4);
|
||||
}
|
||||
|
||||
tileMode = GX2TileModeToAddrTileMode(tileMode);
|
||||
@ -952,7 +951,7 @@ namespace Switch_Toolbox.Library.NEW
|
||||
|
||||
uint thickness = computeSurfaceThickness(tileMode);
|
||||
|
||||
if (IsDepth)
|
||||
if (IsDepth)
|
||||
{
|
||||
pixelBit0 = x & 1;
|
||||
pixelBit1 = y & 1;
|
||||
|
Loading…
Reference in New Issue
Block a user