public static void Prefix(StatCollection __instance, string statName, StatCollection.StatOperation op, Variant variant)
        {
            try {
                Dictionary <string, Statistic> stats = Traverse.Create(__instance).Field <Dictionary <string, Statistic> >("stats").Value;
                if (stats.ContainsKey(statName))
                {
                    return;
                }
                Log.Debug?.TWL(0, "StatCollection.ModifyStatistic " + statName + " is absent. Adding");
                switch (op)
                {
                case StatCollection.StatOperation.Set: {
                    if (variant.CheckType(Variant.boolType))
                    {
                        __instance.AddStatistic <bool>(statName, false);
                    }
                    else
                    if (variant.CheckType(Variant.intType))
                    {
                        __instance.AddStatistic <int>(statName, 0);
                    }
                    else
                    if (variant.CheckType(Variant.floatType))
                    {
                        __instance.AddStatistic <float>(statName, 0.0f);
                    }
                    else
                    if (variant.CheckType(Variant.stringType))
                    {
                        __instance.AddStatistic <string>(statName, string.Empty);
                    }
                }
                break;

                case StatCollection.StatOperation.Int_Add:
                case StatCollection.StatOperation.Int_Subtract:
                case StatCollection.StatOperation.Int_Multiply:
                case StatCollection.StatOperation.Int_Divide:
                case StatCollection.StatOperation.Int_Divide_Denom:
                case StatCollection.StatOperation.Int_Mod:
                case StatCollection.StatOperation.Int_Multiply_Float:
                case StatCollection.StatOperation.Int_Divide_Float:
                case StatCollection.StatOperation.Int_Divide_Denom_Float:
                case StatCollection.StatOperation.Bitflag_SetBit:
                case StatCollection.StatOperation.Bitflag_FlipBit:
                case StatCollection.StatOperation.Bitflag_Combine: {
                    __instance.AddStatistic <int>(statName, 0);
                }; break;

                case StatCollection.StatOperation.Float_Add:
                case StatCollection.StatOperation.Float_Subtract:
                case StatCollection.StatOperation.Float_Multiply:
                case StatCollection.StatOperation.Float_Divide:
                case StatCollection.StatOperation.Float_Divide_Denom:
                case StatCollection.StatOperation.Float_Multiply_Int:
                case StatCollection.StatOperation.Float_Divide_Int:
                case StatCollection.StatOperation.Float_Divide_Denom_Int: {
                    __instance.AddStatistic <float>(statName, 0.0f);
                }; break;

                case StatCollection.StatOperation.String_Append:
                case StatCollection.StatOperation.String_Prepend: {
                    __instance.AddStatistic <string>(statName, string.Empty);
                }; break;
                }
            } catch (Exception e) {
                Log.Error?.TWL(0, e.ToString(), true);
            }
        }
        public static void TestStatistic(this StatCollection stats, EffectData effectData)
        {
            if (stats.ContainsStatistic(effectData.statisticData.statName))
            {
                return;
            }
            if (effectData.statisticData.statName.StartsWith(StatisticEffect_OnEffectBegin.ADD_ENCOUNTER_FLAG_STAT_ID) == false)
            {
                return;
            }
            Variant variant = new Variant(System.Type.GetType(effectData.statisticData.modType));

            switch (effectData.statisticData.operation)
            {
            case StatCollection.StatOperation.Set: {
                if (variant.CheckType(Variant.boolType))
                {
                    stats.AddStatistic <bool>(effectData.statisticData.statName, false);
                }
                else
                if (variant.CheckType(Variant.intType))
                {
                    stats.AddStatistic <int>(effectData.statisticData.statName, 0);
                }
                else
                if (variant.CheckType(Variant.floatType))
                {
                    stats.AddStatistic <float>(effectData.statisticData.statName, 0.0f);
                }
                else
                if (variant.CheckType(Variant.stringType))
                {
                    stats.AddStatistic <string>(effectData.statisticData.statName, string.Empty);
                }
            }
            break;

            case StatCollection.StatOperation.Int_Add:
            case StatCollection.StatOperation.Int_Subtract:
            case StatCollection.StatOperation.Int_Multiply:
            case StatCollection.StatOperation.Int_Divide:
            case StatCollection.StatOperation.Int_Divide_Denom:
            case StatCollection.StatOperation.Int_Mod:
            case StatCollection.StatOperation.Int_Multiply_Float:
            case StatCollection.StatOperation.Int_Divide_Float:
            case StatCollection.StatOperation.Int_Divide_Denom_Float:
            case StatCollection.StatOperation.Bitflag_SetBit:
            case StatCollection.StatOperation.Bitflag_FlipBit:
            case StatCollection.StatOperation.Bitflag_Combine: {
                stats.AddStatistic <int>(effectData.statisticData.statName, 0);
            }; break;

            case StatCollection.StatOperation.Float_Add:
            case StatCollection.StatOperation.Float_Subtract:
            case StatCollection.StatOperation.Float_Multiply:
            case StatCollection.StatOperation.Float_Divide:
            case StatCollection.StatOperation.Float_Divide_Denom:
            case StatCollection.StatOperation.Float_Multiply_Int:
            case StatCollection.StatOperation.Float_Divide_Int:
            case StatCollection.StatOperation.Float_Divide_Denom_Int: {
                stats.AddStatistic <float>(effectData.statisticData.statName, 0.0f);
            }; break;

            case StatCollection.StatOperation.String_Append:
            case StatCollection.StatOperation.String_Prepend: {
                stats.AddStatistic <string>(effectData.statisticData.statName, string.Empty);
            }; break;
            }
        }