mirror of
https://github.com/1dot13/source.git
synced 2026-07-22 13:40:22 +02:00
Improved Game Settings (by Arynn)
- fixed corruption of ja2.set - ja2.set will no be saved to ja2_settings.ini - a few more minor game setting fixes and error tracings git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@2844 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
+148
-8
@@ -8,6 +8,8 @@
|
||||
#include <string.h>
|
||||
#include <sstream>
|
||||
|
||||
#include <float.h> //limits for float/double vars ie. DBL_MAX FLT_MAX
|
||||
|
||||
// Kaiden: INI reading function definitions:
|
||||
|
||||
std::stack<std::string> iniErrorMessages;
|
||||
@@ -25,6 +27,35 @@ CIniReader::CIniReader(const STR8 szFileName)
|
||||
}
|
||||
}
|
||||
|
||||
CIniReader::CIniReader(const STR8 szFileName, BOOL Force_Custom_Data_Path)
|
||||
{
|
||||
// ary-05/05/2009 : force custom data path for potential non existing file -or- force default data path
|
||||
// : Also, flag file detection to allow functions to determine course of action for case of file [not found/is found].
|
||||
if ( Force_Custom_Data_Path )
|
||||
{
|
||||
if ( gCustomDataCat.FindFile(szFileName) )
|
||||
{
|
||||
CIniReader_File_Found = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
CIniReader_File_Found = FALSE;
|
||||
}
|
||||
sprintf(m_szFileName, "%s\\%s", gCustomDataCat.GetRootDir().c_str(), szFileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( gDefaultDataCat.FindFile(szFileName) )
|
||||
{
|
||||
CIniReader_File_Found = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
CIniReader_File_Found = FALSE;
|
||||
}
|
||||
sprintf(m_szFileName, "%s\\%s", gDefaultDataCat.GetRootDir().c_str(), szFileName);
|
||||
}
|
||||
}
|
||||
|
||||
int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int iDefaultValue)
|
||||
{
|
||||
@@ -40,14 +71,14 @@ int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int defaultV
|
||||
if (iniValueReadFromFile < minValue) {
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value of the .ini setting " << szKey << "(" << iniValueReadFromFile
|
||||
<< ") is outsize the valid range of " << minValue << " to " << maxValue
|
||||
<< ") is outside the valid range of " << minValue << " to " << maxValue
|
||||
<< ". " << minValue << " will be used.";
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
return minValue;
|
||||
} else if (iniValueReadFromFile > maxValue) {
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value of the .ini setting " << szKey << "(" << iniValueReadFromFile
|
||||
<< ") is outsize the valid range of " << minValue << " to " << maxValue
|
||||
<< ") is outside the valid range of " << minValue << " to " << maxValue
|
||||
<< ". " << maxValue << " will be used.";
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
return maxValue;
|
||||
@@ -68,27 +99,30 @@ int CIniReader::ReadInteger(const STR8 szSection, const STR8 szKey, int defaultV
|
||||
// return fltResult;
|
||||
//}
|
||||
|
||||
double CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, double defaultValue, double minValue, double maxValue)
|
||||
DOUBLE CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, DOUBLE defaultValue, DOUBLE minValue, DOUBLE maxValue)
|
||||
{
|
||||
char szResult[255];
|
||||
char szDefault[255];
|
||||
double iniValueReadFromFile;
|
||||
DOUBLE iniValueReadFromFile;
|
||||
|
||||
sprintf(szDefault, "%f", defaultValue);
|
||||
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
|
||||
iniValueReadFromFile = (float) atof(szResult);
|
||||
iniValueReadFromFile = strtod(szResult, NULL);
|
||||
|
||||
//AssertGE(iniValueReadFromFile, minValue);
|
||||
//AssertLE(iniValueReadFromFile, maxValue);
|
||||
|
||||
if (iniValueReadFromFile < minValue) {
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value of the .ini setting " << szKey << "(" << iniValueReadFromFile
|
||||
<< ") is outsize the valid range of " << minValue << " to " << maxValue
|
||||
<< ") is outside the valid range of " << minValue << " to " << maxValue
|
||||
<< ". " << minValue << " will be used.";
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
return minValue;
|
||||
} else if (iniValueReadFromFile > maxValue) {
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value of the .ini setting " << szKey << "(" << iniValueReadFromFile
|
||||
<< ") is outsize the valid range of " << minValue << " to " << maxValue
|
||||
<< ") is outside the valid range of " << minValue << " to " << maxValue
|
||||
<< ". " << maxValue << " will be used.";
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
return maxValue;
|
||||
@@ -96,8 +130,38 @@ double CIniReader::ReadDouble(const STR8 szSection, const STR8 szKey, double def
|
||||
return iniValueReadFromFile;
|
||||
}
|
||||
|
||||
FLOAT CIniReader::ReadFloat(const STR8 szSection, const STR8 szKey, FLOAT defaultValue, FLOAT minValue, FLOAT maxValue)
|
||||
{
|
||||
char szResult[255];
|
||||
char szDefault[255];
|
||||
FLOAT iniValueReadFromFile;
|
||||
|
||||
bool CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, bool defaultValue)
|
||||
sprintf(szDefault, "%f", defaultValue);
|
||||
GetPrivateProfileString(szSection, szKey, szDefault, szResult, 255, m_szFileName);
|
||||
iniValueReadFromFile = (FLOAT) atof(szResult);
|
||||
|
||||
//AssertGE(iniValueReadFromFile, minValue);
|
||||
//AssertLE(iniValueReadFromFile, maxValue);
|
||||
|
||||
if (iniValueReadFromFile < minValue) {
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value of the .ini setting " << szKey << "(" << iniValueReadFromFile
|
||||
<< ") is outside the valid range of " << minValue << " to " << maxValue
|
||||
<< ". " << minValue << " will be used.";
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
return minValue;
|
||||
} else if (iniValueReadFromFile > maxValue) {
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value of the .ini setting " << szKey << "(" << iniValueReadFromFile
|
||||
<< ") is outside the valid range of " << minValue << " to " << maxValue
|
||||
<< ". " << maxValue << " will be used.";
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
return maxValue;
|
||||
}
|
||||
return iniValueReadFromFile;
|
||||
}
|
||||
|
||||
BOOL CIniReader::ReadBoolean(const STR8 szSection, const STR8 szKey, BOOL defaultValue)
|
||||
{
|
||||
char szResult[255];
|
||||
char szDefault[255];
|
||||
@@ -119,7 +183,83 @@ STR8 CIniReader::ReadString(const STR8 szSection, const STR8 szKey, const STR8 s
|
||||
|
||||
|
||||
|
||||
UINT8 CIniReader::ReadUINT8(const STR8 szSection, const STR8 szKey, UINT8 defaultValue, UINT8 minValue, UINT8 maxValue)
|
||||
{
|
||||
|
||||
UINT8 iniValueReadFromFile;
|
||||
|
||||
iniValueReadFromFile = (UINT8) this->ReadUINT( szSection, szKey, (UINT32) defaultValue, (UINT32) minValue, (UINT32) maxValue);
|
||||
|
||||
return iniValueReadFromFile;
|
||||
|
||||
}
|
||||
|
||||
UINT16 CIniReader::ReadUINT16(const STR8 szSection, const STR8 szKey, UINT16 defaultValue, UINT16 minValue, UINT16 maxValue)
|
||||
{
|
||||
|
||||
UINT16 iniValueReadFromFile;
|
||||
|
||||
iniValueReadFromFile = (UINT16) this->ReadUINT( szSection, szKey, (UINT32) defaultValue, (UINT32) minValue, (UINT32) maxValue);
|
||||
|
||||
return iniValueReadFromFile;
|
||||
|
||||
}
|
||||
|
||||
UINT32 CIniReader::ReadUINT32(const STR8 szSection, const STR8 szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue)
|
||||
{
|
||||
|
||||
UINT32 iniValueReadFromFile;
|
||||
|
||||
iniValueReadFromFile = (UINT32) this->ReadUINT( szSection, szKey, (UINT32) defaultValue, (UINT32) minValue, (UINT32) maxValue);
|
||||
|
||||
return iniValueReadFromFile;
|
||||
|
||||
}
|
||||
|
||||
UINT32 CIniReader::ReadUINT(const STR8 szSection, const STR8 szKey, UINT32 defaultValue, UINT32 minValue, UINT32 maxValue )
|
||||
{
|
||||
UINT32 iniValueReadFromFile;
|
||||
|
||||
STR8 szResult = new char[255];
|
||||
STR8 szDefault = new char[255];
|
||||
|
||||
memset(szResult, 0x00, 255);
|
||||
memset(szDefault, 0x00, 255);
|
||||
|
||||
sprintf(szDefault, "%u", defaultValue);
|
||||
|
||||
sprintf_s( szResult , (size_t) 255 , "%s", this->ReadString (szSection , szKey , szDefault ));
|
||||
iniValueReadFromFile = (UINT32) strtoul(szResult,NULL,0);
|
||||
|
||||
//AssertGE(iniValueReadFromFile, minValue);
|
||||
//AssertLE(iniValueReadFromFile, maxValue);
|
||||
|
||||
if (iniValueReadFromFile < minValue)
|
||||
{
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value of the .ini setting " << szKey << "(" << iniValueReadFromFile
|
||||
<< ") is outside the valid range of " << minValue << " to " << maxValue
|
||||
<< ". " << minValue << " will be used.";
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
iniValueReadFromFile = minValue;
|
||||
}
|
||||
else if (iniValueReadFromFile > maxValue)
|
||||
{
|
||||
std::stringstream errMessage;
|
||||
errMessage << "The value of the .ini setting " << szKey << "(" << iniValueReadFromFile
|
||||
<< ") is outside the valid range of " << minValue << " to " << maxValue
|
||||
<< ". " << maxValue << " will be used.";
|
||||
iniErrorMessages.push(errMessage.str());
|
||||
iniValueReadFromFile = maxValue;
|
||||
}
|
||||
|
||||
|
||||
delete [] szResult ;
|
||||
delete [] szDefault ;
|
||||
|
||||
return iniValueReadFromFile;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user