using System; using System.Text; using System.Threading.Tasks; using GalaxyBudsClient.Message; using GalaxyBudsClient.Model.Constants; using GalaxyBudsClient.Platform; using GalaxyBudsClient.Scripting.Experiment; using GalaxyBudsClient.Scripting.Hooks; public class SKUDump : IMessageHook, IExperimentBase { public async void OnHooked() { if (BluetoothImpl.Instance.IsConnected) { await BluetoothImpl.Instance.SendRequestAsync(MsgIds.DEBUG_SKU); } else { BluetoothImpl.Instance.Connected += OnConnected; } } public void OnUnhooked() { BluetoothImpl.Instance.Connected -= OnConnected; } private async void OnConnected(object? sender, EventArgs e) { try { await Task.Delay(100); await BluetoothImpl.Instance.SendRequestAsync(MsgIds.DEBUG_SKU); } catch (Exception ex) { Finished?.Invoke(new ExperimentRuntimeResult(1, ex.Message)); } } public void OnMessageAvailable(ref SppMessage msg) { try { if (msg.Id == MsgIds.DEBUG_SKU) { Finished?.Invoke(new ExperimentRuntimeResult(0, Encoding.ASCII.GetString(msg.Payload))); } } catch (Exception ex) { Finished?.Invoke(new ExperimentRuntimeResult(2, ex.Message)); } } public void OnMessageSend(ref SppMessage msg) { } public event Action? Finished; }