示例#1
0
        public static bool OnPortalEnter(PortalInternal __instance)
        {
            if (!AskToPortalSettings.enabled)
            {
                return(true);
            }
            if (!hasTriggered)
            {
                Photon.Pun.PhotonView photonView = __instance.gameObject.GetComponent <Photon.Pun.PhotonView>();
                APIUser dropper;
                if (photonView == null)
                {
                    dropper = new APIUser(displayName: "Not Player Dropped", id: "");
                }
                else
                {
                    dropper = cachedDroppers[__instance.GetInstanceID()].field_Private_APIUser_0; // Get cached user because the photon object before gets the owner and can be spoofed
                }

                if (blacklistedUserIds.Contains(dropper.id))
                {
                    return(false);
                }

                string   roomId   = __instance.field_Private_String_1;
                string   worldId  = __instance.field_Private_ApiWorld_0.id;
                int      roomPop  = __instance.field_Private_Int32_0;
                RoomInfo roomInfo = new RoomInfo();
                if (roomId == null)
                {
                    if (dropper.id != "")
                    {
                        roomInfo.isPortalDropper = true;                   //If there is a dropper but the portal has no room id
                    }
                    roomInfo.instanceType = "Unknown";
                }
                else
                {
                    roomInfo = ParseRoomId(roomId);
                }

                //If portal dropper is not owner of private instance but still dropped the portal or world id is the public ban world or if the population is in the negatives or is above 80
                if ((roomInfo.ownerId != "" && roomInfo.ownerId != dropper.id && !roomInfo.instanceType.Contains("Friend")) || worldId == "wrld_5b89c79e-c340-4510-be1b-476e9fcdedcc" || roomPop < 0 || roomPop > 80)
                {
                    roomInfo.isPortalDropper = true;
                }

                if (roomInfo.isPortalDropper && !(AskToPortalSettings.autoAcceptSelf && dropper.IsSelf))
                {
                    popupV2.Invoke(VRCUiPopupManager.prop_VRCUiPopupManager_0, new object[7] {
                        "Portal Dropper Detected!!!",
                        $"This portal was likely dropped by someone malicious! Only go into this portal if you trust {dropper.displayName}. Pressing \"Leave and Blacklist\" will blacklist {dropper.displayName}'s portals until the game restarts",
                        "Enter", (Il2CppSystem.Action) new Action(() =>
                        {
                            closePopup.Invoke(VRCUiPopupManager.prop_VRCUiPopupManager_0, null);

                            if (__instance == null)
                            {
                                object currentPortalInfo = Activator.CreateInstance(portalInfo);
                                currentPortalInfo.GetType().GetProperty($"field_Public_{portalInfoEnum.Name}_0").SetValue(currentPortalInfo, portalInfoEnum.GetEnumValues().GetValue(3)); //I hate reflection
                                typeof(Il2CppSystem.Collections.Generic.Dictionary <string, string>).GetMethod("Add").Invoke(currentPortalInfo.GetType().GetProperty("field_Public_Dictionary_2_String_String_0").GetValue(currentPortalInfo), new object[2] {
                                    "transitionPortalType", dropper.id == "" ? "Static" : "Dynamic"
                                });
                                typeof(Il2CppSystem.Collections.Generic.Dictionary <string, string>).GetMethod("Add").Invoke(currentPortalInfo.GetType().GetProperty("field_Public_Dictionary_2_String_String_0").GetValue(currentPortalInfo), new object[2] {
                                    "transitionPortalOwner", dropper.id
                                });
                                enterWorld.Invoke(VRCFlowManager.prop_VRCFlowManager_0, new object[5] {
                                    worldId, roomId, currentPortalInfo, (Il2CppSystem.Action <string>) new Action <string>((str) => popupV2Small.Invoke(VRCUiPopupManager.prop_VRCUiPopupManager_0, new object[5] {
                                        "Alert", "Cannot Join World", "Close", (Il2CppSystem.Action) new Action(() => closePopup.Invoke(VRCUiPopupManager.prop_VRCUiPopupManager_0, null)), null
                                    })), false
                                });                                                                                                                                                                                                                                                                                                                                                                                                                           //Just kill me
                            }
                            else
                            {
                                hasTriggered = true;
                                try
                                {
                                    enterPortal.Invoke(__instance, null);
                                }
                                catch {}
                            }
                        }), "Leave and Blacklist", (Il2CppSystem.Action) new Action(() => { closePopup.Invoke(VRCUiPopupManager.prop_VRCUiPopupManager_0, null); blacklistedUserIds.Add(dropper.id); }), null
                    });
                    return(false);
                }
                else if (ShouldCheckUserPortal(dropper) && !(AskToPortalSettings.autoAcceptHome && __instance.field_Internal_Boolean_1) && !AskToPortalSettings.onlyPortalDrop)
                {
                    popupV2.Invoke(VRCUiPopupManager.prop_VRCUiPopupManager_0, new object[7] {
                        "Enter This Portal?",
                        $"Do you want to enter this portal?{Environment.NewLine}World Name: {__instance.field_Private_ApiWorld_0.name}{Environment.NewLine}Dropper: {dropper.displayName}{Environment.NewLine}Instance Type: {roomInfo.instanceType}",
                        "Yes", (Il2CppSystem.Action) new Action(() =>
                        {
                            closePopup.Invoke(VRCUiPopupManager.prop_VRCUiPopupManager_0, null);

                            if (__instance == null)
                            {
                                object currentPortalInfo = Activator.CreateInstance(portalInfo);
                                currentPortalInfo.GetType().GetProperty($"field_Public_{portalInfoEnum.Name}_0").SetValue(currentPortalInfo, portalInfoEnum.GetEnumValues().GetValue(3)); //I hate reflection
                                typeof(Il2CppSystem.Collections.Generic.Dictionary <string, string>).GetMethod("Add").Invoke(currentPortalInfo.GetType().GetProperty("field_Public_Dictionary_2_String_String_0").GetValue(currentPortalInfo), new object[2] {
                                    "transitionPortalType", dropper.id == "" ? "Static" : "Dynamic"
                                });
                                typeof(Il2CppSystem.Collections.Generic.Dictionary <string, string>).GetMethod("Add").Invoke(currentPortalInfo.GetType().GetProperty("field_Public_Dictionary_2_String_String_0").GetValue(currentPortalInfo), new object[2] {
                                    "transitionPortalOwner", dropper.id
                                });
                                enterWorld.Invoke(VRCFlowManager.prop_VRCFlowManager_0, new object[5] {
                                    worldId, roomId, currentPortalInfo, (Il2CppSystem.Action <string>) new Action <string>((str) => popupV2Small.Invoke(VRCUiPopupManager.prop_VRCUiPopupManager_0, new object[5] {
                                        "Alert", "Cannot Join World", "Close", (Il2CppSystem.Action) new Action(() => closePopup.Invoke(VRCUiPopupManager.prop_VRCUiPopupManager_0, null)), null
                                    })), false
                                });                                                                                                                                                                                                                                                                                                                                                                                                                           //Just kill me
                            }
                            else
                            {
                                hasTriggered = true;
                                try
                                {
                                    enterPortal.Invoke(__instance, null);
                                }
                                catch {}
                            }
                        }), "No", (Il2CppSystem.Action) new Action(() => closePopup.Invoke(VRCUiPopupManager.prop_VRCUiPopupManager_0, null)), null
                    });

                    return(false);
                }
            }
            hasTriggered = false;
            return(true);
        }
