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();
|
auto rate = pokemon->GetSpecies()->GetCaptureRate();
|
||||||
|
|
||||||
u8 bonusBall = 1;
|
u8 bonusBall = 1;
|
||||||
auto* itemScript = dynamic_cast<PkmnItemUseScript*>(
|
auto itemScript = pokemon->GetLibrary()->GetScriptResolver()->LoadItemScript(catchItem).As<PkmnItemUseScript>();
|
||||||
pokemon->GetLibrary()->GetScriptResolver()->LoadItemScript(catchItem).GetValue());
|
if (!itemScript.HasValue()) {
|
||||||
itemScript->ModifyPokeballCatchBonus(pokemon, &bonusBall);
|
return {};
|
||||||
|
}
|
||||||
|
itemScript.GetValue()->ModifyPokeballCatchBonus(pokemon, &bonusBall);
|
||||||
|
|
||||||
u8 bonusStatus = 1;
|
u8 bonusStatus = 1;
|
||||||
PKMN_HOOK(ModifyCaptureRateBonus, pokemon, pokemon, catchItem, &bonusStatus);
|
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(_battleData.Side.HasValue());
|
||||||
Ensure(!IsFainted());
|
Ensure(!IsFainted());
|
||||||
Ensure(IsUsable());
|
Ensure(IsUsable());
|
||||||
Ensure(!GetBattleSide().GetValue()->IsSlotUnfillabe(this)) auto captureLibrary =
|
auto captureLibrary =
|
||||||
GetLibrary().ForceAs<const BattleLibrary>()->GetCaptureLibrary();
|
GetLibrary().ForceAs<const BattleLibrary>()->GetCaptureLibrary();
|
||||||
auto result = captureLibrary->TryCatch(this, catchItem, _battleData.Battle.GetValue()->GetRandom());
|
auto result = captureLibrary->TryCatch(this, catchItem, _battleData.Battle.GetValue()->GetRandom());
|
||||||
_battleData.Battle.GetValue()->TriggerEventListener<CaptureAttemptEvent>(this, result);
|
_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);
|
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) {
|
AngelScriptResolver::LoadItemScript(const CreatureLib::Library::Item* item) {
|
||||||
auto v = this->_itemUseScripts.TryGet(item);
|
auto v = this->_itemUseScripts.TryGet(item);
|
||||||
if (v.has_value()) {
|
if (v.has_value()) {
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
ArbUt::OptionalUniquePtr<CreatureLib::Battling::BattleScript>
|
ArbUt::OptionalUniquePtr<CreatureLib::Battling::BattleScript>
|
||||||
LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
|
LoadScript(const ArbUt::OptionalBorrowedPtr<void>& owner, ScriptCategory category,
|
||||||
const ArbUt::StringView& scriptName) override;
|
const ArbUt::StringView& scriptName) override;
|
||||||
ArbUt::OptionalUniquePtr<CreatureLib::Battling::ItemUseScript>
|
ArbUt::OptionalBorrowedPtr<CreatureLib::Battling::ItemUseScript>
|
||||||
LoadItemScript(const CreatureLib::Library::Item* item) override;
|
LoadItemScript(const CreatureLib::Library::Item* item) override;
|
||||||
|
|
||||||
ArbUt::OptionalBorrowedPtr<const PkmnLib::Battling::EvolutionScript>
|
ArbUt::OptionalBorrowedPtr<const PkmnLib::Battling::EvolutionScript>
|
||||||
|
|
|
@ -45,9 +45,9 @@ static AngelScriptItemUseScript* GetScript(PkmnLib::Battling::BattleLibrary* mai
|
||||||
new CreatureLib::Library::SecondaryEffect(100, name, {}), nullptr, {});
|
new CreatureLib::Library::SecondaryEffect(100, name, {}), nullptr, {});
|
||||||
|
|
||||||
auto s = lib->LoadItemScript(&item);
|
auto s = lib->LoadItemScript(&item);
|
||||||
auto script = dynamic_cast<AngelScriptItemUseScript*>(s.TakeOwnership());
|
auto script = s.As<AngelScriptItemUseScript>();
|
||||||
REQUIRE(script != nullptr);
|
REQUIRE(script != nullptr);
|
||||||
return script;
|
return script.GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Invoke isItemUsable item use script function on empty class") {
|
TEST_CASE("Invoke isItemUsable item use script function on empty class") {
|
||||||
|
|
Loading…
Reference in New Issue