-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
162 lines (155 loc) · 5.79 KB
/
Program.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
using System;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;
using DiscordRPC;
using Memory;
using System.Diagnostics;
namespace FLRP
{
static class Program
{
public static bool rpLigado;
public static Thread t;
public static DiscordRpcClient client;
public static int number = 0;
public static ToolStripItem botao;
public static Mem m = new Mem();
public static bool flProc = false;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
NotifyIcon notifyIcon = new NotifyIcon();
notifyIcon.ContextMenuStrip = GetContext();
notifyIcon.Icon = Properties.Resources.flstudiorp;
notifyIcon.Visible = true;
rpLigado = true;
t = new Thread(RpLoop);
t.Start();
Application.Run();
}
private static ContextMenuStrip GetContext()
{
ContextMenuStrip CMS = new ContextMenuStrip();
botao = CMS.Items.Add("Turn rich presence off", null, new EventHandler((object sender, EventArgs e) => {
if (rpLigado)
{
rpLigado = false;
botao.Text = "Turn rich presence on";
t.Interrupt();
}
else
{
rpLigado = true;
botao.Text = "Turn rich presence off";
t = new Thread(RpLoop);
t.Start();
}
}));
return CMS;
}
private static void openFL()
{
flProc = m.OpenProcess("FL64");
if (flProc)
{
m.OpenProcess("FL64");
}
}
private static int map(int value, int fromLow, int fromHigh, int toLow, int toHigh)
{
return (value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow;
}
public static void RpLoop()
{
try
{
DateTime timestamp = DateTime.UtcNow;
client = new DiscordRpcClient("988310374002589716");
//Connect to the RPC
while (true)
{
if (flProc & rpLigado)
{
if (!client.IsInitialized)
{
client.Initialize();
timestamp = DateTime.UtcNow;
};
int ms = m.ReadInt("_FLEngine_x64.dll+0xDDF5D8");
string bpm = m.ReadInt("_FLEngine_x64.dll+0xC9DF88").ToString();
//int master = m.ReadInt("_FLEngine_x64.dll+0xD77330");
if (bpm.Substring(bpm.Length - 3) == "000")
{
bpm = bpm.Substring(0, bpm.Length - 3);
}
else
{
bpm = bpm.Substring(0, bpm.Length - 3) + "." + bpm.Substring(bpm.Length - 3);
}
//if (master < 1000000000)
// master = 1000000000;
//int master_wave = map(master, 1000000000, 1070000000, 0, 20);
//string wave = new string('█', master_wave);
//wave = wave.PadLeft(20);
//wave = wave.Substring(0, 15);
string initialTitle = Process.GetProcessById(m.mProc.Process.Id).MainWindowTitle;
string title;
string version;
if (initialTitle.Contains("-"))
{
title = initialTitle.Split("-")[0] + "- ";
version = initialTitle.Split("- ")[1];
}
else
{
title = "New Project - ";
version = initialTitle;
}
double ticks = double.Parse(ms.ToString());
TimeSpan time = TimeSpan.FromMilliseconds(ticks);
DateTime dt = new DateTime(time.Ticks);
client.SetPresence(new RichPresence()
{
Details = title+bpm+" BPM",
State = dt.Minute.ToString("00") + ":" + dt.Second.ToString("00"),
Assets = new Assets()
{
LargeImageKey = "fl",
LargeImageText = version
},
Timestamps = new Timestamps()
{
Start = timestamp
}
});
Thread.Sleep(1000);
}
else
{
if (client.IsInitialized)
{
client.ClearPresence();
client.Deinitialize();
}
}
openFL();
}
}
catch
{
if (client.IsInitialized)
{
client.ClearPresence();
client.Deinitialize();
}
}
}
}
}