function _saveGameConfigurationData (%projectFile)
{//echo("_saveGameConfigurationData()");echo("%projectFile =" SPC %projectFile);
	%xml = new ScriptObject()
	{
		class = "XML";
	};
	if (%xml.beginWrite(%projectFile))
	{
		// Game settings.
		%xml.writeClassBegin("TorqueGameConfiguration");
        %xml.writeField("Company", $Game::CompanyName);
        %xml.writeField("GameName", $Game::ProductName);
        %xml.writeField("Resolution", $Game::Resolution);
        %xml.writeField("BitDepth", $Game::BitDepth);
        %xml.writeField("FullScreen", $Game::FullScreen);
		// HACK.
		if ($Game::VerticalSync $= "")
		{
			$Game::VerticalSync = 1;
		}
		// END OF HACK
        %xml.writeField("VerticalSync", $Game::VerticalSync);
        %xml.writeField("CommonVer", $Game::CommonVersion);
        %xml.writeField("ConsoleKey", $Game::ConsoleBind);
        %xml.writeField("ScreenShotKey", $Game::ScreenshotBind);
        %xml.writeField("FullscreenKey", $Game::FullscreenBind);
        %xml.writeField("UsesNetwork", $Game::UsesNetwork);
        %xml.writeField("UsesAudio", $Game::UsesAudio);
        %xml.writeField("DefaultScene", $Game::DefaultScene);
		// Gameplay settings.
        %xml.writeField("CameraTrackSpeed", $Game::CameraTrackSpeed);
        %xml.writeField("MonsterTurnSpeed", $Game::MonsterTurnSpeed);
        %xml.writeField("AutoEndTurns", $Game::AutoEndTurns);
        %xml.writeField("AutoSwitchCharacters", $Game::AutoSwitchCharacters);
        %xml.writeField("AutoEndTurnSwitchCharacters", $Game::AutoEndTurnSwitchCharacters);
        %xml.writeField("FadingFogOfWarToggle", $Game::FadingFogOfWarToggle);
        if ($Game::EnemyCameraLock $= "")
        {error("Bad field for $Game::EnemyCameraLock! Defaulting to 1!");
        	$Game::EnemyCameraLock = 1;
        }
        if ($Game::AutoLoot $= "")
        {error("Bad field for $Game::AutoLoot! Defaulting to 1!");
        	$Game::AutoLoot = 1;
        }
        %xml.writeField("EnemyCameraLock", $Game::EnemyCameraLock);
        %xml.writeField("AutoLoot", $Game::AutoLoot);
        %xml.writeField("FacingCostsAP", $Game::FacingCostsAP);
        %xml.writeField("AutoFacing", $Game::AutoFacing);
        %xml.writeField("AutoLock", $Game::AutoLock);
        %xml.writeField("AlwaysShowCursor", $Game::AlwaysShowCursor);
		// HACK.
		if ($Game::AlwaysShowMoveIndicator $= "")
		{
			$Game::AlwaysShowMoveIndicator = 1;
		}
		// END OF HACK
        %xml.writeField("AlwaysShowMoveIndicator", $Game::AlwaysShowMoveIndicator);
        %xml.writeField("LargeFont", $Game::LargeFont);
        %xml.writeField("MusicVolume", $Game::MusicVolume);
        %xml.writeField("SoundVolume", $Game::SoundVolume);
		// Done.
		%xml.writeClassEnd();
		%xml.endWrite();
	}   
	else
	{
		error("saveGameConfigurationData - Failed to write to file: " @ %projectFile);
		return false;
	}
	%xml.delete();
	return true;
}

