コード例 #1
0
        private static List <ArmorData> GetArmorDataFromFiles()
        {
            CheckModFolder();

            List <ArmorData> armorDatas = new List <ArmorData>();

            foreach (string file in Directory.GetFiles(assetPath, "*.json"))
            {
                ArmorData data = JsonUtility.FromJson <ArmorData>(File.ReadAllText(file));
                armorDatas.Add(data);
            }
            return(armorDatas);
        }
コード例 #2
0
        private static ArmorData GetArmorDataFromItem(ItemDrop.ItemData item, string itemName)
        {
            var armor = new ArmorData()
            {
                name = itemName,

                armor            = item.m_shared.m_armor,
                armorPerLevel    = item.m_shared.m_armorPerLevel,
                movementModifier = item.m_shared.m_movementModifier,
                damageModifiers  = item.m_shared.m_damageModifiers.Select(m => m.m_type + ":" + m.m_modifier).ToList()
            };

            return(armor);
        }
コード例 #3
0
        private static void SetArmorData(ref ItemDrop.ItemData item, ArmorData armor)
        {
            item.m_shared.m_armor            = armor.armor;
            item.m_shared.m_armorPerLevel    = armor.armorPerLevel;
            item.m_shared.m_movementModifier = armor.movementModifier;

            item.m_shared.m_damageModifiers.Clear();
            foreach (string modString in armor.damageModifiers)
            {
                string[] mod = modString.Split(':');
                item.m_shared.m_damageModifiers.Add(new HitData.DamageModPair()
                {
                    m_type = (HitData.DamageType)Enum.Parse(typeof(HitData.DamageType), mod[0]), m_modifier = (HitData.DamageModifier)Enum.Parse(typeof(HitData.DamageModifier), mod[1])
                });
            }
        }
コード例 #4
0
        private static ArmorData GetArmorDataFromItem(ItemDrop.ItemData item, string itemName)
        {
            var armor = new ArmorData()
            {
                name = itemName,

                armor            = item.m_shared.m_armor,
                armorPerLevel    = item.m_shared.m_armorPerLevel,
                movementModifier = item.m_shared.m_movementModifier,
                damageModifiers  = item.m_shared.m_damageModifiers.Select(m => m.m_type + ":" + m.m_modifier).ToList()
            };

            List <string> mods = new List <string>();

            foreach (var mod in item.m_shared.m_damageModifiers)
            {
                mods.Add(mod.m_type + "," + mod.m_modifier);
            }

            return(armor);
        }
コード例 #5
0
            static bool Prefix(Console __instance)
            {
                if (!modEnabled.Value)
                {
                    return(true);
                }

                string text = __instance.m_input.text;

                if (text.ToLower().Equals($"{typeof(BepInExPlugin).Namespace.ToLower()} reset"))
                {
                    context.Config.Reload();
                    context.Config.Save();
                    Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();
                    Traverse.Create(__instance).Method("AddString", new object[] { $"{context.Info.Metadata.Name} config reloaded" }).GetValue();
                    return(false);
                }
                else if (text.ToLower().Equals($"{typeof(BepInExPlugin).Namespace.ToLower()} reload"))
                {
                    armorDatas = GetArmorDataFromFiles();
                    if (ZNetScene.instance)
                    {
                        LoadAllArmorData(ZNetScene.instance);
                    }
                    Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();
                    Traverse.Create(__instance).Method("AddString", new object[] { $"{context.Info.Metadata.Name} reloaded armor stats from files" }).GetValue();
                    return(false);
                }
                else if (text.ToLower().Equals($"{typeof(BepInExPlugin).Namespace.ToLower()} damagetypes"))
                {
                    Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();

                    Dbgl("\r\n" + string.Join("\r\n", Enum.GetNames(typeof(HitData.DamageType))));

                    Traverse.Create(__instance).Method("AddString", new object[] { $"{context.Info.Metadata.Name} dumped damage types" }).GetValue();
                    return(false);
                }
                else if (text.ToLower().Equals($"{typeof(BepInExPlugin).Namespace.ToLower()} damagemods"))
                {
                    Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();

                    Dbgl("\r\n" + string.Join("\r\n", Enum.GetNames(typeof(HitData.DamageModifier))));

                    Traverse.Create(__instance).Method("AddString", new object[] { $"{context.Info.Metadata.Name} dumped damage modifiers" }).GetValue();
                    return(false);
                }
                else if (text.ToLower().StartsWith($"{typeof(BepInExPlugin).Namespace.ToLower()} save "))
                {
                    var       t         = text.Split(' ');
                    string    armor     = t[t.Length - 1];
                    ArmorData armorData = GetArmorDataByName(armor);
                    if (armorData == null)
                    {
                        return(false);
                    }
                    CheckModFolder();
                    File.WriteAllText(Path.Combine(assetPath, armorData.name + ".json"), JsonUtility.ToJson(armorData));
                    Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();
                    Traverse.Create(__instance).Method("AddString", new object[] { $"{context.Info.Metadata.Name} saved armor data to {armor}.json" }).GetValue();
                    return(false);
                }
                else if (text.ToLower().StartsWith($"{typeof(BepInExPlugin).Namespace.ToLower()} dump "))
                {
                    var       t         = text.Split(' ');
                    string    armor     = t[t.Length - 1];
                    ArmorData armorData = GetArmorDataByName(armor);
                    if (armorData == null)
                    {
                        return(false);
                    }
                    Dbgl(JsonUtility.ToJson(armorData));
                    Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();
                    Traverse.Create(__instance).Method("AddString", new object[] { $"{context.Info.Metadata.Name} dumped {armor}" }).GetValue();
                    return(false);
                }
                else if (text.ToLower().StartsWith($"{typeof(BepInExPlugin).Namespace.ToLower()}"))
                {
                    string output = $"{context.Info.Metadata.Name} reset\r\n"
                                    + $"{context.Info.Metadata.Name} reload\r\n"
                                    + $"{context.Info.Metadata.Name} dump <ArmorName>\r\n"
                                    + $"{context.Info.Metadata.Name} save <ArmorName>\r\n"
                                    + $"{context.Info.Metadata.Name} damagetypes\r\n"
                                    + $"{context.Info.Metadata.Name} damagemods";

                    Traverse.Create(__instance).Method("AddString", new object[] { text }).GetValue();
                    Traverse.Create(__instance).Method("AddString", new object[] { output }).GetValue();
                    return(false);
                }
                return(true);
            }