forked from Flawkee/FlyffUniverse-WebClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlyffWCForm.cs
More file actions
89 lines (81 loc) · 2.79 KB
/
FlyffWCForm.cs
File metadata and controls
89 lines (81 loc) · 2.79 KB
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
using System;
using System.Drawing;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
using System.Text.RegularExpressions;
using System.Threading;
namespace FlyffUniverse_WebClient
{
public partial class FlyffWCForm : Form
{
private static FlyffWCForm _instance;
public ChromiumWebBrowser chromeBrowser;
private Thread buffThread;
private System.Windows.Forms.Timer waitForGameExitTimer, autoHealTimer, autoFollowTimer;
public FlyffWCForm()
{
if (_instance == null) { _instance = this; }
InitializeComponent();
SetArguments();
}
public static FlyffWCForm Instance { get { return _instance; } }
private void Form1_Load(object sender, EventArgs e)
{
this.Shown += new EventHandler(Form1_Shown);
}
private void SetArguments()
{
ArgumentManager.Instance.InitializeArguments();
InitializeChromium();
}
public void InitializeChromium()
{
CefSettings settings = new CefSettings();
Cef.EnableHighDPISupport();
settings.CachePath = ArgumentManager.profilePath;
Cef.Initialize(settings);
chromeBrowser = new ChromiumWebBrowser("https://universe.flyff.com/play");
this.Controls.Add(chromeBrowser);
chromeBrowser.Dock = DockStyle.Fill;
}
private void Form1_Shown(Object sender, EventArgs e)
{
InitWaitForGameExitTimer();
}
public void WaitForGameExit()
{
string pat = "Restart the Game";
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
if (chromeBrowser.IsBrowserInitialized)
{
var task = chromeBrowser.GetTextAsync();
task.ContinueWith(t =>
{
if (!t.IsFaulted)
{
var response = t.Result;
Match m = r.Match(response);
if (m.Success) { Application.Exit(); }
}
});
}
}
public void InitWaitForGameExitTimer()
{
waitForGameExitTimer = new System.Windows.Forms.Timer();
waitForGameExitTimer.Tick += new EventHandler(waitForGameExitTimer_Tick);
waitForGameExitTimer.Interval = 1000; // in miliseconds
waitForGameExitTimer.Start();
}
private void waitForGameExitTimer_Tick(object sender, EventArgs e)
{
Thread t = new Thread(WaitForGameExit);
t.Start();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
Cef.Shutdown();
}
}
}