mirror of
https://github.com/kwsch/pk3DS.git
synced 2026-10-01 21:36:43 -05:00
Fix tmhm accessing for gen7
might as well replace the indexof method with a less convoluted method, should be faster
This commit is contained in:
@@ -16,7 +16,7 @@ public TMEditor7()
|
||||
if (!File.Exists(files[0]) || !Path.GetFileNameWithoutExtension(files[0]).Contains("code")) { Util.Alert("No .code.bin detected."); Close(); }
|
||||
data = File.ReadAllBytes(files[0]);
|
||||
if (data.Length % 0x200 != 0) { Util.Alert(".code.bin not decompressed. Aborting."); Close(); }
|
||||
offset = Util.IndexOfBytes(data, Signature, 0x500000, 0) + 8;
|
||||
offset = Util.IndexOfBytes(data, Signature, 0x400000, 0) + Signature.Length;
|
||||
codebin = files[0];
|
||||
movelist[0] = "";
|
||||
setupDGV();
|
||||
@@ -119,7 +119,7 @@ internal static void getTMHMList(ref ushort[] TMs)
|
||||
string[] files = Directory.GetFiles(Main.ExeFSPath);
|
||||
if (!File.Exists(files[0]) || !Path.GetFileNameWithoutExtension(files[0]).Contains("code")) return;
|
||||
byte[] data = File.ReadAllBytes(files[0]);
|
||||
int dataoffset = Util.IndexOfBytes(data, Signature, 0x500000, 0) + 8;
|
||||
int dataoffset = Util.IndexOfBytes(data, Signature, 0x400000, 0) + Signature.Length;
|
||||
if (data.Length % 0x200 != 0) return;
|
||||
|
||||
List<ushort> tms = new List<ushort>();
|
||||
|
||||
@@ -592,16 +592,15 @@ internal static char[] Reverse(char[] charArray)
|
||||
// Find Code off of Reference
|
||||
internal static int IndexOfBytes(byte[] array, byte[] pattern, int startIndex, int count)
|
||||
{
|
||||
int i = startIndex;
|
||||
int endIndex = count > 0 ? startIndex + count : array.Length;
|
||||
int fidx = 0;
|
||||
|
||||
while (i++ != endIndex - 1)
|
||||
int len = pattern.Length;
|
||||
int endIndex = count > 0 ? startIndex + count + 1 : array.Length;
|
||||
for (int i = startIndex; i < endIndex; i++)
|
||||
{
|
||||
if (array[i] != pattern[fidx]) i -= fidx;
|
||||
fidx = (array[i] == pattern[fidx]) ? ++fidx : 0;
|
||||
if (fidx == pattern.Length)
|
||||
return i - fidx + 1;
|
||||
for (int j = 0; j < len; j++)
|
||||
if (pattern[j] != array[i + j])
|
||||
goto next_i;
|
||||
return i;
|
||||
next_i:;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user