summaryrefslogtreecommitdiffstats
path: root/src/core/re3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/re3.cpp')
-rw-r--r--src/core/re3.cpp135
1 files changed, 79 insertions, 56 deletions
diff --git a/src/core/re3.cpp b/src/core/re3.cpp
index fe0347d9..b7d89363 100644
--- a/src/core/re3.cpp
+++ b/src/core/re3.cpp
@@ -41,6 +41,9 @@
#include "Camera.h"
#include "MBlur.h"
#include "ControllerConfig.h"
+#include "CarCtrl.h"
+#include "Population.h"
+#include "IniFile.h"
#ifdef DETECT_JOYSTICK_MENU
#include "crossplatform.h"
@@ -179,16 +182,29 @@ CustomFrontendOptionsPopulate(void)
#endif
#ifdef LOAD_INI_SETTINGS
-#include "ini_parser.hpp"
+#define MINI_CASE_SENSITIVE
+#include "ini.h"
+
+mINI::INIFile ini("re3.ini");
+mINI::INIStructure cfg;
-linb::ini cfg;
bool ReadIniIfExists(const char *cat, const char *key, uint32 *out)
{
- std::string strval = cfg.get(cat, key, "\xBA");
- const char *value = strval.c_str();
- char *endPtr;
- if (value && value[0] != '\xBA') {
- *out = strtoul(value, &endPtr, 0);
+ mINI::INIMap<std::string> section = cfg.get(cat);
+ if (section.has(key)) {
+ char *endPtr;
+ *out = strtoul(section.get(key).c_str(), &endPtr, 0);
+ return true;
+ }
+ return false;
+}
+
+bool ReadIniIfExists(const char *cat, const char *key, uint8 *out)
+{
+ mINI::INIMap<std::string> section = cfg.get(cat);
+ if (section.has(key)) {
+ char *endPtr;
+ *out = strtoul(section.get(key).c_str(), &endPtr, 0);
return true;
}
return false;
@@ -196,11 +212,10 @@ bool ReadIniIfExists(const char *cat, const char *key, uint32 *out)
bool ReadIniIfExists(const char *cat, const char *key, bool *out)
{
- std::string strval = cfg.get(cat, key, "\xBA");
- const char *value = strval.c_str();
- char *endPtr;
- if (value && value[0] != '\xBA') {
- *out = strtoul(value, &endPtr, 0);
+ mINI::INIMap<std::string> section = cfg.get(cat);
+ if (section.has(key)) {
+ char *endPtr;
+ *out = strtoul(section.get(key).c_str(), &endPtr, 0);
return true;
}
return false;
@@ -208,11 +223,10 @@ bool ReadIniIfExists(const char *cat, const char *key, bool *out)
bool ReadIniIfExists(const char *cat, const char *key, int32 *out)
{
- std::string strval = cfg.get(cat, key, "\xBA");
- const char *value = strval.c_str();
- char *endPtr;
- if (value && value[0] != '\xBA') {
- *out = strtol(value, &endPtr, 0);
+ mINI::INIMap<std::string> section = cfg.get(cat);
+ if (section.has(key)) {
+ char *endPtr;
+ *out = strtol(section.get(key).c_str(), &endPtr, 0);
return true;
}
return false;
@@ -220,11 +234,10 @@ bool ReadIniIfExists(const char *cat, const char *key, int32 *out)
bool ReadIniIfExists(const char *cat, const char *key, int8 *out)
{
- std::string strval = cfg.get(cat, key, "\xBA");
- const char *value = strval.c_str();
- char *endPtr;
- if (value && value[0] != '\xBA') {
- *out = strtol(value, &endPtr, 0);
+ mINI::INIMap<std::string> section = cfg.get(cat);
+ if (section.has(key)) {
+ char *endPtr;
+ *out = strtol(section.get(key).c_str(), &endPtr, 0);
return true;
}
return false;
@@ -232,10 +245,10 @@ bool ReadIniIfExists(const char *cat, const char *key, int8 *out)
bool ReadIniIfExists(const char *cat, const char *key, float *out)
{
- std::string strval = cfg.get(cat, key, "\xBA");
- const char *value = strval.c_str();
- if (value && value[0] != '\xBA') {
- *out = atof(value);
+ mINI::INIMap<std::string> section = cfg.get(cat);
+ if (section.has(key)) {
+ char *endPtr;
+ *out = strtof(section.get(key).c_str(), &endPtr);
return true;
}
return false;
@@ -243,10 +256,10 @@ bool ReadIniIfExists(const char *cat, const char *key, float *out)
bool ReadIniIfExists(const char *cat, const char *key, char *out, int size)
{
- std::string strval = cfg.get(cat, key, "\xBA");
- const char *value = strval.c_str();
- if (value && value[0] != '\xBA') {
- strncpy(out, value, size);
+ mINI::INIMap<std::string> section = cfg.get(cat);
+ if (section.has(key)) {
+ strncpy(out, section.get(key).c_str(), size - 1);
+ out[size - 1] = '\0';
return true;
}
return false;
@@ -254,42 +267,42 @@ bool ReadIniIfExists(const char *cat, const char *key, char *out, int size)
void StoreIni(const char *cat, const char *key, uint32 val)
{
- char temp[10];
+ char temp[11];
sprintf(temp, "%u", val);
- cfg.set(cat, key, temp);
+ cfg[cat][key] = temp;
}
void StoreIni(const char *cat, const char *key, uint8 val)
{
- char temp[10];
- sprintf(temp, "%u", (uint32)val);
- cfg.set(cat, key, temp);
+ char temp[11];
+ sprintf(temp, "%u", val);
+ cfg[cat][key] = temp;
}
void StoreIni(const char *cat, const char *key, int32 val)
{
- char temp[10];
+ char temp[11];
sprintf(temp, "%d", val);
- cfg.set(cat, key, temp);
+ cfg[cat][key] = temp;
}
void StoreIni(const char *cat, const char *key, int8 val)
{
- char temp[10];
- sprintf(temp, "%d", (int32)val);
- cfg.set(cat, key, temp);
+ char temp[11];
+ sprintf(temp, "%d", val);
+ cfg[cat][key] = temp;
}
void StoreIni(const char *cat, const char *key, float val)
{
- char temp[10];
+ char temp[50];
sprintf(temp, "%f", val);
- cfg.set(cat, key, temp);
+ cfg[cat][key] = temp;
}
void StoreIni(const char *cat, const char *key, char *val, int size)
{
- cfg.set(cat, key, val);
+ cfg[cat][key] = val;
}
const char *iniControllerActions[] = { "PED_FIREWEAPON", "PED_CYCLE_WEAPON_RIGHT", "PED_CYCLE_WEAPON_LEFT", "GO_FORWARD", "GO_BACK", "GO_LEFT", "GO_RIGHT", "PED_SNIPER_ZOOM_IN",
@@ -351,7 +364,7 @@ void LoadINIControllerSettings()
#endif
// force to default GTA behaviour (never overwrite bindings on joy change/initialization) if user init'ed/set bindings before we introduced that
if (!ReadIniIfExists("Controller", "PadButtonsInited", &ControlsManager.ms_padButtonsInited)) {
- ControlsManager.ms_padButtonsInited = cfg.category_size("Bindings") != 0 ? 16 : 0;
+ ControlsManager.ms_padButtonsInited = cfg.get("Bindings").size() != 0 ? 16 : 0;
}
for (int32 i = 0; i < MAX_CONTROLLERACTIONS; i++) {
@@ -453,12 +466,13 @@ void SaveINIControllerSettings()
#endif
#endif
StoreIni("Controller", "PadButtonsInited", ControlsManager.ms_padButtonsInited);
- cfg.write_file("re3.ini");
+
+ ini.write(cfg);
}
bool LoadINISettings()
{
- if (!cfg.load_file("re3.ini"))
+ if (!ini.read(cfg))
return false;
#ifdef IMPROVED_VIDEOMODE
@@ -524,7 +538,7 @@ bool LoadINISettings()
#endif
#ifdef CUSTOM_FRONTEND_OPTIONS
- bool migrate = cfg.category_size("FrontendOptions") != 0;
+ bool migrate = cfg.get("FrontendOptions").size() != 0;
for (int i = 0; i < MENUPAGES; i++) {
for (int j = 0; j < NUM_MENUROWS; j++) {
CMenuScreenCustom::CMenuEntry &option = aScreens[i].m_aEntries[j];
@@ -533,22 +547,29 @@ bool LoadINISettings()
// CFO check
if (option.m_Action < MENUACTION_NOTHING && option.m_CFO->save) {
- // CFO only supports saving uint8 right now
-
// Migrate from old .ini to new .ini
- if (migrate && ReadIniIfExists("FrontendOptions", option.m_CFO->save, option.m_CFO->value))
- cfg.remove("FrontendOptions", option.m_CFO->save);
+ // Old values can only be int8, new ones can contain float if it is slider
+ if (migrate && ReadIniIfExists("FrontendOptions", option.m_CFO->save, (int8*)option.m_CFO->value))
+ cfg["FrontendOptions"].remove(option.m_CFO->save);
+ else if (option.m_Action == MENUACTION_CFO_SLIDER)
+ ReadIniIfExists(option.m_CFO->saveCat, option.m_CFO->save, (float*)option.m_CFO->value);
else
- ReadIniIfExists(option.m_CFO->saveCat, option.m_CFO->save, option.m_CFO->value);
+ ReadIniIfExists(option.m_CFO->saveCat, option.m_CFO->save, (int8*)option.m_CFO->value);
if (option.m_Action == MENUACTION_CFO_SELECT) {
- option.m_CFOSelect->lastSavedValue = option.m_CFOSelect->displayedValue = *option.m_CFO->value;
+ option.m_CFOSelect->lastSavedValue = option.m_CFOSelect->displayedValue = *(int8*)option.m_CFO->value;
}
}
}
}
#endif
+ // Fetched in above block, but needs evaluation
+#ifdef PED_CAR_DENSITY_SLIDERS
+ CPopulation::MaxNumberOfPedsInUse = DEFAULT_MAX_NUMBER_OF_PEDS * CIniFile::PedNumberMultiplier;
+ CCarCtrl::MaxNumberOfCarsInUse = DEFAULT_MAX_NUMBER_OF_CARS * CIniFile::CarNumberMultiplier;
+#endif
+
return true;
}
@@ -623,14 +644,16 @@ void SaveINISettings()
break;
if (option.m_Action < MENUACTION_NOTHING && option.m_CFO->save) {
- // Beware: CFO only supports saving uint8 right now
- StoreIni(option.m_CFO->saveCat, option.m_CFO->save, *option.m_CFO->value);
+ if (option.m_Action == MENUACTION_CFO_SLIDER)
+ StoreIni(option.m_CFO->saveCat, option.m_CFO->save, *(float*)option.m_CFO->value);
+ else
+ StoreIni(option.m_CFO->saveCat, option.m_CFO->save, *(int8*)option.m_CFO->value);
}
}
}
#endif
- cfg.write_file("re3.ini");
+ ini.write(cfg);
}
#endif