Skip to content

Commit

Permalink
Do not rely on atof() for version detection
Browse files Browse the repository at this point in the history
Removes atof() in the AGI version detection. atof() is locale dependent.
If the user has a locale were the decimal point is something other than
'.' the version detection will fail.

On Linux this can be tested by running:
    LC_NUMERIC="sv_SE.UTF-8" AGIStudio
A 2.917 game will then be detected as a 2.0 game.
  • Loading branch information
agren authored and Deledrius committed Aug 1, 2018
1 parent f45fa3e commit 567772d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
20 changes: 10 additions & 10 deletions src/agicommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,28 +240,28 @@ CommandStruct AGICommand[182] = {

int NumAGICommands = 181; // not counting return()

void CorrectCommands(double VerNum)
void CorrectCommands(long VerNum)
{
if (VerNum <= 2.089) {
if (VerNum <= 2089000) {
AGICommand[134].NumArgs = 0; //quit
}
if (VerNum < 2.400) {
if (VerNum < 2400000) {
AGICommand[151].NumArgs = 3; // print.at
AGICommand[152].NumArgs = 3; // print.at.v
}
if (VerNum <= 3.002086)
if (VerNum <= 3002086)
AGICommand[176].NumArgs = 1;
if (VerNum <= 2.089)
if (VerNum <= 2089000)
NumAGICommands = 155;
else if (VerNum <= 2.272)
else if (VerNum <= 2272000)
NumAGICommands = 161;
else if (VerNum <= 2.440)
else if (VerNum <= 2440000)
NumAGICommands = 169;
else if (VerNum <= 2.917)
else if (VerNum <= 2917000)
NumAGICommands = 173;
else if (VerNum <= 2.936)
else if (VerNum <= 2936000)
NumAGICommands = 175;
else if (VerNum <= 3.002086)
else if (VerNum <= 3002086)
NumAGICommands = 177;
else
NumAGICommands = 181;
Expand Down
2 changes: 1 addition & 1 deletion src/agicommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ extern CommandStruct TestCommand[19]; //tests for different flags, etc
extern CommandStruct AGICommand[182]; //all the other


extern void CorrectCommands(double VerNum);
extern void CorrectCommands(long VerNum);

#endif
24 changes: 12 additions & 12 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ int Game::open(std::string name)

if (!ErrorOccured) {
AGIVersionNumber = GetAGIVersionNumber();
//printf("AGIVersion = %f\n",AGIVersionNumber);
//printf("AGIVersion = %lu\n",AGIVersionNumber);
CorrectCommands(AGIVersionNumber);
isOpen = true;
make_source_dir();
Expand Down Expand Up @@ -388,7 +388,7 @@ int Game::newgame(std::string name)
isOpen = true;
isV3 = false;
ID = "";
AGIVersionNumber = 2.917;
AGIVersionNumber = 2917000;
for (int _i = 0; _i <= 3; _i++) {
for (j = 0; j <= 255; j++)
ResourceInfo[_i][j].Exists = false;
Expand Down Expand Up @@ -478,16 +478,15 @@ std::string Game::FindAGIV3GameID(const char *name)
}

//*******************************************************
double Game::GetAGIVersionNumber(void)
long Game::GetAGIVersionNumber(void)
{
double VerNum;
int ResPos, x;
byte VerLen;
bool ISVerNum;
char VerNumText[16];
long VerNum;
std::string InFileName = dir + "/agidata.ovl";
char VersionNumBuffer[] = "A_CDE_GHI";
double ret = 2.917;
int ret = 2917000;
// This is what we use if we can't find the version number.
// Version 2.917 is the most common interpreter and
// the one that all the "new" AGI games should be based on.
Expand Down Expand Up @@ -532,14 +531,15 @@ double Game::GetAGIVersionNumber(void)
} else
ISVerNum = false;
if (VerLen > 0) {
VerNum = (VersionNumBuffer[0] - '0') * 1000000;
VerNum += (VersionNumBuffer[2] - '0') * 100000;
VerNum += (VersionNumBuffer[3] - '0') * 10000;
VerNum += (VersionNumBuffer[4] - '0') * 1000;
if (VersionNumBuffer[5] == '.') {
strcpy(VerNumText, VersionNumBuffer);
strcpy(VerNumText + 5, VersionNumBuffer + 6); // remove second .
} else {
strncpy(VerNumText, VersionNumBuffer, VerLen);
VerNumText[VerLen] = 0;
VerNum += (VersionNumBuffer[6] - '0') * 100;
VerNum += (VersionNumBuffer[7] - '0') * 10;
VerNum += (VersionNumBuffer[8] - '0');
}
VerNum = atof(VerNumText);
if (VerNum != 0) {
ret = VerNum;
break;
Expand Down
4 changes: 2 additions & 2 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class Game
std::string templatedir; //template game directory
std::string helpdir; //help directory
private:
double AGIVersionNumber;
long AGIVersionNumber;
std::string FindAGIV3GameID(const char *name);
double GetAGIVersionNumber(void);
long GetAGIVersionNumber(void);
int ReadV3Resource(char ResourceType, int ResourceID);
FILE *OpenPatchVol(int PatchVol, int *filesize);
FILE *OpenDirUpdate(int *dirsize, int ResType);
Expand Down

0 comments on commit 567772d

Please sign in to comment.