Skip to content

Commit 1602ff0

Browse files
fix(system): Use CRT command-line arguments
1 parent 377032f commit 1602ff0

2 files changed

Lines changed: 9 additions & 138 deletions

File tree

Core/GameEngine/Source/Common/CommandLine.cpp

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "GameClient/TerrainVisual.h" // for TERRAIN_LOD_MIN definition
3737
#include "GameClient/GameText.h"
3838
#include "GameNetwork/NetworkDefs.h"
39-
#include "WWLib/trim.h"
4039

4140

4241

@@ -481,7 +480,7 @@ Int parseSetCwd(char *args[], int num)
481480
// TheSuperHackers @bugfix CryoTheRenegade 29/08/2026
482481
// -setCwd <path> overrides the working directory.
483482
s_cwdOptionSpecified = TRUE;
484-
if (num <= 1 || args[1] == nullptr)
483+
if (num <= 1 || args[1] == nullptr || args[1][0] == '-' || args[1][0] == '/')
485484
{
486485
rts::setCurrentDirectoryToExecutablePath();
487486
return 1;
@@ -1343,72 +1342,11 @@ static CommandLineParam paramsForEngineInit[] =
13431342

13441343
};
13451344

1346-
char *nextParam(char *newSource, const char *seps)
1347-
{
1348-
static char *source = nullptr;
1349-
if (newSource)
1350-
{
1351-
source = newSource;
1352-
}
1353-
if (!source)
1354-
{
1355-
return nullptr;
1356-
}
1357-
1358-
// find first separator
1359-
char *first = source;//strpbrk(source, seps);
1360-
if (first)
1361-
{
1362-
// go past separator
1363-
char *firstSep = strpbrk(first, seps);
1364-
char firstChar[2] = {0,0};
1365-
if (firstSep == first)
1366-
{
1367-
firstChar[0] = *first;
1368-
while (*first == firstChar[0]) first++;
1369-
}
1370-
1371-
// find end
1372-
char *end;
1373-
if (firstChar[0])
1374-
end = strpbrk(first, firstChar);
1375-
else
1376-
end = strpbrk(first, seps);
1377-
1378-
// trim string & save next start pos
1379-
if (end)
1380-
{
1381-
source = end+1;
1382-
*end = 0;
1383-
1384-
if (!*source)
1385-
source = nullptr;
1386-
}
1387-
else
1388-
{
1389-
source = nullptr;
1390-
}
1391-
1392-
if (first && !*first)
1393-
first = nullptr;
1394-
}
1395-
1396-
return first;
1397-
}
1398-
13991345
static void parseCommandLine(
14001346
const CommandLineParam* params, int numParams, std::vector<Bool> *parsedArguments = nullptr)
14011347
{
1402-
std::vector<char*> argv;
1403-
1404-
std::string cmdLine = GetCommandLineA();
1405-
char *token = nextParam(&cmdLine[0], "\" ");
1406-
while (token != nullptr)
1407-
{
1408-
argv.push_back(strtrim(token));
1409-
token = nextParam(nullptr, "\" ");
1410-
}
1411-
int argc = argv.size();
1348+
const int argc = __argc;
1349+
char **argv = __argv;
14121350
if (parsedArguments != nullptr)
14131351
parsedArguments->assign(argc > 0 ? argc - 1 : 0, FALSE);
14141352

Core/Tools/MapCacheBuilder/Source/WinMain.cpp

Lines changed: 6 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
#include "Win32Device/GameClient/Win32Mouse.h"
104104
#include "Win32Device/Common/Win32LocalFileSystem.h"
105105
#include "Win32Device/Common/Win32BIGFileSystem.h"
106-
#include "WWLib/trim.h"
107106

108107

109108
// DEFINES ////////////////////////////////////////////////////////////////////
@@ -142,65 +141,6 @@ const Char *g_csfFile = "data\\%s\\Generals.csf";
142141
// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
143142
///////////////////////////////////////////////////////////////////////////////
144143

145-
static char *nextParam(char *newSource, const char *seps)
146-
{
147-
static char *source = nullptr;
148-
if (newSource)
149-
{
150-
source = newSource;
151-
}
152-
if (!source)
153-
{
154-
return nullptr;
155-
}
156-
157-
// find first separator
158-
char *first = source;//strpbrk(source, seps);
159-
if (first)
160-
{
161-
// go past initial spaces
162-
char *firstNonSpace = first;
163-
while (*firstNonSpace == ' ')
164-
++firstNonSpace;
165-
first = firstNonSpace;
166-
167-
// go past separator
168-
char *firstSep = strpbrk(first, seps);
169-
char firstChar[2] = {0,0};
170-
if (firstSep == first)
171-
{
172-
firstChar[0] = *first;
173-
while (*first == firstChar[0]) first++;
174-
}
175-
176-
// find end
177-
char *end;
178-
if (firstChar[0])
179-
end = strpbrk(first, firstChar);
180-
else
181-
end = strpbrk(first, seps);
182-
183-
// trim string & save next start pos
184-
if (end)
185-
{
186-
source = end+1;
187-
*end = 0;
188-
189-
if (!*source)
190-
source = nullptr;
191-
}
192-
else
193-
{
194-
source = nullptr;
195-
}
196-
197-
if (first && !*first)
198-
first = nullptr;
199-
}
200-
201-
return first;
202-
}
203-
204144
///////////////////////////////////////////////////////////////////////////////
205145
// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
206146
///////////////////////////////////////////////////////////////////////////////
@@ -223,22 +163,15 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
223163

224164
CommandLine::parseCommandLineForStartup();
225165

226-
/*
227-
** Convert WinMain arguments to simple main argc and argv
228-
*/
166+
// Collect CRT arguments not handled during startup parsing.
229167
std::list<std::string> argvSet;
230-
char *token;
231-
int argIndex = 0;
232-
token = nextParam(lpCmdLine, "\" ");
233-
while (token != nullptr) {
234-
char * str = strtrim(token);
235-
if (!CommandLine::isCommandLineArgumentParsedForStartup(argIndex))
168+
for (int arg = 1; arg < __argc; ++arg)
169+
{
170+
if (!CommandLine::isCommandLineArgumentParsedForStartup(arg - 1))
236171
{
237-
argvSet.push_back(str);
238-
DEBUG_LOG(("Adding '%s'", str));
172+
argvSet.push_back(__argv[arg]);
173+
DEBUG_LOG(("Adding '%s'", __argv[arg]));
239174
}
240-
token = nextParam(nullptr, "\" ");
241-
++argIndex;
242175
}
243176

244177
// not part of the subsystem list, because it should normally never be reset!

0 commit comments

Comments
 (0)