Skip to content

Commit d29f36e

Browse files
committed
Fix EGS login issue
- Bump to v0.6.0
1 parent 46560f7 commit d29f36e

File tree

4 files changed

+413
-305
lines changed

4 files changed

+413
-305
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using Hi3Helper.Plugin.Core.Utility;
2+
using Hi3Helper.Plugin.DNA.Management.PresetConfig;
3+
using System;
4+
using System.Diagnostics;
5+
using System.Linq;
6+
using System.Runtime.InteropServices;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
10+
namespace Hi3Helper.Plugin.DNA;
11+
12+
public partial class DNAbyss
13+
{
14+
private const string EpicLaunchUri = "com.epicgames.launcher://apps/ceb703de37854cda9932d2f9dd531520%3A572fcef540b841dd9230d813bd5208fe%3A58c7aa4f48be44f3b40f5f78f62c84b7?action=launch&silent=true";
15+
private bool IsEpicLoading = false;
16+
private DateTime? EpicStartTime = null;
17+
private Process[] EpicProcesses = [];
18+
19+
private const int SW_MINIMIZE = 6;
20+
21+
[DllImport("user32.dll")]
22+
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
23+
24+
private async Task<bool> TryInitializeEpicLauncher(GameManagerExtension.RunGameFromGameManagerContext context, CancellationToken token)
25+
{
26+
if (context.PresetConfig is not DNAEpicPresetConfig presetConfig)
27+
{
28+
return true;
29+
}
30+
31+
IsEpicLoading = true;
32+
EpicStartTime = DateTime.Now;
33+
34+
// Trigger launcher via Epic
35+
ProcessStartInfo psi = new()
36+
{
37+
FileName = EpicLaunchUri,
38+
UseShellExecute = true
39+
};
40+
Process.Start(psi);
41+
42+
// Find main process for launcher
43+
int delay = 0;
44+
while (EpicProcesses.Length == 0 && delay < 15000)
45+
{
46+
EpicProcesses = Process.GetProcessesByName("EMLauncher-Win64-Shipping");
47+
48+
await Task.Delay(200, token);
49+
delay += 200;
50+
}
51+
52+
if (EpicProcesses.Length > 0)
53+
{
54+
Process p = EpicProcesses.First();
55+
while (p.MainWindowHandle == IntPtr.Zero)
56+
{
57+
p.Refresh();
58+
await Task.Delay(100, token);
59+
}
60+
61+
// Minimize launcher window
62+
ShowWindow(p.MainWindowHandle, SW_MINIMIZE);
63+
}
64+
65+
IsEpicLoading = false;
66+
67+
return true;
68+
}
69+
70+
private async Task TryKillEpicLauncher(GameManagerExtension.RunGameFromGameManagerContext context, CancellationToken token)
71+
{
72+
try
73+
{
74+
// Give some time for the launcher to init EOS for the game
75+
await Task.Delay(15000, CancellationToken.None);
76+
77+
// Kill launcher
78+
foreach (var p in EpicProcesses)
79+
{
80+
p.Kill();
81+
p.Dispose();
82+
}
83+
}
84+
catch (Exception)
85+
{
86+
// Pass
87+
}
88+
finally
89+
{
90+
EpicProcesses = [];
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)