mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-23 07:57:51 -05:00
fix events and cleanup
This commit is contained in:
parent
37a9c9ee97
commit
20a2dc9f07
13 changed files with 186 additions and 170 deletions
|
@ -71,8 +71,7 @@ namespace cocos2d::extension {}
|
||||||
|
|
||||||
#define GEODE_FILL_CONSTRUCTOR(Class_, Offset_) \
|
#define GEODE_FILL_CONSTRUCTOR(Class_, Offset_) \
|
||||||
Class_(std::monostate, size_t fill) : \
|
Class_(std::monostate, size_t fill) : \
|
||||||
Class_({}, std::memset(reinterpret_cast<std::byte*>(this) + Offset_, 0, fill - Offset_)) { \
|
Class_({}, std::memset(reinterpret_cast<std::byte*>(this) + Offset_, 0, fill - Offset_)) {} \
|
||||||
} \
|
|
||||||
Class_(std::monostate, void*)
|
Class_(std::monostate, void*)
|
||||||
|
|
||||||
#define GEODE_MONOSTATE_CONSTRUCTOR_BEGIN(Class_) \
|
#define GEODE_MONOSTATE_CONSTRUCTOR_BEGIN(Class_) \
|
||||||
|
@ -177,7 +176,7 @@ namespace cocos2d::extension {}
|
||||||
} \
|
} \
|
||||||
static inline auto GEODE_CONCAT(Exec, __LINE__) = \
|
static inline auto GEODE_CONCAT(Exec, __LINE__) = \
|
||||||
(Loader::get()->scheduleOnModLoad( \
|
(Loader::get()->scheduleOnModLoad( \
|
||||||
nullptr, \
|
getMod(), \
|
||||||
&GEODE_CONCAT(geodeExecFunction, __LINE__) < GEODE_CONCAT(ExecFuncUnique, __LINE__) > \
|
&GEODE_CONCAT(geodeExecFunction, __LINE__) < GEODE_CONCAT(ExecFuncUnique, __LINE__) > \
|
||||||
), \
|
), \
|
||||||
0); \
|
0); \
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../utils/casts.hpp"
|
||||||
#include "Mod.hpp"
|
#include "Mod.hpp"
|
||||||
|
|
||||||
#include <Geode/DefaultInclude.hpp>
|
#include <Geode/DefaultInclude.hpp>
|
||||||
|
@ -45,8 +46,7 @@ namespace geode {
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
concept is_filter =
|
concept is_filter = std::is_base_of_v<EventFilter<typename T::Event>, T> &&
|
||||||
std::is_base_of_v<EventFilter<typename T::Event>, T> &&
|
|
||||||
requires(T a) {
|
requires(T a) {
|
||||||
a.handle(std::declval<typename T::Callback>(), std::declval<typename T::Event*>());
|
a.handle(std::declval<typename T::Callback>(), std::declval<typename T::Event*>());
|
||||||
};
|
};
|
||||||
|
@ -55,11 +55,13 @@ namespace geode {
|
||||||
class EventListener : public EventListenerProtocol {
|
class EventListener : public EventListenerProtocol {
|
||||||
public:
|
public:
|
||||||
using Callback = typename T::Callback;
|
using Callback = typename T::Callback;
|
||||||
template <typename C> requires std::is_class_v<C>
|
template <typename C>
|
||||||
|
requires std::is_class_v<C>
|
||||||
using MemberFn = typename to_member<C, Callback>::value;
|
using MemberFn = typename to_member<C, Callback>::value;
|
||||||
|
|
||||||
ListenerResult passThrough(Event* e) override {
|
ListenerResult passThrough(Event* e) override {
|
||||||
if (auto myev = dynamic_cast<typename T::Event*>(e)) {
|
// it is so silly to use dynamic cast in an interbinary context
|
||||||
|
if (auto myev = cast::typeinfo_cast<typename T::Event*>(e)) {
|
||||||
return m_filter.handle(m_callback, myev);
|
return m_filter.handle(m_callback, myev);
|
||||||
}
|
}
|
||||||
return ListenerResult::Propagate;
|
return ListenerResult::Propagate;
|
||||||
|
@ -68,25 +70,31 @@ namespace geode {
|
||||||
EventListener(T filter = T()) {
|
EventListener(T filter = T()) {
|
||||||
this->enable();
|
this->enable();
|
||||||
}
|
}
|
||||||
EventListener(std::function<Callback> fn, T filter = T()) : m_callback(fn), m_filter(filter) {
|
|
||||||
|
EventListener(std::function<Callback> fn, T filter = T()) :
|
||||||
|
m_callback(fn), m_filter(filter) {
|
||||||
this->enable();
|
this->enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
EventListener(Callback* fnptr, T filter = T()) : m_callback(fnptr), m_filter(filter) {
|
EventListener(Callback* fnptr, T filter = T()) : m_callback(fnptr), m_filter(filter) {
|
||||||
this->enable();
|
this->enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class C>
|
template <class C>
|
||||||
EventListener(C* cls, MemberFn<C> fn, T filter = T()) : EventListener(std::bind(fn, cls, std::placeholders::_1), filter) {
|
EventListener(C* cls, MemberFn<C> fn, T filter = T()) :
|
||||||
|
EventListener(std::bind(fn, cls, std::placeholders::_1), filter) {
|
||||||
this->enable();
|
this->enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bind(std::function<Callback> fn) {
|
void bind(std::function<Callback> fn) {
|
||||||
m_callback = fn;
|
m_callback = fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename C>
|
template <typename C>
|
||||||
void bind(C* cls, MemberFn<C> fn) {
|
void bind(C* cls, MemberFn<C> fn) {
|
||||||
m_callback = std::bind(fn, cls, std::placeholders::_1);
|
m_callback = std::bind(fn, cls, std::placeholders::_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::function<Callback> m_callback;
|
std::function<Callback> m_callback;
|
||||||
T m_filter;
|
T m_filter;
|
||||||
|
@ -96,6 +104,7 @@ namespace geode {
|
||||||
static std::unordered_set<EventListenerProtocol*> s_listeners;
|
static std::unordered_set<EventListenerProtocol*> s_listeners;
|
||||||
Mod* m_sender;
|
Mod* m_sender;
|
||||||
friend EventListenerProtocol;
|
friend EventListenerProtocol;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void postFrom(Mod* sender);
|
void postFrom(Mod* sender);
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Event.hpp"
|
#include "Event.hpp"
|
||||||
#include <optional>
|
|
||||||
#include "Mod.hpp"
|
#include "Mod.hpp"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
namespace geode {
|
namespace geode {
|
||||||
enum class ModEventType {
|
enum class ModEventType {
|
||||||
Loaded,
|
Loaded,
|
||||||
|
@ -45,13 +46,17 @@ void GEODE_CONCAT(geodeExecFunction, __LINE__)(ModStateEvent*); \
|
||||||
namespace { \
|
namespace { \
|
||||||
struct GEODE_CONCAT(ExecFuncUnique, __LINE__) {}; \
|
struct GEODE_CONCAT(ExecFuncUnique, __LINE__) {}; \
|
||||||
} \
|
} \
|
||||||
static inline auto GEODE_CONCAT(Exec, __LINE__) = (geode::Loader::get()->scheduleOnModLoad(\
|
static inline auto GEODE_CONCAT(Exec, __LINE__) = \
|
||||||
geode::Mod::get(), []() { \
|
(geode::Loader::get()->scheduleOnModLoad( \
|
||||||
|
geode::Mod::get(), \
|
||||||
|
[]() { \
|
||||||
static auto _ = geode::EventListener( \
|
static auto _ = geode::EventListener( \
|
||||||
&GEODE_CONCAT(geodeExecFunction, __LINE__)<GEODE_CONCAT(ExecFuncUnique, __LINE__)>,\
|
&GEODE_CONCAT(geodeExecFunction, __LINE__) < \
|
||||||
|
GEODE_CONCAT(ExecFuncUnique, __LINE__) >, \
|
||||||
geode::ModStateFilter(geode::Mod::get(), geode::ModEventType::type) \
|
geode::ModStateFilter(geode::Mod::get(), geode::ModEventType::type) \
|
||||||
); \
|
); \
|
||||||
} \
|
} \
|
||||||
), 0); \
|
), \
|
||||||
|
0); \
|
||||||
template <class> \
|
template <class> \
|
||||||
void GEODE_CONCAT(geodeExecFunction, __LINE__)(ModStateEvent*)
|
void GEODE_CONCAT(geodeExecFunction, __LINE__)(ModStateEvent*)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../loader/Log.hpp"
|
|
||||||
#include "../external/json/json.hpp"
|
#include "../external/json/json.hpp"
|
||||||
|
#include "../loader/Log.hpp"
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
@ -15,9 +15,7 @@ namespace geode {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct is_iterable<
|
struct is_iterable<
|
||||||
T,
|
T, std::void_t<decltype(std::begin(std::declval<T>())), decltype(std::end(std::declval<T>()))>> :
|
||||||
std::void_t<
|
|
||||||
decltype(std::begin(std::declval<T>())), decltype(std::end(std::declval<T>()))>> :
|
|
||||||
std::true_type {};
|
std::true_type {};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -79,7 +77,7 @@ namespace geode {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
using JsonValueValidator = bool (*)(T const&);
|
using JsonValueValidator = std::function<bool(T const&)>;
|
||||||
|
|
||||||
template <class Json>
|
template <class Json>
|
||||||
struct JsonMaybeObject;
|
struct JsonMaybeObject;
|
||||||
|
@ -175,6 +173,11 @@ namespace geode {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
JsonMaybeValue<Json>& validate(bool (*validator)(T const&)) {
|
||||||
|
return this->validate(std::function(validator));
|
||||||
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
JsonMaybeValue<Json>& inferType() {
|
JsonMaybeValue<Json>& inferType() {
|
||||||
if (this->isError() || !m_inferType) return *this;
|
if (this->isError() || !m_inferType) return *this;
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "casts.hpp"
|
|
||||||
#include "../external/json/json.hpp"
|
#include "../external/json/json.hpp"
|
||||||
|
#include "casts.hpp"
|
||||||
#include "general.hpp"
|
#include "general.hpp"
|
||||||
|
|
||||||
#include <Geode/DefaultInclude.hpp>
|
#include <Geode/DefaultInclude.hpp>
|
||||||
#include <cocos2d.h>
|
#include <cocos2d.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -283,6 +284,7 @@ namespace geode {
|
||||||
bool operator==(T* other) const {
|
bool operator==(T* other) const {
|
||||||
return m_obj == other;
|
return m_obj == other;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(Ref<T> const& other) const {
|
bool operator==(Ref<T> const& other) const {
|
||||||
return m_obj == other.m_obj;
|
return m_obj == other.m_obj;
|
||||||
}
|
}
|
||||||
|
@ -290,6 +292,7 @@ namespace geode {
|
||||||
bool operator!=(T* other) const {
|
bool operator!=(T* other) const {
|
||||||
return m_obj != other;
|
return m_obj != other;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(Ref<T> const& other) const {
|
bool operator!=(Ref<T> const& other) const {
|
||||||
return m_obj != other.m_obj;
|
return m_obj != other.m_obj;
|
||||||
}
|
}
|
||||||
|
@ -298,6 +301,7 @@ namespace geode {
|
||||||
bool operator<(Ref<T> const& other) const {
|
bool operator<(Ref<T> const& other) const {
|
||||||
return m_obj < other.m_obj;
|
return m_obj < other.m_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator>(Ref<T> const& other) const {
|
bool operator>(Ref<T> const& other) const {
|
||||||
return m_obj > other.m_obj;
|
return m_obj > other.m_obj;
|
||||||
}
|
}
|
||||||
|
@ -435,7 +439,7 @@ namespace geode::cocos {
|
||||||
*/
|
*/
|
||||||
GEODE_DLL cocos2d::CCScene* switchToScene(cocos2d::CCLayer* layer);
|
GEODE_DLL cocos2d::CCScene* switchToScene(cocos2d::CCLayer* layer);
|
||||||
|
|
||||||
using CreateLayerFunc = cocos2d::CCLayer*(*)();
|
using CreateLayerFunc = std::function<cocos2d::CCLayer*()>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reload textures, overwriting the scene to return to after the loading
|
* Reload textures, overwriting the scene to return to after the loading
|
||||||
|
@ -453,9 +457,7 @@ namespace geode::cocos {
|
||||||
* @param def Default size
|
* @param def Default size
|
||||||
* @param min Minimum size
|
* @param min Minimum size
|
||||||
*/
|
*/
|
||||||
GEODE_DLL void limitNodeSize(
|
GEODE_DLL void limitNodeSize(cocos2d::CCNode* node, cocos2d::CCSize const& size, float def, float min);
|
||||||
cocos2d::CCNode* node, cocos2d::CCSize const& size, float def, float min
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a node is visible (recursively
|
* Checks if a node is visible (recursively
|
||||||
|
@ -497,8 +499,7 @@ namespace geode::cocos {
|
||||||
for (int i = 0; i < children->count(); ++i) {
|
for (int i = 0; i < children->count(); ++i) {
|
||||||
auto newParent = static_cast<cocos2d::CCNode*>(children->objectAtIndex(i));
|
auto newParent = static_cast<cocos2d::CCNode*>(children->objectAtIndex(i));
|
||||||
auto child = findFirstChildRecursive(newParent, predicate);
|
auto child = findFirstChildRecursive(newParent, predicate);
|
||||||
if (child)
|
if (child) return child;
|
||||||
return child;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -602,12 +603,17 @@ namespace geode::cocos {
|
||||||
}
|
}
|
||||||
|
|
||||||
inline cocos2d::ccColor4B invert4B(cocos2d::ccColor4B const& color) {
|
inline cocos2d::ccColor4B invert4B(cocos2d::ccColor4B const& color) {
|
||||||
return { static_cast<GLubyte>(255 - color.r), static_cast<GLubyte>(255 - color.g),
|
return {
|
||||||
static_cast<GLubyte>(255 - color.b), color.a };
|
static_cast<GLubyte>(255 - color.r),
|
||||||
|
static_cast<GLubyte>(255 - color.g),
|
||||||
|
static_cast<GLubyte>(255 - color.b),
|
||||||
|
color.a};
|
||||||
}
|
}
|
||||||
|
|
||||||
inline cocos2d::ccColor3B invert3B(cocos2d::ccColor3B const& color) {
|
inline cocos2d::ccColor3B invert3B(cocos2d::ccColor3B const& color) {
|
||||||
return { static_cast<GLubyte>(255 - color.r), static_cast<GLubyte>(255 - color.g),
|
return {
|
||||||
|
static_cast<GLubyte>(255 - color.r),
|
||||||
|
static_cast<GLubyte>(255 - color.g),
|
||||||
static_cast<GLubyte>(255 - color.b)};
|
static_cast<GLubyte>(255 - color.b)};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,19 +643,23 @@ namespace geode::cocos {
|
||||||
|
|
||||||
constexpr cocos2d::ccColor3B cc3x(int hexValue) {
|
constexpr cocos2d::ccColor3B cc3x(int hexValue) {
|
||||||
if (hexValue <= 0xf)
|
if (hexValue <= 0xf)
|
||||||
return cocos2d::ccColor3B { static_cast<GLubyte>(hexValue * 17),
|
return cocos2d::ccColor3B{
|
||||||
|
static_cast<GLubyte>(hexValue * 17),
|
||||||
static_cast<GLubyte>(hexValue * 17),
|
static_cast<GLubyte>(hexValue * 17),
|
||||||
static_cast<GLubyte>(hexValue * 17)};
|
static_cast<GLubyte>(hexValue * 17)};
|
||||||
if (hexValue <= 0xff)
|
if (hexValue <= 0xff)
|
||||||
return cocos2d::ccColor3B { static_cast<GLubyte>(hexValue),
|
return cocos2d::ccColor3B{
|
||||||
|
static_cast<GLubyte>(hexValue),
|
||||||
static_cast<GLubyte>(hexValue),
|
static_cast<GLubyte>(hexValue),
|
||||||
static_cast<GLubyte>(hexValue)};
|
static_cast<GLubyte>(hexValue)};
|
||||||
if (hexValue <= 0xfff)
|
if (hexValue <= 0xfff)
|
||||||
return cocos2d::ccColor3B { static_cast<GLubyte>((hexValue >> 8 & 0xf) * 17),
|
return cocos2d::ccColor3B{
|
||||||
|
static_cast<GLubyte>((hexValue >> 8 & 0xf) * 17),
|
||||||
static_cast<GLubyte>((hexValue >> 4 & 0xf) * 17),
|
static_cast<GLubyte>((hexValue >> 4 & 0xf) * 17),
|
||||||
static_cast<GLubyte>((hexValue >> 0 & 0xf) * 17)};
|
static_cast<GLubyte>((hexValue >> 0 & 0xf) * 17)};
|
||||||
else
|
else
|
||||||
return cocos2d::ccColor3B { static_cast<GLubyte>(hexValue >> 16 & 0xff),
|
return cocos2d::ccColor3B{
|
||||||
|
static_cast<GLubyte>(hexValue >> 16 & 0xff),
|
||||||
static_cast<GLubyte>(hexValue >> 8 & 0xff),
|
static_cast<GLubyte>(hexValue >> 8 & 0xff),
|
||||||
static_cast<GLubyte>(hexValue >> 0 & 0xff)};
|
static_cast<GLubyte>(hexValue >> 0 & 0xff)};
|
||||||
}
|
}
|
||||||
|
@ -668,9 +678,7 @@ namespace geode::cocos {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, typename C, typename = std::enable_if_t<std::is_pointer_v<C>>>
|
template <typename T, typename C, typename = std::enable_if_t<std::is_pointer_v<C>>>
|
||||||
static cocos2d::CCArray* vectorToCCArray(
|
static cocos2d::CCArray* vectorToCCArray(std::vector<T> const& vec, std::function<C(T)> convFunc) {
|
||||||
std::vector<T> const& vec, std::function<C(T)> convFunc
|
|
||||||
) {
|
|
||||||
auto res = cocos2d::CCArray::createWithCapacity(vec.size());
|
auto res = cocos2d::CCArray::createWithCapacity(vec.size());
|
||||||
for (auto const& item : vec)
|
for (auto const& item : vec)
|
||||||
res->addObject(convFunc(item));
|
res->addObject(convFunc(item));
|
||||||
|
@ -680,8 +688,7 @@ namespace geode::cocos {
|
||||||
template <typename T, typename = std::enable_if_t<std::is_pointer_v<T>>>
|
template <typename T, typename = std::enable_if_t<std::is_pointer_v<T>>>
|
||||||
std::vector<T> ccArrayToVector(cocos2d::CCArray* arr) {
|
std::vector<T> ccArrayToVector(cocos2d::CCArray* arr) {
|
||||||
return std::vector<T>(
|
return std::vector<T>(
|
||||||
reinterpret_cast<T*>(arr->data->arr),
|
reinterpret_cast<T*>(arr->data->arr), reinterpret_cast<T*>(arr->data->arr) + arr->data->num
|
||||||
reinterpret_cast<T*>(arr->data->arr) + arr->data->num
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,9 +705,7 @@ namespace geode::cocos {
|
||||||
template <
|
template <
|
||||||
typename K, typename V, typename C,
|
typename K, typename V, typename C,
|
||||||
typename = std::enable_if_t<std::is_same_v<C, std::string> || std::is_same_v<C, intptr_t>>>
|
typename = std::enable_if_t<std::is_same_v<C, std::string> || std::is_same_v<C, intptr_t>>>
|
||||||
static cocos2d::CCDictionary* mapToCCDict(
|
static cocos2d::CCDictionary* mapToCCDict(std::map<K, V> const& map, std::function<C(K)> convFunc) {
|
||||||
std::map<K, V> const& map, std::function<C(K)> convFunc
|
|
||||||
) {
|
|
||||||
auto res = cocos2d::CCDictionary::create();
|
auto res = cocos2d::CCDictionary::create();
|
||||||
for (auto const& [key, value] : map)
|
for (auto const& [key, value] : map)
|
||||||
res->setObject(value, convFunc(key));
|
res->setObject(value, convFunc(key));
|
||||||
|
@ -797,6 +802,7 @@ namespace geode::cocos {
|
||||||
}
|
}
|
||||||
return CCArrayIterator<T*>(reinterpret_cast<T**>(m_arr->data->arr) + m_arr->count());
|
return CCArrayIterator<T*>(reinterpret_cast<T**>(m_arr->data->arr) + m_arr->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size() const {
|
size_t size() const {
|
||||||
return m_arr ? m_arr->count() : 0;
|
return m_arr ? m_arr->count() : 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../DefaultInclude.hpp"
|
#include "../DefaultInclude.hpp"
|
||||||
#include "Result.hpp"
|
|
||||||
#include "../external/json/json.hpp"
|
#include "../external/json/json.hpp"
|
||||||
|
#include "Result.hpp"
|
||||||
#include "general.hpp"
|
#include "general.hpp"
|
||||||
|
|
||||||
#include <fs/filesystem.hpp>
|
#include <fs/filesystem.hpp>
|
||||||
|
@ -38,8 +38,7 @@ namespace geode::utils::web {
|
||||||
* @returns Returned data as JSON, or error on error
|
* @returns Returned data as JSON, or error on error
|
||||||
*/
|
*/
|
||||||
GEODE_DLL Result<> fetchFile(
|
GEODE_DLL Result<> fetchFile(
|
||||||
std::string const& url, ghc::filesystem::path const& into,
|
std::string const& url, ghc::filesystem::path const& into, FileProgressCallback prog = nullptr
|
||||||
FileProgressCallback prog = nullptr
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -122,7 +122,8 @@ Result<> Mod::loadData() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log::log(
|
log::log(
|
||||||
Severity::Warning, this,
|
Severity::Warning,
|
||||||
|
this,
|
||||||
"Encountered unknown setting \"{}\" while loading "
|
"Encountered unknown setting \"{}\" while loading "
|
||||||
"settings",
|
"settings",
|
||||||
key
|
key
|
||||||
|
|
|
@ -19,7 +19,4 @@ ListenerResult ModStateFilter::handle(std::function<Callback> fn, ModStateEvent*
|
||||||
return ListenerResult::Propagate;
|
return ListenerResult::Propagate;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModStateFilter::ModStateFilter(
|
ModStateFilter::ModStateFilter(Mod* mod, ModEventType type) : m_mod(mod), m_type(type) {}
|
||||||
Mod* mod,
|
|
||||||
ModEventType type
|
|
||||||
) : m_mod(mod), m_type(type) {}
|
|
||||||
|
|
|
@ -100,7 +100,9 @@ BOOL WINAPI DllMain(HINSTANCE lib, DWORD reason, LPVOID) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
$execute {
|
#define $_ GEODE_CONCAT(unnamedVar_, __LINE__)
|
||||||
|
|
||||||
|
static auto $_ =
|
||||||
listenForSettingChanges<BoolSetting>("show-platform-console", [](BoolSetting* setting) {
|
listenForSettingChanges<BoolSetting>("show-platform-console", [](BoolSetting* setting) {
|
||||||
if (setting->getValue()) {
|
if (setting->getValue()) {
|
||||||
Loader::get()->openPlatformConsole();
|
Loader::get()->openPlatformConsole();
|
||||||
|
@ -109,14 +111,16 @@ $execute {
|
||||||
Loader::get()->closePlatfromConsole();
|
Loader::get()->closePlatfromConsole();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
listenForIPC("ipc-test", [](IPCEvent* event) -> nlohmann::json {
|
|
||||||
|
static auto $_ = listenForIPC("ipc-test", [](IPCEvent* event) -> nlohmann::json {
|
||||||
return "Hello from Geode!";
|
return "Hello from Geode!";
|
||||||
});
|
});
|
||||||
listenForIPC("loader-info", [](IPCEvent* event) -> nlohmann::json {
|
|
||||||
|
static auto $_ = listenForIPC("loader-info", [](IPCEvent* event) -> nlohmann::json {
|
||||||
return Loader::get()->getInternalMod()->getModInfo();
|
return Loader::get()->getInternalMod()->getModInfo();
|
||||||
});
|
});
|
||||||
|
|
||||||
listenForIPC("list-mods", [](IPCEvent* event) -> nlohmann::json {
|
static auto $_ = listenForIPC("list-mods", [](IPCEvent* event) -> nlohmann::json {
|
||||||
std::vector<nlohmann::json> res;
|
std::vector<nlohmann::json> res;
|
||||||
|
|
||||||
auto args = event->getMessageData();
|
auto args = event->getMessageData();
|
||||||
|
@ -127,8 +131,10 @@ $execute {
|
||||||
auto dontIncludeLoader = root.has("dont-include-loader").template get<bool>();
|
auto dontIncludeLoader = root.has("dont-include-loader").template get<bool>();
|
||||||
|
|
||||||
if (!dontIncludeLoader) {
|
if (!dontIncludeLoader) {
|
||||||
auto mod = Loader::get()->getInternalMod();
|
res.push_back(
|
||||||
res.push_back(includeRunTimeInfo ? mod->getRuntimeInfo() : mod->getModInfo().toJSON());
|
includeRunTimeInfo ? Loader::get()->getInternalMod()->getRuntimeInfo() :
|
||||||
|
Loader::get()->getInternalMod()->getModInfo().toJSON()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& mod : Loader::get()->getAllMods()) {
|
for (auto& mod : Loader::get()->getAllMods()) {
|
||||||
|
@ -137,7 +143,6 @@ $execute {
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
int geodeEntry(void* platformData) {
|
int geodeEntry(void* platformData) {
|
||||||
// setup internals
|
// setup internals
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include <InternalLoader.hpp>
|
|
||||||
#include <Geode/loader/Log.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
#include <InternalMod.hpp>
|
|
||||||
#include <Geode/loader/IPC.hpp>
|
#include <Geode/loader/IPC.hpp>
|
||||||
|
#include <Geode/loader/Log.hpp>
|
||||||
|
#include <InternalLoader.hpp>
|
||||||
|
#include <InternalMod.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#ifdef GEODE_IS_MACOS
|
#ifdef GEODE_IS_MACOS
|
||||||
|
|
||||||
|
@ -29,46 +29,37 @@ void InternalLoader::closePlatformConsole() {
|
||||||
m_platformConsoleOpen = false;
|
m_platformConsoleOpen = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFDataRef msgPortCallback(
|
CFDataRef msgPortCallback(CFMessagePortRef port, SInt32 messageID, CFDataRef data, void* info) {
|
||||||
CFMessagePortRef port,
|
if (!CFDataGetLength(data)) return NULL;
|
||||||
SInt32 messageID,
|
|
||||||
CFDataRef data,
|
|
||||||
void* info
|
|
||||||
) {
|
|
||||||
if(!CFDataGetLength(data))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
std::string cdata(
|
std::string cdata(reinterpret_cast<char const*>(CFDataGetBytePtr(data)), CFDataGetLength(data));
|
||||||
reinterpret_cast<char const*>(CFDataGetBytePtr(data)),
|
|
||||||
CFDataGetLength(data)
|
|
||||||
);
|
|
||||||
|
|
||||||
std::string reply = InternalLoader::processRawIPC(port, cdata);
|
std::string reply = InternalLoader::processRawIPC(port, cdata);
|
||||||
return CFDataCreate(NULL, (const UInt8*)reply.data(), reply.size());
|
return CFDataCreate(NULL, (UInt8 const*)reply.data(), reply.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void InternalLoader::setupIPC() {
|
void InternalLoader::setupIPC() {
|
||||||
std::thread([]() {
|
std::thread([]() {
|
||||||
CFStringRef portName = CFStringCreateWithCString(NULL, IPC_PORT_NAME, kCFStringEncodingUTF8);
|
CFStringRef portName = CFStringCreateWithCString(NULL, IPC_PORT_NAME, kCFStringEncodingUTF8);
|
||||||
|
|
||||||
CFMessagePortRef localPort = CFMessagePortCreateLocal(
|
CFMessagePortRef localPort =
|
||||||
NULL,
|
CFMessagePortCreateLocal(NULL, portName, msgPortCallback, NULL, NULL);
|
||||||
portName,
|
if (localPort == NULL) {
|
||||||
msgPortCallback,
|
log::warn("Unable to create port, quitting IPC");
|
||||||
NULL,
|
return;
|
||||||
NULL
|
}
|
||||||
);
|
|
||||||
CFRunLoopSourceRef runLoopSource = CFMessagePortCreateRunLoopSource(NULL, localPort, 0);
|
CFRunLoopSourceRef runLoopSource = CFMessagePortCreateRunLoopSource(NULL, localPort, 0);
|
||||||
|
|
||||||
CFRunLoopAddSource(
|
if (runLoopSource == NULL) {
|
||||||
CFRunLoopGetCurrent(),
|
log::warn("Unable to create loop source, quitting IPC");
|
||||||
runLoopSource,
|
return;
|
||||||
kCFRunLoopCommonModes
|
}
|
||||||
);
|
|
||||||
|
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);
|
||||||
CFRunLoopRun();
|
CFRunLoopRun();
|
||||||
CFRelease(localPort);
|
CFRelease(localPort);
|
||||||
}).detach();
|
}).detach();
|
||||||
log::log(Severity::Warning, InternalMod::get(), "IPC is not supported on this platform");
|
log::debug("IPC set up");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include <InternalLoader.hpp>
|
|
||||||
#include <Geode/loader/IPC.hpp>
|
#include <Geode/loader/IPC.hpp>
|
||||||
#include <Geode/loader/Log.hpp>
|
#include <Geode/loader/Log.hpp>
|
||||||
#include <iostream>
|
#include <InternalLoader.hpp>
|
||||||
#include <InternalMod.hpp>
|
#include <InternalMod.hpp>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
USE_GEODE_NAMESPACE();
|
USE_GEODE_NAMESPACE();
|
||||||
|
|
||||||
|
@ -89,14 +89,15 @@ void InternalLoader::setupIPC() {
|
||||||
if (ConnectNamedPipe(pipe, nullptr)) {
|
if (ConnectNamedPipe(pipe, nullptr)) {
|
||||||
// log::debug("Got connection, creating thread");
|
// log::debug("Got connection, creating thread");
|
||||||
std::thread(&ipcPipeThread, pipe).detach();
|
std::thread(&ipcPipeThread, pipe).detach();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// log::debug("No connection, cleaning pipe");
|
// log::debug("No connection, cleaning pipe");
|
||||||
CloseHandle(pipe);
|
CloseHandle(pipe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).detach();
|
}).detach();
|
||||||
|
|
||||||
log::log(Severity::Debug, InternalMod::get(), "IPC set up");
|
log::debug("IPC set up");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -368,32 +368,32 @@ AsyncWebRequest::~AsyncWebRequest() {
|
||||||
|
|
||||||
AsyncWebResult<std::monostate> AsyncWebResponse::into(std::ostream& stream) {
|
AsyncWebResult<std::monostate> AsyncWebResponse::into(std::ostream& stream) {
|
||||||
m_request.m_target = &stream;
|
m_request.m_target = &stream;
|
||||||
return this->as([](byte_array const&) -> Result<std::monostate> {
|
return this->as(+[](byte_array const&) -> Result<std::monostate> {
|
||||||
return Ok(std::monostate());
|
return Ok(std::monostate());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncWebResult<std::monostate> AsyncWebResponse::into(ghc::filesystem::path const& path) {
|
AsyncWebResult<std::monostate> AsyncWebResponse::into(ghc::filesystem::path const& path) {
|
||||||
m_request.m_target = path;
|
m_request.m_target = path;
|
||||||
return this->as([](byte_array const&) -> Result<std::monostate> {
|
return this->as(+[](byte_array const&) -> Result<std::monostate> {
|
||||||
return Ok(std::monostate());
|
return Ok(std::monostate());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncWebResult<std::string> AsyncWebResponse::text() {
|
AsyncWebResult<std::string> AsyncWebResponse::text() {
|
||||||
return this->as([](byte_array const& bytes) -> Result<std::string> {
|
return this->as(+[](byte_array const& bytes) -> Result<std::string> {
|
||||||
return Ok(std::string(bytes.begin(), bytes.end()));
|
return Ok(std::string(bytes.begin(), bytes.end()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncWebResult<byte_array> AsyncWebResponse::bytes() {
|
AsyncWebResult<byte_array> AsyncWebResponse::bytes() {
|
||||||
return this->as([](byte_array const& bytes) -> Result<byte_array> {
|
return this->as(+[](byte_array const& bytes) -> Result<byte_array> {
|
||||||
return Ok(bytes);
|
return Ok(bytes);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncWebResult<nlohmann::json> AsyncWebResponse::json() {
|
AsyncWebResult<nlohmann::json> AsyncWebResponse::json() {
|
||||||
return this->as([](byte_array const& bytes) -> Result<nlohmann::json> {
|
return this->as(+[](byte_array const& bytes) -> Result<nlohmann::json> {
|
||||||
try {
|
try {
|
||||||
return Ok(nlohmann::json::parse(bytes.begin(), bytes.end()));
|
return Ok(nlohmann::json::parse(bytes.begin(), bytes.end()));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue