mirror of
https://github.com/kwsch/pk3DS.git
synced 2026-10-02 13:57:14 -05:00
Minor tweaks r2
No functional change, just a little more explicit / exposed for the CTR namespace classes take faster unpackMini from PKHeX's optimized version
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace CTR
|
||||
{
|
||||
class BCLIM
|
||||
public static class BCLIM
|
||||
{
|
||||
internal static void openFile(string path, bool autosave = false, bool crop = true, char format = 'X')
|
||||
{
|
||||
@@ -548,7 +548,7 @@ internal static int getColorCount(Bitmap img)
|
||||
}
|
||||
|
||||
|
||||
internal static int[] Convert5To8 = { 0x00,0x08,0x10,0x18,0x20,0x29,0x31,0x39,
|
||||
internal static readonly int[] Convert5To8 = { 0x00,0x08,0x10,0x18,0x20,0x29,0x31,0x39,
|
||||
0x41,0x4A,0x52,0x5A,0x62,0x6A,0x73,0x7B,
|
||||
0x83,0x8B,0x94,0x9C,0xA4,0xAC,0xB4,0xBD,
|
||||
0xC5,0xCD,0xD5,0xDE,0xE6,0xEE,0xF6,0xFF };
|
||||
|
||||
@@ -28,11 +28,6 @@ namespace CTR
|
||||
{
|
||||
public class BLZCoder
|
||||
{
|
||||
public static void main(string[] args)
|
||||
{
|
||||
new BLZCoder(args);
|
||||
}
|
||||
|
||||
private const int CMD_DECODE = 0;
|
||||
private const int CMD_ENCODE = 1;
|
||||
|
||||
@@ -43,15 +38,12 @@ public static void main(string[] args)
|
||||
private const int BLZ_THRESHOLD = 2;
|
||||
private const int BLZ_N = 0x1002;
|
||||
private const int BLZ_F = 0x12;
|
||||
|
||||
private const int BLZ_MAXIM = 0x01400000;
|
||||
private const int RAW_MAXIM = 0x00FFFFFF;
|
||||
readonly bool arm9;
|
||||
int new_len;
|
||||
static void EXIT(string text)
|
||||
{
|
||||
Console.Write(text);
|
||||
}
|
||||
|
||||
private readonly bool arm9;
|
||||
private int new_len;
|
||||
|
||||
private readonly ProgressBar pBar1;
|
||||
private void initpBar(int max)
|
||||
{
|
||||
@@ -65,6 +57,7 @@ private void setpBarPos(int pos)
|
||||
pBar1.Invoke((MethodInvoker)delegate { pBar1.Value = pos; });
|
||||
else { pBar1.Value = pos; }
|
||||
}
|
||||
|
||||
public BLZCoder(string[] args, ProgressBar pBar = null)
|
||||
{
|
||||
int cmd, mode = 0;
|
||||
@@ -112,7 +105,7 @@ public BLZCoder(string[] args, ProgressBar pBar = null)
|
||||
|
||||
Console.Write(Environment.NewLine + "Done" + Environment.NewLine);
|
||||
}
|
||||
private void Save(string filename, byte[] buffer, int length)
|
||||
private static void Save(string filename, byte[] buffer, int length)
|
||||
{
|
||||
Array.Resize(ref buffer, length);
|
||||
try
|
||||
@@ -124,7 +117,7 @@ private void Save(string filename, byte[] buffer, int length)
|
||||
Console.Write(Environment.NewLine + "Wrote to 'blz.bin' instead." + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
private void BLZ_Decode(string filename)
|
||||
private static void BLZ_Decode(string filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -141,7 +134,7 @@ private void BLZ_Decode(string filename)
|
||||
catch (IOException e)
|
||||
{ Console.Write(Environment.NewLine + "File read error" + Environment.NewLine + e); }
|
||||
}
|
||||
private BLZResult BLZ_Decode(byte[] data)
|
||||
private static BLZResult BLZ_Decode(byte[] data)
|
||||
{
|
||||
int raw_len, len;
|
||||
int enc_len, dec_len;
|
||||
@@ -270,7 +263,7 @@ private BLZResult BLZ_Encode(byte[] data, int mode)
|
||||
}
|
||||
return new BLZResult(pak_buffer, pak_len);
|
||||
}
|
||||
private byte[] prepareData(byte[] data)
|
||||
private static byte[] prepareData(byte[] data)
|
||||
{
|
||||
int fs = data.Length;
|
||||
byte[] fb = new byte[fs + 3];
|
||||
@@ -279,7 +272,7 @@ private byte[] prepareData(byte[] data)
|
||||
|
||||
return fb;
|
||||
}
|
||||
private void writeUnsigned(byte[] buffer, int offset, int value)
|
||||
private static void writeUnsigned(byte[] buffer, int offset, int value)
|
||||
{
|
||||
buffer[offset] = (byte)(value & 0xFF);
|
||||
buffer[offset + 1] = (byte)((value >> 8) & 0xFF);
|
||||
@@ -386,11 +379,11 @@ private byte[] BLZ_Code(byte[] raw_buffer, int raw_len, int best)
|
||||
else
|
||||
pak_buffer[pak++] = raw_buffer[raw++];
|
||||
|
||||
if (pak + raw_len - raw < pak_tmp + raw_tmp)
|
||||
{
|
||||
pak_tmp = pak;
|
||||
raw_tmp = raw_len - raw;
|
||||
}
|
||||
if (pak + raw_len - raw >= pak_tmp + raw_tmp)
|
||||
continue;
|
||||
|
||||
pak_tmp = pak;
|
||||
raw_tmp = raw_len - raw;
|
||||
}
|
||||
|
||||
while ((mask > 0) && (mask != 1))
|
||||
@@ -411,7 +404,7 @@ private byte[] BLZ_Code(byte[] raw_buffer, int raw_len, int best)
|
||||
raw_end = raw_len;
|
||||
|
||||
while (raw < raw_end)
|
||||
pak_buffer[pak] = raw_buffer[raw];
|
||||
pak_buffer[pak++] = raw_buffer[raw++];
|
||||
|
||||
while ((pak & 3) > 0)
|
||||
pak_buffer[pak++] = 0;
|
||||
@@ -431,10 +424,8 @@ private byte[] BLZ_Code(byte[] raw_buffer, int raw_len, int best)
|
||||
|
||||
for (len = 0; len < pak_tmp; len++)
|
||||
tmp[raw_tmp + len] = pak_buffer[len + pak_len - pak_tmp];
|
||||
|
||||
pak = 0;
|
||||
|
||||
pak_buffer = tmp;
|
||||
|
||||
pak = raw_tmp + pak_tmp;
|
||||
|
||||
int enc_len = pak_tmp;
|
||||
@@ -468,7 +459,7 @@ public SearchPair(int l, int p)
|
||||
this.p = p;
|
||||
}
|
||||
}
|
||||
private SearchPair SEARCH(int p, IList<byte> raw_buffer, int raw, int raw_end)
|
||||
private static SearchPair SEARCH(int p, IList<byte> raw_buffer, int raw, int raw_end)
|
||||
{
|
||||
int l = BLZ_THRESHOLD;
|
||||
int max = raw >= BLZ_N ? BLZ_N : raw;
|
||||
@@ -506,7 +497,7 @@ public BLZResult(byte[] raw_buffer, int raw_len)
|
||||
public readonly byte[] buffer;
|
||||
public readonly int length;
|
||||
}
|
||||
private void BLZ_Invert(byte[] buffer, int offset, int length)
|
||||
private static void BLZ_Invert(byte[] buffer, int offset, int length)
|
||||
{
|
||||
int bottom = offset + length - 1;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace CTR
|
||||
{
|
||||
class CRO
|
||||
internal class CRO
|
||||
{
|
||||
// Utility
|
||||
internal static void updateTB(RichTextBox RTB, string progress)
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace CTR
|
||||
{
|
||||
public class CTR
|
||||
{
|
||||
internal static uint MEDIA_UNIT_SIZE = 0x200;
|
||||
internal const uint MEDIA_UNIT_SIZE = 0x200;
|
||||
|
||||
// Main wrapper that assembles the ROM based on the following specifications:
|
||||
internal static bool buildROM(bool Card2, string LOGO_NAME,
|
||||
|
||||
@@ -58,8 +58,8 @@ public DARCHeader(BinaryReader br = null)
|
||||
FileDataOffset = br.ReadUInt32();
|
||||
}
|
||||
public string Signature;
|
||||
public UInt16 Endianness;
|
||||
public UInt16 HeaderSize;
|
||||
public ushort Endianness;
|
||||
public ushort HeaderSize;
|
||||
public uint Version;
|
||||
public uint FileSize;
|
||||
public uint FileTableOffset;
|
||||
@@ -78,7 +78,7 @@ public FileTableEntry(BinaryReader br = null)
|
||||
DataLength = br.ReadUInt32();
|
||||
}
|
||||
public uint NameOffset;
|
||||
public Boolean IsFolder;
|
||||
public bool IsFolder;
|
||||
public uint DataOffset; // FOLDER: Parent Entry Index
|
||||
public uint DataLength; // FOLDER: Next Folder Index
|
||||
}
|
||||
@@ -156,7 +156,7 @@ internal static DARC getDARC(string folderName)
|
||||
EntryList.Add(new FileTableEntry
|
||||
{
|
||||
DataOffset = 1,
|
||||
DataLength = (uint) (files.Count() + EntryList.Count),
|
||||
DataLength = (uint) (files.Length + EntryList.Count),
|
||||
IsFolder = true,
|
||||
NameOffset = nameOffset
|
||||
});
|
||||
@@ -346,7 +346,7 @@ internal static bool insertFile(ref DARC orig, int index, byte[] data)
|
||||
}
|
||||
internal static DARC insertFiles(DARC orig, string folderName)
|
||||
{
|
||||
string[] fileNames = new string[orig.Entries.Count()];
|
||||
string[] fileNames = new string[orig.Entries.Length];
|
||||
for (int i = 0; i < fileNames.Length; i++)
|
||||
fileNames[i] = orig.FileNameTable[i].FileName;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace CTR
|
||||
{
|
||||
class ETC1
|
||||
internal static class ETC1
|
||||
{
|
||||
[DllImport("ETC1Lib.dll", EntryPoint = "ConvertETC1", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void ConvertETC1(IntPtr dataOut, ref uint dataOutSize, IntPtr dataIn, UInt16 width, UInt16 height, bool alpha);
|
||||
|
||||
@@ -9,9 +9,9 @@ namespace CTR
|
||||
{
|
||||
public class Exheader
|
||||
{
|
||||
public byte[] Data;
|
||||
public byte[] AccessDescriptor;
|
||||
public ulong TitleID;
|
||||
public readonly byte[] Data;
|
||||
public readonly byte[] AccessDescriptor;
|
||||
public readonly ulong TitleID;
|
||||
|
||||
public Exheader(string EXHEADER_PATH)
|
||||
{
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
|
||||
namespace CTR
|
||||
{
|
||||
internal class FileFormat
|
||||
internal static class FileFormat
|
||||
{
|
||||
internal static string defaultExtension = "bin";
|
||||
internal static string[] validEXT = {"BCH",};
|
||||
internal const string defaultExtension = "bin";
|
||||
internal static readonly string[] validEXT = {"BCH",};
|
||||
|
||||
internal static string Guess(string path)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
namespace CTR
|
||||
{
|
||||
// LZSS (de)compression, heavily taken from dsdecmp
|
||||
public class LZSS
|
||||
public static class LZSS
|
||||
{
|
||||
internal static long Decompress(string infile, string outfile)
|
||||
{
|
||||
@@ -269,7 +269,7 @@ internal static int Compress(string infile, string outfile)
|
||||
/// This algorithm should yield files that are the same as those found in the games.
|
||||
/// (delegates to the optimized method if LookAhead is set)
|
||||
/// </summary>
|
||||
internal unsafe static int Compress(Stream instream, long inLength, Stream outstream, bool original)
|
||||
internal static unsafe int Compress(Stream instream, long inLength, Stream outstream, bool original)
|
||||
{
|
||||
// make sure the decompressed size fits in 3 bytes.
|
||||
// There should be room for four bytes, however I'm not 100% sure if that can be used
|
||||
@@ -396,7 +396,7 @@ internal unsafe static int Compress(Stream instream, long inLength, Stream outst
|
||||
/// and determine the optimal 'length' values for the compressed blocks. Is not 100% optimal,
|
||||
/// as the flag-bytes are not taken into account.
|
||||
/// </summary>
|
||||
internal unsafe static int CompressWithLA(Stream instream, long inLength, Stream outstream)
|
||||
internal static unsafe int CompressWithLA(Stream instream, long inLength, Stream outstream)
|
||||
{
|
||||
// save the input data in an array to prevent having to go back and forth in a file
|
||||
byte[] indata = new byte[inLength];
|
||||
@@ -514,7 +514,7 @@ internal unsafe static int CompressWithLA(Stream instream, long inLength, Stream
|
||||
/// this value is the optimal 'length' value. If it is 1, the block should not be compressed.</param>
|
||||
/// <param name="disps">The 'disp' values of the compressed blocks. May be 0, in which case the
|
||||
/// corresponding length will never be anything other than 1.</param>
|
||||
internal unsafe static void GetOptimalCompressionLengths(byte* indata, int inLength, out int[] lengths, out int[] disps)
|
||||
internal static unsafe void GetOptimalCompressionLengths(byte* indata, int inLength, out int[] lengths, out int[] disps)
|
||||
{
|
||||
lengths = new int[inLength];
|
||||
disps = new int[inLength];
|
||||
@@ -586,16 +586,15 @@ public InputTooLargeException()
|
||||
/// </summary>
|
||||
public class NotEnoughDataException : IOException
|
||||
{
|
||||
private readonly long currentOutSize;
|
||||
private readonly long totalOutSize;
|
||||
/// <summary>
|
||||
/// Gets the actual number of written bytes.
|
||||
/// </summary>
|
||||
public long WrittenLength { get { return currentOutSize; } }
|
||||
public long WrittenLength { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of bytes that was supposed to be written.
|
||||
/// </summary>
|
||||
public long DesiredLength { get { return totalOutSize; } }
|
||||
public long DesiredLength { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new NotEnoughDataException.
|
||||
@@ -607,8 +606,8 @@ public NotEnoughDataException(long currentOutSize, long totalOutSize)
|
||||
+ " of " + (totalOutSize < 0 ? "???" : "0x" + totalOutSize.ToString("X"))
|
||||
+ " bytes written.")
|
||||
{
|
||||
this.currentOutSize = currentOutSize;
|
||||
this.totalOutSize = totalOutSize;
|
||||
WrittenLength = currentOutSize;
|
||||
DesiredLength = totalOutSize;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
||||
@@ -10,10 +10,10 @@ namespace CTR
|
||||
public class RomFS
|
||||
{
|
||||
// Get Info
|
||||
public string FileName;
|
||||
public bool isTempFile;
|
||||
public byte[] SuperBlockHash;
|
||||
public uint SuperBlockLen;
|
||||
public readonly string FileName;
|
||||
public readonly bool isTempFile;
|
||||
public readonly byte[] SuperBlockHash;
|
||||
public readonly uint SuperBlockLen;
|
||||
|
||||
public RomFS(string fn)
|
||||
{
|
||||
@@ -166,7 +166,7 @@ internal static void MakeRomFSData(RomfsFile[] RomFiles, MemoryStream metadata,
|
||||
}
|
||||
}
|
||||
if (PB_Show.InvokeRequired)
|
||||
PB_Show.Invoke((MethodInvoker)delegate { PB_Show.PerformStep(); });
|
||||
PB_Show.Invoke((MethodInvoker)PB_Show.PerformStep);
|
||||
else { PB_Show.PerformStep(); }
|
||||
}
|
||||
long hashBaseOfs = (long)Align((ulong)OutFileStream.Position, ivfc.Levels[2].BlockSize);
|
||||
@@ -178,9 +178,10 @@ internal static void MakeRomFSData(RomfsFile[] RomFiles, MemoryStream metadata,
|
||||
updateTB(TB_Progress, "Computing Level " + i + " Hashes...");
|
||||
byte[] buffer = new byte[(int)ivfc.Levels[i].BlockSize];
|
||||
|
||||
var count = (int) (ivfc.Levels[i].DataLength/ivfc.Levels[i].BlockSize);
|
||||
if (PB_Show.InvokeRequired)
|
||||
PB_Show.Invoke((MethodInvoker)delegate { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = (int)(ivfc.Levels[i].DataLength / ivfc.Levels[i].BlockSize); });
|
||||
else { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = (int)(ivfc.Levels[i].DataLength / ivfc.Levels[i].BlockSize); }
|
||||
PB_Show.Invoke((MethodInvoker)delegate { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = count; });
|
||||
else { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = count; }
|
||||
|
||||
for (long ofs = 0; ofs < (long)ivfc.Levels[i].DataLength; ofs += ivfc.Levels[i].BlockSize)
|
||||
{
|
||||
@@ -192,9 +193,13 @@ internal static void MakeRomFSData(RomfsFile[] RomFiles, MemoryStream metadata,
|
||||
OutFileStream.Write(hash, 0, hash.Length);
|
||||
cOfs = OutFileStream.Position;
|
||||
if (PB_Show.InvokeRequired)
|
||||
PB_Show.Invoke((MethodInvoker)delegate { PB_Show.PerformStep(); });
|
||||
PB_Show.Invoke((MethodInvoker)PB_Show.PerformStep);
|
||||
else { PB_Show.PerformStep(); }
|
||||
}
|
||||
|
||||
if (i <= 0)
|
||||
continue;
|
||||
|
||||
if (i == 2)
|
||||
{
|
||||
long len = OutFileStream.Position;
|
||||
@@ -205,7 +210,7 @@ internal static void MakeRomFSData(RomfsFile[] RomFiles, MemoryStream metadata,
|
||||
OutFileStream.Write(buf, 0, buf.Length);
|
||||
}
|
||||
}
|
||||
if (i <= 0) continue;
|
||||
|
||||
hOfs = hashBaseOfs + (long)ivfc.Levels[i - 1].HashOffset;
|
||||
if (i > 1)
|
||||
cOfs = hashBaseOfs + (long)ivfc.Levels[i - 2].HashOffset;
|
||||
@@ -220,15 +225,13 @@ internal static void MakeRomFSData(RomfsFile[] RomFiles, MemoryStream metadata,
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (OutFileStream != null)
|
||||
OutFileStream.Dispose();
|
||||
}
|
||||
|
||||
if (OutFile != TempFile)
|
||||
{
|
||||
if (File.Exists(OutFile)) File.Delete(OutFile);
|
||||
File.Move(TempFile, OutFile);
|
||||
OutFileStream.Dispose();
|
||||
}
|
||||
|
||||
if (OutFile == TempFile)
|
||||
return;
|
||||
if (File.Exists(OutFile)) File.Delete(OutFile);
|
||||
File.Move(TempFile, OutFile);
|
||||
}
|
||||
internal static void WriteBinary(string tempFile, string outFile, RichTextBox TB_Progress = null, ProgressBar PB_Show = null)
|
||||
{
|
||||
@@ -239,10 +242,10 @@ internal static void WriteBinary(string tempFile, string outFile, RichTextBox TB
|
||||
using (FileStream fileStream = new FileStream(tempFile, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
const uint BUFFER_SIZE = 0x400000; // 4MB Buffer
|
||||
|
||||
var steps = (int)(fileStream.Length / BUFFER_SIZE);
|
||||
if (PB_Show.InvokeRequired)
|
||||
PB_Show.Invoke((MethodInvoker)delegate { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = (int)(fileStream.Length / BUFFER_SIZE); });
|
||||
else { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = (int)(fileStream.Length / BUFFER_SIZE); }
|
||||
PB_Show.Invoke((MethodInvoker)delegate { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = steps; });
|
||||
else { PB_Show.Minimum = 0; PB_Show.Step = 1; PB_Show.Value = 0; PB_Show.Maximum = steps; }
|
||||
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
while (true)
|
||||
@@ -252,7 +255,7 @@ internal static void WriteBinary(string tempFile, string outFile, RichTextBox TB
|
||||
{
|
||||
writer.Write(buffer, 0, count);
|
||||
if (PB_Show.InvokeRequired)
|
||||
PB_Show.Invoke((MethodInvoker)delegate { PB_Show.PerformStep(); });
|
||||
PB_Show.Invoke((MethodInvoker)PB_Show.PerformStep);
|
||||
else { PB_Show.PerformStep(); }
|
||||
}
|
||||
else
|
||||
@@ -281,15 +284,11 @@ internal static void UpdateTB_Progress(string text, RichTextBox TB_Progress = nu
|
||||
internal static void BuildRomFSHeader(MemoryStream romfs_stream, RomfsFile[] Entries, string DIR)
|
||||
{
|
||||
ROOT_DIR = DIR;
|
||||
|
||||
Romfs_MetaData MetaData = new Romfs_MetaData();
|
||||
|
||||
InitializeMetaData(MetaData);
|
||||
|
||||
CalcRomfsSize(MetaData);
|
||||
|
||||
PopulateRomfs(MetaData, Entries);
|
||||
|
||||
WriteMetaDataToStream(MetaData, romfs_stream);
|
||||
}
|
||||
internal static void InitializeMetaData(Romfs_MetaData MetaData)
|
||||
@@ -501,27 +500,28 @@ internal static void AddDir(Romfs_MetaData MetaData, DirectoryInfo Dir, uint par
|
||||
for (int i = 0; i < SubDirectories.Length; i++)
|
||||
{
|
||||
AddDir(MetaData, SubDirectories[i], CurrentDir, sibling, false);
|
||||
if (i > 0)
|
||||
{
|
||||
string PrevFullName = SubDirectories[i - 1].FullName;
|
||||
string ThisName = SubDirectories[i].FullName;
|
||||
int PrevIndex = GetRomfsDirEntry(MetaData, PrevFullName);
|
||||
int ThisIndex = GetRomfsDirEntry(MetaData, ThisName);
|
||||
MetaData.DirTable.DirectoryTable[PrevIndex].SiblingOffset =
|
||||
MetaData.DirTable.DirectoryTable[ThisIndex].Offset;
|
||||
}
|
||||
if (i <= 0)
|
||||
continue;
|
||||
|
||||
string PrevFullName = SubDirectories[i - 1].FullName;
|
||||
string ThisName = SubDirectories[i].FullName;
|
||||
int PrevIndex = GetRomfsDirEntry(MetaData, PrevFullName);
|
||||
int ThisIndex = GetRomfsDirEntry(MetaData, ThisName);
|
||||
MetaData.DirTable.DirectoryTable[PrevIndex].SiblingOffset =
|
||||
MetaData.DirTable.DirectoryTable[ThisIndex].Offset;
|
||||
}
|
||||
foreach (DirectoryInfo t in SubDirectories)
|
||||
AddDir(MetaData, t, CurrentDir, sibling, true);
|
||||
}
|
||||
if (SubDirectories.Length > 0)
|
||||
{
|
||||
int curindex = GetRomfsDirEntry(MetaData, Dir.FullName);
|
||||
int childindex = GetRomfsDirEntry(MetaData, SubDirectories[0].FullName);
|
||||
if (curindex > -1 && childindex > -1)
|
||||
MetaData.DirTable.DirectoryTable[curindex].ChildOffset =
|
||||
MetaData.DirTable.DirectoryTable[childindex].Offset;
|
||||
}
|
||||
|
||||
if (SubDirectories.Length <= 0)
|
||||
return;
|
||||
|
||||
int curindex = GetRomfsDirEntry(MetaData, Dir.FullName);
|
||||
int childindex = GetRomfsDirEntry(MetaData, SubDirectories[0].FullName);
|
||||
if (curindex > -1 && childindex > -1)
|
||||
MetaData.DirTable.DirectoryTable[curindex].ChildOffset =
|
||||
MetaData.DirTable.DirectoryTable[childindex].Offset;
|
||||
}
|
||||
internal static void AddFiles(Romfs_MetaData MetaData, RomfsFile[] Entries)
|
||||
{
|
||||
@@ -618,34 +618,25 @@ internal static void WriteMetaDataToStream(Romfs_MetaData MetaData, MemoryStream
|
||||
internal static int GetRomfsDirEntry(Romfs_MetaData MetaData, string FullName)
|
||||
{
|
||||
for (int i = 0; i < MetaData.DirTable.DirectoryTable.Count; i++)
|
||||
{
|
||||
if (MetaData.DirTable.DirectoryTable[i].FullName == FullName)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
internal static int GetRomfsDirEntry(Romfs_MetaData MetaData, uint Offset)
|
||||
{
|
||||
for (int i = 0; i < MetaData.DirTable.DirectoryTable.Count; i++)
|
||||
{
|
||||
if (MetaData.DirTable.DirectoryTable[i].Offset == Offset)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
internal static int GetRomfsFileEntry(Romfs_MetaData MetaData, uint Offset)
|
||||
{
|
||||
for (int i = 0; i < MetaData.FileTable.FileTable.Count; i++)
|
||||
{
|
||||
if (MetaData.FileTable.FileTable[i].Offset == Offset)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -733,15 +724,8 @@ public class IVFCLevel
|
||||
}
|
||||
public class FileNameTable
|
||||
{
|
||||
public List<FileInfo> NameEntryTable { get; private set; }
|
||||
|
||||
public int NumFiles
|
||||
{
|
||||
get
|
||||
{
|
||||
return NameEntryTable.Count;
|
||||
}
|
||||
}
|
||||
public List<FileInfo> NameEntryTable { get; }
|
||||
public int NumFiles => NameEntryTable.Count;
|
||||
|
||||
internal FileNameTable(string rootPath)
|
||||
{
|
||||
@@ -761,7 +745,7 @@ internal void AddDirectory(DirectoryInfo dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
public class LayoutManager
|
||||
public static class LayoutManager
|
||||
{
|
||||
public static Output[] Create(IEnumerable<Input> Input)
|
||||
{
|
||||
@@ -771,7 +755,7 @@ public static Output[] Create(IEnumerable<Input> Input)
|
||||
{
|
||||
Output output = new Output();
|
||||
FileInfo fileInfo = new FileInfo(input.FilePath);
|
||||
ulong ofs = Align(Len, input.AlignmentSize);
|
||||
ulong ofs = AlignInput(Len, input.AlignmentSize);
|
||||
output.FilePath = input.FilePath;
|
||||
output.Offset = ofs;
|
||||
output.Size = (ulong)fileInfo.Length;
|
||||
@@ -780,7 +764,7 @@ public static Output[] Create(IEnumerable<Input> Input)
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
public static ulong Align(ulong input, ulong alignsize)
|
||||
private static ulong AlignInput(ulong input, ulong alignsize)
|
||||
{
|
||||
ulong output = input;
|
||||
if (output % alignsize != 0)
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace CTR
|
||||
{
|
||||
// System Menu Data Header
|
||||
class SMDH
|
||||
public class SMDH
|
||||
{
|
||||
public uint Magic;
|
||||
public ushort Version;
|
||||
@@ -61,7 +60,7 @@ public byte[] Write()
|
||||
}
|
||||
|
||||
// Thanks to Gericom for EveryFileExplorer's SMDH.cs as a basis for the object code (and AppSettings enumeration)
|
||||
class ApplicationInfo
|
||||
public class ApplicationInfo
|
||||
{
|
||||
public string ShortDescription; //0x80
|
||||
public string LongDescription; //0x100
|
||||
@@ -80,17 +79,17 @@ public void Write(BinaryWriter bw)
|
||||
}
|
||||
}
|
||||
|
||||
class ApplicationSettings
|
||||
public class ApplicationSettings
|
||||
{
|
||||
public byte[] GameRatings; //0x10
|
||||
public RegionLockoutFlags RegionLockout;
|
||||
public uint MatchMakerID;
|
||||
public UInt64 MatchMakerBITID;
|
||||
public AppSettingsFlags Flags;
|
||||
public UInt16 EULAVersion;
|
||||
public UInt16 Reserved;
|
||||
public Single AnimationDefaultFrame;
|
||||
public uint StreetPassID;
|
||||
public readonly byte[] GameRatings; //0x10
|
||||
public readonly RegionLockoutFlags RegionLockout;
|
||||
public readonly uint MatchMakerID;
|
||||
public readonly ulong MatchMakerBITID;
|
||||
public readonly AppSettingsFlags Flags;
|
||||
public readonly ushort EULAVersion;
|
||||
public readonly ushort Reserved;
|
||||
public readonly float AnimationDefaultFrame;
|
||||
public readonly uint StreetPassID;
|
||||
|
||||
public enum RegionLockoutFlags : uint
|
||||
{
|
||||
@@ -141,7 +140,7 @@ public void Write(BinaryWriter bw)
|
||||
}
|
||||
}
|
||||
|
||||
class SmallIcon // 24x24
|
||||
public class SmallIcon // 24x24
|
||||
{
|
||||
public Bitmap Icon;
|
||||
public byte[] Bytes;
|
||||
@@ -163,7 +162,7 @@ public bool ChangeIcon(Bitmap img)
|
||||
}
|
||||
}
|
||||
|
||||
class LargeIcon // 48x48
|
||||
public class LargeIcon // 48x48
|
||||
{
|
||||
public Bitmap Icon;
|
||||
public byte[] Bytes;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
namespace CTR
|
||||
{
|
||||
// Mini Packing Util
|
||||
class mini
|
||||
internal static class mini
|
||||
{
|
||||
internal static byte[] adjustMiniHeader(byte[] data, int headerLength)
|
||||
{
|
||||
@@ -185,44 +185,27 @@ internal static void unpackMini(string path, string ident, string outFolder = nu
|
||||
if (delete)
|
||||
File.Delete(path); // File is unpacked.
|
||||
}
|
||||
internal static byte[][] unpackMini(byte[] fileData, string ident)
|
||||
public static byte[][] unpackMini(byte[] fileData, string identifier)
|
||||
{
|
||||
using (var s = new MemoryStream(fileData))
|
||||
using (var br = new BinaryReader(s))
|
||||
if (fileData == null || fileData.Length < 4)
|
||||
return null;
|
||||
|
||||
if (identifier[0] != fileData[0] || identifier[1] != fileData[1])
|
||||
return null;
|
||||
|
||||
int count = BitConverter.ToUInt16(fileData, 2); int ctr = 4;
|
||||
int start = BitConverter.ToInt32(fileData, ctr); ctr += 4;
|
||||
byte[][] returnData = new byte[count][];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
string fx = new string(br.ReadChars(2));
|
||||
|
||||
if (fx != ident) return null;
|
||||
|
||||
ushort count = br.ReadUInt16();
|
||||
byte[][] returnData = new byte[count][];
|
||||
|
||||
uint[] offsets = new uint[count + 1];
|
||||
for (int i = 0; i < count; i++)
|
||||
offsets[i] = br.ReadUInt32();
|
||||
|
||||
uint length = br.ReadUInt32();
|
||||
offsets[offsets.Length - 1] = length;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
br.BaseStream.Seek(offsets[i], SeekOrigin.Begin);
|
||||
using (MemoryStream dataout = new MemoryStream())
|
||||
{
|
||||
byte[] data = new byte[0];
|
||||
s.CopyTo(dataout, (int)offsets[i]);
|
||||
int len = (int)offsets[i + 1] - (int)offsets[i];
|
||||
|
||||
if (len != 0)
|
||||
{
|
||||
data = dataout.ToArray();
|
||||
Array.Resize(ref data, len);
|
||||
}
|
||||
returnData[i] = data;
|
||||
}
|
||||
}
|
||||
return returnData;
|
||||
int end = BitConverter.ToInt32(fileData, ctr); ctr += 4;
|
||||
int len = end - start;
|
||||
byte[] data = new byte[len];
|
||||
Buffer.BlockCopy(fileData, start, data, 0, len);
|
||||
returnData[i] = data;
|
||||
start = end;
|
||||
}
|
||||
return returnData;
|
||||
}
|
||||
internal static string getIsMini(string path)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user