public static bool Prefix(WeaponDef __instance, ref string json) { CustomAmmoCategoriesLog.Log.LogWrite("WeaponDef fromJSON "); JObject defTemp = JObject.Parse(json); CustomAmmoCategoriesLog.Log.LogWrite(defTemp["Description"]["Id"] + "\n"); CustomAmmoCategory custCat = CustomAmmoCategories.find((string)defTemp["AmmoCategory"]); //CustomAmmoCategories.RegisterWeapon((string)defTemp["Description"]["Id"], custCat); ExtWeaponDef extDef = new ExtWeaponDef(); extDef.AmmoCategory = custCat; if (defTemp["Streak"] != null) { extDef.StreakEffect = (bool)defTemp["Streak"]; defTemp.Remove("Streak"); } if (defTemp["HitGenerator"] != null) { try { extDef.HitGenerator = (HitGeneratorType)Enum.Parse(typeof(HitGeneratorType), (string)defTemp["HitGenerator"], true); } catch (Exception e) { extDef.HitGenerator = HitGeneratorType.NotSet; } defTemp.Remove("HitGenerator"); } if (defTemp["FlatJammingChance"] != null) { extDef.FlatJammingChance = (float)defTemp["FlatJammingChance"]; defTemp.Remove("FlatJammingChance"); } if (defTemp["GunneryJammingBase"] != null) { extDef.GunneryJammingBase = (float)defTemp["GunneryJammingBase"]; defTemp.Remove("GunneryJammingBase"); } if (defTemp["GunneryJammingMult"] != null) { extDef.GunneryJammingMult = (float)defTemp["GunneryJammingMult"]; defTemp.Remove("GunneryJammingMult"); } if (defTemp["DirectFireModifier"] != null) { extDef.DirectFireModifier = (float)defTemp["DirectFireModifier"]; defTemp.Remove("DirectFireModifier"); } if (defTemp["DisableClustering"] != null) { extDef.DisableClustering = ((bool)defTemp["DisableClustering"] == true) ? TripleBoolean.True : TripleBoolean.False; defTemp.Remove("DisableClustering"); } if (defTemp["NotUseInMelee"] != null) { extDef.NotUseInMelee = ((bool)defTemp["NotUseInMelee"] == true) ? TripleBoolean.True : TripleBoolean.False; defTemp.Remove("NotUseInMelee"); } if (defTemp["DamageOnJamming"] != null) { extDef.DamageOnJamming = ((bool)defTemp["DamageOnJamming"] == true) ? TripleBoolean.True : TripleBoolean.False; defTemp.Remove("DamageOnJamming"); } if (defTemp["Modes"] != null) { if (defTemp["Modes"].Type == JTokenType.Array) { extDef.Modes.Clear(); JToken jWeaponModes = defTemp["Modes"]; foreach (JObject jWeaponMode in jWeaponModes) { string ModeJSON = jWeaponMode.ToString(); if (string.IsNullOrEmpty(ModeJSON)) { continue; } ; WeaponMode mode = new WeaponMode(); mode.fromJSON(ModeJSON); if (mode.AmmoCategory == null) { mode.AmmoCategory = extDef.AmmoCategory; } //mode.AmmoCategory = extDef.AmmoCategory; CustomAmmoCategoriesLog.Log.LogWrite(" adding mode '" + mode.Id + "'\n"); extDef.Modes.Add(mode.Id, mode); if (mode.isBaseMode == true) { extDef.baseModeId = mode.Id; } } } defTemp.Remove("Modes"); } if (extDef.baseModeId == WeaponMode.NONE_MODE_NAME) { WeaponMode mode = new WeaponMode(); mode.Id = WeaponMode.BASE_MODE_NAME; mode.AmmoCategory = extDef.AmmoCategory; extDef.baseModeId = mode.Id; extDef.Modes.Add(mode.Id, mode); } CustomAmmoCategories.registerExtWeaponDef((string)defTemp["Description"]["Id"], extDef); defTemp["AmmoCategory"] = custCat.BaseCategory.ToString(); //CustomAmmoCategoriesLog.Log.LogWrite("\n--------------ORIG----------------\n" + json + "\n----------------------------------\n"); //CustomAmmoCategoriesLog.Log.LogWrite("\n--------------MOD----------------\n" + defTemp.ToString() + "\n----------------------------------\n"); json = defTemp.ToString(); return(true); }
public static bool Prefix(AmmunitionDef __instance, ref string json) { CustomAmmoCategoriesLog.Log.LogWrite("AmmunitionDef fromJSON "); JObject defTemp = JObject.Parse(json); CustomAmmoCategoriesLog.Log.LogWrite(defTemp["Description"]["Id"] + "\n"); CustomAmmoCategory custCat = CustomAmmoCategories.find((string)defTemp["Category"]); //CustomAmmoCategories.RegisterAmmunition((string)defTemp["Description"]["Id"], custCat); defTemp["Category"] = custCat.BaseCategory.ToString(); ExtAmmunitionDef extAmmoDef = new ExtAmmunitionDef(); extAmmoDef.AmmoCategory = custCat; if (defTemp["AccuracyModifier"] != null) { extAmmoDef.AccuracyModifier = (float)defTemp["AccuracyModifier"]; defTemp.Remove("AccuracyModifier"); } if (defTemp["DamagePerShot"] != null) { extAmmoDef.DamagePerShot = (float)defTemp["DamagePerShot"]; defTemp.Remove("DamagePerShot"); } if (defTemp["HeatDamagePerShot"] != null) { extAmmoDef.HeatDamagePerShot = (float)defTemp["HeatDamagePerShot"]; defTemp.Remove("HeatDamagePerShot"); } if (defTemp["ProjectilesPerShot"] != null) { extAmmoDef.ProjectilesPerShot = (int)defTemp["ProjectilesPerShot"]; defTemp.Remove("ProjectilesPerShot"); } if (defTemp["ShotsWhenFired"] != null) { extAmmoDef.ShotsWhenFired = (int)defTemp["ShotsWhenFired"]; defTemp.Remove("ShotsWhenFired"); } if (defTemp["CriticalChanceMultiplier"] != null) { extAmmoDef.CriticalChanceMultiplier = (float)defTemp["CriticalChanceMultiplier"]; defTemp.Remove("CriticalChanceMultiplier"); } if (defTemp["AIBattleValue"] != null) { extAmmoDef.AIBattleValue = (int)defTemp["AIBattleValue"]; defTemp.Remove("AIBattleValue"); } if (defTemp["MinRange"] != null) { extAmmoDef.MinRange = (float)defTemp["MinRange"]; defTemp.Remove("MinRange"); } if (defTemp["MaxRange"] != null) { extAmmoDef.MaxRange = (float)defTemp["MaxRange"]; defTemp.Remove("MaxRange"); } if (defTemp["ShortRange"] != null) { extAmmoDef.ShortRange = (float)defTemp["ShortRange"]; defTemp.Remove("ShortRange"); } if (defTemp["MediumRange"] != null) { extAmmoDef.MediumRange = (float)defTemp["MediumRange"]; defTemp.Remove("MediumRange"); } if (defTemp["LongRange"] != null) { extAmmoDef.LongRange = (float)defTemp["LongRange"]; defTemp.Remove("LongRange"); } if (defTemp["ForbiddenRange"] != null) { extAmmoDef.ForbiddenRange = (float)defTemp["ForbiddenRange"]; defTemp.Remove("ForbiddenRange"); } if (defTemp["RefireModifier"] != null) { extAmmoDef.RefireModifier = (int)defTemp["RefireModifier"]; defTemp.Remove("RefireModifier"); } if (defTemp["Instability"] != null) { extAmmoDef.Instability = (float)defTemp["Instability"]; defTemp.Remove("Instability"); } if (defTemp["AttackRecoil"] != null) { extAmmoDef.AttackRecoil = (int)defTemp["AttackRecoil"]; defTemp.Remove("AttackRecoil"); } if (defTemp["WeaponEffectID"] != null) { extAmmoDef.WeaponEffectID = (string)defTemp["WeaponEffectID"]; defTemp.Remove("WeaponEffectID"); } if (defTemp["EvasivePipsIgnored"] != null) { extAmmoDef.EvasivePipsIgnored = (float)defTemp["EvasivePipsIgnored"]; defTemp.Remove("EvasivePipsIgnored"); } if (defTemp["FlatJammingChance"] != null) { extAmmoDef.FlatJammingChance = (float)defTemp["FlatJammingChance"]; defTemp.Remove("FlatJammingChance"); } if (defTemp["GunneryJammingBase"] != null) { extAmmoDef.GunneryJammingBase = (float)defTemp["GunneryJammingBase"]; defTemp.Remove("GunneryJammingBase"); } if (defTemp["GunneryJammingMult"] != null) { extAmmoDef.GunneryJammingMult = (float)defTemp["GunneryJammingMult"]; defTemp.Remove("GunneryJammingMult"); } if (defTemp["IndirectFireCapable"] != null) { extAmmoDef.IndirectFireCapable = ((bool)defTemp["IndirectFireCapable"] == true) ? TripleBoolean.True : TripleBoolean.False; defTemp.Remove("IndirectFireCapable"); } if (defTemp["DirectFireModifier"] != null) { extAmmoDef.DirectFireModifier = (float)defTemp["DirectFireModifier"]; defTemp.Remove("DirectFireModifier"); } if (defTemp["AOECapable"] != null) { extAmmoDef.AOECapable = ((bool)defTemp["AOECapable"] == true) ? TripleBoolean.True : TripleBoolean.False; defTemp.Remove("AOECapable"); } if (defTemp["DistantVariance"] != null) { extAmmoDef.DistantVariance = (float)defTemp["DistantVariance"]; defTemp.Remove("DistantVariance"); } if (defTemp["AlwaysIndirectVisuals"] != null) { extAmmoDef.AlwaysIndirectVisuals = ((bool)defTemp["AlwaysIndirectVisuals"] == true) ? TripleBoolean.True : TripleBoolean.False; defTemp.Remove("AlwaysIndirectVisuals"); } if (defTemp["DamageMultiplier"] != null) { extAmmoDef.DamageMultiplier = (float)defTemp["DamageMultiplier"]; defTemp.Remove("DamageMultiplier"); } if (defTemp["DistantVarianceReversed"] != null) { extAmmoDef.DistantVarianceReversed = ((bool)defTemp["DistantVarianceReversed"] == true) ? TripleBoolean.True : TripleBoolean.False; defTemp.Remove("DistantVarianceReversed"); } if (defTemp["DamageVariance"] != null) { extAmmoDef.DamageVariance = (float)defTemp["DamageVariance"]; defTemp.Remove("DamageVariance"); } if (defTemp["HitGenerator"] != null) { try { extAmmoDef.HitGenerator = (HitGeneratorType)Enum.Parse(typeof(HitGeneratorType), (string)defTemp["HitGenerator"], true); } catch (Exception e) { extAmmoDef.HitGenerator = HitGeneratorType.NotSet; } defTemp.Remove("HitGenerator"); } if (defTemp["statusEffects"] != null) { if (defTemp["statusEffects"].Type == JTokenType.Array) { List <EffectData> tmpList = new List <EffectData>(); JToken statusEffects = defTemp["statusEffects"]; foreach (JObject statusEffect in statusEffects) { EffectData effect = new EffectData(); JSONSerializationUtility.FromJSON <EffectData>(effect, statusEffect.ToString()); tmpList.Add(effect); } extAmmoDef.statusEffects = tmpList.ToArray(); } //extAmmoDef.statusEffects = JsonConvert.DeserializeObject<EffectData[]>(defTemp["statusEffects"].ToString()); //JSONSerializationUtility.FromJSON<EffectData[]>(extAmmoDef.statusEffects, defTemp["statusEffects"].ToString()); //CustomAmmoCategoriesLog.Log.LogWrite(JsonConvert.SerializeObject(extAmmoDef.statusEffects)+"\n"); defTemp.Remove("statusEffects"); } CustomAmmoCategories.RegisterExtAmmoDef((string)defTemp["Description"]["Id"], extAmmoDef); json = defTemp.ToString(); return(true); }