Пример #1
0
        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;
                }
            }
        }
Пример #2
0
        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();
            }
        }
Пример #3
0
 internal static bool SendPipeMessage(PipeMessage pipeMessage)
 {
     if (Instance.IsConnected)
     {
         int size = Marshal.SizeOf(pipeMessage);
         // Both managed and unmanaged buffers required.
         byte[] bytes = new byte[size];
         IntPtr ptr   = Marshal.AllocHGlobal(size);
         // Copy object byte-to-byte to unmanaged memory.
         Marshal.StructureToPtr(pipeMessage, ptr, false);
         // Copy data from unmanaged memory to managed buffer.
         Marshal.Copy(ptr, bytes, 0, size);
         // Release unmanaged memory.
         Marshal.FreeHGlobal(ptr);
         //Debug.WriteLine("Sending: " + BitConverter.ToString(bytes));
         Instance.Write(bytes, 0, bytes.Length);
         Instance.WaitForPipeDrain();
         return(true);
     }
     return(false);
 }
        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);
        }
Пример #5
0
        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);
        }