Improve OnInitialize performance in AngelScript by caching type of parameter array.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
330a24c493
commit
1d5c6d696e
|
@ -139,7 +139,7 @@ CreatureLib::Battling::Script* AngelScripResolver::LoadScript(ScriptCategory cat
|
||||||
auto ctx = _contextPool->RequestContext();
|
auto ctx = _contextPool->RequestContext();
|
||||||
auto obj = t->Instantiate(ctx);
|
auto obj = t->Instantiate(ctx);
|
||||||
_contextPool->ReturnContextToPool(ctx);
|
_contextPool->ReturnContextToPool(ctx);
|
||||||
return new AngelScriptScript(t, obj, _contextPool);
|
return new AngelScriptScript(this, t, obj, _contextPool);
|
||||||
}
|
}
|
||||||
void AngelScripResolver::FinalizeModule() {
|
void AngelScripResolver::FinalizeModule() {
|
||||||
int r = _builder.BuildModule();
|
int r = _builder.BuildModule();
|
||||||
|
|
|
@ -22,6 +22,7 @@ private:
|
||||||
static void MessageCallback(const asSMessageInfo* msg, void* param);
|
static void MessageCallback(const asSMessageInfo* msg, void* param);
|
||||||
static void Print(const std::string& str) { std::cout << str << std::endl; }
|
static void Print(const std::string& str) { std::cout << str << std::endl; }
|
||||||
Dictionary<ScriptCategory, Dictionary<ConstString, AngelScriptTypeInfo*>> _typeDatabase;
|
Dictionary<ScriptCategory, Dictionary<ConstString, AngelScriptTypeInfo*>> _typeDatabase;
|
||||||
|
Dictionary<ConstString, asITypeInfo*> _baseTypes;
|
||||||
|
|
||||||
void RegisterTypes();
|
void RegisterTypes();
|
||||||
void InitializeByteCode(asIBinaryStream* stream,
|
void InitializeByteCode(asIBinaryStream* stream,
|
||||||
|
@ -55,5 +56,14 @@ public:
|
||||||
const Dictionary<ScriptCategory, Dictionary<ConstString, AngelScriptTypeInfo*>>& GetTypeDatabase() const noexcept {
|
const Dictionary<ScriptCategory, Dictionary<ConstString, AngelScriptTypeInfo*>>& GetTypeDatabase() const noexcept {
|
||||||
return _typeDatabase;
|
return _typeDatabase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
asITypeInfo* GetBaseType(const ConstString& name){
|
||||||
|
asITypeInfo* t = nullptr;
|
||||||
|
if (!_baseTypes.TryGet(name, t)){
|
||||||
|
t = this->_engine->GetTypeInfoByDecl(name.c_str());
|
||||||
|
_baseTypes.Insert(name, t);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
#endif // PKMNLIB_ANGELSCRIPRESOLVER_HPP
|
#endif // PKMNLIB_ANGELSCRIPRESOLVER_HPP
|
||||||
|
|
|
@ -1 +1,260 @@
|
||||||
#include "AngelScriptScript.hpp"
|
#include "AngelScriptScript.hpp"
|
||||||
|
#include "AngelScripResolver.hpp"
|
||||||
|
|
||||||
|
#define CALL_HOOK(name, setup) \
|
||||||
|
auto s = _type->Get##name(); \
|
||||||
|
if (!s.Exists) \
|
||||||
|
return; \
|
||||||
|
auto ctx = asGetActiveContext(); \
|
||||||
|
bool newContext = false; \
|
||||||
|
if (ctx == nullptr) { \
|
||||||
|
ctx = _ctxPool->RequestContext(); \
|
||||||
|
newContext = true; \
|
||||||
|
} else { \
|
||||||
|
ctx->PushState(); \
|
||||||
|
} \
|
||||||
|
ctx->Prepare(s.Function); \
|
||||||
|
ctx->SetObject(_obj); \
|
||||||
|
setup; \
|
||||||
|
auto scriptResult = ctx->Execute(); \
|
||||||
|
if (scriptResult != asEXECUTION_FINISHED) { \
|
||||||
|
if (scriptResult == asEXECUTION_EXCEPTION) { \
|
||||||
|
std::stringstream err; \
|
||||||
|
err << "Script exception in script '" << GetName().c_str() << "', line " << ctx->GetExceptionLineNumber() \
|
||||||
|
<< ". Message: '" << ctx->GetExceptionString() << "'."; \
|
||||||
|
if (newContext) { \
|
||||||
|
_ctxPool->ReturnContextToPool(ctx); \
|
||||||
|
} else { \
|
||||||
|
ctx->PopState(); \
|
||||||
|
} \
|
||||||
|
throw CreatureException(err.str()); \
|
||||||
|
} \
|
||||||
|
if (newContext) { \
|
||||||
|
_ctxPool->ReturnContextToPool(ctx); \
|
||||||
|
} else { \
|
||||||
|
ctx->PopState(); \
|
||||||
|
} \
|
||||||
|
throw CreatureException("Script didn't finish properly; message " + std::to_string(scriptResult)); \
|
||||||
|
} \
|
||||||
|
if (newContext) { \
|
||||||
|
_ctxPool->ReturnContextToPool(ctx); \
|
||||||
|
} else { \
|
||||||
|
ctx->PopState(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
CScriptArray*
|
||||||
|
AngelScriptScript::GetEffectParameters(const Arbutils::Collections::List<CreatureLib::Library::EffectParameter*>& ls) {
|
||||||
|
asITypeInfo* t = _resolver->GetBaseType("array<EffectParameter@>"_cnc);
|
||||||
|
CScriptArray* arr = CScriptArray::Create(t, ls.Count());
|
||||||
|
for (size_t i = 0; i < ls.Count(); i++) {
|
||||||
|
arr->SetValue(i, (void**)&ls[i]);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AngelScriptScript::OnInitialize(const List<CreatureLib::Library::EffectParameter*>& parameters) {
|
||||||
|
CScriptArray* arr = nullptr;
|
||||||
|
CALL_HOOK(OnInitialize, {
|
||||||
|
arr = GetEffectParameters(parameters);
|
||||||
|
ctx->SetArgAddress(0, arr);
|
||||||
|
})
|
||||||
|
if (arr != nullptr) {
|
||||||
|
arr->Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void AngelScriptScript::Stack() { CALL_HOOK(Stack, ); }
|
||||||
|
void AngelScriptScript::OnRemove() { CALL_HOOK(OnRemove, ); }
|
||||||
|
void AngelScriptScript::OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) {
|
||||||
|
CALL_HOOK(OnBeforeTurn, { ctx->SetArgObject(0, (void*)choice); })
|
||||||
|
}
|
||||||
|
void AngelScriptScript::ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice, ConstString* outAttack) {
|
||||||
|
CALL_HOOK(ChangeAttack, {
|
||||||
|
ctx->SetArgObject(0, (void*)choice);
|
||||||
|
ctx->SetArgAddress(0, outAttack);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::PreventAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) {
|
||||||
|
CALL_HOOK(PreventAttack, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgAddress(1, outResult);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::FailAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outFailed) {
|
||||||
|
CALL_HOOK(FailAttack, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgAddress(1, outFailed);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::StopBeforeAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) {
|
||||||
|
CALL_HOOK(StopBeforeAttack, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgAddress(1, outResult);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::OnBeforeAttack(CreatureLib::Battling::ExecutingAttack* attack) {
|
||||||
|
CALL_HOOK(OnBeforeAttack, { ctx->SetArgObject(0, (void*)attack); })
|
||||||
|
}
|
||||||
|
void AngelScriptScript::FailIncomingAttack(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, bool* outResult) {
|
||||||
|
CALL_HOOK(FailIncomingAttack, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgAddress(2, outResult);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::IsInvulnerable(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, bool* outResult) {
|
||||||
|
CALL_HOOK(IsInvulnerable, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgAddress(2, outResult);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::OnAttackMiss(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target) {
|
||||||
|
CALL_HOOK(OnAttackMiss, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::ChangeAttackType(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber, uint8_t* outType) {
|
||||||
|
CALL_HOOK(ChangeAttackType, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgByte(2, hitNumber);
|
||||||
|
ctx->SetArgAddress(3, outType);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::ChangeEffectiveness(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber,
|
||||||
|
float* effectiveness) {
|
||||||
|
CALL_HOOK(ChangeEffectiveness, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgByte(2, hitNumber);
|
||||||
|
ctx->SetArgAddress(3, effectiveness);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::PreventSecondaryEffects(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber,
|
||||||
|
bool* outResult) {
|
||||||
|
CALL_HOOK(PreventSecondaryEffects, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgByte(2, hitNumber);
|
||||||
|
ctx->SetArgAddress(3, outResult);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::OnSecondaryEffect(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber) {
|
||||||
|
CALL_HOOK(OnSecondaryEffect, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgByte(2, hitNumber);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::OnAfterHits(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target) {
|
||||||
|
CALL_HOOK(OnAfterHits, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::PreventSelfSwitch(const CreatureLib::Battling::SwitchTurnChoice* choice, bool* outResult) {
|
||||||
|
CALL_HOOK(PreventSelfSwitch, {
|
||||||
|
ctx->SetArgObject(0, (void*)choice);
|
||||||
|
ctx->SetArgAddress(1, outResult);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::ModifyEffectChance(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, float* chance) {
|
||||||
|
CALL_HOOK(ModifyEffectChance, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgAddress(2, chance);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::ModifyIncomingEffectChance(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, float* chance) {
|
||||||
|
CALL_HOOK(ModifyIncomingEffectChance, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgAddress(2, chance);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::OverrideBasePower(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
|
||||||
|
uint8_t* basePower) {
|
||||||
|
CALL_HOOK(OverrideBasePower, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgByte(2, hitIndex);
|
||||||
|
ctx->SetArgAddress(3, basePower);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::ChangeDamageStatsUser(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
|
||||||
|
CreatureLib::Battling::Creature** statsUser) {
|
||||||
|
CALL_HOOK(ChangeDamageStatsUser, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgByte(2, hitIndex);
|
||||||
|
ctx->SetArgAddress(3, statsUser);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::BypassDefensiveStat(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex, bool* bypass) {
|
||||||
|
CALL_HOOK(BypassDefensiveStat, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgByte(2, hitIndex);
|
||||||
|
ctx->SetArgAddress(3, bypass);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::BypassOffensiveStat(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex, bool* bypass) {
|
||||||
|
CALL_HOOK(BypassOffensiveStat, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgByte(2, hitIndex);
|
||||||
|
ctx->SetArgAddress(3, bypass);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::ModifyStatModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex, float* modifier) {
|
||||||
|
CALL_HOOK(ModifyStatModifier, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgByte(2, hitIndex);
|
||||||
|
ctx->SetArgAddress(3, modifier);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::ModifyDamageModifier(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex,
|
||||||
|
float* modifier) {
|
||||||
|
CALL_HOOK(ModifyDamageModifier, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgByte(2, hitIndex);
|
||||||
|
ctx->SetArgAddress(3, modifier);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
void AngelScriptScript::OverrideDamage(CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
|
CreatureLib::Battling::Creature* target, uint8_t hitIndex, uint32_t* damage) {
|
||||||
|
CALL_HOOK(OverrideDamage, {
|
||||||
|
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, {
|
||||||
|
ctx->SetArgObject(0, (void*)attack);
|
||||||
|
ctx->SetArgObject(1, (void*)target);
|
||||||
|
ctx->SetArgByte(2, hit);
|
||||||
|
ctx->SetArgAddress(3, critStage);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -10,16 +10,19 @@
|
||||||
#include "AngelScriptTypeInfo.hpp"
|
#include "AngelScriptTypeInfo.hpp"
|
||||||
#include "ContextPool.hpp"
|
#include "ContextPool.hpp"
|
||||||
|
|
||||||
|
class AngelScripResolver;
|
||||||
class AngelScriptScript : public PkmnLib::Battling::PkmnScript {
|
class AngelScriptScript : public PkmnLib::Battling::PkmnScript {
|
||||||
private:
|
private:
|
||||||
|
AngelScripResolver* _resolver = nullptr;
|
||||||
AngelScriptTypeInfo* _type = nullptr;
|
AngelScriptTypeInfo* _type = nullptr;
|
||||||
ContextPool* _ctxPool = nullptr;
|
ContextPool* _ctxPool = nullptr;
|
||||||
|
|
||||||
asIScriptObject* _obj = nullptr;
|
asIScriptObject* _obj = nullptr;
|
||||||
|
CScriptArray* GetEffectParameters(const List<CreatureLib::Library::EffectParameter*>& ls);
|
||||||
public:
|
public:
|
||||||
AngelScriptScript(AngelScriptTypeInfo* type, asIScriptObject* obj, ContextPool* ctxPool)
|
AngelScriptScript(AngelScripResolver* resolver, AngelScriptTypeInfo* type, asIScriptObject* obj,
|
||||||
: _type(type), _ctxPool(ctxPool), _obj(obj) {}
|
ContextPool* ctxPool)
|
||||||
|
: _resolver(resolver), _type(type), _ctxPool(ctxPool), _obj(obj) {}
|
||||||
|
|
||||||
~AngelScriptScript() override { _obj->Release(); }
|
~AngelScriptScript() override { _obj->Release(); }
|
||||||
|
|
||||||
|
@ -34,281 +37,72 @@ public:
|
||||||
|
|
||||||
ContextPool* GetContextPool() { return _ctxPool; }
|
ContextPool* GetContextPool() { return _ctxPool; }
|
||||||
|
|
||||||
#define CALL_HOOK(name, setup) \
|
void OnInitialize(const Arbutils::Collections::List<CreatureLib::Library::EffectParameter*>& parameters) override;
|
||||||
auto s = _type->Get##name(); \
|
void Stack() override;
|
||||||
if (!s.Exists) \
|
|
||||||
return; \
|
|
||||||
auto ctx = asGetActiveContext(); \
|
|
||||||
bool newContext = false; \
|
|
||||||
if (ctx == nullptr) { \
|
|
||||||
ctx = _ctxPool->RequestContext(); \
|
|
||||||
newContext = true; \
|
|
||||||
} else { \
|
|
||||||
ctx->PushState(); \
|
|
||||||
} \
|
|
||||||
ctx->Prepare(s.Function); \
|
|
||||||
ctx->SetObject(_obj); \
|
|
||||||
setup; \
|
|
||||||
auto scriptResult = ctx->Execute(); \
|
|
||||||
if (scriptResult != asEXECUTION_FINISHED) { \
|
|
||||||
if (scriptResult == asEXECUTION_EXCEPTION) { \
|
|
||||||
std::stringstream err; \
|
|
||||||
err << "Script exception in script '" << GetName().c_str() << "', line " << ctx->GetExceptionLineNumber() \
|
|
||||||
<< ". Message: '" << ctx->GetExceptionString() << "'."; \
|
|
||||||
if (newContext) { \
|
|
||||||
_ctxPool->ReturnContextToPool(ctx); \
|
|
||||||
} else { \
|
|
||||||
ctx->PopState(); \
|
|
||||||
} \
|
|
||||||
throw CreatureException(err.str()); \
|
|
||||||
} \
|
|
||||||
if (newContext) { \
|
|
||||||
_ctxPool->ReturnContextToPool(ctx); \
|
|
||||||
} else { \
|
|
||||||
ctx->PopState(); \
|
|
||||||
} \
|
|
||||||
throw CreatureException("Script didn't finish properly; message " + std::to_string(scriptResult)); \
|
|
||||||
} \
|
|
||||||
if (newContext) { \
|
|
||||||
_ctxPool->ReturnContextToPool(ctx); \
|
|
||||||
} else { \
|
|
||||||
ctx->PopState(); \
|
|
||||||
}
|
|
||||||
|
|
||||||
static CScriptArray*
|
void OnRemove() override;
|
||||||
GetEffectParameters(asIScriptContext* ctx,
|
|
||||||
const Arbutils::Collections::List<CreatureLib::Library::EffectParameter*>& ls) {
|
|
||||||
asIScriptEngine* engine = ctx->GetEngine();
|
|
||||||
asITypeInfo* t = engine->GetTypeInfoByDecl("array<EffectParameter@>");
|
|
||||||
CScriptArray* arr = CScriptArray::Create(t, ls.Count());
|
|
||||||
for (size_t i = 0; i < ls.Count(); i++) {
|
|
||||||
arr->SetValue(i, (void**)&ls[i]);
|
|
||||||
}
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnInitialize(const Arbutils::Collections::List<CreatureLib::Library::EffectParameter*>& parameters) override {
|
void OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) override;
|
||||||
CScriptArray* arr = nullptr;
|
|
||||||
CALL_HOOK(OnInitialize, {
|
|
||||||
arr = GetEffectParameters(ctx, parameters);
|
|
||||||
ctx->SetArgAddress(0, arr);
|
|
||||||
})
|
|
||||||
if (arr != nullptr) {
|
|
||||||
arr->Release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void Stack() override { CALL_HOOK(Stack, ); }
|
|
||||||
|
|
||||||
void OnRemove() override { CALL_HOOK(OnRemove, ); }
|
void ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice, ConstString* outAttack) override;
|
||||||
|
|
||||||
void OnBeforeTurn(const CreatureLib::Battling::BaseTurnChoice* choice) override {
|
void PreventAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) override;
|
||||||
CALL_HOOK(OnBeforeTurn, { ctx->SetArgObject(0, (void*)choice); })
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChangeAttack(CreatureLib::Battling::AttackTurnChoice* choice, ConstString* outAttack) override {
|
void FailAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outFailed) override;
|
||||||
CALL_HOOK(ChangeAttack, {
|
|
||||||
ctx->SetArgObject(0, (void*)choice);
|
|
||||||
ctx->SetArgAddress(0, outAttack);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
void PreventAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) override {
|
void StopBeforeAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) override;
|
||||||
CALL_HOOK(PreventAttack, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgAddress(1, outResult);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
void FailAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outFailed) override {
|
void OnBeforeAttack(CreatureLib::Battling::ExecutingAttack* attack) override;
|
||||||
CALL_HOOK(FailAttack, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgAddress(1, outFailed);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
void StopBeforeAttack(CreatureLib::Battling::ExecutingAttack* attack, bool* outResult) override {
|
|
||||||
CALL_HOOK(StopBeforeAttack, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgAddress(1, outResult);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnBeforeAttack(CreatureLib::Battling::ExecutingAttack* attack) override {
|
|
||||||
CALL_HOOK(OnBeforeAttack, { ctx->SetArgObject(0, (void*)attack); })
|
|
||||||
}
|
|
||||||
|
|
||||||
void FailIncomingAttack(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
void FailIncomingAttack(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||||
bool* outResult) override {
|
bool* outResult) override;
|
||||||
CALL_HOOK(FailIncomingAttack, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgAddress(2, outResult);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
void IsInvulnerable(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
void IsInvulnerable(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||||
bool* outResult) override {
|
bool* outResult) override;
|
||||||
CALL_HOOK(IsInvulnerable, {
|
void OnAttackMiss(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target) override;
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgAddress(2, outResult);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
void OnAttackMiss(CreatureLib::Battling::ExecutingAttack* attack,
|
|
||||||
CreatureLib::Battling::Creature* target) override {
|
|
||||||
CALL_HOOK(OnAttackMiss, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChangeAttackType(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
void ChangeAttackType(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||||
uint8_t hitNumber, uint8_t* outType) override {
|
uint8_t hitNumber, uint8_t* outType) override;
|
||||||
CALL_HOOK(ChangeAttackType, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgByte(2, hitNumber);
|
|
||||||
ctx->SetArgAddress(3, outType);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChangeEffectiveness(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
void ChangeEffectiveness(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||||
uint8_t hitNumber, float* effectiveness) override {
|
uint8_t hitNumber, float* effectiveness) override;
|
||||||
CALL_HOOK(ChangeEffectiveness, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgByte(2, hitNumber);
|
|
||||||
ctx->SetArgAddress(3, effectiveness);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
void PreventSecondaryEffects(const CreatureLib::Battling::ExecutingAttack* attack,
|
void PreventSecondaryEffects(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
CreatureLib::Battling::Creature* target, uint8_t hitNumber, bool* outResult) override {
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber, bool* outResult) override;
|
||||||
CALL_HOOK(PreventSecondaryEffects, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgByte(2, hitNumber);
|
|
||||||
ctx->SetArgAddress(3, outResult);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnSecondaryEffect(const CreatureLib::Battling::ExecutingAttack* attack,
|
void OnSecondaryEffect(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
CreatureLib::Battling::Creature* target, uint8_t hitNumber) override {
|
CreatureLib::Battling::Creature* target, uint8_t hitNumber) override;
|
||||||
CALL_HOOK(OnSecondaryEffect, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgByte(2, hitNumber);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnAfterHits(const CreatureLib::Battling::ExecutingAttack* attack,
|
void OnAfterHits(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
CreatureLib::Battling::Creature* target) override {
|
CreatureLib::Battling::Creature* target) override;
|
||||||
CALL_HOOK(OnAfterHits, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
void PreventSelfSwitch(const CreatureLib::Battling::SwitchTurnChoice* choice, bool* outResult) override {
|
void PreventSelfSwitch(const CreatureLib::Battling::SwitchTurnChoice* choice, bool* outResult) override;
|
||||||
CALL_HOOK(PreventSelfSwitch, {
|
|
||||||
ctx->SetArgObject(0, (void*)choice);
|
|
||||||
ctx->SetArgAddress(1, outResult);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
void ModifyEffectChance(const CreatureLib::Battling::ExecutingAttack* attack,
|
void ModifyEffectChance(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
CreatureLib::Battling::Creature* target, float* chance) override {
|
CreatureLib::Battling::Creature* target, float* chance) override;
|
||||||
CALL_HOOK(ModifyEffectChance, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgAddress(2, chance);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
void ModifyIncomingEffectChance(const CreatureLib::Battling::ExecutingAttack* attack,
|
void ModifyIncomingEffectChance(const CreatureLib::Battling::ExecutingAttack* attack,
|
||||||
CreatureLib::Battling::Creature* target, float* chance) override {
|
CreatureLib::Battling::Creature* target, float* chance) override;
|
||||||
CALL_HOOK(ModifyIncomingEffectChance, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgAddress(2, chance);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
void OverrideBasePower(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
void OverrideBasePower(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||||
uint8_t hitIndex, uint8_t* basePower) override {
|
uint8_t hitIndex, uint8_t* basePower) override;
|
||||||
CALL_HOOK(OverrideBasePower, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgByte(2, hitIndex);
|
|
||||||
ctx->SetArgAddress(3, basePower);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
void ChangeDamageStatsUser(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
void ChangeDamageStatsUser(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||||
uint8_t hitIndex, CreatureLib::Battling::Creature** statsUser) override {
|
uint8_t hitIndex, CreatureLib::Battling::Creature** statsUser) override;
|
||||||
CALL_HOOK(ChangeDamageStatsUser, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgByte(2, hitIndex);
|
|
||||||
ctx->SetArgAddress(3, statsUser);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
void BypassDefensiveStat(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
void BypassDefensiveStat(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||||
uint8_t hitIndex, bool* bypass) override {
|
uint8_t hitIndex, bool* bypass) override;
|
||||||
CALL_HOOK(BypassDefensiveStat, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgByte(2, hitIndex);
|
|
||||||
ctx->SetArgAddress(3, bypass);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
void BypassOffensiveStat(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
void BypassOffensiveStat(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||||
uint8_t hitIndex, bool* bypass) override {
|
uint8_t hitIndex, bool* bypass) override;
|
||||||
CALL_HOOK(BypassOffensiveStat, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgByte(2, hitIndex);
|
|
||||||
ctx->SetArgAddress(3, bypass);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
void ModifyStatModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
void ModifyStatModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||||
uint8_t hitIndex, float* modifier) override {
|
uint8_t hitIndex, float* modifier) override;
|
||||||
CALL_HOOK(ModifyStatModifier, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgByte(2, hitIndex);
|
|
||||||
ctx->SetArgAddress(3, modifier);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
void ModifyDamageModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
void ModifyDamageModifier(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||||
uint8_t hitIndex, float* modifier) override {
|
uint8_t hitIndex, float* modifier) override;
|
||||||
CALL_HOOK(ModifyDamageModifier, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgByte(2, hitIndex);
|
|
||||||
ctx->SetArgAddress(3, modifier);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
void OverrideDamage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
void OverrideDamage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||||
uint8_t hitIndex, uint32_t* damage) override {
|
uint8_t hitIndex, uint32_t* damage) override;
|
||||||
CALL_HOOK(OverrideDamage, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgByte(2, hitIndex);
|
|
||||||
ctx->SetArgAddress(3, damage);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
// PkmnLib methods//
|
// PkmnLib methods//
|
||||||
////////////////////
|
////////////////////
|
||||||
|
|
||||||
void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
void ModifyCriticalStage(CreatureLib::Battling::ExecutingAttack* attack, CreatureLib::Battling::Creature* target,
|
||||||
uint8_t hit, uint8_t* critStage) override {
|
uint8_t hit, uint8_t* critStage) override;
|
||||||
CALL_HOOK(ModifyCriticalStage, {
|
|
||||||
ctx->SetArgObject(0, (void*)attack);
|
|
||||||
ctx->SetArgObject(1, (void*)target);
|
|
||||||
ctx->SetArgByte(2, hit);
|
|
||||||
ctx->SetArgAddress(3, critStage);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef CALL_HOOK
|
#undef CALL_HOOK
|
||||||
|
|
Loading…
Reference in New Issue