Skip to content

Commit

Permalink
some mod safety measures
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed May 18, 2024
1 parent 8091558 commit c9c29f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

void AsyncUILayer::handleKeypress(cocos2d::enumKeyCodes key, bool down) {
auto event = ExtendedCCKeyboardDispatcher::getCurrentEventInfo();
if (!event) {
return UILayer::handleKeypress(key, down);
}

auto extendedInfo = static_cast<ExtendedCCEvent*>(event);
m_fields->m_lastTimestamp = extendedInfo->getTimestamp();

Expand All @@ -12,6 +16,10 @@ void AsyncUILayer::handleKeypress(cocos2d::enumKeyCodes key, bool down) {
}

bool AsyncUILayer::ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) {
if (!event) {
return UILayer::ccTouchBegan(touch, event);
}

auto extendedInfo = static_cast<ExtendedCCEvent*>(event);
m_fields->m_lastTimestamp = extendedInfo->getTimestamp();

Expand All @@ -22,6 +30,10 @@ bool AsyncUILayer::ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* event
}

void AsyncUILayer::ccTouchMoved(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) {
if (!event) {
return UILayer::ccTouchMoved(touch, event);
}

auto extendedInfo = static_cast<ExtendedCCEvent*>(event);
m_fields->m_lastTimestamp = extendedInfo->getTimestamp();

Expand All @@ -30,6 +42,10 @@ void AsyncUILayer::ccTouchMoved(cocos2d::CCTouch* touch, cocos2d::CCEvent* event
}

void AsyncUILayer::ccTouchEnded(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) {
if (!event) {
return UILayer::ccTouchEnded(touch, event);
}

auto extendedInfo = static_cast<ExtendedCCEvent*>(event);
m_fields->m_lastTimestamp = extendedInfo->getTimestamp();

Expand All @@ -39,6 +55,10 @@ void AsyncUILayer::ccTouchEnded(cocos2d::CCTouch* touch, cocos2d::CCEvent* event

#ifndef GEODE_IS_WINDOWS
void AsyncUILayer::ccTouchCancelled(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) {
if (!event) {
return UILayer::ccTouchCancelled(touch, event);
}

auto extendedInfo = static_cast<ExtendedCCEvent*>(event);
m_fields->m_lastTimestamp = extendedInfo->getTimestamp();

Expand Down
2 changes: 1 addition & 1 deletion src/windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class ManualKeyboardEvent : public GameEvent {
struct AsyncCCKeyboardDispatcher : geode::Modify<AsyncCCKeyboardDispatcher, cocos2d::CCKeyboardDispatcher> {
static void onModify(auto& self) {
// this is the most likely to be called before by another mod and it would be really bad if that other mod got to it first
(void)self.setHookPriority("cocos2d::CCKeyboardDispatcher::dispatchKeyboardMSG", -10000);
(void)self.setHookPriority("cocos2d::CCKeyboardDispatcher::dispatchKeyboardMSG", -100000);
}

bool dispatchKeyboardMSG(cocos2d::enumKeyCodes key, bool isDown, bool isRepeat) {
Expand Down

0 comments on commit c9c29f9

Please sign in to comment.