private void LoadConfigData() { if (BetterChat) { Puts("We found BetterChat! Enabling Support."); Config["Config", "BetterChat"] = "true"; } else { Puts("No BetterChat found! Disabling Support."); Config["Config", "BetterChat"] = "false"; } if (Config["Plugin", "Version"].ToString() != version) { Puts("Uh oh! Not up to date! No Worries, lets update you!"); switch (version) { case "1.0.1": Config["Config", "EnableEmotes"] = "false"; Config["Emotes", ":)"] = "smiles"; Config["Emotes", ":-)"] = "smiles"; Config["Emotes", ":=)"] = "smiles"; Config["Emotes", ":("] = "sulks"; Config["Emotes", ":-("] = "sulks"; Config["Emotes", ":=("] = "sulks"; Config["Emotes", ":D"] = "grins"; Config["Emotes", ":-D"] = "grins"; Config["Emotes", ":=D"] = "grins"; Config["Emotes", ":d"] = "grins"; Config["Emotes", ":-d"] = "grins"; Config["Emotes", ":=d"] = "grins"; Config["Emotes", ":|"] = "is speechless"; Config["Emotes", ":-|"] = "is speechless"; Config["Emotes", ":=|"] = "is speechless"; Config["Emotes", ":p"] = "sticks out a tongue"; Config["Emotes", ":-p"] = "sticks out a tongue"; Config["Emotes", ":=p"] = "sticks out a tongue"; Config["Emotes", ":P"] = "sticks out a tongue"; Config["Emotes", ":-P"] = "sticks out a tongue"; Config["Emotes", ":=P"] = "sticks out a tongue"; Config["Emotes", ":$"] = "blushes"; Config["Emotes", ":-$"] = "blushes"; Config["Emotes", ":=$"] = "blushes"; Config["Emotes", "]:)"] = "gives an evil grin"; Config["Emotes", ">:)"] = "gives an evil grin"; Config["Emotes", ":*"] = "blows a kiss"; Config["Emotes", ":-*"] = "blows a kiss"; Config["Emotes", ":=*"] = "blows a kiss"; Config["Emotes", ":@"] = "looks angry"; Config["Emotes", ":-@"] = "looks angry"; Config["Emotes", ":=@"] = "looks angry"; Config["Emotes", "x("] = "looks angry"; Config["Emotes", "x-("] = "looks angry"; Config["Emotes", "x=("] = "looks angry"; Config["Emotes", "X("] = "looks angry"; Config["Emotes", "X-("] = "looks angry"; Config["Emotes", "X=("] = "looks angry"; Config["Emotes", "o/"] = "waves"; Config["Emotes", "\\o"] = "waves back"; break; case "1.0.6": Config["Config", "BetterChat"] = "false"; break; } Config["Plugin", "Version"] = version; Config.Save(); } template = Config["Config", "Text"].ToString(); EnableEmotes = Config["Config", "EnableEmotes"].ToString(); }
void LoadConfigFile() { bool missing = false; // Load or set the Join Message Format. if (Config[conf_JoinMsg] != null) { joinFormat = Config[conf_JoinMsg].ToString(); } else { missing = true; Config[conf_JoinMsg] = joinFormat; } // Load or set the Quit Message Format. if (Config[conf_QuitMsg] != null) { quitFormat = Config[conf_QuitMsg].ToString(); } else { missing = true; Config[conf_QuitMsg] = quitFormat; } // Load or set the admin colour. if (Config[conf_AdminCol] != null) { adminColour = Config[conf_AdminCol].ToString(); } else { missing = true; Config[conf_AdminCol] = adminColour; } // Load or set the user colour. if (Config[conf_PlayerCol] != null) { userColour = Config[conf_PlayerCol].ToString(); } else { missing = true; Config[conf_PlayerCol] = userColour; } // Load or set only show admins. if (Config[conf_OnlyAdmin] != null) { onlyShowAdmins = (bool)Config[conf_OnlyAdmin]; } else { missing = true; Config[conf_OnlyAdmin] = onlyShowAdmins; } // Load or set show connections. if (Config[conf_ShowConnect] != null) { showConnections = (bool)Config[conf_ShowConnect]; } else { missing = true; Config[conf_ShowConnect] = showConnections; } // Load or set show disconnections. if (Config[conf_ShowDisConn] != null) { showDisconnections = (bool)Config[conf_ShowDisConn]; } else { missing = true; Config[conf_ShowDisConn] = showDisconnections; } if (missing) { Config.Save(); PrintWarning("Updated the config file."); } }
/*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()); }
private void Loaded() => LoadConfigData(); // What to do when plugin loaded private void LoadConfigData() { if (!permission.PermissionExists("emote.canemote")) { permission.RegisterPermission("emote.canemote", this); } if (Config["Plugin", "Version"].ToString() != version) { Puts("Uh oh! Not up to date! No Worries, lets update you!"); switch (version) { case "1.0.1": Config["Config", "EnableEmotes"] = "false"; Config["Emotes", ":)"] = "smiles"; Config["Emotes", ":-)"] = "smiles"; Config["Emotes", ":=)"] = "smiles"; Config["Emotes", ":("] = "sulks"; Config["Emotes", ":-("] = "sulks"; Config["Emotes", ":=("] = "sulks"; Config["Emotes", ":D"] = "grins"; Config["Emotes", ":-D"] = "grins"; Config["Emotes", ":=D"] = "grins"; Config["Emotes", ":d"] = "grins"; Config["Emotes", ":-d"] = "grins"; Config["Emotes", ":=d"] = "grins"; Config["Emotes", ":|"] = "is speechless"; Config["Emotes", ":-|"] = "is speechless"; Config["Emotes", ":=|"] = "is speechless"; Config["Emotes", ":p"] = "sticks out a tongue"; Config["Emotes", ":-p"] = "sticks out a tongue"; Config["Emotes", ":=p"] = "sticks out a tongue"; Config["Emotes", ":P"] = "sticks out a tongue"; Config["Emotes", ":-P"] = "sticks out a tongue"; Config["Emotes", ":=P"] = "sticks out a tongue"; Config["Emotes", ":$"] = "blushes"; Config["Emotes", ":-$"] = "blushes"; Config["Emotes", ":=$"] = "blushes"; Config["Emotes", "]:)"] = "gives an evil grin"; Config["Emotes", ">:)"] = "gives an evil grin"; Config["Emotes", ":*"] = "blows a kiss"; Config["Emotes", ":-*"] = "blows a kiss"; Config["Emotes", ":=*"] = "blows a kiss"; Config["Emotes", ":@"] = "looks angry"; Config["Emotes", ":-@"] = "looks angry"; Config["Emotes", ":=@"] = "looks angry"; Config["Emotes", "x("] = "looks angry"; Config["Emotes", "x-("] = "looks angry"; Config["Emotes", "x=("] = "looks angry"; Config["Emotes", "X("] = "looks angry"; Config["Emotes", "X-("] = "looks angry"; Config["Emotes", "X=("] = "looks angry"; Config["Emotes", "o/"] = "waves"; Config["Emotes", "\\o"] = "waves back"; break; } Config["Plugin", "Version"] = version; Config.Save(); } template = Config["Config", "Text"].ToString(); EnableEmotes = Config["Config", "EnableEmotes"].ToString(); }