Merge branch 'geode-sdk:main' into main

This commit is contained in:
alk 2022-10-11 23:55:42 +03:00 committed by GitHub
commit 5e8fbe1f3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 166 additions and 48 deletions

View file

@ -1,3 +1,17 @@
# Geode Changelog
## v0.4.3
- Simplified the minimum and maximum loader versions, loader will now load any mod whose target version major and minor match. In practice, this means that for example mods whose target version is v0.4.8 can be loaded by loader of version v0.4.6.
- Add `Geode/ui/GeodeUI.hpp` header for exposing some access to internal Geode UI like opening a mod's settings popup
- Fix crash with settings that could have a slider control
## v0.4.2
- Moved SDK version to its own file so CLI can query it
- md4c is now linked statically on MacOS
- Fix log filenames
## v0.4.1
- Initial dev release of Geode.
@ -6,10 +20,13 @@
Note that from here on, changes to the framework were not tracked by versions as the framework was still considered to be in heavy development and not released. Instead, major changes are listed by dates.
## 2022/10/10
- Geode released for developers
## 2022/10/08
- `ui` branch merged to `main`
- Geode released for developers
## 2022/10/03

View file

@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build libraries static" FORCE)
set(GEODE_VERSION 0.4.1)
file(READ VERSION GEODE_VERSION)
string(STRIP "${GEODE_VERSION}" GEODE_VERSION)
project(geode-sdk VERSION ${GEODE_VERSION} LANGUAGES CXX C)
@ -13,6 +14,9 @@ endif()
add_library(${PROJECT_NAME} INTERFACE)
# Rerun CMake on VERSION file change
set_target_properties(${PROJECT_NAME} PROPERTIES CMAKE_CONFIGURE_DEPENDS VERSION)
target_compile_definitions(${PROJECT_NAME} INTERFACE -DPROJECT_NAME=${CMAKE_PROJECT_NAME})
set(GEODE_CODEGEN_PATH ${CMAKE_CURRENT_BINARY_DIR}/codegenned)

1
VERSION Normal file
View file

@ -0,0 +1 @@
0.4.5

View file

