Skip to content

Commit

Permalink
hook test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rozelette committed Jun 1, 2024
1 parent acae277 commit be41147
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
9 changes: 9 additions & 0 deletions soh/build.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <libultraship/libultra.h>

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[] = "";
27 changes: 27 additions & 0 deletions soh/soh/ActorDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "Scripting.h"

#include "soh/Enhancements/game-interactor/GameInteractor.h"

ActorDB* ActorDB::Instance;


Expand Down Expand Up @@ -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<ICompiledScript> owlScript;

static void TestFunction(GIVanillaBehavior id, bool* should, void* opt) {
Scripting::CallIfExists<GameInteractor::OnVanillaBehavior::fn_raw>(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<GameInteractor::OnVanillaBehavior>([](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) {
Expand Down
1 change: 1 addition & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ typedef uint32_t HOOK_ID;
struct name { \
typedef std::function<void args> fn; \
typedef std::function<bool args> filter; \
using fn_raw = void args; \
}

#define REGISTER_VB_SHOULD(flag, body) \
Expand Down
2 changes: 2 additions & 0 deletions soh/soh/PyZelda.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ template <> struct GetTypeChar<char*> { static constexpr std::string_view value

template <typename T> struct GetTypeChar<T*> { static constexpr std::string_view value = "K"; };

template <typename T> requires std::is_enum_v<T> struct GetTypeChar<T> { static constexpr std::string_view value = "I"; }; // TODO 64b value?

template <typename ReturnType> static ReturnType GetCallResult(PyObject* ret);

template <> static void GetCallResult<void>(PyObject* ret) {
Expand Down
2 changes: 1 addition & 1 deletion soh/src/overlays/actors/ovl_En_Owl/z_en_owl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit be41147

Please sign in to comment.