Ejemplo n.º 1
0
        private static bool GetTypeArray(JSON.Object o, Type type, string key, ref object value)
        {
            JSON.Array result = default(JSON.Array);
            if (!o.Get(key, ref result))
            {
                return(false);
            }
            int   count = result.Count;
            Array array = Array.CreateInstance(type, count);

            for (int i = 0; i < count; ++i)
            {
                JSON.Object tmp1 = default(JSON.Object);
                if (!o.Get(key, ref tmp1))
                {
                    return(false);
                }
                JSON.Readable tmp2;
                try
                {
                    tmp2 = (JSON.Readable)Activator.CreateInstance(type);
                }
                catch (Exception)
                {
                    return(false);
                }
                if (!tmp2.Read(tmp1))
                {
                    return(false);
                }
                array.SetValue(tmp2, i);
            }
            value = array;
            return(true);
        }
Ejemplo n.º 2
0
        private static bool GetEnumArray(JSON.Object o, Type type, string key, ref object value)
        {
            JSON.Array result = default(JSON.Array);
            if (!o.Get(key, ref result))
            {
                return(false);
            }
            int   count = result.Count;
            Array array = Array.CreateInstance(type, count);

            for (int i = 0; i < count; ++i)
            {
                string tmp1 = default(string);
                if (!o.Get(key, ref tmp1))
                {
                    return(false);
                }
                object tmp2;
                try
                {
                    tmp2 = Enum.Parse(type, tmp1);
                }
                catch (Exception)
                {
                    return(false);
                }
                array.SetValue(tmp2, i);
            }
            value = array;
            return(true);
        }
Ejemplo n.º 3
0
 private static void UpdateDamageTypes(JSONArray newDamageTypes, List <DamageTypeEntry> damageTypes)
 {
     damageTypes.Clear();
     damageTypes.AddRange(newDamageTypes.Select(damageType => new DamageTypeEntry
     {
         amount = damageType.Obj.GetFloat("amount", 0), type = (DamageType)Enum.Parse(typeof(DamageType), damageType.Obj.GetString("type", ""))
     }));
 }
Ejemplo n.º 4
0
 public Array(JSON.Array array)
 {
     this.values = new List <Value>();
     this.values = new List <Value>();
     foreach (Value value2 in array.values)
     {
         this.values.Add(new Value(value2));
     }
 }
Ejemplo n.º 5
0
 public static JSON.Array operator +(JSON.Array lhs, JSON.Array rhs)
 {
     JSON.Array array = new JSON.Array(lhs);
     foreach (Value value2 in rhs.values)
     {
         array.Add(value2);
     }
     return(array);
 }
Ejemplo n.º 6
0
 private void StripSubCategoryLoot(JSONArray arr)
 {
     //float sum = arr.Sum(x => x.Obj.GetFloat("weight", 0)), curSum = sum;
     foreach (var entry in arr)
     {
         StripLoot(entry.Obj.GetObject("category"), entry.Obj, "category");
         //curSum -= entry.Obj.GetFloat("weight", 0);
         //entry.Obj["percent"] = Math.Round((sum - curSum)/(sum/100f), 2);
     }
 }
Ejemplo n.º 7
0
 private static void StripArray(JSONArray arr, string key)
 {
     if (arr == null)
     {
         return;
     }
     foreach (var obj in arr)
     {
         StripObject(obj.Obj[key].Obj);
     }
 }
Ejemplo n.º 8
0
 public PlutonUIPanel(string nam = null, string par = null, float?fade = null)
 {
     components = new JSON.Array();
     if (nam != null)
     {
         name = nam;
     }
     if (par != null)
     {
         parent = par;
     }
     if (fade != null)
     {
         fadeOut = (float)fade;
     }
 }
