Skip to content

Commit

Permalink
inputs:
Browse files Browse the repository at this point in the history
- don't make game input go through gui layer by default
- fix some game inputs still going through when not supposed to
  • Loading branch information
xiaoxiao921 committed Jun 1, 2024
1 parent 0f547f0 commit 2ca118a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lua_extensions/bindings/hades/inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ std::unordered_map<std::string, sgg::KeyboardButtonId> key_map = {
namespace lua::hades::inputs
{
bool enable_vanilla_debug_keybinds = false;
bool let_game_input_go_through_gui_layer = true;
bool let_game_input_go_through_gui_layer = false;

std::map<std::string, std::vector<keybind_callback>> vanilla_key_callbacks;
static gmAddress RegisterDebugKey{};
Expand Down
30 changes: 30 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,43 @@ static void hook_ReadAllAnimationData()
}
}

// TODO: Cleanup all this
template<class T>
static void ForceWrite(T &dst, const T &src)
{
DWORD old_flag;
::VirtualProtect(&dst, sizeof(T), PAGE_EXECUTE_READWRITE, &old_flag);
dst = src;
::VirtualProtect(&dst, sizeof(T), old_flag, &old_flag);
}

static void hook_PlayerHandleInput(void *this_, float elapsedSeconds, void *input)
{
static auto jump_stuff = gmAddress::scan("74 7C 38 05").as<uint8_t *>();

if (big::g_gui && big::g_gui->is_open() && !lua::hades::inputs::let_game_input_go_through_gui_layer)
{
if (jump_stuff && *jump_stuff != 0x75)
{
ForceWrite<uint8_t>(*jump_stuff, 0x75);
}

return;
}

if (jump_stuff && *jump_stuff != 0x74)
{
ForceWrite<uint8_t>(*jump_stuff, 0x74);
}

big::g_hooking->get_original<hook_PlayerHandleInput>()(this_, elapsedSeconds, input);
}

extern "C"
{
uintptr_t lpRemain = 0;
}

struct sgg_config_values_fixed
{
bool *addr = nullptr;
Expand Down Expand Up @@ -451,6 +478,9 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID)
LOG(INFO) << rom::g_project_name;
LOGF(INFO, "Build (GIT SHA1): {}", version::GIT_SHA1);

//static auto ptr_for_cave_test =
// gmAddress::scan("E8 ? ? ? ? EB 11 41 80 7D ? ?", "ptr_for_cave_test").get_call().offset(0x37);

// config test
if (0)
{
Expand Down

0 comments on commit 2ca118a

Please sign in to comment.