-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cs
More file actions
193 lines (158 loc) · 7.46 KB
/
Main.cs
File metadata and controls
193 lines (158 loc) · 7.46 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
using System.IO;
using System.Text;
using System.Xml.Linq;
using LSPD_First_Response.Mod.API;
using Rage;
using ReportsPlus.Utils;
using ReportsPlus.Utils.ALPR;
using ReportsPlus.Utils.Data;
using ReportsPlus.Utils.Menu;
using static ReportsPlus.Utils.Data.EventUtils;
using ALPRUtils = ReportsPlus.Utils.ALPR.ALPRUtils;
using Functions = LSPD_First_Response.Mod.API.Functions;
namespace ReportsPlus
{
public class Main : Plugin
{
/*
UPDATE: Update Version
*/
private const string Version = "v1.5.3-alpha";
public const string FileDataFolder = "ReportsPlus/data";
public const string FileResourcesFolder = "Plugins/lspdfr/ReportsPlus/";
internal static bool IsOnDuty;
public static bool CachedIsInVehicle;
public static XDocument CurrentIdDoc;
public static XDocument CalloutDoc;
public static bool HasStopThePed;
public static bool HasPolicingRedefined;
public static bool HasCommonDataFramework;
private static bool _hasCalloutInterface;
private static GameFiber _primaryFiber;
private static GameFiber _playerStateCheckFiber;
internal static Ped LocalPlayer => Game.LocalPlayer.Character;
internal static Vehicle LocalPlayerVehicle => LocalPlayer?.CurrentVehicle;
public override void Initialize()
{
Functions.OnOnDutyStateChanged += OnOnDutyStateChangedHandler;
Game.LogTrivial("ReportsPlusListener Plugin Initialized. Version: " + Version);
}
private void OnOnDutyStateChangedHandler(bool onDuty)
{
IsOnDuty = onDuty;
Game.LogTrivial("ReportsPlusListener: IsOnDuty State Changed: '" + IsOnDuty + "'");
if (!onDuty)
{
RunFullCleanup();
return;
}
Misc.CalloutIds?.Clear();
Misc.PedAddresses?.Clear();
Misc.PedHeights?.Clear();
Misc.PedWeights?.Clear();
Misc.PedExpirations?.Clear();
Misc.PedLicenseNumbers?.Clear();
ConfigUtils.LoadSettings();
if (!Directory.Exists(FileResourcesFolder))
Directory.CreateDirectory(FileResourcesFolder);
Misc.CopyImageResourcesIfMissing();
LicensePlateDisplay.InitializeLicensePlateDisplay();
ConfigUtils.CreateFiles();
if (File.Exists(DataCollection.CitationSignalFilePath))
{
Game.LogTrivial("ReportsPlusListener: Found Old CitationSignalFile, Deleting");
File.Delete(DataCollection.CitationSignalFilePath);
}
var checksOutcome = RunPluginChecks();
MenuProcessing.InitializeMenu();
_primaryFiber = GameFiber.StartNew(() =>
{
_playerStateCheckFiber = GameFiber.StartNew(UpdatePlayerState, "ReportsPlus-UpdatePlayerState");
DataCollection.TrafficStopCollectionFiber = GameFiber.StartNew(DataCollection.TrafficStopCollection, "ReportsPlus-TrafficStopCollection");
DataCollection.KeyCollectionFiber = GameFiber.StartNew(DataCollection.KeyCollection, "ReportsPlus-KeyCollection");
MenuProcessing.MenuProcessingFiber = GameFiber.StartNew(MenuProcessing.ProcessMenus, "ReportsPlus-MenuProcessing");
DataCollection.WorldDataCollectionFiber = GameFiber.StartNew(DataCollection.WorldDataCollection, "ReportsPlus-DataCollection");
DataCollection.SignalFileCheckFiber = GameFiber.StartNew(DataCollection.SignalFileCheck, "ReportsPlus-SignalFileCheck");
Game.DisplayNotification("web_lossantospolicedept", "web_lossantospolicedept", "~w~ReportsPlusListener", "By: ~y~Guess1m", "~g~Version: " + Version + " Loaded!" + "\n" + "~w~Menu Keybind: ~y~" + MenuProcessing.MainMenuBind + "\n" + checksOutcome);
Game.LogTrivial("ReportsPlusListener: " + Version + ", Loaded Successfully");
}, "ReportsPlusListener");
}
private StringBuilder RunPluginChecks()
{
var builder = new StringBuilder();
_hasCalloutInterface = ConfigUtils.IsPluginInstalled("CalloutInterface");
HasStopThePed = ConfigUtils.IsPluginInstalled("StopThePed");
HasPolicingRedefined = ConfigUtils.IsPluginInstalled("PolicingRedefined");
HasCommonDataFramework = ConfigUtils.IsPluginInstalled("CommonDataFramework");
if (_hasCalloutInterface)
{
EstablishCiEvent();
Game.LogTrivial("ReportsPlusListener: Found Callout Interface");
}
else
{
Game.LogTrivial("ReportsPlusListener: CalloutInterface not found. Required for Callout Functions.");
builder.Append("~r~CalloutInterface Not Found\n~o~- Required for Callout Functions.\n");
}
if (HasPolicingRedefined && HasCommonDataFramework)
{
EstablishEventsPr();
Game.LogTrivial("ReportsPlusListener: Found Policing Redefined and Common Data Framework");
HasStopThePed = false;
}
else
{
Game.LogTrivial("ReportsPlusListener: Policing Redefined/CDF not found, checking for STP");
if (HasStopThePed)
{
EstablishEventsStp();
Game.LogTrivial("ReportsPlusListener: Found StopThePed");
}
else
{
Game.LogTrivial("ReportsPlusListener: StopThePed/PR not found. Using base game functions.");
EstablishEventsBaseGame();
builder.Append("~r~StopThePed/PR Not Found\n~o~- Using base game functions.");
}
}
return builder;
}
public override void Finally()
{
Functions.OnOnDutyStateChanged -= OnOnDutyStateChangedHandler;
RunFullCleanup();
}
private static void UpdatePlayerState()
{
while (IsOnDuty)
{
GameFiber.Wait(2000);
CachedIsInVehicle = LocalPlayer?.IsInAnyVehicle(false) ?? false;
}
}
private static void RunFullCleanup()
{
Misc.CleanupFiber(DataCollection.TrafficStopCollectionFiber);
Misc.CleanupFiber(DataCollection.KeyCollectionFiber);
Misc.CleanupFiber(ALPRUtils.AlprFiber);
Misc.CleanupFiber(DataCollection.WorldDataCollectionFiber);
Misc.CleanupFiber(DataCollection.SignalFileCheckFiber);
Misc.CleanupFiber(DataCollection.ActivePulloverCheckFiber);
Misc.CleanupFiber(MenuProcessing.MenuProcessingFiber);
Misc.CleanupFiber(_primaryFiber);
Misc.CleanupFiber(_playerStateCheckFiber);
ALPRUtils.CleanupAllBlips();
Game.RawFrameRender -= LicensePlateDisplay.OnFrameRender;
CurrentIdDoc?.Save(Path.Combine(FileDataFolder, "currentID.xml"));
CalloutDoc?.Save(Path.Combine(FileDataFolder, "callout.xml"));
Misc.CalloutIds?.Clear();
Misc.PedAddresses?.Clear();
Misc.PedLicenseNumbers?.Clear();
Misc.PedHeights?.Clear();
Misc.PedWeights?.Clear();
Misc.PedExpirations?.Clear();
ALPRUtils.RecentlyScannedPlates?.Clear();
Game.LogTrivial("ReportsPlusListener: Cleaned Up.");
}
}
}