-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
169 lines (146 loc) · 5.7 KB
/
Program.cs
File metadata and controls
169 lines (146 loc) · 5.7 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Linq;
using JRPC_Client;
using XDevkit;
using DiscordRPC;
class Program
{
static IXboxConsole Jtag;
static Dictionary<uint, string> titleIdMap = new Dictionary<uint, string>();
static DiscordRpcClient discord;
static DateTime gameStartTime;
static bool isConnected = false;
static void Main()
{
try
{
discord = new DiscordRpcClient("YOUR_APPID_HERE");
discord.Initialize();
loadCsv("titles.csv");
string lastTitle = null;
gameStartTime = DateTime.Now;
while (true)
{
try
{
if (!isConnected)
{
Console.Clear();
Console.WriteLine("Waiting for Xbox connection...");
Console.WriteLine("Please connect your Xbox and ensure it's powered on");
Console.WriteLine("\nPress Ctrl+C to exit");
if (Jtag.Connect(out Jtag))
{
isConnected = true;
Console.Clear();
Console.WriteLine("Connected to Xbox!");
Jtag.XNotify("XboxRPC Connected!");
gameStartTime = DateTime.Now;
lastTitle = null;
}
Thread.Sleep(2000);
continue;
}
try
{
uint titleId = (uint)Jtag.XamGetCurrentTitleId();
string titleName = titleIdMap.ContainsKey(titleId) ? titleIdMap[titleId] : $"Unknown ({titleId:X8})";
if (titleName != lastTitle)
{
gameStartTime = DateTime.Now;
lastTitle = titleName;
}
TimeSpan elapsed = DateTime.Now - gameStartTime;
string elapsedTime = $"Playing for {elapsed.Hours:D2}:{elapsed.Minutes:D2}:{elapsed.Seconds:D2}";
Console.Clear();
Console.WriteLine($"Current Game: {titleName}");
Console.WriteLine($"Title ID: {titleId:X8}");
Console.WriteLine(elapsedTime);
Console.WriteLine("\nPress Ctrl+C to exit");
discord.SetPresence(new RichPresence
{
Details = $"Playing: {titleName}",
State = $"Title ID: {titleId:X8}",
Assets = new Assets
{
LargeImageKey = "xbox",
LargeImageText = "Xbox 360"
}
});
}
catch (Exception)
{
isConnected = false;
Console.Clear();
Console.WriteLine("Xbox connection lost. Waiting for reconnection...");
discord.ClearPresence();
continue;
}
Thread.Sleep(1000);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
Thread.Sleep(5000);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Fatal error: {ex.Message}");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
finally
{
discord?.Dispose();
}
}
static void loadCsv(string path)
{
if (!File.Exists(path))
{
Console.WriteLine($"Warning: CSV file not found at {path}");
return;
}
string[] lines = File.ReadAllLines(path);
if (lines.Length < 2) return;
string[] headers = lines[0].Split(',');
int titleIdIndex = Array.IndexOf(headers, "Title ID");
int gameNameIndex = Array.IndexOf(headers, "Game Name");
if (titleIdIndex == -1 || gameNameIndex == -1)
{
Console.WriteLine("Error: Could not find required columns in CSV file");
return;
}
for (int i = 1; i < lines.Length; i++)
{
string[] values = lines[i].Split(',');
if (values.Length <= Math.Max(titleIdIndex, gameNameIndex)) continue;
try
{
string titleIdStr = values[titleIdIndex].Trim();
if (string.IsNullOrEmpty(titleIdStr)) continue;
titleIdStr = new string(titleIdStr.Where(c => "0123456789ABCDEFabcdef".Contains(c)).ToArray());
if (string.IsNullOrEmpty(titleIdStr)) continue;
titleIdStr = titleIdStr.PadLeft(8, '0');
uint id = Convert.ToUInt32(titleIdStr, 16);
string gameName = values[gameNameIndex].Trim();
if (!string.IsNullOrEmpty(gameName))
{
titleIdMap[id] = gameName;
Console.WriteLine($"Loaded: {gameName} ({id:X8})");
}
}
catch (Exception ex)
{
Console.WriteLine($"Warning: Could not process row {i}: {ex.Message}");
Console.WriteLine($"Row content: {lines[i]}");
}
}
Console.WriteLine($"Loaded {titleIdMap.Count} unique titles from CSV");
}
}