├── README.md
├── InputRedirection
├── Icon.ico
├── Content
│ ├── Fonts
│ │ └── NESFont.png
│ ├── Cursors
│ │ └── Cursor.png
│ └── Content.mgcb
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── InputRedirection.csproj
└── Game1.cs
└── InputRedirection.sln
/README.md:
--------------------------------------------------------------------------------
1 | # InputRedirectionClient
2 | PC client for https://github.com/Kazo/InputRedirection.
3 |
--------------------------------------------------------------------------------
/InputRedirection/Icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kazo/InputRedirectionClient/HEAD/InputRedirection/Icon.ico
--------------------------------------------------------------------------------
/InputRedirection/Content/Fonts/NESFont.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kazo/InputRedirectionClient/HEAD/InputRedirection/Content/Fonts/NESFont.png
--------------------------------------------------------------------------------
/InputRedirection/Content/Cursors/Cursor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kazo/InputRedirectionClient/HEAD/InputRedirection/Content/Cursors/Cursor.png
--------------------------------------------------------------------------------
/InputRedirection/Content/Content.mgcb:
--------------------------------------------------------------------------------
1 |
2 | #----------------------------- Global Properties ----------------------------#
3 |
4 | /outputDir:bin/WindowsGL
5 | /intermediateDir:obj/WindowsGL
6 | /platform:WindowsGL
7 | /config:
8 | /profile:Reach
9 | /compress:False
10 |
11 | #-------------------------------- References --------------------------------#
12 |
13 |
14 | #---------------------------------- Content ---------------------------------#
15 |
16 |
--------------------------------------------------------------------------------
/InputRedirection/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace InputRedirection
4 | {
5 | #if WINDOWS || LINUX
6 | ///
7 | /// The main class.
8 | ///
9 | public static class Program
10 | {
11 | ///
12 | /// The main entry point for the application.
13 | ///
14 | [STAThread]
15 | static void Main()
16 | {
17 | using (var game = new Game1())
18 | game.Run();
19 | }
20 | }
21 | #endif
22 | }
23 |
--------------------------------------------------------------------------------
/InputRedirection.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Express 14 for Windows Desktop
4 | VisualStudioVersion = 14.0.25123.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InputRedirection", "InputRedirection\InputRedirection.csproj", "{476F5922-9EAA-4762-934B-B2B4BA327445}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x86 = Debug|x86
11 | Release|x86 = Release|x86
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {476F5922-9EAA-4762-934B-B2B4BA327445}.Debug|x86.ActiveCfg = Debug|x86
15 | {476F5922-9EAA-4762-934B-B2B4BA327445}.Debug|x86.Build.0 = Debug|x86
16 | {476F5922-9EAA-4762-934B-B2B4BA327445}.Release|x86.ActiveCfg = Release|x86
17 | {476F5922-9EAA-4762-934B-B2B4BA327445}.Release|x86.Build.0 = Release|x86
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/InputRedirection/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("InputRedirection")]
9 | [assembly: AssemblyProduct("InputRedirection")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyCopyright("Copyright © 2016")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("2e9b50d4-79a2-4604-9b49-9d93901330a2")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("3.4.0.456")]
36 | [assembly: AssemblyFileVersion("3.4.0.456")]
37 |
--------------------------------------------------------------------------------
/InputRedirection/InputRedirection.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | 2.0
8 | {476F5922-9EAA-4762-934B-B2B4BA327445}
9 | WinExe
10 | Properties
11 | InputRedirection
12 | InputRedirection
13 | 512
14 | WindowsGL
15 |
16 |
17 |
18 |
19 | x86
20 | true
21 | full
22 | false
23 | bin\WindowsGL\Debug\
24 | DEBUG;TRACE;WINDOWS
25 | prompt
26 | 4
27 |
28 |
29 | x86
30 | pdbonly
31 | true
32 | bin\WindowsGL\Release\
33 | TRACE;WINDOWS
34 | prompt
35 | 4
36 |
37 |
38 | Icon.ico
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | $(MSBuildProgramFiles32)\MonoGame\v3.0\Assemblies\WindowsGL\OpenTK.dll
48 |
49 |
50 | $(MSBuildProgramFiles32)\MonoGame\v3.0\Assemblies\WindowsGL\MonoGame.Framework.dll
51 |
52 |
53 |
54 |
55 |
56 |
57 | PreserveNewest
58 |
59 |
60 | PreserveNewest
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
82 |
--------------------------------------------------------------------------------
/InputRedirection/Game1.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Xna.Framework;
2 | using Microsoft.Xna.Framework.Graphics;
3 | using Microsoft.Xna.Framework.Input;
4 | using System;
5 | using System.IO;
6 | using System.Net;
7 | using System.Net.Sockets;
8 |
9 | namespace InputRedirection
10 | {
11 | public class Game1 : Game
12 | {
13 | GraphicsDeviceManager graphics;
14 | SpriteBatch spriteBatch;
15 | Texture2D Font;
16 | Texture2D Cursor;
17 |
18 | Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0);
19 | IPAddress ipAddress;
20 | string IPAddress = "192.168.1.2";
21 | byte[] data = new byte[12];
22 | uint oldbuttons = 0xFFF;
23 | uint newbuttons = 0xFFF;
24 | uint oldtouch = 0x2000000;
25 | uint newtouch = 0x2000000;
26 | uint oldcpad = 0x800800;
27 | uint newcpad = 0x800800;
28 | uint touchclick = 0x00;
29 | uint cpadclick = 0x00;
30 | int Mode = 0;
31 | Keys[] ipKeysToCheck = { Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9, Keys.NumPad0, Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, Keys.NumPad8, Keys.NumPad9, Keys.Decimal, Keys.OemPeriod, Keys.Back, Keys.Delete, Keys.Escape };
32 | Keys[] buttonKeysToCheck = { Keys.A, Keys.B, Keys.RightShift, Keys.LeftShift, Keys.Enter, Keys.Right, Keys.Left, Keys.Up, Keys.Down, Keys.R, Keys.L, Keys.X, Keys.Y, Keys.Escape };
33 | Keys[] KeyboardInput = { Keys.A, Keys.S, Keys.N, Keys.M, Keys.H, Keys.F, Keys.T, Keys.G, Keys.W, Keys.Q, Keys.Z, Keys.X, Keys.Right, Keys.Left, Keys.Up, Keys.Down };
34 | uint[] GamePadInput = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x020, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800 };
35 | string[] ButtonNames = { "A", "B", "Select", "Start", "DPad Right", "DPad Left", "DPad Up", "DPad Down", "R", "L", "X", "Y" };
36 | Keys UpKey;
37 | bool WaitForKeyUp;
38 | bool debug = false;
39 | KeyboardState keyboardState;
40 | GamePadState gamePadState;
41 | uint KeyIndex;
42 | Keys OldKey;
43 | uint OldButton;
44 | bool useGamePad = true;
45 | string version = "0";
46 |
47 | public Game1()
48 | {
49 | graphics = new GraphicsDeviceManager(this);
50 | Content.RootDirectory = "Content";
51 | }
52 |
53 | protected override void Initialize()
54 | {
55 | this.IsMouseVisible = true;
56 | this.Window.Title = "InputRedirection";
57 | graphics.PreferredBackBufferWidth = 320;
58 | graphics.PreferredBackBufferHeight = 240;
59 | base.Initialize();
60 | }
61 |
62 | protected override void LoadContent()
63 | {
64 | if (File.Exists("config.cfg"))
65 | {
66 | ReadConfig();
67 | }
68 | else
69 | {
70 | SaveConfig();
71 | }
72 |
73 | spriteBatch = new SpriteBatch(GraphicsDevice);
74 | Font = Content.Load("Fonts\\NESFont");
75 | Cursor = Content.Load("Cursors\\Cursor");
76 | }
77 |
78 | protected override void UnloadContent()
79 | {
80 |
81 | }
82 |
83 | protected override void Update(GameTime gameTime)
84 | {
85 | CheckConnection();
86 | switch (Mode)
87 | {
88 | case 0:
89 | {
90 | IsMouseVisible = !debug;
91 | ReadMain();
92 | }
93 | break;
94 |
95 | case 1:
96 | {
97 | IsMouseVisible = true;
98 | ReadIPInput();
99 | }
100 | break;
101 |
102 | case 2:
103 | {
104 | IsMouseVisible = true;
105 | ReadKeyboardInput();
106 | }
107 | break;
108 |
109 | case 3:
110 | {
111 | IsMouseVisible = true;
112 | ReadGamePadInput();
113 | }
114 | break;
115 |
116 | case 4:
117 | {
118 | IsMouseVisible = true;
119 | ReadNewKey();
120 | }
121 | break;
122 |
123 | case 5:
124 | {
125 | IsMouseVisible = true;
126 | ReadNewButton();
127 | }
128 | break;
129 |
130 | }
131 |
132 | base.Update(gameTime);
133 | }
134 |
135 | protected override void Draw(GameTime gameTime)
136 | {
137 | GraphicsDevice.Clear(Color.Black);
138 | spriteBatch.Begin();
139 | {
140 | switch (Mode)
141 | {
142 | case 0:
143 | {
144 | ShowMain();
145 | }
146 | break;
147 |
148 | case 1:
149 | {
150 | ShowIPInput();
151 | }
152 | break;
153 |
154 | case 2:
155 | case 4:
156 | {
157 | ShowKeyboardInput();
158 | }
159 | break;
160 |
161 | case 3:
162 | case 5:
163 | {
164 | ShowGamePadInput();
165 | }
166 | break;
167 | }
168 | }
169 | spriteBatch.End();
170 |
171 | base.Draw(gameTime);
172 | }
173 |
174 | private void ReadConfig()
175 | {
176 | StreamReader sr = new StreamReader("config.cfg");
177 |
178 | if (version == sr.ReadLine())
179 | {
180 | IPAddress = sr.ReadLine();
181 | if (sr.ReadLine() == "True")
182 | {
183 | debug = true;
184 | this.IsMouseVisible = false;
185 | }
186 |
187 | if (sr.ReadLine() == "False")
188 | {
189 | useGamePad = false;
190 | }
191 |
192 | for (int i = 0; i < KeyboardInput.Length; i++)
193 | {
194 | KeyboardInput[i] = (Keys)Enum.Parse(typeof(Keys), sr.ReadLine());
195 | }
196 |
197 | for (int i = 0; i < GamePadInput.Length; i++)
198 | {
199 | GamePadInput[i] = Convert.ToUInt32(sr.ReadLine());
200 | }
201 | sr.Close();
202 | }
203 | else
204 | {
205 | sr.Close();
206 | SaveConfig();
207 | }
208 | }
209 |
210 | private void SaveConfig()
211 | {
212 | StreamWriter sw = new StreamWriter("config.cfg");
213 |
214 | sw.WriteLine(version);
215 | sw.WriteLine(IPAddress);
216 | sw.WriteLine(debug);
217 | sw.WriteLine(useGamePad);
218 |
219 | for (int i = 0; i < KeyboardInput.Length; i++)
220 | {
221 | sw.WriteLine(KeyboardInput[i]);
222 | }
223 |
224 | for (int i = 0; i < GamePadInput.Length; i++)
225 | {
226 | sw.WriteLine(GamePadInput[i]);
227 | }
228 | sw.Close();
229 | }
230 |
231 | private void CheckConnection()
232 | {
233 | if (!socket.Connected)
234 | {
235 | socket.Connect(IPAddress, 4950);
236 | }
237 |
238 | }
239 |
240 | private void ReadNewKey()
241 | {
242 | if (!WaitForKeyUp)
243 | {
244 | keyboardState = Keyboard.GetState();
245 |
246 | if(keyboardState.GetPressedKeys().Length > 0)
247 | {
248 | switch (keyboardState.GetPressedKeys()[0])
249 | {
250 | case Keys.Escape:
251 | {
252 | KeyboardInput[KeyIndex] = OldKey;
253 | Mode = 2;
254 | }
255 | break;
256 |
257 | case Keys.F1:
258 | case Keys.F2:
259 | case Keys.F3:
260 | case Keys.F4:
261 | case Keys.F5:
262 | {
263 | break;
264 | }
265 |
266 | default:
267 | {
268 | for (int i = 0; i < KeyboardInput.Length; i++)
269 | {
270 | if (keyboardState.GetPressedKeys()[0] == KeyboardInput[i])
271 | {
272 | break;
273 | }
274 |
275 | if (i == (KeyboardInput.Length - 1))
276 | {
277 | KeyboardInput[KeyIndex] = keyboardState.GetPressedKeys()[0];
278 | Mode = 2;
279 | WaitForKeyUp = true;
280 | UpKey = keyboardState.GetPressedKeys()[0];
281 | }
282 | }
283 | }
284 | break;
285 | }
286 | }
287 | }
288 | else
289 | {
290 | if (Keyboard.GetState().IsKeyUp(UpKey))
291 | {
292 | WaitForKeyUp = false;
293 | }
294 | }
295 | }
296 |
297 | private void ReadNewButton()
298 | {
299 | if (!WaitForKeyUp)
300 | {
301 | for (int i = 0; i < buttonKeysToCheck.Length; i++)
302 | {
303 | if (Keyboard.GetState().IsKeyDown(buttonKeysToCheck[i]))
304 | {
305 | WaitForKeyUp = true;
306 | UpKey = buttonKeysToCheck[i];
307 | switch (buttonKeysToCheck[i])
308 | {
309 | case Keys.Escape:
310 | {
311 | GamePadInput[KeyIndex] = OldButton;
312 | Mode = 3;
313 | }
314 | break;
315 |
316 | default:
317 | {
318 | switch(buttonKeysToCheck[i])
319 | {
320 | case Keys.A:
321 | {
322 | GamePadInput[KeyIndex] = 0x01;
323 | Mode = 3;
324 | }
325 | break;
326 |
327 | case Keys.B:
328 | {
329 | GamePadInput[KeyIndex] = 0x02;
330 | Mode = 3;
331 | }
332 | break;
333 |
334 | case Keys.RightShift:
335 | case Keys.LeftShift:
336 | {
337 | GamePadInput[KeyIndex] = 0x04;
338 | Mode = 3;
339 | }
340 | break;
341 |
342 | case Keys.Enter:
343 | {
344 | GamePadInput[KeyIndex] = 0x08;
345 | Mode = 3;
346 | }
347 | break;
348 |
349 | case Keys.Right:
350 | {
351 | GamePadInput[KeyIndex] = 0x10;
352 | Mode = 3;
353 | }
354 | break;
355 |
356 | case Keys.Left:
357 | {
358 | GamePadInput[KeyIndex] = 0x20;
359 | Mode = 3;
360 | }
361 | break;
362 |
363 | case Keys.Up:
364 | {
365 | GamePadInput[KeyIndex] = 0x40;
366 | Mode = 3;
367 | }
368 | break;
369 |
370 | case Keys.Down:
371 | {
372 | GamePadInput[KeyIndex] = 0x80;
373 | Mode = 3;
374 | }
375 | break;
376 |
377 | case Keys.R:
378 | {
379 | GamePadInput[KeyIndex] = 0x100;
380 | Mode = 3;
381 | }
382 | break;
383 |
384 | case Keys.L:
385 | {
386 | GamePadInput[KeyIndex] = 0x200;
387 | Mode = 3;
388 | }
389 | break;
390 |
391 | case Keys.X:
392 | {
393 | GamePadInput[KeyIndex] = 0x400;
394 | Mode = 3;
395 | }
396 | break;
397 |
398 | case Keys.Y:
399 | {
400 | GamePadInput[KeyIndex] = 0x800;
401 | Mode = 3;
402 | }
403 | break;
404 | }
405 | }
406 | break;
407 | }
408 | }
409 | }
410 | }
411 | else
412 | {
413 | if (Keyboard.GetState().IsKeyUp(UpKey))
414 | {
415 | WaitForKeyUp = false;
416 | }
417 | }
418 | }
419 |
420 | private void ReadMain()
421 | {
422 | if (!WaitForKeyUp)
423 | {
424 | if (Keyboard.GetState().IsKeyDown(Keys.F1))
425 | {
426 | WaitForKeyUp = true;
427 | UpKey = Keys.F1;
428 | Mode = 1;
429 | }
430 |
431 | if (Keyboard.GetState().IsKeyDown(Keys.F2))
432 | {
433 | WaitForKeyUp = true;
434 | UpKey = Keys.F2;
435 | Mode = 2;
436 | }
437 |
438 | if (Keyboard.GetState().IsKeyDown(Keys.F3))
439 | {
440 | WaitForKeyUp = true;
441 | UpKey = Keys.F3;
442 | Mode = 3;
443 | }
444 |
445 | if (Keyboard.GetState().IsKeyDown(Keys.F4))
446 | {
447 | WaitForKeyUp = true;
448 | UpKey = Keys.F4;
449 | debug = !debug;
450 | this.IsMouseVisible = !this.IsMouseVisible;
451 | SaveConfig();
452 | }
453 |
454 | if (Keyboard.GetState().IsKeyDown(Keys.F5))
455 | {
456 | WaitForKeyUp = true;
457 | UpKey = Keys.F5;
458 | useGamePad = !useGamePad;
459 | SaveConfig();
460 | }
461 | }
462 | else
463 | {
464 | if (Keyboard.GetState().IsKeyUp(UpKey))
465 | {
466 | WaitForKeyUp = false;
467 | }
468 | }
469 |
470 | keyboardState = Keyboard.GetState();
471 | gamePadState = GamePad.GetState(PlayerIndex.One);
472 | newbuttons = 0x00;
473 | //Keyboard
474 | for (int i = 0; i < GamePadInput.Length; i++)
475 | {
476 | if (keyboardState.IsKeyDown(KeyboardInput[i]))
477 | {
478 | newbuttons += (uint)(0x01 << i);
479 | }
480 | }
481 |
482 | //GamePad
483 | if (useGamePad)
484 | {
485 | if (GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed)
486 | {
487 | if ((newbuttons & GamePadInput[0]) != GamePadInput[0])
488 | {
489 | newbuttons += GamePadInput[0];
490 | }
491 | }
492 |
493 | if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)
494 | {
495 | if ((newbuttons & GamePadInput[1]) != GamePadInput[1])
496 | {
497 | newbuttons += GamePadInput[1];
498 | }
499 | }
500 |
501 |
502 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
503 | {
504 | if ((newbuttons & GamePadInput[2]) != GamePadInput[2])
505 | {
506 | newbuttons += GamePadInput[2];
507 | }
508 | }
509 |
510 | if (GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed)
511 | {
512 | if ((newbuttons & GamePadInput[3]) != GamePadInput[3])
513 | {
514 | newbuttons += GamePadInput[3];
515 | }
516 | }
517 |
518 | if (GamePad.GetState(PlayerIndex.One).DPad.Right == ButtonState.Pressed)
519 | {
520 | if ((newbuttons & GamePadInput[4]) != GamePadInput[4])
521 | {
522 | newbuttons += GamePadInput[4];
523 | }
524 | }
525 |
526 | if (GamePad.GetState(PlayerIndex.One).DPad.Left == ButtonState.Pressed)
527 | {
528 | if ((newbuttons & GamePadInput[5]) != GamePadInput[5])
529 | {
530 | newbuttons += GamePadInput[5];
531 | }
532 | }
533 |
534 | if (GamePad.GetState(PlayerIndex.One).DPad.Up == ButtonState.Pressed)
535 | {
536 | if ((newbuttons & GamePadInput[6]) != GamePadInput[6])
537 | {
538 | newbuttons += GamePadInput[6];
539 | }
540 | }
541 |
542 | if (GamePad.GetState(PlayerIndex.One).DPad.Down == ButtonState.Pressed)
543 | {
544 | if ((newbuttons & GamePadInput[7]) != GamePadInput[7])
545 | {
546 | newbuttons += GamePadInput[7];
547 | }
548 | }
549 |
550 | if (GamePad.GetState(PlayerIndex.One).Buttons.RightShoulder == ButtonState.Pressed)
551 | {
552 | if ((newbuttons & GamePadInput[8]) != GamePadInput[8])
553 | {
554 | newbuttons += GamePadInput[8];
555 | }
556 | }
557 |
558 | if (GamePad.GetState(PlayerIndex.One).Buttons.LeftShoulder == ButtonState.Pressed)
559 | {
560 | if ((newbuttons & GamePadInput[9]) != GamePadInput[9])
561 | {
562 | newbuttons += GamePadInput[9];
563 | }
564 | }
565 |
566 | if (GamePad.GetState(PlayerIndex.One).Buttons.Y == ButtonState.Pressed)
567 | {
568 | if ((newbuttons & GamePadInput[10]) != GamePadInput[10])
569 | {
570 | newbuttons += GamePadInput[10];
571 | }
572 | }
573 |
574 | if (GamePad.GetState(PlayerIndex.One).Buttons.X == ButtonState.Pressed)
575 | {
576 | if ((newbuttons & GamePadInput[11]) != GamePadInput[11])
577 | {
578 | newbuttons += GamePadInput[11];
579 | }
580 | }
581 | }
582 |
583 | newbuttons ^= 0xFFF;
584 |
585 | //Touch
586 | if (Mouse.GetState().LeftButton == ButtonState.Pressed)
587 | {
588 | TouchInput(ref newtouch, ref touchclick, false);
589 | }
590 | else
591 | {
592 | touchclick = 0x00;
593 | if (useGamePad)
594 | {
595 | if (GamePad.GetState(PlayerIndex.One).Buttons.RightStick == ButtonState.Pressed)
596 | {
597 | newtouch = (uint)Math.Round(2047.5 + (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X * 2047.5));
598 | newtouch += (uint)Math.Round(2047.5 + (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y * 2047.5)) << 0x0C;
599 | newtouch += 0x1000000;
600 | }
601 | else
602 | {
603 | newtouch = 0x2000000;
604 | }
605 | }
606 | else
607 | {
608 | newtouch = 0x2000000;
609 | }
610 | }
611 |
612 | //Circle Pad
613 | if (Mouse.GetState().RightButton == ButtonState.Pressed)
614 | {
615 | TouchInput(ref newcpad, ref cpadclick, true);
616 | }
617 | else
618 | {
619 | cpadclick = 0x00;
620 | newcpad = (uint)Math.Round(2047.5 + (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X * 2047.5));
621 | newcpad += (uint)Math.Round(4095 - (2047.5 + (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y * 2047.5))) << 0x0C;
622 |
623 | if (newcpad == 0x800800)
624 | {
625 |
626 | if (Keyboard.GetState().IsKeyDown(KeyboardInput[12]))
627 | {
628 | newcpad = 0xFFF + (((newcpad >> 0x0C) & 0xFFF) << 0x0C);
629 | }
630 |
631 | if (Keyboard.GetState().IsKeyDown(KeyboardInput[13]))
632 | {
633 | newcpad = (((newcpad >> 0x0C) & 0xFFF) << 0x0C);
634 | }
635 |
636 | if (Keyboard.GetState().IsKeyDown(KeyboardInput[15]))
637 | {
638 | newcpad = (newcpad & 0xFFF) + (0x00 << 0x0C);
639 | }
640 |
641 | if (Keyboard.GetState().IsKeyDown(KeyboardInput[14]))
642 | {
643 | newcpad = (newcpad & 0xFFF) + (0xFFF << 0x0C);
644 | }
645 | }
646 |
647 | if (newcpad != 0x800800)
648 | {
649 | newcpad += 0x1000000;
650 | }
651 | }
652 |
653 | SendInput();
654 | }
655 |
656 | private void ReadIPInput()
657 | {
658 | if (!WaitForKeyUp)
659 | {
660 | for (int i = 0; i < ipKeysToCheck.Length; i++)
661 | {
662 | if (Keyboard.GetState().IsKeyDown(ipKeysToCheck[i]))
663 | {
664 | WaitForKeyUp = true;
665 | UpKey = ipKeysToCheck[i];
666 | switch (ipKeysToCheck[i])
667 | {
668 | case Keys.Back:
669 | case Keys.Delete:
670 | {
671 | if (IPAddress.Length != 0)
672 | {
673 | IPAddress = IPAddress.Substring(0, IPAddress.Length - 1);
674 | }
675 | }
676 | break;
677 |
678 | case Keys.Escape:
679 | {
680 | if (System.Net.IPAddress.TryParse(IPAddress, out ipAddress))
681 | {
682 | Mode = 0;
683 | IPAddress = ipAddress.ToString();
684 | SaveConfig();
685 | socket.Close();
686 | socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0);
687 |
688 | }
689 | }
690 | break;
691 |
692 | default:
693 | {
694 | if (IPAddress.Length < 15)
695 | {
696 | IPAddress += KeytoText(ipKeysToCheck[i]);
697 | }
698 | }
699 | break;
700 | }
701 | }
702 | }
703 | }
704 | else
705 | {
706 | if (Keyboard.GetState().IsKeyUp(UpKey))
707 | {
708 | WaitForKeyUp = false;
709 | }
710 | }
711 | }
712 |
713 | private void ReadKeyboardInput()
714 | {
715 | if (!WaitForKeyUp)
716 | {
717 | for (int i = 0; i < KeyboardInput.Length; i++)
718 | {
719 | if (Keyboard.GetState().IsKeyDown(KeyboardInput[i]))
720 | {
721 | WaitForKeyUp = true;
722 | UpKey = KeyboardInput[i];
723 | OldKey = KeyboardInput[i];
724 | KeyboardInput[i] = Keys.None;
725 | KeyIndex = (uint)i;
726 | Mode = 4;
727 | }
728 | }
729 |
730 | if (Keyboard.GetState().IsKeyDown(Keys.Escape))
731 | {
732 | Mode = 0;
733 | WaitForKeyUp = true;
734 | UpKey = Keys.Escape;
735 | SaveConfig();
736 | }
737 | }
738 | else
739 | {
740 | if (Keyboard.GetState().IsKeyUp(UpKey))
741 | {
742 | WaitForKeyUp = false;
743 | }
744 | }
745 | }
746 |
747 | private void ReadGamePadInput()
748 | {
749 | if (!WaitForKeyUp)
750 | {
751 | if(GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed)
752 | {
753 | Mode = 5;
754 | KeyIndex = 0;
755 | OldButton = GamePadInput[KeyIndex];
756 | GamePadInput[KeyIndex] = 0;
757 | }
758 |
759 | if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)
760 | {
761 | Mode = 5;
762 | KeyIndex = 1;
763 | OldButton = GamePadInput[KeyIndex];
764 | GamePadInput[KeyIndex] = 0;
765 | }
766 |
767 |
768 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
769 | {
770 | Mode = 5;
771 | KeyIndex = 2;
772 | OldButton = GamePadInput[KeyIndex];
773 | GamePadInput[KeyIndex] = 0;
774 | }
775 |
776 | if (GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed)
777 | {
778 | Mode = 5;
779 | KeyIndex = 3;
780 | OldButton = GamePadInput[KeyIndex];
781 | GamePadInput[KeyIndex] = 0;
782 | }
783 |
784 | if (GamePad.GetState(PlayerIndex.One).DPad.Right == ButtonState.Pressed)
785 | {
786 | Mode = 5;
787 | KeyIndex = 4;
788 | OldButton = GamePadInput[KeyIndex];
789 | GamePadInput[KeyIndex] = 0;
790 | }
791 |
792 | if (GamePad.GetState(PlayerIndex.One).DPad.Left == ButtonState.Pressed)
793 | {
794 | Mode = 5;
795 | KeyIndex = 5;
796 | OldButton = GamePadInput[KeyIndex];
797 | GamePadInput[KeyIndex] = 0;
798 | }
799 |
800 | if (GamePad.GetState(PlayerIndex.One).DPad.Up == ButtonState.Pressed)
801 | {
802 | Mode = 5;
803 | KeyIndex = 6;
804 | OldButton = GamePadInput[KeyIndex];
805 | GamePadInput[KeyIndex] = 0;
806 | }
807 |
808 | if (GamePad.GetState(PlayerIndex.One).DPad.Down == ButtonState.Pressed)
809 | {
810 | Mode = 5;
811 | KeyIndex = 7;
812 | OldButton = GamePadInput[KeyIndex];
813 | GamePadInput[KeyIndex] = 0;
814 | }
815 |
816 | if (GamePad.GetState(PlayerIndex.One).Buttons.RightShoulder == ButtonState.Pressed)
817 | {
818 | Mode = 5;
819 | KeyIndex = 8;
820 | OldButton = GamePadInput[KeyIndex];
821 | GamePadInput[KeyIndex] = 0;
822 | }
823 |
824 | if (GamePad.GetState(PlayerIndex.One).Buttons.LeftShoulder == ButtonState.Pressed)
825 | {
826 | Mode = 5;
827 | KeyIndex = 9;
828 | OldButton = GamePadInput[KeyIndex];
829 | GamePadInput[KeyIndex] = 0;
830 | }
831 |
832 | if (GamePad.GetState(PlayerIndex.One).Buttons.Y == ButtonState.Pressed)
833 | {
834 | Mode = 5;
835 | KeyIndex = 10;
836 | OldButton = GamePadInput[KeyIndex];
837 | GamePadInput[KeyIndex] = 0;
838 | }
839 |
840 | if (GamePad.GetState(PlayerIndex.One).Buttons.X == ButtonState.Pressed)
841 | {
842 | Mode = 5;
843 | KeyIndex = 11;
844 | OldButton = GamePadInput[KeyIndex];
845 | GamePadInput[KeyIndex] = 0;
846 | }
847 |
848 | if (Keyboard.GetState().IsKeyDown(Keys.Escape))
849 | {
850 | Mode = 0;
851 | WaitForKeyUp = true;
852 | UpKey = Keys.Escape;
853 | SaveConfig();
854 | }
855 | }
856 | else
857 | {
858 | if (Keyboard.GetState().IsKeyUp(UpKey))
859 | {
860 | WaitForKeyUp = false;
861 | }
862 | }
863 | }
864 |
865 | private void ShowMain()
866 | {
867 | if (debug)
868 | {
869 | DrawString(8, 8, "GamePad : " + useGamePad, Color.White);
870 | DrawString(8, 16, "IPAddress : " + IPAddress, Color.White);
871 | DrawString(8, 24, "Buttons : " + oldbuttons.ToString("X8"), Color.White);
872 | DrawString(8, 32, "Touch : " + oldtouch.ToString("X8"), Color.White);
873 | DrawString(8, 40, "CPad : " + oldcpad.ToString("X8"), Color.White);
874 |
875 | int mousex = Mouse.GetState().Position.X;
876 | int mousey = Mouse.GetState().Position.Y;
877 | if (oldtouch == 0x2000000)
878 | {
879 | if ((GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X == 0.0) && (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y == 0.0))
880 | {
881 | if (MouseInWindow(mousex, mousey))
882 | {
883 | spriteBatch.Draw(Cursor, new Rectangle(mousex - 1, mousey - 1, 3, 3), Color.Red);
884 | }
885 | }
886 | else
887 | {
888 | int stickx = (int)Math.Round(159.5 + (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.X * 159.5));
889 | int sticky = (int)Math.Round(119.5 + (GamePad.GetState(PlayerIndex.One).ThumbSticks.Right.Y * 119.5));
890 | spriteBatch.Draw(Cursor, new Rectangle(stickx - 1, sticky - 1, 3, 3), Color.Red);
891 | }
892 | }
893 | else
894 | {
895 | int touchx = (int)Math.Round(((double)(oldtouch & 0xFFF) / 0xFFF) * 319);
896 | int touchy = (int)Math.Round(((double)((oldtouch >> 0x0C) & 0xFFF) / 0xFFF) * 239);
897 | spriteBatch.Draw(Cursor, new Rectangle(touchx - 1, touchy - 1, 3, 3), Color.Green);
898 | }
899 |
900 | int cpadx = (int)Math.Round(((double)(oldcpad & 0xFFF) / 0xFFF) * 319);
901 | int cpady = (int)Math.Round(239 - (((double)((oldcpad >> 0x0C) & 0xFFF) / 0xFFF) * 239));
902 | spriteBatch.Draw(Cursor, new Rectangle(cpadx - 1, cpady - 1, 3, 3), Color.Blue);
903 | }
904 | }
905 |
906 | private void ShowIPInput()
907 | {
908 | DrawString(0, 0, "IP Address: " + IPAddress, Color.White);
909 | }
910 |
911 | private void ShowKeyboardInput()
912 | {
913 | DrawString(68, 28, "3DS : Keyboard", Color.White);
914 |
915 | DrawString(68, 44, "DPad Up : " + KeyboardInput[6], Color.White);
916 | DrawString(68, 52, "DPad Down : " + KeyboardInput[7], Color.White);
917 | DrawString(68, 60, "DPad Left : " + KeyboardInput[5], Color.White);
918 | DrawString(68, 68, "DPad Right : " + KeyboardInput[4], Color.White);
919 |
920 | DrawString(68, 84, "CPad Up : " + KeyboardInput[14], Color.White);
921 | DrawString(68, 92, "CPad Down : " + KeyboardInput[15], Color.White);
922 | DrawString(68, 100, "CPad Left : " + KeyboardInput[13], Color.White);
923 | DrawString(68, 108, "CPad Right : " + KeyboardInput[12], Color.White);
924 |
925 |
926 | DrawString(68, 124, "A : " + KeyboardInput[0], Color.White);
927 | DrawString(68, 132, "B : " + KeyboardInput[1], Color.White);
928 | DrawString(68, 140, "Y : " + KeyboardInput[11], Color.White);
929 | DrawString(68, 148, "X : " + KeyboardInput[10], Color.White);
930 |
931 | DrawString(68, 164, "L : " + KeyboardInput[9], Color.White);
932 | DrawString(68, 172, "R : " + KeyboardInput[8], Color.White);
933 | DrawString(68, 180, "Start : " + KeyboardInput[3], Color.White);
934 | DrawString(68, 188, "Select : " + KeyboardInput[2], Color.White);
935 | }
936 |
937 | private void ShowGamePadInput()
938 | {
939 | DrawString(68, 28, "Controller : 3DS", Color.White);
940 | DrawString(68, 44, "DPad Up : " + GetButtonNameFromValue(GamePadInput[6]), Color.White);
941 | DrawString(68, 52, "DPad Down : " + GetButtonNameFromValue(GamePadInput[7]), Color.White);
942 | DrawString(68, 60, "DPad Left : " + GetButtonNameFromValue(GamePadInput[5]), Color.White);
943 | DrawString(68, 68, "DPad Right : " + GetButtonNameFromValue(GamePadInput[4]), Color.White);
944 |
945 | DrawString(68, 84, "Y Axis+ : CPad Up", Color.Gray);
946 | DrawString(68, 92, "Y Axis- : CPad Down", Color.Gray);
947 | DrawString(68, 100, "X Axis+ : CPad Left", Color.Gray);
948 | DrawString(68, 108, "X Axis- : CPad Right", Color.Gray);
949 |
950 |
951 | DrawString(68, 124, "B : " + GetButtonNameFromValue(GamePadInput[0]), Color.White);
952 | DrawString(68, 132, "A : " + GetButtonNameFromValue(GamePadInput[1]), Color.White);
953 | DrawString(68, 140, "X : " + GetButtonNameFromValue(GamePadInput[11]), Color.White);
954 | DrawString(68, 148, "Y : " + GetButtonNameFromValue(GamePadInput[10]), Color.White);
955 |
956 | DrawString(68, 164, "LB : " + GetButtonNameFromValue(GamePadInput[9]), Color.White);
957 | DrawString(68, 172, "RB : " + GetButtonNameFromValue(GamePadInput[8]), Color.White);
958 | DrawString(68, 180, "Start : " + GetButtonNameFromValue(GamePadInput[3]), Color.White);
959 | DrawString(68, 188, "Back : " + GetButtonNameFromValue(GamePadInput[2]), Color.White);
960 | }
961 |
962 | private string GetButtonNameFromValue(uint value)
963 | {
964 | string result = "None";
965 |
966 | for(int i = 0; i < ButtonNames.Length; i++)
967 | {
968 | if((value >> i) == 0x01)
969 | {
970 | result = ButtonNames[i];
971 | break;
972 | }
973 | }
974 |
975 | return result;
976 | }
977 |
978 | private string KeytoText(Keys key)
979 | {
980 | string result = "";
981 |
982 | switch (key)
983 | {
984 | case Keys.NumPad0:
985 | case Keys.NumPad1:
986 | case Keys.NumPad2:
987 | case Keys.NumPad3:
988 | case Keys.NumPad4:
989 | case Keys.NumPad5:
990 | case Keys.NumPad6:
991 | case Keys.NumPad7:
992 | case Keys.NumPad8:
993 | case Keys.NumPad9:
994 | {
995 | result = key.ToString().Substring(6);
996 | }
997 | break;
998 |
999 | case Keys.D0:
1000 | case Keys.D1:
1001 | case Keys.D2:
1002 | case Keys.D3:
1003 | case Keys.D4:
1004 | case Keys.D5:
1005 | case Keys.D6:
1006 | case Keys.D7:
1007 | case Keys.D8:
1008 | case Keys.D9:
1009 | {
1010 | result = key.ToString().Substring(1);
1011 | }
1012 | break;
1013 |
1014 | case Keys.Decimal:
1015 | case Keys.OemPeriod:
1016 | {
1017 | result = ".";
1018 | }
1019 | break;
1020 | }
1021 | return result;
1022 | }
1023 |
1024 | private void DrawString(int X, int Y, string data, Color color)
1025 | {
1026 | int TexX = 0;
1027 | int TexY = 0;
1028 | for (int i = 0; i < data.Length; i++)
1029 | {
1030 | TexX = ((data[i]) & 0x0F) * 0x08;
1031 | TexY = (((data[i]) & 0xF0) >> 0x04) * 0x08;
1032 | spriteBatch.Draw(Font, new Rectangle(X, Y, 8, 8), new Rectangle(TexX, TexY, 8, 8), color);
1033 | X += 8;
1034 | }
1035 | }
1036 |
1037 | private bool MouseInWindow(int x, int y)
1038 | {
1039 | bool result = false;
1040 | if (((x >= 0) && (x < 320)) && ((y >= 0) && (y < 240)))
1041 | {
1042 | result = true;
1043 | }
1044 | return result;
1045 | }
1046 |
1047 | private void ClampValues(ref int x, ref int y)
1048 | {
1049 | if (x < 0)
1050 | {
1051 | x = 0;
1052 | }
1053 |
1054 | if (y < 0)
1055 | {
1056 | y = 0;
1057 | }
1058 |
1059 | if (x > 319)
1060 | {
1061 | x = 319;
1062 | }
1063 |
1064 | if (y > 239)
1065 | {
1066 | y = 239;
1067 | }
1068 | }
1069 |
1070 | private void TouchInput(ref uint value, ref uint mouseclick, bool cpad)
1071 | {
1072 | int X = Mouse.GetState().Position.X;
1073 | int Y = Mouse.GetState().Position.Y;
1074 |
1075 | if (mouseclick == 0x00)
1076 | {
1077 | if (MouseInWindow(X, Y))
1078 | {
1079 | mouseclick = 0x01;
1080 | }
1081 | else
1082 | {
1083 | mouseclick = 0x02;
1084 | }
1085 | }
1086 |
1087 | if (mouseclick == 0x01)
1088 | {
1089 | ClampValues(ref X, ref Y);
1090 | X = (int)Math.Round(((double)X / 319) * 4095);
1091 | if (cpad)
1092 | {
1093 | Y = (int)(4095 - Math.Round(((double)Y / 239) * 4095));
1094 | }
1095 | else
1096 | {
1097 | Y = (int)Math.Round(((double)Y / 239) * 4095);
1098 | }
1099 | value = (uint)X + ((uint)Y << 0x0C) + 0x01000000;
1100 | }
1101 | }
1102 |
1103 | private void SendInput()
1104 | {
1105 | if (socket.Connected)
1106 | {
1107 | if ((newbuttons != oldbuttons) || (newtouch != oldtouch) || (newcpad != oldcpad))
1108 | {
1109 | oldbuttons = newbuttons;
1110 | oldtouch = newtouch;
1111 | oldcpad = newcpad;
1112 |
1113 | //Buttons
1114 | data[0x00] = (byte)(oldbuttons & 0xFF);
1115 | data[0x01] = (byte)((oldbuttons >> 0x08) & 0xFF);
1116 | data[0x02] = (byte)((oldbuttons >> 0x10) & 0xFF);
1117 | data[0x03] = (byte)((oldbuttons >> 0x18) & 0xFF);
1118 |
1119 | //Touch
1120 | data[0x04] = (byte)(oldtouch & 0xFF);
1121 | data[0x05] = (byte)((oldtouch >> 0x08) & 0xFF);
1122 | data[0x06] = (byte)((oldtouch >> 0x10) & 0xFF);
1123 | data[0x07] = (byte)((oldtouch >> 0x18) & 0xFF);
1124 |
1125 | //CPad
1126 | data[0x08] = (byte)(oldcpad & 0xFF);
1127 | data[0x09] = (byte)((oldcpad >> 0x08) & 0xFF);
1128 | data[0x0A] = (byte)((oldcpad >> 0x10) & 0xFF);
1129 | data[0x0B] = (byte)((oldcpad >> 0x18) & 0xFF);
1130 |
1131 | try
1132 | {
1133 | socket.Send(data);
1134 | }
1135 | catch { }
1136 | }
1137 | }
1138 | }
1139 | }
1140 | }
1141 |
--------------------------------------------------------------------------------