Пример #1
0
 // Token: 0x06002090 RID: 8336 RVA: 0x00099564 File Offset: 0x00097764
 private static void StaticFixedUpdate()
 {
     foreach (LocalUser localUser in LocalUserManager.readOnlyLocalUsersList)
     {
         if (localUser != null && localUser.userProfile.hasUnviewedAchievement)
         {
             Canvas canvas = AchievementNotificationPanel.GetUserCanvas(localUser);
             if (!AchievementNotificationPanel.instancesList.Any((AchievementNotificationPanel instance) => instance.transform.parent == canvas.transform) && AchievementNotificationPanel.IsAppropriateTimeToDisplayUserAchievementNotification(localUser))
             {
                 string text = (localUser != null) ? localUser.userProfile.PopNextUnviewedAchievementName() : null;
                 if (text != null)
                 {
                     AchievementDef achievementDef = AchievementManager.GetAchievementDef(text);
                     if (achievementDef != null)
                     {
                         AchievementNotificationPanel.DispatchAchievementNotification(AchievementNotificationPanel.GetUserCanvas(localUser), achievementDef);
                     }
                 }
             }
         }
     }
 }
        // Token: 0x0600207D RID: 8317 RVA: 0x00099094 File Offset: 0x00097294
        public void SetAchievement(string achievementIdentifier, UserProfile userProfile)
        {
            AchievementDef achievementDef = AchievementManager.GetAchievementDef(achievementIdentifier);

            if (achievementDef != null)
            {
                bool flag  = userProfile.HasAchievement(achievementIdentifier);
                bool flag2 = userProfile.CanSeeAchievement(achievementIdentifier);
                if (this.iconImage)
                {
                    this.iconImage.sprite = (flag ? achievementDef.GetAchievedIcon() : achievementDef.GetUnachievedIcon());
                }
                if (this.nameLabel)
                {
                    this.nameLabel.token = (userProfile.CanSeeAchievement(achievementIdentifier) ? achievementDef.nameToken : "???");
                }
                if (this.descriptionLabel)
                {
                    this.descriptionLabel.token = (userProfile.CanSeeAchievement(achievementIdentifier) ? achievementDef.descriptionToken : "???");
                }
                if (this.unlockedImage)
                {
                    this.unlockedImage.gameObject.SetActive(flag);
                }
                if (this.cantBeAchievedImage)
                {
                    this.cantBeAchievedImage.gameObject.SetActive(!flag2);
                }
                if (this.tooltipProvider)
                {
                    string overrideBodyText = "???";
                    if (flag2)
                    {
                        if (flag)
                        {
                            UnlockableDef unlockableDef = UnlockableCatalog.GetUnlockableDef(achievementDef.unlockableRewardIdentifier);
                            if (unlockableDef != null)
                            {
                                string @string = Language.GetString("ACHIEVEMENT_CARD_REWARD_FORMAT");
                                string string2 = Language.GetString(unlockableDef.nameToken);
                                overrideBodyText = string.Format(@string, string2);
                            }
                        }
                        else
                        {
                            string string3 = Language.GetString("ACHIEVEMENT_CARD_REWARD_FORMAT");
                            string arg     = "???";
                            overrideBodyText = string.Format(string3, arg);
                        }
                    }
                    else
                    {
                        AchievementDef achievementDef2 = AchievementManager.GetAchievementDef(achievementDef.prerequisiteAchievementIdentifier);
                        if (achievementDef2 != null)
                        {
                            string string4 = Language.GetString("ACHIEVEMENT_CARD_PREREQ_FORMAT");
                            string string5 = Language.GetString(achievementDef2.nameToken);
                            overrideBodyText = string.Format(string4, string5);
                        }
                    }
                    this.tooltipProvider.titleToken       = (flag2 ? achievementDef.nameToken : "???");
                    this.tooltipProvider.overrideBodyText = overrideBodyText;
                }
                if (this.tabLayoutElement)
                {
                    this.tabLayoutElement.preferredWidth = (float)AchievementCardController.CalcAchievementTabCount(achievementIdentifier) * this.tabWidth;
                }
            }
        }
