-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntryPoint.cs
More file actions
499 lines (448 loc) · 25 KB
/
EntryPoint.cs
File metadata and controls
499 lines (448 loc) · 25 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
using Rage;
using RAGENativeUI;
using RAGENativeUI.Elements;
using RAGENativeUI.PauseMenu;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
[assembly: Rage.Attributes.Plugin("HAHTDisplay", Description = "A plugin displaying the player's life and armour with an icon and its value. Also add an hunger and thirst system", Author = "SSStuart", PrefersSingleInstance = true, SupportUrl = "https://ssstuart.net/discord")]
namespace HealthArmourDisplay
{
public class EntryPoint
{
public static string pluginName = "HAHTDisplay";
public static string pluginVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
private static MenuPool myMenuPool;
private static UIMenu storeMenu;
private static UIMenu inventoryMenu;
private static readonly List<List<float>> storesLocations = new List<List<float>>();
private static bool storeHelpDisplayed = false;
private static List<List<string>> foodsAndDrinks;
//private static Rage.Graphics graphics;
public static void Main()
{
Game.LogTrivial($"{pluginName} plugin v{pluginVersion} has been loaded.");
Settings.LoadSettings();
UpdateChecker.CheckForUpdates();
GameFiber.StartNew(delegate
{
Random random = new Random();
string patternRGB = @"^\d{1,3}\s?,\s?\d{1,3}\s?,\s?\d{1,3}$";
Color healthColor, armourColor, hungerColor, thirstColor;
if (Regex.Match(Settings.HealthColor, patternRGB, RegexOptions.IgnorePatternWhitespace).Success)
{
string[] configColor = Settings.HealthColor.Split(',');
int[] configColorInt = Array.ConvertAll(configColor, int.Parse);
healthColor = Color.FromArgb(configColorInt[0], configColorInt[1], configColorInt[2]);
}
else if (Enum.TryParse(Settings.HealthColor, out HudColor healthColorHUD))
{
healthColor = healthColorHUD.GetColor();
}
else
{
healthColor = HudColor.RadarHealth.GetColor();
}
if (Regex.Match(Settings.ArmourColor, patternRGB, RegexOptions.IgnorePatternWhitespace).Success) {
string[] configColor = Settings.ArmourColor.Split(',');
int[] configColorInt = Array.ConvertAll(configColor, int.Parse);
armourColor = Color.FromArgb(configColorInt[0], configColorInt[1], configColorInt[2]);
}
else if (Enum.TryParse(Settings.ArmourColor, true, out HudColor armourColorHUD))
{
armourColor = armourColorHUD.GetColor();
}
else
{
armourColor = HudColor.RadarArmour.GetColor();
}
if (Regex.Match(Settings.HungerColor, patternRGB, RegexOptions.IgnorePatternWhitespace).Success) {
string[] configColor = Settings.HungerColor.Split(',');
int[] configColorInt = Array.ConvertAll(configColor, int.Parse);
hungerColor = Color.FromArgb(configColorInt[0], configColorInt[1], configColorInt[2]);
}
else if (Enum.TryParse(Settings.HungerColor, true, out HudColor hungerColorHUD))
{
hungerColor = hungerColorHUD.GetColor();
}
else
{
hungerColor = HudColor.OrangeLight.GetColor();
}
if (Regex.Match(Settings.ThirstColor, patternRGB, RegexOptions.IgnorePatternWhitespace).Success) {
string[] configColor = Settings.ThirstColor.Split(',');
int[] configColorInt = Array.ConvertAll(configColor, int.Parse);
thirstColor = Color.FromArgb(configColorInt[0], configColorInt[1], configColorInt[2]);
}
else if (Enum.TryParse(Settings.ThirstColor, true, out HudColor thirstColorHUD))
{
thirstColor = thirstColorHUD.GetColor();
}
else
{
thirstColor = HudColor.BlueLight.GetColor();
}
Common.EFont fontFamily = Settings.FontFamily;
float fontSize = Settings.FontSize;
int hunger = 100;
int thirst = 100;
float hungerDepletionMult = 1;
float thirstDepletionMult = 1.5f;
uint lastHungerUpdate = 0;
uint lastThirstUpdate = 0;
List<string> storesLocationsString = Settings.StoreLocations.Split('|').ToList();
foreach (var coordinates in storesLocationsString)
{
bool xOk = float.TryParse(coordinates.Split(',')[0], out float x);
bool yOk = float.TryParse(coordinates.Split(',')[1], out float y);
bool zOk = float.TryParse(coordinates.Split(',')[2], out float z);
if (xOk && yOk && zOk)
storesLocations.Add(new List<float> { x, y, z });
else
Game.LogTrivial("Error parsing store location : " + coordinates);
}
foodsAndDrinks = new List<List<string>>();
List<string> drinksString = Settings.Drinks.Split('|').ToList();
foreach (var drink in drinksString)
{
List<string> drinkList = new List<string>(drink.Split(':').ToList())
{
"drink",
"0"
};
foodsAndDrinks.Add(drinkList);
}
List<string> foodsString = Settings.Foods.Split('|').ToList();
foreach (var food in foodsString)
{
List<string> foodList = new List<string>(food.Split(':').ToList())
{
"food",
"0"
};
foodsAndDrinks.Add(foodList);
}
int savedInventoryLenght = Settings.Inventory.Split('|').Length;
if (savedInventoryLenght == foodsAndDrinks.Count) {
int itemindex = 0;
foreach (var inventoryItem in foodsAndDrinks) {
inventoryItem[3] = Settings.Inventory.Split('|')[itemindex].Trim();
itemindex++;
}
}
int playerMaxHealth = Game.LocalPlayer.Character.MaxHealth - 100; // Player is killed by game when player health is under 100
double playerHealthPercent;
Point offset = new Point(Settings.BaseOffsetHorizontal, Game.Resolution.Height - Settings.BaseOffsetVertical);
Game.LogTrivial("Stores Locations :");
foreach (var loc in storesLocations)
{
Game.LogTrivial(loc[0] + " " + loc[1] + " " + loc[2]);
}
Game.LogTrivial("------------------");
// Menu
myMenuPool = new MenuPool();
storeMenu = new UIMenu("Store", "~b~Drinks and snacks");
myMenuPool.Add(storeMenu);
// start the fiber which will handle drawing and processing the menus
GameFiber.StartNew(ProcessMenus);
foreach (var foodAndDrink in foodsAndDrinks)
{
Color itemcolor;
if (foodAndDrink[2] == "food")
itemcolor = hungerColor;
else
itemcolor = thirstColor;
UIMenuItem storeItem = new UIMenuItem(foodAndDrink[0].Trim(), "$" + foodAndDrink[1].Trim())
{
ForeColor = itemcolor
};
storeMenu.AddItem(storeItem);
storeItem.Activated += (menu, item) =>
{
foodsAndDrinks[storeMenu.CurrentSelection][3] = (int.Parse(foodsAndDrinks[storeMenu.CurrentSelection][3]) + 1).ToString();
SaveInventory();
};
}
inventoryMenu = new UIMenu("Inventory", "~b~Consumables");
myMenuPool.Add(inventoryMenu);
foreach (var foodAndDrink in foodsAndDrinks)
{
Color itemcolor;
if (foodAndDrink[2] == "food")
itemcolor = hungerColor;
else
itemcolor = thirstColor;
UIMenuItem invItem = new UIMenuItem(foodAndDrink[0].Trim(), foodAndDrink[3] + " in your inventory")
{
ForeColor = itemcolor
};
if (int.Parse(foodAndDrink[3]) < 1)
invItem.Enabled = false;
inventoryMenu.AddItem(invItem);
invItem.Activated += (menu, item) =>
{
foodsAndDrinks[inventoryMenu.CurrentSelection][3] = (int.Parse(foodsAndDrinks[inventoryMenu.CurrentSelection][3]) - 1).ToString();
if (foodsAndDrinks[inventoryMenu.CurrentSelection][2] == "food")
{
if (Settings.HungerAnimationEnabled)
{
Rage.Object foodItem = new Rage.Object(Settings.HungerAnimProp, Game.LocalPlayer.Character.Position)
{
IsPersistent = false
};
foodItem.AttachTo(Game.LocalPlayer.Character, Game.LocalPlayer.Character.GetBoneIndex(PedBoneId.RightHand), new Vector3(0.14f, 0.05f, -0.04f), new Rotator(0f, 0f, 0f));
Game.LocalPlayer.Character.Tasks.PlayAnimation(Settings.HungerAnimDictio, Settings.HungerAnimName, 8f, AnimationFlags.UpperBodyOnly).WaitForCompletion();
foodItem.Detach();
}
hunger = Math.Min(hunger + 50, 100);
}
else if (foodsAndDrinks[inventoryMenu.CurrentSelection][2] == "drink")
{
if (Settings.ThirstAnimationEnabled)
{
Rage.Object drinkBottle = new Rage.Object(Settings.ThirstAnimProp, Game.LocalPlayer.Character.Position)
{
IsPersistent = false
};
drinkBottle.AttachTo(Game.LocalPlayer.Character, Game.LocalPlayer.Character.GetBoneIndex(PedBoneId.RightHand), new Vector3(0.14f, 0.03f, -0.03f), new Rotator(90f, 180f, 0f));
Game.LocalPlayer.Character.Tasks.PlayAnimation(Settings.ThirstAnimDictio, Settings.ThirstAnimName, 1f, AnimationFlags.UpperBodyOnly).WaitForCompletion();
drinkBottle.Detach();
}
thirst = Math.Min(thirst + 50, 100);
}
UpdateInventoryMenu();
};
}
while (true)
{
GameFiber.Yield();
if (Game.LocalPlayer.Character.IsAlive && !Game.IsPaused)
{
// CIRCLE MINIMAP
// Health
playerHealthPercent = (Game.LocalPlayer.Character.Health - 100) * 100 / playerMaxHealth;
// Border
Sprite.Draw("commonmenu", "shop_health_icon_a", new Point(offset.X + Settings.HealthIconHorizontal - 4, offset.Y - Settings.HealthIconVertical - 4), new Size(58, 58), 0f, Color.FromArgb(Math.Min(255 - (int)(playerHealthPercent * 2.5), 255), Color.Red));
// Text
ResText.Draw(playerHealthPercent.ToString(), new Point(offset.X + Settings.HealthTextHorizontal, offset.Y - Settings.HealthTextVertical), fontSize, healthColor, Common.EFont.Pricedown, false);
// Icon
Sprite.Draw("commonmenu", "shop_health_icon_b", new Point(offset.X + Settings.HealthIconHorizontal, offset.Y - Settings.HealthIconVertical), new Size(50, 50), 0f, healthColor);
// Armour
// Border
Sprite.Draw("commonmenu", "shop_armour_icon_a", new Point(offset.X + Settings.ArmourIconHorizontal - 4, offset.Y - Settings.ArmourIconVertical - 4), new Size(58, 58), 0f, Color.FromArgb(Math.Min((int)(Game.LocalPlayer.Character.Armor * 2.5), 255), armourColor));
// Icon
Sprite.Draw("commonmenu", "shop_armour_icon_b", new Point(offset.X + Settings.ArmourIconHorizontal, offset.Y - Settings.ArmourIconVertical), new Size(50, 50), 0f, Color.FromArgb(Game.LocalPlayer.Character.Armor == 0 ? 50 : 255, armourColor));
// Text
ResText.Draw(Game.LocalPlayer.Character.Armor.ToString(), new Point(offset.X + Settings.ArmourTextHorizontal, offset.Y - Settings.ArmourTextVertical), fontSize, Color.FromArgb(Game.LocalPlayer.Character.Armor == 0 ? 50 : 255, armourColor), Common.EFont.Pricedown, false);
// Hunger
// Icon
Sprite.Draw("commonmenu", "shop_health_icon_b", new Point(offset.X + Settings.HungerIconHorizontal, offset.Y - Settings.HungerIconVertical), new Size(50, 50), 0f, hungerColor);
// Text
ResText.Draw(hunger.ToString(), new Point(offset.X + Settings.HungerTextHorizontal, offset.Y - Settings.HungerTextVertical), fontSize, hungerColor, Common.EFont.Pricedown, false);
// Thirst
// Text
ResText.Draw(thirst.ToString(), new Point(offset.X + Settings.ThirstTextHorizontal, offset.Y - Settings.ThirstTextVertical), fontSize, thirstColor, Common.EFont.Pricedown, false);
// Icon
Sprite.Draw("commonmenu", "shop_health_icon_b", new Point(offset.X + Settings.ThirstIconHorizontal, offset.Y - Settings.ThirstIconVertical), new Size(50, 50), 0f, thirstColor);
// SQUARE MINIMAP
/*Sprite.Draw("commonmenu", "bettingbox_centre", new Point(offset.X - 40, offset.Y + 4), new Size(270, 50), 0f, Color.FromArgb(100, Color.Black));
Sprite.Draw("commonmenu", "shop_health_icon_b", offset, new Size(50, 50), 0f, Color.LightCoral);
ResText.Draw((Game.LocalPlayer.Character.Health-100).ToString(), new Point(offset.X + 60, offset.Y + 12), 0.3f, Color.LightCoral, Common.EFont.ChaletLondon, true);
Sprite.Draw("commonmenu", "shop_armour_icon_b", new Point(offset.X + 100, offset.Y), new Size(50, 50), 0f, Color.LightBlue);
ResText.Draw(Game.LocalPlayer.Character.Armor.ToString(), new Point(offset.X + 160, offset.Y + 12), 0.3f, Color.LightBlue, Common.EFont.ChaletLondon, true);*/
switch (Game.LocalPlayer.Character)
{
case Ped player when player.IsSprinting:
hungerDepletionMult = 0.2f;
thirstDepletionMult = 0.3f;
break;
case Ped player when player.IsRunning:
hungerDepletionMult = 0.5f;
thirstDepletionMult = 0.7f;
break;
case Ped player when player.IsSwimming:
hungerDepletionMult = 0.8f;
thirstDepletionMult = 0.8f;
break;
case Ped player when player.IsDiving:
hungerDepletionMult = 0.3f;
thirstDepletionMult = 0.5f;
break;
default:
hungerDepletionMult = 1.0f;
thirstDepletionMult = 1.0f;
break;
}
// Create a new game fiber to show the stores locations
GameFiber.StartNew(delegate
{
foreach (var loc in storesLocations)
{
Vector3 storeLocation = new Vector3(loc[0], loc[1], loc[2]);
float distance = Game.LocalPlayer.Character.Position.DistanceTo(storeLocation);
if (distance < 50)
{
Rage.Native.NativeFunction.Natives.DRAW_MARKER(1, storeLocation.X, storeLocation.Y, storeLocation.Z, 0f, 0f, 0f, 0f, 0f, 0f, 2f, 2f, 1f, 255, 194, 170, 100, false, false, 2, true, 0, 0, false);
}
if (distance < 2 && !storeHelpDisplayed)
{
Game.DisplayHelp("Press ~b~"+Settings.StoreKey+"~w~ to buy food and drinks");
storeHelpDisplayed = true;
}else { storeHelpDisplayed = false;}
}
});
if (lastHungerUpdate + Settings.HungerDepletionSpeed * 100 * hungerDepletionMult < Game.GameTime)
{
lastHungerUpdate = Game.GameTime;
if (hunger < 20 && Settings.AutoConsume)
{
foreach (var foodAndDrink in foodsAndDrinks)
{
if (foodAndDrink[2] == "food" && int.Parse(foodAndDrink[3]) > 0)
{
foodsAndDrinks[foodsAndDrinks.IndexOf(foodAndDrink)][3] = (int.Parse(foodAndDrink[3]) - 1).ToString();
hunger = Math.Min(hunger + 50, 100);
break;
}
}
}
if (hunger > 0)
hunger--;
else if (hunger == 0)
{
int randomValue = random.Next(0, 100);
if (randomValue > (Game.LocalPlayer.Character.Health - 75))
{
Game.LocalPlayer.Character.IsRagdoll = true;
}
if (randomValue > 10 && randomValue < 50)
{
Game.LocalPlayer.Character.Health -= 1;
}
else if (randomValue > 50 && Game.LocalPlayer.Character.IsRagdoll)
{
Game.LocalPlayer.Character.IsRagdoll = false;
}
}
}
if (lastThirstUpdate + Settings.ThirstDepletionSpeed * 100 * thirstDepletionMult < Game.GameTime)
{
lastThirstUpdate = Game.GameTime;
if (thirst < 20 && Settings.AutoConsume)
{
foreach (var foodAndDrink in foodsAndDrinks)
{
if (foodAndDrink[2] == "drink" && int.Parse(foodAndDrink[3]) > 0)
{
foodsAndDrinks[foodsAndDrinks.IndexOf(foodAndDrink)][3] = (int.Parse(foodAndDrink[3]) - 1).ToString();
thirst = Math.Min(thirst + 50, 100);
break;
}
}
}
if (thirst > 0)
thirst--;
else if (thirst == 0)
{
int randomValue = random.Next(0, 100);
if (randomValue > (Game.LocalPlayer.Character.Health - 80))
{
Game.FadeScreenOut(1500, true);
Game.FadeScreenIn(2000, true);
}
if (randomValue > 10 && randomValue < 50)
{
Game.LocalPlayer.Character.Health -= 1;
}
}
}
}
else if (Game.LocalPlayer.Character.IsDead)
{
hunger = 100;
thirst = 100;
}
}
});
}
private static void ProcessMenus()
{
while (true)
{
GameFiber.Yield();
myMenuPool.ProcessMenus();
bool playerIsInStore = false;
foreach(var storePos in storesLocations)
{
if (Game.LocalPlayer.Character.Position.DistanceTo(new Vector3(storePos[0], storePos[1], storePos[2])) < 2)
{
playerIsInStore = true;
}
}
if (Game.IsKeyDown(Settings.StoreKey) && !Game.IsControlKeyDownRightNow) // the open/close trigger
{
if (storeMenu.Visible)
{
// close the menu
storeMenu.Visible = false;
}
else if (!UIMenu.IsAnyMenuVisible && !TabView.IsAnyPauseMenuVisible && playerIsInStore) // check that no menus are visible
{
// open the menu
storeMenu.Visible = true;
}
}
if (Game.IsKeyDown(Settings.InventoryKey) && Game.IsKeyDownRightNow(Settings.InventoryModifier)) {
if (inventoryMenu.Visible) {
inventoryMenu.Visible = false;
} else if (!UIMenu.IsAnyMenuVisible && !TabView.IsAnyPauseMenuVisible) {
UpdateInventoryMenu();
inventoryMenu.Visible = true;
}
}
}
}
private static void UpdateInventoryMenu()
{
for (int i = 0; i < foodsAndDrinks.Count; i++)
{
if (int.Parse(foodsAndDrinks[i][3]) < 1)
{
inventoryMenu.MenuItems[i].Enabled = false;
inventoryMenu.MenuItems[i].Description = "You don't have any " + foodsAndDrinks[i][0].Trim() + " in your inventory";
} else
{
inventoryMenu.MenuItems[i].Enabled = true;
inventoryMenu.MenuItems[i].Description = "You have " + foodsAndDrinks[i][3] + " " + foodsAndDrinks[i][0].Trim() + " in your inventory";
}
}
SaveInventory();
}
private static void SaveInventory()
{
string inventoryString = "";
foreach (List<string> inventoryItem in foodsAndDrinks)
{
inventoryString += inventoryItem[3] + " | ";
}
inventoryString = inventoryString.Remove(inventoryString.Length - 3);
Settings.SaveSettings("Other", "Inventory", inventoryString);
}
/*static void drawSprites(object sender, GraphicsEventArgs e)
{
Sprite.DrawTexture(Game.CreateTextureFromFile(@"D:\Jeux\Rockstar Games\Grand Theft Auto V\plugins\thirst.png"), new Point(10, 10), new Size(100, 100), e.Graphics);
Game.RawFrameRender -= drawSprites;
}*/
}
public static class ReloadHADOverlayCommand
{
[Rage.Attributes.ConsoleCommand]
public static void Command_ReloadHADOverlay()
{
Game.ReloadActivePlugin();
}
}
}