From 20a2dc9f0793a6f5db2d8821c865ce1730927419 Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Sun, 4 Dec 2022 19:39:40 +0300 Subject: [PATCH] fix events and cleanup --- loader/include/Geode/DefaultInclude.hpp | 9 +- loader/include/Geode/loader/Event.hpp | 27 +++-- loader/include/Geode/loader/ModEvent.hpp | 59 ++++++----- loader/include/Geode/utils/JsonValidation.hpp | 13 ++- loader/include/Geode/utils/cocos.hpp | 98 ++++++++++--------- loader/include/Geode/utils/web.hpp | 7 +- loader/src/loader/Event.cpp | 2 +- loader/src/loader/Mod.cpp | 3 +- loader/src/loader/ModEvent.cpp | 5 +- loader/src/main.cpp | 53 +++++----- loader/src/platform/mac/InternalLoader.cpp | 53 +++++----- .../src/platform/windows/InternalLoader.cpp | 17 ++-- loader/src/utils/web.cpp | 10 +- 13 files changed, 186 insertions(+), 170 deletions(-) diff --git a/loader/include/Geode/DefaultInclude.hpp b/loader/include/Geode/DefaultInclude.hpp index f2a6f5c1..23a7a8e8 100644 --- a/loader/include/Geode/DefaultInclude.hpp +++ b/loader/include/Geode/DefaultInclude.hpp @@ -69,10 +69,9 @@ namespace cocos2d::extension {} #define GEODE_EXPAND(x) x #define GEODE_INVOKE(macro, ...) GEODE_EXPAND(macro(__VA_ARGS__)) -#define GEODE_FILL_CONSTRUCTOR(Class_, Offset_) \ - Class_(std::monostate, size_t fill) : \ - Class_({}, std::memset(reinterpret_cast(this) + Offset_, 0, fill - Offset_)) { \ - } \ +#define GEODE_FILL_CONSTRUCTOR(Class_, Offset_) \ + Class_(std::monostate, size_t fill) : \ + Class_({}, std::memset(reinterpret_cast(this) + Offset_, 0, fill - Offset_)) {} \ Class_(std::monostate, void*) #define GEODE_MONOSTATE_CONSTRUCTOR_BEGIN(Class_) \ @@ -177,7 +176,7 @@ namespace cocos2d::extension {} } \ static inline auto GEODE_CONCAT(Exec, __LINE__) = \ (Loader::get()->scheduleOnModLoad( \ - nullptr, \ + getMod(), \ &GEODE_CONCAT(geodeExecFunction, __LINE__) < GEODE_CONCAT(ExecFuncUnique, __LINE__) > \ ), \ 0); \ diff --git a/loader/include/Geode/loader/Event.hpp b/loader/include/Geode/loader/Event.hpp index 1ccc3348..b7892388 100644 --- a/loader/include/Geode/loader/Event.hpp +++ b/loader/include/Geode/loader/Event.hpp @@ -1,5 +1,6 @@ #pragma once +#include "../utils/casts.hpp" #include "Mod.hpp" #include @@ -25,9 +26,9 @@ namespace geode { template struct to_member; - template + template struct to_member { - using value = R(C::*)(Args...); + using value = R (C::*)(Args...); }; template @@ -43,10 +44,9 @@ namespace geode { return fn(e); } }; - + template - concept is_filter = - std::is_base_of_v, T> && + concept is_filter = std::is_base_of_v, T> && requires(T a) { a.handle(std::declval(), std::declval()); }; @@ -55,11 +55,13 @@ namespace geode { class EventListener : public EventListenerProtocol { public: using Callback = typename T::Callback; - template requires std::is_class_v + template + requires std::is_class_v using MemberFn = typename to_member::value; ListenerResult passThrough(Event* e) override { - if (auto myev = dynamic_cast(e)) { + // it is so silly to use dynamic cast in an interbinary context + if (auto myev = cast::typeinfo_cast(e)) { return m_filter.handle(m_callback, myev); } return ListenerResult::Propagate; @@ -68,25 +70,31 @@ namespace geode { EventListener(T filter = T()) { this->enable(); } - EventListener(std::function fn, T filter = T()) : m_callback(fn), m_filter(filter) { + + EventListener(std::function fn, T filter = T()) : + m_callback(fn), m_filter(filter) { this->enable(); } + EventListener(Callback* fnptr, T filter = T()) : m_callback(fnptr), m_filter(filter) { this->enable(); } template - EventListener(C* cls, MemberFn fn, T filter = T()) : EventListener(std::bind(fn, cls, std::placeholders::_1), filter) { + EventListener(C* cls, MemberFn fn, T filter = T()) : + EventListener(std::bind(fn, cls, std::placeholders::_1), filter) { this->enable(); } void bind(std::function fn) { m_callback = fn; } + template void bind(C* cls, MemberFn fn) { m_callback = std::bind(fn, cls, std::placeholders::_1); } + protected: std::function m_callback; T m_filter; @@ -96,6 +104,7 @@ namespace geode { static std::unordered_set s_listeners; Mod* m_sender; friend EventListenerProtocol; + public: void postFrom(Mod* sender); diff --git a/loader/include/Geode/loader/ModEvent.hpp b/loader/include/Geode/loader/ModEvent.hpp index 016464da..70fc22a4 100644 --- a/loader/include/Geode/loader/ModEvent.hpp +++ b/loader/include/Geode/loader/ModEvent.hpp @@ -1,9 +1,10 @@ #pragma once #include "Event.hpp" -#include #include "Mod.hpp" +#include + namespace geode { enum class ModEventType { Loaded, @@ -18,40 +19,44 @@ namespace geode { protected: ModEventType m_type; Mod* m_mod; - + public: ModStateEvent(Mod* mod, ModEventType type); ModEventType getType() const; Mod* getMod() const; }; - class GEODE_DLL ModStateFilter : public EventFilter { - public: - using Callback = void(ModStateEvent*); - - protected: + class GEODE_DLL ModStateFilter : public EventFilter { + public: + using Callback = void(ModStateEvent*); + + protected: ModEventType m_type; Mod* m_mod; - - public: + + public: ListenerResult handle(std::function fn, ModStateEvent* event); - ModStateFilter(Mod* mod, ModEventType type); - }; + ModStateFilter(Mod* mod, ModEventType type); + }; } -#define $on_mod(type) \ -template \ -void GEODE_CONCAT(geodeExecFunction, __LINE__)(ModStateEvent*); \ -namespace { \ - struct GEODE_CONCAT(ExecFuncUnique, __LINE__) {}; \ -} \ -static inline auto GEODE_CONCAT(Exec, __LINE__) = (geode::Loader::get()->scheduleOnModLoad(\ - geode::Mod::get(), []() { \ - static auto _ = geode::EventListener( \ - &GEODE_CONCAT(geodeExecFunction, __LINE__),\ - geode::ModStateFilter(geode::Mod::get(), geode::ModEventType::type)\ - ); \ - } \ -), 0); \ -template \ -void GEODE_CONCAT(geodeExecFunction, __LINE__)(ModStateEvent*) +#define $on_mod(type) \ + template \ + void GEODE_CONCAT(geodeExecFunction, __LINE__)(ModStateEvent*); \ + namespace { \ + struct GEODE_CONCAT(ExecFuncUnique, __LINE__) {}; \ + } \ + static inline auto GEODE_CONCAT(Exec, __LINE__) = \ + (geode::Loader::get()->scheduleOnModLoad( \ + geode::Mod::get(), \ + []() { \ + static auto _ = geode::EventListener( \ + &GEODE_CONCAT(geodeExecFunction, __LINE__) < \ + GEODE_CONCAT(ExecFuncUnique, __LINE__) >, \ + geode::ModStateFilter(geode::Mod::get(), geode::ModEventType::type) \ + ); \ + } \ + ), \ + 0); \ + template \ + void GEODE_CONCAT(geodeExecFunction, __LINE__)(ModStateEvent*) diff --git a/loader/include/Geode/utils/JsonValidation.hpp b/loader/include/Geode/utils/JsonValidation.hpp index db9c011b..9de90ac1 100644 --- a/loader/include/Geode/utils/JsonValidation.hpp +++ b/loader/include/Geode/utils/JsonValidation.hpp @@ -1,7 +1,7 @@ #pragma once -#include "../loader/Log.hpp" #include "../external/json/json.hpp" +#include "../loader/Log.hpp" #include #include @@ -15,9 +15,7 @@ namespace geode { template struct is_iterable< - T, - std::void_t< - decltype(std::begin(std::declval())), decltype(std::end(std::declval()))>> : + T, std::void_t())), decltype(std::end(std::declval()))>> : std::true_type {}; template @@ -79,7 +77,7 @@ namespace geode { } template - using JsonValueValidator = bool (*)(T const&); + using JsonValueValidator = std::function; template struct JsonMaybeObject; @@ -175,6 +173,11 @@ namespace geode { return *this; } + template + JsonMaybeValue& validate(bool (*validator)(T const&)) { + return this->validate(std::function(validator)); + } + template JsonMaybeValue& inferType() { if (this->isError() || !m_inferType) return *this; diff --git a/loader/include/Geode/utils/cocos.hpp b/loader/include/Geode/utils/cocos.hpp index acbc9603..a20233bb 100644 --- a/loader/include/Geode/utils/cocos.hpp +++ b/loader/include/Geode/utils/cocos.hpp @@ -1,8 +1,9 @@ #pragma once -#include "casts.hpp" #include "../external/json/json.hpp" +#include "casts.hpp" #include "general.hpp" + #include #include #include @@ -139,11 +140,11 @@ namespace geode { } static cocos2d::CCSize operator-(cocos2d::CCSize const& size, float f) { - return { size.width - f, size.height - f }; + return {size.width - f, size.height - f}; } static cocos2d::CCSize operator-(cocos2d::CCSize const& size) { - return { -size.width, -size.height }; + return {-size.width, -size.height}; } static bool operator==(cocos2d::CCPoint const& p1, cocos2d::CCPoint const& p2) { @@ -283,6 +284,7 @@ namespace geode { bool operator==(T* other) const { return m_obj == other; } + bool operator==(Ref const& other) const { return m_obj == other.m_obj; } @@ -290,6 +292,7 @@ namespace geode { bool operator!=(T* other) const { return m_obj != other; } + bool operator!=(Ref const& other) const { return m_obj != other.m_obj; } @@ -298,6 +301,7 @@ namespace geode { bool operator<(Ref const& other) const { return m_obj < other.m_obj; } + bool operator>(Ref const& other) const { return m_obj > other.m_obj; } @@ -435,13 +439,13 @@ namespace geode::cocos { */ GEODE_DLL cocos2d::CCScene* switchToScene(cocos2d::CCLayer* layer); - using CreateLayerFunc = cocos2d::CCLayer*(*)(); + using CreateLayerFunc = std::function; /** - * Reload textures, overwriting the scene to return to after the loading + * Reload textures, overwriting the scene to return to after the loading * screen is finished - * @param returnTo A function that returns a new layer. After loading is - * finished, the game switches to the given layer instead of MenuLayer. + * @param returnTo A function that returns a new layer. After loading is + * finished, the game switches to the given layer instead of MenuLayer. * Leave nullptr to enable default behaviour */ GEODE_DLL void reloadTextures(CreateLayerFunc returnTo = nullptr); @@ -453,9 +457,7 @@ namespace geode::cocos { * @param def Default size * @param min Minimum size */ - GEODE_DLL void limitNodeSize( - cocos2d::CCNode* node, cocos2d::CCSize const& size, float def, float min - ); + GEODE_DLL void limitNodeSize(cocos2d::CCNode* node, cocos2d::CCSize const& size, float def, float min); /** * Checks if a node is visible (recursively @@ -478,12 +480,12 @@ namespace geode::cocos { GEODE_DLL cocos2d::CCNode* getChildByTagRecursive(cocos2d::CCNode* node, int tag); /** - * Get first node that conforms to the predicate + * Get first node that conforms to the predicate * by traversing children recursively - * + * * @param node Parent node * @param predicate Predicate used to evaluate nodes - * @return Child node if one is found, or null if + * @return Child node if one is found, or null if * there is none */ template @@ -497,8 +499,7 @@ namespace geode::cocos { for (int i = 0; i < children->count(); ++i) { auto newParent = static_cast(children->objectAtIndex(i)); auto child = findFirstChildRecursive(newParent, predicate); - if (child) - return child; + if (child) return child; } return nullptr; @@ -602,13 +603,18 @@ namespace geode::cocos { } inline cocos2d::ccColor4B invert4B(cocos2d::ccColor4B const& color) { - return { static_cast(255 - color.r), static_cast(255 - color.g), - static_cast(255 - color.b), color.a }; + return { + static_cast(255 - color.r), + static_cast(255 - color.g), + static_cast(255 - color.b), + color.a}; } inline cocos2d::ccColor3B invert3B(cocos2d::ccColor3B const& color) { - return { static_cast(255 - color.r), static_cast(255 - color.g), - static_cast(255 - color.b) }; + return { + static_cast(255 - color.r), + static_cast(255 - color.g), + static_cast(255 - color.b)}; } inline cocos2d::ccColor3B lighten3B(cocos2d::ccColor3B const& color, int amount) { @@ -624,34 +630,38 @@ namespace geode::cocos { } inline cocos2d::ccColor3B to3B(cocos2d::ccColor4B const& color) { - return { color.r, color.g, color.b }; + return {color.r, color.g, color.b}; } inline cocos2d::ccColor4B to4B(cocos2d::ccColor3B const& color, GLubyte alpha = 255) { - return { color.r, color.g, color.b, alpha }; + return {color.r, color.g, color.b, alpha}; } inline cocos2d::ccColor4F to4F(cocos2d::ccColor4B const& color) { - return { color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f }; + return {color.r / 255.f, color.g / 255.f, color.b / 255.f, color.a / 255.f}; } constexpr cocos2d::ccColor3B cc3x(int hexValue) { if (hexValue <= 0xf) - return cocos2d::ccColor3B { static_cast(hexValue * 17), - static_cast(hexValue * 17), - static_cast(hexValue * 17) }; + return cocos2d::ccColor3B{ + static_cast(hexValue * 17), + static_cast(hexValue * 17), + static_cast(hexValue * 17)}; if (hexValue <= 0xff) - return cocos2d::ccColor3B { static_cast(hexValue), - static_cast(hexValue), - static_cast(hexValue) }; + return cocos2d::ccColor3B{ + static_cast(hexValue), + static_cast(hexValue), + static_cast(hexValue)}; if (hexValue <= 0xfff) - return cocos2d::ccColor3B { static_cast((hexValue >> 8 & 0xf) * 17), - static_cast((hexValue >> 4 & 0xf) * 17), - static_cast((hexValue >> 0 & 0xf) * 17) }; + return cocos2d::ccColor3B{ + static_cast((hexValue >> 8 & 0xf) * 17), + static_cast((hexValue >> 4 & 0xf) * 17), + static_cast((hexValue >> 0 & 0xf) * 17)}; else - return cocos2d::ccColor3B { static_cast(hexValue >> 16 & 0xff), - static_cast(hexValue >> 8 & 0xff), - static_cast(hexValue >> 0 & 0xff) }; + return cocos2d::ccColor3B{ + static_cast(hexValue >> 16 & 0xff), + static_cast(hexValue >> 8 & 0xff), + static_cast(hexValue >> 0 & 0xff)}; } GEODE_DLL Result cc3bFromHexString(std::string const& hexValue); @@ -668,9 +678,7 @@ namespace geode::cocos { } template >> - static cocos2d::CCArray* vectorToCCArray( - std::vector const& vec, std::function convFunc - ) { + static cocos2d::CCArray* vectorToCCArray(std::vector const& vec, std::function convFunc) { auto res = cocos2d::CCArray::createWithCapacity(vec.size()); for (auto const& item : vec) res->addObject(convFunc(item)); @@ -680,8 +688,7 @@ namespace geode::cocos { template >> std::vector ccArrayToVector(cocos2d::CCArray* arr) { return std::vector( - reinterpret_cast(arr->data->arr), - reinterpret_cast(arr->data->arr) + arr->data->num + reinterpret_cast(arr->data->arr), reinterpret_cast(arr->data->arr) + arr->data->num ); } @@ -698,9 +705,7 @@ namespace geode::cocos { template < typename K, typename V, typename C, typename = std::enable_if_t || std::is_same_v>> - static cocos2d::CCDictionary* mapToCCDict( - std::map const& map, std::function convFunc - ) { + static cocos2d::CCDictionary* mapToCCDict(std::map const& map, std::function convFunc) { auto res = cocos2d::CCDictionary::create(); for (auto const& [key, value] : map) res->setObject(value, convFunc(key)); @@ -725,7 +730,7 @@ namespace geode::cocos { // std specializations namespace std { // enables using Ref as the key in unordered_map etc. - template + template struct hash> { size_t operator()(geode::Ref const& ref) const { return std::hash()(ref.data()); @@ -797,6 +802,7 @@ namespace geode::cocos { } return CCArrayIterator(reinterpret_cast(m_arr->data->arr) + m_arr->count()); } + size_t size() const { return m_arr ? m_arr->count() : 0; } @@ -829,10 +835,10 @@ namespace geode::cocos { std::pair operator*() { if constexpr (std::is_same::value) { - return { m_ptr->getStrKey(), static_cast(m_ptr->getObject()) }; + return {m_ptr->getStrKey(), static_cast(m_ptr->getObject())}; } else { - return { m_ptr->getIntKey(), static_cast(m_ptr->getObject()) }; + return {m_ptr->getIntKey(), static_cast(m_ptr->getObject())}; } } @@ -997,7 +1003,7 @@ namespace geode::cocos { using Selector = Ret (Base::*)(Args...); using Holder = LambdaHolder; - static inline Holder s_selector {}; + static inline Holder s_selector{}; Ret selector(Args... args) { return s_selector(std::forward(args)...); diff --git a/loader/include/Geode/utils/web.hpp b/loader/include/Geode/utils/web.hpp index 94b08f4a..8cbe6935 100644 --- a/loader/include/Geode/utils/web.hpp +++ b/loader/include/Geode/utils/web.hpp @@ -1,8 +1,8 @@ #pragma once #include "../DefaultInclude.hpp" -#include "Result.hpp" #include "../external/json/json.hpp" +#include "Result.hpp" #include "general.hpp" #include @@ -10,7 +10,7 @@ namespace geode::utils::web { GEODE_DLL void openLinkInBrowser(std::string const& url); - + using FileProgressCallback = std::function; /** @@ -38,8 +38,7 @@ namespace geode::utils::web { * @returns Returned data as JSON, or error on error */ GEODE_DLL Result<> fetchFile( - std::string const& url, ghc::filesystem::path const& into, - FileProgressCallback prog = nullptr + std::string const& url, ghc::filesystem::path const& into, FileProgressCallback prog = nullptr ); /** diff --git a/loader/src/loader/Event.cpp b/loader/src/loader/Event.cpp index 2b4244e5..1275dd9a 100644 --- a/loader/src/loader/Event.cpp +++ b/loader/src/loader/Event.cpp @@ -13,7 +13,7 @@ void EventListenerProtocol::disable() { } EventListenerProtocol::~EventListenerProtocol() { - this->disable(); + this->disable(); } Event::~Event() {} diff --git a/loader/src/loader/Mod.cpp b/loader/src/loader/Mod.cpp index ee18f1b3..dcfaac1c 100644 --- a/loader/src/loader/Mod.cpp +++ b/loader/src/loader/Mod.cpp @@ -122,7 +122,8 @@ Result<> Mod::loadData() { } else { log::log( - Severity::Warning, this, + Severity::Warning, + this, "Encountered unknown setting \"{}\" while loading " "settings", key diff --git a/loader/src/loader/ModEvent.cpp b/loader/src/loader/ModEvent.cpp index 85ed083f..753d8e5d 100644 --- a/loader/src/loader/ModEvent.cpp +++ b/loader/src/loader/ModEvent.cpp @@ -19,7 +19,4 @@ ListenerResult ModStateFilter::handle(std::function fn, ModStateEvent* return ListenerResult::Propagate; } -ModStateFilter::ModStateFilter( - Mod* mod, - ModEventType type -) : m_mod(mod), m_type(type) {} +ModStateFilter::ModStateFilter(Mod* mod, ModEventType type) : m_mod(mod), m_type(type) {} diff --git a/loader/src/main.cpp b/loader/src/main.cpp index 7fe6337e..2a57c3a6 100644 --- a/loader/src/main.cpp +++ b/loader/src/main.cpp @@ -100,7 +100,9 @@ BOOL WINAPI DllMain(HINSTANCE lib, DWORD reason, LPVOID) { } #endif -$execute { +#define $_ GEODE_CONCAT(unnamedVar_, __LINE__) + +static auto $_ = listenForSettingChanges("show-platform-console", [](BoolSetting* setting) { if (setting->getValue()) { Loader::get()->openPlatformConsole(); @@ -109,35 +111,38 @@ $execute { Loader::get()->closePlatfromConsole(); } }); - listenForIPC("ipc-test", [](IPCEvent* event) -> nlohmann::json { - return "Hello from Geode!"; - }); - listenForIPC("loader-info", [](IPCEvent* event) -> nlohmann::json { - return Loader::get()->getInternalMod()->getModInfo(); - }); - listenForIPC("list-mods", [](IPCEvent* event) -> nlohmann::json { - std::vector res; +static auto $_ = listenForIPC("ipc-test", [](IPCEvent* event) -> nlohmann::json { + return "Hello from Geode!"; +}); - auto args = event->getMessageData(); - JsonChecker checker(args); - auto root = checker.root("").obj(); +static auto $_ = listenForIPC("loader-info", [](IPCEvent* event) -> nlohmann::json { + return Loader::get()->getInternalMod()->getModInfo(); +}); - auto includeRunTimeInfo = root.has("include-runtime-info").template get(); - auto dontIncludeLoader = root.has("dont-include-loader").template get(); +static auto $_ = listenForIPC("list-mods", [](IPCEvent* event) -> nlohmann::json { + std::vector res; - if (!dontIncludeLoader) { - auto mod = Loader::get()->getInternalMod(); - res.push_back(includeRunTimeInfo ? mod->getRuntimeInfo() : mod->getModInfo().toJSON()); - } + auto args = event->getMessageData(); + JsonChecker checker(args); + auto root = checker.root("").obj(); - for (auto& mod : Loader::get()->getAllMods()) { - res.push_back(includeRunTimeInfo ? mod->getRuntimeInfo() : mod->getModInfo().toJSON()); - } + auto includeRunTimeInfo = root.has("include-runtime-info").template get(); + auto dontIncludeLoader = root.has("dont-include-loader").template get(); - return res; - }); -} + if (!dontIncludeLoader) { + res.push_back( + includeRunTimeInfo ? Loader::get()->getInternalMod()->getRuntimeInfo() : + Loader::get()->getInternalMod()->getModInfo().toJSON() + ); + } + + for (auto& mod : Loader::get()->getAllMods()) { + res.push_back(includeRunTimeInfo ? mod->getRuntimeInfo() : mod->getModInfo().toJSON()); + } + + return res; +}); int geodeEntry(void* platformData) { // setup internals diff --git a/loader/src/platform/mac/InternalLoader.cpp b/loader/src/platform/mac/InternalLoader.cpp index ca54d58e..8c791e2a 100644 --- a/loader/src/platform/mac/InternalLoader.cpp +++ b/loader/src/platform/mac/InternalLoader.cpp @@ -1,12 +1,12 @@ -#include -#include -#include -#include #include +#include +#include +#include +#include #ifdef GEODE_IS_MACOS -#include + #include void InternalLoader::platformMessageBox(char const* title, std::string const& info) { CFStringRef cfTitle = CFStringCreateWithCString(NULL, title, kCFStringEncodingUTF8); @@ -29,46 +29,37 @@ void InternalLoader::closePlatformConsole() { m_platformConsoleOpen = false; } -CFDataRef msgPortCallback( - CFMessagePortRef port, - SInt32 messageID, - CFDataRef data, - void* info -) { - if(!CFDataGetLength(data)) - return NULL; +CFDataRef msgPortCallback(CFMessagePortRef port, SInt32 messageID, CFDataRef data, void* info) { + if (!CFDataGetLength(data)) return NULL; - std::string cdata( - reinterpret_cast(CFDataGetBytePtr(data)), - CFDataGetLength(data) - ); + std::string cdata(reinterpret_cast(CFDataGetBytePtr(data)), CFDataGetLength(data)); 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() { std::thread([]() { CFStringRef portName = CFStringCreateWithCString(NULL, IPC_PORT_NAME, kCFStringEncodingUTF8); - CFMessagePortRef localPort = CFMessagePortCreateLocal( - NULL, - portName, - msgPortCallback, - NULL, - NULL - ); + CFMessagePortRef localPort = + CFMessagePortCreateLocal(NULL, portName, msgPortCallback, NULL, NULL); + if (localPort == NULL) { + log::warn("Unable to create port, quitting IPC"); + return; + } CFRunLoopSourceRef runLoopSource = CFMessagePortCreateRunLoopSource(NULL, localPort, 0); - CFRunLoopAddSource( - CFRunLoopGetCurrent(), - runLoopSource, - kCFRunLoopCommonModes - ); + if (runLoopSource == NULL) { + log::warn("Unable to create loop source, quitting IPC"); + return; + } + + CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes); CFRunLoopRun(); CFRelease(localPort); }).detach(); - log::log(Severity::Warning, InternalMod::get(), "IPC is not supported on this platform"); + log::debug("IPC set up"); } #endif diff --git a/loader/src/platform/windows/InternalLoader.cpp b/loader/src/platform/windows/InternalLoader.cpp index 638b084f..ad07754f 100644 --- a/loader/src/platform/windows/InternalLoader.cpp +++ b/loader/src/platform/windows/InternalLoader.cpp @@ -1,8 +1,8 @@ -#include #include #include -#include +#include #include +#include USE_GEODE_NAMESPACE(); @@ -77,10 +77,10 @@ void InternalLoader::setupIPC() { nullptr ); if (pipe == INVALID_HANDLE_VALUE) { - // todo: Rn this quits IPC, but we might wanna change that later - // to just continue trying. however, I'm assuming that if - // CreateNamedPipeA fails, then it will probably fail again if - // you try right after, so changing the break; to continue; might + // todo: Rn this quits IPC, but we might wanna change that later + // to just continue trying. however, I'm assuming that if + // CreateNamedPipeA fails, then it will probably fail again if + // you try right after, so changing the break; to continue; might // just result in the console getting filled with error messages log::warn("Unable to create pipe, quitting IPC"); break; @@ -89,14 +89,15 @@ void InternalLoader::setupIPC() { if (ConnectNamedPipe(pipe, nullptr)) { // log::debug("Got connection, creating thread"); std::thread(&ipcPipeThread, pipe).detach(); - } else { + } + else { // log::debug("No connection, cleaning pipe"); CloseHandle(pipe); } } }).detach(); - log::log(Severity::Debug, InternalMod::get(), "IPC set up"); + log::debug("IPC set up"); } #endif diff --git a/loader/src/utils/web.cpp b/loader/src/utils/web.cpp index b0aca92d..8d25333b 100644 --- a/loader/src/utils/web.cpp +++ b/loader/src/utils/web.cpp @@ -368,32 +368,32 @@ AsyncWebRequest::~AsyncWebRequest() { AsyncWebResult AsyncWebResponse::into(std::ostream& stream) { m_request.m_target = &stream; - return this->as([](byte_array const&) -> Result { + return this->as(+[](byte_array const&) -> Result { return Ok(std::monostate()); }); } AsyncWebResult AsyncWebResponse::into(ghc::filesystem::path const& path) { m_request.m_target = path; - return this->as([](byte_array const&) -> Result { + return this->as(+[](byte_array const&) -> Result { return Ok(std::monostate()); }); } AsyncWebResult AsyncWebResponse::text() { - return this->as([](byte_array const& bytes) -> Result { + return this->as(+[](byte_array const& bytes) -> Result { return Ok(std::string(bytes.begin(), bytes.end())); }); } AsyncWebResult AsyncWebResponse::bytes() { - return this->as([](byte_array const& bytes) -> Result { + return this->as(+[](byte_array const& bytes) -> Result { return Ok(bytes); }); } AsyncWebResult AsyncWebResponse::json() { - return this->as([](byte_array const& bytes) -> Result { + return this->as(+[](byte_array const& bytes) -> Result { try { return Ok(nlohmann::json::parse(bytes.begin(), bytes.end())); }