//
// Load config data
//
function _loadGameConfigurationData (%projectFile)
{//echo("_loadGameConfigurationData()");echo("%projectFile =" SPC %projectFile);
	%xml = new ScriptObject()
	{
		class = "XML";
	};
	if (%xml.beginRead(%projectFile))
	{
		if (%xml.readClassBegin("TorqueGameConfiguration"))		// NOTE: T2d v3.0 broke this!
		{//echo("BEGIN reading commonConfig.xml...");
			$Game::CompanyName   				= %xml.readField("Company");
			$Game::ProductName   				= %xml.readField("GameName");
			$Game::Resolution    				= %xml.readField("Resolution");
		//echo("$Game::Resolution =" SPC $Game::Resolution);
		//echo("%xml.readField(Resolution) =" SPC %xml.readField("Resolution"));
			$Game::FullScreen    				= %xml.readField("FullScreen");
			// HACK
			$Game::VerticalSync = 1;
			$Game::VerticalSync    				= %xml.readField("VerticalSync");
		error("$Game::VerticalSync =" SPC $Game::VerticalSync);
			if ($Game::VerticalSync != 0	&&
				$Game::VerticalSync != 1)
			{error("     Incomprehensible vertical sync value! Defaulting to 1!");
				$Game::VerticalSync = 1;
			}
			/*else
			{error("$Game::VerticalSync set to" SPC $Game::VerticalSync @ "!");
			}*/
			else if ($Game::VerticalSync $= "")
			{error("Vertical sync value not found! $Game::VerticalSync set to 1!");
				$Game::VerticalSync = 1;
			}
			// END OF HACK.
			$Game::CommonVersion 				= %xml.readField("CommonVer");
			$Game::ConsoleBind    				= %xml.readField("ConsoleKey");
			$Game::ScreenshotBind 				= "print";//%xml.readField("ScreenShotKey");
			$Game::FullscreenBind				= %xml.readField("FullscreenKey");
			$Game::UsesNetwork   				= %xml.readField("UsesNetwork");
			$Game::UsesAudio    				= %xml.readField("UsesAudio");
			$Game::DefaultScene 				= %xml.readField("DefaultScene");
			
			// Custom game settings for Steam Marines!
			$Game::CameraTrackSpeed				= %xml.readField("CameraTrackSpeed");
			$Game::MonsterTurnSpeed				= %xml.readField("MonsterTurnSpeed");
			$Game::AutoEndTurns					= %xml.readField("AutoEndTurns");
			$Game::AutoSwitchCharacters			= %xml.readField("AutoSwitchCharacters");
			$Game::AutoEndTurnSwitchCharacters	= %xml.readField("AutoEndTurnSwitchCharacters");
			
			$Game::FadingFogOfWarToggle			= %xml.readField("FadingFogOfWarToggle");
			$Game::EnemyCameraLock				= %xml.readField("EnemyCameraLock");
			if ($Game::EnemyCameraLock $= "")
			{
				$Game::EnemyCameraLock = 1;
				EnemyCameraLockToggle.setValue($Game::EnemyCameraLock);
			}
			$Game::AutoLoot						= %xml.readField("AutoLoot");
			if ($Game::AutoLoot $= "")
			{
				$Game::AutoLoot = 1;
				AutoLootToggle.setValue($Game::AutoLoot);
			}
			$Game::FacingCostsAP				= %xml.readField("FacingCostsAP");
			$Game::AutoFacing					= %xml.readField("AutoFacing");
			
			$Game::AlwaysShowCursor				= %xml.readField("AlwaysShowCursor");
			$Game::AlwaysShowMoveIndicator		= %xml.readField("AlwaysShowMoveIndicator");
			$Game::AutoLock						= %xml.readField("AutoLock");
			$Game::LargeFont					= %xml.readField("LargeFont");
			
			$Game::MusicVolume					= %xml.readField("MusicVolume");
			$Game::SoundVolume					= %xml.readField("SoundVolume");
			
			$Game::BitDepth						= %xml.readField("BitDepth");
			
			%xml.readClassEnd();
		//echo("END reading commonConfig.xml!");
		}
		else
		{error("	Corrupt commonConfig.xml! Reverting to defaults!");
			_defaultGameConfigurationData();
		}
		%xml.endRead();
	}
	else
	{error("	Can't read commonConfig.xml! Reverting to defaults!");
		_defaultGameConfigurationData();
	}
	%xml.delete();
	setCompanyAndProduct($Game::CompanyName, $Game::ProductName);
}
function _defaultGameConfigurationData ()
{//echo("_defaultGameConfigurationData()");
	//echo("Defaulting common config!");
	$Game::CompanyName     				= "Worthless Bums";
	$Game::ProductName     				= "Steam Marines";
	$Game::Resolution      				= "800 600 32";
	$Game::BitDepth       				= "32";
	$Game::FullScreen      				= "false";
	$Game::VerticalSync      			= "1";
	$Game::ConsoleBind     				= "ctrl tilde";
	$Game::ScreenshotBind  				= "print";
	if ($platform $= "macos")
	{
		$Game::ScreenshotBind  			= "ctrl p";
	}
	$Game::FullscreenBind  				= "alt enter";
	$Game::UsesNetwork     				= false;
	$Game::UsesAudio       				= true;
	$Game::DefaultScene    				= "^AppCore/data/levels/startLevel.t2d";
	$Game::CameraTrackSpeed				= 4;//7;		// 7 is for when girder parallax is enabled!
	$Game::MonsterTurnSpeed 			= 4;
	$Game::AutoEndTurns					= 1;
	$Game::AutoSwitchCharacters			= 1;
	$Game::AutoEndTurnSwitchCharacters 	= 1;
	$Game::FadingFogOfWarToggle			= 0;
	$Game::EnemyCameraLock				= 1;
	$Game::AutoLoot						= 1;
	$Game::FacingCostsAP				= 1;
	$Game::AutoFacing					= 1;
	$Game::AlwaysShowCursor				= 0;
	$Game::AlwaysShowMoveIndicator		= 0;
	$Game::AutoLock					 	= 0;
	$Game::LargeFont				 	= 1;
	$Game::MusicVolume 					= 0.8;
	$Game::SoundVolume 					= 0.8;
}