diff --git a/BackgroundColor.ini b/BackgroundColor.ini new file mode 100644 index 0000000..fa44ef1 --- /dev/null +++ b/BackgroundColor.ini @@ -0,0 +1 @@ +0,0,0 diff --git a/JoystickDisplay.cs b/JoystickDisplay.cs index 9cffae8..c697121 100644 --- a/JoystickDisplay.cs +++ b/JoystickDisplay.cs @@ -4,489 +4,490 @@ namespace JoystickDisplay { - public partial class Display : Form - { - private static int joyX; - private static int joyY; - private static int A; - private static int B; - private static int X; - private static int Y; - private static int L; - private static int R; - private static int S; - - private static int prevA; - private static int prevB; - private static int prevX; - private static int prevY; - private static int prevL; - private static int prevR; - private static int prevS; - - private static int countA; - private static int countB; - private static int countX; - private static int countY; - private static int countL; - private static int countR; - private static int countS; - - private static Rectangle recA; - private static Rectangle recB; - private static Rectangle recX; - private static Rectangle recY; - private static Rectangle recL; - private static Rectangle recR; - private static Rectangle recS; - - private static Bitmap imgBase; - private static Bitmap imgStick; - private static Bitmap imgStickSmall; - private static Bitmap imgA; - private static Bitmap imgB; - private static Bitmap imgX; - private static Bitmap imgY; - private static Bitmap imgL; - private static Bitmap imgR; - private static Bitmap imgS; - - private static Pen penBlack; - private static Font fontArial; - - private static StringFormat formatLeft; - private static StringFormat formatCenter; - private static StringFormat formatRight; - - private static int folderIndex = 0; - - private static bool drawButtonCount = false; - - public Display() - { - joyX = 0; - joyY = 0; - A = 1; - B = 1; - X = 1; - Y = 1; - L = 1; - R = 1; - S = 1; - - prevA = 1; - prevB = 1; - prevX = 1; - prevY = 1; - prevL = 1; - prevR = 1; - prevS = 1; - - countA = 0; - countB = 0; - countX = 0; - countY = 0; - countL = 0; - countR = 0; - countS = 0; - - - - try - { - string[] lines = System.IO.File.ReadAllLines("Index.ini"); - int savedIndex = Int32.Parse(lines[0]); - folderIndex = savedIndex; - } - catch {} - - string path = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); - string[] folders = System.IO.Directory.GetDirectories(path,"*", System.IO.SearchOption.AllDirectories); - string folder = folders[folderIndex]; - - imgBase = new Bitmap(folder+"/base.png"); - imgStick = new Bitmap(folder+"/stick.png"); - imgA = new Bitmap(folder+"/buttA.png"); - imgB = new Bitmap(folder+"/buttB.png"); - imgX = new Bitmap(folder+"/buttX.png"); - imgY = new Bitmap(folder+"/buttY.png"); - imgL = new Bitmap(folder+"/buttL.png"); - imgR = new Bitmap(folder+"/buttR.png"); - imgS = new Bitmap(folder+"/buttS.png"); - imgStickSmall = new Bitmap(folder+"/stickSmall.png"); - - penBlack = new Pen(Color.Black, 1); - fontArial = new Font("Arial", 16, FontStyle.Bold, GraphicsUnit.Point); - - recL = new Rectangle(40, 4 , 96, 36); - recY = new Rectangle(40, 52 , 96, 36); - recA = new Rectangle(40, 100, 96, 36); - recR = new Rectangle(80, 4 , 96, 36); - recX = new Rectangle(80, 52 , 96, 36); - recB = new Rectangle(80, 100, 96, 36); - recS = new Rectangle(60, 28 , 96, 36); - - formatLeft = new StringFormat(); - formatCenter = new StringFormat(); - formatRight = new StringFormat(); - - formatLeft .Alignment = StringAlignment.Near; - formatLeft .LineAlignment = StringAlignment.Center; - - formatCenter.Alignment = StringAlignment.Center; - formatCenter.LineAlignment = StringAlignment.Center; - - formatRight .Alignment = StringAlignment.Far; - formatRight .LineAlignment = StringAlignment.Center; - - this.DoubleBuffered = true; - this.Icon = new Icon("icon.ico"); - - this.KeyPreview = true; - this.PreviewKeyDown += new PreviewKeyDownEventHandler(keyPress); - } - - public void setControllerDataSA2(int buttons, int newX, int newY) - { - A = buttons & 256; - B = buttons & 512; - Y = buttons & 2048; - X = buttons & 1024; - S = buttons & 4096; - R = buttons & 32; - L = buttons & 64; - - joyX = newX; - joyY = newY; - - //D-Pad - int up = buttons & 8; - int down = buttons & 4; - int left = buttons & 1; - int right = buttons & 2; - - if (right != 0) - { - joyX = 127; - } - else if (left != 0) - { - joyX = -128; - } - - if (up != 0) - { - joyY = 127; - } - else if (down != 0) - { - joyY = -128; - } - - refreshButtonCounts(); - } - - public void setControllerDataSADX(int buttons, int newX, int newY) - { - A = buttons & 4; - B = buttons & 2; - Y = buttons & 512; - X = buttons & 1024; - S = buttons & 8; - R = buttons & 65536; - L = buttons & 131072; - - joyX = newX; - joyY = newY; - - //D-Pad - int up = buttons & 16; - int down = buttons & 32; - int left = buttons & 64; - int right = buttons & 128; - - if (right != 0) - { - joyX = 127; - } - else if (left != 0) - { - joyX = -128; - } - - if (up != 0) - { - joyY = 127; - } - else if (down != 0) - { - joyY = -128; - } - - refreshButtonCounts(); - } - - public void setControllerDataHeroes(int buttons, float newX, float newY, float camPan) - { - A = buttons & 1; - B = buttons & 2; - Y = buttons & 8; - X = buttons & 4; - S = buttons & 16384; - R = buttons & 512; - L = buttons & 256; - - if (camPan < -0.3) - { - R = 1; - } - - if (camPan > 0.3) - { - L = 1; - } - - joyX = (int)(newX*127); - joyY = (int)(-newY*127); - - //D-Pad - int up = buttons & 16; - int down = buttons & 32; - int left = buttons & 64; - int right = buttons & 128; - - if (right != 0) - { - joyX = 127; - } - else if (left != 0) - { - joyX = -128; - } - - if (up != 0) - { - joyY = 127; - } - else if (down != 0) - { - joyY = -128; - } - - refreshButtonCounts(); - } - - public void setControllerDataMania(int buttons, int stick) - { - A = buttons & 16; - B = buttons & 32; - Y = buttons & 128; - X = buttons & 64; - S = stick & 16; - - R = 0; - L = 0; - - joyX = 0; - joyY = 0; - - int up = stick & 1; - int down = stick & 2; - int left = stick & 4; - int right = stick & 8; - - if (right != 0) - { - joyX = 127; - } - else if (left != 0) - { - joyX = -128; - } - - if (up != 0) - { - joyY = 127; - } - else if (down != 0) - { - joyY = -128; - } - - refreshButtonCounts(); - } - - protected override void OnPaint(PaintEventArgs e) - { - if (A != 0) - { - e.Graphics.DrawImage(imgA, 4, 100); - } - - if (B != 0) - { - e.Graphics.DrawImage(imgB, 180, 100); - } - - if (X != 0) - { - e.Graphics.DrawImage(imgX, 180, 52); - } - - if (Y != 0) - { - e.Graphics.DrawImage(imgY, 4, 52); - } + public partial class Display : Form + { + private static int joyX; + private static int joyY; + private static int A; + private static int B; + private static int X; + private static int Y; + private static int L; + private static int R; + private static int S; + + private static int prevA; + private static int prevB; + private static int prevX; + private static int prevY; + private static int prevL; + private static int prevR; + private static int prevS; + + private static int countA; + private static int countB; + private static int countX; + private static int countY; + private static int countL; + private static int countR; + private static int countS; + + private static Rectangle recA; + private static Rectangle recB; + private static Rectangle recX; + private static Rectangle recY; + private static Rectangle recL; + private static Rectangle recR; + private static Rectangle recS; + + private static Bitmap imgBase; + private static Bitmap imgStick; + private static Bitmap imgStickSmall; + private static Bitmap imgA; + private static Bitmap imgB; + private static Bitmap imgX; + private static Bitmap imgY; + private static Bitmap imgL; + private static Bitmap imgR; + private static Bitmap imgS; + + private static Pen penBlack; + private static Font fontArial; + + private static StringFormat formatLeft; + private static StringFormat formatCenter; + private static StringFormat formatRight; + + private static int folderIndex; + + private static bool drawButtonCount = false; + + public Display() + { + joyX = 0; + joyY = 0; + A = 1; + B = 1; + X = 1; + Y = 1; + L = 1; + R = 1; + S = 1; + + prevA = 1; + prevB = 1; + prevX = 1; + prevY = 1; + prevL = 1; + prevR = 1; + prevS = 1; + + countA = 0; + countB = 0; + countX = 0; + countY = 0; + countL = 0; + countR = 0; + countS = 0; + + folderIndex = 0; + + + try + { + string[] lines = System.IO.File.ReadAllLines("Index.ini"); + int savedIndex = Int32.Parse(lines[0]); + folderIndex = savedIndex; + } + catch {} + + reloadImages(); + + penBlack = new Pen(Color.Black, 1); + fontArial = new Font("Arial", 16, FontStyle.Bold, GraphicsUnit.Point); + + recL = new Rectangle(40, 4 , 96, 36); + recY = new Rectangle(40, 52 , 96, 36); + recA = new Rectangle(40, 100, 96, 36); + recR = new Rectangle(80, 4 , 96, 36); + recX = new Rectangle(80, 52 , 96, 36); + recB = new Rectangle(80, 100, 96, 36); + recS = new Rectangle(60, 28 , 96, 36); + + formatLeft = new StringFormat(); + formatCenter = new StringFormat(); + formatRight = new StringFormat(); + + formatLeft .Alignment = StringAlignment.Near; + formatLeft .LineAlignment = StringAlignment.Center; + + formatCenter.Alignment = StringAlignment.Center; + formatCenter.LineAlignment = StringAlignment.Center; + + formatRight .Alignment = StringAlignment.Far; + formatRight .LineAlignment = StringAlignment.Center; + + this.DoubleBuffered = true; + this.Icon = new Icon("icon.ico"); + + this.KeyPreview = true; + this.PreviewKeyDown += new PreviewKeyDownEventHandler(keyPress); + } + + public void setControllerDataSA2(int buttons, int newX, int newY) + { + A = buttons & 256; + B = buttons & 512; + Y = buttons & 2048; + X = buttons & 1024; + S = buttons & 4096; + R = buttons & 32; + L = buttons & 64; + + joyX = newX; + joyY = newY; + + //D-Pad + int up = buttons & 8; + int down = buttons & 4; + int left = buttons & 1; + int right = buttons & 2; + + if (right != 0) + { + joyX = 127; + } + else if (left != 0) + { + joyX = -128; + } + + if (up != 0) + { + joyY = 127; + } + else if (down != 0) + { + joyY = -128; + } + + refreshButtonCounts(); + } + + public void setControllerDataSADX(int buttons, int newX, int newY) + { + A = buttons & 4; + B = buttons & 2; + Y = buttons & 512; + X = buttons & 1024; + S = buttons & 8; + R = buttons & 65536; + L = buttons & 131072; + + joyX = newX; + joyY = newY; + + //D-Pad + int up = buttons & 16; + int down = buttons & 32; + int left = buttons & 64; + int right = buttons & 128; + + if (right != 0) + { + joyX = 127; + } + else if (left != 0) + { + joyX = -128; + } + + if (up != 0) + { + joyY = 127; + } + else if (down != 0) + { + joyY = -128; + } + + refreshButtonCounts(); + } + + public void setControllerDataHeroes(int buttons, float newX, float newY, float camPan) + { + A = buttons & 1; + B = buttons & 2; + Y = buttons & 8; + X = buttons & 4; + S = buttons & 16384; + R = buttons & 512; + L = buttons & 256; + + if (camPan < -0.3) + { + R = 1; + } + + if (camPan > 0.3) + { + L = 1; + } + + joyX = (int)(newX*127); + joyY = (int)(-newY*127); + + //D-Pad + int up = buttons & 16; + int down = buttons & 32; + int left = buttons & 64; + int right = buttons & 128; + + if (right != 0) + { + joyX = 127; + } + else if (left != 0) + { + joyX = -128; + } + + if (up != 0) + { + joyY = 127; + } + else if (down != 0) + { + joyY = -128; + } + + refreshButtonCounts(); + } + + public void setControllerDataMania(int buttons, int stick) + { + A = buttons & 16; + B = buttons & 32; + Y = buttons & 128; + X = buttons & 64; + S = stick & 16; + + R = 0; + L = 0; + + joyX = 0; + joyY = 0; + + int up = stick & 1; + int down = stick & 2; + int left = stick & 4; + int right = stick & 8; + + if (right != 0) + { + joyX = 127; + } + else if (left != 0) + { + joyX = -128; + } + + if (up != 0) + { + joyY = 127; + } + else if (down != 0) + { + joyY = -128; + } + + refreshButtonCounts(); + } + + protected override void OnPaint(PaintEventArgs e) + { + if (A != 0) + { + e.Graphics.DrawImage(imgA, 4, 100, 32, 32); + } + + if (B != 0) + { + e.Graphics.DrawImage(imgB, 180, 100, 32, 32); + } + + if (X != 0) + { + e.Graphics.DrawImage(imgX, 180, 52, 32, 32); + } + + if (Y != 0) + { + e.Graphics.DrawImage(imgY, 4, 52, 32, 32); + } - if (L != 0) - { - e.Graphics.DrawImage(imgL, 4, 4); - } + if (L != 0) + { + e.Graphics.DrawImage(imgL, 4, 4, 32, 32); + } - if (R != 0) - { - e.Graphics.DrawImage(imgR, 180, 4); - } + if (R != 0) + { + e.Graphics.DrawImage(imgR, 180, 4, 32, 32); + } - if (!drawButtonCount) - { - if (S != 0) - { - e.Graphics.DrawImage(imgS, 156, 4); - } + if (!drawButtonCount) + { + if (S != 0) + { + e.Graphics.DrawImage(imgS, 156, 4, 16, 16); + } - int drawX = 108+((64*joyX)/128); - int drawY = 68 -((64*joyY)/128); + int drawX = 108+((64*joyX)/128); + int drawY = 68 -((64*joyY)/128); - e.Graphics.DrawImage(imgBase, 108-64, 68-64); - e.Graphics.DrawLine(penBlack, 108, 68, drawX, drawY); - e.Graphics.DrawImage(imgStickSmall, drawX-4, drawY-4); + e.Graphics.DrawImage(imgBase, 108-64, 68-64, 128, 128); + e.Graphics.DrawLine(penBlack, 108, 68, drawX, drawY); + e.Graphics.DrawImage(imgStickSmall, drawX-4, drawY-4, 8, 8); - double radius = Math.Min(Math.Sqrt((joyX*joyX)+(joyY*joyY)), 128.0); - double angle = Math.Atan2(joyY, joyX); - int capX = (int)(radius*Math.Cos(angle)); - int capY = (int)(radius*Math.Sin(angle)); - int drawCapX = 108+((64*capX)/128); - int drawCapY = 68 -((64*capY)/128); + double radius = Math.Min(Math.Sqrt((joyX*joyX)+(joyY*joyY)), 128.0); + double angle = Math.Atan2(joyY, joyX); + int capX = (int)(radius*Math.Cos(angle)); + int capY = (int)(radius*Math.Sin(angle)); + int drawCapX = 108+((64*capX)/128); + int drawCapY = 68 -((64*capY)/128); - e.Graphics.DrawImage(imgStick, drawCapX-4, drawCapY-4); - } - else - { - if (S != 0) - { - e.Graphics.DrawImage(imgS, 100, 12); - } - - e.Graphics.DrawString(""+countL, fontArial, Brushes.White, recL, formatLeft); - e.Graphics.DrawString(""+countY, fontArial, Brushes.White, recY, formatLeft); - e.Graphics.DrawString(""+countA, fontArial, Brushes.White, recA, formatLeft); - e.Graphics.DrawString(""+countR, fontArial, Brushes.White, recR, formatRight); - e.Graphics.DrawString(""+countX, fontArial, Brushes.White, recX, formatRight); - e.Graphics.DrawString(""+countB, fontArial, Brushes.White, recB, formatRight); - e.Graphics.DrawString(""+countS, fontArial, Brushes.White, recS, formatCenter); - } + e.Graphics.DrawImage(imgStick, drawCapX-4, drawCapY-4, 8, 8); + } + else + { + if (S != 0) + { + e.Graphics.DrawImage(imgS, 100, 12, 16, 16); + } + + e.Graphics.DrawString(""+countL, fontArial, Brushes.White, recL, formatLeft); + e.Graphics.DrawString(""+countY, fontArial, Brushes.White, recY, formatLeft); + e.Graphics.DrawString(""+countA, fontArial, Brushes.White, recA, formatLeft); + e.Graphics.DrawString(""+countR, fontArial, Brushes.White, recR, formatRight); + e.Graphics.DrawString(""+countX, fontArial, Brushes.White, recX, formatRight); + e.Graphics.DrawString(""+countB, fontArial, Brushes.White, recB, formatRight); + e.Graphics.DrawString(""+countS, fontArial, Brushes.White, recS, formatCenter); + } - base.OnPaint(e); - } - - public void refreshButtonCounts() - { - if (A != 0 && prevA == 0) { countA++; } - if (B != 0 && prevB == 0) { countB++; } - if (X != 0 && prevX == 0) { countX++; } - if (Y != 0 && prevY == 0) { countY++; } - if (L != 0 && prevL == 0) { countL++; } - if (R != 0 && prevR == 0) { countR++; } - if (S != 0 && prevS == 0) { countS++; } - - prevA = A; - prevB = B; - prevX = X; - prevY = Y; - prevL = L; - prevR = R; - prevS = S; - } - - public void keyPress(object sender, PreviewKeyDownEventArgs e) - { - string path = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); - string[] folders = System.IO.Directory.GetDirectories(path,"*", System.IO.SearchOption.AllDirectories); - - int prevFolderIndex = folderIndex; - - folderIndex = Math.Max(0, Math.Min(folders.Length-1, folderIndex)); - - switch (e.KeyCode) - { - case Keys.Left: - { - folderIndex--; - if (folderIndex == -1) - { - folderIndex = folders.Length-1; - } - break; - } - - case Keys.Right: - { - folderIndex++; - if (folderIndex == folders.Length) - { - folderIndex = 0; - } - break; - } - - case Keys.R: - { - countA = 0; - countB = 0; - countX = 0; - countY = 0; - countL = 0; - countR = 0; - countS = 0; - break; - } - - case Keys.B: - { - drawButtonCount = !drawButtonCount; - break; - } - - default: - break; - } - - if (folderIndex != prevFolderIndex) - { - string folder = folders[folderIndex]; - - imgBase = new Bitmap(folder+"/base.png"); - imgStick = new Bitmap(folder+"/stick.png"); - imgA = new Bitmap(folder+"/buttA.png"); - imgB = new Bitmap(folder+"/buttB.png"); - imgX = new Bitmap(folder+"/buttX.png"); - imgY = new Bitmap(folder+"/buttY.png"); - imgL = new Bitmap(folder+"/buttL.png"); - imgR = new Bitmap(folder+"/buttR.png"); - imgS = new Bitmap(folder+"/buttS.png"); - imgStickSmall = new Bitmap(folder+"/stickSmall.png"); - } - } - - public void saveIndex() - { - try - { - string text = ""+folderIndex; - System.IO.File.WriteAllText("Index.ini", text); - } - catch {} - } - } -} + base.OnPaint(e); + } + + public void refreshButtonCounts() + { + if (A != 0 && prevA == 0) { countA++; } + if (B != 0 && prevB == 0) { countB++; } + if (X != 0 && prevX == 0) { countX++; } + if (Y != 0 && prevY == 0) { countY++; } + if (L != 0 && prevL == 0) { countL++; } + if (R != 0 && prevR == 0) { countR++; } + if (S != 0 && prevS == 0) { countS++; } + + prevA = A; + prevB = B; + prevX = X; + prevY = Y; + prevL = L; + prevR = R; + prevS = S; + } + + public void reloadImages() + { + string path = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); + string[] folders = System.IO.Directory.GetDirectories(path,"*", System.IO.SearchOption.AllDirectories); + + if (folderIndex < 0 || folderIndex >= folders.Length) + { + folderIndex = 0; + } + + string folder = folders[folderIndex]; + + imgBase = new Bitmap(folder+"/base.png", false); + imgStick = new Bitmap(folder+"/stick.png", false); + imgA = new Bitmap(folder+"/buttA.png", false); + imgB = new Bitmap(folder+"/buttB.png", false); + imgX = new Bitmap(folder+"/buttX.png", false); + imgY = new Bitmap(folder+"/buttY.png", false); + imgL = new Bitmap(folder+"/buttL.png", false); + imgR = new Bitmap(folder+"/buttR.png", false); + imgS = new Bitmap(folder+"/buttS.png", false); + imgStickSmall = new Bitmap(folder+"/stickSmall.png", false); + } + + public void keyPress(object sender, PreviewKeyDownEventArgs e) + { + string path = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); + string[] folders = System.IO.Directory.GetDirectories(path,"*", System.IO.SearchOption.AllDirectories); + + int prevFolderIndex = folderIndex; + + folderIndex = Math.Max(0, Math.Min(folders.Length-1, folderIndex)); + + switch (e.KeyCode) + { + case Keys.Left: + { + folderIndex--; + if (folderIndex == -1) + { + folderIndex = folders.Length-1; + } + break; + } + + case Keys.Right: + { + folderIndex++; + if (folderIndex == folders.Length) + { + folderIndex = 0; + } + break; + } + + case Keys.R: + { + countA = 0; + countB = 0; + countX = 0; + countY = 0; + countL = 0; + countR = 0; + countS = 0; + break; + } + + case Keys.B: + { + drawButtonCount = !drawButtonCount; + break; + } + + default: + break; + } + + if (folderIndex != prevFolderIndex) + { + reloadImages(); + } + } + + public void saveIndex() + { + try + { + string text = ""+folderIndex; + System.IO.File.WriteAllText("Index.ini", text); + } + catch {} + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index 773b092..39e4d70 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,15 @@ An input display that directly reads what the game sees as input from your contr ![Imgur](http://i.imgur.com/cca2wiI.png) ### Download the exe: -https://github.com/TurtleMan64/SADX-SA2-Input-Display/releases/tag/v1.5 +https://github.com/TurtleMan64/SADX-SA2-Input-Display/releases/tag/latest -How to compile: +#### How to compile: Compile JoystickDisplay.cs as a DLL with the command: -C:/Windows/Microsoft.NET/Framework/v4.0.30319/csc.exe /target:library /out:joydisp.DLL JoystickDisplay.cs +`C:/Windows/Microsoft.NET/Framework/v4.0.30319/csc.exe /target:library /out:joydisp.DLL JoystickDisplay.cs` Now compile the main SonicInputDisplay.cs while linking the library: -C:/Windows/Microsoft.NET/Framework/v4.0.30319/csc.exe /out:SonicInputDisplay.exe /reference:joydisp.DLL SonicInputDisplay.cs +`C:/Windows/Microsoft.NET/Framework/v4.0.30319/csc.exe /out:SonicInputDisplay.exe /reference:joydisp.DLL SonicInputDisplay.cs` -Now you have the SonicInputDisplay.exe that you can run. Make sure that you run it in the same folder as the res folder that contains all of the images. +Now you have the `SonicInputDisplay.exe` that you can run. Make sure that you run it in the same folder as the res folder that contains all of the images. diff --git a/SonicInputDisplay.cs b/SonicInputDisplay.cs index 722bcb5..e17c38b 100644 --- a/SonicInputDisplay.cs +++ b/SonicInputDisplay.cs @@ -9,7 +9,7 @@ public class SonicInputDisplay { - const int PROCESS_WM_READ = 0x0010; + const int PROCESS_VM_READ = 0x0010; const int SW_HIDE = 0; [DllImport("kernel32.dll")] @@ -24,63 +24,74 @@ public class SonicInputDisplay [DllImport("kernel32.dll")] public static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesRead); - + public static IntPtr processHandle = IntPtr.Zero; - public static int gameID = -1; - public static bool loop = true; - - private static Display theDisplay; - - public static void Main() + public static int gameID = -1; + public static bool loop = true; + + private static Display theDisplay; + + public static void Main() { - var handle = GetConsoleWindow(); + var handle = GetConsoleWindow(); ShowWindow(handle, SW_HIDE); - - theDisplay = new Display(); - theDisplay.ClientSize = new Size(216, 136); - theDisplay.MinimizeBox = false; - theDisplay.MaximizeBox = false; - theDisplay.FormBorderStyle = FormBorderStyle.FixedSingle; - theDisplay.StartPosition = FormStartPosition.CenterScreen; - theDisplay.BackColor = Color.FromArgb(2, 2, 2); //Almost, but not exactly black - theDisplay.Text = "Searching for game..."; - - //Thread to handle the window + + theDisplay = new Display(); + theDisplay.ClientSize = new Size(216, 136); + theDisplay.MinimizeBox = false; + theDisplay.MaximizeBox = false; + theDisplay.FormBorderStyle = FormBorderStyle.FixedSingle; + theDisplay.StartPosition = FormStartPosition.CenterScreen; + theDisplay.BackColor = Color.FromArgb(2, 2, 2); //Almost, but not exactly black + theDisplay.Text = "Searching for game..."; + + try + { + string[] lines = System.IO.File.ReadAllLines("BackgroundColor.ini"); + string[] color = lines[0].Split(','); + int r = Int32.Parse(color[0]); + int g = Int32.Parse(color[1]); + int b = Int32.Parse(color[2]); + theDisplay.BackColor = Color.FromArgb(r, g, b); + } + catch {} + + //Thread to handle the window new Thread(() => { Thread.CurrentThread.IsBackground = true; theDisplay.ShowDialog(); - theDisplay.saveIndex(); + theDisplay.saveIndex(); loop = false; }).Start(); - - while (loop) + + while (loop) { - switch (gameID) - { - case 0: setValuesFromSA2(); break; - - case 1: setValuesFromSADX(); break; - - case 2: setValuesFromHeroes(); break; - - case 3: setValuesFromMania(); break; - - default: attatchToGame(); break; - } - theDisplay.Refresh(); + switch (gameID) + { + case 0: setValuesFromSA2(); break; + + case 1: setValuesFromSADX(); break; + + case 2: setValuesFromHeroes(); break; + + case 3: setValuesFromMania(); break; + + default: attatchToGame(); break; + } + theDisplay.Refresh(); System.Threading.Thread.Sleep(14); } - } + } - private static void setValuesFromSA2() - { - int bytesRead = 0; + private static void setValuesFromSA2() + { + int bytesRead = 0; byte[] buffer = new byte[12]; if (ReadProcessMemory((int)processHandle, 0x01A52C4C, buffer, 12, ref bytesRead) == false || bytesRead != 12) { - theDisplay.setControllerDataSA2(0, 0, 0); - gameID = -1; + theDisplay.setControllerDataSA2(0, 0, 0); + gameID = -1; return; } @@ -89,30 +100,30 @@ private static void setValuesFromSA2() buttons+=buffer[1]<<8; buttons+=buffer[2]<<16; buttons+=buffer[3]<<24; - - int joyX = 0; - joyX+=buffer[4]; + + int joyX = 0; + joyX+=buffer[4]; joyX+=buffer[5]<<8; joyX+=buffer[6]<<16; joyX+=buffer[7]<<24; - - int joyY = 0; - joyY+=buffer[8]; + + int joyY = 0; + joyY+=buffer[8]; joyY+=buffer[9]<<8; joyY+=buffer[10]<<16; joyY+=buffer[11]<<24; - - theDisplay.setControllerDataSA2(buttons, joyX, joyY); - } - - private static void setValuesFromSADX() - { - int bytesRead = 0; + + theDisplay.setControllerDataSA2(buttons, joyX, joyY); + } + + private static void setValuesFromSADX() + { + int bytesRead = 0; byte[] buffer = new byte[20]; if (ReadProcessMemory((int)processHandle, 0x03B0E80C, buffer, 20, ref bytesRead) == false || bytesRead != 20) { - theDisplay.setControllerDataSADX(0, 0, 0); - gameID = -1; + theDisplay.setControllerDataSADX(0, 0, 0); + gameID = -1; return; } @@ -121,30 +132,30 @@ private static void setValuesFromSADX() buttons+=buffer[17]<<8; buttons+=buffer[18]<<16; buttons+=buffer[19]<<24; - - int joyX = 0; - joyX+=buffer[0]; - joyX+=buffer[1]<<8; - joyX+=buffer[1]<<16; + + int joyX = 0; + joyX+=buffer[0]; + joyX+=buffer[1]<<8; + joyX+=buffer[1]<<16; joyX+=buffer[1]<<24; - - int joyY = 0; - joyY+=buffer[2]; - joyY+=buffer[3]<<8; - joyY+=buffer[3]<<16; + + int joyY = 0; + joyY+=buffer[2]; + joyY+=buffer[3]<<8; + joyY+=buffer[3]<<16; joyY+=buffer[3]<<24; - - theDisplay.setControllerDataSADX(buttons, joyX, -joyY); - } - - private static void setValuesFromHeroes() - { - int bytesRead = 0; + + theDisplay.setControllerDataSADX(buttons, joyX, -joyY); + } + + private static void setValuesFromHeroes() + { + int bytesRead = 0; byte[] buffer = new byte[28]; if (ReadProcessMemory((int)processHandle, 0x00A23598, buffer, 28, ref bytesRead) == false || bytesRead != 28) { - theDisplay.setControllerDataHeroes(0, 0, 0, 0); - gameID = -1; + theDisplay.setControllerDataHeroes(0, 0, 0, 0); + gameID = -1; return; } @@ -153,108 +164,108 @@ private static void setValuesFromHeroes() buttons+=buffer[1]<<8; buttons+=buffer[2]<<16; buttons+=buffer[3]<<24; - - float joyX = System.BitConverter.ToSingle(buffer, 16); - float joyY = System.BitConverter.ToSingle(buffer, 20); - float cameraPan = System.BitConverter.ToSingle(buffer, 24); - - theDisplay.setControllerDataHeroes(buttons, joyX, joyY, cameraPan); - } - - private static void setValuesFromMania() - { - int bytesRead = 0; + + float joyX = System.BitConverter.ToSingle(buffer, 16); + float joyY = System.BitConverter.ToSingle(buffer, 20); + float cameraPan = System.BitConverter.ToSingle(buffer, 24); + + theDisplay.setControllerDataHeroes(buttons, joyX, joyY, cameraPan); + } + + private static void setValuesFromMania() + { + int bytesRead = 0; byte[] buffer = new byte[2]; if (ReadProcessMemory((int)processHandle, 0x0083251D, buffer, 2, ref bytesRead) == false || bytesRead != 2) { - theDisplay.setControllerDataMania(0, 0); - gameID = -1; + theDisplay.setControllerDataMania(0, 0); + gameID = -1; return; } int buttons = 0; buttons+=buffer[0]; - - int stick = 0; - stick+=buffer[1]; - - theDisplay.setControllerDataMania(buttons, stick); - } - - private static void attatchToGame() - { - theDisplay.Text = "Searching for game..."; - processHandle = IntPtr.Zero; - gameID = -1; - - Process process = null; - try - { - process = Process.GetProcessesByName("sonic2app")[0]; - gameID = 0; - } - catch - { - try - { - process = Process.GetProcessesByName("sonic")[0]; - gameID = 1; - } - catch - { - try - { - process = Process.GetProcessesByName("Sonic Adventure DX")[0]; - gameID = 1; - } - catch - { - try - { - process = Process.GetProcessesByName("Tsonic_win")[0]; - gameID = 2; - } - catch - { - try - { - process = Process.GetProcessesByName("SonicMania")[0]; - gameID = 3; - } - catch - { - gameID = -1; - } - } - } - } - } - - if (gameID != -1) - { - try - { - processHandle = OpenProcess(PROCESS_WM_READ, false, process.Id); - } - catch - { - gameID = -1; - } - } - - System.Threading.Thread.Sleep(500); - - switch (gameID) - { - case 0: theDisplay.Text = "SA2 Input"; break; - - case 1: theDisplay.Text = "SADX Input"; break; - - case 2: theDisplay.Text = "Heroes Input"; break; - - case 3: theDisplay.Text = "Mania Input"; break; - - default: break; - } - } -} + + int stick = 0; + stick+=buffer[1]; + + theDisplay.setControllerDataMania(buttons, stick); + } + + private static void attatchToGame() + { + theDisplay.Text = "Searching for game..."; + processHandle = IntPtr.Zero; + gameID = -1; + + Process process = null; + try + { + process = Process.GetProcessesByName("sonic2app")[0]; + gameID = 0; + } + catch + { + try + { + process = Process.GetProcessesByName("sonic")[0]; + gameID = 1; + } + catch + { + try + { + process = Process.GetProcessesByName("Sonic Adventure DX")[0]; + gameID = 1; + } + catch + { + try + { + process = Process.GetProcessesByName("Tsonic_win")[0]; + gameID = 2; + } + catch + { + try + { + process = Process.GetProcessesByName("SonicMania")[0]; + gameID = 3; + } + catch + { + gameID = -1; + } + } + } + } + } + + if (gameID != -1) + { + try + { + processHandle = OpenProcess(PROCESS_VM_READ, false, process.Id); + } + catch + { + gameID = -1; + } + } + + System.Threading.Thread.Sleep(500); + + switch (gameID) + { + case 0: theDisplay.Text = "SA2 Input"; break; + + case 1: theDisplay.Text = "SADX Input"; break; + + case 2: theDisplay.Text = "Heroes Input"; break; + + case 3: theDisplay.Text = "Mania Input"; break; + + default: break; + } + } +} \ No newline at end of file