Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using UsbHid;
- using UsbHid.USB.Classes.Messaging;
- namespace Powersaves {
- public partial class Form1 : Form {
- public UsbHidDevice Device;
- private List<String> responses;
- private StringBuilder strBuild;
- public Form1() {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e) {
- Device = new UsbHidDevice(0x1C1A, 0x03D5);
- Device.OnConnected += DeviceOnConnected;
- Device.OnDisConnected += DeviceOnDisConnected;
- Device.DataReceived += DeviceDataReceived;
- Device.Connect();
- }
- private void connectBut_Click(object sender, EventArgs e) {
- responses = new List<String>();
- strBuild = new StringBuilder();
- new System.Threading.Thread(delegate() {
- if (!Device.IsDeviceConnected) return;
- strBuild.Append("ROM ID:\n");
- Device.SendMessage(new CommandMessage(0x13, new byte[] { 0x08, 0x00, 0x00, 0x00, 0x71, 0xC9, 0x3F, 0xE9, 0xBB, 0x0A, 0x3B, 0x18 }));
- System.Threading.Thread.Sleep(20);
- Device.SendMessage(new CommandMessage(0x13, new byte[] { 0x08, 0x00, 0x04, 0x00, 0x90 }));
- System.Threading.Thread.Sleep(20);
- foreach (String val in responses) {
- strBuild.Append(val + "\n");
- }
- strBuild.Append("NCCH Header:\n");
- Device.SendMessage(new CommandMessage(0x13, new byte[] { 0x08, 0x00, 0x00, 0x00, 0x3E }));
- System.Threading.Thread.Sleep(20);
- Device.SendMessage(new CommandMessage(0x14, new byte[] { 0x10, 0x00, 0x00, 0x02, 0x82 }));
- System.Threading.Thread.Sleep(20);
- foreach (String val in responses) {
- strBuild.Append(val + "\n");
- }
- strBuild.Append("-----------------------------");
- ThreadSafe(() => consoleBox.Text += strBuild.ToString());
- }).Start();
- }
- private static string ByteArrayToString(byte[] input) {
- return string.Join(" ", input.Select(b => Convert.ToString(b, 16).ToUpper()));
- }
- private void DeviceDataReceived(byte[] data) {
- ThreadSafe(() => consoleBox.Text += "trying!!");
- try {
- responses.Add(ByteArrayToString(data));
- } catch (NullReferenceException e) {
- Console.Write(e.StackTrace);
- }
- }
- private void ThreadSafe(MethodInvoker method) {
- if (InvokeRequired)
- Invoke(method);
- else
- method();
- }
- private void DeviceOnDisConnected() {
- ThreadSafe(() => connectLabel.Text = "Disconnected.");
- }
- private void DeviceOnConnected() {
- ThreadSafe(() => connectLabel.Text = "Connected!");
- }
- private void consoleBox_TextChanged(object sender, EventArgs e) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement