コード例 #1
0
        public void RunThread()
        {
            m_currentState = MaiMaiState.Waiting;
            while (true)
            {
                Thread.Sleep(500);

                Process[] allMais = Process.GetProcessesByName("maimai_dump_");

                if (allMais.Length > 0 && allMais[0] != null)
                {
                    m_currentState = MaiMaiState.Connecting;
                    Thread.Sleep(10000);
                    Process process       = allMais[0];
                    IntPtr  processHandle = process.Handle;// OpenProcess(PROCESS_WM_READ, false, process.Id);

                    int    bytesRead = 0;
                    byte[] buffer    = new byte[4]; // ptr 4 bytes

                    // 0x0046A3B8 is the address where I found the string, replace it with what you found
                    Int32 baseAddress = process.MainModule.BaseAddress.ToInt32();
                    // 0x8DF9C0 is Reaver's magic address
                    ReadProcessMemory((int)processHandle, 0x8DF9C0, buffer, buffer.Length, ref bytesRead);

                    // get the pointer
                    int val = BitConverter.ToInt32(buffer, 0);
                    Console.WriteLine(string.Format("{0:X}", val));

                    m_currentState = MaiMaiState.Setup;

                    // get the window rect for MaiMai
                    RECT rect = new RECT();

                    try
                    {
                        GetWindowRect(process.MainWindowHandle, ref rect);
                        Console.WriteLine(rect.Bottom + " " + rect.Left + " " + rect.Top + " " + rect.Right);
                    }
                    catch
                    {
                        m_currentState = MaiMaiState.Error;
                    }

                    byte[] structBuf = new byte[8];

                    try
                    {
                        ReadProcessMemory((int)processHandle, val + 52, structBuf, structBuf.Length, ref bytesRead);

                        for (int i = 0; i < 8; ++i)
                        {
                            Console.Write(string.Format("{0:X}", structBuf[i]));
                        }
                        Console.WriteLine();
                    }
                    catch
                    {
                        m_currentState = MaiMaiState.Error;
                    }


                    byte[] toWrite = new byte[4];
                    while (m_currentState != MaiMaiState.Error)
                    {
                        m_currentState = MaiMaiState.Running;
                        RawInput_dll.RawTouch.TouchInfo touchCopy = m_touchInfo;
                        int j = 0;
                        for (int i = 0; i < m_touchInfo.GetNumTouches(); ++i)
                        {
                            GetWindowRect(process.MainWindowHandle, ref rect);
                            if (rect.Bottom == rect.Top)
                            {
                                rect.Bottom = Screen.PrimaryScreen.Bounds.Height;
                                rect.Top    = 0;
                                rect.Left   = 0;
                                rect.Right  = Screen.PrimaryScreen.Bounds.Width;
                            }
                            RawInput_dll.RawTouch.TouchInfo.SingleTouch st = m_touchInfo.GetTouch(i);
                            // x and y flipped 'coz portrait
                            int   xScreen = (int)(((float)st.Y() / (float)4096) * Screen.PrimaryScreen.Bounds.Width);
                            int   yScreen = Screen.PrimaryScreen.Bounds.Height - ((int)(((float)st.X() / (float)4096) * Screen.PrimaryScreen.Bounds.Height));
                            float xS      = (float)(xScreen - rect.Left) / (float)(rect.Right - rect.Left);
                            float yS      = (float)(rect.Bottom - yScreen) / (float)(rect.Right - rect.Left);

                            // player 1
                            j = j | GetTouchedAreas(xS - 0.25f, yS - 0.25f);
                            // player 2 - not tested... might use a 2nd screen?
                            //j = GetTouchedAreas(xS - 0.75f, yS - 0.25f);
                            //Console.WriteLine(j);
                            //toWrite = BitConverter.GetBytes(j);
                            //WriteProcessMemory((int)processHandle, val + 56, toWrite, structBuf.Length, ref bytesRead);
                        }

                        toWrite = BitConverter.GetBytes(j);
                        if (!process.HasExited)
                        {
                            try
                            {
                                WriteProcessMemory((int)processHandle, val + 52, toWrite, structBuf.Length, ref bytesRead);
                            }
                            catch
                            {
                                m_currentState = MaiMaiState.Error;
                                break;
                            }
                        }
                        else
                        {
                            m_currentState = MaiMaiState.Error;
                            break;
                        }

                        Thread.Sleep(16);
                    }
                }
                m_currentState = MaiMaiState.Error;
                Thread.Sleep(2000);
            }
        }
コード例 #2
0
 public void SetTouchInfo(RawInput_dll.RawTouch.TouchInfo ti)
 {
     m_touchInfo = ti;
 }