Fixes for use after free
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
39a163a1aa
commit
1639a132a9
|
@ -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);
|
||||
|
|
|
@ -83,7 +83,7 @@ void PkmnLib::Battling::Pokemon::AttemptCapture(PkmnLib::Library::Item* catchIte
|
|||
Ensure(_battleData.Side.HasValue());
|
||||
Ensure(!IsFainted());
|
||||
Ensure(IsUsable());
|
||||
Ensure(!GetBattleSide().GetValue()->IsSlotUnfillabe(this)) auto captureLibrary =
|
||||
auto captureLibrary =
|
||||
GetLibrary().ForceAs<const BattleLibrary>()->GetCaptureLibrary();
|
||||
auto result = captureLibrary->TryCatch(this, catchItem, _battleData.Battle.GetValue()->GetRandom());
|
||||
_battleData.Battle.GetValue()->TriggerEventListener<CaptureAttemptEvent>(this, result);
|
||||
|
|
|
@ -193,7 +193,7 @@ AngelScriptResolver::LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, S
|
|||
return new AngelScriptScript(owner, ownerType, this, t.value(), obj, _contextPool);
|
||||
}
|
||||
|
||||
ArbUt::OptionalUniquePtr<CreatureLib::Battling::ItemUseScript>
|
||||
ArbUt::OptionalBorrowedPtr<CreatureLib::Battling::ItemUseScript>
|
||||
AngelScriptResolver::LoadItemScript(const CreatureLib::Library::Item* item) {
|
||||
auto v = this->_itemUseScripts.TryGet(item);
|
||||
if (v.has_value()) {
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
ArbUt::OptionalUniquePtr<CreatureLib::Battling::BattleScript>
|
||||
LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
|
||||
const ArbUt::StringView& scriptName) override;
|
||||
ArbUt::OptionalUniquePtr<CreatureLib::Battling::ItemUseScript>
|
||||
ArbUt::OptionalBorrowedPtr<CreatureLib::Battling::ItemUseScript>
|
||||
LoadItemScript(const CreatureLib::Library::Item* item) override;
|
||||
|
||||
ArbUt::OptionalBorrowedPtr<const PkmnLib::Battling::EvolutionScript>
|
||||
|
|
|
@ -45,9 +45,9 @@ static AngelScriptItemUseScript* GetScript(PkmnLib::Battling::BattleLibrary* mai
|
|||
new CreatureLib::Library::SecondaryEffect(100, name, {}), nullptr, {});
|
||||
|
||||
auto s = lib->LoadItemScript(&item);
|
||||
auto script = dynamic_cast<AngelScriptItemUseScript*>(s.TakeOwnership());
|
||||
auto script = s.As<AngelScriptItemUseScript>();
|
||||
REQUIRE(script != nullptr);
|
||||
return script;
|
||||
return script.GetValue();
|
||||
}
|
||||
|
||||
TEST_CASE("Invoke isItemUsable item use script function on empty class") {
|
||||
|
|
Loading…
Reference in New Issue