diff --git a/src/Battling/Library/MiscLibrary.cpp b/src/Battling/Library/MiscLibrary.cpp index 6f3bfb1..e2ea779 100644 --- a/src/Battling/Library/MiscLibrary.cpp +++ b/src/Battling/Library/MiscLibrary.cpp @@ -8,6 +8,12 @@ bool PkmnLib::Battling::MiscLibrary::IsCritical(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, uint8_t hit) const { + bool preventCrit = false; + PKMN_HOOK(PreventIncomingCritical, target, attack, target, hit, &preventCrit); + if (preventCrit) { + return false; + } + uint8_t critStage = 0; PKMN_HOOK(ModifyCriticalStage, attack, attack, target, hit, &critStage); Ensure(target->GetBattle().HasValue()); diff --git a/src/Battling/PkmnScript.hpp b/src/Battling/PkmnScript.hpp index cd13278..6805c90 100644 --- a/src/Battling/PkmnScript.hpp +++ b/src/Battling/PkmnScript.hpp @@ -16,6 +16,8 @@ namespace PkmnLib::Battling { public: PkmnScript(const ArbUt::OptionalBorrowedPtr& owner) : CreatureLib::Battling::BattleScript(owner) {} + virtual void PreventIncomingCritical(CreatureLib::Battling::ExecutingAttack* attack, + CreatureLib::Battling::Creature* target, uint8_t hit, bool* preventCrit){}; virtual void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage){}; virtual void OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack, diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp index d03ef5d..ff78c2d 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp @@ -249,6 +249,16 @@ void AngelScriptScript::OverrideIncomingDamage(CreatureLib::Battling::ExecutingA ctx->SetArgAddress(3, damage); }) } +void AngelScriptScript::PreventIncomingCritical(CreatureLib::Battling::ExecutingAttack* attack, + CreatureLib::Battling::Creature* target, uint8_t hit, + bool* preventCrit) { + CALL_HOOK(PreventIncomingCritical, { + ctx->SetArgObject(0, (void*)attack); + ctx->SetArgObject(1, (void*)target); + ctx->SetArgByte(2, hit); + ctx->SetArgAddress(3, preventCrit); + }) +} void AngelScriptScript::ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage) { CALL_HOOK(ModifyCriticalStage, { diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp index 345a439..f856953 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp @@ -133,6 +133,8 @@ public: // PkmnLib methods// //////////////////// + void PreventIncomingCritical(CreatureLib::Battling::ExecutingAttack* attack, + CreatureLib::Battling::Creature* target, uint8_t hit, bool* preventCrit) override; void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, uint8_t hit, uint8_t* critStage) override; void OverrideCriticalModifier(CreatureLib::Battling::ExecutingAttack* attack, diff --git a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp index 3e2924a..2c6bb6d 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp @@ -147,6 +147,9 @@ public: SCRIPT_HOOK_FUNCTION(OverrideIncomingDamage, "void OverrideIncomingDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, int& damage)"); + SCRIPT_HOOK_FUNCTION( + PreventIncomingCritical, + "void PreventIncomingCritical(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& preventCrit)"); SCRIPT_HOOK_FUNCTION( ModifyCriticalStage, "void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage)"); diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp index 2cb1cab..f7b2c8a 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp @@ -58,6 +58,7 @@ shared abstract class PkmnScript { void OnFaint(Pokemon@ pokemon, DamageSource damageSource){}; // PkmnLib methods + void PreventIncomingCritical(ExecutingMove@ attack, Pokemon@ target, uint8 hit, bool& preventCrit){}; void ModifyCriticalStage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint8& critStage){}; void OverrideCriticalModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& critModifier){}; void OverrideSTABModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& stabModifier){};