|
| 1 | +#ifdef GEODE_IS_WINDOWS |
| 2 | +#include "MenuLayer.hpp" |
| 3 | +#include <Geode/cocos/platform/third_party/win32/OGLES/GL/glew.h> |
| 4 | + |
| 5 | +// populate defaults by getting amount of system vram |
| 6 | +bool HookedMenuLayer::init() { |
| 7 | + if (!MenuLayer::init()) return false; |
| 8 | + |
| 9 | + auto mod = geode::Mod::get(); |
| 10 | + |
| 11 | + bool hasSetRecommended = mod->getSavedValue<bool>("has-set-recommended", false); |
| 12 | + if (hasSetRecommended) return true; |
| 13 | + mod->setSavedValue<bool>("has-set-recommended", true); |
| 14 | + |
| 15 | + // https://stackoverflow.com/a/5695427 |
| 16 | + // no intel support very sad |
| 17 | + int values[4] = {}; |
| 18 | + glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, values); // nvidia |
| 19 | + glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, values); // amd (ati) |
| 20 | + |
| 21 | + if (values[0] == 0) { |
| 22 | + geode::log::info("No data returned from vram checks :( ({}, {}, {}, {})", values[0], values[1], values[2], values[3]); |
| 23 | + return true; |
| 24 | + } |
| 25 | + |
| 26 | + int kb = values[0]; |
| 27 | + int frames = (kb / 42000) + 80; // https://www.desmos.com/calculator/m2hlel1fjj |
| 28 | + |
| 29 | + geode::log::info("Video memory checks returned {}kb (approx), mapped to {} frames", kb, frames); |
| 30 | + |
| 31 | + frames = std::max(20, std::min(frames, 500)); |
| 32 | + |
| 33 | + mod->setSettingValue<int64_t>("history-length", frames); |
| 34 | + |
| 35 | + auto pop = FLAlertLayer::create( |
| 36 | + "Rewind", |
| 37 | + fmt::format( |
| 38 | + "Rewind has automagically detected <cy>{}GB</c> of video memory free, and " |
| 39 | + "has set the <cj>max history length</c> to <cy>{}</c>, which can be customised in " |
| 40 | + "the <co>mod settings</c>.", |
| 41 | + kb / 1000000, frames |
| 42 | + ).c_str(), |
| 43 | + "ok" |
| 44 | + ); |
| 45 | + pop->m_scene = this; |
| 46 | + pop->show(); |
| 47 | + |
| 48 | + return true; |
| 49 | +} |
| 50 | +#endif |
0 commit comments