From 1281fdb8f9e97100f282e657ed82165dc4632692 Mon Sep 17 00:00:00 2001 From: undefined06855 <98057141+undefined06855@users.noreply.github.com> Date: Sat, 19 Apr 2025 18:41:31 +0100 Subject: [PATCH 1/5] test other platforms, zero on my laptop --- mod.json | 2 +- src/settings.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/mod.json b/mod.json index bc3c2d2..b38505c 100644 --- a/mod.json +++ b/mod.json @@ -56,7 +56,7 @@ "description": "The length of rewind history stored, in capture frame count.", "type": "int", "min": 20, - "max": 400, + "max": 500, "default": { "android": 140, "ios": 140, diff --git a/src/settings.cpp b/src/settings.cpp index b654965..588e918 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,4 +1,5 @@ #include +#include #include "hooks/GJBaseGameLayer.hpp" // shouldnt be necessary but i bet some people will be changing their mod settings @@ -18,4 +19,27 @@ fields->m_resolutionMultiplier = geode::Mod::get()->getSettingValue("resolution-multiplier"); } }); -}; + + + // populate defaults by getting amount of system vram + bool hasSetRecommended = geode::Mod::get()->getSavedValue("has-set-recommended", false); + if (hasSetRecommended) return; + + geode::Mod::get()->setSavedValue("has-set-recommended", true); + + // https://stackoverflow.com/a/5695427 + // some pretty sketchy glgetinteger calls + auto values = new int[4](); + glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, values); + glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, values); + + if (values[0] == 0) { + geode::log::info("No data returned from vram checks :( ({}, {}, {}, {})", values[0], values[1], values[2], values[3]); + delete[] values; + return; + } + + geode::log::info("Video memory checks returned {}", values[0]); + + delete[] values; +} From 77f0572a809aabe45f5197663abb24e4e266fdbe Mon Sep 17 00:00:00 2001 From: undefined06855 <98057141+undefined06855@users.noreply.github.com> Date: Sat, 19 Apr 2025 18:45:57 +0100 Subject: [PATCH 2/5] yeah probably wont work on other platforms --- src/settings.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/settings.cpp b/src/settings.cpp index 588e918..44d52a2 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -20,7 +20,7 @@ } }); - +#ifdef GEODE_IS_WINDOWS // populate defaults by getting amount of system vram bool hasSetRecommended = geode::Mod::get()->getSavedValue("has-set-recommended", false); if (hasSetRecommended) return; @@ -42,4 +42,5 @@ geode::log::info("Video memory checks returned {}", values[0]); delete[] values; +#endif } From be4ebc8eb7fc946d333b54ecfd7223a434e69f0c Mon Sep 17 00:00:00 2001 From: undefined06855 <98057141+undefined06855@users.noreply.github.com> Date: Sat, 19 Apr 2025 19:27:17 +0100 Subject: [PATCH 3/5] add popup, move to menulayer hook --- mod.json | 2 +- src/hooks/MenuLayer.cpp | 52 +++++++++++++++++++++++++++++++++++++++++ src/hooks/MenuLayer.hpp | 9 +++++++ src/settings.cpp | 25 -------------------- 4 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 src/hooks/MenuLayer.cpp create mode 100644 src/hooks/MenuLayer.hpp diff --git a/mod.json b/mod.json index b38505c..f7243a2 100644 --- a/mod.json +++ b/mod.json @@ -53,7 +53,7 @@ }, "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": 500, diff --git a/src/hooks/MenuLayer.cpp b/src/hooks/MenuLayer.cpp new file mode 100644 index 0000000..566c357 --- /dev/null +++ b/src/hooks/MenuLayer.cpp @@ -0,0 +1,52 @@ +#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; + mod->setSavedValue("has-set-recommended", true); + + // https://stackoverflow.com/a/5695427 + // no intel support very sad + auto values = new int[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]); + delete[] values; + return; + } + + int kb = values[0]; + delete[] values; + int frames = (kb / 40000) + 20; // 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 " + "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 44d52a2..c5d65fa 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1,5 +1,4 @@ #include -#include #include "hooks/GJBaseGameLayer.hpp" // shouldnt be necessary but i bet some people will be changing their mod settings @@ -19,28 +18,4 @@ fields->m_resolutionMultiplier = geode::Mod::get()->getSettingValue("resolution-multiplier"); } }); - -#ifdef GEODE_IS_WINDOWS - // populate defaults by getting amount of system vram - bool hasSetRecommended = geode::Mod::get()->getSavedValue("has-set-recommended", false); - if (hasSetRecommended) return; - - geode::Mod::get()->setSavedValue("has-set-recommended", true); - - // https://stackoverflow.com/a/5695427 - // some pretty sketchy glgetinteger calls - auto values = new int[4](); - glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, values); - glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, values); - - if (values[0] == 0) { - geode::log::info("No data returned from vram checks :( ({}, {}, {}, {})", values[0], values[1], values[2], values[3]); - delete[] values; - return; - } - - geode::log::info("Video memory checks returned {}", values[0]); - - delete[] values; -#endif } From c25057beb14676c7554068ab88c0e8d7998f0551 Mon Sep 17 00:00:00 2001 From: undefined06855 <98057141+undefined06855@users.noreply.github.com> Date: Sat, 19 Apr 2025 19:35:59 +0100 Subject: [PATCH 4/5] balls --- src/hooks/MenuLayer.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/hooks/MenuLayer.cpp b/src/hooks/MenuLayer.cpp index 566c357..b3ff83b 100644 --- a/src/hooks/MenuLayer.cpp +++ b/src/hooks/MenuLayer.cpp @@ -9,23 +9,21 @@ bool HookedMenuLayer::init() { auto mod = geode::Mod::get(); bool hasSetRecommended = mod->getSavedValue("has-set-recommended", false); - if (hasSetRecommended) return; + if (hasSetRecommended) return true; mod->setSavedValue("has-set-recommended", true); // https://stackoverflow.com/a/5695427 // no intel support very sad - auto values = new int[4](); + 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]); - delete[] values; - return; + return true; } int kb = values[0]; - delete[] values; int frames = (kb / 40000) + 20; // https://www.desmos.com/calculator/m2hlel1fjj geode::log::info("Video memory checks returned {}kb (approx), mapped to {} frames", kb, frames); From 1143539643cf183170b3b7c2e4fa68a2f32229db Mon Sep 17 00:00:00 2001 From: undefined06855 <98057141+undefined06855@users.noreply.github.com> Date: Sat, 19 Apr 2025 19:56:19 +0100 Subject: [PATCH 5/5] colours + adjust calculation --- src/hooks/MenuLayer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hooks/MenuLayer.cpp b/src/hooks/MenuLayer.cpp index b3ff83b..8d74689 100644 --- a/src/hooks/MenuLayer.cpp +++ b/src/hooks/MenuLayer.cpp @@ -24,7 +24,7 @@ bool HookedMenuLayer::init() { } int kb = values[0]; - int frames = (kb / 40000) + 20; // https://www.desmos.com/calculator/m2hlel1fjj + 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); @@ -35,9 +35,9 @@ bool HookedMenuLayer::init() { 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 " - "settings.", + "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"