Repository navigation
Expand file tree
/
Copy pathInstallForm.cs
More file actions
200 lines (185 loc) · 10.3 KB
/
Copy pathInstallForm.cs
File metadata and controls
200 lines (185 loc) · 10.3 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
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
using STALK_IRC.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using Microsoft.Win32;
namespace STALK_IRC
{
public partial class InstallForm : Form
{
string games, lastInstall;
Dictionary<string, string> oldGames = new Dictionary<string, string>();
public InstallForm()
{
InitializeComponent();
}
private void InstallForm_Load(object sender, EventArgs e)
{
games = (string)ClientForm.REGISTRY.GetValue("GameList", "");
foreach (Match match in Regex.Matches(games, @"([^\|]+)\|([^\|]+)"))
{
string game = match.Groups[1].Value;
string path = match.Groups[2].Value;
oldGames[path] = game;
}
lastInstall = (string)ClientForm.REGISTRY.GetValue("LastInstall", "");
textBox1.Text = lastInstall;
}
private void InstallForm_FormClosing(object sender, FormClosingEventArgs e)
{
ClientForm.REGISTRY.SetValue("GameList", games);
ClientForm.REGISTRY.SetValue("LastInstall", lastInstall);
}
private void button2_Click(object sender, EventArgs e)
{
string path = textBox1.Text;
if (path != "")
{
textBox1.BackColor = Color.White;
string game = radioButton4.Checked ? "SoC" : (radioButton1.Checked ? "CS" : (radioButton2.Checked ? "CoP" : "LA"));
if (Install(game, path, false))
{
lastInstall = path;
if (!oldGames.ContainsKey(textBox1.Text))
games += game + "|" + textBox1.Text + "|";
}
}
else
textBox1.BackColor = Color.LightPink;
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (lastInstall != "" && Directory.Exists(lastInstall))
folderBrowserDialog1.SelectedPath = lastInstall;
folderBrowserDialog1.ShowDialog();
textBox1.Text = folderBrowserDialog1.SelectedPath;
}
public static bool Install(string game, string path, bool silent)
{
if (Directory.Exists(path))
if (File.Exists(path + @"\fsgame.ltx"))
{
string configPath = path + @"\gamedata" + ((game == "SoC" || game == "LA") ? @"\config" : @"\configs");
string scriptPath = path + @"\gamedata\scripts";
string texturePath = path + @"\gamedata\textures\ui";
if (!Directory.Exists(configPath + @"\ui"))
Directory.CreateDirectory(configPath + @"\ui");
if (!Directory.Exists(scriptPath))
Directory.CreateDirectory(scriptPath);
if (!Directory.Exists(texturePath))
Directory.CreateDirectory(texturePath);
File.WriteAllText(configPath + @"\ui\ui_chatinput.xml", Resources.chatInputUIXML);
File.WriteAllText(scriptPath + @"\stalk_irc.script", Resources.stalkIRCScript);
File.WriteAllText(scriptPath + @"\stalk_irc_icons.script", Resources.stalkIRCIconsScript);
File.WriteAllBytes(texturePath + @"\stalk_irc_icons.dds", Resources.stalkIRCIcons);
if (game == "CS" || game == "CoP")
{
if (!Directory.Exists(configPath + @"\ui\textures_descr"))
Directory.CreateDirectory(configPath + @"\ui\textures_descr");
File.WriteAllText(configPath + @"\ui\textures_descr\ui_stalk_irc_icons.xml", Resources.stalkIRCIconsXML);
}
// Patching ui_main_menu.script
if (File.Exists(scriptPath + @"\ui_main_menu.script"))
{
string script = File.ReadAllText(scriptPath + @"\ui_main_menu.script");
if (!Regex.Match(script, "stalk_irc").Success)
{
File.Copy(scriptPath + @"\ui_main_menu.script", scriptPath + @"\ui_main_menu.script.bak", true);
Match keypressMatch = Regex.Match(script, @"if\s+keyboard_action\s*==\s*ui_events\s*\.\s*WINDOW_KEY_PRESSED\s+then");
script = script.Insert(keypressMatch.Index + keypressMatch.Length, "\r\n\t\tstalk_irc.onKeypress( dik )");
File.WriteAllText(scriptPath + @"\ui_main_menu.script", script);
}
}
else
File.WriteAllText(scriptPath + @"\ui_main_menu.script",
game == "SoC" ? Resources.socMainMenu : (game == "CS" ? Resources.csMainMenu : (game == "CoP" ? Resources.copMainMenu : Resources.laMainMenu)));
// Patching bind_stalker.script (SoC, CS, CoP) or bind_actor.script (LA)
string bindWhat = scriptPath + (game == "LA" ? @"\bind_actor.script" : @"\bind_stalker.script");
if (File.Exists(bindWhat))
{
string script = File.ReadAllText(bindWhat);
if (!Regex.Match(script, "stalk_irc").Success)
{
File.Copy(bindWhat, bindWhat + ".bak", true);
Match callbackMatch = Regex.Match(script, @"callback\s*\.\s*death\s*,\s*self\s*\.\s*([^\s,]+)");
// Callback already exists
if (callbackMatch.Success)
{
string function = callbackMatch.Groups[1].Value;
Match functionMatch = Regex.Match(script, @"function\s+actor_binder\s*:\s*" + function + @"\(([^\)]+)\)");
string arguments = functionMatch.Groups[1].Value.Trim();
if (arguments.Contains(','))
{
string argument = Regex.Match(arguments, @",\s*([^\s]+)\s*").Groups[1].Value;
script = script.Insert(functionMatch.Index + functionMatch.Length, "\r\n\tstalk_irc.onDeath( " + argument + " )");
}
else
{
script = script.Insert(functionMatch.Index + functionMatch.Length, "\r\n\tstalk_irc.onDeath( who )");
script = script.Insert(functionMatch.Groups[1].Index + functionMatch.Groups[1].Length, ", who");
}
}
// Create new callback
else
{
Match takeItemMatch = Regex.Match(script, @"callback\s*\.\s*take_item_from_box\s*,\s*nil\s*\)");
script = script.Insert(takeItemMatch.Index + takeItemMatch.Length, "\r\n\tself.object:set_callback(callback.death, nil)");
Match takeItemMatch2 = Regex.Match(script, @"callback\s*\.\s*take_item_from_box\s*,\s*self\s*\.\s*([^\s,]+)[^\)]+\)");
script = script.Insert(takeItemMatch2.Index + takeItemMatch2.Length, "\r\n\tself.object:set_callback(callback.death, self.onDeath, self)");
string function = takeItemMatch2.Groups[1].Value;
Match takeItemMatch3 = Regex.Match(script, @"function\s+actor_binder\s*:\s*" + function);
script = script.Insert(takeItemMatch3.Index, "function actor_binder:onDeath( victim, who )\r\n\tstalk_irc.onDeath( who )\r\nend\r\n" +
"----------------------------------------------------------------------------------------------------------------------\r\n");
}
Match updateMatch = Regex.Match(script, @"function\s+actor_binder\s*:\s*update\s*\([^\)]*\)");
script = script.Insert(updateMatch.Index + updateMatch.Length, "\r\n\tstalk_irc.onUpdate()");
File.WriteAllText(bindWhat, script);
}
}
else
File.WriteAllText(bindWhat,
game == "SoC" ? Resources.socBindStalker : (game == "CS" ? Resources.csBindStalker :
(game == "CoP" ? Resources.copBindStalker : Resources.laBindActor)));
if (game == "SoC")
{
if (!Directory.Exists(configPath + @"\misc"))
Directory.CreateDirectory(configPath + @"\misc");
File.WriteAllText(configPath + @"\misc\stalk_irc_clear.ltx", Resources.socInputClear);
File.WriteAllText(configPath + @"\misc\stalk_irc.ltx", Resources.socInputClear);
}
if (!silent)
MessageBox.Show("Mod installed.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
return true;
}
else
{
if (!silent)
MessageBox.Show("fsgame.ltx not found in the specified directory.\nPlease select again.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
else
{
if (!silent)
MessageBox.Show("The specified directory does not exist.\nPlease select again.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
private void InstallForm_HelpButtonClicked(object sender, CancelEventArgs e)
{
e.Cancel = true;
new HelpForm(2).ShowDialog();
}
}
}