-
Notifications
You must be signed in to change notification settings - Fork 44
/
ClientManager.cs
889 lines (763 loc) · 30.6 KB
/
ClientManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
using System.Threading;
using System.Drawing;
using System.Windows.Media.Imaging;
using System.ComponentModel;
using Gw2_Launchbuddy;
using System.Windows.Threading;
using Gw2_Launchbuddy.Modifiers;
using Gw2_Launchbuddy.Extensions;
using Gw2_Launchbuddy.Helpers;
using System.Collections.Generic;
using PluginContracts.ObjectInterfaces;
namespace Gw2_Launchbuddy.ObjectManagers
{
public static class ClientManager
{
public static ObservableCollection<Client> Clients = new ObservableCollection<Client>();
public static ObservableCollection<Client> ActiveClients = new ObservableCollection<Client>(); //initialize one instance, get{} would create a new instance every statusupdate (bad for ui)
public static void Add(Client client)
{
Clients.Add(client);
client.StatusChanged += UpdateActiveList;
}
public static void UpdateActiveList(object sender, EventArgs e)
{
Client client = sender as Client;
if(client == null)
{
return;
}
Console.WriteLine(client.account.Nickname + " status changed to: " + client.Status + " = " + ((int)client.Status).ToString());
Application.Current.Dispatcher.BeginInvoke(
DispatcherPriority.Background,
new Action(() =>
{
ActiveClients.Clear();
foreach(var cl in Clients)
{
if(cl.IsActive) ActiveClients.Add(cl);
if (!cl.IsActive && ActiveClients.Contains(cl)) ActiveClients.Remove(cl);
}
SaveActiveClients();
}));
}
private static void SaveActiveClients()
{
//Saving all active clients to a file within the Appdata Lb folder, rather than registry, to minimize errors by privileges
//Format:"Nickname,Client.Status,Client.Process.Id,Client.Process.StartTime
if (File.Exists(EnviromentManager.LBActiveClientsPath))
File.Delete(EnviromentManager.LBActiveClientsPath);
var filewriter = File.AppendText(EnviromentManager.LBActiveClientsPath);
foreach (Client client in ActiveClients)
{
filewriter.WriteLine(client.account.Nickname + "," + (int)client.Status + "," + client.Process.Id + "," + client.Process.StartTime.ToString());
}
filewriter.Close();
}
public static List<Process> SearchForeignClients(bool silent =false, Client.ClientStatus minstatus = Client.ClientStatus.Running)
{
List<Process> newprocesses = new List<Process>();
foreach (Process pro in Process.GetProcessesByName(EnviromentManager.GwClientExeNameWithoutExtension))
{
try
{
if (Clients.Where<Client>(c=>c.Status > minstatus).Where<Client>(c => c.Process.Id == pro.Id).Count<Client>() == 0)
{
newprocesses.Add(pro);
}
}catch
{
//pro is null
continue;
}
}
if (!silent && newprocesses.Count > 0)
{
MessageBox.Show("A Guild Wars 2 instance has been found which is not configured for multiboxing.\n Please close the application or wait for the update to be completed to avoid unexpected behavior.");
}
return newprocesses;
}
public static bool ImportActiveClients()
{
if (File.Exists(EnviromentManager.LBActiveClientsPath))
{
var lines_client = File.ReadLines(EnviromentManager.LBActiveClientsPath);
foreach (string line in lines_client)
{
Account acc;
try
{
acc = AccountManager.Accounts.First(a => a.Nickname == line.Split(',')[0]);
}
catch
{
continue;
}
Process pro;
try
{
pro = Process.GetProcessById(Int32.Parse(line.Split(',')[2]));
}
catch
{
continue;
}
if (pro != null)
{
String processStartTime;
try
{
processStartTime = pro.StartTime.ToString();
}
catch
{
continue;
}
if (processStartTime == line.Split(',')[3])
{
Client.ClientStatus status = (Client.ClientStatus)Int32.Parse(line.Split(',')[1]);
acc.Client.SetProcess(new GwGameProcess(pro),status); // This is a Downcast __> >:(
if (status.HasFlag(Client.ClientStatus.Running)) ActiveClients.Add(acc.Client);
}
else
{
continue;
}
}
}
}
SearchForeignClients();
return true;
}
}
public class Client : INotifyPropertyChanged
{
public readonly Account account;
private ClientStatus status = ClientStatus.None;
public GwGameProcess Process = new GwGameProcess(new Process());
//public Process CoherentUIProcess; Could be used to improve login timings; needs more testing
public event EventHandler StatusChanged;
public event PropertyChangedEventHandler PropertyChanged;
//public ObservableCollection<string> HotkeyCommands { get { return GetCommands(typeof(Client)); } }
public Account Account { set {} get { return account; } }
protected virtual void OnStatusChanged(EventArgs e)
{
account.Settings.ClientStatusChanged();
OnPropertyChanged("StatusToIcon");
#if DEBUG
Console.WriteLine("Account: " + account + " Status: " + Status);
#endif
PluginManager.OnClientStatusChanged(new PluginContracts.EventArguments.ClientStatusEventArgs(account.ID,(PluginContracts.ObjectInterfaces.ClientStatus)Status)); //Plugincall
EventHandler handler = StatusChanged;
if (handler != null)
{
handler(this, e);
}
}
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
public bool IsActive
{
get { return Status >= Client.ClientStatus.Running; }
}
[Flags]
public enum ClientStatus
{
None = 0x00,
Configured = 0x01,
Created = 0x01 << 1,
Injected = 0x01 << 2,
MutexClosed = 0x01 << 3,
Login = 0x01 <<4,
Running = 0x01 << 5,
Closed = 0x01 << 6,
Crash= 0x01 << 7
};
public ClientStatus Status
{
set
{
status = status | value;
if (value == ClientStatus.None || value == ClientStatus.Closed)
{ status = ClientStatus.None; }
OnStatusChanged(EventArgs.Empty);
}
get { return status; }
}
public void SetProcess(GwGameProcess pro, ClientStatus prostatus)
{
Process = pro;
try
{
if (pro == null) return;
if (pro.HasExited) return;
Process.EnableRaisingEvents = true;
Process.Exited += OnClientClose;
status = status | prostatus;
if (prostatus == ClientStatus.None || prostatus == ClientStatus.Closed)
status = ClientStatus.None;
}
catch
{
status = ClientStatus.Crash;
}
}
public Client(Account acc)
{
account = acc;
Process.Exited += OnClientClose;
ClientManager.Add(this);
}
private bool ProcessIsClosed()
{
if (Process.HasExited)
{
this.status = ClientStatus.Closed;
return true;
}
return false;
}
public void Close()
{
//May need more gracefully close function
if(Status> ClientStatus.Created)
{
Process.Stop();
Account.Settings.RelaunchesLeft = 0;
Status = ClientStatus.Closed;
}
}
[Flags]
public enum ThreadAccess : int
{
TERMINATE = (0x0001),
SUSPEND_RESUME = (0x0002),
GET_CONTEXT = (0x0008),
SET_CONTEXT = (0x0010),
SET_INFORMATION = (0x0020),
QUERY_INFORMATION = (0x0040),
SET_THREAD_TOKEN = (0x0080),
IMPERSONATE = (0x0100),
DIRECT_IMPERSONATION = (0x0200)
}
[DllImport("kernel32.dll")]
static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId);
[DllImport("kernel32.dll")]
public static extern uint SuspendThread(IntPtr hThread);
[DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool CloseHandle(IntPtr handle);
[DllImport("kernel32.dll")]
public static extern uint ResumeThread(IntPtr hThread);
public void Suspend()
{
if (ProcessIsClosed()) return;
foreach (ProcessThread pT in Process.Threads)
{
IntPtr pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id);
if (pOpenThread == IntPtr.Zero)
{
continue;
}
SuspendThread(pOpenThread);
CloseHandle(pOpenThread);
}
}
public void Minimize()
{
WindowUtil.Minimize(Process.GetProcess());
}
public void Maximize()
{
WindowUtil.Maximize(Process.GetProcess());
}
public void Resume()
{
if (ProcessIsClosed()) return;
foreach (ProcessThread pT in Process.Threads)
{
IntPtr pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id);
if (pOpenThread == IntPtr.Zero)
{
continue;
}
uint suspendCount = 0;
do
{
suspendCount = ResumeThread(pOpenThread);
} while (suspendCount > 0);
CloseHandle(pOpenThread);
}
}
public bool Focus()
{
return WindowUtil.Focus(Process.GetProcess());
}
protected virtual void OnClientClose(object sender, EventArgs e)
{
Process pro = sender as Process;
Status = ClientStatus.Closed;
if (Account.Settings.RelaunchesLeft > 0)
{
Account.Settings.RelaunchesLeft--;
Launch();
}
account.Settings.AccountInformation.SetLastClose();
//GetNewGFXFile();
foreach(Process addpro in account.AdditionalSoftware)
{
addpro.Close();
}
account.AdditionalSoftware.Clear();
}
/*
* Disabled. Oversight: Gw2 does periodically save to the gfx xml file for this to work a symlink must be created at launch
*
private bool GetNewGFXFile()
{
try
{
account.Settings.GFXFile = GFXManager.LoadFile(EnviromentManager.GwClientXmlPath);
}catch
{
return false;
}
return true;
}
*/
public void Window_MoveTo_Default()
{
WindowConfig config = account.Settings.WinConfig;
Window_Move(config.WinPos_X,config.WinPos_Y);
}
public void Window_ScaleTo_Default()
{
WindowConfig config = account.Settings.WinConfig;
Window_Scale(config.Win_Width,config.Win_Height);
}
public void Window_Move(int posx,int posy)
{
WindowUtil.MoveTo(Process.GetProcess(), posx, posy);
}
public void Window_Scale(int width,int height)
{
WindowUtil.ScaleTo(Process.GetProcess(), width,height);
}
private void Window_Init()
{
new Thread (Th_Window_Init).Start();
}
private async void Th_Window_Init()
{
// icm32.dll
await Process.WaitForStateAsynch(GwGameProcess.GameStatus.game_charscreen);
Console.WriteLine($"{account.Nickname} configuring Windowsize");
Window_MoveTo_Default();
Window_ScaleTo_Default();
int i = 0;
while (i<3 && account.Settings.WinConfig.IsConfigured(Process.GetProcess()) !=true)
{
try
{
Window_MoveTo_Default();
Window_ScaleTo_Default();
}
catch { }
Thread.Sleep(500);
i++;
}
}
private void ConfigureProcess()
{
if (Process == null) Process = new GwGameProcess(new Process());
Process.EnableRaisingEvents = true;
string args = "";
try
{
Argument dx9arg = account.Settings.Arguments.FirstOrDefault(x => x.ToString() == "-dx9");
Argument dx11arg = account.Settings.Arguments.FirstOrDefault(x => x.ToString() == "-dx11");
if (dx9arg.IsActive && dx11arg.IsActive)
{
MessageBox.Show($"On account {account.Nickname} both DirectX 9 and DirectX 11 was enabled. Please disable one of both options in the future. This setting got reset to DirectX 9 for this account.");
dx11arg.IsActive = false;
}
}catch
{
Console.WriteLine("Could not fetch direct X settings");
}
try
{
foreach (Argument arg in account.Settings.Arguments.GetActive())
{
args += arg.ToString() + " ";
}
}
catch
{
Console.WriteLine("Account arguments corrupted");
}
args += "-shareArchive ";
account.CustomMumbleLink = false;
if (ClientManager.ActiveClients.Count != 0 || account.Settings.AlwaysUseCustomMumbleLink)
{
args += $"-mumble GW2MumbleLink{account.ID} ";
account.CustomMumbleLink = true;
}
if (account.Settings.WinConfig != null && !args.Contains("-windowed")) args += "-windowed ";
//Add Login Credentials
/*
if (account.Settings.HasLoginCredentials)
{
args += "-nopatchui -autologin ";
args += "-email \"" + account.Settings.Email+"\" ";
args += "-password \"" + account.Settings.Password + "\" ";
}
*/
/*
if(account.Settings.Loginfile!=null && account.Settings.Loginfile.Gw2Build==EnviromentManager.GwClientVersion)
{
args += "-autologin ";
}
*/
//Add Server Options
if (ServerManager.SelectedAssetserver != null)
if(ServerManager.SelectedAssetserver.Enabled)
args += "-assetsrv " + ServerManager.SelectedAssetserver.ToArgument;
if (ServerManager.SelectedAuthserver != null)
if (ServerManager.SelectedAuthserver.Enabled)
args += "-authsrv " + ServerManager.SelectedAuthserver.ToArgument;
if(ServerManager.clientport!=null)
{
args += "-clientport " + ServerManager.clientport;
}
if(account.Settings.IsArenaNetAccount)
{
Process.StartInfo = new ProcessStartInfo { FileName = EnviromentManager.GwClientExePath, Arguments = args };
}
if (account.Settings.IsSteamAccount)
{
this.Process = new SteamGwGameProcess(Process.GetProcess(),new Process{ StartInfo = new ProcessStartInfo(EnviromentManager.GwSteamLaunchLink + " " + args) });
}
//Sub to events after process has been configured. Otherwise process migration (steam) wont work
try { Process.Exited -= OnClientClose; } catch { };
Process.Exited += OnClientClose;
}
private void SetProcessPriority()
{
if (Account.Settings.ProcessPriority != ProcessPriorityClass.Normal)
{
try
{
Process.PriorityClass = Account.Settings.ProcessPriority;
}
catch
{
MessageBox.Show("Could not set Process priority");
}
}
}
private bool IsAutomatedClient { get
{
if (account.Settings.IsSteamAccount) return true;
return account.Settings.HasLoginCredentials;
} }
private void SetProcessAffinity()
{
if (account.Settings.ProcessAffinityConfig != null)
{
try
{
Process.ProcessorAffinity = account.Settings.ProcessAffinityConfig.MaskAsPtr;
}
catch { }
}
}
private void SwapLocalDat()
{
if (account.Settings.Loginfile != null && account.Settings.IsArenaNetAccount)
{
LocalDatManager.Apply(account.Settings.Loginfile);
}else
{
LocalDatManager.ApplyNullLoginfile(); //Create symbolic link to local dat itself --> closes file handle on gamestart
}
}
private void CloseMutex()
{
for (var i = 0; i < 10; i++)
{
#if DEBUG
System.Diagnostics.Debug.Print("Mutex Kill Attempt Nr" + i);
#endif
try
{
//if (HandleManager.ClearMutex(ClientManager.ClientInfo.ProcessName, "AN-Mutex-Window-Guild Wars 2", ref nomutexpros)) i = 10;
if (HandleManager.KillHandle(Process.GetProcess(), "AN-Mutex-Window-Guild Wars 2", false)) i = 10;
}
catch (Exception err)
{
MessageBox.Show("Mutex release failed, will try again. Please provide the following if you want to help fix this problem: \r\n" + err.GetType().ToString() + "\r\n" + err.Message + "\r\n" + err.StackTrace);
}
//Maxtime 10 secs
Thread.Sleep((int)(Math.Pow(i, 2) * 25 + 50));
}
}
private void SwapGFX()
{
if(account.Settings.GFXFile!=null)
{
GFXManager.UseGFX(account.Settings.GFXFile);
}
}
private void RestoreGFX()
{
GFXManager.RestoreDefault();
}
private void InjectDlls()
{
foreach(string dll in account.Settings.DLLs)
{
DllInjector.Inject((uint)Process.Id,dll);
}
}
public void Inject(string dllname)
{
DllInjector.Inject((uint)Process.Id, dllname);
}
private bool ProcessExists()
{
try
{
object res = System.Diagnostics.Process.GetProcessById(Process.Id);
return true;
}
catch
{
return false;
}
}
private void FillLogin()
{
if(account.Settings.Email!=null && account.Settings.Password!=null)
{
Loginfiller.Login(account.Settings.Email, account.Settings.Password, this.Process,true);
}
}
private void PressLoginButton()
{
int timetowait = DDOSDelays.GetWaitTime();
if(LBConfiguration.Config.uselogindelays)
{
Action loginwait = () => { Thread.Sleep(timetowait); };
Helpers.BlockerInfo.Run("Delaying Login", $"Launchbuddy is currently delaying the login for {timetowait / 1000} sec(s). This is a safety measure to avoid triggering GW2 DDOS protection. Press cancel to skip.", loginwait, false);
}
Loginfiller.PressLoginButton(Account);
}
private void WaitForLogin()
{
Action blockefunc = () => Process.WaitForState(GwGameProcess.GameStatus.loginwindow_authentication);
Helpers.BlockerInfo.Run($"{account.Nickname} Login pending", $"{account.Nickname} Login requiring additional information.", blockefunc);
}
private void ShowProcessStatusbar()
{
//if (account.Settings.LoginType == LoginType.Steam) return;
Thread statusbar = new Thread(() =>
{
UIStatusbar loginwindowblocker = new UIStatusbar(this, new Func<bool>(() => Process.ReachedState(GwGameProcess.GameStatus.game_startup)), GwUIPoints.pos_loginwindow_offset);
loginwindowblocker.Show();
loginwindowblocker.Closed += (sender, e) => loginwindowblocker.Dispatcher.InvokeShutdown();
Dispatcher.Run();
});
statusbar.SetApartmentState(ApartmentState.STA);
statusbar.Start();
}
public int LaunchProgress
{
get{
return (int)((float)Process.Status / (float)GwGameProcess.GameStatus.game_startup * 100);
}
}
private void StartProcess()
{
Process.Start();
if(account.Settings.IsSteamAccount)
{
Action waitforgame = () => { Process.WaitForState(GwGameProcess.GameStatus.loginwindow_prelogin); };
BlockerInfo.Run("Waiting for steam launch","Launchbuddy waits for steam to launch the gw2 gameclient.",waitforgame);
if(!BlockerInfo.Done)
{
Status = ClientStatus.None;
MessageBox.Show("Steam gamelaunch aborted. The gw2 gamelaunch with steam got closed.");
}
}
}
public void Launch()
{
try
{
var starttime = DateTime.Now;
while (Status < ClientStatus.Running)
{
//Check if it crashed/closed in between a step
if (!Process.IsRunning && Status > ClientStatus.Created)
{
try
{
Process.Stop();
}
catch { }
RestoreGameSettings();
MessageBoxResult win = MessageBox.Show($"Client {account.Nickname} got closed or crashed before a clean Start (Errorcode: {Convert.ToString((int)Status, 16)}). Do you want to retry to start this Client?", "Client Retry", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (win.ToString() == "Yes")
{
Status = ClientStatus.None;
}
else
{
Account.Settings.RelaunchesLeft = 0;
Status = ClientStatus.Crash;
}
}
if (Status.HasFlag(ClientStatus.Closed))
{
Status = ClientStatus.None;
return;
}
switch (Status)
{
case var expression when (Status < ClientStatus.Configured):
ConfigureProcess();
if(IsAutomatedClient) SwapGFX();
SwapLocalDat();
Status = ClientStatus.Configured;
break;
case var expression when (Status < ClientStatus.Created):
Console.WriteLine($"{Status.ToString()} {DateTime.Now - starttime}");
StartProcess();
if (IsAutomatedClient) ShowProcessStatusbar();
Status = ClientStatus.Created;
break;
case var expression when (Status < ClientStatus.Injected):
Console.WriteLine($"{Status.ToString()} {DateTime.Now - starttime}");
if (!Process.WaitForState(GwGameProcess.GameStatus.loginwindow_prelogin))
{
Status = ClientStatus.Crash;
}
Console.WriteLine($"{Status.ToString()} {DateTime.Now - starttime}");
InjectDlls();
Status = ClientStatus.Injected;
break;
case var expression when (Status < ClientStatus.MutexClosed):
Console.WriteLine($"{Status.ToString()} {DateTime.Now - starttime}");
CloseMutex();
Status = ClientStatus.MutexClosed;
break;
case var expression when (Status < ClientStatus.Login):
Console.WriteLine($"{Status.ToString()} {DateTime.Now - starttime}");
if(Account.Settings.IsSteamAccount)
{
if (LBConfiguration.Config.pushgameclientbuttons) PressLoginButton();
}
if (Account.Settings.IsArenaNetAccount && Account.Settings.Loginfile != null)
{
if (LBConfiguration.Config.pushgameclientbuttons) PressLoginButton();
LocalDatManager.ToDefault(account.Settings.Loginfile);
}
else
{
LocalDatManager.ToDefault(null); // Reset symbolic link
}
Status = ClientStatus.Login;
break;
case var expression when (Status < ClientStatus.Running):
Console.WriteLine($"{Status.ToString()} {DateTime.Now - starttime}");
if (IsAutomatedClient) RestoreGFX();
SetProcessPriority();
SetProcessAffinity();
try { if (account.Settings.WinConfig != null) new Thread(Window_Init).Start(); } catch { }
account.Settings.AccountInformation.SetLastLogin();
new Thread(
() =>
{
// Launch TacO & BlisH
try
{
if (account.Settings.StartBlish) LBBlish.LaunchBlishInstance(account);
if (account.Settings.StartTaco) LBTacO.LaunchTacoInstance(account);
}
catch { }
}).Start();
if(IsAutomatedClient)
{
if (Process.WaitForState(GwGameProcess.GameStatus.game_charscreen))
{
Status = ClientStatus.Running;
}
else
{
Status = ClientStatus.Crash;
}
}else
{
Status = ClientStatus.Running;
}
break;
}
}
}
catch (Exception e)
{
RestoreGameSettings();
MessageBox.Show("Account: "+account.Nickname+"\n\n"+ e.Message);
Status = ClientStatus.None;
CrashReporter.ReportCrashToAll(e);
}
if (Status.HasFlag(ClientStatus.Crash)) Status = ClientStatus.None;
}
void RestoreGameSettings()
{
try
{
GFXManager.RestoreDefault();
}
catch
{
}
try
{
LocalDatManager.ToDefault(account.Settings.Loginfile);
}
catch
{
}
}
//UI functions
public BitmapImage StatusToIcon
{
get
{
if (Status >= ClientStatus.Running)
return new BitmapImage(new Uri("pack://application:,,,/Resources/Icons/running.png", UriKind.RelativeOrAbsolute));
if (Status > ClientStatus.None)
return new BitmapImage(new Uri("pack://application:,,,/Resources/Icons/loading.png", UriKind.RelativeOrAbsolute));
return new BitmapImage(new Uri("pack://application:,,,/Resources/Icons/idle.png", UriKind.RelativeOrAbsolute));
}
set
{
StatusToIcon = value;
}
}
}
}