Skip to content

Commit

Permalink
Hide Rich Presence on other locations
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisFeline committed Oct 5, 2024
1 parent 2c4268b commit 4d65159
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 51 deletions.
49 changes: 3 additions & 46 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,5 @@
# Latest Changelog

## Important Changes
- Every country or region should be able to use this app now.
- It now runs on Invariant Culture. This fixes the app not being able to parse the logs in some countries.
- This means if your friends from 'Tailand' couldn't use the app, they might be able to now lol
- Updated for new ToN Update. Yes, it's time! Create a new instance!

## Additions
- Added WebSocket API. You can connect to the save manager and receive in-game events via a websocket to facilitate the creation of visual tools like interactive stream overlays or trackers.
- Additionally, this feature adds support for the live tracker at `tontrack.me`
- Added stats window. Here you can track stats like rounds won/lost, killer stuns, etc...
- Added Discord Rich Presence support, yes... you can show you're friends how addicted you're to the game.
- Added OpenRGB support, you can color your keyboard and other peripherals based on in-game events. (Like round type or terror color)
- Added chatbox stats display. (Only shown on Intermissions)
- You can display your stats in the chatbox, but the chatbox will be hidden on purpose when participating on a round. Chatbox will be displayed again after death or end of round.
- You can customize the chatbox message template.
- For example: "Stuns - `{LobbyStuns}`" will be displayed as "Stuns - 3"
- Added 'Round Info to File' in settings.
- This feature lets you create templates that will write to a text file, this file can be read by streaming tools like OBS to display round info about your suffering to your audience.
- Added more keyboard navigation. (Suggested by YoBro)
- Save code will now display the Map where you survived.
- HOR... HOR... HOR HOR... HOR... HOR... HOR HOR... HOR HOR...

## Fixes & Improvements
- Log now parses from room join every time you launch the app. This fixes some terror names not being displayed when the app is opened in the middle of a run.
- Fixed save code delete warning message being the same as log history delete message.
- Rename & Import context menu buttons are disabled on entries that are not custom collections or favorites.
- Fixed clipboard clearing it's content after closing the app.
- App should detect your native UI language properly at first launch now.

### OSC Changes
* Please open README.md to see more OSC specifications.
- Some RoundType values has changed, please revisit your avatar and the documentation for more info.
- Added an OSC emulator window that allows you to emulate and test ToN encounters without actually being in the world. This should help avatar creators test their parameters and animations.
- To open the emulator, launch the app with --emulator as a console argument.
- This feature will be locked for at least a week to prevent spoilers.
- Added parameters for the HUD terror color, allowing you to colorize your avatar with HSV.
- Added a bunch of other parameters that will be listed on the documentation.
- Eight Pages is now fully supported.
- Supports alternates on Fog rounds.
- Added parameters for special encounters.
- Added parameters for some terror phases. (Faker & Bliss)
- 'RUN' round type is now properly detected.

### Localization
- Added German localization (Provided by @sageyx2002)
- Added Simplified Chinese localization (Provided by @Fallen-ice)
- Added Rich Presence PartyID, when you are in a VC it will collapse into a single presence when playing on the same lobby.
- Rich Presence now dissapears when you are not in the ToN world.
- Fixed Web Tracker Compatibility toggle sometimes showing up when Web Socket Server option was disabled.
3 changes: 3 additions & 0 deletions Models/Stats/RoundInfoTemplate.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Newtonsoft.Json;
using System.ComponentModel;
using System.Text.RegularExpressions;

namespace ToNSaveManager.Models.Stats {
public class RoundInfoTemplate {
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue("")]
public string FileName { get; set; }

[JsonIgnore] private string m_FilePath { get; set; } = string.Empty;
[JsonIgnore] private string m_FileDir { get; set; } = string.Empty;
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore), DefaultValue("")]
public string FilePath {
get => m_FilePath;
set {
Expand Down
61 changes: 56 additions & 5 deletions Utils/Discord/DSRichPresence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using DiscordRPC.Logging;
using DiscordRPC.Message;
using Microsoft.VisualBasic.Logging;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using ToNSaveManager.Models;
Expand Down Expand Up @@ -99,6 +100,9 @@ internal static void SetInstanceID(string instanceId, bool isHome) {
TerrorsInstanceID = instanceId;
if (!MainWindow.Started) return;

UpdateTimestamp();
Log.Debug("Setting instance home: " + isHome);

if (isHome) {
int index1 = instanceId.IndexOf(':') + 1;
int index2 = instanceId.IndexOf('~', index1);
Expand Down Expand Up @@ -236,19 +240,66 @@ internal static void Send() {
}
}

// Check game running
internal static bool VRCIsOpen;

static async Task WaitForVRChat_Interval() {
while (true) {
Log.Debug("Attempting to find game process...");

try {
var vrc = Process.GetProcessesByName("VRChat").FirstOrDefault();
if (vrc != null) {
Log.Debug("Game process found, initializing.");

VRCIsOpen = true;
Initialize();

Log.Debug("Waiting for game exit.");
await vrc.WaitForExitAsync();
} else {
VRCIsOpen = false;
}
} catch (Exception e) {
Log.Error("Error trying to find game process.");
Log.Error(e);
VRCIsOpen = false;
}

Initialize();
// Retry to find vrc process in 5 seconds.
Log.Debug("Could not find VRChat process, retrying in 30 seconds.");
await Task.Delay(30000);
}
}

internal static void VRCProcessTest() {
_ = WaitForVRChat_Interval();
}

static bool CurrentInitState = false;
internal static void Initialize(bool onStart = false) {
if (onStart)
if (onStart) {
SetInstanceID(TerrorsInstanceID, IsPlayingTerrors);
VRCProcessTest();
return;
}

bool currentState = Settings.Get.DiscordRichPresence && IsPlayingTerrors;
if (CurrentInitState == currentState) return;
bool currentState = Settings.Get.DiscordRichPresence && IsPlayingTerrors && VRCIsOpen;
if (CurrentInitState != currentState) {
CurrentInitState = currentState;

if (CurrentInitState) DeInitialize_Internal();
else Initialize_Internal();
if (CurrentInitState) {
Initialize_Internal();
} else {
DeInitialize_Internal();
}
}
}

static void Initialize_Internal() {
Log.Debug("Init Internal");

if (Client == null || Client.IsDisposed) {
Client = new DiscordRpcClient("1281246143224746035");
// Client.RegisterUriScheme("438100");
Expand Down

0 comments on commit 4d65159

Please sign in to comment.