// Retrieves a current state of all player slots. public void GetUpdate(IntPtr ptrHandle, IntPtr ptrBaseAddress) { // Create an Update_t in foreign process. Update_t update = new Update_t(); IntPtr ptrUpdate = ippc.WriteStruct(ptrHandle, update); // Pass pointer to Update_t to GetUpdate C++. IntPtr ptrGetUpdate = ippc.GetRemoteProcAddress(ptrHandle, ptrBaseAddress, "GetUpdate"); if (ptrGetUpdate == IntPtr.Zero) { Console.WriteLine("Failed to get update. GetUpdate exported function not found!"); return; } IntPtr ptrThread = ippc.Run(ptrHandle, ptrGetUpdate, ptrUpdate); uint uiResult = ippc.GetThreadReturnValue(ptrThread); // Read Update_t from foreign process. update = (Update_t)ippc.ReadStruct(ptrHandle, ptrUpdate, update); PlayerUpdate_t ply = new PlayerUpdate_t(); object local_struct = ippc.ReadStruct(ptrHandle, update.ptrLocalPlayer, ply); uint[] uiPlayers = ippc.ReadUIntArray(ptrHandle, update.ptrSlots, PLAYER_NUM); PlayerUpdate_t[] players = new PlayerUpdate_t[PLAYER_NUM]; for (int i = 0; i < PLAYER_NUM; i++) { players[i] = (PlayerUpdate_t)ippc.ReadStruct(ptrHandle, new IntPtr(uiPlayers[i]), ply); } CPlayerUpdate result = new CPlayerUpdate(update.iLocalPlayerNum, players, (PlayerUpdate_t)local_struct); UpdateFound(result); // Process & Destory memory. ippc.FreeMemory(ptrHandle, update.ptrSlots); ippc.FreeMemory(ptrHandle, ptrUpdate); }
private void Control_UpdateFound(CPlayerUpdate update) { if (this.InvokeRequired) { Control_UpdateFound_Delegate call = new Control_UpdateFound_Delegate(Control_UpdateFound); this.Invoke(call, new object[] { update }); } else { lsPlayers.Items.Clear(); bool added = false; for (int i = 0; i < update.GetPlayerList().Length; i++) { PlayerUpdate_t ply = (PlayerUpdate_t)update.GetPlayerList()[i]; ListViewItem it = new ListViewItem(); it.Tag = ply; it.Text = ply.iPlayerNum.ToString(); it.SubItems.Add(ply.fGold.ToString()); it.SubItems.Add(update.GetTotalResources(ply.iPlayerNum).ToString()); it.SubItems.Add(update.GetTotalFood(ply.iPlayerNum).ToString()); it.SubItems.Add(update.GetTotalWeapons(ply.iPlayerNum).ToString()); if (ply.iPlayerNum == update.iLocalPlayerNum) { if (added) { continue; } added = true; it.Text = it.Text + " (You)"; } lsPlayers.Items.Add(it); } } }