diff --git a/include/script_builder.h b/include/script_builder.h index 5680e9f..14c4da0 100644 --- a/include/script_builder.h +++ b/include/script_builder.h @@ -19,47 +19,18 @@ #define LEAFGREEN 0x475042 #define EMERALD 0x455042 - -#define LOC_SENDMONTOPC ((GAMECODE == RUBY || GAMECODE == SAPPHIRE) ? 0x01 : ((GAMECODE == FIRERED || GAMECODE == LEAFGREEN) ? 0x08040B90 : 0x0806B490)) -#define LOC_GSPECIALVAR_0x8000 ((GAMECODE == RUBY || GAMECODE == SAPPHIRE) ? 0x01 : ((GAMECODE == FIRERED || GAMECODE == LEAFGREEN) ? 0x020370B8 : 0x020375D8)) -#define LOC_GSAVEBLOCK1PTR ((GAMECODE == RUBY || GAMECODE == SAPPHIRE) ? 0x01 : ((GAMECODE == FIRERED || GAMECODE == LEAFGREEN) ? 0x03005008 : 0x03005D8C)) -#define OFFSET_RAMSCRIPT ((GAMECODE == RUBY || GAMECODE == SAPPHIRE) ? 0x01 : ((GAMECODE == FIRERED || GAMECODE == LEAFGREEN) ? 0x3690 : 0x3728)) - // Source: https://github.com/pret/pokeemerald/blob/master/include/global.h#L1012 -#define OFFSET_FLAGS ((GAMECODE == RUBY || GAMECODE == SAPPHIRE) ? 0x01 : ((GAMECODE == FIRERED || GAMECODE == LEAFGREEN) ? 0x3690 : 0x2F0)) //Why not 0x1270? +#define LOC_SENDMONTOPC ((GAMECODE == RUBY || GAMECODE == SAPPHIRE) ? 0x01 : ((GAMECODE == FIRERED || GAMECODE == LEAFGREEN) ? 0x08040BA4 : 0x0806B490)) // 94 is where the script jumps to in normal gameplay +#define LOC_GSPECIALVAR_0x8000 ((GAMECODE == RUBY || GAMECODE == SAPPHIRE) ? 0x01 : ((GAMECODE == FIRERED || GAMECODE == LEAFGREEN) ? 0x020370B8 : 0x020375D8)) +#define LOC_GSAVEBLOCK1PTR ((GAMECODE == RUBY || GAMECODE == SAPPHIRE) ? 0x01 : ((GAMECODE == FIRERED || GAMECODE == LEAFGREEN) ? 0x03005008 : 0x03005D8C)) +#define OFFSET_RAMSCRIPT ((GAMECODE == RUBY || GAMECODE == SAPPHIRE) ? 0x01 : ((GAMECODE == FIRERED || GAMECODE == LEAFGREEN) ? 0x361C : 0x3728)) +// Source: https://github.com/pret/pokeemerald/blob/master/include/global.h#L1012 +#define OFFSET_FLAGS ((GAMECODE == RUBY || GAMECODE == SAPPHIRE) ? 0x01 : ((GAMECODE == FIRERED || GAMECODE == LEAFGREEN) ? 0x0EE0 : 0x1270)) +// Flag offset as found within the SaveBlock1 struct in global.h #define PC_MAKER ((GAMECODE == RUBY || GAMECODE == SAPPHIRE || GAMECODE == EMERALD) ? "LANETTE" : "BILL") + #define FLAG_ID_START 0x21 // This one stays consistant, at least for FRLG/E. Must also be 8x or 8x+1 to store in one byte #define VAR_ID_START 0x8000 // This one should also stay consistant -#define NUM_JUMPS 4 -#define JUMP_ALL_COLLECTED 0 -#define JUMP_PKMN_COLLECTED 1 -#define JUMP_BOX_FULL 2 -#define JUMP_LOOP 3 - -#define NUM_TEXTBOXES 4 -#define TEXT_GREET 0 -#define TEXT_THANK 1 -#define TEXT_FULL 2 -#define TEXT_RECEIVED 3 - -#define NUM_ASM_OFFSET 4 -#define ASM_OFFSET_PKMN_OFFSET 0 -#define ASM_OFFSET_PKMN_STRUCT 1 -#define ASM_OFFSET_SENDMON_PTR 2 -#define ASM_OFFSET_BOX_SUC_PTR 3 - -#define NUM_RELATIVE_PTR 1 -#define REL_PTR_ASM_START 0 - -#define COND_LESSTHAN 0 -#define COND_EQUALS 1 -#define COND_GREATERTHAN 2 -#define COND_LESSEQUALTHAN 3 -#define COND_GREATEREQUALTHAN 4 -#define COND_NOTEQUAL 5 -#define COND_FLAGTRUE 1 -#define COND_FLAGFALSE 5 - #define VAR_CALLASM (VAR_ID_START + 0x00) #define VAR_SCRIPT_PTR_LOW (VAR_ID_START + 0x01) #define VAR_SCRIPT_PTR_HIGH (VAR_ID_START + 0x02) @@ -91,6 +62,38 @@ #define FLAG_PKMN_6 (FLAG_ID_START + 0x5) #define FLAG_ALL_COLLECTED (FLAG_ID_START + 0x6) + +#define NUM_JUMPS 4 +#define JUMP_ALL_COLLECTED 0 +#define JUMP_PKMN_COLLECTED 1 +#define JUMP_BOX_FULL 2 +#define JUMP_LOOP 3 + +#define NUM_TEXTBOXES 4 +#define TEXT_GREET 0 +#define TEXT_THANK 1 +#define TEXT_FULL 2 +#define TEXT_RECEIVED 3 + +#define NUM_ASM_OFFSET 4 +#define ASM_OFFSET_PKMN_OFFSET 0 +#define ASM_OFFSET_PKMN_STRUCT 1 +#define ASM_OFFSET_SENDMON_PTR 2 +#define ASM_OFFSET_BOX_SUC_PTR 3 + +#define NUM_RELATIVE_PTR 1 +#define REL_PTR_ASM_START 0 + +#define COND_LESSTHAN 0 +#define COND_EQUALS 1 +#define COND_GREATERTHAN 2 +#define COND_LESSEQUALTHAN 3 +#define COND_GREATEREQUALTHAN 4 +#define COND_NOTEQUAL 5 +#define COND_FLAGTRUE 1 +#define COND_FLAGFALSE 5 + + #define r0 0b0000 #define r1 0b0001 #define r2 0b0010 diff --git a/source/script.cpp b/source/script.cpp index c8c3f60..1619585 100644 --- a/source/script.cpp +++ b/source/script.cpp @@ -6,7 +6,7 @@ static u32 wonder_card[0x14E] = { 0xFC, 0x85, 0x00, 0x00, 0xE8, 0x03, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBB, 0xCF, 0xCC, 0xC9, 0xCC, 0xBB, 0xCE, 0xC3, 0xBD, 0xC5, 0xBF, 0xCE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBF, 0xEC, 0xD7, 0xDC, 0xD5, 0xE2, 0xDB, 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0x00, 0xBE, 0xE3, 0x00, 0xE2, 0xE3, 0xE8, 0x00, 0xE8, 0xE3, 0xE7, 0xE7, 0x00, 0xE8, 0xDC, 0xDD, 0xE7, 0x00, 0xBF, 0xEC, 0xD7, 0xDC, 0xD5, 0xE2, 0xDB, 0xD9, 0x00, 0xBD, 0xD5, 0xE6, 0xD8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD6, 0xD9, 0xDA, 0xE3, 0xE6, 0xD9, 0x00, 0xE6, 0xD9, 0xD7, 0xD9, 0xDD, 0xEA, 0xDD, 0xE2, 0xDB, 0x00, 0xE8, 0xDC, 0xD9, 0x00, 0xBB, 0xCF, 0xCC, 0xC9, 0xCC, 0xBB, 0xCE, 0xC3, 0xBD, 0xC5, 0xBF, 0xCE, 0xAB, 0xAB, 0x00, 0x00, 0x00, 0x00, 0x00}; - + // CRC16 checksum void inject_mystery(Pokemon incoming_party_aray[]) { @@ -34,13 +34,12 @@ void inject_mystery(Pokemon incoming_party_aray[]) update_memory_buffer_checksum(); flash_write(memory_section_array[4], &global_memory_buffer[0], 0x1000); - //Set flags - flash_read(memory_section_array[2], &global_memory_buffer[0], 0x1000); - global_memory_buffer[ + (FLAG_ID_START / 8)] |= (0b00111111 << (FLAG_ID_START % 8)); //Set "to obtain" flags to 1 - global_memory_buffer[0x2F0 + (FLAG_ID_START / 8)] &= (~0b01000000 << (FLAG_ID_START % 8)); //Set "collected all" flag to 0 + // Set flags + flash_read(memory_section_array[1 + ((OFFSET_FLAGS + (FLAG_ID_START / 8)) / 0xF80)], &global_memory_buffer[0], 0x1000); + global_memory_buffer[(OFFSET_FLAGS + (FLAG_ID_START / 8)) % 0xF80] |= (0b00111111 << (FLAG_ID_START % 8)); // Set "to obtain" flags to 1 + global_memory_buffer[(OFFSET_FLAGS + (FLAG_ID_START / 8)) % 0xF80] &= (~0b01000000 << (FLAG_ID_START % 8)); // Set "collected all" flag to 0 update_memory_buffer_checksum(); - flash_write(memory_section_array[2], &global_memory_buffer[0], 0x1000); - + flash_write(memory_section_array[1 + ((OFFSET_FLAGS + (FLAG_ID_START / 8)) / 0xF80)], &global_memory_buffer[0], 0x1000); } /* @@ -67,25 +66,25 @@ void inject_mystery(Pokemon incoming_party_aray[]) 000188: .word 0x020375E8 the location of variable "0x8008" (the pokemon offset) -- 00 B5 -- 08 4B -- 1B 68 -- 08 A0 -- C0 18 -- 04 49 -- 7A 46 -- 07 32 -- 96 46 -- 08 47 -- 02 4A -- 10 60 -01 BC -00 47 -91 B4 -06 08 -E4 75 -03 02 -E8 75 +- 00 B5 +- 08 4B +- 1B 68 +- 08 A0 +- C0 18 +- 04 49 +- 7A 46 +- 07 32 +- 96 46 +- 08 47 +- 02 4A +- 10 60 +01 BC +00 47 +91 B4 +06 08 +E4 75 +03 02 +E8 75 03 02 */ \ No newline at end of file diff --git a/source/script_builder.cpp b/source/script_builder.cpp index a276d51..c26e610 100644 --- a/source/script_builder.cpp +++ b/source/script_builder.cpp @@ -74,7 +74,7 @@ void mystery_gift_script::build_script(Pokemon incoming_party_array[]) add3(r0, r0, r3); ldr3(r1, asm_offset_distance(ASM_OFFSET_SENDMON_PTR)); mov3(r2, r15); - add2(r2, 7); + add2(r2, 5); // Add 0x05 for the four instruction bytes ahead of it, plus one so it is read as THUMB, not ARM mov3(r14, r2); bx(r1); ldr3(r2, asm_offset_distance(ASM_OFFSET_BOX_SUC_PTR));