示例#2
0
        public static RoomInfo ParseRoomId(string roomId)
        {
            //Example invite room id: instanceId~private(someones user id here)~nonce(Long hex code here)
            //Example invite+ room id: instanceId~private(someones user id here)~canRequestInvite~nonce(Long hex code here)
            //Example friends room id: instanceId~friend(someones user id here)~nonce(Long hex code here)
            //Example friends+ room id: instanceId~hidden(someones user id here)~nonce(Long hex code here)
            //Example public room id: instanceId
            RoomInfo roomInfo = new RoomInfo();

            IEnumerator splitString = roomId.Split(new char[1] {
                '~'
            }).GetEnumerator();

            splitString.MoveNext();
            roomInfo.instanceId = (string)splitString.Current;
            try
            {
                int instanceId = int.Parse(roomInfo.instanceId);
                if (instanceId > 99998 || instanceId < 1)
                {
                    throw new Exception();
                }
            }
            catch
            {
                roomInfo.isPortalDropper = true;
                return(roomInfo);
            }
            if (splitString.MoveNext())
            {
                string[] tempString = ((string)splitString.Current).Split(new char[1] {
                    '('
                });

                switch (tempString[0])
                {
                case "private":
                    roomInfo.instanceType = "Invite Only";
                    break;

                case "friend":
                    roomInfo.instanceType = "Friends Only";
                    break;

                case "hidden":
                    roomInfo.instanceType = "Friends+";
                    break;

                default:
                    roomInfo.isPortalDropper = true;
                    return(roomInfo);
                }
                try
                {
                    roomInfo.ownerId = tempString[1].TrimEnd(new char[1] {
                        ')'
                    });
                }
                catch (IndexOutOfRangeException)
                {
                    roomInfo.isPortalDropper = true;
                    return(roomInfo);
                }

                if (!splitString.MoveNext())
                {
                    roomInfo.isPortalDropper = true;
                    return(roomInfo);
                }
                if ((string)splitString.Current == "canRequestInvite")
                {
                    roomInfo.instanceType = "Invite+";
                    splitString.MoveNext();
                }

                try
                {
                    roomInfo.nonce = ((string)splitString.Current).Split(new char[1] {
                        '('
                    })[1].TrimEnd(new char[1] {
                        ')'
                    });
                }
                catch
                {
                    roomInfo.isPortalDropper = true;
                    return(roomInfo);
                }
            }
            else
            {
                roomInfo.instanceType = "Public";
            }

            return(roomInfo);
        }
