diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp index ffd8f10..16325bf 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterBattleClass.cpp @@ -1,8 +1,10 @@ #include "RegisterBattleClass.hpp" #include #include +#include "../../../../../extern/angelscript_addons/scripthandle/scripthandle.h" #include "../../../../Battling/Battle/Battle.hpp" #include "../../../../Battling/Pokemon/Pokemon.hpp" +#include "../../AngelScriptResolver.hpp" #include "../../AngelScriptScript.hpp" #include "../HelperFile.hpp" @@ -52,9 +54,12 @@ CreatureLib::Battling::BattleSide* GetBattleSideWrapper(PkmnLib::Battling::Battl return battle->GetSides()[index]; } -static asIScriptObject* AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) { - auto* scriptObject = (AngelScriptScript*)obj->AddVolatileScript(name); - return scriptObject->GetRawAngelscriptObject(); +static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Battle* obj, const ArbUt::StringView& name) { + auto handle = CScriptHandle(); + auto* resolver = static_cast(obj->GetLibrary()->GetScriptResolver().get()); + auto script = static_cast(obj->AddVolatileScript(name))->GetRawAngelscriptObject(); + handle.Set(script, resolver->GetBaseType("PkmnScript")); + return handle; } static u8 GetPokemonIndexWrapper(CreatureLib::Battling::BattleSide* obj, PkmnLib::Battling::Pokemon* pokemon) { @@ -90,7 +95,7 @@ void RegisterBattleClass::RegisterBattle(asIScriptEngine* engine) { r = engine->RegisterObjectMethod("Battle", "ChoiceQueue@ get_TurnQueue() const property", asFUNCTION(GetCurrentTurnQueueWrapper), asCALL_CDECL_OBJFIRST); Ensure(r >= 0); - r = engine->RegisterObjectMethod("Battle", "ref@ AddVolatile(const constString &in name) const", + r = engine->RegisterObjectMethod("Battle", "ref@ AddVolatile(const constString &in name)", asFUNCTION(AddVolatileWrapper), asCALL_CDECL_OBJFIRST); Ensure(r >= 0); r = engine->RegisterObjectMethod( diff --git a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp index f4bd6f5..455a63b 100644 --- a/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp +++ b/src/ScriptResolving/AngelScript/TypeRegistry/Battling/RegisterPokemonClass.cpp @@ -94,7 +94,6 @@ static CScriptHandle AddVolatileWrapper(PkmnLib::Battling::Pokemon* obj, const A auto handle = CScriptHandle(); auto* resolver = static_cast(obj->GetLibrary()->GetScriptResolver().get()); auto script = static_cast(obj->AddVolatileScript(name))->GetRawAngelscriptObject(); - script->AddRef(); handle.Set(script, resolver->GetBaseType("PkmnScript")); return handle; }