Skip to content

Commit 0ba775d

Browse files
committed
Added keyboard input.
1 parent 2784393 commit 0ba775d

File tree

11 files changed

+676
-1
lines changed

11 files changed

+676
-1
lines changed

Core/CoreFunctionsManager.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Collections.Generic;
33
using System.Diagnostics.Contracts;
44
using System.IO;
5+
using System.Runtime.InteropServices;
6+
using System.Windows.Forms;
57
using ReClassNET.Debugger;
68
using ReClassNET.Memory;
79
using ReClassNET.Native;
@@ -210,6 +212,21 @@ public bool DisassembleCode(IntPtr address, int length, IntPtr virtualAddress, o
210212
return internalCoreFunctions.DisassembleCode(address, length, virtualAddress, out instruction);
211213
}
212214

215+
public bool InitializeInput()
216+
{
217+
return internalCoreFunctions.InitializeInput();
218+
}
219+
220+
public Keys[] GetPressedKeys()
221+
{
222+
return internalCoreFunctions.GetPressedKeys();
223+
}
224+
225+
public void ReleaseInput()
226+
{
227+
internalCoreFunctions.ReleaseInput();
228+
}
229+
213230
#endregion
214231
}
215232
}

Core/InternalCoreFunctions.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.InteropServices;
3+
using System.Windows.Forms;
34

45
namespace ReClassNET.Core
56
{
@@ -8,17 +9,58 @@ internal class InternalCoreFunctions : NativeCoreWrapper
89
[return: MarshalAs(UnmanagedType.I1)]
910
private delegate bool DisassembleCodeDelegate(IntPtr address, IntPtr length, IntPtr virtualAddress, out InstructionData instruction);
1011

12+
[return: MarshalAs(UnmanagedType.I1)]
13+
private delegate bool InitializeInputDelegate();
14+
15+
[return: MarshalAs(UnmanagedType.I1)]
16+
private delegate bool GetPressedKeysDelegate(out IntPtr address, out int length);
17+
18+
private delegate void ReleaseInputDelegate();
19+
1120
private readonly DisassembleCodeDelegate disassembleCodeDelegate;
1221

22+
private readonly InitializeInputDelegate initializeInputDelegate;
23+
private readonly GetPressedKeysDelegate getPressedKeysDelegate;
24+
private readonly ReleaseInputDelegate releaseInputDelegate;
25+
1326
public InternalCoreFunctions(IntPtr handle)
1427
: base(handle)
1528
{
1629
disassembleCodeDelegate = GetFunctionDelegate<DisassembleCodeDelegate>(handle, "DisassembleCode");
30+
31+
initializeInputDelegate = GetFunctionDelegate<InitializeInputDelegate>(handle, "InitializeInput");
32+
getPressedKeysDelegate = GetFunctionDelegate<GetPressedKeysDelegate>(handle, "GetPressedKeys");
33+
releaseInputDelegate = GetFunctionDelegate<ReleaseInputDelegate>(handle, "ReleaseInput");
1734
}
1835

1936
public bool DisassembleCode(IntPtr address, int length, IntPtr virtualAddress, out InstructionData instruction)
2037
{
2138
return disassembleCodeDelegate(address, (IntPtr)length, virtualAddress, out instruction);
2239
}
40+
41+
public bool InitializeInput()
42+
{
43+
return initializeInputDelegate();
44+
}
45+
46+
private static readonly Keys[] empty = new Keys[0];
47+
48+
public Keys[] GetPressedKeys()
49+
{
50+
if (!getPressedKeysDelegate(out var buffer, out var length) || length == 0)
51+
{
52+
return empty;
53+
}
54+
55+
var keys = new int[length];
56+
Marshal.Copy(buffer, keys, 0, length);
57+
return (Keys[])(object)keys; // Yes, it's legal...
58+
//return Array.ConvertAll(keys, k => (Keys)k);
59+
}
60+
61+
public void ReleaseInput()
62+
{
63+
releaseInputDelegate();
64+
}
2365
}
2466
}

