* BugFix: Correct $i and %i interchangeably being used in parseArgs.tscript.

This commit is contained in:
Robert MacGregor 2021-08-20 20:38:24 -04:00
parent 1b54162580
commit 452ef71274

View file

@ -43,11 +43,11 @@ function popFront(%list, %delim)
function parseArgs() function parseArgs()
{ {
for ($i = 1; $i < $Game::argc ; $i++) for (%i = 1; %i < $Game::argc ; %i++)
{ {
$arg = $Game::argv[$i]; $arg = $Game::argv[%i];
$nextArg = $Game::argv[$i+1]; $nextArg = $Game::argv[%i+1];
$hasNextArg = $Game::argc - $i > 1; $hasNextArg = $Game::argc - %i > 1;
$logModeSpecified = false; $logModeSpecified = false;
// Check for dedicated run // Check for dedicated run
@ -55,7 +55,7 @@ function parseArgs()
{ {
$userDirs = $defaultGame; $userDirs = $defaultGame;
$dirCount = 1; $dirCount = 1;
$isDedicated = true; %isDedicated = true;
}*/ }*/
switch$ ($arg) switch$ ($arg)
@ -64,31 +64,31 @@ function parseArgs()
case "-dedicated": case "-dedicated":
$userDirs = $defaultGame; $userDirs = $defaultGame;
$dirCount = 1; $dirCount = 1;
$isDedicated = true; %isDedicated = true;
$Server::Dedicated = true; $Server::Dedicated = true;
enableWinConsole(true); enableWinConsole(true);
$argUsed[$i]++; $argUsed[%i]++;
//-------------------- //--------------------
case "-mission": case "-mission":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
$missionArg = $nextArg; $missionArg = $nextArg;
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -mission <filename>"); error("Error: Missing Command Line argument. Usage: -mission <filename>");
//-------------------- //--------------------
case "-connect": case "-connect":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
$JoinGameAddress = $nextArg; $JoinGameAddress = $nextArg;
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -connect <ip_address>"); error("Error: Missing Command Line argument. Usage: -connect <ip_address>");
@ -96,7 +96,7 @@ function parseArgs()
//-------------------- //--------------------
case "-log": case "-log":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
// Turn on console logging // Turn on console logging
@ -107,22 +107,22 @@ function parseArgs()
} }
setLogMode($nextArg); setLogMode($nextArg);
$logModeSpecified = true; $logModeSpecified = true;
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -log <Mode: 0,1,2>"); error("Error: Missing Command Line argument. Usage: -log <Mode: 0,1,2>");
//-------------------- //--------------------
case "-dir": case "-dir":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
// Append the mod to the end of the current list // Append the mod to the end of the current list
$userDirs = strreplace($userDirs, $nextArg, ""); $userDirs = strreplace($userDirs, $nextArg, "");
$userDirs = pushFront($userDirs, $nextArg, ";"); $userDirs = pushFront($userDirs, $nextArg, ";");
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
$dirCount++; $dirCount++;
} }
else else
@ -133,12 +133,12 @@ function parseArgs()
// defaults to ONLY loading the game, not tools // defaults to ONLY loading the game, not tools
// default auto-run already loads in tools --SRZ 11/29/07 // default auto-run already loads in tools --SRZ 11/29/07
case "-game": case "-game":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
// Set the selected dir --NOTE: we no longer allow tools with this argument // Set the selected dir --NOTE: we no longer allow tools with this argument
/* /*
if( $isDedicated ) if( %isDedicated )
{ {
$userDirs = $nextArg; $userDirs = $nextArg;
$dirCount = 1; $dirCount = 1;
@ -151,8 +151,8 @@ function parseArgs()
*/ */
$userDirs = $nextArg; $userDirs = $nextArg;
$dirCount = 1; $dirCount = 1;
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
error($userDirs); error($userDirs);
} }
else else
@ -161,109 +161,109 @@ function parseArgs()
//-------------------- //--------------------
case "-console": case "-console":
enableWinConsole(true); enableWinConsole(true);
$argUsed[$i]++; $argUsed[%i]++;
//-------------------- //--------------------
case "-jSave": case "-jSave":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
echo("Saving event log to journal: " @ $nextArg); echo("Saving event log to journal: " @ $nextArg);
saveJournal($nextArg); saveJournal($nextArg);
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -jSave <journal_name>"); error("Error: Missing Command Line argument. Usage: -jSave <journal_name>");
//-------------------- //--------------------
case "-jPlay": case "-jPlay":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
playJournal($nextArg); playJournal($nextArg);
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -jPlay <journal_name>"); error("Error: Missing Command Line argument. Usage: -jPlay <journal_name>");
//-------------------- //--------------------
case "-jPlayToVideo": case "-jPlayToVideo":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
$VideoCapture::journalName = $nextArg; $VideoCapture::journalName = $nextArg;
$VideoCapture::captureFromJournal = true; $VideoCapture::captureFromJournal = true;
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -jPlayToVideo <journal_name>"); error("Error: Missing Command Line argument. Usage: -jPlayToVideo <journal_name>");
//-------------------- //--------------------
case "-vidCapFile": case "-vidCapFile":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
$VideoCapture::fileName = $nextArg; $VideoCapture::fileName = $nextArg;
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -vidCapFile <ouput_video_name>"); error("Error: Missing Command Line argument. Usage: -vidCapFile <ouput_video_name>");
//-------------------- //--------------------
case "-vidCapFPS": case "-vidCapFPS":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
$VideoCapture::fps = $nextArg; $VideoCapture::fps = $nextArg;
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -vidCapFPS <ouput_video_framerate>"); error("Error: Missing Command Line argument. Usage: -vidCapFPS <ouput_video_framerate>");
//-------------------- //--------------------
case "-vidCapEncoder": case "-vidCapEncoder":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
$VideoCapture::encoder = $nextArg; $VideoCapture::encoder = $nextArg;
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -vidCapEncoder <ouput_video_encoder>"); error("Error: Missing Command Line argument. Usage: -vidCapEncoder <ouput_video_encoder>");
//-------------------- //--------------------
case "-vidCapWidth": case "-vidCapWidth":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
$videoCapture::width = $nextArg; $videoCapture::width = $nextArg;
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -vidCapWidth <ouput_video_width>"); error("Error: Missing Command Line argument. Usage: -vidCapWidth <ouput_video_width>");
//-------------------- //--------------------
case "-vidCapHeight": case "-vidCapHeight":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
$videoCapture::height = $nextArg; $videoCapture::height = $nextArg;
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -vidCapHeight <ouput_video_height>"); error("Error: Missing Command Line argument. Usage: -vidCapHeight <ouput_video_height>");
//-------------------- //--------------------
case "-level": case "-level":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) if ($hasNextArg)
{ {
%hasExt = strpos($nextArg, ".mis"); %hasExt = strpos($nextArg, ".mis");
@ -271,7 +271,7 @@ function parseArgs()
{ {
$levelToLoad = $nextArg @ " "; $levelToLoad = $nextArg @ " ";
for(%j = $i + 2; %j < $Game::argc; %j++) for(%j = %i + 2; %j < $Game::argc; %j++)
{ {
$arg = $Game::argv[%j]; $arg = $Game::argv[%j];
%hasExt = strpos($arg, ".mis"); %hasExt = strpos($arg, ".mis");
@ -291,8 +291,8 @@ function parseArgs()
$levelToLoad = $nextArg; $levelToLoad = $nextArg;
} }
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -level <level file name (no path), with or without extension>"); error("Error: Missing Command Line argument. Usage: -level <level file name (no path), with or without extension>");
@ -300,59 +300,59 @@ function parseArgs()
//------------------- //-------------------
case "-worldeditor": case "-worldeditor":
$startWorldEditor = true; $startWorldEditor = true;
$argUsed[$i]++; $argUsed[%i]++;
//------------------- //-------------------
case "-guieditor": case "-guieditor":
$startGUIEditor = true; $startGUIEditor = true;
$argUsed[$i]++; $argUsed[%i]++;
//------------------- //-------------------
case "-help": case "-help":
$displayHelp = true; $displayHelp = true;
$argUsed[$i]++; $argUsed[%i]++;
//------------------- //-------------------
case "-compileAll": case "-compileAll":
$compileAll = true; $compileAll = true;
$argUsed[$i]++; $argUsed[%i]++;
//------------------- //-------------------
case "-compileTools": case "-compileTools":
$compileTools = true; $compileTools = true;
$argUsed[$i]++; $argUsed[%i]++;
//------------------- //-------------------
case "-genScript": case "-genScript":
$genScript = true; $genScript = true;
$argUsed[$i]++; $argUsed[%i]++;
case "-fullscreen": case "-fullscreen":
$cliFullscreen = true; $cliFullscreen = true;
$argUsed[$i]++; $argUsed[%i]++;
case "-windowed": case "-windowed":
$cliFullscreen = false; $cliFullscreen = false;
$argUsed[$i]++; $argUsed[%i]++;
case "-openGL": case "-openGL":
$pref::Video::displayDevice = "OpenGL"; $pref::Video::displayDevice = "OpenGL";
$argUsed[$i]++; $argUsed[%i]++;
case "-directX": case "-directX":
$pref::Video::displayDevice = "D3D"; $pref::Video::displayDevice = "D3D";
$argUsed[$i]++; $argUsed[%i]++;
case "-autoVideo": case "-autoVideo":
$pref::Video::displayDevice = ""; $pref::Video::displayDevice = "";
$argUsed[$i]++; $argUsed[%i]++;
case "-prefs": case "-prefs":
$argUsed[$i]++; $argUsed[%i]++;
if ($hasNextArg) { if ($hasNextArg) {
exec($nextArg, true, true); exec($nextArg, true, true);
$argUsed[$i+1]++; $argUsed[%i+1]++;
$i++; %i++;
} }
else else
error("Error: Missing Command Line argument. Usage: -prefs <path/script." @ $TorqueScriptFileExtension @ ">"); error("Error: Missing Command Line argument. Usage: -prefs <path/script." @ $TorqueScriptFileExtension @ ">");
@ -360,7 +360,7 @@ function parseArgs()
//------------------- //-------------------
default: default:
$argUsed[$i]++; $argUsed[%i]++;
if($userDirs $= "") if($userDirs $= "")
$userDirs = $arg; $userDirs = $arg;
} }