- Added Freeze Time

This commit is contained in:
EricPlayZ
2024-02-06 03:30:41 +02:00
parent 675eb58988
commit 9bd867bc9f
11 changed files with 93 additions and 23 deletions

View File

@ -27,6 +27,8 @@ static LRESULT __stdcall hkWindowProc(_In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARA
for (auto& option : *KeyBindOption::GetInstances()) {
if (option->GetChangesAreDisabled())
continue;
if (option->GetKeyBind() == VK_NONE)
continue;
if (wParam == option->GetKeyBind()) {
KeyBindOption::wasAnyKeyPressed = true;

View File

@ -20,6 +20,8 @@ namespace Config {
int code;
};
static constexpr auto virtualKeyCodes = std::to_array<VKey>({
{ "VK_NONE", VK_NONE },
// Function keys
{ "VK_F1", VK_F1 },
{ "VK_F2", VK_F2 },
@ -4032,6 +4034,7 @@ namespace Config {
{ "Menu:Keybinds", "ThirdPersonToggleKey", std::string("VK_F1"), &Menu::Camera::thirdPersonCamera, String},
{ "Menu:Keybinds", "UseTPPModelToggleKey", std::string("VK_F2"), &Menu::Camera::tpUseTPPModel, String},
{ "Menu:Keybinds", "DisableHUDToggleKey", std::string("VK_F8"), &Menu::Misc::disableHUD, String},
{ "Menu:Keybinds", "FreezeTimeToggleKey", std::string("VK_NONE"), &Menu::World::freezeTime, String},
{ "Player:Misc", "GodMode", false, &Menu::Player::godMode, OPTION },
{ "Player:Misc", "DisableOutOfBoundsTimer", true, &Menu::Player::disableOutOfBoundsTimer, OPTION },
{ "Player:Misc", "NightrunnerMode", false, &Menu::Player::nightrunnerMode, OPTION },

View File

@ -167,8 +167,11 @@ namespace Core {
void Cleanup() {
exiting = true;
PrintInfo("Game request exit, running cleanup");
PrintInfo("Saving config to file");
Config::SaveConfig();
PrintInfo("Unhooking everything");
MH_DisableHook(MH_ALL_HOOKS);
MH_Uninitialize();
}

View File

@ -10,7 +10,7 @@
#define MOD_VERSION_STR "v1.1.0"
#define GAME_VER_COMPAT_STR ">= v1.14.0"
#define GAME_VER_COMPAT 11401
#define GAME_VER_COMPAT 11400
#define VK_NONE -1
#define VK_MWHEELDOWN 0x100

View File

@ -56,8 +56,6 @@ namespace Hook {
void HookLoop() override {
while (true) {
Sleep(250);
if (!pGetOffsetFunc)
continue;
@ -67,6 +65,8 @@ namespace Hook {
MH_EnableHook(pTarget);
break;
}
Sleep(250);
}
}
@ -83,8 +83,6 @@ namespace Hook {
void HookLoop() override {
while (true) {
Sleep(250);
if (!pGetOffsetFunc)
continue;
@ -94,6 +92,8 @@ namespace Hook {
Hook::HookVT(pInstance, pDetour, reinterpret_cast<LPVOID*>(&pOriginal), offset);
break;
}
Sleep(250);
}
}

View File

@ -45,7 +45,7 @@ namespace Menu {
ImGui::TextCentered(gameCompat.c_str());
const std::string gameVer = "The game version you are currently running is v" + GamePH::GetCurrentGameVersionStr() + ".";
ImGui::TextCentered(gameVer.c_str());
const std::string gameTestedVer = "This mod has been tested with version v" + GamePH::GameVerToStr(GAME_VER_COMPAT) + ".";
const std::string gameTestedVer = "This mod has been last tested with version v" + GamePH::GameVerToStr(GAME_VER_COMPAT) + ".";
ImGui::TextCentered(gameTestedVer.c_str());
if (GamePH::GetCurrentGameVersion() < 11400 || GamePH::GetCurrentGameVersion() > GAME_VER_COMPAT) {
const std::string gameNotCompat = "Please note that your game version has not been officially tested with this mod, therefore expect bugs, glitches or the mod to completely stop working. If so, please " + std::string(GamePH::GetCurrentGameVersion() > GAME_VER_COMPAT ? "wait for a new patch." : "upgrade your game version to one that the mod supports.");
@ -122,7 +122,7 @@ namespace Menu {
maxWndSize = defMaxWndSize * scale;
ImGui::SetNextWindowSizeConstraints(minWndSize, maxWndSize);
ImGui::Begin("EGameTools", &menuToggle.value, windowFlags); {
ImGui::Begin(std::string("EGameTools " + std::string(MOD_VERSION_STR)).c_str(), &menuToggle.value, windowFlags); {
if (ImGui::BeginTabBar("##MainTabBar")) {
for (auto& tab : *MenuTab::GetInstances()) {
if (ImGui::BeginTabItem(tab.second->tabName.data())) {

View File

@ -6080,13 +6080,13 @@ namespace Menu {
std::ofstream outFile(std::string(saveSCRPath) + "\\player_variables.scr", std::ios::binary);
if (!outFile.is_open()) {
ImGui::OpenPopup("Failed saving.");
ImGui::OpenPopup("Failed saving player variables.");
return;
}
outFile << tempPlayerVarsSCR;
outFile.close();
ImGui::OpenPopup("Saved!");
ImGui::OpenPopup("Saved player variables!");
}
static void LoadPlayerVariablesSCR() {
if (!std::filesystem::exists(loadSCRFilePath))
@ -6094,7 +6094,7 @@ namespace Menu {
std::ifstream file(loadSCRFilePath);
if (!file.is_open()) {
ImGui::OpenPopup("Failed loading.");
ImGui::OpenPopup("Failed loading player variables.");
return;
}
@ -6111,7 +6111,7 @@ namespace Menu {
}
file.close();
ImGui::OpenPopup("Loaded!");
ImGui::OpenPopup("Loaded player variables!");
}
static void RestoreVariablesToDefault() {
@ -6300,8 +6300,11 @@ namespace Menu {
ImGui::SeparatorText("Player Jump Parameters");
if (ImGui::Button("Reload Jump Params")) {
GamePH::ReloadJumps();
ImGui::OpenPopup("Reloaded player jump parameters!");
if (Utils::FileExistsInDir("jump_parameters.scr", "EGameTools\\FilesToLoad")) {
GamePH::ReloadJumps();
ImGui::OpenPopup("Reloaded player jump parameters!");
} else
ImGui::OpenPopup("Failed reloading player jump parameters.");
}
ImGui::SeparatorText("Player Variables");
@ -6401,31 +6404,37 @@ namespace Menu {
}
ImGuiFileDialog::Instance()->Close();
}
if (ImGui::BeginPopupModal("Reloaded player jump parameters!", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("Player jump parameters have been reloaded from \"jump_parameters.scr\" located inside the \"EGameTools\\FilesToLoad\" folder!");
if (ImGui::BeginPopupModal("Failed reloading player jump parameters.", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("Could not find any \"jump_parameters.scr\" inside \"EGameTools\\FilesToLoad\"! Please make sure a \"jump_parameters.scr\" file is present in the directory mentioned earlier.");
if (ImGui::Button("OK", ImVec2(120.0f, 0.0f)))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
if (ImGui::BeginPopupModal("Failed saving.", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::BeginPopupModal("Reloaded player jump parameters!", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("Player jump parameters have been reloaded! from \"EGameTools\\FilesToLoad\"");
if (ImGui::Button("OK", ImVec2(120.0f, 0.0f)))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
if (ImGui::BeginPopupModal("Failed saving player variables.", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("There was an error opening a handle to the file \"%s\\player_variables.scr\"! The file is most likely already open in another program. Please close it!", saveSCRPath.c_str());
if (ImGui::Button("OK", ImVec2(120.0f, 0.0f)))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
if (ImGui::BeginPopupModal("Saved!", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::BeginPopupModal("Saved player variables!", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("Player variables have been saved to \"%s\\player_variables.scr\"!", saveSCRPath.c_str());
if (ImGui::Button("OK", ImVec2(120.0f, 0.0f)))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
if (ImGui::BeginPopupModal("Failed loading.", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::BeginPopupModal("Failed loading player variables.", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("There was an error opening the file \"%s\"! The file is most likely already open in another program. Please close it!", loadSCRFilePath.c_str());
if (ImGui::Button("OK", ImVec2(120.0f, 0.0f)))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
if (ImGui::BeginPopupModal("Loaded!", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
if (ImGui::BeginPopupModal("Loaded player variables!", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
ImGui::Text("Player variables have been loaded from \"%s\"!", loadSCRFilePath.c_str());
if (ImGui::Button("OK", ImVec2(120.0f, 0.0f)))
ImGui::CloseCurrentPopup();

View File

@ -1,3 +1,5 @@
#include <Hotkey.h>
#include <ImGuiEx.h>
#include <imgui.h>
#include "..\game_classes.h"
#include "world.h"
@ -5,6 +7,8 @@
namespace Menu {
namespace World {
float time = 0.0f;
static float timeBeforeFreeze = 0.0f;
KeyBindOption freezeTime{ VK_NONE };
EWeather::TYPE weather = EWeather::TYPE::Default;
static const char* const weatherItems[7] = {
@ -18,16 +22,56 @@ namespace Menu {
};
Tab Tab::instance{};
void Tab::Update() {}
void Tab::Update() {
GamePH::DayNightCycle* dayNightCycle = GamePH::DayNightCycle::Get();
if (!dayNightCycle)
return;
GamePH::LevelDI* iLevel = GamePH::LevelDI::Get();
if (!iLevel || !iLevel->IsLoaded())
return;
if (freezeTime.HasChangedTo(true)) {
timeBeforeFreeze = time;
freezeTime.SetPrevValue(true);
}
if (!menuToggle.GetValue()) {
if (!freezeTime.GetValue()) {
if (freezeTime.HasChangedTo(false)) {
dayNightCycle->SetDaytime(time);
freezeTime.SetPrevValue(false);
}
time = dayNightCycle->time1 * 24;
} else if (!Utils::are_same(time, timeBeforeFreeze))
dayNightCycle->SetDaytime(timeBeforeFreeze);
}
}
void Tab::Render() {
GamePH::DayNightCycle* dayNightCycle = GamePH::DayNightCycle::Get();
GamePH::LevelDI* iLevel = GamePH::LevelDI::Get();
ImGui::SeparatorText("Misc##World");
ImGui::BeginDisabled(!iLevel || !iLevel->IsLoaded() || !dayNightCycle || dayNightCycle->time1 == 0.0f); {
static bool sliderBeingPressed = false;
if (ImGui::SliderFloat("Time", &time, 0.01f, 24.0f, "%.2f", ImGuiSliderFlags_AlwaysClamp) && dayNightCycle)
dayNightCycle->SetDaytime(time);
else if (dayNightCycle)
time = dayNightCycle->time1 * 24;
sliderBeingPressed = true;
else if (dayNightCycle) {
if (sliderBeingPressed) {
sliderBeingPressed = false;
timeBeforeFreeze = time;
dayNightCycle->SetDaytime(time);
}
if (!freezeTime.GetValue()) {
if (freezeTime.HasChangedTo(false)) {
dayNightCycle->SetDaytime(timeBeforeFreeze);
freezeTime.SetPrevValue(false);
}
time = dayNightCycle->time1 * 24;
} else if (!Utils::are_same(time, timeBeforeFreeze))
dayNightCycle->SetDaytime(timeBeforeFreeze);
}
ImGui::Checkbox("Freeze Time", &freezeTime);
ImGui::Hotkey("##FreezeTimeToggleKey", freezeTime);
ImGui::EndDisabled();
}

View File

@ -5,6 +5,7 @@
namespace Menu {
namespace World {
extern float time;
extern KeyBindOption freezeTime;
extern EWeather::TYPE weather;

View File

@ -80,6 +80,13 @@ namespace Utils {
GetModuleFileNameA(nullptr, buffer, sizeof(buffer));
return std::filesystem::path(buffer).parent_path().string();
}
bool FileExistsInDir(const char* fileName, const char* dir) {
for (const auto& entry : std::filesystem::directory_iterator(dir)) {
if (entry.path().filename().string() == fileName)
return true;
}
return false;
}
WindowsVersion GetWindowsVersion() {
OSVERSIONINFOEX info{};
DWORDLONG dwlConditionMask = 0;

View File

@ -41,5 +41,6 @@ namespace Utils {
extern std::string_view GetDesktopDir();
extern std::string_view GetDocumentsDir();
extern std::string GetCurrentProcDirectory();
extern bool FileExistsInDir(const char* fileName, const char* dir);
extern WindowsVersion GetWindowsVersion();
}