Ejemplo n.º 9
0
        private JSONValue ObjectToJsonObject(object obj)
        {
            if (obj == null)
            {
                return(new JSONValue(JSONValueType.Null));
            }
            if (obj is string)
            {
                return(new JSONValue((string)obj));
            }
            if (obj is double)
            {
                return(new JSONValue((double)obj));
            }
            if (obj is int)
            {
                return(new JSONValue((int)obj));
            }
            if (obj is bool)
            {
                return(new JSONValue((bool)obj));
            }
            var dict = obj as Dictionary <string, object>;

            if (dict != null)
            {
                var newObj = new JSONObject();
                foreach (var prop in dict)
                {
                    newObj.Add(prop.Key, ObjectToJsonObject(prop.Value));
                }
                return(newObj);
            }
            var list = obj as List <object>;

            if (list != null)
            {
                var arr = new JSONArray();
                foreach (var o in list)
                {
                    arr.Add(ObjectToJsonObject(o));
                }
                return(arr);
            }
            Puts("Unknown: " + obj.GetType().FullName + " Value: " + obj);
            return(new JSONValue(JSONValueType.Null));
        }
Ejemplo n.º 10
0
        private async Task <VersionNumber> GetLatestExtensionVersion()
        {
            string json = await WebClient.DownloadStringTaskAsync(OxideRustReleaseListUrl);

            if (string.IsNullOrWhiteSpace(json))
            {
                throw new Exception("Could not retrieve latest Oxide.Rust version from GitHub API");
            }

            JSON.Array  releaseArray = JSON.Array.Parse(json);
            JSON.Object latest       = releaseArray[0].Obj;

            string tag = latest.GetString("tag_name");

            if (string.IsNullOrWhiteSpace(tag))
            {
                throw new Exception("Tag name is undefined");
            }

            VersionNumber tagVersion = ParseVersionNumber(tag);

            return(tagVersion);
        }
Ejemplo n.º 11
0
 private static JSONArray ToJsonArray(object obj)
 {
     return(JSONArray.Parse(ToJsonString(obj)));
 }
Ejemplo n.º 12
0
        private bool CreateDefaultConfig()
        {
            Config.Clear();
            Config["Version"] = Protocol.network;
            var itemList = Resources.LoadAll <ItemDefinition>("items/").ToList();
            var bpList   = Resources.LoadAll <ItemBlueprint>("items/").ToList();
            var items    = new JSONArray();

            foreach (var definition in itemList)
            {
                var obj      = ToJsonObject(definition);
                var mods     = definition.GetComponentsInChildren <ItemMod>(true);
                var modArray = new JSONArray();
                foreach (var itemMod in mods)
                {
                    if (itemMod.GetType() == typeof(ItemModMenuOption))
                    {
                        continue;
                    }
                    var mod = ToJsonObject(itemMod);
                    if (itemMod.GetType() == typeof(ItemModBurnable))
                    {
                        StripObject(mod["byproductItem"].Obj);
                    }
                    else if (itemMod.GetType() == typeof(ItemModCookable))
                    {
                        StripObject(mod["becomeOnCooked"].Obj);
                    }
                    else if (itemMod.GetType() == typeof(ItemModConsume))
                    {
                        mod["effects"] = ToJsonArray(itemMod.GetComponent <ItemModConsumable>().effects);
                    }
                    else if (itemMod.GetType() == typeof(ItemModSwap))
                    {
                        var becomeItems = mod["becomeItem"].Array;
                        foreach (var entry in becomeItems)
                        {
                            entry.Obj["itemDef"] = entry.Obj.GetObject("itemDef").GetString("shortname", "unnamed");
                        }
                    }
                    if (!mod.Any())
                    {
                        continue;
                    }
                    mod["type"] = itemMod.GetType().FullName;
                    modArray.Add(mod);
                }
                var modProjectile = definition.GetComponent <ItemModProjectile>();
                if (modProjectile != null)
                {
                    var projectile = modProjectile.projectileObject.targetObject.GetComponent <Projectile>();
                    var mod        = ToJsonObject(projectile);
                    mod.Remove("sourceWeapon");
                    mod.Remove("projectileID");
                    mod.Remove("seed");
                    mod.Remove("velocityScalar");
                    mod["type"] = modProjectile.GetType().FullName;
                    modArray.Add(mod);
                }
                obj["modules"] = modArray;

                items.Add(obj);
            }
            Config["Items"] = JsonObjectToObject(items);
            var bps = ToJsonArray(bpList);

            foreach (var bp in bps)
            {
                StripObject(bp.Obj["targetItem"].Obj);
                foreach (var ing in bp.Obj.GetArray("ingredients"))
                {
                    ing.Obj["itemDef"] = ing.Obj.GetObject("itemDef").GetString("shortname", "unnamed");
                }
            }
            Config["Blueprints"] = JsonObjectToObject(bps);

            /*var constructions = new Dictionary<string, object>();
             * Config["Constructions"] = constructions;
             * var protectionProperties = new HashSet<ProtectionProperties>();
             * var constructionSkinArray = Resources.LoadAll<ConstructionSkin>("Prefabs/build/skins");
             * var constructionArray = Resources.LoadAll<Construction>("Prefabs/build/");
             * foreach (var construct in constructionArray)
             * {
             *  var common = new Construction.Common(construct, constructionSkinArray);
             *  var construction = new Dictionary<string, object>();
             *  var grades = new Dictionary<string, object>();
             *  for (var g = 0; g < common.grades.Length; g++)
             *  {
             *      var grade = common.grades[g];
             *      if (grade == null) continue;
             *      var dict = new Dictionary<string, object>();
             *      dict["maxHealth"] = grade.maxHealth;
             *      var costToBuild = ToJsonArray(grade.costToBuild);
             *      foreach (var cost in costToBuild)
             *      {
             *          cost.Obj["itemDef"] = cost.Obj.GetObject("itemDef").GetString("shortname", "unnamed");
             *      }
             *      dict["costToBuild"] = JsonObjectToObject(costToBuild);
             *      if (grade.damageProtecton != null)
             *      {
             *          protectionProperties.Add(grade.damageProtecton);
             *      }
             *      grades[((BuildingGrade.Enum)g).ToString()] = dict;
             *  }
             *  construction["grades"] = grades;
             *  constructions[common.name] = construction;
             * }
             * var protections = new Dictionary<string, object>();
             * Config["DamageProtections"] = protections;
             * foreach (var protectionProperty in protectionProperties)
             * {
             *  var damageProtection = new Dictionary<string, object>();
             *  for (var i = 0; i < protectionProperty.amounts.Length; i++)
             *  {
             *      damageProtection[Enum.GetName(typeof(DamageType), i)] = protectionProperty.amounts[i];
             *  }
             *  protections[protectionProperty.name] = damageProtection;
             * }*/
            try
            {
                Config.Save(_configpath);
            }
            catch (Exception e)
            {
                LocalPuts(e.Message);
                return(false);
            }
            LocalPuts("Created new config");
            return(LoadConfig());
        }
