mirror of
https://github.com/UltiNaruto/PKGTool
synced 2024-11-10 06:04:19 +00:00
Version 1.2
Added original file path support (not all files have their original file path) To add custom files you need to reference it using a relative path from the folder in files.list where files.list is
This commit is contained in:
parent
c09511b959
commit
46c5278587
7 changed files with 19679 additions and 4 deletions
19320
PKGTool/Dread/Resources/resource_infos.json
Normal file
19320
PKGTool/Dread/Resources/resource_infos.json
Normal file
File diff suppressed because it is too large
Load diff
119
PKGTool/Misc/Structs/CRC64.cs
Normal file
119
PKGTool/Misc/Structs/CRC64.cs
Normal file
|
@ -0,0 +1,119 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace HashLib.Checksum
|
||||
{
|
||||
public class CRC64
|
||||
{
|
||||
private ulong[] m_crc_tab = new ulong[256];
|
||||
private ulong m_initial_value;
|
||||
private ulong m_final_xor;
|
||||
|
||||
public CRC64()
|
||||
{
|
||||
m_initial_value = ulong.MaxValue;
|
||||
m_final_xor = 0UL;
|
||||
|
||||
GenerateCRCTable(0x42F0E1EBA9EA3693);
|
||||
}
|
||||
|
||||
private byte Reflect8(byte val)
|
||||
{
|
||||
byte res = 0;
|
||||
for(int i=0;i<8;i++)
|
||||
{
|
||||
if ((val & (1 << i)) != 0)
|
||||
res |= (byte)((1 << (7 - i)) & 0xFF);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private ulong Reflect64(ulong val)
|
||||
{
|
||||
ulong res = 0;
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
if ((val & (1UL << i)) != 0UL)
|
||||
res |= (1UL << (63 - i)) & UInt64.MaxValue;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private void GenerateCRCTable(ulong a_poly64)
|
||||
{
|
||||
ulong castMask = ulong.MaxValue;
|
||||
ulong msbMask = (ulong)long.MaxValue + 1UL;
|
||||
ulong curByte = 0UL;
|
||||
for (ulong divident = 0; divident < 256; divident++)
|
||||
{
|
||||
curByte = (divident << 56) & castMask;
|
||||
|
||||
for (uint j = 0; j < 8; j++)
|
||||
{
|
||||
if ((curByte & msbMask) != 0)
|
||||
curByte = (curByte << 1) ^ a_poly64;
|
||||
else
|
||||
curByte <<= 1;
|
||||
}
|
||||
|
||||
m_crc_tab[divident] = curByte & castMask;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] Compute(byte[] a_data, int a_index, int a_length)
|
||||
{
|
||||
Debug.Assert(a_index >= 0);
|
||||
Debug.Assert(a_length >= 0);
|
||||
Debug.Assert(a_index + a_length <= a_data.Length);
|
||||
|
||||
ulong castMask = ulong.MaxValue;
|
||||
ulong m_hash = m_initial_value;
|
||||
ulong curByte = 0UL;
|
||||
int pos = 0;
|
||||
|
||||
for (int i = a_index; a_length > 0; i++, a_length--)
|
||||
{
|
||||
curByte = (ulong)Reflect8(a_data[i]) << 56;
|
||||
m_hash ^= curByte;
|
||||
m_hash &= castMask;
|
||||
|
||||
pos = (int)((m_hash >> 56) & 0xFF);
|
||||
m_hash <<= 8;
|
||||
m_hash &= castMask;
|
||||
m_hash ^= m_crc_tab[pos];
|
||||
m_hash &= castMask;
|
||||
}
|
||||
|
||||
m_hash = Reflect64(m_hash);
|
||||
m_hash = (m_hash ^ m_final_xor) & castMask;
|
||||
|
||||
return BitConverter.GetBytes(m_hash);
|
||||
}
|
||||
|
||||
public ulong ComputeAsValue(byte[] a_data, int a_index, int a_length)
|
||||
{
|
||||
return BitConverter.ToUInt64(Compute(a_data, a_index, a_length), 0);
|
||||
}
|
||||
|
||||
public String ComputeAsString(byte[] a_data, int a_index, int a_length)
|
||||
{
|
||||
return String.Format("{0:X8}", ComputeAsValue(a_data, a_index, a_length));
|
||||
}
|
||||
|
||||
public byte[] Compute(String text, String encoding = "UTF-8")
|
||||
{
|
||||
return Compute(Encoding.GetEncoding(encoding).GetBytes(text), 0, text.Length);
|
||||
}
|
||||
|
||||
public ulong ComputeAsValue(String text, String encoding = "UTF-8")
|
||||
{
|
||||
return BitConverter.ToUInt64(Compute(Encoding.GetEncoding(encoding).GetBytes(text), 0, text.Length), 0);
|
||||
}
|
||||
|
||||
public String ComputeAsString(String text, String encoding = "UTF-8")
|
||||
{
|
||||
return String.Format("{0:X8}", ComputeAsValue(Encoding.GetEncoding(encoding).GetBytes(text), 0, text.Length));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,4 +5,23 @@
|
|||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
using System;
|
||||
using HashLib.Checksum;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace PKGTool
|
||||
|
@ -90,10 +93,14 @@ namespace PKGTool
|
|||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
CRC64 crc = new CRC64();
|
||||
FileStream tmp = null;
|
||||
String fn = String.Empty;
|
||||
String filePath = String.Empty;
|
||||
String outPath = String.Empty;
|
||||
Dread.FileFormats.PKG pkg = new Dread.FileFormats.PKG();
|
||||
Dictionary<String, UInt64> AssetIDByFilePath = JObject.Parse(Encoding.UTF8.GetString(Properties.Resources.resource_infos)).ToObject<Dictionary<String, UInt64>>();
|
||||
Dictionary<UInt64, String> AssetFilePathByID = AssetIDByFilePath.ToDictionary(kvp => kvp.Value, kvp => kvp.Key);
|
||||
try
|
||||
{
|
||||
if (args.Length >= 2)
|
||||
|
@ -131,7 +138,15 @@ namespace PKGTool
|
|||
list.WriteLine($"Padding = {pkg.HeaderPaddingLength}");
|
||||
foreach (var file in pkg.Files)
|
||||
{
|
||||
fn = GenerateFileName(file.Key, file.Value);
|
||||
if (AssetFilePathByID.ContainsKey(file.Key))
|
||||
{
|
||||
fn = AssetFilePathByID[file.Key];
|
||||
filePath = String.Join(Path.DirectorySeparatorChar, outPath, fn.Replace('/', Path.DirectorySeparatorChar));
|
||||
if (!Directory.Exists(Path.GetDirectoryName(filePath)))
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
|
||||
}
|
||||
else
|
||||
fn = GenerateFileName(file.Key, file.Value);
|
||||
Console.WriteLine($"Extracting {fn}...");
|
||||
tmp = File.Open(String.Join(Path.DirectorySeparatorChar, outPath, fn), FileMode.Create, FileAccess.Write);
|
||||
file.Value.CopyTo(tmp);
|
||||
|
@ -180,8 +195,12 @@ namespace PKGTool
|
|||
while (!list.EndOfStream)
|
||||
{
|
||||
fn = list.ReadLine().TrimEnd('\r', '\n');
|
||||
try {
|
||||
pkg.Files.Add(new KeyValuePair<UInt64, MemoryStream>(Convert.ToUInt64("0x" + Path.GetFileNameWithoutExtension(fn), 16), new MemoryStream(File.ReadAllBytes(String.Join(Path.DirectorySeparatorChar, args[1], fn)))));
|
||||
} catch {
|
||||
pkg.Files.Add(new KeyValuePair<UInt64, MemoryStream>(crc.ComputeAsValue(fn), new MemoryStream(File.ReadAllBytes(String.Join(Path.DirectorySeparatorChar, args[1], fn)))));
|
||||
}
|
||||
Console.WriteLine($"Adding {fn}...");
|
||||
pkg.Files.Add(new KeyValuePair<UInt64, MemoryStream>(Convert.ToUInt64("0x" + Path.GetFileNameWithoutExtension(fn), 16), new MemoryStream(File.ReadAllBytes(String.Join(Path.DirectorySeparatorChar, args[1], fn)))));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
73
PKGTool/Properties/Resources.Designer.cs
generated
Normal file
73
PKGTool/Properties/Resources.Designer.cs
generated
Normal file
|
@ -0,0 +1,73 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Ce code a été généré par un outil.
|
||||
// Version du runtime :4.0.30319.42000
|
||||
//
|
||||
// Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
|
||||
// le code est régénéré.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace PKGTool.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées.
|
||||
/// </summary>
|
||||
// Cette classe a été générée automatiquement par la classe StronglyTypedResourceBuilder
|
||||
// à l'aide d'un outil, tel que ResGen ou Visual Studio.
|
||||
// Pour ajouter ou supprimer un membre, modifiez votre fichier .ResX, puis réexécutez ResGen
|
||||
// avec l'option /str ou régénérez votre projet VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retourne l'instance ResourceManager mise en cache utilisée par cette classe.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PKGTool.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remplace la propriété CurrentUICulture du thread actuel pour toutes
|
||||
/// les recherches de ressources à l'aide de cette classe de ressource fortement typée.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recherche une ressource localisée de type System.Byte[].
|
||||
/// </summary>
|
||||
internal static byte[] resource_infos {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("resource_infos", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
124
PKGTool/Properties/Resources.resx
Normal file
124
PKGTool/Properties/Resources.resx
Normal file
|
@ -0,0 +1,124 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="resource_infos" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\dread\resources\resource_infos.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
</root>
|
|
@ -1,7 +1,8 @@
|
|||
{
|
||||
"profiles": {
|
||||
"PKGTool": {
|
||||
"commandName": "Project"
|
||||
"commandName": "Project",
|
||||
"commandLineArgs": "-x \"D:\\Emulateur\\Switch\\Modding\\Metroid Dread\\packs\\maps\\s010_cave\\s010_cave.pkg\""
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue