From 9ef72164bb760caec0c8e4a1874e0de98cdf2a35 Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Sun, 6 Aug 2023 22:21:18 +0300 Subject: [PATCH] * Add writeable configuration. --- platforms/windows/AppPlatform_windows.cpp | 12 +++++++++ platforms/windows/AppPlatform_windows.hpp | 3 +++ platforms/windows/main.cpp | 2 ++ source/AppPlatform.cpp | 4 +++ source/AppPlatform.hpp | 4 ++- source/Minecraft.cpp | 5 ++++ source/Minecraft.hpp | 1 + source/client/common/Options.cpp | 32 ++++++++++++++++++++--- source/client/common/Options.hpp | 5 ++-- windows_vs/options.txt | 12 +++------ 10 files changed, 64 insertions(+), 16 deletions(-) diff --git a/platforms/windows/AppPlatform_windows.cpp b/platforms/windows/AppPlatform_windows.cpp index a2c73f2..85675c5 100644 --- a/platforms/windows/AppPlatform_windows.cpp +++ b/platforms/windows/AppPlatform_windows.cpp @@ -209,6 +209,18 @@ std::vector AppPlatform_windows::getOptionStrings() return o; } +void AppPlatform_windows::setOptionStrings(const std::vector& str) +{ + assert(str.size() % 2 == 0); + + std::ofstream os("options.txt"); + + os << "#Config file for Minecraft PE. The # at the start denotes a comment, removing it makes it a command.\n\n"; + + for (int i = 0; i < int(str.size()); i += 2) + os << str[i] << '|' << str[i + 1] << '\n'; +} + void AppPlatform_windows::setScreenSize(int width, int height) { m_ScreenWidth = width; diff --git a/platforms/windows/AppPlatform_windows.hpp b/platforms/windows/AppPlatform_windows.hpp index c91c09a..01387fb 100644 --- a/platforms/windows/AppPlatform_windows.hpp +++ b/platforms/windows/AppPlatform_windows.hpp @@ -47,6 +47,9 @@ public: // Also add these to allow proper text input within the game. bool shiftPressed() override; void setShiftPressed(bool b); + + // Also add these to allow saving options. + void setOptionStrings(const std::vector & str) override; void setScreenSize(int width, int height); diff --git a/platforms/windows/main.cpp b/platforms/windows/main.cpp index b616cab..c43a134 100644 --- a/platforms/windows/main.cpp +++ b/platforms/windows/main.cpp @@ -276,6 +276,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLin } _cleanup: + g_pApp->saveOptions(); + // disable OpenGL for the window DisableOpenGL(hWnd, hDC, hRC); diff --git a/source/AppPlatform.cpp b/source/AppPlatform.cpp index 5cdda46..0ea9f3f 100644 --- a/source/AppPlatform.cpp +++ b/source/AppPlatform.cpp @@ -122,3 +122,7 @@ bool AppPlatform::shiftPressed() { return false; } + +void AppPlatform::setOptionStrings(const std::vector& vec) +{ +} diff --git a/source/AppPlatform.hpp b/source/AppPlatform.hpp index 487e836..d836b3a 100644 --- a/source/AppPlatform.hpp +++ b/source/AppPlatform.hpp @@ -39,7 +39,7 @@ public: virtual void showDialog(eDialogType); virtual void uploadPlatformDependentData(int, void*); virtual Texture loadTexture(const std::string&, bool); - virtual std::vector getOptionStrings(); + virtual std::vector getOptionStrings(); #ifndef ORIGINAL_CODE // Also add these to allow proper turning within the game. @@ -50,6 +50,8 @@ public: virtual void updateFocused(bool focused); // Also add this to allow proper text input within the game. virtual bool shiftPressed(); + // Also add this to allow option saving. + virtual void setOptionStrings(const std::vector& vec); #endif diff --git a/source/Minecraft.cpp b/source/Minecraft.cpp index fc82561..8d8f778 100644 --- a/source/Minecraft.cpp +++ b/source/Minecraft.cpp @@ -152,6 +152,11 @@ void Minecraft::reloadOptions() m_pUser->field_0 = m_options.m_playerName; } +void Minecraft::saveOptions() +{ + platform()->setOptionStrings(m_options.getOptionStrings()); +} + bool Minecraft::isLevelGenerated() { if (m_pLevel) diff --git a/source/Minecraft.hpp b/source/Minecraft.hpp index f070851..3e56f7d 100644 --- a/source/Minecraft.hpp +++ b/source/Minecraft.hpp @@ -41,6 +41,7 @@ public: void tick(); void tickInput(); void reloadOptions(); + void saveOptions(); void handleMouseClick(int type); void handleMouseDown(int type, bool b); bool isLevelGenerated(); diff --git a/source/client/common/Options.cpp b/source/client/common/Options.cpp index 91bea63..e8a4ba9 100644 --- a/source/client/common/Options.cpp +++ b/source/client/common/Options.cpp @@ -133,7 +133,6 @@ bool Options::readBool(const std::string& str) return false; } -#ifndef ORIGINAL_CODE int Options::readInt(const std::string& str) { int f; @@ -143,7 +142,18 @@ int Options::readInt(const std::string& str) return f; } -#endif + +std::string Options::saveBool(bool b) +{ + return b ? "true" : "false"; +} + +std::string Options::saveInt(int i) +{ + std::stringstream ss; + ss << i; + return ss.str(); +} void Options::update(const std::vector& strings) { @@ -159,11 +169,25 @@ void Options::update(const std::vector& strings) m_bFancyGraphics = readBool(value); else if (key == "mp_server_visible_default") m_bServerVisibleDefault = readBool(value); -#ifndef ORIGINAL_CODE else if (key == "gfx_smoothlighting") Minecraft::useAmbientOcclusion = field_18 = readBool(value); else if (key == "gfx_viewdistance") field_10 = readInt(value); -#endif } } + +std::vector Options::getOptionStrings() +{ + std::vector vec; + +#define SO(optname, value) do { vec.push_back(optname); vec.push_back(value); } while (0) + + SO("mp_username", m_playerName); + SO("ctrl_invertmouse", saveBool(m_bInvertMouse)); + SO("gfx_fancygraphics", saveBool(m_bFancyGraphics)); + SO("mp_server_visible_default", saveBool(m_bServerVisibleDefault)); + SO("gfx_smoothlighting", saveBool(field_18)); + SO("gfx_viewdistance", saveInt (field_10)); + + return vec; +} diff --git a/source/client/common/Options.hpp b/source/client/common/Options.hpp index 23065fe..e3974cf 100644 --- a/source/client/common/Options.hpp +++ b/source/client/common/Options.hpp @@ -23,12 +23,13 @@ public: void save(); std::string getMessage(const Options::Option&); void update(const std::vector& string); + std::vector getOptionStrings(); public: static bool readBool(const std::string& str); -#ifndef ORIGINAL_CODE static int readInt(const std::string& str); -#endif + static std::string saveBool(bool b); + static std::string saveInt(int i); public: enum KeyBindIndex diff --git a/windows_vs/options.txt b/windows_vs/options.txt index bf78c30..3e1ff83 100644 --- a/windows_vs/options.txt +++ b/windows_vs/options.txt @@ -1,14 +1,8 @@ #Config file for Minecraft PE. The # at the start denotes a comment, removing it makes it a command. -# Multiplayer mp_username|ReMinecraftPE -mp_server_visible_default|true - -# Controls -#ctrl_invertmouse|true - -# Graphics Options +ctrl_invertmouse|false gfx_fancygraphics|true -gfx_smoothlighting|false +mp_server_visible_default|true +gfx_smoothlighting|true gfx_viewdistance|2 -#gfx_viewdistance|0