Ejemplo n.º 13
0
 private JSONValue ObjectToJsonObject(object obj)
 {
     if (obj == null)
     {
         return new JSONValue(JSONValueType.Null);
     }
     if (obj is string)
     {
         return new JSONValue((string)obj);
     }
     if (obj is double)
     {
         return new JSONValue((double)obj);
     }
     if (obj is int)
     {
         return new JSONValue((int)obj);
     }
     if (obj is bool)
     {
         return new JSONValue((bool)obj);
     }
     var dict = obj as Dictionary<string, object>;
     if (dict != null)
     {
         var newObj = new JSONObject();
         foreach (var prop in dict)
         {
             newObj.Add(prop.Key, ObjectToJsonObject(prop.Value));
         }
         return newObj;
     }
     var list = obj as List<object>;
     if (list != null)
     {
         var arr = new JSONArray();
         foreach (var o in list)
         {
             arr.Add(ObjectToJsonObject(o));
         }
         return arr;
     }
     Puts("Unknown: " + obj.GetType().FullName + " Value: " + obj);
     return new JSONValue(JSONValueType.Null);
 }
Ejemplo n.º 14
0
 private static bool Get(JSON.Object o, string key, ref JSON.Array a)
 {
     return(o.Get(key, ref a));
 }
Ejemplo n.º 15
0
 public Value(JSON.Array array)
 {
     this.Type  = JSON.ValueType.Array;
     this.Array = array;
 }