示例#3
0
        public static bool OnPortalEnter(PortalInternal __instance)
        {
            if (!AskToPortalSettings.enabled.Value)
            {
                return(true);
            }
            if (!shouldInterrupt)
            {
                return(true);
            }

            Photon.Pun.PhotonView photonView = __instance.gameObject.GetComponent <Photon.Pun.PhotonView>();
            APIUser dropper;

            if (photonView == null)
            {
                dropper = new APIUser(displayName: "Not Player Dropped", id: "");
            }
            else
            {
                dropper = cachedDroppers[__instance.GetInstanceID()].prop_APIUser_0; // Get cached user because the photon object before gets the owner and can be spoofed
            }
            if (blacklistedUserIds.Contains(dropper.id))
            {
                return(false);
            }
            if (!ShouldCheckUserPortal(dropper, photonView == null))
            {
                return(true);
            }

            string roomId  = __instance.field_Private_String_1;
            string worldId = __instance.field_Private_ApiWorld_0.id;
            int    roomPop = __instance.field_Private_Int32_0;

            RoomInfo roomInfo;

            if (photonView == null)
            {
                roomInfo = new RoomInfo();
            }
            else
            {
                roomInfo = new RoomInfo(roomId);
            }

            //If portal dropper is not owner of private instance but still dropped the portal or world id is the public ban world or if the population is in the negatives or is above 80
            if (!string.IsNullOrWhiteSpace(roomInfo.ownerId) && roomInfo.ownerId != dropper.id && !roomInfo.instanceType.Contains("Public"))
            {
                roomInfo.errors.Add("Instance type was non-public and the owner of the instance did not match the dropper of the portal");
            }

            if (worldId == "wrld_5b89c79e-c340-4510-be1b-476e9fcdedcc")
            {
                roomInfo.errors.Add("Portal leads to the public ban world, which is used almost exclusively by portal droppers");
            }

            if (roomPop < 0 || roomPop > 80)
            {
                roomInfo.errors.Add("Room population was an invalid value");
            }

            MenuManager.OnPortalEnter(roomInfo, __instance, dropper, worldId, roomId);
            return(false);
        }