* Add support for an options file on Windows.

This commit is contained in:
iProgramInCpp
2023-07-31 18:28:10 +03:00
parent 4853c6e18b
commit 47f9b45ac4
4 changed files with 69 additions and 2 deletions

View File

@@ -12,6 +12,8 @@
#include "thirdparty/stb_image.h"
#include "thirdparty/stb_image_write.h"
#include <fstream>
#include <sstream>
#include <shlobj.h>
extern LPCTSTR g_GameTitle;
@@ -157,8 +159,32 @@ std::vector<std::string> AppPlatform_windows::getOptionStrings()
{
std::vector<std::string> 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;
}

View File

@@ -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<std::string>& strings)
{
for (int i = 0; i<int(strings.size()); i += 2)
@@ -137,5 +155,11 @@ void Options::update(const std::vector<std::string>& 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
}
}

View File

@@ -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

14
windows_vs/options.txt Normal file
View File

@@ -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