Skip to content

Commit 0d719b4

Browse files
committed
Samll code refactoring + Update Assembly Infos + Update checker
- Updated Assembly Version and name. - Small code refactoring. - Added the Update Checker system. - Added Readme.md
1 parent 2fbe0a2 commit 0d719b4

7 files changed

Lines changed: 141 additions & 22 deletions

File tree

EntryPoint.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
using System.Collections.Generic;
77
using System.Drawing;
88
using System.Linq;
9+
using System.Reflection;
910
using System.Text.RegularExpressions;
1011

11-
[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")]
12-
12+
[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")]
1313

1414
namespace HealthArmourDisplay
1515
{
1616
public class EntryPoint
1717
{
1818
public static string pluginName = "HAHTDisplay";
19-
public static string pluginVersion = "v 0.0.1";
19+
public static string pluginVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
2020

2121
private static MenuPool myMenuPool;
2222
private static UIMenu storeMenu;
@@ -29,10 +29,12 @@ public class EntryPoint
2929

3030
public static void Main()
3131
{
32-
Game.LogTrivial("Health, Armour, Hunger & Thirst Display loaded.");
32+
Game.LogTrivial($"{pluginName} Plugin v{pluginVersion} has been loaded.");
3333

3434
Settings.LoadSettings();
35-
Game.LogTrivial("[" + pluginName + "] Plugin settings loaded.");
35+
Game.LogTrivial($"[{pluginName}] Plugin settings loaded.");
36+
37+
UpdateChecker.CheckForUpdates();
3638

3739
GameFiber.StartNew(delegate
3840
{
@@ -102,7 +104,6 @@ public static void Main()
102104
float thirstDepletionMult = 1.5f;
103105
uint lastHungerUpdate = 0;
104106
uint lastThirstUpdate = 0;
105-
106107

107108
List<string> storesLocationsString = Settings.StoreLocations.Split('|').ToList();
108109
foreach (var coordinates in storesLocationsString)
@@ -148,14 +149,6 @@ public static void Main()
148149
}
149150
}
150151

151-
152-
//Game.RawFrameRender += drawSprites;
153-
154-
/*while (!Game.LocalPlayer.Character.IsOnScreen)
155-
{
156-
GameFiber.Yield();
157-
}
158-
Ped player = Game.LocalPlayer.Character;*/
159152
int playerMaxHealth = Game.LocalPlayer.Character.MaxHealth - 100; // Player is killed by game when player health is under 100
160153
double playerHealthPercent;
161154
Point offset = new Point(Settings.BaseOffsetHorizontal, Game.Resolution.Height - Settings.BaseOffsetVertical);
@@ -193,7 +186,6 @@ public static void Main()
193186
{
194187
foodsAndDrinks[storeMenu.CurrentSelection][3] = (int.Parse(foodsAndDrinks[storeMenu.CurrentSelection][3]) + 1).ToString();
195188
SaveInventory();
196-
// Game.LocalPlayer.Character.Money -= int.Parse(foodsAndDrinks[storeMenu.CurrentSelection][1]);
197189
};
198190
}
199191

HealthArmourDisplay.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,17 @@
7070
<Compile Include="EntryPoint.cs" />
7171
<Compile Include="IniFile.cs" />
7272
<Compile Include="Properties\AssemblyInfo.cs" />
73+
<Compile Include="UpdateChecker.cs" />
7374
</ItemGroup>
7475
<ItemGroup>
7576
<None Include="packages.config" />
77+
<None Include="README.md" />
78+
</ItemGroup>
79+
<ItemGroup>
80+
<Content Include="example.jpg" />
7681
</ItemGroup>
7782
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7883
<PropertyGroup>
79-
<PostBuildEvent>call C:\Users\Stuart\source\repos\HealthArmourDisplay\bin\x64\Debug\Z-[moveToPluginsFolder].bat</PostBuildEvent>
84+
<PostBuildEvent>call C:\Users\SSStuart\source\repos\HealthArmourDisplay\bin\x64\Debug\Z-[moveToPluginsFolder].bat</PostBuildEvent>
8085
</PropertyGroup>
8186
</Project>

IniFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal static class Settings
6363

6464
internal static void LoadSettings()
6565
{
66-
Game.LogTrivial("[LOG]: Loading config file for " + EntryPoint.pluginName + ".");
66+
Game.LogTrivial($"[{EntryPoint.pluginName}] Loading plugin settings...");
6767

6868
ini.Create();
6969
BaseOffsetVertical = ini.ReadInt16("BasePosition", "BaseOffsetVertical", 45);

Properties/AssemblyInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
// Les informations générales relatives à un assembly dépendent de
66
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
77
// associées à un assembly.
8-
[assembly: AssemblyTitle("HealthArmourDisplay")]
8+
[assembly: AssemblyTitle("HAHT Display")]
99
[assembly: AssemblyDescription("")]
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("")]
12-
[assembly: AssemblyProduct("HealthArmourDisplay")]
13-
[assembly: AssemblyCopyright("Copyright © 2024")]
12+
[assembly: AssemblyProduct("HAHT Display")]
13+
[assembly: AssemblyCopyright("")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,5 +32,5 @@
3232
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
3333
// en utilisant '*', comme indiqué ci-dessous :
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
35+
[assembly: AssemblyVersion("0.2.1.0")]
36+
[assembly: AssemblyFileVersion("0.2.1.0")]

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# HAHT Display - *RPH Plugin*
2+
*Health Armour Hunger Thirst*
3+
4+
This RAGE Plugin Hook Plugin adds visual indicators for the player's health, armor, hunger, and thirst. And implement a small hunger/thirst system,
5+
6+
![Overview screenshot](example.jpg)
7+
8+
## How it works
9+
- Icons and value are displayed around the minimap.
10+
- Hunger and thirst values decrease over time (more or less quickly depending on whether the player is running, swimming, etc.).
11+
- You can buy snacks and drinks in the stores around the map (look for the marker and press the key (<kbd>E</kbd> by default)).
12+
- You can consume your snacks/drinks by opening your inventory (<kbd>Ctrl + I</kbd> by default).
13+
14+
## Configuration
15+
You can adjust some values in the `.ini` file :
16+
- ↔ The position and color of the icons/values.
17+
- ⏱ The speed at which hunger/thirst values decreases.
18+
- 🙋‍ The animations to play while eating/drinking.
19+
- 🏪 Stores location and snacks/drinks types.
20+
- ⌨ Keys....
21+
22+
## Prerequisites
23+
- [RAGE Plugin Hook](https://ragepluginhook.net/Downloads.aspx)
24+
- [RAGENativeUI](https://github.com/alexguirre/RAGENativeUI/releases)
25+
26+
## Recommendation
27+
- [Circle HD Minimap](https://www.gta5-mods.com/misc/circle-hd-minimap)

UpdateChecker.cs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using Rage;
2+
using System;
3+
using System.Net.Http;
4+
using System.Text.RegularExpressions;
5+
6+
namespace HealthArmourDisplay
7+
{
8+
public static class UpdateChecker
9+
{
10+
private static readonly string url = "https://ssstuart.net/api/GTAModVersion/HAHT%20Display";
11+
private static readonly HttpClient httpClient = new HttpClient();
12+
private static Version lastVersion = null;
13+
private static readonly Version currentVersion = new Version(EntryPoint.pluginVersion);
14+
private static string updateAvailable = "";
15+
16+
public static void CheckForUpdates()
17+
{
18+
System.Threading.Tasks.Task.Run(async () =>
19+
{
20+
updateAvailable = await CheckUpdate();
21+
});
22+
23+
GameFiber.StartNew(updateNotification);
24+
25+
void updateNotification()
26+
{
27+
do
28+
{
29+
GameFiber.Yield();
30+
31+
if (updateAvailable == "yes")
32+
{
33+
DisplayUpdateNotification();
34+
}
35+
} while (updateAvailable == "");
36+
}
37+
}
38+
39+
private static async System.Threading.Tasks.Task<string> CheckUpdate()
40+
{
41+
try
42+
{
43+
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
44+
45+
HttpResponseMessage response = await httpClient.GetAsync(url);
46+
response.EnsureSuccessStatusCode();
47+
string responseMessage = await response.Content.ReadAsStringAsync();
48+
Match m = new Regex("last_version\":\"([\\d.]+)\"").Match(responseMessage);
49+
50+
if (m.Success)
51+
{
52+
System.Text.RegularExpressions.Group g = m.Groups[1];
53+
CaptureCollection cc = g.Captures;
54+
Capture c = cc[0];
55+
lastVersion = new Version(c.ToString());
56+
57+
Game.LogTrivial($"[{EntryPoint.pluginName}] Current version: {currentVersion}, Latest version: {lastVersion}");
58+
if (currentVersion < lastVersion)
59+
{
60+
Game.LogTrivial($"[{EntryPoint.pluginName}] Update available ! Current version: {currentVersion}, Latest version: {lastVersion}");
61+
return "yes";
62+
}
63+
else if (currentVersion >= lastVersion)
64+
{
65+
Game.LogTrivial($"[{EntryPoint.pluginName}] You are using the latest version ({currentVersion}).");
66+
return "no";
67+
}
68+
69+
}
70+
else
71+
{
72+
Game.LogTrivial($"[{EntryPoint.pluginName}] Update check failed: Could not parse version from response : {responseMessage}");
73+
return "error";
74+
}
75+
}
76+
catch (Exception ex)
77+
{
78+
Game.LogTrivial($"[{EntryPoint.pluginName}] Update check failed: {ex.InnerException}");
79+
return "error";
80+
}
81+
82+
return "error";
83+
}
84+
85+
private static void DisplayUpdateNotification()
86+
{
87+
do
88+
{
89+
GameFiber.Yield();
90+
GameFiber.Sleep(5000);
91+
} while (Game.IsLoading);
92+
Game.DisplayNotification("mpturf", "swap", EntryPoint.pluginName, $"V {lastVersion}", $"~y~Update available !");
93+
}
94+
}
95+
}

example.jpg

355 KB
Loading

0 commit comments

Comments
 (0)