mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-06-08 18:47:34 +00:00
Initial commit
This commit is contained in:
187
MinecraftUSkinEditor/Classes/Bink.cs
Normal file
187
MinecraftUSkinEditor/Classes/Bink.cs
Normal file
@@ -0,0 +1,187 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace minekampf.Classes
|
||||
{
|
||||
internal class Bink
|
||||
{
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern IntPtr LoadLibrary(string lpFileName);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern IntPtr FreeLibrary(IntPtr library);
|
||||
|
||||
public unsafe static string Binka(string infile, string outDir = null, bool last = true, string working = null)
|
||||
{
|
||||
bool flag = working == null;
|
||||
string text;
|
||||
string text2;
|
||||
string path;
|
||||
if (flag)
|
||||
{
|
||||
working = Path.GetTempPath() + DateTime.Now.Second.ToString();
|
||||
text = minekampf.Classes.Bink.ExtractResource("Resources.binka_encode.exe", working, "binka_encode.exe");
|
||||
text2 = minekampf.Classes.Bink.ExtractResource("Resources.mss32.dll", working, "mss32.dll");
|
||||
path = minekampf.Classes.Bink.ExtractResource("Resources.binkawin.asi", working, "binkawin.asi");
|
||||
minekampf.Classes.Bink.library = minekampf.Classes.Bink.LoadLibrary(text2);
|
||||
}
|
||||
else
|
||||
{
|
||||
text = working + "\\binka_encode.exe";
|
||||
text2 = working + "\\mss32.dll";
|
||||
path = working + "\\binkawin.asi";
|
||||
}
|
||||
bool flag2 = minekampf.Classes.Bink.getType(infile) == "WAV";
|
||||
if (flag2)
|
||||
{
|
||||
string[] array = minekampf.Classes.Bink.createArg(infile, outDir);
|
||||
Process process = new Process();
|
||||
process.StartInfo.FileName = text;
|
||||
process.StartInfo.Arguments = string.Concat(new string[]
|
||||
{
|
||||
" \"",
|
||||
array[0],
|
||||
"\" \"",
|
||||
array[1],
|
||||
"\""
|
||||
});
|
||||
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
process.Start();
|
||||
process.WaitForExit();
|
||||
}
|
||||
else
|
||||
{
|
||||
bool flag3 = minekampf.Classes.Bink.getType(infile) == "BINKA";
|
||||
if (flag3)
|
||||
{
|
||||
string[] array2 = minekampf.Classes.Bink.createArg(infile, outDir);
|
||||
byte[] array3 = File.ReadAllBytes(array2[0]);
|
||||
uint num = 0U;
|
||||
minekampf.Classes.Bink.AIL_set_redist_directory(".");
|
||||
minekampf.Classes.Bink.AIL_startup();
|
||||
IntPtr intPtr;
|
||||
bool flag4 = minekampf.Classes.Bink.AIL_decompress_ASI(array3, (uint)array3.Length, ".binka", &intPtr, &num, 0U) == 0;
|
||||
if (flag4)
|
||||
{
|
||||
throw new Exception("AIL ERROR");
|
||||
}
|
||||
byte[] array4 = new byte[num];
|
||||
Marshal.Copy(intPtr, array4, 0, array4.Length);
|
||||
minekampf.Classes.Bink.AIL_mem_free_lock(intPtr);
|
||||
minekampf.Classes.Bink.AIL_shutdown();
|
||||
File.WriteAllBytes(array2[1], array4);
|
||||
}
|
||||
}
|
||||
if (last)
|
||||
{
|
||||
minekampf.Classes.Bink.FreeLibrary(minekampf.Classes.Bink.library);
|
||||
minekampf.Classes.Bink.FreeLibrary(minekampf.Classes.Bink.library);
|
||||
File.Delete(text);
|
||||
File.Delete(path);
|
||||
while (File.Exists(text2))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(text2);
|
||||
}
|
||||
catch
|
||||
{
|
||||
minekampf.Classes.Bink.FreeLibrary(minekampf.Classes.Bink.library);
|
||||
}
|
||||
}
|
||||
}
|
||||
return working;
|
||||
}
|
||||
|
||||
private static string getType(string loc)
|
||||
{
|
||||
string a = Path.GetExtension(loc).ToLower();
|
||||
bool flag = a == ".binka";
|
||||
string result;
|
||||
if (flag)
|
||||
{
|
||||
result = "BINKA";
|
||||
}
|
||||
else
|
||||
{
|
||||
bool flag2 = !(a == ".wav");
|
||||
if (flag2)
|
||||
{
|
||||
throw new Exception("File type not valid. To use MP3 or other audio formats, convert to wav format before using tool");
|
||||
}
|
||||
result = "WAV";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string[] createArg(string inFile, string outdir = null)
|
||||
{
|
||||
string[] array = new string[2];
|
||||
array[0] = inFile;
|
||||
string[] array2 = array;
|
||||
string type = minekampf.Classes.Bink.getType(inFile);
|
||||
bool flag = type == "BINKA";
|
||||
if (flag)
|
||||
{
|
||||
array2[1] = ((outdir.Length <= 3) ? Path.GetFullPath(inFile.Replace(".binka", ".wav")) : (outdir + "\\" + Path.GetFileName(inFile.Replace(".binka", ".wav"))));
|
||||
}
|
||||
else
|
||||
{
|
||||
bool flag2 = type == "WAV";
|
||||
if (flag2)
|
||||
{
|
||||
array2[1] = ((outdir.Length <= 3) ? Path.GetFullPath(inFile.Replace(".wav", ".binka")) : (outdir + "\\" + Path.GetFileName(inFile.Replace(".wav", ".binka"))));
|
||||
}
|
||||
}
|
||||
bool flag3 = !Directory.Exists(Path.GetDirectoryName(array2[1]));
|
||||
if (flag3)
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(array2[1]));
|
||||
}
|
||||
return array2;
|
||||
}
|
||||
|
||||
internal static string ExtractResource(string resource, string path, string filename)
|
||||
{
|
||||
Stream manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);
|
||||
byte[] array = new byte[(int)manifestResourceStream.Length];
|
||||
manifestResourceStream.Read(array, 0, array.Length);
|
||||
manifestResourceStream.Close();
|
||||
bool flag = !Directory.Exists(path);
|
||||
if (flag)
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
path = path + "\\" + filename;
|
||||
File.WriteAllBytes(path, array);
|
||||
return path;
|
||||
}
|
||||
|
||||
[DllImport("mss32.dll", EntryPoint = "_AIL_decompress_ASI@24")]
|
||||
private unsafe static extern int AIL_decompress_ASI([MarshalAs(UnmanagedType.LPArray)] byte[] indata, uint insize, [MarshalAs(UnmanagedType.LPStr)] string ext, IntPtr* result, uint* resultsize, uint zero);
|
||||
|
||||
[DllImport("mss32.dll", EntryPoint = "_AIL_last_error@0")]
|
||||
private static extern IntPtr AIL_last_error();
|
||||
|
||||
[DllImport("mss32.dll", EntryPoint = "_AIL_set_redist_directory@4")]
|
||||
private static extern IntPtr AIL_set_redist_directory([MarshalAs(UnmanagedType.LPStr)] string redistDir);
|
||||
|
||||
[DllImport("mss32.dll", EntryPoint = "_AIL_mem_free_lock@4")]
|
||||
private static extern void AIL_mem_free_lock(IntPtr ptr);
|
||||
|
||||
[DllImport("mss32.dll", EntryPoint = "_AIL_startup@0")]
|
||||
private static extern int AIL_startup();
|
||||
|
||||
[DllImport("mss32.dll", EntryPoint = "_AIL_shutdown@0")]
|
||||
private static extern int AIL_shutdown();
|
||||
|
||||
public Bink()
|
||||
{
|
||||
}
|
||||
|
||||
private static IntPtr library;
|
||||
}
|
||||
}
|
||||
23
MinecraftUSkinEditor/Classes/COL.cs
Normal file
23
MinecraftUSkinEditor/Classes/COL.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace minekampf.Classes
|
||||
{
|
||||
public class COL
|
||||
{
|
||||
|
||||
public COL(byte[] data)
|
||||
{
|
||||
Read(data);
|
||||
}
|
||||
|
||||
public void Read(byte[] data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
25
MinecraftUSkinEditor/Classes/DiscordBot.cs
Normal file
25
MinecraftUSkinEditor/Classes/DiscordBot.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace minekampf.Classes
|
||||
{
|
||||
class DiscordBot
|
||||
{
|
||||
//https://discordapp.com/api/webhooks/797263532139479070/ExbpwHKxP-1_cpxnAVrqFXm9SFKhk2cIUyhEVobT2Ds8PuQKbaFvzl2hjrKsEZXrXHI3
|
||||
|
||||
public static void sendDiscordWebhook(string URL, string profilepic, string username, string message)
|
||||
{
|
||||
NameValueCollection discordValues = new NameValueCollection();
|
||||
discordValues.Add("username", username);
|
||||
discordValues.Add("avatar_url", profilepic);
|
||||
discordValues.Add("content", message);
|
||||
new WebClient().UploadValues(URL, discordValues);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
33
MinecraftUSkinEditor/Classes/FileBase.cs
Normal file
33
MinecraftUSkinEditor/Classes/FileBase.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MinecraftUSkinEditor
|
||||
{
|
||||
public enum Endianness
|
||||
{
|
||||
Little = 0,
|
||||
Big = 1
|
||||
}
|
||||
|
||||
public abstract class FileBase
|
||||
{
|
||||
public abstract Endianness Endian { get; set; }
|
||||
|
||||
|
||||
public abstract void Read(string filename);
|
||||
public abstract byte[] Rebuild();
|
||||
|
||||
public void Save(string filename)
|
||||
{
|
||||
var Data = Rebuild();
|
||||
if (Data.Length <= 0)
|
||||
throw new Exception("Warning: Data was empty!");
|
||||
|
||||
File.WriteAllBytes(filename, Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
264
MinecraftUSkinEditor/Classes/FileData.cs
Normal file
264
MinecraftUSkinEditor/Classes/FileData.cs
Normal file
@@ -0,0 +1,264 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace MinecraftUSkinEditor
|
||||
{
|
||||
public class FileData
|
||||
{
|
||||
private byte[] b;
|
||||
|
||||
private int p;
|
||||
|
||||
public Endianness Endian;
|
||||
|
||||
public FileData(string f)
|
||||
{
|
||||
b = File.ReadAllBytes(f);
|
||||
}
|
||||
|
||||
public FileData(byte[] b)
|
||||
{
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public int eof()
|
||||
{
|
||||
return b.Length;
|
||||
}
|
||||
|
||||
public byte[] read(int length)
|
||||
{
|
||||
if (length + p > b.Length)
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
byte[] array = new byte[length];
|
||||
int num = 0;
|
||||
while (num < length)
|
||||
{
|
||||
array[num] = b[p];
|
||||
num++;
|
||||
p++;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public int readInt()
|
||||
{
|
||||
if (Endian == Endianness.Little)
|
||||
{
|
||||
return (b[p++] & 0xFF) | ((b[p++] & 0xFF) << 8) | ((b[p++] & 0xFF) << 16) | ((b[p++] & 0xFF) << 24);
|
||||
}
|
||||
return ((b[p++] & 0xFF) << 24) | ((b[p++] & 0xFF) << 16) | ((b[p++] & 0xFF) << 8) | (b[p++] & 0xFF);
|
||||
}
|
||||
|
||||
public int readThree()
|
||||
{
|
||||
if (Endian == Endianness.Little)
|
||||
{
|
||||
return (b[p++] & 0xFF) | ((b[p++] & 0xFF) << 8) | ((b[p++] & 0xFF) << 16);
|
||||
}
|
||||
return ((b[p++] & 0xFF) << 16) | ((b[p++] & 0xFF) << 8) | (b[p++] & 0xFF);
|
||||
}
|
||||
|
||||
public int readShort()
|
||||
{
|
||||
if (Endian == Endianness.Little)
|
||||
{
|
||||
return (b[p++] & 0xFF) | ((b[p++] & 0xFF) << 8);
|
||||
}
|
||||
return ((b[p++] & 0xFF) << 8) | (b[p++] & 0xFF);
|
||||
}
|
||||
|
||||
public int readByte()
|
||||
{
|
||||
return b[p++] & 0xFF;
|
||||
}
|
||||
|
||||
public byte[] readBytes(int length)
|
||||
{
|
||||
List<byte> list = new List<byte>();
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
list.Add((byte)readByte());
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public float readFloat()
|
||||
{
|
||||
byte[] array = new byte[4];
|
||||
array = ((Endian != 0) ? new byte[4]
|
||||
{
|
||||
b[p + 3],
|
||||
b[p + 2],
|
||||
b[p + 1],
|
||||
b[p]
|
||||
} : new byte[4]
|
||||
{
|
||||
b[p],
|
||||
b[p + 1],
|
||||
b[p + 2],
|
||||
b[p + 3]
|
||||
});
|
||||
p += 4;
|
||||
return BitConverter.ToSingle(array, 0);
|
||||
}
|
||||
|
||||
public float readHalfFloat()
|
||||
{
|
||||
return toFloat((short)readShort());
|
||||
}
|
||||
|
||||
public static float toFloat(int hbits)
|
||||
{
|
||||
int num = hbits & 0x3FF;
|
||||
int num2 = hbits & 0x7C00;
|
||||
switch (num2)
|
||||
{
|
||||
case 31744:
|
||||
num2 = 261120;
|
||||
break;
|
||||
default:
|
||||
num2 += 114688;
|
||||
if (num == 0 && num2 > 115712)
|
||||
{
|
||||
return BitConverter.ToSingle(BitConverter.GetBytes(((hbits & 0x8000) << 16) | (num2 << 13) | 0x3FF), 0);
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
if (num != 0)
|
||||
{
|
||||
num2 = 115712;
|
||||
do
|
||||
{
|
||||
num <<= 1;
|
||||
num2 -= 1024;
|
||||
}
|
||||
while ((num & 0x400) == 0);
|
||||
num &= 0x3FF;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return BitConverter.ToSingle(BitConverter.GetBytes(((hbits & 0x8000) << 16) | ((num2 | num) << 13)), 0);
|
||||
}
|
||||
|
||||
public static int fromFloat(float fval, bool littleEndian)
|
||||
{
|
||||
int num = FileOutput.SingleToInt32Bits(fval, littleEndian);
|
||||
int num2 = (num >> 16) & 0x8000;
|
||||
int num3 = (num & 0x7FFFFFFF) + 4096;
|
||||
if (num3 >= 1199570944)
|
||||
{
|
||||
if ((num & 0x7FFFFFFF) >= 1199570944)
|
||||
{
|
||||
if (num3 < 2139095040)
|
||||
{
|
||||
return num2 | 0x7C00;
|
||||
}
|
||||
return num2 | 0x7C00 | ((num & 0x7FFFFF) >> 13);
|
||||
}
|
||||
return num2 | 0x7BFF;
|
||||
}
|
||||
if (num3 >= 947912704)
|
||||
{
|
||||
return num2 | (num3 - 939524096 >> 13);
|
||||
}
|
||||
if (num3 < 855638016)
|
||||
{
|
||||
return num2;
|
||||
}
|
||||
num3 = (num & 0x7FFFFFFF) >> 23;
|
||||
return num2 | (((num & 0x7FFFFF) | 0x800000) + (8388608 >> num3 - 102) >> 126 - num3);
|
||||
}
|
||||
|
||||
public static int sign12Bit(int i)
|
||||
{
|
||||
if (((i >> 11) & 1) == 1)
|
||||
{
|
||||
i = ~i;
|
||||
i &= 0xFFF;
|
||||
i++;
|
||||
i *= -1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public void skip(int i)
|
||||
{
|
||||
p += i;
|
||||
}
|
||||
|
||||
public void seek(int i)
|
||||
{
|
||||
p = i;
|
||||
}
|
||||
|
||||
public int pos()
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
public int size()
|
||||
{
|
||||
return b.Length;
|
||||
}
|
||||
|
||||
public string readString()
|
||||
{
|
||||
string text = "";
|
||||
while (b[p] != 0)
|
||||
{
|
||||
string str = text;
|
||||
char c = (char)b[p];
|
||||
text = str + c;
|
||||
p++;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
public byte[] getSection(int offset, int size)
|
||||
{
|
||||
byte[] array = new byte[size];
|
||||
Array.Copy(b, offset, array, 0, size);
|
||||
return array;
|
||||
}
|
||||
|
||||
public string readString(int p, int size)
|
||||
{
|
||||
if (size == -1)
|
||||
{
|
||||
string text = "";
|
||||
while (p < b.Length && (b[p] & 0xFFu) != 0)
|
||||
{
|
||||
text += (char)(b[p] & 0xFFu);
|
||||
p++;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
string text2 = "";
|
||||
for (int i = p; i < p + size; i++)
|
||||
{
|
||||
if ((b[i] & 0xFFu) != 0)
|
||||
{
|
||||
text2 += (char)(b[i] & 0xFFu);
|
||||
}
|
||||
}
|
||||
return text2;
|
||||
}
|
||||
|
||||
public void align(int i)
|
||||
{
|
||||
while (p % i != 0)
|
||||
{
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
public int readOffset()
|
||||
{
|
||||
return p + readInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
175
MinecraftUSkinEditor/Classes/FileOutput.cs
Normal file
175
MinecraftUSkinEditor/Classes/FileOutput.cs
Normal file
@@ -0,0 +1,175 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace MinecraftUSkinEditor
|
||||
{
|
||||
public class FileOutput
|
||||
{
|
||||
|
||||
List<byte> data = new List<byte>();
|
||||
|
||||
public Endianness Endian;
|
||||
|
||||
public byte[] getBytes()
|
||||
{
|
||||
return data.ToArray();
|
||||
}
|
||||
|
||||
public void writeString(String s){
|
||||
char[] c = s.ToCharArray();
|
||||
for(int i = 0; i < c.Length ; i++)
|
||||
data.Add((byte)c[i]);
|
||||
}
|
||||
|
||||
public int size(){
|
||||
return data.Count;
|
||||
}
|
||||
|
||||
public void writeOutput(FileOutput d){
|
||||
foreach(byte b in d.data)
|
||||
data.Add(b);
|
||||
}
|
||||
|
||||
private static char[] HexToCharArray(string hex)
|
||||
{
|
||||
return Enumerable.Range(0, hex.Length)
|
||||
.Where(x => x % 2 == 0)
|
||||
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
|
||||
.Select(x => Convert.ToChar(x))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public void writeHex(string s)
|
||||
{
|
||||
char[] c = HexToCharArray(s);
|
||||
for (int i = 0; i < c.Length; i++)
|
||||
data.Add((byte)c[i]);
|
||||
}
|
||||
|
||||
public void writeInt(int i){
|
||||
if(Endian == Endianness.Little){
|
||||
data.Add((byte)((i)&0xFF));
|
||||
data.Add((byte)((i>>8)&0xFF));
|
||||
data.Add((byte)((i>>16)&0xFF));
|
||||
data.Add((byte)((i>>24)&0xFF));
|
||||
}else{
|
||||
data.Add((byte)((i>>24)&0xFF));
|
||||
data.Add((byte)((i>>16)&0xFF));
|
||||
data.Add((byte)((i>>8)&0xFF));
|
||||
data.Add((byte)((i)&0xFF));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void writeIntAt(int i, int p){
|
||||
if(Endian == Endianness.Little){
|
||||
data[p++] = (byte)((i)&0xFF);
|
||||
data[p++] = (byte)((i>>8)&0xFF);
|
||||
data[p++] = (byte)((i>>16)&0xFF);
|
||||
data[p++] = (byte)((i>>24)&0xFF);
|
||||
}else{
|
||||
data[p++] = (byte)((i>>24)&0xFF);
|
||||
data[p++] = (byte)((i>>16)&0xFF);
|
||||
data[p++] = (byte)((i>>8)&0xFF);
|
||||
data[p++] = (byte)((i)&0xFF);
|
||||
}
|
||||
}
|
||||
public void writeShortAt(int i, int p){
|
||||
if(Endian == Endianness.Little){
|
||||
data[p++] = (byte)((i)&0xFF);
|
||||
data[p++] = (byte)((i>>8)&0xFF);
|
||||
}else{
|
||||
data[p++] = (byte)((i>>8)&0xFF);
|
||||
data[p++] = (byte)((i)&0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
public void align(int i){
|
||||
while(data.Count % i != 0)
|
||||
writeByte(0);
|
||||
}
|
||||
|
||||
public void align(int i, int v){
|
||||
while(data.Count % i != 0)
|
||||
writeByte(v);
|
||||
}
|
||||
|
||||
/*public void align(int i, int value){
|
||||
while(data.size() % i != 0)
|
||||
writeByte(value);
|
||||
}*/
|
||||
|
||||
|
||||
public void writeFloat(float f){
|
||||
int i = SingleToInt32Bits (f, Endian == Endianness.Big);
|
||||
data.Add((byte)((i)&0xFF));
|
||||
data.Add((byte)((i>>8)&0xFF));
|
||||
data.Add((byte)((i>>16)&0xFF));
|
||||
data.Add((byte)((i>>24)&0xFF));
|
||||
}
|
||||
|
||||
public static int SingleToInt32Bits(float value, bool littleEndian) {
|
||||
byte[] b = BitConverter.GetBytes (value);
|
||||
int p = 0;
|
||||
|
||||
if (!littleEndian) {
|
||||
return (b [p++]&0xFF) | ((b [p++] & 0xFF) << 8) | ((b [p++] & 0xFF) << 16) | ((b [p++] & 0xFF) << 24);
|
||||
}else
|
||||
return ((b [p++] & 0xFF) << 24) | ((b [p++] & 0xFF) << 16) | ((b [p++] & 0xFF) << 8) | (b [p++]&0xFF);
|
||||
}
|
||||
|
||||
public void writeHalfFloat(float f){
|
||||
int i = FileData.fromFloat(f, Endian == Endianness.Little);
|
||||
data.Add((byte)((i>>8)&0xFF));
|
||||
data.Add((byte)((i)&0xFF));
|
||||
}
|
||||
|
||||
public void writeShort(int i){
|
||||
if(Endian == Endianness.Little){
|
||||
data.Add((byte)((i)&0xFF));
|
||||
data.Add((byte)((i>>8)&0xFF));
|
||||
} else {
|
||||
data.Add((byte)((i>>8)&0xFF));
|
||||
data.Add((byte)((i)&0xFF));
|
||||
}
|
||||
}
|
||||
|
||||
public void writeByte(int i){
|
||||
data.Add((byte)((i)&0xFF));
|
||||
}
|
||||
|
||||
public void writeChars(char[] c)
|
||||
{
|
||||
foreach (char ch in c)
|
||||
writeByte(Convert.ToByte(ch));
|
||||
}
|
||||
|
||||
public void writeBytes(byte[] bytes)
|
||||
{
|
||||
foreach(byte b in bytes)
|
||||
writeByte(b);
|
||||
}
|
||||
|
||||
public void writeFlag(bool b)
|
||||
{
|
||||
if (b)
|
||||
writeByte(1);
|
||||
else
|
||||
writeByte(0);
|
||||
}
|
||||
|
||||
public int pos()
|
||||
{
|
||||
return data.Count;
|
||||
}
|
||||
|
||||
public void save(String fname)
|
||||
{
|
||||
File.WriteAllBytes (fname, data.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
6
MinecraftUSkinEditor/Classes/KeyValuePair.cs
Normal file
6
MinecraftUSkinEditor/Classes/KeyValuePair.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace MinecraftUSkinEditor
|
||||
{
|
||||
internal class KeyValuePair<T>
|
||||
{
|
||||
}
|
||||
}
|
||||
130
MinecraftUSkinEditor/Classes/LOC.cs
Normal file
130
MinecraftUSkinEditor/Classes/LOC.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MinecraftUSkinEditor
|
||||
{
|
||||
public class LOC
|
||||
{
|
||||
public LOC()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public LOC(byte[] data)
|
||||
{
|
||||
Read(data);
|
||||
}
|
||||
|
||||
public string readString(FileData f)
|
||||
{
|
||||
int length = f.readShort();
|
||||
string str = f.readString(f.pos(), length);
|
||||
f.skip(length);
|
||||
return str;
|
||||
}
|
||||
|
||||
public class Language
|
||||
{
|
||||
public string name;
|
||||
public int unk1;
|
||||
public List<string> names = new List<string>();
|
||||
|
||||
public string readString(FileData f)
|
||||
{
|
||||
int length = f.readShort();
|
||||
string str = f.readString(f.pos(), length);
|
||||
f.skip(length);
|
||||
return str;
|
||||
}
|
||||
|
||||
public Language() { }
|
||||
|
||||
public void Read(FileData f)
|
||||
{
|
||||
int idCount = f.readInt();
|
||||
for (int i = 0; i < idCount; i++)
|
||||
names.Add(readString(f));
|
||||
}
|
||||
|
||||
public byte[] Rebuild()
|
||||
{
|
||||
FileOutput f = new FileOutput();
|
||||
f.Endian = Endianness.Big;
|
||||
|
||||
f.writeInt(names.Count);
|
||||
foreach(string name in names)
|
||||
{
|
||||
f.writeShort(name.Length);
|
||||
f.writeString(name);
|
||||
}
|
||||
|
||||
return f.getBytes();
|
||||
}
|
||||
}
|
||||
|
||||
public Language ids = new Language();
|
||||
public List<Language> langs = new List<Language>();
|
||||
|
||||
public void Read(byte[] data)
|
||||
{
|
||||
FileData f = new FileData(data);
|
||||
f.Endian = Endianness.Big;
|
||||
|
||||
int unk1 = f.readInt();
|
||||
if (unk1 != 2)
|
||||
throw new NotImplementedException("Not localization data");
|
||||
int langCount = f.readInt();
|
||||
f.skip(1);
|
||||
|
||||
ids.Read(f);
|
||||
|
||||
for(int i = 0; i < langCount; i++)
|
||||
{
|
||||
Language l = new Language();
|
||||
l.name = readString(f);
|
||||
l.unk1 = f.readInt();
|
||||
langs.Add(l);
|
||||
}
|
||||
|
||||
foreach (Language l in langs)
|
||||
{
|
||||
f.skip(5);
|
||||
f.skip(f.readShort());
|
||||
l.Read(f);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] Rebuild()
|
||||
{
|
||||
FileOutput f = new FileOutput();
|
||||
f.Endian = Endianness.Big;
|
||||
|
||||
f.writeInt(2);
|
||||
f.writeInt(langs.Count);
|
||||
f.writeByte(0);
|
||||
|
||||
f.writeBytes(ids.Rebuild());
|
||||
|
||||
foreach(Language l in langs)
|
||||
{
|
||||
f.writeShort(l.name.Length);
|
||||
f.writeString(l.name);
|
||||
f.writeInt(7 + l.name.Length + l.Rebuild().Length);
|
||||
}
|
||||
|
||||
foreach(Language l in langs)
|
||||
{
|
||||
f.writeInt(2);
|
||||
f.writeByte(0);
|
||||
f.writeShort(l.name.Length);
|
||||
f.writeString(l.name);
|
||||
f.writeBytes(l.Rebuild());
|
||||
}
|
||||
|
||||
return f.getBytes();
|
||||
}
|
||||
}
|
||||
}
|
||||
217
MinecraftUSkinEditor/Classes/PCK.cs
Normal file
217
MinecraftUSkinEditor/Classes/PCK.cs
Normal file
@@ -0,0 +1,217 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
||||
namespace MinecraftUSkinEditor
|
||||
{
|
||||
public class PCK
|
||||
{
|
||||
|
||||
public class MineFile
|
||||
{
|
||||
public int filesize;
|
||||
public int type;
|
||||
public string name;
|
||||
public byte[] data;
|
||||
public List<object[]> entries = new List<object[]>();
|
||||
}
|
||||
|
||||
public int pckType = 0;
|
||||
|
||||
public Dictionary<int, string> types = new Dictionary<int, string>();
|
||||
public Dictionary<string, int> typeCodes = new Dictionary<string, int>();
|
||||
public List<MineFile> mineFiles = new List<MineFile>();
|
||||
|
||||
public PCK()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public PCK(string filename)
|
||||
{
|
||||
Read(File.ReadAllBytes(filename));
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public static string readMineString(FileData f)
|
||||
{
|
||||
int length = f.readInt() * 2;
|
||||
Console.WriteLine(length.ToString());
|
||||
return Encoding.Unicode.GetString(endianReverseUnicode(f.readBytes(length)));
|
||||
|
||||
}
|
||||
|
||||
public static string readMineStringVita(FileData f)
|
||||
{
|
||||
int length = f.readInt() / 20000000;
|
||||
Console.WriteLine(length.ToString() + " - caught");
|
||||
return Encoding.Unicode.GetString(endianReverseUnicode(f.readBytes(length)));
|
||||
|
||||
}
|
||||
|
||||
public static string readMineStringVita2(FileData f)
|
||||
{
|
||||
int length = (f.readInt() / 20000000) * 2;
|
||||
Console.WriteLine(length.ToString() + " - caught");
|
||||
return Encoding.Unicode.GetString(endianReverseUnicode(f.readBytes(length)));
|
||||
|
||||
}
|
||||
|
||||
public void Read(byte[] data)
|
||||
{
|
||||
FileData fileData = new FileData(data);
|
||||
fileData.Endian = Endianness.Big;
|
||||
fileData.readInt();
|
||||
int entryTypeCount = fileData.readInt();
|
||||
for (int i = 0; i < entryTypeCount; i++)
|
||||
{
|
||||
int unk = fileData.readInt();
|
||||
string text = "";
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
text = readMineString(fileData);
|
||||
}
|
||||
catch
|
||||
{
|
||||
try
|
||||
{
|
||||
text = readMineStringVita(fileData);
|
||||
}
|
||||
catch
|
||||
{
|
||||
text = readMineStringVita2(fileData);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
text = "Hello!";
|
||||
}
|
||||
types.Add(unk, text);
|
||||
typeCodes.Add(text, unk);
|
||||
fileData.skip(4);
|
||||
}
|
||||
|
||||
int itemCount = fileData.readInt();
|
||||
|
||||
// no metadata
|
||||
if (entryTypeCount == 0)
|
||||
{
|
||||
Console.WriteLine("PckType0");
|
||||
}
|
||||
// type 1 or 2
|
||||
else if (itemCount < 3)
|
||||
{
|
||||
pckType = itemCount;
|
||||
itemCount = fileData.readInt();
|
||||
if (pckType == 1)
|
||||
Console.WriteLine("PckType1");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeMinecraftString(FileOutput f, string str)
|
||||
{
|
||||
byte[] d = Encoding.Unicode.GetBytes(str);
|
||||
f.writeInt(d.Length / 2);
|
||||
f.writeBytes(endianReverseUnicode(d));
|
||||
f.writeInt(0);
|
||||
}
|
||||
|
||||
public byte[] Rebuild()
|
||||
{
|
||||
FileOutput f = new FileOutput();
|
||||
f.Endian = Endianness.Big;
|
||||
|
||||
f.writeInt(3);
|
||||
f.writeInt(types.Count);
|
||||
foreach (int type in types.Keys)
|
||||
{
|
||||
f.writeInt(type);
|
||||
writeMinecraftString(f, types[type]);
|
||||
}
|
||||
|
||||
f.writeInt(mineFiles.Count);
|
||||
foreach (MineFile mf in mineFiles)
|
||||
{
|
||||
f.writeInt(mf.data.Length);
|
||||
f.writeInt(mf.type);
|
||||
writeMinecraftString(f, mf.name);
|
||||
}
|
||||
|
||||
foreach (MineFile mf in mineFiles)
|
||||
{
|
||||
string missing = "";
|
||||
try
|
||||
{
|
||||
f.writeInt(mf.entries.Count);
|
||||
foreach (object[] entry in mf.entries)
|
||||
{
|
||||
missing = entry[0].ToString();
|
||||
f.writeInt(typeCodes[(string)entry[0]]);
|
||||
writeMinecraftString(f, (string)entry[1]);
|
||||
}
|
||||
|
||||
f.writeBytes(mf.data);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
MessageBox.Show(missing + " is not in the main metadatabase");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return f.getBytes();
|
||||
}
|
||||
}
|
||||
}
|
||||
33
MinecraftUSkinEditor/Classes/Program.cs
Normal file
33
MinecraftUSkinEditor/Classes/Program.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MinecraftUSkinEditor
|
||||
{
|
||||
|
||||
|
||||
static class Program
|
||||
{
|
||||
public static string baseurl = "http://www.pckstudio.tk/";
|
||||
|
||||
public static FormMain formMain;
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("ja");
|
||||
Thread.CurrentThread.CurrentCulture = ci;
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
minekampf.Forms.goodbye gg = new minekampf.Forms.goodbye();
|
||||
if(!System.IO.File.Exists(Environment.CurrentDirectory + "\\goodbyemark"))
|
||||
gg.ShowDialog();
|
||||
Application.Run(new FormMain());
|
||||
}
|
||||
}
|
||||
}
|
||||
2296
MinecraftUSkinEditor/Classes/RenderBase.cs
Normal file
2296
MinecraftUSkinEditor/Classes/RenderBase.cs
Normal file
File diff suppressed because it is too large
Load Diff
576
MinecraftUSkinEditor/Classes/TextureCodec.cs
Normal file
576
MinecraftUSkinEditor/Classes/TextureCodec.cs
Normal file
@@ -0,0 +1,576 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Ohana3DS_Rebirth.Ohana
|
||||
{
|
||||
class TextureCodec
|
||||
{
|
||||
private static int[] tileOrder = { 0, 1, 8, 9, 2, 3, 10, 11, 16, 17, 24, 25, 18, 19, 26, 27, 4, 5, 12, 13, 6, 7, 14, 15, 20, 21, 28, 29, 22, 23, 30, 31, 32, 33, 40, 41, 34, 35, 42, 43, 48, 49, 56, 57, 50, 51, 58, 59, 36, 37, 44, 45, 38, 39, 46, 47, 52, 53, 60, 61, 54, 55, 62, 63 };
|
||||
private static int[,] etc1LUT = { { 2, 8, -2, -8 }, { 5, 17, -5, -17 }, { 9, 29, -9, -29 }, { 13, 42, -13, -42 }, { 18, 60, -18, -60 }, { 24, 80, -24, -80 }, { 33, 106, -33, -106 }, { 47, 183, -47, -183 } };
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a PICA200 Texture.
|
||||
/// </summary>
|
||||
/// <param name="data">Buffer with the Texture</param>
|
||||
/// <param name="width">Width of the Texture</param>
|
||||
/// <param name="height">Height of the Texture</param>
|
||||
/// <param name="format">Pixel Format of the Texture</param>
|
||||
/// <returns></returns>
|
||||
public static Bitmap decode(byte[] data, int width, int height, RenderBase.OTextureFormat format)
|
||||
{
|
||||
byte[] output = new byte[width * height * 4];
|
||||
long dataOffset = 0;
|
||||
bool toggle = false;
|
||||
|
||||
switch (format)
|
||||
{
|
||||
case RenderBase.OTextureFormat.rgba8:
|
||||
for (int tY = 0; tY < height / 8; tY++)
|
||||
{
|
||||
for (int tX = 0; tX < width / 8; tX++)
|
||||
{
|
||||
for (int pixel = 0; pixel < 64; pixel++)
|
||||
{
|
||||
int x = tileOrder[pixel] % 8;
|
||||
int y = (tileOrder[pixel] - x) / 8;
|
||||
long outputOffset = ((tX * 8) + x + ((tY * 8 + y) * width)) * 4;
|
||||
|
||||
Buffer.BlockCopy(data, (int)dataOffset + 1, output, (int)outputOffset, 3);
|
||||
output[outputOffset + 3] = data[dataOffset];
|
||||
|
||||
dataOffset += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderBase.OTextureFormat.rgb8:
|
||||
for (int tY = 0; tY < height / 8; tY++)
|
||||
{
|
||||
for (int tX = 0; tX < width / 8; tX++)
|
||||
{
|
||||
for (int pixel = 0; pixel < 64; pixel++)
|
||||
{
|
||||
int x = tileOrder[pixel] % 8;
|
||||
int y = (tileOrder[pixel] - x) / 8;
|
||||
long outputOffset = ((tX * 8) + x + (((tY * 8 + y)) * width)) * 4;
|
||||
|
||||
Buffer.BlockCopy(data, (int)dataOffset, output, (int)outputOffset, 3);
|
||||
output[outputOffset + 3] = 0xff;
|
||||
|
||||
dataOffset += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderBase.OTextureFormat.rgba5551:
|
||||
for (int tY = 0; tY < height / 8; tY++)
|
||||
{
|
||||
for (int tX = 0; tX < width / 8; tX++)
|
||||
{
|
||||
for (int pixel = 0; pixel < 64; pixel++)
|
||||
{
|
||||
int x = tileOrder[pixel] % 8;
|
||||
int y = (tileOrder[pixel] - x) / 8;
|
||||
long outputOffset = ((tX * 8) + x + (((tY * 8 + y)) * width)) * 4;
|
||||
|
||||
ushort pixelData = (ushort)(data[dataOffset] | (data[dataOffset + 1] << 8));
|
||||
|
||||
byte r = (byte)(((pixelData >> 1) & 0x1f) << 3);
|
||||
byte g = (byte)(((pixelData >> 6) & 0x1f) << 3);
|
||||
byte b = (byte)(((pixelData >> 11) & 0x1f) << 3);
|
||||
byte a = (byte)((pixelData & 1) * 0xff);
|
||||
|
||||
output[outputOffset] = (byte)(r | (r >> 5));
|
||||
output[outputOffset + 1] = (byte)(g | (g >> 5));
|
||||
output[outputOffset + 2] = (byte)(b | (b >> 5));
|
||||
output[outputOffset + 3] = a;
|
||||
|
||||
dataOffset += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderBase.OTextureFormat.rgb565:
|
||||
for (int tY = 0; tY < height / 8; tY++)
|
||||
{
|
||||
for (int tX = 0; tX < width / 8; tX++)
|
||||
{
|
||||
for (int pixel = 0; pixel < 64; pixel++)
|
||||
{
|
||||
int x = tileOrder[pixel] % 8;
|
||||
int y = (tileOrder[pixel] - x) / 8;
|
||||
long outputOffset = ((tX * 8) + x + (((tY * 8 + y)) * width)) * 4;
|
||||
|
||||
ushort pixelData = (ushort)(data[dataOffset] | (data[dataOffset + 1] << 8));
|
||||
|
||||
byte r = (byte)((pixelData & 0x1f) << 3);
|
||||
byte g = (byte)(((pixelData >> 5) & 0x3f) << 2);
|
||||
byte b = (byte)(((pixelData >> 11) & 0x1f) << 3);
|
||||
|
||||
output[outputOffset] = (byte)(r | (r >> 5));
|
||||
output[outputOffset + 1] = (byte)(g | (g >> 6));
|
||||
output[outputOffset + 2] = (byte)(b | (b >> 5));
|
||||
output[outputOffset + 3] = 0xff;
|
||||
|
||||
dataOffset += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderBase.OTextureFormat.rgba4:
|
||||
for (int tY = 0; tY < height / 8; tY++)
|
||||
{
|
||||
for (int tX = 0; tX < width / 8; tX++)
|
||||
{
|
||||
for (int pixel = 0; pixel < 64; pixel++)
|
||||
{
|
||||
int x = tileOrder[pixel] % 8;
|
||||
int y = (tileOrder[pixel] - x) / 8;
|
||||
long outputOffset = ((tX * 8) + x + (((tY * 8 + y)) * width)) * 4;
|
||||
|
||||
ushort pixelData = (ushort)(data[dataOffset] | (data[dataOffset + 1] << 8));
|
||||
|
||||
byte r = (byte)((pixelData >> 4) & 0xf);
|
||||
byte g = (byte)((pixelData >> 8) & 0xf);
|
||||
byte b = (byte)((pixelData >> 12) & 0xf);
|
||||
byte a = (byte)(pixelData & 0xf);
|
||||
|
||||
output[outputOffset] = (byte)(r | (r << 4));
|
||||
output[outputOffset + 1] = (byte)(g | (g << 4));
|
||||
output[outputOffset + 2] = (byte)(b | (b << 4));
|
||||
output[outputOffset + 3] = (byte)(a | (a << 4));
|
||||
|
||||
dataOffset += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderBase.OTextureFormat.la8:
|
||||
case RenderBase.OTextureFormat.hilo8:
|
||||
for (int tY = 0; tY < height / 8; tY++)
|
||||
{
|
||||
for (int tX = 0; tX < width / 8; tX++)
|
||||
{
|
||||
for (int pixel = 0; pixel < 64; pixel++)
|
||||
{
|
||||
int x = tileOrder[pixel] % 8;
|
||||
int y = (tileOrder[pixel] - x) / 8;
|
||||
long outputOffset = ((tX * 8) + x + (((tY * 8 + y)) * width)) * 4;
|
||||
|
||||
output[outputOffset] = data[dataOffset];
|
||||
output[outputOffset + 1] = data[dataOffset];
|
||||
output[outputOffset + 2] = data[dataOffset];
|
||||
output[outputOffset + 3] = data[dataOffset + 1];
|
||||
|
||||
dataOffset += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderBase.OTextureFormat.l8:
|
||||
for (int tY = 0; tY < height / 8; tY++)
|
||||
{
|
||||
for (int tX = 0; tX < width / 8; tX++)
|
||||
{
|
||||
for (int pixel = 0; pixel < 64; pixel++)
|
||||
{
|
||||
int x = tileOrder[pixel] % 8;
|
||||
int y = (tileOrder[pixel] - x) / 8;
|
||||
long outputOffset = ((tX * 8) + x + (((tY * 8 + y)) * width)) * 4;
|
||||
|
||||
output[outputOffset] = data[dataOffset];
|
||||
output[outputOffset + 1] = data[dataOffset];
|
||||
output[outputOffset + 2] = data[dataOffset];
|
||||
output[outputOffset + 3] = 0xff;
|
||||
|
||||
dataOffset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderBase.OTextureFormat.a8:
|
||||
for (int tY = 0; tY < height / 8; tY++)
|
||||
{
|
||||
for (int tX = 0; tX < width / 8; tX++)
|
||||
{
|
||||
for (int pixel = 0; pixel < 64; pixel++)
|
||||
{
|
||||
int x = tileOrder[pixel] % 8;
|
||||
int y = (tileOrder[pixel] - x) / 8;
|
||||
long outputOffset = ((tX * 8) + x + (((tY * 8 + y)) * width)) * 4;
|
||||
|
||||
output[outputOffset] = 0xff;
|
||||
output[outputOffset + 1] = 0xff;
|
||||
output[outputOffset + 2] = 0xff;
|
||||
output[outputOffset + 3] = data[dataOffset];
|
||||
|
||||
dataOffset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderBase.OTextureFormat.la4:
|
||||
for (int tY = 0; tY < height / 8; tY++)
|
||||
{
|
||||
for (int tX = 0; tX < width / 8; tX++)
|
||||
{
|
||||
for (int pixel = 0; pixel < 64; pixel++)
|
||||
{
|
||||
int x = tileOrder[pixel] % 8;
|
||||
int y = (tileOrder[pixel] - x) / 8;
|
||||
long outputOffset = ((tX * 8) + x + (((tY * 8 + y)) * width)) * 4;
|
||||
|
||||
output[outputOffset] = (byte)(data[dataOffset] >> 4);
|
||||
output[outputOffset + 1] = (byte)(data[dataOffset] >> 4);
|
||||
output[outputOffset + 2] = (byte)(data[dataOffset] >> 4);
|
||||
output[outputOffset + 3] = (byte)(data[dataOffset] & 0xf);
|
||||
|
||||
dataOffset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderBase.OTextureFormat.l4:
|
||||
for (int tY = 0; tY < height / 8; tY++)
|
||||
{
|
||||
for (int tX = 0; tX < width / 8; tX++)
|
||||
{
|
||||
for (int pixel = 0; pixel < 64; pixel++)
|
||||
{
|
||||
int x = tileOrder[pixel] % 8;
|
||||
int y = (tileOrder[pixel] - x) / 8;
|
||||
long outputOffset = ((tX * 8) + x + (((tY * 8 + y)) * width)) * 4;
|
||||
|
||||
byte c = toggle ? (byte)((data[dataOffset++] & 0xf0) >> 4) : (byte)(data[dataOffset] & 0xf);
|
||||
toggle = !toggle;
|
||||
c = (byte)((c << 4) | c);
|
||||
output[outputOffset] = c;
|
||||
output[outputOffset + 1] = c;
|
||||
output[outputOffset + 2] = c;
|
||||
output[outputOffset + 3] = 0xff;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderBase.OTextureFormat.a4:
|
||||
for (int tY = 0; tY < height / 8; tY++)
|
||||
{
|
||||
for (int tX = 0; tX < width / 8; tX++)
|
||||
{
|
||||
for (int pixel = 0; pixel < 64; pixel++)
|
||||
{
|
||||
int x = tileOrder[pixel] % 8;
|
||||
int y = (tileOrder[pixel] - x) / 8;
|
||||
long outputOffset = ((tX * 8) + x + (((tY * 8 + y)) * width)) * 4;
|
||||
|
||||
output[outputOffset] = 0xff;
|
||||
output[outputOffset + 1] = 0xff;
|
||||
output[outputOffset + 2] = 0xff;
|
||||
byte a = toggle ? (byte)((data[dataOffset++] & 0xf0) >> 4) : (byte)(data[dataOffset] & 0xf);
|
||||
toggle = !toggle;
|
||||
output[outputOffset + 3] = (byte)((a << 4) | a);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case RenderBase.OTextureFormat.etc1:
|
||||
case RenderBase.OTextureFormat.etc1a4:
|
||||
byte[] decodedData = etc1Decode(data, width, height, format == RenderBase.OTextureFormat.etc1a4);
|
||||
int[] etc1Order = etc1Scramble(width, height);
|
||||
|
||||
int i = 0;
|
||||
for (int tY = 0; tY < height / 4; tY++) {
|
||||
for (int tX = 0; tX < width / 4; tX++) {
|
||||
int TX = etc1Order[i] % (width / 4);
|
||||
int TY = (etc1Order[i] - TX) / (width / 4);
|
||||
for (int y = 0; y < 4; y++) {
|
||||
for (int x = 0; x < 4; x++) {
|
||||
dataOffset = ((TX * 4) + x + (((TY * 4) + y) * width)) * 4;
|
||||
long outputOffset = ((tX * 4) + x + (((tY * 4 + y)) * width)) * 4;
|
||||
|
||||
Buffer.BlockCopy(decodedData, (int)dataOffset, output, (int)outputOffset, 4);
|
||||
}
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return TextureUtils.getBitmap(output.ToArray(), width, height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes a PICA200 Texture.
|
||||
/// </summary>
|
||||
/// <param name="img">Input image to be encoded</param>
|
||||
/// <param name="format">Pixel Format of the Texture</param>
|
||||
/// <returns></returns>
|
||||
public static byte[] encode(Bitmap img, RenderBase.OTextureFormat format)
|
||||
{
|
||||
byte[] data = TextureUtils.getArray(img);
|
||||
byte[] output = new byte[data.Length];
|
||||
|
||||
uint outputOffset = 0;
|
||||
switch (format)
|
||||
{
|
||||
case RenderBase.OTextureFormat.rgba8:
|
||||
for (int tY = 0; tY < img.Height / 8; tY++)
|
||||
{
|
||||
for (int tX = 0; tX < img.Width / 8; tX++)
|
||||
{
|
||||
for (int pixel = 0; pixel < 64; pixel++)
|
||||
{
|
||||
int x = tileOrder[pixel] % 8;
|
||||
int y = (tileOrder[pixel] - x) / 8;
|
||||
long dataOffset = ((tX * 8) + x + ((tY * 8 + y) * img.Width)) * 4;
|
||||
|
||||
Buffer.BlockCopy(data, (int)dataOffset, output, (int)outputOffset + 1, 3);
|
||||
output[outputOffset] = data[dataOffset + 3];
|
||||
|
||||
outputOffset += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default: throw new NotImplementedException();
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
#region "ETC1"
|
||||
private static byte[] etc1Decode(byte[] input, int width, int height, bool alpha)
|
||||
{
|
||||
byte[] output = new byte[(width * height * 4)];
|
||||
long offset = 0;
|
||||
|
||||
for (int y = 0; y < height / 4; y++)
|
||||
{
|
||||
for (int x = 0; x < width / 4; x++)
|
||||
{
|
||||
byte[] colorBlock = new byte[8];
|
||||
byte[] alphaBlock = new byte[8];
|
||||
if (alpha)
|
||||
{
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
colorBlock[7 - i] = input[offset + 8 + i];
|
||||
alphaBlock[i] = input[offset + i];
|
||||
}
|
||||
offset += 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
colorBlock[7 - i] = input[offset + i];
|
||||
alphaBlock[i] = 0xff;
|
||||
}
|
||||
offset += 8;
|
||||
}
|
||||
|
||||
colorBlock = etc1DecodeBlock(colorBlock);
|
||||
|
||||
bool toggle = false;
|
||||
long alphaOffset = 0;
|
||||
for (int tX = 0; tX < 4; tX++)
|
||||
{
|
||||
for (int tY = 0; tY < 4; tY++)
|
||||
{
|
||||
int outputOffset = (x * 4 + tX + ((y * 4 + tY) * width)) * 4;
|
||||
int blockOffset = (tX + (tY * 4)) * 4;
|
||||
Buffer.BlockCopy(colorBlock, blockOffset, output, outputOffset, 3);
|
||||
|
||||
byte a = toggle ? (byte)((alphaBlock[alphaOffset++] & 0xf0) >> 4) : (byte)(alphaBlock[alphaOffset] & 0xf);
|
||||
output[outputOffset + 3] = (byte)((a << 4) | a);
|
||||
toggle = !toggle;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private static byte[] etc1DecodeBlock(byte[] data)
|
||||
{
|
||||
uint blockTop = BitConverter.ToUInt32(data, 0);
|
||||
uint blockBottom = BitConverter.ToUInt32(data, 4);
|
||||
|
||||
bool flip = (blockTop & 0x1000000) > 0;
|
||||
bool difference = (blockTop & 0x2000000) > 0;
|
||||
|
||||
uint r1, g1, b1;
|
||||
uint r2, g2, b2;
|
||||
|
||||
if (difference)
|
||||
{
|
||||
r1 = blockTop & 0xf8;
|
||||
g1 = (blockTop & 0xf800) >> 8;
|
||||
b1 = (blockTop & 0xf80000) >> 16;
|
||||
|
||||
r2 = (uint)((sbyte)(r1 >> 3) + ((sbyte)((blockTop & 7) << 5) >> 5));
|
||||
g2 = (uint)((sbyte)(g1 >> 3) + ((sbyte)((blockTop & 0x700) >> 3) >> 5));
|
||||
b2 = (uint)((sbyte)(b1 >> 3) + ((sbyte)((blockTop & 0x70000) >> 11) >> 5));
|
||||
|
||||
r1 |= r1 >> 5;
|
||||
g1 |= g1 >> 5;
|
||||
b1 |= b1 >> 5;
|
||||
|
||||
r2 = (r2 << 3) | (r2 >> 2);
|
||||
g2 = (g2 << 3) | (g2 >> 2);
|
||||
b2 = (b2 << 3) | (b2 >> 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
r1 = blockTop & 0xf0;
|
||||
g1 = (blockTop & 0xf000) >> 8;
|
||||
b1 = (blockTop & 0xf00000) >> 16;
|
||||
|
||||
r2 = (blockTop & 0xf) << 4;
|
||||
g2 = (blockTop & 0xf00) >> 4;
|
||||
b2 = (blockTop & 0xf0000) >> 12;
|
||||
|
||||
r1 |= r1 >> 4;
|
||||
g1 |= g1 >> 4;
|
||||
b1 |= b1 >> 4;
|
||||
|
||||
r2 |= r2 >> 4;
|
||||
g2 |= g2 >> 4;
|
||||
b2 |= b2 >> 4;
|
||||
}
|
||||
|
||||
uint table1 = (blockTop >> 29) & 7;
|
||||
uint table2 = (blockTop >> 26) & 7;
|
||||
|
||||
byte[] output = new byte[(4 * 4 * 4)];
|
||||
if (!flip)
|
||||
{
|
||||
for (int y = 0; y <= 3; y++)
|
||||
{
|
||||
for (int x = 0; x <= 1; x++)
|
||||
{
|
||||
Color color1 = etc1Pixel(r1, g1, b1, x, y, blockBottom, table1);
|
||||
Color color2 = etc1Pixel(r2, g2, b2, x + 2, y, blockBottom, table2);
|
||||
|
||||
int offset1 = (y * 4 + x) * 4;
|
||||
output[offset1] = color1.B;
|
||||
output[offset1 + 1] = color1.G;
|
||||
output[offset1 + 2] = color1.R;
|
||||
|
||||
int offset2 = (y * 4 + x + 2) * 4;
|
||||
output[offset2] = color2.B;
|
||||
output[offset2 + 1] = color2.G;
|
||||
output[offset2 + 2] = color2.R;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int y = 0; y <= 1; y++)
|
||||
{
|
||||
for (int x = 0; x <= 3; x++)
|
||||
{
|
||||
Color color1 = etc1Pixel(r1, g1, b1, x, y, blockBottom, table1);
|
||||
Color color2 = etc1Pixel(r2, g2, b2, x, y + 2, blockBottom, table2);
|
||||
|
||||
int offset1 = (y * 4 + x) * 4;
|
||||
output[offset1] = color1.B;
|
||||
output[offset1 + 1] = color1.G;
|
||||
output[offset1 + 2] = color1.R;
|
||||
|
||||
int offset2 = ((y + 2) * 4 + x) * 4;
|
||||
output[offset2] = color2.B;
|
||||
output[offset2 + 1] = color2.G;
|
||||
output[offset2 + 2] = color2.R;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private static Color etc1Pixel(uint r, uint g, uint b, int x, int y, uint block, uint table)
|
||||
{
|
||||
int index = x * 4 + y;
|
||||
uint MSB = block << 1;
|
||||
|
||||
int pixel = index < 8
|
||||
? etc1LUT[table, ((block >> (index + 24)) & 1) + ((MSB >> (index + 8)) & 2)]
|
||||
: etc1LUT[table, ((block >> (index + 8)) & 1) + ((MSB >> (index - 8)) & 2)];
|
||||
|
||||
r = saturate((int)(r + pixel));
|
||||
g = saturate((int)(g + pixel));
|
||||
b = saturate((int)(b + pixel));
|
||||
|
||||
return Color.FromArgb((int)r, (int)g, (int)b);
|
||||
}
|
||||
|
||||
private static byte saturate(int value)
|
||||
{
|
||||
if (value > 0xff) return 0xff;
|
||||
if (value < 0) return 0;
|
||||
return (byte)(value & 0xff);
|
||||
}
|
||||
|
||||
private static int[] etc1Scramble(int width, int height)
|
||||
{
|
||||
//Maybe theres a better way to do this?
|
||||
int[] tileScramble = new int[((width / 4) * (height / 4))];
|
||||
int baseAccumulator = 0;
|
||||
int rowAccumulator = 0;
|
||||
int baseNumber = 0;
|
||||
int rowNumber = 0;
|
||||
|
||||
for (int tile = 0; tile < tileScramble.Length; tile++)
|
||||
{
|
||||
if ((tile % (width / 4) == 0) && tile > 0)
|
||||
{
|
||||
if (rowAccumulator < 1)
|
||||
{
|
||||
rowAccumulator += 1;
|
||||
rowNumber += 2;
|
||||
baseNumber = rowNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
rowAccumulator = 0;
|
||||
baseNumber -= 2;
|
||||
rowNumber = baseNumber;
|
||||
}
|
||||
}
|
||||
|
||||
tileScramble[tile] = baseNumber;
|
||||
|
||||
if (baseAccumulator < 1)
|
||||
{
|
||||
baseAccumulator++;
|
||||
baseNumber++;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseAccumulator = 0;
|
||||
baseNumber += 3;
|
||||
}
|
||||
}
|
||||
|
||||
return tileScramble;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
39
MinecraftUSkinEditor/Classes/TextureUtils.cs
Normal file
39
MinecraftUSkinEditor/Classes/TextureUtils.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ohana3DS_Rebirth.Ohana
|
||||
{
|
||||
class TextureUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a Bitmap from a RGBA8 Texture buffer.
|
||||
/// </summary>
|
||||
/// <param name="array">The Buffer</param>
|
||||
/// <param name="width">Width of the Texture</param>
|
||||
/// <param name="height">Height of the Texture</param>
|
||||
/// <returns></returns>
|
||||
public static Bitmap getBitmap(byte[] array, int width, int height)
|
||||
{
|
||||
Bitmap img = new Bitmap(width, height, PixelFormat.Format32bppArgb);
|
||||
BitmapData imgData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
|
||||
Marshal.Copy(array, 0, imgData.Scan0, array.Length);
|
||||
img.UnlockBits(imgData);
|
||||
return img;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a RGBA8 Texture Buffer from a Bitmap.
|
||||
/// </summary>
|
||||
/// <param name="img">The Bitmap</param>
|
||||
/// <returns></returns>
|
||||
public static byte[] getArray(Bitmap img)
|
||||
{
|
||||
BitmapData imgData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||
byte[] array = new byte[imgData.Stride * img.Height];
|
||||
Marshal.Copy(imgData.Scan0, array, 0, array.Length);
|
||||
img.UnlockBits(imgData);
|
||||
return array;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user