diff --git a/mod.json b/mod.json index bc3c2d2..f7243a2 100644 --- a/mod.json +++ b/mod.json @@ -53,10 +53,10 @@ }, "history-length": { "name": "History length", - "description": "The length of rewind history stored, in capture frame count.", + "description": "The length of rewind history stored, in capture frame count. This will be attempted to be automatically populated on windows machines with Nvidia or AMD graphics cards by the amount of video memory available.", "type": "int", "min": 20, - "max": 400, + "max": 500, "default": { "android": 140, "ios": 140, diff --git a/src/hooks/MenuLayer.cpp b/src/hooks/MenuLayer.cpp new file mode 100644 index 0000000..8d74689 --- /dev/null +++ b/src/hooks/MenuLayer.cpp @@ -0,0 +1,50 @@ +#ifdef GEODE_IS_WINDOWS +#include "MenuLayer.hpp" +#include + +// populate defaults by getting amount of system vram +bool HookedMenuLayer::init() { + if (!MenuLayer::init()) return false; + + auto mod = geode::Mod::get(); + + bool hasSetRecommended = mod->getSavedValue("has-set-recommended", false); + if (hasSetRecommended) return true; + mod->setSavedValue("has-set-recommended", true); + + // https://stackoverflow.com/a/5695427 + // no intel support very sad + int values[4] = {}; + glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, values); // nvidia + glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, values); // amd (ati) + + if (values[0] == 0) { + geode::log::info("No data returned from vram checks :( ({}, {}, {}, {})", values[0], values[1], values[2], values[3]); + return true; + } + + int kb = values[0]; + int frames = (kb / 42000) + 80; // https://www.desmos.com/calculator/m2hlel1fjj + + geode::log::info("Video memory checks returned {}kb (approx), mapped to {} frames", kb, frames); + + frames = std::max(20, std::min(frames, 500)); + + mod->setSettingValue("history-length", frames); + + auto pop = FLAlertLayer::create( + "Rewind", + fmt::format( + "Rewind has automagically detected {}GB of video memory free, and " + "has set the max history length to {}, which can be customised in " + "the mod settings.", + kb / 1000000, frames + ).c_str(), + "ok" + ); + pop->m_scene = this; + pop->show(); + + return true; +} +#endif diff --git a/src/hooks/MenuLayer.hpp b/src/hooks/MenuLayer.hpp new file mode 100644 index 0000000..1d42099 --- /dev/null +++ b/src/hooks/MenuLayer.hpp @@ -0,0 +1,9 @@ +#pragma once +#ifdef GEODE_IS_WINDOWS +#include + +class $modify(HookedMenuLayer, MenuLayer) { + bool init(); +}; + +#endif diff --git a/src/settings.cpp b/src/settings.cpp index b654965..c5d65fa 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -18,4 +18,4 @@ fields->m_resolutionMultiplier = geode::Mod::get()->getSettingValue("resolution-multiplier"); } }); -}; +}