Esempio n. 1
0
        private static void GiveShortHash(Def def, Type defType)
        {
            if (def.shortHash != 0)
            {
                Log.Error(def + " already has short hash.", false);
                return;
            }
            HashSet <ushort> hashSet;

            if (!ShortHashGiver.takenHashesPerDeftype.TryGetValue(defType, out hashSet))
            {
                hashSet = new HashSet <ushort>();
                ShortHashGiver.takenHashesPerDeftype.Add(defType, hashSet);
            }
            ushort num  = (ushort)(GenText.StableStringHash(def.defName) % 65535);
            int    num2 = 0;

            while (num == 0 || hashSet.Contains(num))
            {
                num += 1;
                num2++;
                if (num2 > 5000)
                {
                    Log.Message("Short hashes are saturated. There are probably too many Defs.", false);
                }
            }
            def.shortHash = num;
            hashSet.Add(num);
        }
Esempio n. 2
0
        private static void GiveShortHash(Def def, Type defType)
        {
            if (def.shortHash != 0)
            {
                Log.Error(string.Concat(def, " already has short hash."));
                return;
            }
            if (!takenHashesPerDeftype.TryGetValue(defType, out var value))
            {
                value = new HashSet <ushort>();
                takenHashesPerDeftype.Add(defType, value);
            }
            ushort num  = (ushort)(GenText.StableStringHash(def.defName) % 65535);
            int    num2 = 0;

            while (num == 0 || value.Contains(num))
            {
                num = (ushort)(num + 1);
                num2++;
                if (num2 > 5000)
                {
                    Log.Message("Short hashes are saturated. There are probably too many Defs.");
                }
            }
            def.shortHash = num;
            value.Add(num);
        }
Esempio n. 3
0
 public override void ResolveReferences()
 {
     this.thinkRoot.ResolveSubnodesAndRecur();
     foreach (ThinkNode current in this.thinkRoot.ThisAndChildrenRecursive)
     {
         current.ResolveReferences();
     }
     ThinkTreeKeyAssigner.AssignKeys(this.thinkRoot, GenText.StableStringHash(this.defName));
     this.ResolveParentNodes(this.thinkRoot);
 }
Esempio n. 4
0
        private static int NextUnusedKeyFor(ThinkNode node)
        {
            int num = 0;

            while (node != null)
            {
                num  = Gen.HashCombineInt(num, GenText.StableStringHash(node.GetType().Name));
                node = node.parent;
            }
            while (ThinkTreeKeyAssigner.assignedKeys.Contains(num))
            {
                num ^= Rand.Int;
            }
            ThinkTreeKeyAssigner.assignedKeys.Add(num);
            return(num);
        }
            public bool TryParsePackageId(bool isOfficial, bool logIssues = true)
            {
                bool flag = false;

                if (packageId.NullOrEmpty())
                {
                    string str = "none";
                    if (!description.NullOrEmpty())
                    {
                        str = GenText.StableStringHash(description).ToString().Replace("-", "");
                        str = str.Substring(0, Math.Min(3, str.Length));
                    }
                    packageId = ConvertToASCII(author + str) + "." + ConvertToASCII(name);
                    if (logIssues)
                    {
                        Log.Warning("Mod " + name + " is missing packageId in About.xml! (example: <packageId>AuthorName.ModName.Specific</packageId>)");
                    }
                    flag = true;
                }
                if (!PackageIdFormatRegex.IsMatch(packageId))
                {
                    if (logIssues)
                    {
                        Log.Warning("Mod " + name + " <packageId> (" + packageId + ") is not in valid format.");
                    }
                    flag = true;
                }
                if (!isOfficial && packageId.ToLower().Contains(ModContentPack.LudeonPackageIdAuthor))
                {
                    if (logIssues)
                    {
                        Log.Warning("Mod " + name + " <packageId> contains word \"Ludeon\", which is reserved for official content.");
                    }
                    flag = true;
                }
                return(!flag);
            }