Meep

phasmophobia anti modder room

Sep 21st, 2021 (edited)
123
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Validates whether the current room follows standard Phasmophobia protocol
  2. // If using PUN2.0, replace peer with PhotonNetwork.LocalPlayer
  3.  
  4. public static bool ValidateCurrentRoom(IMeepPeer peer)
  5. {
  6.     if (peer == null)
  7.         return false;
  8.  
  9.     var room = peer.Instance.CurrentRoom;
  10.  
  11.     // Room is null, return
  12.     if (room == null)
  13.         return false;
  14.  
  15.     // Max players is more than 4 (this can be spoofed)
  16.     if (room.MaxPlayers > 4)
  17.         return false;
  18.  
  19.     // PlayerCount cannot be spoofed
  20.     if (room.PlayerCount > 4)
  21.         return false;
  22.  
  23.     var masterID = room.MasterClientId;
  24.  
  25.     // Spoofing this is also possible
  26.     if (masterID <= 0)
  27.         return false;
  28.  
  29.     var lowestId = int.MaxValue;
  30.  
  31.     // We verify nobody has stolen MasterClient when we join
  32.     // If someone has Master and their ID is higher than someone elses, it's stolen
  33.     foreach (var player in room.Players)
  34.         if (lowestId > player.Key)
  35.             lowestId = player.Key;
  36.  
  37.     // Someone stole master in this room
  38.     if (lowestId != masterID)
  39.         return false;
  40.  
  41.     // CustomProperties is more than 0, this shouldn't happen in Phasmophobia
  42.     if (room.CustomProperties.Count > 0)
  43.         return false;
  44.  
  45.     // PublishUserId should always be true now
  46.     if (!room.PublishUserId)
  47.         return false;
  48.  
  49.     // This should always be false or OnJoinedRoom won't run
  50.     if (room.SuppressRoomEvents)
  51.         return false;
  52.  
  53.     // This should always be false or join/leave events won't be sent
  54.     if (room.SuppressPlayerInfo)
  55.         return false;
  56.  
  57.     // We joined a room, but the IsOpen property is false, this shouldn't happen
  58.     if (!room.IsOpen)
  59.         return false;
  60.  
  61.     var name = room.Name;
  62.  
  63.     // The room name should never be below 6 characters in length
  64.     // The code is always 6 digits long regardless of private or public
  65.     if (string.IsNullOrEmpty(name) || name.Length < 6)
  66.         return false;
  67.  
  68.     // Rooms that are visible have {name#code}
  69.     if (room.IsVisible)
  70.     {
  71.         // No # = malformed room
  72.         if (!name.Contains("#"))
  73.             return false;
  74.  
  75.         var split = name.Split('#');
  76.  
  77.         // There should always be at least 2 indexes
  78.         if (split.Length < 2)
  79.             return false;
  80.  
  81.         var code = split[split.Length - 1];
  82.  
  83.         return code.Length == 6 && int.TryParse(code, out var codePublic);
  84.     }
  85.  
  86.     // Rooms that are invisible have only {code}
  87.     else
  88.     {
  89.         return name.Length == 6 && int.TryParse(name, out var codePrivate);
  90.     }
  91. }
RAW Paste Data