Esempio n. 1
0
        public override int GetHashCode(GridTempModel obj)
        {
            unchecked
            {
                int hash;
                hash = HashUtility.HashOne(obj.Cell.GetHashCode());
                hash = HashUtility.HashOne(obj.Map.GetHashCode(), hash);

                return(hash);
            }
        }
Esempio n. 2
0
        public static int GetKey(ThoughtDef def, Pawn pawn)
        {
            int hash = 0;

            unchecked
            {
                hash = HashUtility.HashOne(def.shortHash);
                hash = HashUtility.HashOne(pawn.thingIDNumber.GetHashCode(), hash);
            }
            return(hash);
        }
Esempio n. 3
0
        public static int GetKey(StatRequest req)
        {
            unchecked
            {
                int hash;
                hash = HashUtility.HashOne(req.thingInt?.thingIDNumber ?? 0);
                hash = HashUtility.HashOne(req.stuffDefInt?.shortHash ?? 0, hash);
                hash = HashUtility.HashOne((int)req.qualityCategoryInt, hash);
                hash = HashUtility.HashOne(req.defInt?.shortHash ?? 0, hash);
                hash = HashUtility.HashOne(req.faction?.loadID ?? 0, hash);
                hash = HashUtility.HashOne(req.pawn?.thingIDNumber ?? 0, hash);

                return(hash);
            }
        }
Esempio n. 4
0
 public static int GetKey(StatWorker statWorker, StatRequest req, bool applyPostProcess)
 {
     unchecked
     {
         int hash;
         hash = HashUtility.HashOne(statWorker.stat.shortHash);
         hash = HashUtility.HashOne(req.thingInt?.thingIDNumber ?? 0, hash);
         hash = HashUtility.HashOne(req.stuffDefInt?.shortHash ?? 0, hash);
         hash = HashUtility.HashOne((int)req.qualityCategoryInt, hash);
         hash = HashUtility.HashOne(req.defInt?.shortHash ?? 0, hash);
         hash = HashUtility.HashOne(req.faction?.loadID ?? 0, hash);
         hash = HashUtility.HashOne(req.pawn?.thingIDNumber ?? 0, hash);
         hash = HashUtility.HashOne(applyPostProcess ? 1 : 0, hash);
         return(hash);
     }
 }
Esempio n. 5
0
            public static void TransformValue_Postfix(StatPart_ApparelStatOffset __instance, StatRequest req, ref float val, Pair <float, bool> __state)
            {
                if (!__state.second || !Finder.enabled)
                {
                    return;
                }

                if (!req.HasThing || req.Thing == null || !(req.thingInt is Pawn))
                {
                    return;
                }

                var key    = Tools.GetKey(req);
                var tick   = GenTicks.TicksGame;
                var stat   = __instance.apparelStat ?? __instance.parentStat;
                var subKey = 0;

                unchecked
                {
                    subKey = HashUtility.HashOne(__state.first.GetHashCode());
                    subKey = HashUtility.HashOne(stat.index, subKey);
                }

                if (cache.TryGetValue(key, out var store) && tick - store.second < 2500)
                {
                    store.first[(ushort)subKey] = val;
                }
                else
                {
                    Dictionary <ushort, float> dict;

                    if (store == null || store.first == null)
                    {
                        dict = new Dictionary <ushort, float>();
                    }
                    else
                    {
                        store.first.Clear();
                        dict = store.first;
                    }

                    dict[(ushort)subKey] = val;
                    cache[key]           = new Pair <Dictionary <ushort, float>, int>(dict, tick);
                }
            }
Esempio n. 6
0
        public override int GetHashCode(StatRequestModel obj)
        {
            StatRequest statRequest = obj.StatRequest;

            unchecked
            {
                int hash;
                hash = HashUtility.HashOne(obj.Stat.shortHash);
                hash = HashUtility.HashOne(statRequest.Thing?.thingIDNumber ?? 0, hash);
                hash = HashUtility.HashOne(statRequest.StuffDef?.GetHashCode() ?? 0, hash);
                hash = HashUtility.HashOne((int)statRequest.QualityCategory, hash);
                hash = HashUtility.HashOne(statRequest.Def?.GetHashCode() ?? 0, hash);
                hash = HashUtility.HashOne(statRequest.Faction?.loadID ?? 0, hash);
                hash = HashUtility.HashOne(statRequest.Pawn?.thingIDNumber ?? 0, hash);
                hash = HashUtility.HashOne(obj.ApplyPostProcess ? 1 : 0, hash);

                return(hash);
            }
        }
Esempio n. 7
0
            public static bool TransformValue_Prefix(StatPart_ApparelStatOffset __instance, StatRequest req, ref float val, out Pair <float, bool> __state)
            {
                if (Finder.enabled)
                {
                    if (!req.HasThing || req.Thing == null || !(req.thingInt is Pawn))
                    {
                        __state = new Pair <float, bool>(val, true);
                        return(false);
                    }

                    var key    = Tools.GetKey(req);
                    var tick   = GenTicks.TicksGame;
                    var stat   = __instance.apparelStat ?? __instance.parentStat;
                    var subKey = 0;

                    unchecked
                    {
                        subKey = HashUtility.HashOne(val.GetHashCode());
                        subKey = HashUtility.HashOne(stat.index, subKey);
                    }

                    if (cache.TryGetValue(key, out var store) && tick - store.second < 2500)
                    {
                        if (store.first.TryGetValue((ushort)subKey, out float value))
                        {
                            __state = new Pair <float, bool>(val = value, false);
                            return(false);
                        }
                    }

                    __state = new Pair <float, bool>(val, true);
                    return(true);
                }
                else
                {
                    __state = new Pair <float, bool>(val, false);
                    return(true);
                }
            }