Skip to content

Commit

Permalink
Improvements to game launch process
Browse files Browse the repository at this point in the history
  • Loading branch information
paulov-t committed Jul 1, 2023
1 parent a7de167 commit c4739bb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 60 deletions.
110 changes: 52 additions & 58 deletions Libraries/FrostySdk/ModdingSupport/ModExecutor.cs
Expand Up @@ -1076,13 +1076,13 @@ public async Task<bool> Run(ILogger inLogger, string gameRootPath, params string
if (foundMods && !UseModData)
{
Logger.Log("Launching game: " + fs.BasePath + ProfileManager.ProfileName + ".exe (with Frostbite Mods)");
ExecuteProcess(fs.BasePath + ProfileManager.ProfileName + ".exe", "");
await ExecuteProcess(fs.BasePath + ProfileManager.ProfileName + ".exe", "");
}
else if (UseModData)
{
if (EADesktopIsInstalled)
{
RunEADesktop();
await RunEADesktop();
LaunchedViaEADesktop = true;
}
else
Expand All @@ -1092,13 +1092,13 @@ public async Task<bool> Run(ILogger inLogger, string gameRootPath, params string
else
Logger.Log("Launching game: " + fs.BasePath + ProfileManager.ProfileName + ".exe (with Frostbite Mods in ModData)");

ExecuteProcess(GameEXEPath, arguments);
await ExecuteProcess(GameEXEPath, arguments);
}
}
else
{
Logger.Log("Launching game: " + fs.BasePath + ProfileManager.ProfileName + ".exe");
ExecuteProcess(fs.BasePath + ProfileManager.ProfileName + ".exe", "");
await ExecuteProcess(fs.BasePath + ProfileManager.ProfileName + ".exe", "");
}

if (UseACBypass && ProfileManager.IsFIFA23DataVersion())
Expand Down Expand Up @@ -1204,7 +1204,7 @@ private async Task RunEADesktop()

}

ExecuteProcess(fs.BasePath + ProfileManager.ProfileName + ".exe", "");
await ExecuteProcess(fs.BasePath + ProfileManager.ProfileName + ".exe", "");
//ExecuteCommand("start \"" + fs.BasePath + ProfileManager.ProfileName + ".exe\"");
}

Expand Down Expand Up @@ -1410,63 +1410,57 @@ private void RunSetupFIFAConfig()
// Process = Process.Start(ProcessInfo);
//}

public async void ExecuteProcess(string processName, string args, bool waitForExit = false, bool asAdmin = false)
public async Task ExecuteProcess(string processName, string args, bool waitForExit = false, bool asAdmin = false)
{
FileLogger.WriteLine($"Launching {processName} {args}");
Logger.Log($"Launching {processName} {args}");
using Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = $"/K \"\"{processName}\" \"{args}\"\" && exit";
p.Start();
await Task.Delay(10000);
p.Kill();
//Task.Run(async() => { await Task.Delay(10000); if (p != null) p.Kill(); });

//var result = await Task.FromResult(async() =>
//{
//using Process p = new Process();
//p.StartInfo.FileName = "cmd.exe";
//p.StartInfo.Arguments = $"/K \"\"{processName}\" \"{args}\"\" && exit";
//p.Start();
//await Task.Delay(20000);
//p.Kill();

if (Process.GetProcessesByName(processName).Length > 0)
return;

// using (Process process = new ())
// //Process process = new();
// {
// FileInfo fileInfo = new FileInfo(processName);
// process.StartInfo.FileName = processName;
// process.StartInfo.WorkingDirectory = fileInfo.DirectoryName;
// process.StartInfo.Arguments = args;
// process.StartInfo.UseShellExecute = true;
// if (asAdmin)
// {
// process.StartInfo.UseShellExecute = true;
// process.StartInfo.Verb = "runas";
// }
// try
// {
// if (!process.Start())
// {
// throw new Exception($"Unable to start {processName}");
// }
// while (true)
// {
// await Task.Delay(1000);
// if (Process.GetProcesses().Any(x => x.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase)))
// break;
// }
// }
// catch(Exception e)
// {
// //throw e;
// }
// //return true;
// }
//}
//);
//FileInfo fileInfo = new FileInfo(processName);
//Process.Start(new ProcessStartInfo
//{
// FileName = fileInfo.FullName,
// WorkingDirectory = fileInfo.DirectoryName,
// Arguments = args,
// UseShellExecute = false
//});
using (Process process = new())
{
FileInfo fileInfo = new FileInfo(processName);
process.StartInfo.FileName = processName;
process.StartInfo.WorkingDirectory = fileInfo.DirectoryName;
process.StartInfo.Arguments = args;
process.StartInfo.UseShellExecute = false;
if (asAdmin)
{
process.StartInfo.UseShellExecute = true;
process.StartInfo.Verb = "runas";
}
//try
//{
if (!process.Start())
{
throw new Exception($"Unable to start {processName}");
}
//int waitedTime = 0;
//while (true)
//{
// await Task.Delay(1000);
// if (Process.GetProcesses().Any(x => x.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase)))
// break;

// if(++waitedTime > 60)
// {
// throw new Exception("Process did not start. If your EA Desktop is setup correctly. You can still start the game manually now!");
// }
//}
//}
//catch (Exception e)
//{
// throw e;
//}
}

}

private byte[] GetResourceData(string modFilename, int archiveIndex, long offset, int size)
Expand Down
5 changes: 3 additions & 2 deletions Tests/FrostbiteModdingTests/FIFA23Tests.cs
Expand Up @@ -18,6 +18,7 @@
using System.Linq;
using System.Runtime;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using v2k4FIFAModding.Frosty;
using v2k4FIFAModdingCL;
Expand Down Expand Up @@ -461,15 +462,15 @@ public void TestAvatarExpansionMod()
}

[TestMethod]
public void TestCareerMod()
public async Task TestCareerMod()
{
GameInstanceSingleton.InitializeSingleton(GamePathEXE, true, this);
ProjectManagement projectManagement = new ProjectManagement(GamePathEXE);
projectManagement.Project = FMTProject.Read(@"G:\Work\FIFA Modding\Career Mod\FIFA-23-Career-Mod\V Career Mod - Version 2a4.fmtproj");
projectManagement.Project.WriteToMod("test.fbmod", projectManagement.Project.ModSettings);
ModdingSupport.ModExecutor frostyModExecutor = new ModdingSupport.ModExecutor();
frostyModExecutor.ForceRebuildOfMods = true;
var r = frostyModExecutor.Run(this, GameInstanceSingleton.Instance.GAMERootPath, new List<string>() { "test.fbmod" }.ToArray()).Result;
await frostyModExecutor.Run(this, GameInstanceSingleton.Instance.GAMERootPath, new List<string>() { "test.fbmod" }.ToArray());
}

[TestMethod]
Expand Down

0 comments on commit c4739bb

Please sign in to comment.