Exemple #1
0
        public static void UpdatePlayerList()
        {
            // There's probably a better way to get all current active P2P connections,
            // but I couldn't find one. The SessionInfo pointers are not reliable as
            // players can spoof their Steam ID there.
            int cnt = SteamFriends.GetCoplayFriendCount();

            for (int i = 0; i < cnt; i++)
            {
                CSteamID id = SteamFriends.GetCoplayFriend(i);

                P2PSessionState_t session = new P2PSessionState_t();
                if (!SteamNetworking.GetP2PSessionState(id, out session) || (session.m_bConnectionActive == 0 && session.m_bConnecting == 0))
                {
                    if (activePlayers.ContainsKey(id))
                    {
                        ETWPingMonitor.Unregister(activePlayers[id].NetId);
                        activePlayers.Remove(id);
                    }
                    continue;
                }
                if (!activePlayers.ContainsKey(id))
                {
                    activePlayers[id] = new Player(id);
                }

                activePlayers[id].UpdateNetInfo(session);
            }
        }
Exemple #2
0
        private void UpdateNetInfo(P2PSessionState_t session)
        {
            bool endpointChanged = sessionState.m_nRemoteIP != session.m_nRemoteIP || sessionState.m_nRemotePort != session.m_nRemotePort;

            sessionState = session;

            if (endpointChanged)
            {
                // If IP/port changed for whatever reason
                ETWPingMonitor.Unregister(NetId);

                Region = "...";

                byte[] ipBytes = BitConverter.GetBytes(sessionState.m_nRemoteIP).Reverse().ToArray();
                NetId = (ulong)sessionState.m_nRemotePort << 32 | BitConverter.ToUInt32(ipBytes, 0);
                ETWPingMonitor.Register(NetId);

                if (session.m_bUsingRelay == 0)
                {
                    IpLocationAPI.GetLocationAsync(new IPAddress(ipBytes).ToString(), r => Region = r);
                }
                else
                {
                    Region = "[STEAM RELAY]";
                }
            }
        }
 private void MainWindow_Closed(object sender, EventArgs e)
 {
     Settings.Default.Save();
     overlay.Close();
     HotkeyManager.Disable();
     ETWPingMonitor.Stop();
 }
        static void Main(string[] args)
        {
            JObject settings = JObject.Parse(File.ReadAllText("settings.txt"));

            Console.CursorVisible = false;
            Console.Title         = "DS3 Connection Info V3.3";

            SteamNative.Initialize();
            mem = new MemoryManager();

            Console.WriteLine("Dark Souls III: Closed");
            do
            {
                try { mem.OpenProcess("DarkSoulsIII"); }
                catch { }
                Thread.Sleep(2000);
            } while (mem.ProcHandle == IntPtr.Zero);

            if (!SteamApi.Initialize(374320))
            {
                Console.WriteLine("ERROR: Could not initalize SteamAPI.");
                Console.Read();
                return;
            }

            ETWPingMonitor.Start();

            if ((bool)settings["overlay"])
            {
                Overlay.Enable(settings);
            }


            Console.Clear();
            while (!mem.HasExited)
            {
                Player.UpdatePlayerList();
                Player.UpdateInGameInfo(mem.Process);
                PrintConnInfo();

                Thread.Sleep(1000);
            }

            Overlay.Disable();
            ETWPingMonitor.Stop();
        }
        private void GameStartTimer_Tick(object sender, EventArgs e)
        {   // Wait for both process attach & main window existing
            if (DS3Interop.TryAttach() && DS3Interop.FindWindow())
            {
                DS3Interop.Process.EnableRaisingEvents = true;
                DS3Interop.Process.Exited += DarkSouls_HasExited;
                labelGameState.Content     = "DS3: RUNNING";
                labelGameState.Foreground  = Brushes.LawnGreen;

                File.WriteAllText("steam_appid.txt", "374320");
                if (!SteamAPI.Init())
                {
                    MessageBox.Show("Could not initialize Steam API", "Steam API Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                }

                if (!HotkeyManager.Enable())
                {
                    MessageBox.Show("Could not initialize keyboard hook for hotkeys", "WINAPI Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                if (!overlay.InstallMsgHook())
                {
                    MessageBox.Show("Could not overlay message hook", "WINAPI Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                overlay.UpdateVisibility();
                if (swBorderless.IsOn ^ DS3Interop.Borderless)
                {
                    DS3Interop.MakeBorderless(swBorderless.IsOn);
                }

                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.BorderlessHotkey, () => swBorderless.IsOn ^= true);
                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.OverlayHotkey, () => swOverlay.IsOn       ^= true);
                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.PingFilterHotkey, () => Settings.Default.UsePingFilter ^= true);
                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.REOHotkey, () => OnlineHotkey(11));
                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.RSDHotkey, () => OnlineHotkey(10));
                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.WSDHotkey, () => OnlineHotkey(4));
                HotkeyManager.AddHotkey(DS3Interop.WinHandle, () => Settings.Default.LeaveSessionHotkey, () => DS3Interop.LeaveSession());

                ETWPingMonitor.Start();
                updateTimer.Start();
                gameStartTimer.Stop();
            }
        }