mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-26 04:39:51 -04:00
fix events, resources, and minor stuff
This commit is contained in:
parent
208ba02279
commit
80b5b20efb
16 changed files with 70 additions and 14 deletions
bindings
loader
include/Geode/loader
src
|
@ -4789,8 +4789,6 @@ class PlayerObject : GameObject, AnimatedSpriteDelegate {
|
|||
void usingWallLimitedMode() = mac 0x22df00;
|
||||
void yStartDown() = mac 0x22e9b0;
|
||||
void yStartUp() = mac 0x22e990;
|
||||
void runRotateAction() = win 0x1e9bf0;
|
||||
void runBallRotation() = win 0x1e9d10;
|
||||
|
||||
PAD = mac 0x14, win 0x14;
|
||||
bool m_unk480;
|
||||
|
|
|
@ -65,6 +65,7 @@ namespace geode {
|
|||
std::vector<InvalidGeodeFile> getFailedMods() const;
|
||||
|
||||
void updateResources();
|
||||
void updateResources(bool forceReload);
|
||||
|
||||
void queueInGDThread(ScheduledFunction func);
|
||||
void waitForModsToBeLoaded();
|
||||
|
|
|
@ -52,6 +52,7 @@ namespace geode {
|
|||
* @param type Type of event to listen to. Ignored if mod is nullptr
|
||||
*/
|
||||
ModStateFilter(Mod* mod, ModEventType type);
|
||||
ModStateFilter(ModStateFilter const&);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ struct ResourcesUpdate : Modify<ResourcesUpdate, LoadingLayer> {
|
|||
LoadingLayer::loadAssets();
|
||||
// this is in case the user refreshes texture quality at runtime
|
||||
if (m_loadStep == 10) {
|
||||
Loader::get()->updateResources();
|
||||
Loader::get()->updateResources(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -99,6 +99,10 @@ void Loader::updateResources() {
|
|||
return m_impl->updateResources();
|
||||
}
|
||||
|
||||
void Loader::updateResources(bool forceReload) {
|
||||
return m_impl->updateResources(forceReload);
|
||||
}
|
||||
|
||||
void Loader::queueInGDThread(ScheduledFunction func) {
|
||||
return m_impl->queueInGDThread(func);
|
||||
}
|
||||
|
|
|
@ -108,14 +108,18 @@ void Loader::Impl::addSearchPaths() {
|
|||
}
|
||||
|
||||
void Loader::Impl::updateResources() {
|
||||
log::debug("Adding resources");
|
||||
this->updateResources(true);
|
||||
}
|
||||
|
||||
// add own spritesheets
|
||||
this->updateModResources(Mod::get());
|
||||
void Loader::Impl::updateResources(bool forceReload) {
|
||||
log::debug("Adding resources");
|
||||
|
||||
// add mods' spritesheets
|
||||
for (auto const& [_, mod] : m_mods) {
|
||||
this->updateModResources(mod);
|
||||
if (forceReload || !ModImpl::getImpl(mod)->m_resourcesLoaded) {
|
||||
this->updateModResources(mod);
|
||||
ModImpl::getImpl(mod)->m_resourcesLoaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -138,6 +138,7 @@ namespace geode {
|
|||
std::vector<InvalidGeodeFile> getFailedMods() const;
|
||||
|
||||
void updateResources();
|
||||
void updateResources(bool forceReload);
|
||||
|
||||
void waitForModsToBeLoaded();
|
||||
|
||||
|
@ -149,6 +150,8 @@ namespace geode {
|
|||
void executeGDThreadQueue();
|
||||
|
||||
void logConsoleMessage(std::string const& msg);
|
||||
void logConsoleMessageWithSeverity(std::string const& msg, Severity severity);
|
||||
|
||||
bool platformConsoleOpen() const;
|
||||
void openPlatformConsole();
|
||||
void closePlatformConsole();
|
||||
|
|
|
@ -209,7 +209,7 @@ void Logger::setup() {
|
|||
void Logger::push(Log&& log) {
|
||||
std::string logStr = log.toString(true);
|
||||
|
||||
LoaderImpl::get()->logConsoleMessage(logStr);
|
||||
LoaderImpl::get()->logConsoleMessageWithSeverity(logStr, log.getSeverity());
|
||||
logStream() << logStr << std::endl;
|
||||
|
||||
logs().emplace_back(std::forward<Log>(log));
|
||||
|
|
|
@ -13,10 +13,13 @@ Mod* ModStateEvent::getMod() const {
|
|||
}
|
||||
|
||||
ListenerResult ModStateFilter::handle(utils::MiniFunction<Callback> fn, ModStateEvent* event) {
|
||||
if (!m_mod || (event->getMod() == m_mod && event->getType() == m_type)) {
|
||||
// log::debug("Event mod filter: {}, {}, {}, {}", m_mod, static_cast<int>(m_type), event->getMod(), static_cast<int>(event->getType()));
|
||||
if ((!m_mod || event->getMod() == m_mod) && event->getType() == m_type) {
|
||||
fn(event);
|
||||
}
|
||||
return ListenerResult::Propagate;
|
||||
}
|
||||
|
||||
ModStateFilter::ModStateFilter(Mod* mod, ModEventType type) : m_mod(mod), m_type(type) {}
|
||||
|
||||
ModStateFilter::ModStateFilter(ModStateFilter const& other) : m_mod(other.m_mod), m_type(other.m_type) {}
|
||||
|
|
|
@ -289,6 +289,7 @@ bool Mod::Impl::hasSetting(std::string const& key) const {
|
|||
// Loading, Toggling, Installing
|
||||
|
||||
Result<> Mod::Impl::loadBinary() {
|
||||
log::debug("Loading binary for mod {}", m_info.id());
|
||||
if (m_binaryLoaded) {
|
||||
return Ok();
|
||||
}
|
||||
|
@ -305,6 +306,7 @@ Result<> Mod::Impl::loadBinary() {
|
|||
if (!res) {
|
||||
// make sure to free up the next mod mutex
|
||||
LoaderImpl::get()->releaseNextMod();
|
||||
log::warn("Failed to load binary for mod {}: {}", m_info.id(), res.unwrapErr());
|
||||
return res;
|
||||
}
|
||||
m_binaryLoaded = true;
|
||||
|
@ -316,8 +318,11 @@ Result<> Mod::Impl::loadBinary() {
|
|||
});
|
||||
|
||||
Loader::get()->updateAllDependencies();
|
||||
Loader::get()->updateResources();
|
||||
|
||||
if (LoaderImpl::get()->m_isSetup) {
|
||||
Loader::get()->updateResources(false);
|
||||
}
|
||||
|
||||
log::debug("Enabling mod {}", m_info.id());
|
||||
GEODE_UNWRAP(this->enable());
|
||||
|
||||
return Ok();
|
||||
|
@ -375,7 +380,8 @@ Result<> Mod::Impl::enable() {
|
|||
|
||||
for (auto const& patch : m_patches) {
|
||||
if (!patch->apply()) {
|
||||
return Err("Unable to apply patch at " + std::to_string(patch->getAddress()));
|
||||
log::warn("Unable to apply patch at {}", patch->getAddress());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,11 @@ namespace geode {
|
|||
*/
|
||||
json::Value m_savedSettingsData = json::Object();
|
||||
|
||||
/**
|
||||
* Whether the mod resources are loaded or not
|
||||
*/
|
||||
bool m_resourcesLoaded = false;
|
||||
|
||||
Impl(Mod* self, ModInfo const& info);
|
||||
~Impl();
|
||||
|
||||
|
|
|
@ -87,6 +87,9 @@ Result<ModInfo> ModInfo::Impl::createFromSchemaV010(ModJson const& rawJson) {
|
|||
|
||||
root.addKnownKey("geode");
|
||||
|
||||
// don't think its used locally yet
|
||||
root.addKnownKey("tags");
|
||||
|
||||
root.needs("id").validate(MiniFunction<bool(std::string const&)>(&ModInfo::validateID)).into(impl->m_id);
|
||||
root.needs("version").into(impl->m_version);
|
||||
root.needs("name").into(impl->m_name);
|
||||
|
|
|
@ -15,6 +15,12 @@ void Loader::Impl::platformMessageBox(char const* title, std::string const& info
|
|||
std::cout << title << ": " << info << std::endl;
|
||||
}
|
||||
|
||||
void Loader::Impl::logConsoleMessageWithSeverity(std::string const& msg, Severity severity) {
|
||||
if (m_platformConsoleOpen) {
|
||||
std::cout << msg << "\n" << std::flush;
|
||||
}
|
||||
}
|
||||
|
||||
void Loader::Impl::openPlatformConsole() {
|
||||
ghc::filesystem::path(getpwuid(getuid())->pw_dir);
|
||||
freopen(ghc::filesystem::path(dirs::getGeodeDir() / "geode_log.txt").string().c_str(), "w", stdout);
|
||||
|
|
|
@ -19,11 +19,27 @@ void Loader::Impl::platformMessageBox(char const* title, std::string const& info
|
|||
);
|
||||
}
|
||||
|
||||
void Loader::Impl::logConsoleMessageWithSeverity(std::string const& msg, Severity severity) {
|
||||
if (m_platformConsoleOpen) {
|
||||
int colorcode = 0;
|
||||
switch (severity) {
|
||||
case Severity::Debug: colorcode = 36; break;
|
||||
case Severity::Info: colorcode = 34; break;
|
||||
case Severity::Warning: colorcode = 33; break;
|
||||
case Severity::Error: colorcode = 31; break;
|
||||
default: colorcode = 35; break;
|
||||
}
|
||||
auto newMsg = "\033[1;" + std::to_string(colorcode) + "m" + msg.substr(0, 8) + "\033[0m" + msg.substr(8);
|
||||
|
||||
std::cout << newMsg << "\n" << std::flush;
|
||||
}
|
||||
}
|
||||
|
||||
void Loader::Impl::openPlatformConsole() {
|
||||
m_platformConsoleOpen = true;
|
||||
|
||||
for (auto const& log : log::Logger::list()) {
|
||||
std::cout << log->toString(true) << "\n";
|
||||
this->logConsoleMessageWithSeverity(log->toString(true), log->getSeverity());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ void utils::web::openLinkInBrowser(std::string const& url) {
|
|||
|
||||
int result = [panel runModal];
|
||||
|
||||
if (result == NSFileHandlingPanelOKButton) {
|
||||
if (result == NSModalResponseOK) {
|
||||
std::vector<ghc::filesystem::path> fileURLs;
|
||||
|
||||
for (NSURL* i in panel.URLs) {
|
||||
|
|
|
@ -17,6 +17,12 @@ void Loader::Impl::platformMessageBox(char const* title, std::string const& info
|
|||
MessageBoxA(nullptr, info.c_str(), title, MB_ICONERROR);
|
||||
}
|
||||
|
||||
void Loader::Impl::logConsoleMessageWithSeverity(std::string const& msg, Severity severity) {
|
||||
if (m_platformConsoleOpen) {
|
||||
std::cout << msg << "\n" << std::flush;
|
||||
}
|
||||
}
|
||||
|
||||
void Loader::Impl::openPlatformConsole() {
|
||||
if (m_platformConsoleOpen) return;
|
||||
if (AllocConsole() == 0) return;
|
||||
|
|
Loading…
Add table
Reference in a new issue