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:
Kurt
2016-12-04 11:05:28 -08:00
parent ec964c4ec1
commit cd74212694
2 changed files with 10 additions and 11 deletions

View File

@@ -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>();

View File

@@ -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;
}