-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
126 lines (111 loc) · 4.39 KB
/
MainForm.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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Media;
using System.Windows.Forms;
namespace BotM
{
public partial class MainForm : Form
{
public static Settings Settings;
FormSettings formSettings;
FormMods formMods;
SoundPlayer rollover = new SoundPlayer(Properties.Resources.mouseover);
SoundPlayer click = new SoundPlayer(Properties.Resources.pop);
public static Dictionary<string, string> ReplacedFiles = new Dictionary<string, string>();
public static void SaveSettings()
{
System.IO.Directory.CreateDirectory(Settings.InstalledModsDirectory);
System.IO.Directory.CreateDirectory(Settings.NotInstalledModsDirectory);
System.IO.Directory.CreateDirectory(Settings.BackupDirectory);
string json = JsonConvert.SerializeObject(Settings, Formatting.Indented);
System.IO.File.WriteAllText("config.json", json);
}
public MainForm(Settings s)
{
if (System.IO.File.Exists("affected.json"))
{
string j = System.IO.File.ReadAllText("affected.json");
ReplacedFiles = JsonConvert.DeserializeObject<Dictionary<string,string>>(j);
}
InitializeComponent();
CenterToScreen();
Settings = s;
formSettings = new FormSettings();
formMods = new FormMods();
formSettings.Visible = false;
formMods.Visible = false;
//sound effects
buttonPlay.MouseEnter += OnButtonHover;
buttonMods.MouseEnter += OnButtonHover;
buttonSettings.MouseEnter += OnButtonHover;
buttonExit.MouseEnter += OnButtonHover;
buttonPlay.MouseClick += ButtonPlay_MouseClick;
buttonMods.MouseClick += ButtonMods_MouseClick;
buttonSettings.MouseClick += ButtonSettings_MouseClick;
//draggable hacks
MouseDown += OnMouseDown;
pictureBox1.MouseDown += OnMouseDown;
label2.MouseDown += OnMouseDown;
FormClosed += MainForm_FormClosed;
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
string json = JsonConvert.SerializeObject(ReplacedFiles, Formatting.Indented);
System.IO.File.WriteAllText("affected.json", json);
}
private void ButtonSettings_MouseClick(object sender, MouseEventArgs e)
{
click.Play();
formSettings.ShowDialog(this);
}
private void ButtonMods_MouseClick(object sender, MouseEventArgs e)
{
click.Play();
formMods.ShowDialog(this);
}
private void ButtonPlay_MouseClick(object sender, MouseEventArgs e)
{
click.Play();
//todo: safety & sanity
new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
WorkingDirectory = new System.IO.FileInfo(Settings.LaunchCommand.Split(' ')[0]).Directory.FullName,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
FileName = "cmd.exe",
Arguments = "/C " + Settings.LaunchCommand
}
}.Start();
if (Settings.CloseOnRun)
{
System.Threading.Thread.Sleep(250);
Application.Exit();
}
}
private void ButtonExit_Click(object sender, EventArgs e)
{
click.Play();
System.Threading.Thread.Sleep(250);
Application.Exit();
}
private void OnButtonHover(object sender, EventArgs e)
{
rollover.Play();
}
//draggable winform hack
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
private void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, 0xA1, 0x2, 0);
}
}
}
}