Skip to content

Commit

Permalink
feat(all): Target v3.0.0-alpha.1 and add support for macchew os
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaghettDev committed Jun 6, 2024
1 parent 0a9c505 commit 9e3a644
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 43 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [v2.3.0-beta] - 2024-06-06

### Added

- MacOS support :o

### Changed

- Target Geode version (v2.0.0-beta.27 -> v3.0.0-alpha.1)

## [2.2.1-beta] - 2024-06-01

### Changed
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.21)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OSX_ARCHITECTURES "x86_64")
set(CMAKE_OSX_ARCHITECTURES "x64")
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

project(BetterInputs VERSION 1.0.0)
Expand All @@ -16,6 +16,8 @@ else()
message(STATUS "Found Geode: $ENV{GEODE_SDK}")
endif()

set(GEODE_LINK_NIGHTLY ON)

add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)

setup_geode_mod(${PROJECT_NAME})
10 changes: 6 additions & 4 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{
"geode": "2.0.0-beta.27",
"geode": "3.0.0-alpha.1",
"gd": {
"win": "2.204"
"win": "2.206",
"mac": "2.206"
},
"version": "v2.2.1-beta",
"version": "v2.3.0-beta",
"id": "spaghettdev.betterinputs",
"name": "BetterInputs",
"developer": "SpaghettDev",
"description": "Makes inputs behave like on Windows (text highlighting, Ctrl+A, Ctrl+Arrow hotkeys, etc...)",
"tags": ["enhancement"],
"repository": "https://github.com/SpaghettDev/BetterInputs",
"links": {
"community": "https://discord.gg/3bShQb6Jz3",
Expand All @@ -28,7 +30,7 @@
"type": "bool",
"default": true,
"name": "Allow any character",
"description": "Allows inputting any character (even ones not allowed) into input nodes. <cr>This is ignored if you have a mod menu that already has this enabled!</c>"
"description": "Allows inputting any character (even ones not allowed) into input nodes."
}
}
}
47 changes: 18 additions & 29 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ struct BetterTextInputNode : Modify<BetterTextInputNode, CCTextInputNode>
this->m_cursor->setVisible(false);
}

void onStringEmpty()
{
if (this->m_placeholderLabel)
this->m_placeholderLabel->setString("");
else
this->m_textArea->setString("");
updateBlinkLabelToCharForced(-1);
showTextOrPlaceholder(false);
}


// Left and Right arrow events
void onRightArrow(bool isCtrl, bool isShift)
Expand Down Expand Up @@ -342,14 +352,7 @@ struct BetterTextInputNode : Modify<BetterTextInputNode, CCTextInputNode>
);

if (m_fields->m_string.empty())
{
if (this->m_placeholderLabel)
this->m_placeholderLabel->setString("");
else
this->m_textArea->setString("");
updateBlinkLabelToCharForced(-1);
showTextOrPlaceholder(false);
}
onStringEmpty();
}


Expand Down Expand Up @@ -596,14 +599,7 @@ struct BetterTextInputNode : Modify<BetterTextInputNode, CCTextInputNode>
);

if (m_fields->m_string.empty())
{
if (this->m_placeholderLabel)
this->m_placeholderLabel->setString("");
else
this->m_textArea->setString("");
updateBlinkLabelToCharForced(-1);
showTextOrPlaceholder(false);
}
onStringEmpty();

return;
}
Expand All @@ -622,14 +618,7 @@ struct BetterTextInputNode : Modify<BetterTextInputNode, CCTextInputNode>
updateBlinkLabelToCharForced(pos - 1 == m_fields->m_string.length() ? -1 : pos - 1);

if (m_fields->m_string.empty())
{
if (this->m_placeholderLabel)
this->m_placeholderLabel->setString("");
else
this->m_textArea->setString("");
updateBlinkLabelToCharForced(-1);
showTextOrPlaceholder(false);
}
onStringEmpty();
}

/**
Expand Down Expand Up @@ -958,15 +947,15 @@ struct BetterCCEGLView : Modify<BetterCCEGLView, CCEGLView>

case GLFW_KEY_RIGHT:
g_selectedInput->onRightArrow(
BI::windows::keyDown(VK_CONTROL),
BI::windows::keyDown(VK_SHIFT)
BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL),
BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT)
);
break;

case GLFW_KEY_LEFT:
g_selectedInput->onLeftArrow(
BI::windows::keyDown(VK_CONTROL),
BI::windows::keyDown(VK_SHIFT)
BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL),
BI::platform::keyDown(BI::PlatformKey::LEFT_SHIFT)
);
break;

Expand All @@ -976,7 +965,7 @@ struct BetterCCEGLView : Modify<BetterCCEGLView, CCEGLView>
}

// this is what onGLFWKeyCallback actually does to check for control lol
if (action == 1 && BI::windows::keyDown(VK_CONTROL))
if (action == 1 && BI::platform::keyDown(BI::PlatformKey::LEFT_CONTROL))
{
switch (key)
{
Expand Down
47 changes: 38 additions & 9 deletions src/utils.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include <string>
#include <string_view>

#include <Geode/platform/windows.hpp>
#include <Geode/cocos/robtop/glfw/glfw3.h>

#ifdef GEODE_IS_WINDOWS
#include <WinUser.h> // virtual keys
#endif

#include <Geode/cocos/cocoa/CCGeometry.h>

Expand Down Expand Up @@ -106,23 +110,48 @@ namespace BI
}
}

namespace windows
enum class PlatformKey
{
LEFT_CONTROL,
LEFT_SHIFT
};
namespace platform
{
inline bool keyDown(unsigned int vk)
inline bool keyDown(PlatformKey key)
{
return GetKeyState(vk) & 0x8000;
#ifdef GEODE_IS_WINDOWS
switch (key)
{
case BI::PlatformKey::LEFT_CONTROL:
return GetKeyState(VK_CONTROL) & 0x8000;
case BI::PlatformKey::LEFT_SHIFT:
return GetKeyState(VK_SHIFT) & 0x8000;
}
#elif defined(GEODE_IS_MACOS)
switch (key)
{
case BI::PlatformKey::LEFT_CONTROL:
return cocos2d::CCKeyboardDispatcher::get()->getControlKeyPressed();
case BI::PlatformKey::LEFT_SHIFT:
return cocos2d::CCKeyboardDispatcher::get()->getShiftKeyPressed();
}
#endif
}
}

namespace gd
{
inline bool isVanillaInput()
{
std::uintptr_t readMemory;

std::memcpy(&readMemory, reinterpret_cast<void*>(geode::base::get() + 0x2F974), 1);

return readMemory == 0x0475;
return true;
// std::uintptr_t readMemory;

// #ifdef GEODE_IS_WINDOWS
// std::memcpy(&readMemory, reinterpret_cast<void*>(geode::base::get() + 0x2F974), 1);
// #elif defined(GEODE_IS_MACOS)
// std::memcpy(&readMemory, reinterpret_cast<void*>(geode::base::get() + 0x2F974), 1);
// #endif
// return readMemory == 0x0475;
}
}

Expand Down

0 comments on commit 9e3a644

Please sign in to comment.