Exemplo n.º 1
0
        public static void ReconstructSurvivors()
        {
            SurvivorCatalog.survivorMaxCount = Mathf.Max(SurvivorDefinitions.Count, 10);

            for (int i = 0; i < SurvivorDefinitions.Count; i++)
            {
                SurvivorDefinitions[i].survivorIndex = (SurvivorIndex)i;
            }

            SurvivorCatalog.idealSurvivorOrder = SurvivorDefinitions.Select(x => x.survivorIndex).ToArray();

            survivorDefs.SetValue(null, SurvivorDefinitions.ToArray());
            allSurvivorDefs.SetValue(null, SurvivorDefinitions.ToArray());

            ViewablesCatalog.Node node = new ViewablesCatalog.Node("/Survivors/", true, null);

            var existingNode = ViewablesCatalog.FindNode("/Survivors/");

            //this essentially deletes an existing node if it exists
            existingNode?.SetParent(new ViewablesCatalog.Node("dummy", true, null));

            for (var i = 0; i < SurvivorDefinitions.Count; i++)
            {
                var survivor = SurvivorDefinitions[i];

                ViewablesCatalog.Node survivorEntryNode = new ViewablesCatalog.Node(survivor.displayNameToken, false, node);
                survivorEntryNode.shouldShowUnviewed = userProfile => !userProfile.HasViewedViewable(survivorEntryNode.fullName) && userProfile.HasSurvivorUnlocked(survivor.survivorIndex) && !string.IsNullOrEmpty(survivor.unlockableName);
            }

            ViewablesCatalog.AddNodeToRoot(node);
        }
        // Token: 0x0600244A RID: 9290 RVA: 0x000AA504 File Offset: 0x000A8704
        private bool Check()
        {
            if (LocalUserManager.readOnlyLocalUsersList.Count == 0)
            {
                return(false);
            }
            UserProfile userProfile = LocalUserManager.readOnlyLocalUsersList[0].userProfile;

            ViewablesCatalog.Node node = ViewablesCatalog.FindNode(this.viewableName ?? "");
            if (node == null)
            {
                Debug.LogErrorFormat("Viewable {0} is not defined.", new object[]
                {
                    this.viewableName
                });
                return(false);
            }
            return(node.shouldShowUnviewed(userProfile));
        }
Exemplo n.º 3
0
        private static void ReconstructSurvivors()
        {
            SurvivorDefinitions.GroupBy(x => x.survivorIndex).Where(x => x.Count() > 1).ToList().ForEach(x => {
                R2API.Logger.LogError($"{CenterText("!ERROR!")}");
                R2API.Logger.LogError($"{CenterText($"One of your mods assigns a duplicate SurvivorIndex for \"{x.Key}\"")}");
                R2API.Logger.LogError($"{CenterText("Please ask the author to fix their mod.")}");
            });

            SurvivorCatalog.survivorMaxCount =
                Math.Max((int)SurvivorDefinitions.Select(x => x.survivorIndex).Max() + 1, 10);
            SurvivorCatalog.idealSurvivorOrder = SurvivorDefinitions.Select(x => x.survivorIndex).ToArray();

            // Only contains not null survivors
            typeof(SurvivorCatalog).SetFieldValue("_allSurvivorDefs",
                                                  SurvivorDefinitions
                                                  .OrderBy(x => x.survivorIndex)
                                                  .ToArray()
                                                  );

            // Contains null for index with no survivor
            typeof(SurvivorCatalog).SetFieldValue("survivorDefs",
                                                  Enumerable.Range(0, SurvivorCatalog.survivorMaxCount)
                                                  .Select(i => SurvivorDefinitions.FirstOrDefault(x => x.survivorIndex == (SurvivorIndex)i)
                                                          ?? new SurvivorDef {
                survivorIndex = (SurvivorIndex)i
            })
                                                  .OrderBy(x => x.survivorIndex)
                                                  .Select(x => x.bodyPrefab == null ? null : x)
                                                  .ToArray()
                                                  );

            var bodyIndexToSurvivorIndex = new SurvivorIndex[BodyCatalog.bodyCount];
            var survivorIndexToBodyIndex = new int[SurvivorCatalog.survivorMaxCount];

            foreach (var survivorDef in SurvivorDefinitions)
            {
                int bodyIndex = survivorDef.bodyPrefab.GetComponent <CharacterBody>().bodyIndex;
                bodyIndexToSurvivorIndex[bodyIndex] = survivorDef.survivorIndex;
                survivorIndexToBodyIndex[(int)survivorDef.survivorIndex] = bodyIndex;
            }

            typeof(SurvivorCatalog).SetFieldValue("bodyIndexToSurvivorIndex", bodyIndexToSurvivorIndex);
            typeof(SurvivorCatalog).SetFieldValue("survivorIndexToBodyIndex", survivorIndexToBodyIndex);

            var parent = ViewablesCatalog.FindNode("/Survivors/")
                         ?? new ViewablesCatalog.Node("Survivors", true);

            if (parent.parent == null)
            {
                ViewablesCatalog.AddNodeToRoot(parent);
            }

            foreach (var survivor in SurvivorDefinitions)
            {
                var name = survivor.survivorIndex.ToString();

                var child =
                    ViewablesCatalog.FindNode(parent.fullName + name)
                    ?? new ViewablesCatalog.Node(name, false, parent);

                child.shouldShowUnviewed = userProfile =>
                                           !string.IsNullOrEmpty(survivor.unlockableName) &&
                                           survivor.survivorIndex < SurvivorIndex.Count &&
                                           userProfile.HasSurvivorUnlocked(survivor.survivorIndex) &&
                                           !userProfile.HasViewedViewable(child.fullName)
                ;
            }

            Debug.Log("Re-setting all survivor nodes, duplicates may occur. This is no problem.");
            ViewablesCatalog.AddNodeToRoot(parent);
            Debug.Log("Re-setting survivor nodes complete.");

            // Survivors over the builtin limit will be returned as null from SurvivorCatalog.GetSurvivorDef
            // This is a quick check if the MonoMod component is installed correctly.
            var overLimit = SurvivorDefinitions.FirstOrDefault(x => x.survivorIndex >= SurvivorIndex.Count);

            if (overLimit == null || SurvivorCatalog.GetSurvivorDef(overLimit.survivorIndex) != null)
            {
                return;
            }

            R2API.Logger.LogError($"{CenterText("!ERROR!")}");
            R2API.Logger.LogError($"{CenterText("MonoMod component of R2API is not installed correctly!")}");
            R2API.Logger.LogError($"{CenterText("Please copy Assembly-CSharp.R2API.mm.dll to BepInEx/monomod.")}");
        }