From be41147a18e48521a132b13c3009f63cf8461e29 Mon Sep 17 00:00:00 2001 From: rozlette Date: Fri, 31 May 2024 19:34:26 -0500 Subject: [PATCH] hook test --- soh/build.c | 9 +++++++ soh/soh/ActorDB.cpp | 27 +++++++++++++++++++ .../game-interactor/GameInteractor.h | 1 + soh/soh/PyZelda.h | 2 ++ soh/src/overlays/actors/ovl_En_Owl/z_en_owl.c | 2 +- 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 soh/build.c diff --git a/soh/build.c b/soh/build.c new file mode 100644 index 00000000000..ec3a85ad5f6 --- /dev/null +++ b/soh/build.c @@ -0,0 +1,9 @@ +#include + +const char gBuildVersion[] = "MacReady Charlie (8.0.4)"; +const u16 gBuildVersionMajor = 8; +const u16 gBuildVersionMinor = 0; +const u16 gBuildVersionPatch = 4; +const char gBuildTeam[] = "github.com/harbourmasters"; +const char gBuildDate[] = __DATE__ " " __TIME__; +const char gBuildMakeOption[] = ""; diff --git a/soh/soh/ActorDB.cpp b/soh/soh/ActorDB.cpp index 7f4a924552a..e65aeda97fc 100644 --- a/soh/soh/ActorDB.cpp +++ b/soh/soh/ActorDB.cpp @@ -5,6 +5,8 @@ #include "Scripting.h" +#include "soh/Enhancements/game-interactor/GameInteractor.h" + ActorDB* ActorDB::Instance; @@ -761,11 +763,36 @@ static std::string EnPythonScript2 = " actor.draw(play)\n" "\n"; +static std::string OwlScript = +"import ctypes\n" +"def Func(id, should, opt):\n" +" if id == 8:\n" +" ctypes.cast(should, ctypes.POINTER(ctypes.c_bool))[0] = 1\n" +"\n"; + +static std::shared_ptr owlScript; + +static void TestFunction(GIVanillaBehavior id, bool* should, void* opt) { + Scripting::CallIfExists(owlScript, "Func", id, should, opt); +} + void ActorDB::AddBuiltInCustomActors() { gEnPartnerId = ActorDB::Instance->AddEntry(EnPartnerInit).entry.id; EnPythonInit.script = PyZelda::Instance->Compile(EnPythonScript2); gEnPythonId = ActorDB::Instance->AddEntry(EnPythonInit).entry.id; + + owlScript = PyZelda::Instance->Compile(OwlScript); + + static uint32_t onVanillaBehaviorHook = GameInteractor::Instance->RegisterGameHook([](GIVanillaBehavior id, bool* should, void* opt) { + TestFunction(id, should, opt); + }); + + bool hey = false; + TestFunction(VB_OPEN_KOKIRI_FOREST, &hey, 0); + assert(hey == false); + TestFunction(VB_OWL_INTERACTION, &hey, 0); + assert(hey == true); } extern "C" ActorDBEntry* ActorDB_Retrieve(const int id) { diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor.h b/soh/soh/Enhancements/game-interactor/GameInteractor.h index 57f1d1e5c99..6f76bf5a201 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor.h +++ b/soh/soh/Enhancements/game-interactor/GameInteractor.h @@ -439,6 +439,7 @@ typedef uint32_t HOOK_ID; struct name { \ typedef std::function fn; \ typedef std::function filter; \ + using fn_raw = void args; \ } #define REGISTER_VB_SHOULD(flag, body) \ diff --git a/soh/soh/PyZelda.h b/soh/soh/PyZelda.h index 02d9f87c6fa..7d61f790202 100644 --- a/soh/soh/PyZelda.h +++ b/soh/soh/PyZelda.h @@ -55,6 +55,8 @@ template <> struct GetTypeChar { static constexpr std::string_view value template struct GetTypeChar { static constexpr std::string_view value = "K"; }; +template requires std::is_enum_v struct GetTypeChar { static constexpr std::string_view value = "I"; }; // TODO 64b value? + template static ReturnType GetCallResult(PyObject* ret); template <> static void GetCallResult(PyObject* ret) { diff --git a/soh/src/overlays/actors/ovl_En_Owl/z_en_owl.c b/soh/src/overlays/actors/ovl_En_Owl/z_en_owl.c index 776c5914933..cddb3135e8a 100644 --- a/soh/src/overlays/actors/ovl_En_Owl/z_en_owl.c +++ b/soh/src/overlays/actors/ovl_En_Owl/z_en_owl.c @@ -285,7 +285,7 @@ s32 EnOwl_CheckInitTalk(EnOwl* this, PlayState* play, u16 textId, f32 targetDist distCheck = (flags & 2) ? 200.0f : 1000.0f; if (GameInteractor_Should(VB_OWL_INTERACTION, this->actor.xzDistToPlayer < targetDist, this)) { this->actor.flags |= ACTOR_FLAG_WILL_TALK; - func_8002F1C4(&this->actor, play, targetDist, distCheck, 0); + func_8002F1C4(&this->actor, play, this->actor.xzDistToPlayer, distCheck, 0); } return false; }