mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-09-26 23:10:45 +00:00
update
This commit is contained in:
+185
-163
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
@@ -11,6 +9,40 @@ namespace MinecraftUSkinEditor
|
||||
public class PCK
|
||||
{
|
||||
|
||||
public PCK(string filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
IsLittleEndian = !(Read(File.ReadAllBytes(filename)));
|
||||
if(IsLittleEndian)
|
||||
ReadVita(File.ReadAllBytes(filename));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] endianReverseUnicode(byte[] str)
|
||||
{
|
||||
List<byte> NewBte = new List<byte>();
|
||||
NewBte.AddRange(str);
|
||||
NewBte.Reverse();
|
||||
return NewBte.ToArray();
|
||||
|
||||
|
||||
/* Old Endian Reverse Code
|
||||
byte[] newStr = new byte[str.Length];
|
||||
for (int i = 0; i < str.Length; i += 2)
|
||||
{
|
||||
newStr[i] = str[i + 1];
|
||||
newStr[i + 1] = str[i];
|
||||
}
|
||||
return newStr;
|
||||
*/
|
||||
}
|
||||
|
||||
#region Variables
|
||||
|
||||
public class MineFile
|
||||
{
|
||||
public int filesize;
|
||||
@@ -26,35 +58,9 @@ namespace MinecraftUSkinEditor
|
||||
public Dictionary<string, int> typeCodes = new Dictionary<string, int>();
|
||||
public List<MineFile> mineFiles = new List<MineFile>();
|
||||
|
||||
public PCK()
|
||||
{
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
public PCK(string filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
Read(File.ReadAllBytes(filename));
|
||||
IsLittleEndian = false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
ReadVita(File.ReadAllBytes(filename));
|
||||
IsLittleEndian = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] endianReverseUnicode(byte[] str)
|
||||
{
|
||||
byte[] newStr = new byte[str.Length];
|
||||
for (int i = 0; i < str.Length; i += 2)
|
||||
{
|
||||
newStr[i] = str[i + 1];
|
||||
newStr[i + 1] = str[i];
|
||||
}
|
||||
return newStr;
|
||||
}
|
||||
#region NormalPCK
|
||||
|
||||
public static string readMineString(FileData f)
|
||||
{
|
||||
@@ -63,6 +69,153 @@ namespace MinecraftUSkinEditor
|
||||
return Encoding.Unicode.GetString(endianReverseUnicode(f.readBytes(length)));
|
||||
|
||||
}
|
||||
|
||||
public bool Read(byte[] data)
|
||||
{
|
||||
try
|
||||
{
|
||||
pckType = 0;
|
||||
types = new Dictionary<int, string>();
|
||||
typeCodes = new Dictionary<string, int>();
|
||||
mineFiles = new List<MineFile>();
|
||||
|
||||
FileData fileData = new FileData(data);
|
||||
fileData.Endian = Endianness.Big;
|
||||
fileData.readInt();
|
||||
int entryTypeCount = fileData.readInt();
|
||||
//int a = 0;
|
||||
for (int i = 0; i < entryTypeCount; i++)
|
||||
{
|
||||
int unk = fileData.readInt();
|
||||
string text = "";
|
||||
try
|
||||
{
|
||||
text = readMineString(fileData);
|
||||
//File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\exp\\PCKDump" + a + ".bin", text);
|
||||
//a++;
|
||||
}
|
||||
catch
|
||||
{
|
||||
text = "Hello!";
|
||||
}
|
||||
types.Add(unk, text);
|
||||
typeCodes.Add(text, unk);
|
||||
fileData.skip(4);
|
||||
}
|
||||
|
||||
int itemCount = fileData.readInt();
|
||||
|
||||
Console.WriteLine(itemCount);
|
||||
// no metadata
|
||||
if (entryTypeCount == 0)
|
||||
{
|
||||
Console.WriteLine("PckType0");
|
||||
}
|
||||
// type 1 or 2
|
||||
else if (itemCount < 3)
|
||||
{
|
||||
pckType = itemCount;
|
||||
if (pckType == 1)
|
||||
{
|
||||
Console.WriteLine("PckType1");
|
||||
itemCount = fileData.readInt();
|
||||
}
|
||||
if (pckType == 2)
|
||||
Console.WriteLine("PckType2");
|
||||
}
|
||||
// regular pck
|
||||
else
|
||||
{
|
||||
Console.WriteLine("NormalPCK");
|
||||
}
|
||||
|
||||
|
||||
for (int j = 0; j < itemCount; j++)
|
||||
{
|
||||
MineFile mineFile = new MineFile();
|
||||
mineFile.filesize = fileData.readInt();
|
||||
mineFile.type = fileData.readInt();
|
||||
int length = fileData.readInt() * 2;
|
||||
mineFile.name = Encoding.Unicode.GetString(endianReverseUnicode(fileData.readBytes(length)));
|
||||
fileData.skip(4);
|
||||
mineFiles.Add(mineFile);
|
||||
}
|
||||
|
||||
foreach (MineFile mineFile2 in mineFiles)
|
||||
{
|
||||
int num4 = fileData.readInt();
|
||||
for (int k = 0; k < num4; k++)
|
||||
{
|
||||
object[] array = new object[2];
|
||||
int key = fileData.readInt();
|
||||
array[0] = types[key];
|
||||
array[1] = readMineString(fileData);
|
||||
fileData.skip(4);
|
||||
mineFile2.entries.Add(array);
|
||||
}
|
||||
mineFile2.data = fileData.readBytes(mineFile2.filesize);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeMinecraftString(FileOutput f, string str)
|
||||
{
|
||||
byte[] bytes = Encoding.Unicode.GetBytes(str);
|
||||
f.writeInt(bytes.Length / 2);
|
||||
f.writeBytes(PCK.endianReverseUnicode(bytes));
|
||||
f.writeInt(0);
|
||||
}
|
||||
|
||||
public byte[] Rebuild()
|
||||
{
|
||||
FileOutput fileOutput = new FileOutput();
|
||||
fileOutput.Endian = Endianness.Big;
|
||||
fileOutput.writeInt(3);
|
||||
fileOutput.writeInt(this.types.Count);
|
||||
foreach (int num in this.types.Keys)
|
||||
{
|
||||
fileOutput.writeInt(num);
|
||||
PCK.writeMinecraftString(fileOutput, this.types[num]);
|
||||
}
|
||||
fileOutput.writeInt(this.mineFiles.Count);
|
||||
foreach (PCK.MineFile mineFile in this.mineFiles)
|
||||
{
|
||||
fileOutput.writeInt(mineFile.data.Length);
|
||||
fileOutput.writeInt(mineFile.type);
|
||||
PCK.writeMinecraftString(fileOutput, mineFile.name);
|
||||
}
|
||||
foreach (PCK.MineFile mineFile2 in this.mineFiles)
|
||||
{
|
||||
string str = "";
|
||||
try
|
||||
{
|
||||
fileOutput.writeInt(mineFile2.entries.Count);
|
||||
foreach (object[] array in mineFile2.entries)
|
||||
{
|
||||
str = array[0].ToString();
|
||||
fileOutput.writeInt(this.typeCodes[(string)array[0]]);
|
||||
PCK.writeMinecraftString(fileOutput, (string)array[1]);
|
||||
}
|
||||
fileOutput.writeBytes(mineFile2.data);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
MessageBox.Show(str + " is not in the main metadatabase");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return fileOutput.getBytes();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region VitaPCK
|
||||
|
||||
public static string readMineStringVita(FileData f)
|
||||
{
|
||||
int length = f.readIntVita() * 2;
|
||||
@@ -70,90 +223,6 @@ namespace MinecraftUSkinEditor
|
||||
return Encoding.Unicode.GetString((f.readBytes(length)));
|
||||
|
||||
}
|
||||
public void Read(byte[] data)
|
||||
{
|
||||
pckType = 0;
|
||||
types = new Dictionary<int, string>();
|
||||
typeCodes = new Dictionary<string, int>();
|
||||
mineFiles = new List<MineFile>();
|
||||
|
||||
FileData fileData = new FileData(data);
|
||||
fileData.Endian = Endianness.Big;
|
||||
fileData.readInt();
|
||||
int entryTypeCount = fileData.readInt();
|
||||
//int a = 0;
|
||||
for (int i = 0; i < entryTypeCount; i++)
|
||||
{
|
||||
int unk = fileData.readInt();
|
||||
string text = "";
|
||||
try
|
||||
{
|
||||
text = readMineString(fileData);
|
||||
//File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\exp\\PCKDump" + a + ".bin", text);
|
||||
//a++;
|
||||
}
|
||||
catch
|
||||
{
|
||||
text = "Hello!";
|
||||
}
|
||||
types.Add(unk, text);
|
||||
typeCodes.Add(text, unk);
|
||||
fileData.skip(4);
|
||||
}
|
||||
|
||||
int itemCount = fileData.readInt();
|
||||
|
||||
Console.WriteLine(itemCount);
|
||||
// no metadata
|
||||
if (entryTypeCount == 0)
|
||||
{
|
||||
Console.WriteLine("PckType0");
|
||||
}
|
||||
// type 1 or 2
|
||||
else if (itemCount < 3)
|
||||
{
|
||||
pckType = itemCount;
|
||||
if (pckType == 1)
|
||||
{
|
||||
Console.WriteLine("PckType1");
|
||||
itemCount = fileData.readInt();
|
||||
}
|
||||
if (pckType == 2)
|
||||
Console.WriteLine("PckType2");
|
||||
}
|
||||
// regular pck
|
||||
else
|
||||
{
|
||||
Console.WriteLine("NormalPCK");
|
||||
}
|
||||
|
||||
|
||||
for (int j = 0; j < itemCount; j++)
|
||||
{
|
||||
MineFile mineFile = new MineFile();
|
||||
mineFile.filesize = fileData.readInt();
|
||||
mineFile.type = fileData.readInt();
|
||||
int length = fileData.readInt() * 2;
|
||||
mineFile.name = Encoding.Unicode.GetString(endianReverseUnicode(fileData.readBytes(length)));
|
||||
fileData.skip(4);
|
||||
mineFiles.Add(mineFile);
|
||||
}
|
||||
|
||||
foreach (MineFile mineFile2 in mineFiles)
|
||||
{
|
||||
int num4 = fileData.readInt();
|
||||
for (int k = 0; k < num4; k++)
|
||||
{
|
||||
object[] array = new object[2];
|
||||
int key = fileData.readInt();
|
||||
array[0] = types[key];
|
||||
array[1] = readMineString(fileData);
|
||||
fileData.skip(4);
|
||||
mineFile2.entries.Add(array);
|
||||
}
|
||||
mineFile2.data = fileData.readBytes(mineFile2.filesize);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReadVita(byte[] data)
|
||||
{
|
||||
@@ -240,14 +309,6 @@ namespace MinecraftUSkinEditor
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeMinecraftString(FileOutput f, string str)
|
||||
{
|
||||
byte[] bytes = Encoding.Unicode.GetBytes(str);
|
||||
f.writeInt(bytes.Length / 2);
|
||||
f.writeBytes(PCK.endianReverseUnicode(bytes));
|
||||
f.writeInt(0);
|
||||
}
|
||||
|
||||
private static void writeMinecraftStringVita(FileOutput f, string str)
|
||||
{
|
||||
Console.WriteLine("WriteVita -- " + str);
|
||||
@@ -257,47 +318,6 @@ namespace MinecraftUSkinEditor
|
||||
f.writeIntVita(0);
|
||||
}
|
||||
|
||||
public byte[] Rebuild()
|
||||
{
|
||||
FileOutput fileOutput = new FileOutput();
|
||||
fileOutput.Endian = Endianness.Big;
|
||||
fileOutput.writeInt(3);
|
||||
fileOutput.writeInt(this.types.Count);
|
||||
foreach (int num in this.types.Keys)
|
||||
{
|
||||
fileOutput.writeInt(num);
|
||||
PCK.writeMinecraftString(fileOutput, this.types[num]);
|
||||
}
|
||||
fileOutput.writeInt(this.mineFiles.Count);
|
||||
foreach (PCK.MineFile mineFile in this.mineFiles)
|
||||
{
|
||||
fileOutput.writeInt(mineFile.data.Length);
|
||||
fileOutput.writeInt(mineFile.type);
|
||||
PCK.writeMinecraftString(fileOutput, mineFile.name);
|
||||
}
|
||||
foreach (PCK.MineFile mineFile2 in this.mineFiles)
|
||||
{
|
||||
string str = "";
|
||||
try
|
||||
{
|
||||
fileOutput.writeInt(mineFile2.entries.Count);
|
||||
foreach (object[] array in mineFile2.entries)
|
||||
{
|
||||
str = array[0].ToString();
|
||||
fileOutput.writeInt(this.typeCodes[(string)array[0]]);
|
||||
PCK.writeMinecraftString(fileOutput, (string)array[1]);
|
||||
}
|
||||
fileOutput.writeBytes(mineFile2.data);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
MessageBox.Show(str + " is not in the main metadatabase");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return fileOutput.getBytes();
|
||||
}
|
||||
|
||||
public byte[] RebuildVita()
|
||||
{
|
||||
FileOutput fileOutput = new FileOutput();
|
||||
@@ -338,5 +358,7 @@ namespace MinecraftUSkinEditor
|
||||
}
|
||||
return fileOutput.getBytes();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user