@ -3760,7 +3760,7 @@ class LevelPage {
class LevelSearchLayer : cocos2d::CCLayer {
static LevelSearchLayer* create() = mac 0x0, win 0x17d9c0, ios 0x0;
bool init() = mac 0x384770, win 0x0, ios 0x0;
bool init() = mac 0x384770, win 0x17da60, ios 0x0;
GJSearchObject* getSearchObject(SearchType, gd::string) = mac 0x388a50, win 0x1805f0, ios 0x0;
void onMoreOptions(cocos2d::CCObject*) = mac 0x0, win 0x17f500, ios 0x0;
void onSearch(cocos2d::CCObject*) = mac 0x0, win 0x180fc0, ios 0x0;

View file

@ -9,6 +9,6 @@
static std::string calculateHash(std::string const& path) {
std::vector<uint8_t> s(picosha3::bits_to_bytes(256));
auto sha3_256 = picosha3::get_sha3_generator<256>();
std::ifstream file(path);
std::ifstream file(path, std::ios::binary);
return sha3_256.get_hex_string(file);
}

View file

@ -3,6 +3,7 @@
#include "Event.hpp"
#include <optional>
#include "Setting.hpp"
#include "Loader.hpp"
namespace geode {
class GEODE_DLL SettingChangedEvent : public Event {
@ -67,5 +68,30 @@ namespace geode {
m_targetKey(std::nullopt),
m_consumer(handler) {}
};
template<class T>
requires std::is_base_of_v<Setting, T>
std::monostate listenForSettingChanges(
std::string const& settingID,
void(*callback)(std::shared_ptr<T>)
) {
Loader::get()->scheduleOnModLoad(getMod(), [=]() {
static SettingChangedEventHandler<T> _(
getMod()->getID(), settingID, callback
);
});
return std::monostate();
}
static std::monostate listenForAllSettingChanges(
void(*callback)(std::shared_ptr<Setting>)
) {
Loader::get()->scheduleOnModLoad(getMod(), [=]() {
static SettingChangedEventHandler<Setting> _(
getMod()->getID(), callback
);
});
return std::monostate();
}
}

View file

@ -0,0 +1,23 @@
#pragma once
#include "../loader/Mod.hpp"
namespace geode {
/**
* Open the Geode mods list
*/
GEODE_DLL void openModsList();
/**
* Open the info popup for a mod
*/
GEODE_DLL void openInfoPopup(Mod* mod);
/**
* Open the store page for a mod (if it exists)
*/
GEODE_DLL void openIndexPopup(Mod* mod);
/**
* Open the settings popup for a mod (if it has any settings)
*/
GEODE_DLL void openSettingsPopup(Mod* mod);
}

View file

@ -6,16 +6,17 @@ void showError(std::string const& error) {
MessageBoxA(nullptr, error.c_str(), "Error Loading Geode", MB_ICONERROR);
}
int loadGeode() {
int loadGeode(PVOID module) {
if (!LoadLibraryW(L"Geode.dll")) {
auto code = GetLastError();
showError("Unable to load Geode (code " + std::to_string(code) + ")");
return code;
}
FreeLibraryAndExitThread(static_cast<HINSTANCE>(module), 0);
return 0;
}
DWORD WINAPI load(PVOID _) {
DWORD WINAPI load(PVOID module) {
auto workingDir = ghc::filesystem::current_path();
auto updatesDir = workingDir / "geode" / "update";
auto resourcesDir = workingDir / "geode" / "resources";
@ -23,22 +24,22 @@ DWORD WINAPI load(PVOID _) {
auto error = std::error_code();
if (ghc::filesystem::exists(updatesDir / "Geode.dll", error) && !error) {
ghc::filesystem::rename(
updatesDir / "Geode.dll",
workingDir / "Geode.dll", error
);
if (error) {
ghc::filesystem::rename(
updatesDir / "Geode.dll",
workingDir / "Geode.dll", error
);
if (error) {
showError("Unable to update Geode: Unable to move Geode.dll - " + error.message());
return error.value();
}
}
}
if (ghc::filesystem::exists(updatesDir / "resources", error) && !error) {
ghc::filesystem::remove_all(resourcesDir / "geode.loader", error);
if (ghc::filesystem::exists(updatesDir / "resources", error) && !error) {
ghc::filesystem::remove_all(resourcesDir / "geode.loader", error);
if (error) {
if (error) {
showError("Unable to update Geode resources: " + error.message());
} else {
} else {
ghc::filesystem::rename(
updatesDir / "resources",
resourcesDir / "geode.loader", error
@ -47,18 +48,19 @@ DWORD WINAPI load(PVOID _) {
showError("Unable to update Geode resources: " + error.message());
}
}
}
}
return loadGeode();
return loadGeode(module);
}
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID _) {
BOOL WINAPI DllMain(HINSTANCE module, DWORD reason, LPVOID) {
if (reason == DLL_PROCESS_ATTACH) {
HANDLE handle = CreateThread(NULL, 0, load, module, 0, NULL);
if (handle)
if (handle) {
CloseHandle(handle);
else
} else {
return FALSE;
}
}
return TRUE;
}

View file

@ -166,8 +166,6 @@ namespace geode::core::impl {
// DobbyDestroy(at);
// DobbyHook(at, to, &trampolines()[at]);
static auto _ = MH_Initialize();
MH_RemoveHook(at);
MH_CreateHook(at, to, &trampolines()[at]);
MH_EnableHook(at);
@ -175,7 +173,7 @@ namespace geode::core::impl {
}
bool geode::core::hook::initialize() {
return true;
return MH_Initialize() == MH_OK;
}
#endif

View file

@ -2,7 +2,7 @@
#include "about.hpp"
#include "InternalLoader.hpp"
static auto SUPPORT_INFO = R"MD(
static constexpr const char* SUPPORT_INFO = R"MD(
**Geode** is funded through your gracious <cy>**donations**</c>!
You can support our work by sending <cp>**catgirl pictures**</c> to [HJfod](user:104257) :))
)MD";

View file

@ -439,11 +439,21 @@ size_t Loader::getFieldIndexForClass(size_t hash) {
}
VersionInfo Loader::minModVersion() {
return { 0, 4, 0 };
// patches are always backwards-compatible. if not, we have failed
return VersionInfo {
Loader::getVersion().getMajor(),
Loader::getVersion().getMinor(),
0,
};
}
VersionInfo Loader::maxModVersion() {
return Loader::getVersion();
// patches are always backwards-compatible. if not, we have failed
return VersionInfo {
Loader::getVersion().getMajor(),
Loader::getVersion().getMinor(),
99999999,
};
}
bool Loader::supportedModVersion(VersionInfo const& version) {

View file

@ -54,20 +54,26 @@ __attribute__((constructor)) void _entry() {
#include <Windows.h>
DWORD WINAPI loadThread(void* arg) {
auto module = GetModuleHandleA("GeodeBootstrapper.dll");
FreeLibrary(module);
bool canMoveBootstrapper = true;
if (auto mod = GetModuleHandleA("GeodeBootstrapper.dll")) {
if (WaitForSingleObject(mod, 1000) != WAIT_OBJECT_0) {
canMoveBootstrapper = false;
}
}
auto workingDir = ghc::filesystem::current_path();
auto updatesDir = workingDir / "geode" / "update";
if (canMoveBootstrapper) {
auto workingDir = ghc::filesystem::current_path();
auto updatesDir = workingDir / "geode" / "update";
auto error = std::error_code();
auto error = std::error_code();
if (ghc::filesystem::exists(updatesDir / "GeodeBootstrapper.dll", error) && !error) {
ghc::filesystem::rename(
updatesDir / "GeodeBootstrapper.dll",
workingDir / "GeodeBootstrapper.dll", error
);
if (error) return error.value();
if (ghc::filesystem::exists(updatesDir / "GeodeBootstrapper.dll", error) && !error) {
ghc::filesystem::rename(
updatesDir / "GeodeBootstrapper.dll",
workingDir / "GeodeBootstrapper.dll", error
);
if (error) return error.value();
}
}
return geodeEntry(arg);
@ -91,9 +97,9 @@ BOOL WINAPI DllMain(HINSTANCE lib, DWORD reason, LPVOID) {
}
#endif
static SettingChangedEventHandler<BoolSetting> _(
"geode.loader", "show-platform-console",
[](auto setting) {
static auto _ = listenForSettingChanges(
"show-platform-console",
+[](std::shared_ptr<BoolSetting> setting) {
if (setting->getValue()) {
Loader::get()->openPlatformConsole();
} else {

View file

@ -0,0 +1,29 @@
#include <Geode/ui/GeodeUI.hpp>
#include "list/ModListLayer.hpp"
#include "info/ModInfoLayer.hpp"
#include "settings/ModSettingsPopup.hpp"
#include "../index/Index.hpp"
void geode::openModsList() {
ModListLayer::scene();
}
void geode::openInfoPopup(Mod* mod) {
ModInfoLayer::create(mod, nullptr)->show();
}
void geode::openIndexPopup(Mod* mod) {
if (Index::get()->isKnownItem(mod->getID())) {
ModInfoLayer::create(
new ModObject(Index::get()->getKnownItem(mod->getID())),
nullptr
)->show();
}
}
void geode::openSettingsPopup(Mod* mod) {
if (mod->hasSettings()) {
ModSettingsPopup::create(mod)->show();
}
}

View file

@ -576,7 +576,7 @@ void ModInfoLayer::FLAlert_Clicked(FLAlertLayer* layer, bool btn2) {
)->show();
}
}
m_list->refreshList();
if (m_list) m_list->refreshList();
this->onClose(nullptr);
} break;
}
@ -631,7 +631,7 @@ void ModInfoLayer::modInstallProgress(
m_ticket = nullptr;
m_list->refreshList();
if (m_list) m_list->refreshList();
this->onClose(nullptr);
} break;

View file

@ -423,11 +423,13 @@ namespace {
}
void updateSlider() {
auto setting = std::static_pointer_cast<T>(self()->m_setting);
m_slider->setValue(
valueToSlider(setting, self()->m_uncommittedValue)
);
m_slider->updateBar();
if (m_slider) {
auto setting = std::static_pointer_cast<T>(self()->m_setting);
m_slider->setValue(
valueToSlider(setting, self()->m_uncommittedValue)
);
m_slider->updateBar();
}
}
void onSlider(CCObject* slider) {