From f447e406630ddb06e7a7d67d70c7a9db46a9f7d6 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 29 Oct 2021 18:29:30 +0200 Subject: [PATCH] Adds damage script hooks. --- src/Battling/Library/DamageLibrary.cpp | 3 ++- src/ScriptResolving/AngelScript/AngelScriptScript.cpp | 10 ++++++++++ src/ScriptResolving/AngelScript/AngelScriptScript.hpp | 2 ++ .../AngelScript/AngelScriptTypeInfo.hpp | 2 ++ .../AngelScript/TypeRegistry/BasicScriptClass.cpp | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Battling/Library/DamageLibrary.cpp b/src/Battling/Library/DamageLibrary.cpp index 12f67ec..70877e9 100644 --- a/src/Battling/Library/DamageLibrary.cpp +++ b/src/Battling/Library/DamageLibrary.cpp @@ -57,7 +57,8 @@ uint32_t PkmnLib::Battling::DamageLibrary::GetDamage(CreatureLib::Battling::Exec } else { damage = static_cast(floatDamage); } - // HOOK: Override damage + PKMN_HOOK(OverrideDamage, attack, attack, target, hitIndex, &damage); + PKMN_HOOK(OverrideIncomingDamage, target, attack, target, hitIndex, &damage); return damage; } uint8_t PkmnLib::Battling::DamageLibrary::GetBasePower(CreatureLib::Battling::ExecutingAttack* attack, diff --git a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp index 3998090..d78a307 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.cpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.cpp @@ -208,6 +208,16 @@ void AngelScriptScript::OverrideDamage(CreatureLib::Battling::ExecutingAttack* a ctx->SetArgAddress(3, damage); }) } +void AngelScriptScript::OverrideIncomingDamage(CreatureLib::Battling::ExecutingAttack* attack, + CreatureLib::Battling::Creature* target, uint8_t hitIndex, + uint32_t* damage) { + CALL_HOOK(OverrideIncomingDamage, { + ctx->SetArgObject(0, (void*)attack); + ctx->SetArgObject(1, (void*)target); + ctx->SetArgByte(2, hitIndex); + ctx->SetArgAddress(3, damage); + }) +} 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 e9721a4..f117b81 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptScript.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptScript.hpp @@ -104,6 +104,8 @@ public: uint8_t hitIndex, float* modifier) override; void OverrideDamage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, uint8_t hitIndex, uint32_t* damage) override; + void OverrideIncomingDamage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target, + uint8_t hitIndex, uint32_t* damage) override; void ChangePriority(CreatureLib::Battling::AttackTurnChoice* choice, int8_t* priority) override; void OnFail(CreatureLib::Battling::Creature* target) override; diff --git a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp index c9178a2..19bbdbd 100644 --- a/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp +++ b/src/ScriptResolving/AngelScript/AngelScriptTypeInfo.hpp @@ -119,6 +119,8 @@ public: "void ModifyDamageModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& modifier)"); SCRIPT_HOOK_FUNCTION(OverrideDamage, "void OverrideDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, int& damage)"); + SCRIPT_HOOK_FUNCTION(OverrideIncomingDamage, + "void OverrideIncomingDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, int& damage)"); SCRIPT_HOOK_FUNCTION( ModifyCriticalStage, diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp index a97e60b..00a726c 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/BasicScriptClass.cpp @@ -36,6 +36,7 @@ shared abstract class PkmnScript { void ModifyStatModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& modifier){}; void ModifyDamageModifier(ExecutingMove@ attack, Pokemon@ target, uint8 hit, float& modifier){}; void OverrideDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint& damage){}; + void OverrideIncomingDamage(ExecutingMove@ attack, Pokemon@ target, uint8 hit, uint& damage){}; void ChangePriority(MoveTurnChoice@ choice, int8& priority){}; void OnFail(Pokemon@ user){};