Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
50 changes: 50 additions & 0 deletions src/hooks/MenuLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifdef GEODE_IS_WINDOWS
#include "MenuLayer.hpp"
#include <Geode/cocos/platform/third_party/win32/OGLES/GL/glew.h>

// 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<bool>("has-set-recommended", false);
if (hasSetRecommended) return true;
mod->setSavedValue<bool>("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<int64_t>("history-length", frames);

auto pop = FLAlertLayer::create(
"Rewind",
fmt::format(
"Rewind has automagically detected <cy>{}GB</c> of video memory free, and "
"has set the <cj>max history length</c> to <cy>{}</c>, which can be customised in "
"the <co>mod settings</c>.",
kb / 1000000, frames
).c_str(),
"ok"
);
pop->m_scene = this;
pop->show();

return true;
}
#endif
9 changes: 9 additions & 0 deletions src/hooks/MenuLayer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#ifdef GEODE_IS_WINDOWS
#include <Geode/modify/MenuLayer.hpp>

class $modify(HookedMenuLayer, MenuLayer) {
bool init();
};

#endif
2 changes: 1 addition & 1 deletion src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
fields->m_resolutionMultiplier = geode::Mod::get()->getSettingValue<double>("resolution-multiplier");
}
});
};
}
Loading