Skip to content

Commit

Permalink
Finish Steam args support and robustify cfg file writers for Steam
Browse files Browse the repository at this point in the history
  • Loading branch information
FenPhoenix committed Oct 17, 2019
1 parent 9e1d5cd commit 50f43f6
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions AngelLoader/InstallAndPlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,16 @@ private static bool PlayFM(FanMission fm, bool playMP = false)
// Must be empty, not null, so it can be concatenated
string steamArgs = "";
var sv = GetSteamValues(fm.Game);
if (sv.Success)
{
(_, gameExe, gamePath, steamArgs) = sv;
steamArgs += " ";
}
if (sv.Success) (_, gameExe, gamePath, steamArgs) = sv;

// Only use the stub if we need to pass something we can't pass on the command line
// 2019-10-16: This includes launching through Steam; we can't pass anything custom then either
// Add quotes around it in case there are spaces in the dir name. Will only happen if you put an FM
// dir in there manually. Which if you do, you're on your own mate.
var args = steamArgs + "-fm=\"" + fm.InstalledDir + "\"";
if (!fm.DisabledMods.IsWhiteSpace() || fm.DisableAllMods)
var args = !steamArgs.IsEmpty() ? steamArgs : "-fm=\"" + fm.InstalledDir + "\"";
if (!steamArgs.IsEmpty() || !fm.DisabledMods.IsWhiteSpace() || fm.DisableAllMods)
{
args = steamArgs + "-fm";
args = !steamArgs.IsEmpty() ? steamArgs : "-fm";
Paths.PrepareTempPath(Paths.StubCommTemp);

try
Expand Down Expand Up @@ -282,9 +279,13 @@ private static void SetUsAsSelector(Game game, string gameExe, string gamePath)
}
}

// 2019-10-16: We also now force the loader to start in the config files rather than just on the command
// line. This is to support Steam launching, because Steam can't take game-specific command line arguments.

private static bool SetUsAsDarkFMSelector(string gameExe, string gamePath)
{
const string fmSelectorKey = "fm_selector";
const string fmCommentLine = "always start the FM Selector (if one is present)";

var camModIni = Path.Combine(gamePath, "cam_mod.ini");
if (!File.Exists(camModIni))
Expand Down Expand Up @@ -318,6 +319,7 @@ private static bool SetUsAsDarkFMSelector(string gameExe, string gamePath)
*/
int lastSelKeyIndex = -1;
bool fmLineFound = false;
int fmCommentLineIndex = -1;
bool loaderIsAlreadyUs = false;
for (int i = 0; i < lines.Count; i++)
{
Expand All @@ -328,13 +330,24 @@ private static bool SetUsAsDarkFMSelector(string gameExe, string gamePath)
lt = lt.TrimStart(';').Trim();
} while (lt.Length > 0 && lt[0] == ';');

// Steam robustness: get rid of any fan mission specifiers in here
// line is "fm BrokenTriad_1_0" for example
if (lt.StartsWithI("fm") && lt.Length > 2 && char.IsWhiteSpace(lt[2]) &&
lt.Substring(2).Trim().Length > 0)
{
if (!lines[i].TrimStart().StartsWith(";")) lines[i] = ";" + lines[i];
}

if (fmCommentLineIndex == -1 && lt.EqualsI(fmCommentLine)) fmCommentLineIndex = i;

if (!fmLineFound && lt.EqualsI("fm"))
{
if (lines[i].TrimStart().StartsWith(";")) lines[i] = "fm";
fmLineFound = true;
}

if (lt.StartsWithI(fmSelectorKey) && lt.Length > fmSelectorKey.Length && lt
if (lt.StartsWithI(fmSelectorKey) && lt.Length > fmSelectorKey.Length &&
char.IsWhiteSpace(lt[fmSelectorKey.Length]) && lt
.Substring(fmSelectorKey.Length + 1).TrimStart().ToBackSlashes()
.EqualsI(stubPath.ToBackSlashes()))
{
Expand All @@ -354,7 +367,7 @@ private static bool SetUsAsDarkFMSelector(string gameExe, string gamePath)

if (lt.EqualsI(fmSelectorKey) ||
(lt.StartsWithI(fmSelectorKey) && lt.Length > fmSelectorKey.Length &&
(lt[fmSelectorKey.Length] == ' ' || lt[fmSelectorKey.Length] == '\t')))
char.IsWhiteSpace(lt[fmSelectorKey.Length])))
{
if (!lines[i].TrimStart().StartsWith(";")) lines[i] = ";" + lines[i];
lastSelKeyIndex = i;
Expand All @@ -373,6 +386,20 @@ private static bool SetUsAsDarkFMSelector(string gameExe, string gamePath)
}
}

if (!fmLineFound)
{
if (fmCommentLineIndex == -1 || fmCommentLineIndex == lines.Count - 1)
{
lines.Add("");
lines.Add("; " + fmCommentLine);
lines.Add("fm");
}
else
{
lines.Insert(fmCommentLineIndex + 1, "fm");
}
}

try
{
File.WriteAllLines(camModIni, lines);
Expand All @@ -393,6 +420,7 @@ private static bool SetUsAsT3FMSelector()
{
const string externSelectorKey = "ExternSelector=";
const string alwaysShowKey = "AlwaysShow=";
const string fanMissionKey = "FanMission=";
bool existingExternSelectorKeyOverwritten = false;
bool existingAlwaysShowKeyOverwritten = false;
int insertLineIndex = -1;
Expand Down Expand Up @@ -438,6 +466,11 @@ private static bool SetUsAsT3FMSelector()
lines[i + 1] = alwaysShowKey + "true";
existingAlwaysShowKeyOverwritten = true;
}
// Steam robustness: get rid of any fan mission specifiers in here
else if (lt.StartsWithI(fanMissionKey))
{
lines[i + 1] = fanMissionKey;
}

if (!lt.IsEmpty() && lt[0] == '[' && lt[lt.Length - 1] == ']') break;

Expand Down

0 comments on commit 50f43f6

Please sign in to comment.