-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatboxManager.cs
147 lines (118 loc) · 4.42 KB
/
ChatboxManager.cs
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
// /*
// *
// * Zuxi.OSC - ChatboxManager.cs
// * Copyright 2023 - 2024 Zuxi and contributors
// * https://zuxi.dev
// *
// */
using BuildSoft.VRChat.Osc.Chatbox;
using Zuxi.OSC.HeartRate;
using Zuxi.OSC.Modules;
using Zuxi.OSC.utility;
namespace Zuxi.OSC;
internal class ChatboxManager
{
internal static readonly List<string> ChatboxQue = new();
private static string _lastSong = "";
public static void SendToChatBox(string chatboxText, bool bypass = false)
{
if (string.IsNullOrEmpty(chatboxText) && !bypass)
{
// Bail Early no update saves VRChat Chat box from throwing a spam error
return;
}
// This is to Debug the Chatbox however its not needed in release but since i un in debug mode more often then not id rather comment this out
// Console.WriteLine(chatboxText);
OscChatbox.SendMessage(chatboxText.Trim(), true);
}
public static void UpdateChatboxFunc()
{
if (ChatboxQue.Count > 0)
{
SendToChatBox(ChatboxQue[0]);
// OBSHook64.dll (Real)
// File.WriteAllText(Path.Combine(FileUtils.GetAppFolder(), "OBSOUT.txt"), ChatboxQue[0]);
ChatboxQue.RemoveAt(0);
return;
}
var ChatboxText = "";
if (Program.NormalChatbox)
{
// Disabled lol let me not flex my site my bio does that enough
// ChatboxText += "imzuxi.com\v";
}
if (Program.HeartRate)
{
if (HeartBeat.Lasthr != 0)
ChatboxText += $"{HeartBeat.Lasthr}❤️\v";
}
else
{
if (!Program.NormalChatbox) ChatboxText += "imzuxi.com";
}
if (Program.NormalChatbox)
{
var currentSong = MediaPlayback.GetCurrentSong();
if (!string.IsNullOrEmpty(currentSong) && _lastSong != currentSong)
{
if (IsInVR)
_lastSong = currentSong;
ChatboxText += $"[ Current Song ] \v {currentSong}";
if (!IsInVR)
ChatboxText += $"\v{MediaPlayback.getProgressVisual()}";
}
if (!IsInVR)
{
var ProgramWindow = ActiveWindow.Get();
if (!string.IsNullOrEmpty(ProgramWindow) && !currentSong.Contains(ProgramWindow) &&
Console.Title != ProgramWindow && ProgramWindow.Contains(currentSong.Split('-').FirstOrDefault()))
{
if (!string.IsNullOrEmpty(currentSong)) ChatboxText += "\v";
ChatboxText += $"[ Current Window ]: \v {ProgramWindow}";
}
}
#region Broken Will NOT Fix
//TODO: dont fix jk please fix should be in above if loop edit: BROKEN CANNOT BE ASKED TO FIX IT feel
//free to fix it
// ChatboxText += "\v";
// ChatboxText += "[ System Info ]\v ";
// float cpuUsage = SystemInfo.GetCpuUsage();
// SystemInfo.GetMemoryUsage(out ulong totalMemory, out ulong usedMemory, out float memoryUsage);
// ChatboxText += $"CPU: {100 - cpuUsage:F0}% M: {usedMemory / (1024.0 * 1024.0 * 1024.0):F1} / {totalMemory / (1024.0 * 1024.0 * 1024.0):F1} GB";
// Get Memory Usage
// Console.WriteLine($"Memory Usage: ");
#endregion
}
try
{
var FileText = File.ReadAllText(Path.Combine(FileUtils.GetAppFolder(), "chatbox.txt"));
if (!string.IsNullOrEmpty(FileText))
ChatboxText += "\v\v" + FileText.Replace("{{env.newline}}", "\v");
}
catch (FileNotFoundException)
{
File.Create(Path.Combine(FileUtils.GetAppFolder(), "chatbox.txt")).Close();
}
SendToChatBox(ChatboxText);
}
public static void AddNewMessageToChatboxQue(string data)
{
ChatboxQue.Add(data);
}
#region Timer Loop to Update Chatbox
private static System.Timers.Timer timer;
internal static bool IsInVR;
internal static void Start()
{
if (timer is not null)
return;
timer = new System.Timers.Timer();
if (IsInVR)
timer.Interval = 5000; // 3 seconds seems to be a safe value to update at
else
timer.Interval = 3000;
timer.Elapsed += (s, e) => UpdateChatboxFunc();
timer.Start();
}
#endregion
}