internal async Task PlayAsync(int pid, CancellationToken cts) { PipeMessage noteOff = new PipeMessage(pid, PMCommand.PlayNote) { Parameter = 0 }; foreach (Note n in Sheet) { PersistentNamedPipeServer.SendPipeMessage(new PipeMessage(pid, PMCommand.PlayNote) { Parameter = n.Id }); await Task.Delay((int)n.Length); PersistentNamedPipeServer.SendPipeMessage(noteOff); TimeSpan untilNextNote = TimeSpan.FromMilliseconds((int)n.Wait - (int)n.Length); if (untilNextNote.TotalMilliseconds > 0) { await Task.Delay(untilNextNote); } if (cts.IsCancellationRequested) { break; } } }
internal async Task PlayMML(ImplementedPlayer p, CancellationToken cts) { p.Unmute(); p.Play(); if (!PersistentNamedPipeServer.Instance.IsConnected) { await TryInject(); } PipeMessage noteOff = new PipeMessage(Process.Id, PMCommand.PlayNote) { Parameter = 0 }; foreach (var track in p.Tracks) { new Thread(() => { TimeSpan ts = new TimeSpan(0); foreach (TextPlayer.Note note in track.notes) { TimeSpan w = note.TimeSpan - ts; if (w.TotalMilliseconds > 0) { Thread.Sleep(w); } if (cts.IsCancellationRequested) { return; } PersistentNamedPipeServer.SendPipeMessage(new PipeMessage(Process.Id, PMCommand.PlayNote) { Parameter = note.GetStep() }); Thread.Sleep(note.Length); PersistentNamedPipeServer.SendPipeMessage(noteOff); ts = note.TimeSpan + note.Length; } }) { Priority = ThreadPriority.Highest, IsBackground = true }.Start(); } }
internal async Task Play(int pid, CancellationToken cts) { PipeMessage noteOff = new PipeMessage(pid, PMCommand.PlayNote, 0); foreach (Note i in this.Sheet) { PersistentNamedPipeServer.SendPipeMessage(new PipeMessage(pid, PMCommand.PlayNote, i.Id)); await Task.Delay((int)i.Length).ConfigureAwait(false); PersistentNamedPipeServer.SendPipeMessage(noteOff); TimeSpan untilNextNote = TimeSpan.FromMilliseconds((double)(i.Wait - i.Length)); if (untilNextNote.TotalMilliseconds > 0.0) { await Task.Delay(untilNextNote).ConfigureAwait(false); } if (cts.IsCancellationRequested) { break; } i = null; } List <Note> .Enumerator enumerator = default(List <Note> .Enumerator); }
private async Task WriteChatMessage(byte[] msg) { await TryInject(); if (msg.Last() != 0x00) { msg = msg.Concat(new byte[] { 0x00 }).ToArray(); } ulong tail = Is64Bit ? GetUInt64(chatLogTailAddress) : GetUInt32(chatLogTailAddress); NativeMethods.WriteProcessMemory(Process.Handle, (IntPtr)tail, msg, new IntPtr(msg.Length), out uint written); if (Is64Bit) { NativeMethods.WriteProcessMemory(Process.Handle, chatLogTailAddress, BitConverter.GetBytes(tail + Convert.ToUInt64(msg.Length)), new IntPtr(sizeof(ulong)), out written); } else { NativeMethods.WriteProcessMemory(Process.Handle, chatLogTailAddress, BitConverter.GetBytes(tail + Convert.ToUInt32(msg.Length)), new IntPtr(sizeof(uint)), out written); } var SlashInstanceCommand = new PipeMessage(Process.Id, PMCommand.SlashInstance); PersistentNamedPipeServer.SendPipeMessage(SlashInstanceCommand); }