Пример #3
0
        // Token: 0x06002656 RID: 9814 RVA: 0x000A6710 File Offset: 0x000A4910
        public static void InitializeChallenge(GameObject gameObject, Entry entry, EntryStatus status, UserProfile userProfile)
        {
            TextMeshProUGUI textMeshProUGUI     = null;
            TextMeshProUGUI textMeshProUGUI2    = null;
            RawImage        rawImage            = null;
            AchievementDef  achievementDef      = (AchievementDef)entry.extraData;
            float           achievementProgress = AchievementManager.GetUserAchievementManager(LocalUserManager.readOnlyLocalUsersList.FirstOrDefault((LocalUser v) => v.userProfile == userProfile)).GetAchievementProgress(achievementDef);
            ChildLocator    component           = gameObject.GetComponent <ChildLocator>();

            if (component)
            {
                textMeshProUGUI       = component.FindChild("DescriptionLabel").GetComponent <TextMeshProUGUI>();
                textMeshProUGUI2      = component.FindChild("NameLabel").GetComponent <TextMeshProUGUI>();
                rawImage              = component.FindChild("RewardImage").GetComponent <RawImage>();
                textMeshProUGUI2.text = Language.GetString(achievementDef.nameToken);
                textMeshProUGUI.text  = Language.GetString(achievementDef.descriptionToken);
            }
            Texture texture = null;
            Color   color   = Color.white;

            switch (status)
            {
            case EntryStatus.None:
                component.FindChild("RewardImageContainer").gameObject.SetActive(true);
                textMeshProUGUI2.text = "";
                textMeshProUGUI.text  = "";
                break;

            case EntryStatus.Unimplemented:
                texture = Resources.Load <Texture2D>("Textures/MiscIcons/texWIPIcon");
                break;

            case EntryStatus.Locked:
                texture = Resources.Load <Texture2D>("Textures/MiscIcons/texUnlockIcon");
                color   = Color.black;
                textMeshProUGUI2.text = Language.GetString("UNIDENTIFIED");
                textMeshProUGUI.text  = Language.GetString("UNIDENTIFIED_DESCRIPTION");
                component.FindChild("CantBeAchieved").gameObject.SetActive(true);
                break;

            case EntryStatus.Unencountered:
                texture = Resources.Load <Texture2D>("Textures/MiscIcons/texUnlockIcon");
                color   = Color.gray;
                component.FindChild("ProgressTowardsUnlocking").GetComponent <Image>().fillAmount = achievementProgress;
                break;

            case EntryStatus.Available:
                texture = entry.iconTexture;
                color   = Color.white;
                component.FindChild("HasBeenUnlocked").gameObject.SetActive(true);
                break;

            case EntryStatus.New:
                texture = entry.iconTexture;
                color   = new Color(1f, 0.8f, 0.5f, 1f);
                component.FindChild("HasBeenUnlocked").gameObject.SetActive(true);
                break;

            default:
                throw new ArgumentOutOfRangeException("status", status, null);
            }
            if (texture != null)
            {
                rawImage.texture = texture;
                rawImage.color   = color;
                return;
            }
            rawImage.enabled = false;
        }
