public override void Setup(PortalInternal portal, RoomInfo roomInfo, APIUser dropper, string worldId, string roomId)
        {
            base.Setup(portal, roomInfo, dropper, worldId, roomId);

            field_Public_String_1 = "AskToPortal Basic";

            if (AskToPortalMod.cachedDroppers.ContainsKey(portal.GetInstanceID()))
            {
                try
                {
                    avatarImage.texture = AskToPortalMod.cachedDroppers[portal.GetInstanceID()].prop_VRCPlayer_0.field_Private_Texture2D_1;
                    if (avatarImage.texture == null)
                    {
                        avatarImage.texture = AskToPortalMod.cachedDroppers[portal.GetInstanceID()].prop_VRCPlayer_0.field_Private_Texture2D_0;
                    }
                }
                catch (NullReferenceException)
                {
                }
            }
            else
            {
                avatarImage.texture = null;
            }

            if (dropper.id != "")
            {
                messageText.text = $"{dropper.displayName} has dropped a portal to {portal.field_Private_ApiWorld_0.name} #{roomInfo.instanceId} {roomInfo.instanceType}.";
            }
            else
            {
                messageText.text = $"This is a world portal to {portal.field_Private_ApiWorld_0.name}.";
            }

            switch (roomInfo.errors.Count)
            {
            case 0:
                messageText.text += "\nThere are no detected errors with the portal, so it's destination should be safe.";
                break;

            case 1:
                messageText.text += "\nThere is one error with the portal, so it's destination will most likely be safe.";
                break;

            case 2:
                messageText.text += "\nThere are multiple errors with the portal. You probably should leave this one alone";
                break;

            default:
                messageText.text += "\nThere are a lot of errors with this portal. You really can only get this high when deliberately messing with the portal. Leave this one alone.";
                break;
            }

            if (dropper.id != "")
            {
                messageText.text += "\nDo you wish to enter, leave, or blacklist this dropper so you cant enter their porals until you restart?";
            }
            else
            {
                messageText.text += "\nDo you wish to enter or leave?";
            }
        }
Example #2
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);
        }
Example #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);
        }