Fixes for use after free
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-05-15 10:08:15 +02:00
parent 39a163a1aa
commit 1639a132a9
5 changed files with 10 additions and 8 deletions

View File

@@ -11,9 +11,11 @@ namespace PkmnLib::Battling {
auto rate = pokemon->GetSpecies()->GetCaptureRate();
u8 bonusBall = 1;
auto* itemScript = dynamic_cast<PkmnItemUseScript*>(
pokemon->GetLibrary()->GetScriptResolver()->LoadItemScript(catchItem).GetValue());
itemScript->ModifyPokeballCatchBonus(pokemon, &bonusBall);
auto itemScript = pokemon->GetLibrary()->GetScriptResolver()->LoadItemScript(catchItem).As<PkmnItemUseScript>();
if (!itemScript.HasValue()) {
return {};
}
itemScript.GetValue()->ModifyPokeballCatchBonus(pokemon, &bonusBall);
u8 bonusStatus = 1;
PKMN_HOOK(ModifyCaptureRateBonus, pokemon, pokemon, catchItem, &bonusStatus);