Skip to content

Commit 7165d28

Browse files
committed
Update 1.2
1 parent 414d4c4 commit 7165d28

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

ValorantStatus/MainWindow.xaml.cs

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using RestSharp;
1212
using System.Globalization;
1313
using System.Configuration;
14+
using System.Threading;
1415

1516
namespace ValorantRPC
1617
{
@@ -31,6 +32,7 @@ public partial class MainWindow : Window
3132
public MainWindow()
3233
{
3334
InitializeComponent();
35+
this.Dispatcher.UnhandledException += Dispatcher_UnhandledException; ;
3436
icon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().ManifestModule.Name);
3537
//Gets Riot Client Location
3638
string filepath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\Riot Games\\Metadata\\valorant.live\\valorant.live.product_settings.yaml";
@@ -43,6 +45,25 @@ public MainWindow()
4345
p.Start();
4446
}
4547

48+
private void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
49+
{
50+
if (e.Exception == null)
51+
{
52+
Application.Current.Shutdown();
53+
return;
54+
}
55+
string errorMessage = string.Format("An application error occurred. If this error occurs again there seems to be a serious bug in the application, and you better close it.\n\nError:{0}\n\nDo you want to continue?\n(if you click Yes you will continue with your work, if you click No the application will close)", e.Exception.Message);
56+
//insert code to log exception here
57+
if (MessageBox.Show(errorMessage, "Application User Interface Error", MessageBoxButton.YesNoCancel, MessageBoxImage.Error) == MessageBoxResult.No)
58+
{
59+
if (MessageBox.Show("WARNING: The application will close. Any changes will not be saved!\nDo you really want to close it?", "Close the application!", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning) == MessageBoxResult.Yes)
60+
{
61+
Application.Current.Shutdown();
62+
}
63+
}
64+
e.Handled = true;
65+
}
66+
4667
//The meat of the script
4768
private async void MainScript(object sender, RoutedEventArgs e)
4869
{
@@ -60,6 +81,16 @@ private async void MainScript(object sender, RoutedEventArgs e)
6081
rpcclient.OnJoin += Rpcclient_OnJoin;
6182
rpcclient.OnJoinRequested += Rpcclient_OnJoinRequested;
6283
rpcclient.Initialize();
84+
rpcclient.SetPresence(new RichPresence()
85+
{
86+
Details = "Logging into Valorant",
87+
State = $"Using ValorantStatus",
88+
Assets = new Assets()
89+
{
90+
LargeImageKey = "logo"
91+
},
92+
Buttons = new Button[] {new Button() { Label="ValorantStatus", Url= "https://github.com/brianbaldner/ValorantStatus" } }
93+
});
6394

6495
//So I can do title case
6596
TextInfo myTI = new CultureInfo("en-US", false).TextInfo;
@@ -83,6 +114,12 @@ await Task.Run(async () =>
83114

84115
//Checks for Discord events
85116
rpcclient.Invoke();
117+
if (presence != null)
118+
{
119+
if(presence.privinfo.matchMap != "")
120+
mapName = presence.privinfo.matchMap;
121+
gameMode = presence.privinfo.queueId;
122+
}
86123

87124
//If presence hasn't started or in menus
88125
if (presence == null || presence.privinfo.sessionLoopState == "MENUS")
@@ -98,8 +135,7 @@ await Task.Run(async () =>
98135
if (presence != null && presence.privinfo.partyAccessibility == "OPEN")
99136
{
100137
//Get match map and real mode from presence
101-
mapName = presence.privinfo.matchMap;
102-
gameMode = presence.privinfo.queueId;
138+
103139
//If looking for match
104140
if (presence.privinfo.partyState == "MATCHMAKING")
105141
{
@@ -201,9 +237,11 @@ await Task.Run(async () =>
201237
}
202238
else
203239
{
204-
if (mapName == null) mapName = "/Game/Maps/Poveglia/Range";
205-
if (presence.privinfo.provisioningFlow == "ShootingRange") gameMode = "Shooting Range";
206-
240+
if (presence.privinfo.provisioningFlow == "ShootingRange")
241+
{
242+
gameMode = "Shooting Range";
243+
mapName = "/Game/Maps/Poveglia/Range";
244+
}
207245
//One size fits all in game presence
208246
rpcclient.SetPresence(new RichPresence()
209247
{
@@ -299,7 +337,8 @@ public string GetMapName(string mapid)
299337
displayName = "The Range";
300338
break;
301339
default:
302-
displayName = "Unknown Map";
340+
displayName = mapid;
341+
//displayName = "Unknown Map";
303342
break;
304343
}
305344
return displayName;

ValorantStatus/ValorantStatus.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<OutputType>WinExe</OutputType>
4+
<OutputType>Exe</OutputType>
55
<TargetFramework>net5.0-windows</TargetFramework>
66
<UseWPF>true</UseWPF>
77
<ApplicationIcon>valorant.live.ico</ApplicationIcon>
88
<AssemblyName>ValorantStatus</AssemblyName>
9+
<StartupObject />
910
</PropertyGroup>
1011

1112
<ItemGroup>

0 commit comments

Comments
 (0)