Ejemplo n.º 16
0
        public static JSON.Object Parse(string jsonString)
        {
            if (!string.IsNullOrEmpty(jsonString))
            {
                Value         value2 = null;
                List <string> list   = new List <string>();
                ParsingState  key    = ParsingState.Object;
                for (int i = 0; i < jsonString.Length; i++)
                {
                    string str;
                    char   ch;
                    string str2;
                    double num2;
                    Value  value4;
                    char   ch2;
                    i = SkipWhitespace(jsonString, i);
                    switch (key)
                    {
                    case ParsingState.Object:
                        if (jsonString[i] == '{')
                        {
                            break;
                        }
                        return(Fail('{', i));

                    case ParsingState.Array:
                        if (jsonString[i] == '[')
                        {
                            goto Label_059A;
                        }
                        return(Fail('[', i));

                    case ParsingState.EndObject:
                        if (jsonString[i] == '}')
                        {
                            goto Label_00B7;
                        }
                        return(Fail('}', i));

                    case ParsingState.EndArray:
                        if (jsonString[i] == ']')
                        {
                            goto Label_05D5;
                        }
                        return(Fail(']', i));

                    case ParsingState.Key:
                    {
                        if (jsonString[i] != '}')
                        {
                            goto Label_0169;
                        }
                        i--;
                        key = ParsingState.EndObject;
                        continue;
                    }

                    case ParsingState.Value:
                        ch = jsonString[i];
                        if (ch != '"')
                        {
                            goto Label_0235;
                        }
                        key = ParsingState.String;
                        goto Label_02E3;

                    case ParsingState.KeyValueSeparator:
                        if (jsonString[i] == ':')
                        {
                            goto Label_01AC;
                        }
                        return(Fail(':', i));

                    case ParsingState.ValueSeparator:
                        ch2 = jsonString[i];
                        switch (ch2)
                        {
                        case ',':
                            goto Label_01DC;

                        case ']':
                            goto Label_0200;

                        case '}':
                            goto Label_01F5;
                        }
                        return(Fail(", } ]", i));

                    case ParsingState.String:
                        str2 = ParseString(jsonString, ref i);
                        if (str2 != null)
                        {
                            goto Label_0309;
                        }
                        return(Fail("string value", i));

                    case ParsingState.Number:
                        num2 = ParseNumber(jsonString, ref i);
                        if (!double.IsNaN(num2))
                        {
                            goto Label_0394;
                        }
                        return(Fail("valid number", i));

                    case ParsingState.Boolean:
                        if (jsonString[i] != 't')
                        {
                            goto Label_04BE;
                        }
                        if (((jsonString.Length >= (i + 4)) && (jsonString[i + 1] == 'r')) && ((jsonString[i + 2] == 'u') && (jsonString[i + 3] == 'e')))
                        {
                            goto Label_0455;
                        }
                        return(Fail("true", i));

                    case ParsingState.Null:
                        if (jsonString[i] != 'n')
                        {
                            goto Label_072A;
                        }
                        if (((jsonString.Length >= (i + 4)) && (jsonString[i + 1] == 'u')) && ((jsonString[i + 2] == 'l') && (jsonString[i + 3] == 'l')))
                        {
                            goto Label_06C6;
                        }
                        return(Fail("null", i));

                    default:
                    {
                        continue;
                    }
                    }
                    Value value3 = new JSON.Object();
                    if (value2 != null)
                    {
                        value3.Parent = value2;
                    }
                    value2 = value3;
                    key    = ParsingState.Key;
                    continue;
Label_00B7:
                    if (value2.Parent == null)
                    {
                        return(value2.Obj);
                    }
                    JSON.ValueType type = value2.Parent.Type;
                    if (type != JSON.ValueType.Object)
                    {
                        if (type != JSON.ValueType.Array)
                        {
                            return(Fail("valid object", i));
                        }
                    }
                    else
                    {
                        value2.Parent.Obj.values[list.Pop <string>()] = new Value(value2.Obj);
                        goto Label_0142;
                    }
                    value2.Parent.Array.Add(new Value(value2.Obj));
Label_0142:
                    value2 = value2.Parent;
                    key    = ParsingState.ValueSeparator;
                    continue;
Label_0169:
                    str = ParseString(jsonString, ref i);
                    if (str == null)
                    {
                        return(Fail("key string", i));
                    }
                    list.Add(str);
                    key = ParsingState.KeyValueSeparator;
                    continue;
Label_01AC:
                    key = ParsingState.Value;
                    continue;
Label_01DC:
                    key = (value2.Type != JSON.ValueType.Object) ? ParsingState.Value : ParsingState.Key;
                    continue;
Label_01F5:
                    key = ParsingState.EndObject;
                    i--;
                    continue;
Label_0200:
                    key = ParsingState.EndArray;
                    i--;
                    continue;
Label_0235:
                    if (char.IsDigit(ch) || (ch == '-'))
                    {
                        key = ParsingState.Number;
                    }
                    else
                    {
                        ch2 = ch;
                        switch (ch2)
                        {
                        case '[':
                            key = ParsingState.Array;
                            goto Label_02E3;

                        case ']':
                            if (value2.Type != JSON.ValueType.Array)
                            {
                                return(Fail("valid array", i));
                            }
                            key = ParsingState.EndArray;
                            goto Label_02E3;
                        }
                        switch (ch2)
                        {
                        case 'f':
                        case 't':
                            key = ParsingState.Boolean;
                            break;

                        case 'n':
                            key = ParsingState.Null;
                            break;

                        default:
                            if (ch2 != '{')
                            {
                                return(Fail("beginning of value", i));
                            }
                            key = ParsingState.Object;
                            break;
                        }
                    }
Label_02E3:
                    i--;
                    continue;
Label_0309:
                    type = value2.Type;
                    if (type != JSON.ValueType.Object)
                    {
                        if (type == JSON.ValueType.Array)
                        {
                            goto Label_0348;
                        }
                        goto Label_035F;
                    }
                    value2.Obj.values[list.Pop <string>()] = new Value(str2);
                    goto Label_036B;
Label_0348:
                    value2.Array.Add(str2);
                    goto Label_036B;
Label_035F:
                    Debug.LogError("Fatal error, current JSON value not valid");
                    return(null);

Label_036B:
                    key = ParsingState.ValueSeparator;
                    continue;
Label_0394:
                    type = value2.Type;
                    if (type != JSON.ValueType.Object)
                    {
                        if (type == JSON.ValueType.Array)
                        {
                            goto Label_03D3;
                        }
                        goto Label_03EA;
                    }
                    value2.Obj.values[list.Pop <string>()] = new Value(num2);
                    goto Label_03F6;
Label_03D3:
                    value2.Array.Add(num2);
                    goto Label_03F6;
Label_03EA:
                    Debug.LogError("Fatal error, current JSON value not valid");
                    return(null);

Label_03F6:
                    key = ParsingState.ValueSeparator;
                    continue;
Label_0455:
                    type = value2.Type;
                    if (type != JSON.ValueType.Object)
                    {
                        if (type == JSON.ValueType.Array)
                        {
                            goto Label_0493;
                        }
                        goto Label_04A9;
                    }
                    value2.Obj.values[list.Pop <string>()] = new Value(true);
                    goto Label_04B5;
Label_0493:
                    value2.Array.Add(new Value(true));
                    goto Label_04B5;
Label_04A9:
                    Debug.LogError("Fatal error, current JSON value not valid");
                    return(null);

Label_04B5:
                    i += 3;
                    goto Label_057C;
Label_04BE:
                    if (((jsonString.Length < (i + 5)) || (jsonString[i + 1] != 'a')) || (((jsonString[i + 2] != 'l') || (jsonString[i + 3] != 's')) || (jsonString[i + 4] != 'e')))
                    {
                        return(Fail("false", i));
                    }
                    type = value2.Type;
                    if (type != JSON.ValueType.Object)
                    {
                        if (type == JSON.ValueType.Array)
                        {
                            goto Label_0556;
                        }
                        goto Label_056C;
                    }
                    value2.Obj.values[list.Pop <string>()] = new Value(false);
                    goto Label_0578;
Label_0556:
                    value2.Array.Add(new Value(false));
                    goto Label_0578;
Label_056C:
                    Debug.LogError("Fatal error, current JSON value not valid");
                    return(null);

Label_0578:
                    i += 4;
Label_057C:
                    key = ParsingState.ValueSeparator;
                    continue;
Label_059A:
                    value4 = new JSON.Array();
                    if (value2 != null)
                    {
                        value4.Parent = value2;
                    }
                    value2 = value4;
                    key    = ParsingState.Value;
                    continue;
Label_05D5:
                    if (value2.Parent == null)
                    {
                        return(value2.Obj);
                    }
                    type = value2.Parent.Type;
                    if (type != JSON.ValueType.Object)
                    {
                        if (type != JSON.ValueType.Array)
                        {
                            return(Fail("valid object", i));
                        }
                    }
                    else
                    {
                        value2.Parent.Obj.values[list.Pop <string>()] = new Value(value2.Array);
                        goto Label_0660;
                    }
                    value2.Parent.Array.Add(new Value(value2.Array));
Label_0660:
                    value2 = value2.Parent;
                    key    = ParsingState.ValueSeparator;
                    continue;
Label_06C6:
                    type = value2.Type;
                    if (type != JSON.ValueType.Object)
                    {
                        if (type == JSON.ValueType.Array)
                        {
                            goto Label_0704;
                        }
                        goto Label_071A;
                    }
                    value2.Obj.values[list.Pop <string>()] = new Value(JSON.ValueType.Null);
                    goto Label_0726;
Label_0704:
                    value2.Array.Add(new Value(JSON.ValueType.Null));
                    goto Label_0726;
Label_071A:
                    Debug.LogError("Fatal error, current JSON value not valid");
                    return(null);

Label_0726:
                    i += 3;
Label_072A:
                    key = ParsingState.ValueSeparator;
                }
                Debug.LogError("Unexpected end of string");
            }
            return(null);
        }
