private static void RebindWeaponAttributes(EntityTypeAttributes entityType, WeaponAttributesWrapper weaponAttributesWrapper) { var unitAttributes = entityType.Get <UnitAttributes>(); if (unitAttributes != null) { var unitAttributesWrapper = new UnitAttributesWrapper(unitAttributes); for (var i = 0; i < unitAttributesWrapper.WeaponLoadout.Length; i++) { var weaponBinding = unitAttributesWrapper.WeaponLoadout[i]; if (weaponBinding.Weapon.Name == weaponAttributesWrapper.Name) { unitAttributesWrapper.WeaponLoadout[i] = new WeaponBinding( weaponID: weaponBinding.WeaponID, weaponBindingIndex: weaponBinding.WeaponBindingIndex, weapon: weaponAttributesWrapper, ammoID: weaponBinding.AmmoID, turretIndex: weaponBinding.TurretIndex, defaultTurretAngleOffsetRadians: weaponBinding.DefaultTurretAngleOffsetRadians, disabledOnSpawn: weaponBinding.DisabledOnSpawn, weaponOffsetFromUnitOrigin: weaponBinding.OffsetFromUnitCenterInLocalSpace, showAmmoOnHUD: weaponBinding.ShowAmmoOnHUD ); } } entityType.Replace(unitAttributes, unitAttributesWrapper); } }
private void applyCPatch <TAttributes, TWrapper>( EntityTypeAttributes entityType, SubsystemPatch patch, Func <TAttributes, TWrapper> createWrapper, string name = null) where TAttributes : class where TWrapper : TAttributes { var attributes = name != null?entityType.Get <TAttributes>(name) : entityType.Get <TAttributes>(); if (attributes == null) { if (notFoundErrors) { logger.Log($"ERROR: {typeof(TAttributes).Name}" + (name != null ? $": {name}" : "") + " not found"); } return; } using (logger.BeginScope($"{typeof(TAttributes).Name}: {name}")) { var wrapper = createWrapper(attributes); patch.Apply(this, wrapper, entityType); entityType.Replace(attributes, wrapper); } }
private void applyComponentPatch <TPatch, TAttributes, TWrapper>(EntityTypeAttributes entityType, TPatch patch, Func <TAttributes, TWrapper> createWrapper, Action <TPatch, TWrapper> applyPatch, string name = null) where TAttributes : class where TWrapper : TAttributes { using (logger.BeginScope($"{typeof(TAttributes).Name}: {name}")) { var attributes = name != null ? entityType.Get <TAttributes>(name) : entityType.Get <TAttributes>(); if (attributes == null) { logger.Log($"ERROR: {typeof(TAttributes).Name} not found"); return; } var wrapper = createWrapper(attributes); applyPatch(patch, wrapper); entityType.Replace(attributes, wrapper); } }