From 1a5aaaed21f5974601ee1a12cfba861a56057b09 Mon Sep 17 00:00:00 2001 From: Lorenzooone Date: Sat, 10 Aug 2019 13:07:18 +0200 Subject: [PATCH] Improve background window consistency --- src/c/goods.c | 27 +++++++ src/m2-hack.asm | 61 ++++++++++++++ src/m2-vwf-entries.asm | 176 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 264 insertions(+) diff --git a/src/c/goods.c b/src/c/goods.c index 5e14182..d233f8f 100644 --- a/src/c/goods.c +++ b/src/c/goods.c @@ -186,6 +186,33 @@ int goods_outer_process(WINDOW* window, int y_offset, bool give) return ACTION_NONE; } +//Returns in *String a string containing either "PSI \n Check" or "Check" based on the value of PSIValid +void setupShortMainMenu(char *String, byte PSIValid) +{ + String[0] = 1; + String[1] = 0xFF; + char PSI[] = "PSI"; + char Check[] = "Check"; + int index = 2; + if(PSIValid != 0xFF) + { + String[index++] = 0x5F; + String[index++] = 0xFF; + String[index++] = 0x08; + for(int i = 0; i < (sizeof(PSI) - 1); i++) + String[index++] = encode_ascii(PSI[i]); + } + String[index++] = 1; + String[index++] = 0xFF; + String[index++] = 0x5F; + String[index++] = 0xFF; + String[index++] = 0x08; + for(int i = 0; i < (sizeof(Check) - 1); i++) + String[index++] = encode_ascii(Check[i]); + String[index++] = 0; + String[index++] = 0xFF; +} + // Process the inner Goods window (i.e. item selection) // Called every frame. Replaces $80BEB6C fully. // Returns diff --git a/src/m2-hack.asm b/src/m2-hack.asm index 2b89ae6..d6e1c1e 100644 --- a/src/m2-hack.asm +++ b/src/m2-hack.asm @@ -690,12 +690,72 @@ pop {pc} .org 0x80BA61C bl ba61c_get_print_inventory_window +//--------------------------------------------------------- +// B9ECC hacks (Fixes inventory when out of selecting a party member to give food to via B button) +//--------------------------------------------------------- +.org 0x80B9ECC +bl b9ecc_get_print_inventory_window + //--------------------------------------------------------- // BA48E hacks (Fixes inventory when out of Give via text) //--------------------------------------------------------- .org 0x80BA48E bl ba48e_get_print_inventory_window +//--------------------------------------------------------- +// B9F96 hacks (Fixes main window after consuming an item) +//--------------------------------------------------------- +.org 0x80B9F96 +bl _reprint_first_menu + +//--------------------------------------------------------- +// B9CF8 hacks (Fixes main window after an item prints a dialogue) +//--------------------------------------------------------- +.org 0x80B9CF8 +bl _reprint_first_menu + +//--------------------------------------------------------- +// B9C88 hacks (Fixes main window after an equippable item prints a dialogue) +//--------------------------------------------------------- +.org 0x80B9C88 +bl _reprint_first_menu + +//--------------------------------------------------------- +// BA52C hacks (Fixes main window after giving an item) +//--------------------------------------------------------- +.org 0x80BA52C +bl _reprint_first_menu + +//--------------------------------------------------------- +// BA44E hacks (Fixes main window after not being able to give an item) +//--------------------------------------------------------- +.org 0x80BA44E +bl _reprint_first_menu + +//--------------------------------------------------------- +// BA7BE hacks (Fixes main window after calling the help function) +//--------------------------------------------------------- +.org 0x80BA7BE +bl ba7be_reprint_first_menu + +//--------------------------------------------------------- +// B9AA2 hacks (Fixes main window after exiting the item action window) +//--------------------------------------------------------- +.org 0x80B9AA2 +bl b9aa2_reprint_first_menu + +//--------------------------------------------------------- +// C6BA2 hacks (Fixes main window after exiting the Stored Goods window) +//--------------------------------------------------------- +.org 0x80C6BA2 +bl c6ba2_reprint_first_menu + +//--------------------------------------------------------- +// BCEB0 hacks (Fixes main window after exiting the pickup menu) +//--------------------------------------------------------- +.org 0x80BCEB0 +bl _reprint_first_menu + //--------------------------------------------------------- // C1C98 hacks (menu selection) //--------------------------------------------------------- @@ -1176,6 +1236,7 @@ m2_enemy_attributes: .definelabel m2_cstm_last_printed ,0x3001F4F .definelabel m2_player1 ,0x3001F50 .definelabel m2_script_readability ,0x3004F08 +.definelabel m2_psi_exist ,0x300525C .definelabel m2_active_window_pc ,0x3005264 .definelabel m2_setup_naming_mem ,0x8001D5C .definelabel m2_soundeffect ,0x8001720 diff --git a/src/m2-vwf-entries.asm b/src/m2-vwf-entries.asm index 9115114..dbc4f0c 100644 --- a/src/m2-vwf-entries.asm +++ b/src/m2-vwf-entries.asm @@ -1570,6 +1570,19 @@ pop {r4} bl 0x80BD7F8 //Copies old arrangements, this includes the highlight pop {pc} +//============================================================================== +//Specific Routine which calls get_print_inventory_window +b9ecc_get_print_inventory_window: +push {lr} +push {r4-r5} +mov r5,r4 +mov r4,#0x1C +sub r5,r5,r4 //Address with the windows' pc +ldr r4,=#0x3005230 +bl get_print_inventory_window //Prints old inventory +pop {r4-r5} +bl 0x80BD7F8 //Copies old arrangements, this includes the highlight +pop {pc} //============================================================================== //Specific Routine which calls get_print_inventory_window @@ -1580,4 +1593,167 @@ bl get_print_inventory_window //Prints old inventory bl 0x80BD7F8 //Copies old arrangements, this includes the highlight pop {r5,pc} +.pool + +//============================================================================== +//Reprints both the Main window and the Cash window if need be +generic_reprinting_first_menu: +push {lr} +push {r0-r6} +add sp,#-8 +ldr r6,=#0x3005078 //Make sure the game expects only the right amount of lines to be written (so only 1) +ldrb r4,[r6,#0] +str r4,[sp,#4] +mov r4,#0 +strb r4,[r6,#0] +ldr r4,=#0x3005230 //Window generic address + +//Main window +mov r2,#1 +ldr r0,[r4,#0] //Main window place in ram +ldrb r0,[r0,#0] +and r2,r0 +cmp r2,#0 +beq @@cash //Check if window is enabled before printing in it + +ldr r0,=#0x8B17EE4 +ldr r1,=#0x8B17424 +ldr r3,=m2_psi_exist //Flag which if not 0xFF means no one has PSI +ldrb r3,[r3,#0] +cmp r3,#0xFF +beq @@psiNotFound +mov r2,#0 +b @@keep_going +@@psiNotFound: +mov r2,#1 +@@keep_going: +bl m2_strlookup //Load the proper menu string based on m2_psi_exist +mov r1,#0 +str r1,[sp,#0] +mov r1,r0 +ldr r0,[r4,#0] +mov r2,#5 +mov r3,#2 +bl 0x80BE4C8 //Let it do its things +ldr r0,[r4,#0] +bl 0x80C8BE4 //Print text in the window + +@@cash: +//Cash +mov r2,#1 +ldr r0,[r4,#4] //Cash window place in ram +ldrb r0,[r0,#0] +and r2,r0 +cmp r2,#0 +beq @@end //Check if window is enabled before printing in it + +ldr r2,=#0x300130C +ldr r0,[r2,#0] +mov r1,#2 +orr r0,r1 +str r0,[r2,#0] +ldr r0,=#0x3001D40 +mov r1,#0xD2 +lsl r1,r1,#3 +add r0,r0,r1 +ldr r0,[r0,#0] //Load the money +ldr r5,=#0x3005200 +ldr r1,[r5,#0] +mov r2,r1 //Load the string address +mov r1,#0x30 //Padding +bl format_cash_window +ldr r0,[r4,#4] +ldr r1,[r5,#0] +mov r2,#0 +bl m2_initwindow //Let it do its things +ldr r0,[r4,#4] +bl 0x80C8BE4 //Print text in the window + +@@end: +ldr r4,[sp,#4] +strb r4,[r6,#0] //Restore expected amount of lines to be written +add sp,#8 +pop {r0-r6} +pop {pc} + +.pool + +//============================================================================== +//Specific (But still very generic) call to generic_reprinting_first_menu which then calls swapwindowbuf as expected from the game +_reprint_first_menu: +push {lr} +bl generic_reprinting_first_menu +mov r0,#1 +bl m2_swapwindowbuf +pop {pc} + +//============================================================================== +//Specific call to generic_reprinting_first_menu which then calls a DMA transfer of the old arrangement +c6ba2_reprint_first_menu: +push {lr} +bl generic_reprinting_first_menu +mov r0,#1 +bl 0x80BD7F8 +pop {pc} + +//============================================================================== +//Specific call to b9aa2_special_string, needed for the help function +ba7be_reprint_first_menu: +push {lr} +bl b9aa2_special_string +ldr r1,=#0x40000D4 +ldr r0,=#0x3005200 +pop {pc} + +//============================================================================== +//Specific call to b9aa2_special_string, needed for when you exit the item action function +b9aa2_reprint_first_menu: +push {lr} +bl b9aa2_special_string +mov r0,#1 +bl 0x80BD7F8 +pop {pc} + +//============================================================================== +//Setup which only prints either "Check" or "PSI \n Check" in the main window. Needed in order to avoid the not-needed options popping in the item window for 2-3 frames +b9aa2_special_string: +push {lr} +push {r0-r5} +add sp,#-68 +ldr r5,=#0x3005078 //Make sure the game expects only the right amount of lines to be written (so only 1) +ldrb r4,[r5,#0] +str r4,[sp,#4] +mov r4,#0 +strb r4,[r5,#0] +ldr r4,=#0x3005230 //Window generic address + +//Main window +mov r2,#1 +ldr r0,[r4,#0] //Main window place in ram +ldrb r0,[r0,#0] +and r2,r0 +cmp r2,#0 +beq @@end //Check if window is enabled before printing in it + +ldr r1,=m2_psi_exist +ldrb r1,[r1,#0] +add r0,sp,#8 +bl setupShortMainMenu //Get shortened menu string +mov r1,#0 +str r1,[sp,#0] +add r1,sp,#8 +ldr r0,[r4,#0] +mov r2,#5 +mov r3,#2 +bl 0x80BE4C8 //Let it do its things +ldr r0,[r4,#0] +bl 0x80C8BE4 //Print text in the window + +@@end: +ldr r4,[sp,#4] +strb r4,[r5,#0] //Restore expected amount of lines to be written +add sp,#68 +pop {r0-r5} +pop {pc} + .pool \ No newline at end of file