NativeCore/Keys.hpp

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
#pragma once
2+
3+
enum class Keys : int32_t
4+
{
5+
None = 0,
6+
LButton = 1,
7+
RButton = 2,
8+
Cancel = 3,
9+
MButton = 4,
10+
XButton1 = 5,
11+
XButton2 = 6,
12+
Back = 8,
13+
Tab = 9,
14+
LineFeed = 10,
15+
Clear = 12,
16+
Return = 13,
17+
Enter = 13,
18+
ShiftKey = 16,
19+
ControlKey = 17,
20+
Menu = 18,
21+
Pause = 19,
22+
Capital = 20,
23+
CapsLock = 20,
24+
KanaMode = 21,
25+
HanguelMode = 21,
26+
HangulMode = 21,
27+
JunjaMode = 23,
28+
FinalMode = 24,
29+
HanjaMode = 25,
30+
KanjiMode = 25,
31+
Escape = 27,
32+
IMEConvert = 28,
33+
IMENonconvert = 29,
34+
IMEAccept = 30,
35+
IMEAceept = 30,
36+
IMEModeChange = 31,
37+
Space = 32,
38+
Prior = 33,
39+
PageUp = 33,
40+
Next = 34,
41+
PageDown = 34,
42+
End = 35,
43+
Home = 36,
44+
Left = 37,
45+
Up = 38,
46+
Right = 39,
47+
Down = 40,
48+
Select = 41,
49+
Print = 42,
50+
Execute = 43,
51+
Snapshot = 44,
52+
PrintScreen = 44,
53+
Insert = 45,
54+
Delete = 46,
55+
Help = 47,
56+
D0 = 48,
57+
D1 = 49,
58+
D2 = 50,
59+
D3 = 51,
60+
D4 = 52,
61+
D5 = 53,
62+
D6 = 54,
63+
D7 = 55,
64+
D8 = 56,
65+
D9 = 57,
66+
A = 65,
67+
B = 66,
68+
C = 67,
69+
D = 68,
70+
E = 69,
71+
F = 70,
72+
G = 71,
73+
H = 72,
74+
I = 73,
75+
J = 74,
76+
K = 75,
77+
L = 76,
78+
M = 77,
79+
N = 78,
80+
O = 79,
81+
P = 80,
82+
Q = 81,
83+
R = 82,
84+
S = 83,
85+
T = 84,
86+
U = 85,
87+
V = 86,
88+
W = 87,
89+
X = 88,
90+
Y = 89,
91+
Z = 90,
92+
LWin = 91,
93+
RWin = 92,
94+
Apps = 93,
95+
Sleep = 95,
96+
NumPad0 = 96,
97+
NumPad1 = 97,
98+
NumPad2 = 98,
99+
NumPad3 = 99,
100+
NumPad4 = 100,
101+
NumPad5 = 101,
102+
NumPad6 = 102,
103+
NumPad7 = 103,
104+
NumPad8 = 104,
105+
NumPad9 = 105,
106+
Multiply = 106,
107+
Add = 107,
108+
Separator = 108,
109+
Subtract = 109,
110+
Decimal = 110,
111+
Divide = 111,
112+
F1 = 112,
113+
F2 = 113,
114+
F3 = 114,
115+
F4 = 115,
116+
F5 = 116,
117+
F6 = 117,
118+
F7 = 118,
119+
F8 = 119,
120+
F9 = 120,
121+
F10 = 121,
122+
F11 = 122,
123+
F12 = 123,
124+
F13 = 124,
125+
F14 = 125,
126+
F15 = 126,
127+
F16 = 127,
128+
F17 = 128,
129+
F18 = 129,
130+
F19 = 130,
131+
F20 = 131,
132+
F21 = 132,
133+
F22 = 133,
134+
F23 = 134,
135+
F24 = 135,
136+
NumLock = 144,
137+
Scroll = 145,
138+
LShiftKey = 160,
139+
RShiftKey = 161,
140+
LControlKey = 162,
141+
RControlKey = 163,
142+
LMenu = 164,
143+
RMenu = 165,
144+
BrowserBack = 166,
145+
BrowserForward = 167,
146+
BrowserRefresh = 168,
147+
BrowserStop = 169,
148+
BrowserSearch = 170,
149+
BrowserFavorites = 171,
150+
BrowserHome = 172,
151+
VolumeMute = 173,
152+
VolumeDown = 174,
153+
VolumeUp = 175,
154+
MediaNextTrack = 176,
155+
MediaPreviousTrack = 177,
156+
MediaStop = 178,
157+
MediaPlayPause = 179,
158+
LaunchMail = 180,
159+
SelectMedia = 181,
160+
LaunchApplication1 = 182,
161+
LaunchApplication2 = 183,
162+
OemSemicolon = 186,
163+
Oem1 = 186,
164+
OemPlus = 187,
165+
OemComma = 188,
166+
OemMinus = 189,
167+
OemPeriod = 190,
168+
OemQuestion = 191,
169+
Oem2 = 191,
170+
Oemtilde = 192,
171+
Oem3 = 192,
172+
OemOpenBrackets = 219,
173+
Oem4 = 219,
174+
OemPipe = 220,
175+
Oem5 = 220,
176+
OemCloseBrackets = 221,
177+
Oem6 = 221,
178+
OemQuotes = 222,
179+
Oem7 = 222,
180+
Oem8 = 223,
181+
OemBackslash = 226,
182+
Oem102 = 226,
183+
ProcessKey = 229,
184+
Packet = 231,
185+
Attn = 246,
186+
Crsel = 247,
187+
Exsel = 248,
188+
EraseEof = 249,
189+
Play = 250,
190+
Zoom = 251,
191+
NoName = 252,
192+
Pa1 = 253,
193+
OemClear = 254,
194+
195+
KeyCode = 65535,
196+
Shift = 65536,
197+
Control = 131072,
198+
Alt = 262144,
199+
200+
Modifiers = -65536
201+
};
202+
203+
inline Keys& operator|=(Keys& lhs, Keys rhs)
204+
{
205+
using T = std::underlying_type_t<Keys>;
206+
207+
lhs = static_cast<Keys>(static_cast<T>(lhs) | static_cast<T>(rhs));
208+
209+
return lhs;
210+
}