Пример #4
0
 private float UserAchievementManager_GetAchievementProgress(On.RoR2.UserAchievementManager.orig_GetAchievementProgress orig, UserAchievementManager self, AchievementDef achievementDef)
 {
     return(1.0f);
 }
 // Token: 0x0600217E RID: 8574 RVA: 0x000910CE File Offset: 0x0008F2CE
 private static void DispatchAchievementNotification(Canvas canvas, AchievementDef achievementDef)
 {
     UnityEngine.Object.Instantiate <GameObject>(Resources.Load <GameObject>("Prefabs/UI/AchievementNotificationPanel"), canvas.transform).GetComponent <AchievementNotificationPanel>().SetAchievementDef(achievementDef);
     Util.PlaySound(achievementDef.GetAchievementSoundString(), RoR2Application.instance.gameObject);
 }
 // Token: 0x0600217B RID: 8571 RVA: 0x00091057 File Offset: 0x0008F257
 public void SetAchievementDef(AchievementDef achievementDef)
 {
     this.achievementIconImage.sprite = achievementDef.GetAchievedIcon();
     this.achievementName.text        = Language.GetString(achievementDef.nameToken);
     this.achievementDescription.text = Language.GetString(achievementDef.descriptionToken);
 }
        public static bool Prefix(ref Dictionary <string, AchievementDef> ___achievementNamesToDefs, ref List <string> ___achievementIdentifiers, ref AchievementDef[] ___achievementDefs, ref AchievementDef[] ___serverAchievementDefs, ref Action ___onAchievementsRegistered, Dictionary <string, AchievementDef> map)
        {
            //Setup logging
            var achievementLogger = new ManualLogSource("AchievementLoader.Achievement");

            BepInEx.Logging.Logger.Sources.Add(achievementLogger);

            achievementLogger.LogMessage("__== Achievement Loader ==__");
            achievementLogger.LogInfo("Searching for overrides");

            //Search and collect overrides
            IEnumerable <Type> achievementOverrides =
                from t in AppDomain.CurrentDomain.GetAssemblies().Where(a => a.GetName().Name != "ConfigurationManager").SelectMany(a => { achievementLogger.LogDebug(String.Format("Scanning assembly {0} for override defs", a.FullName)); try { return(a.GetTypes()); } catch { achievementLogger.LogError(String.Format("Unable to scan {0} for override defs", a.FullName)); return(new Type[0]); } })
                let attributes = t.GetCustomAttributes(typeof(OverrideAchievement), true)
                                 where attributes != null && attributes.Length > 0
                                 select attributes.Cast <OverrideAchievement>().ToArray()[0].achievementType;

            //Convert from IEnum to List since it's way faster to search a list lmao
            List <Type> achievementOverrideTypes = achievementOverrides.ToList();

            achievementLogger.LogInfo(string.Format("Found {0} overrides", achievementOverrides.Count()));

            //Used for building achievement unlock chains?
            List <AchievementDef> list = new List <AchievementDef>();

            //Used for building achievement unlock chains?
            map.Clear();

            //Get all classes that inherit from BaseAchievement

            foreach (Type achievementClass in from type in (AppDomain.CurrentDomain.GetAssemblies()
                                                            .Where(a => !a.IsDynamic)
                                                            .SelectMany(a => { try { return(a.GetTypes()); } catch { achievementLogger.LogError(String.Format("Unable to scan {0} for achievements", a.FullName)); return(new Type[0]); } }))
                     where type.IsSubclassOf(typeof(BaseAchievement))
                     orderby type.Name
                     select type)
            {
                //Check if the achievement has an override defined
                if (achievementOverrideTypes.Contains(achievementClass))
                {
                    //If it does, don't add it
                    continue;
                }

                //Get the achievement attribute
                RegisterAchievementAttribute registerAchievementAttribute = (RegisterAchievementAttribute)Attribute.GetCustomAttribute(achievementClass, typeof(RegisterAchievementAttribute));

                //Get the custom achievement attribute
                CustomAchievementAttribute customAchievementAttribute = (CustomAchievementAttribute)Attribute.GetCustomAttribute(achievementClass, typeof(CustomAchievementAttribute));

                //If it's found, set the vanilla attribute to have the same values so we don't have to change a bunch of stuff
                if (customAchievementAttribute != null)
                {
                    registerAchievementAttribute = customAchievementAttribute;
                }

                //Check if the achievement was registered
                if (registerAchievementAttribute != null)
                {
                    //Make sure each achievement is unique
                    if (map.ContainsKey(registerAchievementAttribute.identifier))
                    {
                        Debug.LogErrorFormat("Class {0} attempted to register as achievement {1}, but class {2} has already registered as that achievement.", new object[]
                        {
                            achievementClass.FullName,
                            registerAchievementAttribute.identifier,
                            ___achievementNamesToDefs[registerAchievementAttribute.identifier].type.FullName
                        });
                    }
                    else
                    {
                        //Create the vanilla resource path
                        string iconPath = "Textures/AchievementIcons/tex" + registerAchievementAttribute.identifier + "Icon";

                        //Create the icon name
                        string iconName = "tex" + registerAchievementAttribute.identifier + "Icon";

                        //If it's a custom achievement, get the path for it
                        if (customAchievementAttribute != null)
                        {
                            iconPath = customAchievementAttribute.GetPath(iconName);
                        }

                        //If  the achievement is unique, build the achievement
                        AchievementDef achievementDef2 = new AchievementDef
                        {
                            identifier = registerAchievementAttribute.identifier,
                            unlockableRewardIdentifier        = registerAchievementAttribute.unlockableRewardIdentifier,
                            prerequisiteAchievementIdentifier = registerAchievementAttribute.prerequisiteAchievementIdentifier,
                            nameToken         = "ACHIEVEMENT_" + registerAchievementAttribute.identifier.ToUpper(CultureInfo.InvariantCulture) + "_NAME",
                            descriptionToken  = "ACHIEVEMENT_" + registerAchievementAttribute.identifier.ToUpper(CultureInfo.InvariantCulture) + "_DESCRIPTION",
                            iconPath          = iconPath,
                            type              = achievementClass,
                            serverTrackerType = registerAchievementAttribute.serverTrackerType
                        };

                        //Add the achievement identifier to the achievement identifier list
                        ___achievementIdentifiers.Add(registerAchievementAttribute.identifier);

                        //Used for building achievement unlock chains?
                        map.Add(registerAchievementAttribute.identifier, achievementDef2);

                        //Used to build achievement defs array?
                        list.Add(achievementDef2);

                        //Get the related unlockable def
                        UnlockableDef unlockableDef = UnlockableCatalog.GetUnlockableDef(achievementDef2.unlockableRewardIdentifier);

                        //If there is an unlockable def, set the how to unlock and unlocked text
                        if (unlockableDef != null)
                        {
                            string achievementName        = Language.GetString(achievementDef2.nameToken);
                            string achievementDescription = Language.GetString(achievementDef2.descriptionToken);
                            unlockableDef.getHowToUnlockString = (() => Language.GetStringFormatted("UNLOCK_VIA_ACHIEVEMENT_FORMAT", new object[]
                            {
                                achievementName,
                                achievementDescription
                            }));

                            unlockableDef.getUnlockedString = (() => Language.GetStringFormatted("UNLOCKED_FORMAT", new object[]
                            {
                                achievementName,
                                achievementDescription
                            }));
                        }
                    }
                }
                else
                {
                    //Warn that a class inheriting from BaseAchievement doesn't have a AchievementAttribute
                    string msg = string.Format("Class {0} in {1} inherits from BaseAchievement but doesn't have a RegisterAchievement attribute.", new object[] { achievementClass.FullName, achievementClass.Assembly.GetName().Name });
                    achievementLogger.LogWarning(msg);
                }
            }

            ___achievementDefs = list.ToArray();

            //Order achievements
            ___achievementDefs = ___achievementDefs.OrderBy(def => UnlockableCatalog.GetUnlockableSortScore(def.unlockableRewardIdentifier)).ToArray();

            //Get achievements that need to be server tracked
            ___serverAchievementDefs = (from achievementDef in ___achievementDefs
                                        where achievementDef.serverTrackerType != null
                                        select achievementDef).ToArray <AchievementDef>();

            //Build achievements to be tracked by client?
            for (int i = 0; i < ___achievementDefs.Length; i++)
            {
                ___achievementDefs[i].index = new AchievementIndex
                {
                    intValue = i
                };
            }

            //Build achievements to be tracked by server?
            for (int j = 0; j < ___serverAchievementDefs.Length; j++)
            {
                ___serverAchievementDefs[j].serverIndex = new ServerAchievementIndex
                {
                    intValue = j
                };
            }

            //Build achievement requirement chains?
            for (int k = 0; k < ___achievementIdentifiers.Count; k++)
            {
                string currentAchievementIdentifier = ___achievementIdentifiers[k];
                map[currentAchievementIdentifier].childAchievementIdentifiers = (from v in ___achievementIdentifiers
                                                                                 where map[v].prerequisiteAchievementIdentifier == currentAchievementIdentifier
                                                                                 select v).ToArray <string>();
            }

            //Let the system know all achievements have been created
            Action action = ___onAchievementsRegistered;

            if (action == null)
            {
                return(false);
            }
            action();

            //Skip the original code
            return(false);
        }