示例#1
0
    public bool InitializeDolphinInfo()
    {
        // Get the Dolphin process
        Process[] processList = Process.GetProcessesByName("dolphin");
        // TODO: Add better handling for when Dolphin isn't running
        if (processList.Length == 0)
        {
            return(false);
        }
        Process process = processList[0];

        ProcessPointer = WindowsSystemUtils.OpenProcess(0x0400 | 0x0008 | 0x0020 | 0x0010, false, process.Id);

        WindowsSystemUtils.SYSTEM_INFO sys_info = new WindowsSystemUtils.SYSTEM_INFO();
        WindowsSystemUtils.GetSystemInfo(out sys_info);
        Int64 maxAddress     = (Int64)sys_info.maximumApplicationAddress;
        long  currentAddress = 0;

        do
        {
            WindowsSystemUtils.MEMORY_BASIC_INFORMATION64 memoryInfo;
            int result = WindowsSystemUtils.VirtualQueryEx(ProcessPointer, (IntPtr)currentAddress, out memoryInfo, (uint)Marshal.SizeOf(typeof(WindowsSystemUtils.MEMORY_BASIC_INFORMATION64)));

            // We are looking for MEM_MAPPED (0x40000) memory of size 0x2000000
            if ((int)memoryInfo.RegionSize == 0x2000000 && memoryInfo.Type == 0x40000)
            {
                // Confirm that the current page has valid working set information, otherwise ignore it
                WindowsSystemUtils._PSAPI_WORKING_SET_EX_INFORMATION[] WsInfo = new WindowsSystemUtils._PSAPI_WORKING_SET_EX_INFORMATION [1];
                WsInfo[0].VirtualAddress = (IntPtr)memoryInfo.BaseAddress;
                if (WindowsSystemUtils.QueryWorkingSetEx(ProcessPointer, WsInfo, Marshal.SizeOf <WindowsSystemUtils._PSAPI_WORKING_SET_EX_INFORMATION>()))
                {
                    Console.WriteLine(WsInfo[0].VirtualAttributes.Flags.ToString("X8"));
                    // Checks the Valid flag on the PSAPI response
                    if ((WsInfo[0].VirtualAttributes.Flags & 0b1) == 1)
                    {
                        if (MemoryStartAddress == IntPtr.Zero)
                        {
                            // TODO: Add handling for multiple pages
                            MemoryStartAddress = WsInfo[0].VirtualAddress;
                        }
                    }
                }
            }

            // Check to see if we've searched the entire process memory region
            if (currentAddress == (long)memoryInfo.BaseAddress + (long)memoryInfo.RegionSize)
            {
                break;
            }

            // Jump to the next page
            currentAddress = (long)memoryInfo.BaseAddress + (long)memoryInfo.RegionSize;
        } while (currentAddress <= (long)maxAddress);

        return(true);
    }
        static unsafe void Main(string[] args)
        {
            DolphinProcessInfo dolphin_Process = new DolphinProcessInfo();

            // int[] attributes = { 19, 19, 1, 8, 5, 16, 17, 6, 6, 2 };
            // Player Lamar = new Player("Thomas", "Bullock", 8, "QB", 9, 212, attributes);
            if (dolphin_Process.InitializeDolphinInfo())
            {
                Console.WriteLine("Process base address: " + dolphin_Process.MemoryStartAddress.ToString("X8"));
                int           index   = 0;
                List <Player> players = new List <Player>();
                using (var reader = new StreamReader(@"C:\Users\Victor Geary\Desktop\Street NFC - 2020\Street Rosters_vSEA.csv"))
                {
                    while (!reader.EndOfStream)
                    {
                        var line   = reader.ReadLine();
                        var values = line.Split(',');

                        Console.WriteLine(string.Join(",", values));

                        string[] attributeStrings = new string[10];
                        Array.Copy(values, 6, attributeStrings, 0, attributeStrings.Length);
                        int[] attributes = Array.ConvertAll(attributeStrings, s => int.Parse(s));

                        players.Add(new Player(index, values[0], values[1], Int32.Parse(values[2]), values[3], Int32.Parse(values[4]), Int32.Parse(values[5]), attributes));
                        index++;
                    }
                }

                IntPtr ptr = new IntPtr(dolphin_Process.MemoryStartAddress.ToInt64() + 2152221376);
                byte[] consoleAddressBuffer = new byte[(sizeof(byte) * 88)];

                // Write the player count
                IntPtr playerCountAddress = (IntPtr)(dolphin_Process.MemoryStartAddress.ToInt64() + CommonUtils.DolphinAddressToOffset(0x80484691));
                byte[] playerCount        = { (byte)players.Count };
                WindowsSystemUtils.WriteProcessMemory(dolphin_Process.ProcessPointer, playerCountAddress, playerCount, sizeof(byte), out _);


                // Loop over the players
                IntPtr playerAddress = (IntPtr)(dolphin_Process.MemoryStartAddress.ToInt64() + CommonUtils.DolphinAddressToOffset(0x80484ac0));
                for (int i = 0; i < players.Count; i++)
                {
                    WindowsSystemUtils.WriteProcessMemory(dolphin_Process.ProcessPointer, playerAddress, players[i].GetByteStream(), (sizeof(byte) * 88), out _);
                    playerAddress += 88;
                }
            }
            else
            {
                Console.WriteLine("Unable to find Dolphin's base address...");
            }
        }