Skip to content

Commit 3e9debe

Browse files
authored
Add files via upload
day 396 working on this mess
1 parent 3baf35d commit 3e9debe

24 files changed

+8631
-1275
lines changed

ConfigHandler.cpp

+45-58
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,22 @@ namespace midi {
1717
if (ADJUSTMENT_INTERVAL_MS < 0) throw ConfigException("ADJUSTMENT_INTERVAL_MS cannot be negative");
1818
}
1919

20-
void LegitModeSettings::validate() const {
21-
if (TIMING_VARIATION < 0.0 || TIMING_VARIATION > 1.0)
22-
throw ConfigException("TIMING_VARIATION must be between 0.0 and 1.0");
23-
if (NOTE_SKIP_CHANCE < 0.0 || NOTE_SKIP_CHANCE > 1.0)
24-
throw ConfigException("NOTE_SKIP_CHANCE must be between 0.0 and 1.0");
25-
if (EXTRA_DELAY_CHANCE < 0.0 || EXTRA_DELAY_CHANCE > 1.0)
26-
throw ConfigException("EXTRA_DELAY_CHANCE must be between 0.0 and 1.0");
27-
if (EXTRA_DELAY_MIN < 0.0) throw ConfigException("EXTRA_DELAY_MIN cannot be negative");
28-
if (EXTRA_DELAY_MAX < EXTRA_DELAY_MIN)
29-
throw ConfigException("EXTRA_DELAY_MAX cannot be less than EXTRA_DELAY_MIN");
30-
}
3120

3221
void AutoTranspose::validate() const {
3322
if (TRANSPOSE_UP_KEY.empty() || TRANSPOSE_DOWN_KEY.empty()) {
3423
throw ConfigException("Transpose hotkeys cannot be empty");
3524
}
3625
}
3726

27+
void AutoplayerTimingAccuracy::validate() const {
28+
if (MAX_PASSES <= 0)
29+
throw ConfigException("MAX_PASSES must be positive");
30+
if (MEASURE_SEC <= 0.0)
31+
throw ConfigException("MEASURE_SEC must be positive");
32+
}
33+
3834
void MIDISettings::validate() const {
39-
//abcdefg
35+
// No specific validation needed for DETECT_DRUMS
4036
}
4137

