mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-22 20:43:09 +00:00
Improve zlib support. Add NXARC
This commit is contained in:
parent
b759a293fe
commit
ffdb042c3f
13 changed files with 149 additions and 11 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -132,9 +132,9 @@ namespace FirstPlugin
|
|||
{
|
||||
uint decompSize = reader.ReadUInt32();
|
||||
uint compSize = (uint)reader.BaseStream.Length;
|
||||
compSize -= 16;
|
||||
compSize -= 10;
|
||||
|
||||
byte[] filedata = reader.getSection(16, (int)compSize);
|
||||
byte[] filedata = reader.getSection(10, (int)compSize);
|
||||
reader.Close();
|
||||
reader.Dispose();
|
||||
|
||||
|
|
136
Switch_FileFormatsMain/FileFormats/Archives/NXARC.cs
Normal file
136
Switch_FileFormatsMain/FileFormats/Archives/NXARC.cs
Normal file
|
@ -0,0 +1,136 @@
|
|||
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 NXARC : IArchiveFile, IFileFormat
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Layout;
|
||||
|
||||
public bool CanSave { get; set; }
|
||||
public string[] Description { get; set; } = new string[] { "NX Archive" };
|
||||
public string[] Extension { get; set; } = new string[] { "*.nxarc" };
|
||||
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.CheckSignature(4, "RAXN");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
reader.ReadSignature(4, "RAXN");
|
||||
uint unk = reader.ReadUInt32();
|
||||
char[] Type = reader.ReadChars(4);
|
||||
uint OffsetBlock = reader.ReadUInt32();
|
||||
uint HeaderSize = reader.ReadUInt32();
|
||||
uint FileCount = reader.ReadUInt32();
|
||||
uint BlockSize = reader.ReadUInt32();
|
||||
|
||||
List<string> FileNames = new List<string>();
|
||||
reader.Seek(OffsetBlock, System.IO.SeekOrigin.Begin);
|
||||
for (int i = 0; i < FileCount; i++)
|
||||
{
|
||||
FileNames.Add(reader.ReadZeroTerminatedString());
|
||||
}
|
||||
|
||||
reader.Seek(HeaderSize, System.IO.SeekOrigin.Begin);
|
||||
for (int i = 0; i < FileCount; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
//Skip string table
|
||||
reader.Seek(32);
|
||||
}
|
||||
else
|
||||
{
|
||||
var file = new FileEntry();
|
||||
file.FileName = FileNames[i];
|
||||
file.Read(reader);
|
||||
files.Add(file);
|
||||
}
|
||||
}
|
||||
|
||||
reader.Seek(HeaderSize, System.IO.SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
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 void Read(FileReader reader)
|
||||
{
|
||||
ulong Size = reader.ReadUInt64();
|
||||
ulong Offset = reader.ReadUInt64();
|
||||
ulong Flag = reader.ReadUInt64();
|
||||
ulong Unknown = reader.ReadUInt64();
|
||||
|
||||
using (reader.TemporarySeek((long)Offset, System.IO.SeekOrigin.Begin))
|
||||
{
|
||||
FileData = reader.ReadBytes((int)Size);
|
||||
if (Flag == 1)
|
||||
{
|
||||
FileData = STLibraryCompression.ZLIB.Decompress(FileData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(FileWriter writer)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -293,6 +293,7 @@ namespace FirstPlugin
|
|||
// Formats.Add(typeof(SDF));
|
||||
Formats.Add(typeof(TMPK));
|
||||
Formats.Add(typeof(TEX3DS));
|
||||
Formats.Add(typeof(NXARC));
|
||||
|
||||
Formats.Add(typeof(Turbo.Course_MapCamera_bin));
|
||||
Formats.Add(typeof(Turbo.PartsBIN));
|
||||
|
|
|
@ -191,6 +191,7 @@
|
|||
<Compile Include="Config.cs" />
|
||||
<Compile Include="FileFormats\AAMP\AAMP.cs" />
|
||||
<Compile Include="FileFormats\Archives\APAK.cs" />
|
||||
<Compile Include="FileFormats\Archives\NXARC.cs" />
|
||||
<Compile Include="FileFormats\Archives\RARC.cs" />
|
||||
<Compile Include="FileFormats\Archives\TMPK.cs" />
|
||||
<Compile Include="FileFormats\Audio\Archives\BARS.cs" />
|
||||
|
|
Binary file not shown.
|
@ -1 +1 @@
|
|||
b3fd6195e956ad1a3ce80bfdafc7f0f462fb99cc
|
||||
f3116c416a062081738ca7e7aee034e76dab7162
|
||||
|
|
Binary file not shown.
|
@ -9,7 +9,7 @@ namespace Switch_Toolbox.Library.Animations
|
|||
{
|
||||
SEAnim seAnim = new SEAnim();
|
||||
seAnim.Looping = anim.CanLoop;
|
||||
|
||||
seAnim.AnimType = AnimationType.Absolute;
|
||||
//Reset active animation to 0
|
||||
anim.SetFrame(0);
|
||||
for (int frame = 0; frame < anim.FrameCount; frame++)
|
||||
|
|
|
@ -70,13 +70,13 @@ namespace Switch_Toolbox.Library.IO
|
|||
{
|
||||
public static byte[] Decompress(byte[] b)
|
||||
{
|
||||
var output = new MemoryStream();
|
||||
using (var compressedStream = new MemoryStream(b)) {
|
||||
using (var zipStream = new DeflateStream(compressedStream, CompressionMode.Decompress))
|
||||
{
|
||||
zipStream.CopyTo(output);
|
||||
return output.ToArray();
|
||||
}
|
||||
using (var br = new FileReader(new MemoryStream(b), true))
|
||||
{
|
||||
var ms = new System.IO.MemoryStream();
|
||||
br.BaseStream.Position = 2;
|
||||
using (var ds = new DeflateStream(new MemoryStream(br.ReadBytes((int)br.BaseStream.Length - 6)), CompressionMode.Decompress))
|
||||
ds.CopyTo(ms);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue