Adding changes needed for legendary rematch.

This commit is contained in:
sergiotarxz 2023-01-30 17:57:10 +01:00
parent 62685a8bc4
commit 80f81ca307
1 changed files with 53 additions and 5 deletions

View File

@ -7,7 +7,8 @@ use warnings;
use Data::Dumper;
use Rsaves::Constants::Ruby::Flags qw/$FLAG_SYS_HAS_EON_TICKET/;
use Rsaves::Constants::Ruby::Flags qw/$FLAG_SYS_HAS_EON_TICKET $FLAG_LEGENDARY_BATTLE_COMPLETED $FLAG_HIDE_LEGEND_MON_CAVE_OF_ORIGIN/;
use Rsaves::Constants::Ruby::Vars qw/$VAR_CAVE_OF_ORIGIN_B4F_STATE $VARS_START/;
use Exporter;
@ -17,7 +18,9 @@ our @EXPORT_OK = (
qw/read_pc_storage save_pc_changes save_changes enable_eon_ticket
add_key_item set_flag_id change_gender read_save get_saves
find_current_save_index check_correct_size find_pokemon_substruct
read_pkm_file_box calculate_shiny_personality pokemon_set_shiny get_first_super_data set_first_super_data/
read_pkm_file_box calculate_shiny_personality pokemon_set_shiny
get_first_super_data set_first_super_data enable_rematch_main_legendary
check_flag_id/
);
my $SAVE_SIZE = 57344;
@ -741,13 +744,27 @@ sub enable_eon_ticket {
my $save = shift;
my $superdata = get_first_super_data($save);
say "Latios already enabled", return
if _check_flag_id( $save, $superdata, $FLAG_SYS_HAS_EON_TICKET );
printf "%x", $FLAG_SYS_HAS_EON_TICKET;
if check_flag_id( $save, $superdata, $FLAG_SYS_HAS_EON_TICKET );
set_flag_id( $save, $superdata, $FLAG_SYS_HAS_EON_TICKET, 1 );
add_key_item( $save, $superdata, $ITEM_EON_TICKET );
set_first_super_data( $save, $superdata );
}
sub enable_rematch_main_legendary {
my $save = shift;
my $superdata = get_first_super_data($save);
if (check_flag_id($save, $superdata, $FLAG_LEGENDARY_BATTLE_COMPLETED)) {
set_flag_id ($save, $superdata, $FLAG_LEGENDARY_BATTLE_COMPLETED, 0);
}
if (check_flag_id($save, $superdata, $FLAG_HIDE_LEGEND_MON_CAVE_OF_ORIGIN)) {
set_flag_id ($save, $superdata, $FLAG_HIDE_LEGEND_MON_CAVE_OF_ORIGIN, 0);
}
if (get_var($save, $superdata, $VAR_CAVE_OF_ORIGIN_B4F_STATE)) {
set_var($save, $superdata, $VAR_CAVE_OF_ORIGIN_B4F_STATE, 0);
}
set_first_super_data( $save, $superdata );
}
sub add_key_item {
my $save = shift;
my $superdata = shift;
@ -782,6 +799,37 @@ sub add_key_item {
close $fh;
}
sub get_var {
my $save = shift;
my $superdata = shift;
my $var = shift;
my $read_until = (($var - $VARS_START) * 2) + 0x1340;
open my $fh, '<', $superdata;
read $fh, (my $read), $read_until or die "Unable to read";
read $fh, $read, 2 or die "Unable to read";
my $flag = unpack 'v', $read;
close $fh;
return $flag;
}
sub set_var {
my $save = shift;
my $superdata = shift;
my $var = shift;
my $value = shift;
die "$value bigger than 0xffff" if $value > 0xffff;
my $read_until = (($var - $VARS_START) * 2) + 0x1340;
my $result = shift;
open my $fh, '<', $superdata;
read $fh, (my $read), $read_until or die "Unable to read";
$result .= $read;
read $fh, $read, 2 or die "Unable to read";
$result .= pack 'v', $value;
$result .= join '', <$fh>;
${$superdata} = $result;
close $fh;
}
sub set_flag_id {
my $save = shift;
my $superdata = shift;
@ -806,7 +854,7 @@ sub set_flag_id {
close $fh;
}
sub _check_flag_id {
sub check_flag_id {
my $save = shift;
my $superdata = shift;
my $id = shift;