Ejemplo n.º 17
0
        /*private static void StripObject(JSONObject obj)
         * {
         *  if (obj == null) return;
         *  var keys = obj.Select(entry => entry.Key).ToList();
         *  foreach (var key in keys)
         *  {
         *      if (!key.Equals("shortname") && !key.Equals("itemid"))
         *          obj.Remove(key);
         *  }
         * }
         *
         * private static void StripArray(JSONArray arr, string key)
         * {
         *  if (arr == null) return;
         *  foreach (var obj in arr)
         *  {
         *      StripObject(obj.Obj[key].Obj);
         *  }
         * }*/

        private bool CreateDefaultConfig()
        {
            Config.Clear();
            Config["Version"]       = Protocol.network;
            Config["VersionConfig"] = VersionConfig;
            var gameObjectArray = FileSystem.Load <ObjectList>("Assets/items.asset").objects.Cast <GameObject>().ToArray();
            var itemList        = gameObjectArray.Select(x => x.GetComponent <ItemDefinition>()).Where(x => x != null).ToArray();
            var bpList          = gameObjectArray.Select(x => x.GetComponent <ItemBlueprint>()).Where(x => x != null).ToArray();
            var items           = new JSONArray();

            foreach (var definition in itemList)
            {
                //Puts("Item: {0}", definition.displayName.english);
                var obj = ToJsonObject(definition);
                obj.Remove("itemid");
                obj.Remove("hidden");
                obj.Remove("isWearable");
                obj["Parent"]             = definition.Parent?.shortname;
                obj["displayName"]        = definition.displayName.english;
                obj["displayDescription"] = definition.displayDescription.english;
                var mods     = definition.GetComponentsInChildren <ItemMod>(true);
                var modArray = new JSONArray();
                foreach (var itemMod in mods)
                {
                    if (itemMod.GetType() == typeof(ItemModMenuOption) || itemMod.GetType() == typeof(ItemModConditionHasFlag) || itemMod.GetType() == typeof(ItemModConditionContainerFlag) ||
                        itemMod.GetType() == typeof(ItemModSwitchFlag) || itemMod.GetType() == typeof(ItemModCycle) || itemMod.GetType() == typeof(ItemModConditionHasContents) ||
                        itemMod.GetType() == typeof(ItemModUseContent) || itemMod.GetType() == typeof(ItemModEntity) || itemMod.GetType() == typeof(ItemModUnwrap))
                    {
                        continue;
                    }
                    //Puts("ItemMod: {0}", itemMod.GetType());
                    var mod = ToJsonObject(itemMod);
                    if (itemMod.GetType() == typeof(ItemModBurnable))
                    {
                        mod["byproductItem"] = mod.GetObject("byproductItem")?.GetString("shortname", "unnamed");
                    }
                    else if (itemMod.GetType() == typeof(ItemModCookable))
                    {
                        mod["becomeOnCooked"] = mod.GetObject("becomeOnCooked")?.GetString("shortname", "unnamed");
                    }
                    else if (itemMod.GetType() == typeof(ItemModContainer))
                    {
                        var defaultContents = mod["defaultContents"].Array;
                        foreach (var entry in defaultContents)
                        {
                            entry.Obj["shortname"] = entry.Obj.GetObject("itemDef").GetString("shortname", "unnamed");
                            entry.Obj.Remove("itemDef");
                            entry.Obj.Remove("itemid");
                        }
                        mod["onlyAllowedItemType"] = mod.GetObject("onlyAllowedItemType")?.GetString("shortname", "unnamed");
                    }
                    else if (itemMod.GetType() == typeof(ItemModConsume))
                    {
                        mod["effects"] = ToJsonArray(itemMod.GetComponent <ItemModConsumable>().effects);
                    }
                    else if (itemMod.GetType() == typeof(ItemModReveal))
                    {
                        mod["revealedItemOverride"] = mod.GetObject("revealedItemOverride")?.GetString("shortname", "unnamed");
                    }
                    else if (itemMod.GetType() == typeof(ItemModRecycleInto))
                    {
                        mod["recycleIntoItem"] = mod.GetObject("recycleIntoItem")?.GetString("shortname", "unnamed");
                    }
                    else if (itemMod.GetType() == typeof(ItemModUpgrade))
                    {
                        mod["upgradedItem"] = mod.GetObject("upgradedItem")?.GetString("shortname", "unnamed");
                    }
                    else if (itemMod.GetType() == typeof(ItemModSwap))
                    {
                        var becomeItems = mod["becomeItem"].Array;
                        foreach (var entry in becomeItems)
                        {
                            entry.Obj["shortname"] = entry.Obj.GetObject("itemDef").GetString("shortname", "unnamed");
                            entry.Obj.Remove("itemDef");
                            entry.Obj.Remove("itemid");
                        }
                    }
                    else if (itemMod.GetType() == typeof(ItemModWearable))
                    {
                        var itemModWearable = itemMod.GetComponent <ItemModWearable>();
                        if (itemModWearable.protectionProperties != null)
                        {
                            var protectionObj = new JSONObject
                            {
                                ["density"] = itemModWearable.protectionProperties.density
                            };
                            var amounts = new JSONObject();
                            for (var i = 0; i < itemModWearable.protectionProperties.amounts.Length; i++)
                            {
                                amounts[((DamageType)i).ToString()] = itemModWearable.protectionProperties.amounts[i];
                            }
                            protectionObj["amounts"] = amounts;
                            mod["protection"]        = protectionObj;
                        }
                        if (itemModWearable.armorProperties != null)
                        {
                            mod["armor"] = FromJsonString <string>(ToJsonString((HitAreaUnity)itemModWearable.armorProperties.area));
                        }
                        var targetWearable = mod.GetObject("targetWearable");
                        targetWearable.Remove("showCensorshipCube");
                        targetWearable.Remove("showCensorshipCubeBreasts");
                        targetWearable.Remove("followBone");
                        targetWearable["occupationOver"]  = FromJsonString <string>(ToJsonString((OccupationSlotsUnity)itemModWearable.targetWearable.occupationOver));
                        targetWearable["occupationUnder"] = FromJsonString <string>(ToJsonString((OccupationSlotsUnity)itemModWearable.targetWearable.occupationUnder));
                    }
                    if (!mod.Any())
                    {
                        continue;
                    }
                    mod["type"] = itemMod.GetType().FullName;
                    modArray.Add(mod);
                }
                var modEntity = definition.GetComponent <ItemModEntity>();
                if (modEntity != null)
                {
                    var prefab         = modEntity.entityPrefab?.Get();
                    var timedExplosive = prefab?.GetComponent <ThrownWeapon>()?.prefabToThrow?.Get()?.GetComponent <TimedExplosive>();
                    if (timedExplosive != null)
                    {
                        var mod = ToJsonObject(timedExplosive);
                        mod["type"] = modEntity.GetType().FullName + timedExplosive.GetType().FullName;
                        if (timedExplosive is DudTimedExplosive)
                        {
                            mod.Remove("itemToGive");
                        }
                        modArray.Add(mod);
                    }
                    var modMelee = prefab?.GetComponent <BaseMelee>();
                    if (modMelee != null)
                    {
                        var mod = ToJsonObject(modMelee);
                        mod["type"] = modEntity.GetType().FullName + typeof(BaseMelee).FullName;
                        mod.Remove("strikeEffect");
                        modArray.Add(mod);
                    }
                    var baseProjectile = prefab?.GetComponent <BaseProjectile>();
                    if (baseProjectile != null)
                    {
                        var mod = new JSONObject
                        {
                            ["ammoType"] = baseProjectile.primaryMagazine.ammoType.shortname,
                            //["ammoTypes"] = ToJsonString(baseProjectile.primaryMagazine.definition.ammoTypes),
                            ["builtInSize"] = baseProjectile.primaryMagazine.definition.builtInSize,
                            //["capacity"] = baseProjectile.primaryMagazine.capacity,
                            ["contents"] = baseProjectile.primaryMagazine.contents,
                            ["type"]     = modEntity.GetType().FullName + typeof(BaseProjectile).FullName
                        };
                        modArray.Add(mod);
                    }
                }
                var modProjectile = definition.GetComponent <ItemModProjectile>();
                if (modProjectile != null)
                {
                    var prefab     = modProjectile.projectileObject?.Get();
                    var projectile = prefab?.GetComponent <Projectile>();
                    if (projectile != null)
                    {
                        var mod = ToJsonObject(projectile);
                        mod.Remove("sourceWeapon");
                        mod.Remove("projectileID");
                        mod.Remove("seed");
                        mod.Remove("velocityScalar");
                        if (modProjectile.mods != null)
                        {
                            var modsArray = new JSONArray();
                            foreach (var projectileMod in modProjectile.mods)
                            {
                                var projMod = ToJsonObject(projectileMod);
                                projMod["type"] = projectileMod.GetType().FullName;
                                modsArray.Add(projMod);
                            }
                            mod["mods"] = modsArray;
                        }
                        var spawn = modProjectile as ItemModProjectileSpawn;
                        if (spawn != null)
                        {
                            mod["createOnImpactChance"] = spawn.createOnImpactChance;
                            mod["spreadAngle"]          = spawn.spreadAngle;
                        }
                        mod["type"] = modProjectile.GetType().FullName;
                        modArray.Add(mod);
                    }

                    /*var components = modProjectile.projectileObject.targetObject.GetComponents(typeof (Component));
                     * foreach (var component in components)
                     * {
                     *  LocalPuts("Name: " + component.name + " Type: " + component.GetType().Name);
                     * }*/
                    var timedExplosive = prefab?.GetComponent <TimedExplosive>();
                    if (timedExplosive != null)
                    {
                        var mod = ToJsonObject(timedExplosive);
                        mod["type"] = modProjectile.GetType().FullName + timedExplosive.GetType().FullName;
                        modArray.Add(mod);
                    }
                    var serverProjectile = prefab?.GetComponent <ServerProjectile>();
                    if (serverProjectile != null)
                    {
                        var mod = ToJsonObject(serverProjectile);
                        mod["type"] = modProjectile.GetType().FullName + serverProjectile.GetType().FullName;
                        modArray.Add(mod);
                    }
                }
                obj["modules"] = modArray;

                items.Add(obj);
            }

            Config["Items"] = JsonObjectToObject(items);
            var bps = ToJsonArray(bpList);

            foreach (var bp in bps)
            {
                bp.Obj["targetItem"] = bp.Obj.GetObject("targetItem").GetString("shortname", "unnamed");
                bp.Obj.Remove("userCraftable");
                bp.Obj.Remove("defaultBlueprint");
                foreach (var ing in bp.Obj.GetArray("ingredients"))
                {
                    ing.Obj["shortname"] = ing.Obj.GetObject("itemDef").GetString("shortname", "unnamed");
                    ing.Obj.Remove("itemDef");
                    ing.Obj.Remove("itemid");
                }
            }
            Config["Blueprints"] = JsonObjectToObject(bps);

            try
            {
                Config.Save(_configpath);
            }
            catch (Exception e)
            {
                Puts("Config save failed: {0}{1}{2}", e.Message, Environment.NewLine, e.StackTrace);
                return(false);
            }
            Puts("Created new config");
            return(LoadConfig());
        }