4238
void HotkeySettings::validate() const {
@@ -108,9 +104,9 @@ namespace midi {
108104
midi.validate();
109105
playback.validate();
110106
volume.validate();
111-
legit_mode.validate();
112107
auto_transpose.validate();
113108
hotkeys.validate();
109+
autoplayer_timing.validate();
114110
validateKeyMappings();
115111
}
116112
catch (const ConfigException& e) {
@@ -175,27 +171,6 @@ namespace midi {
175171
v.validate();
176172
}
177173

178-
void to_json(json& j, const LegitModeSettings& l) {
179-
j = json{
180-
{"ENABLED", l.ENABLED},
181-
{"TIMING_VARIATION", l.TIMING_VARIATION},
182-
{"NOTE_SKIP_CHANCE", l.NOTE_SKIP_CHANCE},
183-
{"EXTRA_DELAY_CHANCE", l.EXTRA_DELAY_CHANCE},
184-
{"EXTRA_DELAY_MIN", l.EXTRA_DELAY_MIN},
185-
{"EXTRA_DELAY_MAX", l.EXTRA_DELAY_MAX}
186-
};
187-
}
188-
189-
void from_json(const json& j, LegitModeSettings& l) {
190-
j.at("ENABLED").get_to(l.ENABLED);
191-
j.at("TIMING_VARIATION").get_to(l.TIMING_VARIATION);
192-
j.at("NOTE_SKIP_CHANCE").get_to(l.NOTE_SKIP_CHANCE);
193-
j.at("EXTRA_DELAY_CHANCE").get_to(l.EXTRA_DELAY_CHANCE);
194-
j.at("EXTRA_DELAY_MIN").get_to(l.EXTRA_DELAY_MIN);
195-
j.at("EXTRA_DELAY_MAX").get_to(l.EXTRA_DELAY_MAX);
196-
l.validate();
197-
}
198-
199174
void to_json(json& j, const AutoTranspose& at) {
200175
j = json{
201176
{"ENABLED", at.ENABLED},
@@ -210,14 +185,28 @@ namespace midi {
210185
j.at("TRANSPOSE_DOWN_KEY").get_to(at.TRANSPOSE_DOWN_KEY);
211186
}
212187

188+
void to_json(json& j, const AutoplayerTimingAccuracy& a) {
189+
j = json{
190+
{"MAX_PASSES", a.MAX_PASSES},
191+
{"MEASURE_SEC", a.MEASURE_SEC}
192+
};
193+
}
194+
195+
void from_json(const json& j, AutoplayerTimingAccuracy& a) {
196+
j.at("MAX_PASSES").get_to(a.MAX_PASSES);
197+
j.at("MEASURE_SEC").get_to(a.MEASURE_SEC);
198+
a.validate();
199+
}
200+
213201
void to_json(json& j, const MIDISettings& m) {
214-
j = json{ {"FILTER_DRUMS", m.FILTER_DRUMS} };
202+
j = json{ {"DETECT_DRUMS", m.DETECT_DRUMS} };
215203
}
216204

217205
void from_json(const json& j, MIDISettings& m) {
218-
j.at("FILTER_DRUMS").get_to(m.FILTER_DRUMS);
206+
j.at("DETECT_DRUMS").get_to(m.DETECT_DRUMS);
219207
m.validate();
220208
}
209+
221210
void to_json(nlohmann::json& j, const UISettings& ui) {
222211
j = nlohmann::json{ {"alwaysOnTop", ui.alwaysOnTop} };
223212
}
@@ -282,10 +271,10 @@ namespace midi {
282271
j = json{
283272
{"VOLUME_SETTINGS", c.volume},
284273
{"KEY_MAPPINGS", c.key_mappings},
285-
{"LEGIT_MODE_SETTINGS", c.legit_mode},
286274
{"AUTO_TRANSPOSE", c.auto_transpose},
287275
{"HOTKEY_SETTINGS", c.hotkeys},
288-
{"MIDI_SETTINGS", json{{"FILTER_DRUMS", c.midi.FILTER_DRUMS}}},
276+
{"MIDI_SETTINGS", json{{"DETECT_DRUMS", c.midi.DETECT_DRUMS}}},
277+
{"AUTOPLAYER_TIMING_ACCURACY", c.autoplayer_timing},
289278
{"STACKED_NOTE_HANDLING_MODE", Config::noteHandlingModeToString(c.playback.noteHandlingMode)},
290279
{"CUSTOM_VELOCITY_CURVES", json::array()},
291280
{"PLAYLIST_FILES", c.playlistFiles},
@@ -303,10 +292,13 @@ namespace midi {
303292
void from_json(const json& j, Config& c) {
304293
j.at("VOLUME_SETTINGS").get_to(c.volume);
305294
j.at("KEY_MAPPINGS").get_to(c.key_mappings);
306-
j.at("LEGIT_MODE_SETTINGS").get_to(c.legit_mode);
307295
j.at("AUTO_TRANSPOSE").get_to(c.auto_transpose);
308296
j.at("HOTKEY_SETTINGS").get_to(c.hotkeys);
309-
j.at("MIDI_SETTINGS").at("FILTER_DRUMS").get_to(c.midi.FILTER_DRUMS);
297+
j.at("MIDI_SETTINGS").at("DETECT_DRUMS").get_to(c.midi.DETECT_DRUMS);
298+
299+
if (j.contains("AUTOPLAYER_TIMING_ACCURACY")) {
300+
j.at("AUTOPLAYER_TIMING_ACCURACY").get_to(c.autoplayer_timing);
301+
}
310302

311303
if (j.contains("STACKED_NOTE_HANDLING_MODE")) {
312304
std::string mode = j.at("STACKED_NOTE_HANDLING_MODE").get<std::string>();
@@ -331,13 +323,10 @@ namespace midi {
331323
}
332324
}
333325

334-
// New: read UI settings
326+
// Read UI settings
335327
if (j.contains("UI_SETTINGS")) {
336328
j.at("UI_SETTINGS").get_to(c.ui);
337329
}
338-
339-
// Validate at the end
340-
c.validate();
341330
}
342331

343332
void Config::setDefaults() {
@@ -349,28 +338,26 @@ namespace midi {
349338
10, // VOLUME_STEP
350339
50 // ADJUSTMENT_INTERVAL_MS
351340
};
352-
353-
// Legit mode settings
354-
legit_mode = {
355-
false, // ENABLED
356-
0.1, // TIMING_VARIATION
357-
0.02, // NOTE_SKIP_CHANCE
358-
0.05, // EXTRA_DELAY_CHANCE
359-
0.05, // EXTRA_DELAY_MIN
360-
0.2 // EXTRA_DELAY_MAX
361-
};
362-
363341
// AutoTranspose settings
364342
auto_transpose = {
365343
false, // ENABLED
366344
"VK_UP", // TRANSPOSE_UP_KEY
367345
"VK_DOWN" // TRANSPOSE_DOWN_KEY
368346
};
369347

348+
// Autoplayer timing accuracy settings
349+
autoplayer_timing = {
350+
20, // MAX_PASSES
351+
1.0 // MEASURE_SEC
352+
};
353+
370354
// MIDI settings
371-
midi = { true }; // FILTER_DRUMS
355+
midi = { true }; // DETECT_DRUMS
356+
357+
// UI settings
358+
ui = { true }; // alwaysOnTop
372359

373-
// Hotkey settings (updated with additional keys)
360+
// Hotkey settings
374361
hotkeys = {
375362
"VK_SPACE", // SUSTAIN_KEY
376363
"VK_RIGHT", // VOLUME_UP_KEY
@@ -425,4 +412,4 @@ namespace midi {
425412
validate();
426413
}
427414

428-
} // namespace midi
415+
}

InputHeader.h

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
extern "C" {
66
#endif
77

8-
// Global syscall number (defined in NtUserSendInputSyscall.cpp).
8+
// Global syscall number (defined in implementation file)
99
extern DWORD SyscallNumber;
1010

11-
// Returns the NtUserSendInput syscall number by decoding one of several DLL exports.
11+
// Returns the NtUserSendInput syscall number
1212
unsigned long __cdecl GetNtUserSendInputSyscallNumber(void);
1313

14-
// The assembly routine for performing the syscall.
15-
UINT __fastcall NtUserSendInputCall(ULONG cInputs, LPINPUT pInputs, int cbSize);
14+
// Direct function pointer - maximum speed
15+
// This replaces the regular function declaration for ultra-fast access
16+
extern UINT(__fastcall* NtUserSendInputCall)(ULONG cInputs, LPINPUT pInputs, int cbSize);
17+
18+
// Initialize the direct syscall - call after setting SyscallNumber
19+
void InitializeNtUserSendInputCall(void);
1620

1721
#ifdef __cplusplus
1822
}
19-
#endif
23+
#endif

InputInjector.cpp

+23-15
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,32 @@
33
#include <windows.h>
44
#include <iostream>
55

6-
// Define our global variable.
76
extern "C" DWORD SyscallNumber = 0;
8-
// shady, but there's a reason MIDI++ also has 0 false positives on virustotal.
7+
static UINT __fastcall gay(ULONG cInputs, LPINPUT pInputs, int cbSize)
8+
{
9+
return 69;
10+
}
11+
12+
extern "C" UINT(__fastcall* NtUserSendInputCall)(ULONG cInputs, LPINPUT pInputs, int cbSize) = gay;
13+
914
extern "C" unsigned long __cdecl GetNtUserSendInputSyscallNumber(void)
1015
{
1116
// Encoded strings:
1217
// g_dll0: Encoded with +7 offset. Real string: "win32u.dll"
1318
// g_dll1: Encoded with +5 offset. Real string: "user32.dll"
1419
// g_dll2: Encoded with +6 offset. Real string: "ntdll.dll"
1520
// g_func: Encoded with +4 offset. Real string: "NtUserSendInput"
16-
21+
1722
static bool g_decoded = false;
1823
static char g_dll0[] = { '~','p','u',':','9','|','5','k','s','s','\0' };
1924
static char g_dll1[] = { 'z','x','j','w','8','7','3','i','q','q','\0' };
2025
static char g_dll2[] = { 't','z','j','r','r','4','j','r','r','\0' };
2126
static char g_func[] = { 'R','x','Y','w','i','v','W','i','r','h','M','r','t','y','x','\0' };
22-
23-
//subtract 'offset' from each character
2427
auto decodeString = [](char* arr, int offset)
2528
{
2629
for (; *arr; ++arr)
2730
*arr = static_cast<char>(*arr - offset);
2831
};
29-
3032
if (!g_decoded)
3133
{
3234
decodeString(g_dll0, 7);
@@ -35,8 +37,6 @@ extern "C" unsigned long __cdecl GetNtUserSendInputSyscallNumber(void)
3537
decodeString(g_func, 4);
3638
g_decoded = true;
3739
}
38-
39-
// Try each DLL name until one contains the target function.
4040
const char* dllNames[] = { g_dll0, g_dll1, g_dll2 };
4141
FARPROC pFunc = nullptr;
4242
HMODULE hModule = nullptr;
@@ -51,17 +51,25 @@ extern "C" unsigned long __cdecl GetNtUserSendInputSyscallNumber(void)
5151
}
5252
if (!pFunc)
5353
throw std::runtime_error("Go upgrade ur windows bro wtf..");
54-
55-
// Expected prologue:
56-
// 4C 8B D1 mov r10,rcx
57-
// B8 xx xx xx xx mov eax,<syscall_number>
58-
// 0F 05 syscall
5954
BYTE* pBytes = reinterpret_cast<BYTE*>(pFunc);
6055
if (pBytes[0] != 0x4C || pBytes[1] != 0x8B || pBytes[2] != 0xD1)
6156
throw std::runtime_error("god damn it windows broke something!");
6257
DWORD number = *reinterpret_cast<DWORD*>(pBytes + 4);
6358
return number;
6459
}
6560

66-
// NtUserSendInputCall
67-
extern "C" UINT __fastcall NtUserSendInputCall(ULONG cInputs, LPINPUT pInputs, int cbSize);
61+
// because why read from memory and do syscall when you can just do syscall lol, god forgive me for what im doing
62+
extern "C" void InitializeNtUserSendInputCall(void)
63+
{
64+
void* pMemory = VirtualAlloc(NULL, 16, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
65+
if (!pMemory) return;
66+
BYTE* pCode = (BYTE*)pMemory;
67+
pCode[0] = 0x4C; pCode[1] = 0x8B; pCode[2] = 0xD1;
68+
pCode[3] = 0xB8;
69+
*(DWORD*)(&pCode[4]) = SyscallNumber;
70+
pCode[8] = 0x0F; pCode[9] = 0x05;
71+
pCode[10] = 0xC3;
72+
DWORD oldProtect;
73+
VirtualProtect(pMemory, 16, PAGE_EXECUTE_READ, &oldProtect);
74+
NtUserSendInputCall = (UINT(__fastcall*)(ULONG, LPINPUT, int))pMemory;
75+
}

0 commit comments

Comments
 (0)