This repository was archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cs
More file actions
266 lines (247 loc) · 9.17 KB
/
Copy pathMain.cs
File metadata and controls
266 lines (247 loc) · 9.17 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
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
using GTA;
using GTA.Native;
using System.Windows.Forms;
using System;
using System.IO;
using System.Collections.Generic;
public class VigilanteMissions: Script
{
bool isPlayerInStoppedPoliceVehicle = false;
bool isMenuOpenable = false;
bool isInStationComputer = false;
bool rewardEnabled = false;
bool filterEnabled = false;
static Menu menu;
public static Controls AccessComputerControl { get; private set; }
public static Controls InteractionControl { get; private set; }
public static Controls CancelMissionControl { get; private set; }
ScriptSettings iniFile;
int startTime;
int currentTime;
public static int jokerMissionCount = 15;
string[] vehicleModels = new string[200];
List<VehicleHash> vehicleHashes = new List<VehicleHash>();
public static bool WOVCompatibility { get; private set; }
public VigilanteMissions()
{
iniFile = ScriptSettings.Load("scripts\\VigilanteMissionsConfig.ini");
AccessComputerControl = iniFile.GetValue("Controls", "AccessComputer", Controls.INPUT_CONTEXT);
CancelMissionControl = iniFile.GetValue("Controls", "CancelMission", Controls.INPUT_SWITCH_VISOR);
InteractionControl = iniFile.GetValue("Controls", "Interact", Controls.INPUT_CONTEXT);
rewardEnabled = iniFile.GetValue("Gameplay", "RewardEnabled", false);
filterEnabled = iniFile.GetValue("Gameplay", "FilterOn", false);
vehicleModels = iniFile.GetAllValues<string>("Gameplay", "VehicleModels");
WOVCompatibility = iniFile.GetValue("Settings", "WorldOfVarietyCompatibility", false);
vehicleModels = vehicleModels[0].Split(',');
for (var i = 0; i < vehicleModels.Length; i++)
{
if (!Enum.TryParse<VehicleHash>(vehicleModels[i], out var parsedHash))
{
continue;
} else
{
vehicleHashes.Add(parsedHash);
}
}
ReadProgress();
new MissionWorld(this);
menu = new Menu();
AddJoker();
Tick += (o, e) =>
{
menu.menuPool.Process();
IsPlayerDead();
IsPlayerIsInPoliceCar();
IsPlayerInStationComputer();
SetIsMenuOpenable();
ShowOpenMenuMessage();
};
Tick += UpdateMenuItemTitle;
Tick += ControlWatch;
Tick += UpdateMenuItemTitle;
Aborted += ScriptAborted;
}
void ScriptAborted(object o, EventArgs e)
{
if (MissionWorld.isMissionActive)
{
MissionWorld.QuitMission();
}
}
void UpdateMenuItemTitle(object o, EventArgs e)
{
if (Progress.jokerKilled && menu.LoseCopsAdded)
{
menu.UpdateLoseCopsTitle();
} else if (Progress.jokerKilled && !menu.LoseCopsAdded)
{
menu.AddLoseCops();
}
}
void ControlWatch(object o, EventArgs e)
{
if (Function.Call<bool>(Hash.IS_CONTROL_JUST_PRESSED, 0, CancelMissionControl) && MissionWorld.isMissionActive)
{
startTime = Game.GameTime;
}
if (Function.Call<bool>(Hash.IS_CONTROL_PRESSED, 0, CancelMissionControl) && MissionWorld.isMissionActive)
{
currentTime = Game.GameTime - startTime;
if (currentTime >= 3000)
{
GTA.UI.Screen.ShowSubtitle("~r~Vigilante mission canceled.");
MissionWorld.QuitMission();
}
}
if (Function.Call<bool>(Hash.IS_CONTROL_JUST_RELEASED, 0, AccessComputerControl) && !menu.menuPool.AreAnyVisible && isMenuOpenable)
{
menu.mainMenu.Visible = true;
}
}
void ShowOpenMenuMessage()
{
if (isMenuOpenable)
{
if (menu.menuPool.AreAnyVisible)
{
return;
}
GTA.UI.Screen.ShowHelpTextThisFrame($"Press ~{AccessComputerControl}~ to access the police computer");
} else
{
if (menu.menuPool.AreAnyVisible)
{
menu.menuPool.HideAll();
}
}
}
void SetIsMenuOpenable()
{
isMenuOpenable = isPlayerInStoppedPoliceVehicle || isInStationComputer;
}
void IsPlayerInStationComputer()
{
isInStationComputer = StationComputers.IsNearPoliceComputer(Game.Player.Character);
}
void IsPlayerIsInPoliceCar()
{
bool isInVehicle = false;
if (Progress.jokerKilled && rewardEnabled)
{
if (filterEnabled)
{
var currentVehicle = Game.Player.Character.CurrentVehicle;
if (currentVehicle != null)
{
foreach (VehicleHash model in vehicleHashes)
{
if (currentVehicle.Model == new Model(model))
{
isInVehicle = true;
}
}
} else
{
isInVehicle = false;
}
} else
{
isInVehicle = Game.Player.Character.IsInVehicle();
}
} else
{
isInVehicle = Game.Player.Character.IsInPoliceVehicle;
}
if (isInVehicle)
{
var currentVehicle = Game.Player.Character.CurrentVehicle;
isInVehicle = currentVehicle.Driver == Game.Player.Character;
}
isPlayerInStoppedPoliceVehicle = isInVehicle && Game.Player.Character.CurrentVehicle.IsStopped;
}
void IsPlayerDead()
{
if (Game.Player.IsDead && MissionWorld.isMissionActive)
{
MissionWorld.QuitMission();
Progress.missionsFailedCount += 1;
SaveProgress();
}
}
public static void AddJoker()
{
if (Progress.jokerUnlocked && !menu.jokerAdded)
{
menu.AddJoker();
}
}
public static void SaveProgress()
{
GTA.UI.LoadingPrompt.Show("Saving vigilante missions progress");
try
{
var currDir = Directory.GetCurrentDirectory();
var fileDir = $"{currDir}\\scripts\\VigilanteMissions\\progress.data";
if (!Directory.Exists($"{currDir}\\scripts\\VigilanteMissions"))
{
Directory.CreateDirectory($"{currDir}\\scripts\\VigilanteMissions");
}
using (BinaryWriter writer = new BinaryWriter(File.Open(fileDir, FileMode.OpenOrCreate, FileAccess.Write)))
{
writer.Write(Progress.jokerUnlocked);
writer.Write(Progress.jokerUnlockedMessageSent);
writer.Write(Progress.completedMostWantedMissionsCount);
writer.Write(Progress.jokerKilled);
writer.Write(Progress.completedCurrentCrimesMissionsCount);
writer.Write(Progress.enemiesKilledCount);
writer.Write(Progress.missionsFailedCount);
}
} catch (Exception)
{
GTA.UI.Notification.Show(GTA.UI.NotificationIcon.Lester, "Lester", "Vigilante missions", "Fuck, there was an error saving your Vigilante Missions progress. Any unsaved progress will be lost after you close the game.");
} finally
{
Wait(2500);
GTA.UI.LoadingPrompt.Hide();
}
}
public static void ReadProgress()
{
try
{
var currDir = Directory.GetCurrentDirectory();
var fileDir = $"{currDir}\\scripts\\VigilanteMissions\\progress.data";
if (!File.Exists(fileDir))
{
Progress.jokerUnlocked = false;
Progress.jokerUnlockedMessageSent = false;
Progress.completedMostWantedMissionsCount = 0;
Progress.jokerKilled = false;
Progress.completedCurrentCrimesMissionsCount = 0;
Progress.enemiesKilledCount = 0;
Progress.missionsFailedCount = 0;
return;
}
using (BinaryReader reader = new BinaryReader(File.OpenRead(fileDir)))
{
Progress.jokerUnlocked = reader.ReadBoolean();
Progress.jokerUnlockedMessageSent = reader.ReadBoolean();
Progress.completedMostWantedMissionsCount = reader.ReadInt32();
Progress.jokerKilled = reader.ReadBoolean();
Progress.completedCurrentCrimesMissionsCount = reader.ReadInt32();
Progress.enemiesKilledCount = reader.ReadInt32();
Progress.missionsFailedCount = reader.ReadInt32();
}
} catch(Exception)
{
Progress.jokerUnlocked = false;
Progress.jokerUnlockedMessageSent = false;
Progress.completedMostWantedMissionsCount = 0;
Progress.jokerKilled = false;
Progress.completedCurrentCrimesMissionsCount = 0;
Progress.enemiesKilledCount = 0;
Progress.missionsFailedCount = 0;
//GTA.UI.Notification.Show(GTA.UI.NotificationIcon.Lester, "Lester", "Vigilante missions", "I couldn't read your vigilante missions progress file. Your progress for the last most wanted is lost!");
}
}
}