Rsaves/examples/modifyJorgeTeam.pl

235 lines
10 KiB
Perl
Raw Normal View History

2023-11-01 13:25:03 +01:00
#!/usr/bin/env perl
use v5.34.1;
use strict;
use warnings;
use feature 'signatures';
use Rsaves
qw/read_save check_correct_size get_saves find_current_save_index check_correct_size find_pokemon_substruct change_gender read_pc_storage save_pc_changes enable_eon_ticket save_changes pokemon_set_shiny read_pkm_file_box enable_mirage_island_for_pokemon parse_version_name/;
use Rsaves::Constants::Global
2023-11-01 17:02:34 +01:00
qw/$MOVE_SPIKES $MOVE_DRILL_PECK $MOVE_HIDDEN_POWER $MOVE_TAUNT $MOVE_THUNDERBOLT $MOVE_ROAR $MOVE_THUNDER_WAVE $ITEM_LEFTOVERS $MOVE_DRAGON_DANCE $MOVE_ROCK_SLIDE $MOVE_EARTHQUAKE $MOVE_TAUNT $MOVE_FLAMETHROWER $MOVE_WILL_O_WISP/;
2023-11-01 13:25:03 +01:00
use Rsaves::Constants::Ruby::Global qw/$MALE $FEMALE/;
my $input = $ARGV[0] or die "No input save";
my $output = $ARGV[1] or die "No output save";
my $version = parse_version_name( $ARGV[2] ) // parse_version_name('ruby');
sub start {
my ( @saves_raw, $extra );
( @saves_raw[ 0, 1 ], $extra ) = read_save($input);
check_correct_size( @saves_raw, $extra );
my @saves = get_saves( @saves_raw, $version );
my $current_save_index = find_current_save_index(@saves);
my $save = $saves[$current_save_index];
my $pc = read_pc_storage($save);
2023-11-01 16:08:40 +01:00
my $skarmory = $pc->{boxes}[0][5];
my $jolteon = $pc->{boxes}[0][4];
2023-11-01 17:02:34 +01:00
my $moltres = $pc->{boxes}[0][3];
2023-11-01 16:41:59 +01:00
my $larvitar = $pc->{boxes}[0][2];
2023-11-01 16:08:40 +01:00
modifySkarmory($skarmory);
modifyJolteon($jolteon);
2023-11-01 16:41:59 +01:00
modifyLarvitar($larvitar);
2023-11-01 17:02:34 +01:00
modifyMoltres($moltres);
2023-11-01 13:25:03 +01:00
save_pc_changes( $save, $pc );
save_changes( @saves, $extra, $output );
}
2023-11-01 17:33:22 +01:00
sub _hihalf_u32 {
my $n = shift;
return ( ( $n & 0xFFFF0000 ) >> 16 );
}
sub _lowhalf_u32 {
my $n = shift;
return ( $n & 0xFFFF );
}
2023-11-01 17:02:34 +01:00
sub modifyMoltres($pokemon) {
print Data::Dumper::Dumper $pokemon;
$pokemon->{personality} = 0x336E4D34;
my $ivs_egg_status_and_ability =
$pokemon->{substructures}[3]{ivs_egg_status_and_ability};
2023-11-01 17:33:22 +01:00
say _hihalf_u32($pokemon->{otid});
say _lowhalf_u32($pokemon->{otid});
2023-11-01 17:02:34 +01:00
my $ability = $ivs_egg_status_and_ability >> 31 & 1;
my $egg = $ivs_egg_status_and_ability >> 30 & 1;
my $iv_special_defense = $ivs_egg_status_and_ability >> 25 & 0x1F;
my $iv_special_attack = $ivs_egg_status_and_ability >> 20 & 0x1F;
my $iv_speed = $ivs_egg_status_and_ability >> 15 & 0x1F;
my $iv_defense = $ivs_egg_status_and_ability >> 10 & 0x1F;
my $iv_attack = $ivs_egg_status_and_ability >> 5 & 0x1F;
my $iv_hp = $ivs_egg_status_and_ability >> 0 & 0x1F;
(
$iv_hp, $iv_attack, $iv_defense, $iv_special_attack,
$iv_special_defense, $iv_speed, $ability
) = ( 30, 18, 31, 30, 31, 31, 0 );
$ivs_egg_status_and_ability = 0;
$ivs_egg_status_and_ability |= ( ( $ability & 1 ) << 31 );
$ivs_egg_status_and_ability |= ( ( $egg & 1 ) << 30 );
$ivs_egg_status_and_ability |= ( ( $iv_special_defense & 0x1F ) << 25 );
$ivs_egg_status_and_ability |= ( ( $iv_special_attack & 0x1F ) << 20 );
$ivs_egg_status_and_ability |= ( ( $iv_speed & 0x1F ) << 15 );
$ivs_egg_status_and_ability |= ( ( $iv_defense & 0x1F ) << 10 );
$ivs_egg_status_and_ability |= ( ( $iv_attack & 0x1F ) << 5 );
$ivs_egg_status_and_ability |= ( ( $iv_hp & 0x1F ) );
$pokemon->{substructures}[3]{ivs_egg_status_and_ability} =
$ivs_egg_status_and_ability;
$pokemon->{substructures}[2]{hp_ev} = 0;
$pokemon->{substructures}[2]{attack_ev} = 0;
$pokemon->{substructures}[2]{defense_ev} = 0;
$pokemon->{substructures}[2]{speed_ev} = 0;
$pokemon->{substructures}[2]{special_attack_ev} = 0;
$pokemon->{substructures}[2]{special_defense_ev} = 0;
$pokemon->{substructures}[1]{movements}[0] = $MOVE_FLAMETHROWER;
$pokemon->{substructures}[1]{movements}[1] = $MOVE_HIDDEN_POWER;
$pokemon->{substructures}[1]{movements}[2] = $MOVE_WILL_O_WISP;
$pokemon->{substructures}[1]{movements}[3] = $MOVE_ROAR;
$pokemon->{substructures}[0]{held_item} = $ITEM_LEFTOVERS;
2023-11-01 16:41:59 +01:00
print Data::Dumper::Dumper $pokemon;
2023-11-01 17:02:34 +01:00
}
sub modifyLarvitar($pokemon) {
2023-11-01 16:41:59 +01:00
$pokemon->{personality} = 0x9CF2063B;
my $ivs_egg_status_and_ability =
$pokemon->{substructures}[3]{ivs_egg_status_and_ability};
my $ability = $ivs_egg_status_and_ability >> 31 & 1;
my $egg = $ivs_egg_status_and_ability >> 30 & 1;
my $iv_special_defense = $ivs_egg_status_and_ability >> 25 & 0x1F;
my $iv_special_attack = $ivs_egg_status_and_ability >> 20 & 0x1F;
my $iv_speed = $ivs_egg_status_and_ability >> 15 & 0x1F;
my $iv_defense = $ivs_egg_status_and_ability >> 10 & 0x1F;
my $iv_attack = $ivs_egg_status_and_ability >> 5 & 0x1F;
my $iv_hp = $ivs_egg_status_and_ability >> 0 & 0x1F;
(
$iv_hp, $iv_attack, $iv_defense, $iv_special_attack,
$iv_special_defense, $iv_speed, $ability
) = ( 31, 30, 30, 23, 30, 31, 0 );
$ivs_egg_status_and_ability = 0;
$ivs_egg_status_and_ability |= ( ( $ability & 1 ) << 31 );
$ivs_egg_status_and_ability |= ( ( $egg & 1 ) << 30 );
$ivs_egg_status_and_ability |= ( ( $iv_special_defense & 0x1F ) << 25 );
$ivs_egg_status_and_ability |= ( ( $iv_special_attack & 0x1F ) << 20 );
$ivs_egg_status_and_ability |= ( ( $iv_speed & 0x1F ) << 15 );
$ivs_egg_status_and_ability |= ( ( $iv_defense & 0x1F ) << 10 );
$ivs_egg_status_and_ability |= ( ( $iv_attack & 0x1F ) << 5 );
$ivs_egg_status_and_ability |= ( ( $iv_hp & 0x1F ) );
$pokemon->{substructures}[3]{ivs_egg_status_and_ability} =
$ivs_egg_status_and_ability;
$pokemon->{substructures}[2]{hp_ev} = 0;
$pokemon->{substructures}[2]{attack_ev} = 0;
$pokemon->{substructures}[2]{defense_ev} = 0;
$pokemon->{substructures}[2]{speed_ev} = 0;
$pokemon->{substructures}[2]{special_attack_ev} = 0;
$pokemon->{substructures}[2]{special_defense_ev} = 0;
$pokemon->{substructures}[1]{movements}[0] = $MOVE_DRAGON_DANCE;
$pokemon->{substructures}[1]{movements}[1] = $MOVE_ROCK_SLIDE;
$pokemon->{substructures}[1]{movements}[2] = $MOVE_EARTHQUAKE;
$pokemon->{substructures}[1]{movements}[3] = $MOVE_TAUNT;
$pokemon->{substructures}[0]{held_item} = $ITEM_LEFTOVERS;
}
sub modifyJolteon ($pokemon) {
2023-11-01 16:08:40 +01:00
$pokemon->{personality} = 0x46F43BCA;
my $ivs_egg_status_and_ability =
$pokemon->{substructures}[3]{ivs_egg_status_and_ability};
my $ability = $ivs_egg_status_and_ability >> 31 & 1;
my $egg = $ivs_egg_status_and_ability >> 30 & 1;
my $iv_special_defense = $ivs_egg_status_and_ability >> 25 & 0x1F;
my $iv_special_attack = $ivs_egg_status_and_ability >> 20 & 0x1F;
my $iv_speed = $ivs_egg_status_and_ability >> 15 & 0x1F;
my $iv_defense = $ivs_egg_status_and_ability >> 10 & 0x1F;
my $iv_attack = $ivs_egg_status_and_ability >> 5 & 0x1F;
my $iv_hp = $ivs_egg_status_and_ability >> 0 & 0x1F;
(
$iv_hp, $iv_attack, $iv_defense, $iv_special_attack,
$iv_special_defense, $iv_speed, $ability
) = ( 31, 22, 30, 31, 31, 31, 0 );
$ivs_egg_status_and_ability = 0;
$ivs_egg_status_and_ability |= ( ( $ability & 1 ) << 31 );
$ivs_egg_status_and_ability |= ( ( $egg & 1 ) << 30 );
$ivs_egg_status_and_ability |= ( ( $iv_special_defense & 0x1F ) << 25 );
$ivs_egg_status_and_ability |= ( ( $iv_special_attack & 0x1F ) << 20 );
$ivs_egg_status_and_ability |= ( ( $iv_speed & 0x1F ) << 15 );
$ivs_egg_status_and_ability |= ( ( $iv_defense & 0x1F ) << 10 );
$ivs_egg_status_and_ability |= ( ( $iv_attack & 0x1F ) << 5 );
$ivs_egg_status_and_ability |= ( ( $iv_hp & 0x1F ) );
$pokemon->{substructures}[3]{ivs_egg_status_and_ability} =
$ivs_egg_status_and_ability;
$pokemon->{substructures}[2]{hp_ev} = 0;
$pokemon->{substructures}[2]{attack_ev} = 0;
$pokemon->{substructures}[2]{defense_ev} = 0;
$pokemon->{substructures}[2]{speed_ev} = 0;
$pokemon->{substructures}[2]{special_attack_ev} = 0;
$pokemon->{substructures}[2]{special_defense_ev} = 0;
$pokemon->{substructures}[1]{movements}[0] = $MOVE_THUNDERBOLT;
$pokemon->{substructures}[1]{movements}[1] = $MOVE_HIDDEN_POWER;
$pokemon->{substructures}[1]{movements}[2] = $MOVE_THUNDER_WAVE;
$pokemon->{substructures}[1]{movements}[3] = $MOVE_ROAR;
2023-11-01 16:28:17 +01:00
$pokemon->{substructures}[0]{held_item} = $ITEM_LEFTOVERS;
2023-11-01 16:08:40 +01:00
}
sub modifySkarmory ($pokemon) {
2023-11-01 17:33:22 +01:00
$pokemon->{personality} = 0xFB0CCAA8;
2023-11-01 13:25:03 +01:00
my $ivs_egg_status_and_ability =
$pokemon->{substructures}[3]{ivs_egg_status_and_ability};
my $ability = $ivs_egg_status_and_ability >> 31 & 1;
my $egg = $ivs_egg_status_and_ability >> 30 & 1;
my $iv_special_defense = $ivs_egg_status_and_ability >> 25 & 0x1F;
my $iv_special_attack = $ivs_egg_status_and_ability >> 20 & 0x1F;
my $iv_speed = $ivs_egg_status_and_ability >> 15 & 0x1F;
my $iv_defense = $ivs_egg_status_and_ability >> 10 & 0x1F;
my $iv_attack = $ivs_egg_status_and_ability >> 5 & 0x1F;
my $iv_hp = $ivs_egg_status_and_ability >> 0 & 0x1F;
(
$iv_hp, $iv_attack, $iv_defense, $iv_special_attack,
2023-11-01 17:33:22 +01:00
$iv_special_defense, $iv_speed, $ability
) = ( 30, 30, 30, 23, 30, 30, 0 );
2023-11-01 13:25:03 +01:00
$ivs_egg_status_and_ability = 0;
$ivs_egg_status_and_ability |= ( ( $ability & 1 ) << 31 );
$ivs_egg_status_and_ability |= ( ( $egg & 1 ) << 30 );
$ivs_egg_status_and_ability |= ( ( $iv_special_defense & 0x1F ) << 25 );
$ivs_egg_status_and_ability |= ( ( $iv_special_attack & 0x1F ) << 20 );
$ivs_egg_status_and_ability |= ( ( $iv_speed & 0x1F ) << 15 );
$ivs_egg_status_and_ability |= ( ( $iv_defense & 0x1F ) << 10 );
$ivs_egg_status_and_ability |= ( ( $iv_attack & 0x1F ) << 5 );
$ivs_egg_status_and_ability |= ( ( $iv_hp & 0x1F ) );
$pokemon->{substructures}[3]{ivs_egg_status_and_ability} =
$ivs_egg_status_and_ability;
$pokemon->{substructures}[2]{hp_ev} = 0;
$pokemon->{substructures}[2]{attack_ev} = 0;
$pokemon->{substructures}[2]{defense_ev} = 0;
$pokemon->{substructures}[2]{speed_ev} = 0;
$pokemon->{substructures}[2]{special_attack_ev} = 0;
$pokemon->{substructures}[2]{special_defense_ev} = 0;
$pokemon->{substructures}[1]{movements}[0] = $MOVE_SPIKES;
$pokemon->{substructures}[1]{movements}[1] = $MOVE_DRILL_PECK;
$pokemon->{substructures}[1]{movements}[2] = $MOVE_HIDDEN_POWER;
$pokemon->{substructures}[1]{movements}[3] = $MOVE_TAUNT;
2023-11-01 16:28:17 +01:00
$pokemon->{substructures}[0]{held_item} = $ITEM_LEFTOVERS;
2023-11-01 13:25:03 +01:00
}
start;