Add patched offset detection for Mart6/Tutor6

Closes #147
Thanks @sora10pls !
This commit is contained in:
Kurt 2017-07-10 19:19:16 -07:00
parent 5aa13871d3
commit 53b21f17ee
2 changed files with 56 additions and 3 deletions

View File

@ -15,7 +15,7 @@ public MartEditor6()
if (!File.Exists(files[0]) || !Path.GetFileNameWithoutExtension(files[0]).Contains("code")) { WinFormsUtil.Alert("No .code.bin detected."); Close(); }
data = File.ReadAllBytes(files[0]);
if (data.Length % 0x200 != 0) { WinFormsUtil.Alert(".code.bin not decompressed. Aborting."); Close(); }
offset = Util.IndexOfBytes(data, new byte[] { 0x00, 0x72, 0x6F, 0x6D, 0x3A, 0x2F, 0x44, 0x6C, 0x6C, 0x53, 0x74, 0x61, 0x72, 0x74, 0x4D, 0x65, 0x6E, 0x75, 0x2E, 0x63, 0x72, 0x6F, 0x00 }, 0x400000, 0) + 0x17;
offset = GetDataOffset();
codebin = files[0];
itemlist[0] = "";
setupDGV();
@ -23,6 +23,30 @@ public MartEditor6()
CB_Location.SelectedIndex = 0;
}
private int GetDataOffset()
{
byte[] vanilla =
{
0x00, 0x72, 0x6F, 0x6D, 0x3A, 0x2F, 0x44, 0x6C, 0x6C, 0x53, 0x74, 0x61, 0x72, 0x74, 0x4D, 0x65,
0x6E, 0x75, 0x2E, 0x63, 0x72, 0x6F, 0x00
};
int o = Util.IndexOfBytes(data, vanilla, 0x400000, 0);
if (offset >= 0)
return o + vanilla.Length;
byte[] patched =
{
0x00, 0x72, 0x6F, 0x6D, 0x32, 0x3A, 0x2F, 0x44, 0x6C, 0x6C, 0x53, 0x74, 0x61, 0x72, 0x74, 0x4D,
0x65, 0x6E, 0x75, 0x2E, 0x63, 0x72, 0x6F, 0x00
};
o = Util.IndexOfBytes(data, patched, 0x400000, 0);
if (offset >= 0)
return o + patched.Length;
return -1;
}
private readonly string codebin;
private readonly string[] itemlist = Main.Config.getText(TextName.ItemNames);
private readonly byte[] data;
@ -52,7 +76,7 @@ public MartEditor6()
3, // Balls
};
private readonly int offset = Main.Config.ORAS ? 0x0047AB58 : 0x0043C89E;
private readonly int offset;
private int dataoffset;
readonly string[] locations = Main.Config.ORAS

View File

@ -15,6 +15,7 @@ public TutorEditor6()
if (!File.Exists(files[0]) || !Path.GetFileNameWithoutExtension(files[0]).Contains("code")) { WinFormsUtil.Alert("No .code.bin detected."); Close(); }
data = File.ReadAllBytes(files[0]);
if (data.Length % 0x200 != 0) { WinFormsUtil.Alert(".code.bin not decompressed. Aborting."); Close(); }
offset = GetDataOffset();
codebin = files[0];
movelist[0] = "";
setupDGV();
@ -23,11 +24,39 @@ public TutorEditor6()
WinFormsUtil.Alert("Changes made do not reflect ingame.", "Still needs more research.");
}
private int GetDataOffset()
{
byte[] vanilla =
{
0x00, 0x46, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x54, 0x79, 0x70, 0x65, 0x00, 0x00, 0x45, 0x64, 0x67,
0x65, 0x49, 0x44, 0x00, 0xFF
};
int o = Util.IndexOfBytes(data, vanilla, 0x400000, 0);
if (offset >= 0)
return o + vanilla.Length;
byte[] patched =
{
0x00, 0x46, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x54, 0x79, 0x70, 0x65, 0x00, 0x00, 0x45, 0x64, 0x67,
0x65, 0x49, 0x44, 0x00, 0x00, 0x63, 0x3A, 0x5C, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6F, 0x6E,
0x31, 0x5F, 0x73, 0x61, 0x6E, 0x67, 0x6F, 0x5C, 0x73, 0x61, 0x6E, 0x67, 0x6F, 0x5F, 0x70, 0x72,
0x6F, 0x6A, 0x65, 0x63, 0x74, 0x5C, 0x70, 0x72, 0x6F, 0x67, 0x5C, 0x73, 0x72, 0x63, 0x2F, 0x73,
0x79, 0x73, 0x74, 0x65, 0x6D, 0x2F, 0x6D, 0x6F, 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x4D, 0x6F, 0x74,
0x69, 0x6F, 0x6E, 0x2E, 0x63, 0x70, 0x70, 0x00, 0x00
};
o = Util.IndexOfBytes(data, patched, 0x400000, 0);
if (offset >= 0)
return o + patched.Length;
return -1;
}
private readonly string codebin;
private readonly string[] movelist = Main.Config.getText(TextName.MoveNames);
private readonly byte[] data;
private readonly byte[] entries = { 0xF, 0x11, 0x10, 0xF }; // Entries per Tutor
private const int offset = 0x004960F8;
private readonly int offset;
private int dataoffset;
readonly string[] locations = { "1", "2", "3", "4" };
private void getDataOffset(int index)