public static void TouchscreenRelease() { if (_luma) { byte[] inputredirection = new byte[] { 0xFF, 0x0F, 0x00, 0x00, /**/ 0x00, 0x00, 0x00, 0x02, /**/ 0x00, 0x08, 0x80, 0x00, 0x81, 0x00, 0x80, 0x80, //CStick 0x00, 0x00, 0x00, 0x00 //Special }; NetworkLuma.Write(inputredirection); } else { if (Network.tcpClientStream != null && Network.tcpClientStream.CanWrite) { byte[] inputredirection = new byte[] { 0xFF, 0x0F, 0x00, 0x00, /**/ 0x00, 0x00, 0x00, 0x02, /**/ 0x00, 0x08, 0x80, 0x00 }; //bValue.CopyTo(inputredirection, 4); NTRPacket ntrIR = NTRPacket.NewWriteMemory(1000, 16, 1105696, 12, 12); Network.tcpClientStream.Write(ntrIR.GetBytes(), 0, 84); Network.tcpClientStream.Write(inputredirection, 0, inputredirection.Length); oldtouch = 0x00000002; } } }
public static void TouchscreenClick(int X, int Y) { X = (int)Math.Round(((double)X / 319) * 4095); Y = (int)Math.Round(((double)Y / 239) * 4095); uint touch = (uint)(X | (Y << 12) | (0x01 << 24)); //Don't compare to oldtouch as you might be clicking the same pixel again. byte[] bValue = BitConverter.GetBytes(touch); if (_luma) { byte[] inputredirection = new byte[] { 0xFF, 0x0F, 0x00, 0x00, /**/ 0x00, 0x00, 0x00, 0x02, /**/ 0x00, 0x08, 0x80, 0x00, 0x81, 0x00, 0x80, 0x80, //CStick 0x00, 0x00, 0x00, 0x00 //Special }; bValue.CopyTo(inputredirection, 4); NetworkLuma.Write(inputredirection); } else { if (Network.tcpClientStream != null && Network.tcpClientStream.CanWrite) { byte[] inputredirection = new byte[] { 0xFF, 0x0F, 0x00, 0x00, /**/ 0x00, 0x00, 0x00, 0x02, /**/ 0x00, 0x08, 0x80, 0x00 }; bValue.CopyTo(inputredirection, 4); NTRPacket ntrIR = NTRPacket.NewWriteMemory(1000, 16, 1105696, 12, 12); Network.tcpClientStream.Write(ntrIR.GetBytes(), 0, 84); Network.tcpClientStream.Write(inputredirection, 0, inputredirection.Length); } } oldtouch = touch; }
private void BtnPatchNFCSM_Click(object sender, EventArgs e) { Network.DoCONNandHB(); //Sun/Moon //int addr1 = 0x3DFFD0; //v1.0 int addr2 = 0x3E14C0; //v1.1, seems to work for v1.2 if (Network.dictionaryProcess.ContainsKey("niji_loc")) { int pid = Network.dictionaryProcess["niji_loc"];// 0x2b; Console.WriteLine(pid); uint data = 0xE3A01000; byte[] bdata = BitConverter.GetBytes(data); //NTRPacket ntr1 = NTRPacket.NewWriteMemory(1000, pid, addr1, bdata.Length, bdata.Length); NTRPacket ntr2 = NTRPacket.NewWriteMemory(1000, pid, addr2, bdata.Length, bdata.Length); //tcpClientStream.Write(ntr1.GetBytes(), 0, 84); //tcpClientStream.Write(bdata, 0, bdata.Length); Network.tcpClientStream.Write(ntr2.GetBytes(), 0, 84); Network.tcpClientStream.Write(bdata, 0, bdata.Length); btnPatchNFCSM.Text = "SM Patched"; } }
public static void Start(string ip, int priority, int priorityScreen, int quality, int qos) { if (tcpClientStream != null) { tcpClientStream.Close(); udpClient.Close(); } TcpClient tcpClient = new TcpClient(); if (tcpClient.ConnectAsync(ip, 8000).Wait(1000)) { tcpClientStream = tcpClient.GetStream(); udpClient = new UdpClient(); udpClient.DontFragment = true; udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); udpClient.Client.Bind(new IPEndPoint(IPAddress.Any, 8001)); udpEP = new IPEndPoint(IPAddress.Any, 8001); NTRPacket ntrRP = NTRPacket.NewRemotePlay(1000, (byte)priority, (byte)priorityScreen, quality, qos); tcpClientStream.Write(ntrRP.GetBytes(), 0, 84); DoCONNandHB(); Thread threadNetwork = new Thread(() => { while (true) { DoThing(); } }); threadNetwork.Start(); } }
private void BtnPatchNFCOther_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Break Input Redirection and reconnecting?", "NTR-VP NFC Patch", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); if (dialogResult == DialogResult.Yes) { int addr1 = 0x00105B00; int pid = 0x1a; byte[] buffer = new byte[] { 0x70, 0x47 }; NTRPacket ntr1 = NTRPacket.NewWriteMemory(1000, pid, addr1, buffer.Length, buffer.Length); Network.tcpClientStream.Write(ntr1.GetBytes(), 0, 84); Network.tcpClientStream.Write(buffer, 0, buffer.Length); } }
private static void CheckState() { if (controller != null && Network.tcpClientStream != null && Network.tcpClientStream.CanWrite) { byte b0 = (byte)( ((controller.ButtonDownPressed ? 0x0 : 0x1) << 7) //Down + ((controller.ButtonUpPressed ? 0x0 : 0x1) << 6) //Up + ((controller.ButtonLeftPressed ? 0x0 : 0x1) << 5) //Left + ((controller.ButtonRightPressed ? 0x0 : 0x1) << 4) //Right + ((controller.ButtonStartPressed ? 0x0 : 0x1) << 3) //Start + ((controller.ButtonBackPressed ? 0x0 : 0x1) << 2) //Select + ((controller.ButtonAPressed ? 0x0 : 0x1) << 1) //B + ((controller.ButtonBPressed ? 0x0 : 0x1)) //A ); byte b1 = (byte)( ((controller.ButtonXPressed ? 0x0 : 0x1) << 3) //Y + ((controller.ButtonYPressed ? 0x0 : 0x1) << 2) //X + ((controller.ButtonShoulderLeftPressed ? 0x0 : 0x1) << 1) //L + ((controller.ButtonShoulderRightPressed ? 0x0 : 0x1)) //R ); uint buttons = (uint)((b0 << 8) + b1); uint leftX = (uint)(controller.ThumbLeftX * 40d); uint leftY = (uint)((100 - controller.ThumbLeftY) * 40d); if (leftX > 0x600 && leftX < 0xA00) { leftX = 0x7FF; } if (leftY > 0x600 && leftY < 0xA00) { leftY = 0x7FF; } uint circle = ((0xFFF - leftY) << 12) + leftX; byte[] bCircle = BitConverter.GetBytes(circle); bCircle[3] = 0x01; uint rightX = (uint)(controller.ThumbRightX * 2d); uint rightY = (uint)((controller.ThumbRightY * 2d)); //Needs to be flipped //0xFF - if (rightX > 0x60 && rightX < 0xA0) { rightX = 0x7F; } if (rightY > 0x60 && rightY < 0xA0) { rightY = 0x7F; } // The C-Stick needs to be rotated 45 degrees... // https://stackoverflow.com/questions/2259476/rotating-a-point-about-another-point-2d double pX = rightX - 127; // translate point back to origin: double pY = rightY - 127; // (rotate point) byte rotatedCX = (byte)((pX * c - pY * s) + 127); // translate point back: byte rotatedCY = (byte)((pX * s + pY * c) + 127); uint cstick = (uint)(rotatedCX << 8) + (rotatedCY); //Left currently doesn't work at all byte z = (byte)(((controller.TriggerRightPressed ? 0x0 : 0x1) << 2) //ZR + ((controller.TriggerLeftPressed ? 0x0 : 0x1) << 1)); //ZL uint touch = 0x00000002; if (oldbuttons != buttons || /*oldtouch != touch ||*/ oldcircle != circle || oldz != z || oldcstick != cstick) { //Don't compare touch, it's not managed by this loop if (_luma) { byte[] inputredirection = new byte[] { b0, b1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x08, 0x80, 0x00, 0x81, 0x00, 0x80, 0x80, //CStick 0x00, 0x00, 0x00, 0x00 //Special }; bCircle.CopyTo(inputredirection, 8); inputredirection[13] = z; inputredirection[14] = (byte)rotatedCX; inputredirection[15] = (byte)rotatedCY; NetworkLuma.Write(inputredirection); } else { //Console.WriteLine(b0.ToString("X2") + " " + b1.ToString("X2")); byte[] inputredirection = new byte[] { b0, b1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x08, 0x80, 0x00 }; bCircle.CopyTo(inputredirection, 8); NTRPacket ntrIR = NTRPacket.NewWriteMemory(1000, 16, 1105696, 12, 12); Network.tcpClientStream.Write(ntrIR.GetBytes(), 0, 84); Network.tcpClientStream.Write(inputredirection, 0, inputredirection.Length); } oldbuttons = buttons; oldtouch = touch; oldcircle = circle; oldcstick = cstick; oldz = z; } else { Console.WriteLine("."); } //Console.WriteLine(leftX.ToString("X") + " " + leftY.ToString("X")); Thread.Sleep(1); } }
public static void DoCONNandHB() { NTRPacket ntrCON = NTRPacket.NewConnect(2000); NTRPacket ntrHB = NTRPacket.NewHeartbeat(3000); tcpClientStream.Write(ntrCON.GetBytes(), 0, 84); tcpClientStream.Write(ntrHB.GetBytes(), 0, 84); byte[] buffer = new byte[84]; tcpClientStream.Read(buffer, 0, 84); NTRPacket ntrRec = new NTRPacket(buffer); string test = ""; byte[] buffer2 = new byte[ntrRec.DataLen]; tcpClientStream.Read(buffer2, 0, ntrRec.DataLen); for (int i = buffer2.Length - 1; i >= 0; i--) { if (buffer2[i] != 0x00) { test = test + Encoding.ASCII.GetString(buffer2, 0, i + 1); break; } } if (test.Length < ntrRec.DataLen) { byte[] buffer3 = new byte[ntrRec.DataLen]; tcpClientStream.Read(buffer3, 0, ntrRec.DataLen); for (int i = buffer3.Length - 1; i >= 0; i--) { if (buffer3[i] != 0x00) { test = test + Encoding.ASCII.GetString(buffer3, 0, i); break; } } } dictionaryProcess = new Dictionary <string, int>(); string[] lines = test.Split('\n'); //pid: 0x00000030, pname: niji_loc, tid: 0004000000164800, kpobj: fff7bdb0 foreach (string line in lines) { if (line.StartsWith("pid: ")) { int pos_pid = line.IndexOf("pid: "); //5 int pos_pname = line.IndexOf("pname: "); //7 int pos_tid = line.IndexOf(", tid: "); //7 //int pos_kpobj = line.IndexOf("kpobj: "); //7 string s_pid = line.Substring(pos_pid + 5, 10); int pid = (int)new System.ComponentModel.Int32Converter().ConvertFromString(s_pid); string pname = line.Substring(pos_pname + 7, pos_tid - 7 - pos_pname).Trim(); //string tid = line.Substring(pos_tid + 7, 16); dictionaryProcess.Add(pname, pid); } } }