using System.Linq;
using System.Text;
namespace NHSE.Injection;
///
/// Encodes commands for a to be sent as a array.
///
public static class SwitchCommand
{
private static readonly Encoding Encoder = Encoding.UTF8;
private static byte[] Encode(string command, bool addrn = true) => Encoder.GetBytes(addrn ? command + "\r\n" : command);
///
/// Removes the virtual controller from the bot. Allows physical controllers to control manually.
///
/// Encoded command bytes
public static byte[] DetachController() => Encode("detachController");
///
/// Presses and releases a for 50ms.
///
/// Button to click.
/// Press & Release timing is performed by the console automatically.
/// Encoded command bytes
public static byte[] Click(SwitchButton button) => Encode($"click {button}");
///
/// Presses and does NOT release a .
///
/// Button to hold.
/// Encoded command bytes
public static byte[] Hold(SwitchButton button) => Encode($"press {button}");
///
/// Releases the held .
///
/// Button to release.
/// Encoded command bytes
public static byte[] Release(SwitchButton button) => Encode($"release {button}");
///
/// Sets the specified to the desired and positions.
///
/// Encoded command bytes
public static byte[] SetStick(SwitchStick stick, int x, int y) => Encode($"setStick {stick} {x} {y}");
///
/// Resets the specified to (0,0)
///
/// Encoded command bytes
public static byte[] ResetStick(SwitchStick stick) => SetStick(stick, 0, 0);
///
/// Requests the Bot to send bytes from .
///
/// Address of the data
/// Amount of bytes
/// Encoded command bytes
public static byte[] Peek(uint offset, int count) => Encode($"peek 0x{offset:X8} {count}");
///
/// Sends the Bot to be written to .
///
/// Address of the data
/// Data to write
/// Encoded command bytes
public static byte[] Poke(uint offset, byte[] data) => Encode($"poke 0x{offset:X8} 0x{string.Concat(data.Select(z => $"{z:X2}"))}");
///
/// (Without return) Requests the Bot to send bytes from .
///
/// Address of the data
/// Amount of bytes
/// Encoded command bytes
public static byte[] PeekRaw(uint offset, int count) => Encode($"peek 0x{offset:X8} {count}", false);
///
/// (Without return) Sends the Bot to be written to .
///
/// Address of the data
/// Data to write
/// Encoded command bytes
public static byte[] PokeRaw(uint offset, byte[] data) => Encode($"poke 0x{offset:X8} 0x{string.Concat(data.Select(z => $"{z:X2}"))}", false);
}