|
|
@ -15,7 +15,6 @@ namespace NetMFAPatcher.Utils
|
|
|
|
{
|
|
|
|
{
|
|
|
|
static class Helper
|
|
|
|
static class Helper
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public static string CleanInput(string strIn)
|
|
|
|
public static string CleanInput(string strIn)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -39,55 +38,58 @@ namespace NetMFAPatcher.Utils
|
|
|
|
if (i > 0)
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
temp += " " + item.ToString(format);
|
|
|
|
temp += " " + item.ToString(format);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
temp += item.ToString(format);
|
|
|
|
temp += item.ToString(format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (log)
|
|
|
|
if (log)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(temp);
|
|
|
|
Console.WriteLine(temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return temp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static string AutoReadUnicode(ByteIO reader)
|
|
|
|
|
|
|
|
|
|
|
|
public static string AutoReadUnicode(ByteReader reader)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var len = reader.ReadInt16();
|
|
|
|
var len = reader.ReadInt16();
|
|
|
|
reader.Skip(2);
|
|
|
|
reader.Skip(2);
|
|
|
|
return reader.ReadWideString(len);
|
|
|
|
return reader.ReadWideString(len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static void AutoWriteUnicode(this ByteWriter writer,string value)
|
|
|
|
|
|
|
|
|
|
|
|
public static void AutoWriteUnicode(this ByteWriter writer, string value)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
writer.WriteInt16((short)value.Length);
|
|
|
|
writer.WriteInt16((short) value.Length);
|
|
|
|
writer.Skip(2);
|
|
|
|
writer.Skip(2);
|
|
|
|
writer.WriteUnicode(value);
|
|
|
|
writer.WriteUnicode(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static DataLoader LoadParameter(int code, ByteIO reader)
|
|
|
|
|
|
|
|
|
|
|
|
public static DataLoader LoadParameter(int code, ByteReader reader)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
DataLoader item = null;
|
|
|
|
DataLoader item = null;
|
|
|
|
if (code == 1)
|
|
|
|
if (code == 1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
item = new ParamObject(reader);
|
|
|
|
item = new ParamObject(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (code == 2)
|
|
|
|
if (code == 2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
item = new Time(reader);
|
|
|
|
item = new Time(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (code==3|| code == 10|| code == 11 || code == 12 || code == 17 || code == 26 || code == 31 || code == 43 || code == 57 || code == 58 || code == 60 || code == 61)
|
|
|
|
|
|
|
|
|
|
|
|
if (code == 3 || code == 10 || code == 11 || code == 12 || code == 17 || code == 26 || code == 31 ||
|
|
|
|
|
|
|
|
code == 43 || code == 57 || code == 58 || code == 60 || code == 61)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
item = new Short(reader);
|
|
|
|
item = new Short(reader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static string GetHex(this byte[] data, int count=-1,int position=0)
|
|
|
|
|
|
|
|
|
|
|
|
public static string GetHex(this byte[] data, int count = -1, int position = 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var actualCount = count;
|
|
|
|
var actualCount = count;
|
|
|
|
if (actualCount == -1) actualCount = data.Length;
|
|
|
|
if (actualCount == -1) actualCount = data.Length;
|
|
|
@ -97,6 +99,7 @@ namespace NetMFAPatcher.Utils
|
|
|
|
temp += data[i].ToString("X2");
|
|
|
|
temp += data[i].ToString("X2");
|
|
|
|
temp += " ";
|
|
|
|
temp += " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -112,13 +115,10 @@ namespace NetMFAPatcher.Utils
|
|
|
|
if (b < 128 && b > 32) charAcc += Convert.ToChar(b);
|
|
|
|
if (b < 128 && b > 32) charAcc += Convert.ToChar(b);
|
|
|
|
else charAcc += '.';
|
|
|
|
else charAcc += '.';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var bLen = block.Count();
|
|
|
|
var bLen = block.Count();
|
|
|
|
//var accLen=
|
|
|
|
//var accLen=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static byte[] GetContents(this ByteWriter wrt)
|
|
|
|
public static byte[] GetContents(this ByteWriter wrt)
|
|
|
@ -126,12 +126,12 @@ namespace NetMFAPatcher.Utils
|
|
|
|
var buff = new byte[wrt.BaseStream.Length];
|
|
|
|
var buff = new byte[wrt.BaseStream.Length];
|
|
|
|
for (int i = 0; i < wrt.BaseStream.Length; i++)
|
|
|
|
for (int i = 0; i < wrt.BaseStream.Length; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
buff.Append<byte>((byte)wrt.BaseStream.ReadByte());
|
|
|
|
buff.Append<byte>((byte) wrt.BaseStream.ReadByte());
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return buff;
|
|
|
|
return buff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Splits an array into several smaller arrays.
|
|
|
|
/// Splits an array into several smaller arrays.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
@ -141,7 +141,7 @@ namespace NetMFAPatcher.Utils
|
|
|
|
/// <returns>An array containing smaller arrays.</returns>
|
|
|
|
/// <returns>An array containing smaller arrays.</returns>
|
|
|
|
public static IEnumerable<IEnumerable<T>> Split<T>(this T[] array, int size)
|
|
|
|
public static IEnumerable<IEnumerable<T>> Split<T>(this T[] array, int size)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (var i = 0; i < (float)array.Length / size; i++)
|
|
|
|
for (var i = 0; i < (float) array.Length / size; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
yield return array.Skip(i * size).Take(size);
|
|
|
|
yield return array.Skip(i * size).Take(size);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -150,7 +150,7 @@ namespace NetMFAPatcher.Utils
|
|
|
|
public static List<Color> GetColors(this byte[] bytes)
|
|
|
|
public static List<Color> GetColors(this byte[] bytes)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
List<Color> colors = new List<Color>();
|
|
|
|
List<Color> colors = new List<Color>();
|
|
|
|
for (int i = 0; i < bytes.Length; i+=4)
|
|
|
|
for (int i = 0; i < bytes.Length; i += 4)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var color = Color.FromArgb(bytes[i], bytes[i + 1], bytes[i + 2], bytes[i + 3]);
|
|
|
|
var color = Color.FromArgb(bytes[i], bytes[i + 1], bytes[i + 2], bytes[i + 3]);
|
|
|
|
colors.Add(color);
|
|
|
|
colors.Add(color);
|
|
|
@ -161,10 +161,11 @@ namespace NetMFAPatcher.Utils
|
|
|
|
|
|
|
|
|
|
|
|
public static void CheckPattern(object source, object pattern)
|
|
|
|
public static void CheckPattern(object source, object pattern)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (source.GetType() != pattern.GetType()) throw new InvalidDataException("Data is not valid: types are different");
|
|
|
|
if (source.GetType() != pattern.GetType())
|
|
|
|
|
|
|
|
throw new InvalidDataException("Data is not valid: types are different");
|
|
|
|
if (source is string)
|
|
|
|
if (source is string)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ((string)source != (string)pattern)
|
|
|
|
if ((string) source != (string) pattern)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
throw new InvalidDataException($"Data is not valid: {source} != {pattern}");
|
|
|
|
throw new InvalidDataException($"Data is not valid: {source} != {pattern}");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -178,13 +179,14 @@ namespace NetMFAPatcher.Utils
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void OnImageSaved(int index,int all)
|
|
|
|
public static void OnImageSaved(int index, int all)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Program.MyForm.UpdateImageBar(index,all);
|
|
|
|
Program.MyForm.UpdateImageBar(index, all);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public static void OnSoundSaved(int index,int all)
|
|
|
|
|
|
|
|
|
|
|
|
public static void OnSoundSaved(int index, int all)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Program.MyForm.UpdateSoundBar(index,all);
|
|
|
|
Program.MyForm.UpdateSoundBar(index, all);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private const long OneKb = 1024;
|
|
|
|
private const long OneKb = 1024;
|
|
|
@ -194,65 +196,65 @@ namespace NetMFAPatcher.Utils
|
|
|
|
|
|
|
|
|
|
|
|
public static string ToPrettySize(this int value, int decimalPlaces = 0)
|
|
|
|
public static string ToPrettySize(this int value, int decimalPlaces = 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return ((long)value).ToPrettySize(decimalPlaces);
|
|
|
|
return ((long) value).ToPrettySize(decimalPlaces);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string ToPrettySize(this long value, int decimalPlaces = 0)
|
|
|
|
public static string ToPrettySize(this long value, int decimalPlaces = 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var asTb = Math.Round((double)value / OneTb, decimalPlaces);
|
|
|
|
var asTb = Math.Round((double) value / OneTb, decimalPlaces);
|
|
|
|
var asGb = Math.Round((double)value / OneGb, decimalPlaces);
|
|
|
|
var asGb = Math.Round((double) value / OneGb, decimalPlaces);
|
|
|
|
var asMb = Math.Round((double)value / OneMb, decimalPlaces);
|
|
|
|
var asMb = Math.Round((double) value / OneMb, decimalPlaces);
|
|
|
|
var asKb = Math.Round((double)value / OneKb, decimalPlaces);
|
|
|
|
var asKb = Math.Round((double) value / OneKb, decimalPlaces);
|
|
|
|
string chosenValue = asTb > 1 ? string.Format("{0} TB",asTb)
|
|
|
|
string chosenValue = asTb > 1 ? string.Format("{0} TB", asTb)
|
|
|
|
: asGb > 1 ? string.Format("{0} GB",asGb)
|
|
|
|
: asGb > 1 ? string.Format("{0} GB", asGb)
|
|
|
|
: asMb > 1 ? string.Format("{0} MB",asMb)
|
|
|
|
: asMb > 1 ? string.Format("{0} MB", asMb)
|
|
|
|
: asKb > 1 ? string.Format("{0} KB",asKb)
|
|
|
|
: asKb > 1 ? string.Format("{0} KB", asKb)
|
|
|
|
: string.Format("{0} B", Math.Round((double)value, decimalPlaces));
|
|
|
|
: string.Format("{0} B", Math.Round((double) value, decimalPlaces));
|
|
|
|
return chosenValue;
|
|
|
|
return chosenValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string ActualName(this ChunkList.Chunk chunk)
|
|
|
|
public static string ActualName(this ChunkList.Chunk chunk)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var constName = ((Constants.ChunkNames)chunk.Id).ToString();
|
|
|
|
var constName = ((Constants.ChunkNames) chunk.Id).ToString();
|
|
|
|
int tempId = 0;
|
|
|
|
int tempId = 0;
|
|
|
|
int.TryParse(constName,out tempId);
|
|
|
|
int.TryParse(constName, out tempId);
|
|
|
|
if (tempId != chunk.Id) return constName;
|
|
|
|
if (tempId != chunk.Id) return constName;
|
|
|
|
else return $"Unknown-{chunk.Id}";
|
|
|
|
else return $"Unknown-{chunk.Id}";
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static ChunkNode GetChunkNode(ChunkList.Chunk chunk,string customName = "[DEFAULT-NAME]")
|
|
|
|
public static ChunkNode GetChunkNode(ChunkList.Chunk chunk, string customName = "[DEFAULT-NAME]")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ChunkNode node = null;
|
|
|
|
ChunkNode node = null;
|
|
|
|
if (chunk.Loader != null)
|
|
|
|
if (chunk.Loader != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
node = new ChunkNode(chunk.Name,chunk.Loader);
|
|
|
|
node = new ChunkNode(chunk.Name, chunk.Loader);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
node = new ChunkNode(chunk.Name,chunk);
|
|
|
|
node = new ChunkNode(chunk.Name, chunk);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (customName != "[DEFAULT-NAME]")
|
|
|
|
if (customName != "[DEFAULT-NAME]")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
node.Text = customName;
|
|
|
|
node.Text = customName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Animation GetClosestAnimation(int index, Dictionary<int,Animation> animDict,int count)
|
|
|
|
public static Animation GetClosestAnimation(int index, Dictionary<int, Animation> animDict, int count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return animDict[index];
|
|
|
|
return animDict[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch {}
|
|
|
|
catch
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("kernel32.dll")]
|
|
|
|
[DllImport("kernel32.dll")]
|
|
|
|
public static extern IntPtr GetConsoleWindow();
|
|
|
|
public static extern IntPtr GetConsoleWindow();
|
|
|
|
|
|
|
|
|
|
|
@ -263,7 +265,24 @@ namespace NetMFAPatcher.Utils
|
|
|
|
public const int SW_SHOW = 5;
|
|
|
|
public const int SW_SHOW = 5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static T[] To1DArray<T>(T[,] input)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Step 1: get total size of 2D array, and allocate 1D array.
|
|
|
|
|
|
|
|
int size = input.Length;
|
|
|
|
|
|
|
|
T[] result = new T[size];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Step 2: copy 2D array elements into a 1D array.
|
|
|
|
|
|
|
|
int write = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i <= input.GetUpperBound(0); i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (int z = 0; z <= input.GetUpperBound(1); z++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
result[write++] = input[i, z];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Step 3: return the new array.
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|