NativeCore/Unix/Input.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "NativeCore.hpp"
2+
#include "../Keys.hpp"
3+
4+
void ReleaseInput();
5+
6+
bool InitializeInput()
7+
{
8+
return false;
9+
}
10+
11+
bool GetPressedKeys(Keys* state[], int* count)
12+
{
13+
return false;
14+
}
15+
16+
void ReleaseInput()
17+
{
18+
19+
}

NativeCore/Unix/NativeCore.Unix.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@
117117
<ClCompile Include="DisassembleCode.cpp" />
118118
<ClCompile Include="EnumerateProcesses.cpp" />
119119
<ClCompile Include="EnumerateRemoteSectionsAndModules.cpp" />
120+
<ClCompile Include="Input.cpp" />
120121
<ClCompile Include="IsProcessValid.cpp" />
121122
<ClCompile Include="OpenRemoteProcess.cpp" />
122123
<ClCompile Include="ReadRemoteMemory.cpp" />
123124
<ClCompile Include="WriteRemoteMemory.cpp" />
124125
</ItemGroup>
125126
<ItemGroup>
127+
<ClInclude Include="..\Keys.hpp" />
126128
<ClInclude Include="..\ReClassNET_Plugin.hpp" />
127129
<ClInclude Include="NativeCore.hpp" />
128130
</ItemGroup>

NativeCore/Unix/NativeCore.Unix.vcxproj.filters

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@
4242
<ClCompile Include="..\Dependencies\beaengine\src\BeaEngine.c">
4343
<Filter>Dependencies</Filter>
4444
</ClCompile>
45+
<ClCompile Include="Input.cpp">
46+
<Filter>Functions</Filter>
47+
</ClCompile>
4548
</ItemGroup>
4649
<ItemGroup>
4750
<ClInclude Include="NativeCore.hpp" />
4851
<ClInclude Include="..\ReClassNET_Plugin.hpp" />
52+
<ClInclude Include="..\Keys.hpp" />
4953
</ItemGroup>
5054
</Project>

NativeCore/Unix/NativeCore.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <sstream>
55

66
#include "../ReClassNET_Plugin.hpp"
7+
#include "../Keys.hpp"
78

89
typedef void(EnumerateProcessCallback)(EnumerateProcessData* data);
910

@@ -29,6 +30,10 @@ extern "C"
2930
bool AwaitDebugEvent(DebugEvent* evt, int timeoutInMilliseconds);
3031
void HandleDebugEvent(DebugEvent* evt);
3132
bool SetHardwareBreakpoint(RC_Pointer id, RC_Pointer address, HardwareBreakpointRegister reg, HardwareBreakpointTrigger type, HardwareBreakpointSize size, bool set);
33+
34+
bool InitializeInput();
35+
bool GetPressedKeys(Keys* state[], int* count);
36+
void ReleaseInput();
3237
}
3338

3439
inline bool is_number(const std::string& s)

0 commit comments

Comments
 (0)