From 47f9b45ac47250f189ec0df5fec8aa14d4b56c49 Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Mon, 31 Jul 2023 18:28:10 +0300 Subject: [PATCH] * Add support for an options file on Windows. --- platforms/windows/AppPlatform_windows.cpp | 30 +++++++++++++++++++++-- source/Options.cpp | 24 ++++++++++++++++++ source/Options.hpp | 3 +++ windows_vs/options.txt | 14 +++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 windows_vs/options.txt diff --git a/platforms/windows/AppPlatform_windows.cpp b/platforms/windows/AppPlatform_windows.cpp index 92ba0ca..baa52e0 100644 --- a/platforms/windows/AppPlatform_windows.cpp +++ b/platforms/windows/AppPlatform_windows.cpp @@ -12,6 +12,8 @@ #include "thirdparty/stb_image.h" #include "thirdparty/stb_image_write.h" +#include +#include #include extern LPCTSTR g_GameTitle; @@ -157,8 +159,32 @@ std::vector AppPlatform_windows::getOptionStrings() { std::vector o; - o.push_back("mp_username"); - o.push_back("iProgramInCpp"); + //o.push_back("mp_username"); + //o.push_back("iProgramInCpp"); + + std::ifstream ifs("options.txt"); + if (!ifs.is_open()) + return o; + + std::string str; + while (true) + { + if (!std::getline(ifs, str, '\n')) + break; + + if (str.empty() || str[0] == '#') + continue; + + std::stringstream ss; + ss << str; + + std::string key, value; + if (std::getline(ss, key, '|') && std::getline(ss, value)) + { + o.push_back(key); + o.push_back(value); + } + } return o; } diff --git a/source/Options.cpp b/source/Options.cpp index 2f7287a..a5aa50c 100644 --- a/source/Options.cpp +++ b/source/Options.cpp @@ -113,6 +113,11 @@ void Options::save() // stub } +std::string Options::getMessage(const Options::Option& option) +{ + return "Options::getMessage - Not implemented"; +} + bool Options::readBool(const std::string& str) { std::string trimmed = Util::stringTrim(str); @@ -120,9 +125,22 @@ bool Options::readBool(const std::string& str) return true; if (trimmed == "false" || trimmed == "0") return false; + return false; } +#ifndef ORIGINAL_CODE +int Options::readInt(const std::string& str) +{ + int f; + + if (!sscanf(str.c_str(), "%d", &f)) + f = 0; + + return f; +} +#endif + void Options::update(const std::vector& strings) { for (int i = 0; i& 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 } } diff --git a/source/Options.hpp b/source/Options.hpp index d582c3d..23065fe 100644 --- a/source/Options.hpp +++ b/source/Options.hpp @@ -26,6 +26,9 @@ public: public: static bool readBool(const std::string& str); +#ifndef ORIGINAL_CODE + static int readInt(const std::string& str); +#endif public: enum KeyBindIndex diff --git a/windows_vs/options.txt b/windows_vs/options.txt new file mode 100644 index 0000000..bf78c30 --- /dev/null +++ b/windows_vs/options.txt @@ -0,0 +1,14 @@ +#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 +gfx_fancygraphics|true +gfx_smoothlighting|false +gfx_viewdistance|2 +#gfx_viewdistance|0