/// <summary> /// Adjusts Atmo and Jet suit decor. /// </summary> /// <param name="options">The options for the decor of those suits.</param> /// <param name="suit">The suit def to modify.</param> internal static void TuneSuits(DecorReimaginedOptions options, EquipmentDef suit) { var attr = Db.Get().BuildingAttributes; suit.AttributeModifiers.Add(new AttributeModifier(attr.Decor.Id, options. AtmoSuitDecor, STRINGS.EQUIPMENT.PREFABS.ATMO_SUIT.NAME, false, false, true)); }
public static void OnLoad() { PUtil.InitLibrary(); Options = new DecorReimaginedOptions(); POptions.RegisterOptions(typeof(DecorReimaginedOptions)); PUtil.RegisterPostload(DecorTuning.TuneBuildings); }
/// <summary> /// Applies decor values from the database. /// </summary> internal static void ApplyDatabase(DecorReimaginedOptions options) { DecorDbEntry[] entries = null; try { // Read in database from the embedded config json using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( "PeterHan.DecorRework.buildings.json")) { var jr = new JsonTextReader(new StreamReader(stream)); entries = new JsonSerializer { MaxDepth = 2 }.Deserialize <DecorDbEntry[]>(jr); jr.Close(); } } catch (JsonException e) { // Error when loading decor PUtil.LogExcWarn(e); } catch (IOException e) { // Error when loading decor PUtil.LogExcWarn(e); } if (entries != null) { var editDecor = DictionaryPool <string, DecorDbEntry, DecorDbEntry> .Allocate(); string id; // Add to dictionary, way faster foreach (var entry in entries) { if (!string.IsNullOrEmpty(id = entry.id) && !editDecor.ContainsKey(id)) { editDecor.Add(id, entry); } } foreach (var def in Assets.BuildingDefs) { if (editDecor.TryGetValue(id = def.PrefabID, out DecorDbEntry entry)) { float decor = entry.decor; int radius = entry.radius; var provider = def.BuildingComplete.GetComponent <DecorProvider>(); // For reference, these do not alter the BuildingComplete def.BaseDecor = decor; def.BaseDecorRadius = radius; // Actual decor provider if (provider != null) { PUtil.LogDebug("Patched: {0} Decor: {1:F1} Radius: {2:D}".F(id, decor, radius)); provider.baseDecor = decor; provider.baseRadius = radius; } } } editDecor.Recycle(); } // Patch in the debris decor var baseOreTemplate = Traverse.Create(typeof(EntityTemplates)).GetField < GameObject>("baseOreTemplate"); DecorProvider component; if (baseOreTemplate != null && (component = baseOreTemplate. GetComponent <DecorProvider>()) != null) { component.baseDecor = options.DebrisDecor; component.baseRadius = Math.Max(1, options.DebrisRadius); } // Patch the suits PUtil.LogDebug("Snazzy Suit: {0:D} Warm/Cool Vest: {1:D}".F(options. SnazzySuitDecor, options.VestDecor)); ClothingWearer.ClothingInfo.FANCY_CLOTHING.decorMod = options.SnazzySuitDecor; ClothingWearer.ClothingInfo.COOL_CLOTHING.decorMod = options.VestDecor; ClothingWearer.ClothingInfo.WARM_CLOTHING.decorMod = options.VestDecor; }