using System; using JetBrains.Annotations; using RoR2.EntitlementManagement; using RoR2.ExpansionManagement; using RoR2.Skills; using UnityEngine; namespace RoR2.ContentManagement; public sealed class ContentPack { [NotNull] private string _identifier = "UNIDENTIFIED"; private static Func getGameObjectName = (GameObject obj) => obj.name; private static Func getComponentName = (Component obj) => obj.gameObject.name; private static Func getScriptableObjectName = (ScriptableObject obj) => obj.name; private static Func getEffectDefName = (EffectDef obj) => obj.prefabName; private static Func getTypeName = (Type obj) => obj.FullName; [NotNull] public NamedAssetCollection bodyPrefabs = new NamedAssetCollection(getGameObjectName); [NotNull] public NamedAssetCollection masterPrefabs = new NamedAssetCollection(getGameObjectName); [NotNull] public NamedAssetCollection projectilePrefabs = new NamedAssetCollection(getGameObjectName); [NotNull] public NamedAssetCollection gameModePrefabs = new NamedAssetCollection(getGameObjectName); [NotNull] public NamedAssetCollection networkedObjectPrefabs = new NamedAssetCollection(getGameObjectName); [NotNull] public NamedAssetCollection skillDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection skillFamilies = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection sceneDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection itemDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection itemTierDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection itemRelationshipProviders = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection itemRelationshipTypes = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection equipmentDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection buffDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection eliteDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection unlockableDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection survivorDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection artifactDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection effectDefs = new NamedAssetCollection(getEffectDefName); [NotNull] public NamedAssetCollection surfaceDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection networkSoundEventDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection musicTrackDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection gameEndingDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection entityStateConfigurations = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection expansionDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection entitlementDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection miscPickupDefs = new NamedAssetCollection(getScriptableObjectName); [NotNull] public NamedAssetCollection entityStateTypes = new NamedAssetCollection(getTypeName); private object[] assetCollections; [NotNull] public string identifier { get { return _identifier; } internal set { _identifier = value ?? throw new ArgumentNullException("'identifier' cannot be null."); } } public ContentPack() { assetCollections = new object[28] { bodyPrefabs, masterPrefabs, projectilePrefabs, gameModePrefabs, networkedObjectPrefabs, skillDefs, skillFamilies, sceneDefs, itemDefs, itemTierDefs, itemRelationshipProviders, itemRelationshipTypes, equipmentDefs, buffDefs, eliteDefs, unlockableDefs, survivorDefs, artifactDefs, effectDefs, surfaceDefs, networkSoundEventDefs, musicTrackDefs, gameEndingDefs, entityStateConfigurations, expansionDefs, entitlementDefs, miscPickupDefs, entityStateTypes }; } public bool ValueEquals(ContentPack other) { return ValueEquals(this, other); } public static void Copy([NotNull] ContentPack src, [NotNull] ContentPack dest) { src = src ?? throw new ArgumentNullException("src"); dest = dest ?? throw new ArgumentNullException("dest"); dest.identifier = src.identifier; src.bodyPrefabs.CopyTo(dest.bodyPrefabs); src.masterPrefabs.CopyTo(dest.masterPrefabs); src.projectilePrefabs.CopyTo(dest.projectilePrefabs); src.gameModePrefabs.CopyTo(dest.gameModePrefabs); src.networkedObjectPrefabs.CopyTo(dest.networkedObjectPrefabs); src.skillDefs.CopyTo(dest.skillDefs); src.skillFamilies.CopyTo(dest.skillFamilies); src.sceneDefs.CopyTo(dest.sceneDefs); src.itemDefs.CopyTo(dest.itemDefs); src.itemTierDefs.CopyTo(dest.itemTierDefs); src.itemRelationshipProviders.CopyTo(dest.itemRelationshipProviders); src.equipmentDefs.CopyTo(dest.equipmentDefs); src.buffDefs.CopyTo(dest.buffDefs); src.eliteDefs.CopyTo(dest.eliteDefs); src.unlockableDefs.CopyTo(dest.unlockableDefs); src.survivorDefs.CopyTo(dest.survivorDefs); src.artifactDefs.CopyTo(dest.artifactDefs); src.effectDefs.CopyTo(dest.effectDefs); src.surfaceDefs.CopyTo(dest.surfaceDefs); src.networkSoundEventDefs.CopyTo(dest.networkSoundEventDefs); src.musicTrackDefs.CopyTo(dest.musicTrackDefs); src.gameEndingDefs.CopyTo(dest.gameEndingDefs); src.entityStateConfigurations.CopyTo(dest.entityStateConfigurations); src.expansionDefs.CopyTo(dest.expansionDefs); src.entitlementDefs.CopyTo(dest.entitlementDefs); src.miscPickupDefs.CopyTo(dest.miscPickupDefs); src.entityStateTypes.CopyTo(dest.entityStateTypes); } public static bool ValueEquals([CanBeNull] ContentPack a, [CanBeNull] ContentPack b) { if (a == null != (b == null)) { return false; } if (a == null) { return true; } if (!a.identifier.Equals(b.identifier, StringComparison.Ordinal)) { return false; } if (a.bodyPrefabs.Equals(b.bodyPrefabs) && a.masterPrefabs.Equals(b.masterPrefabs) && a.projectilePrefabs.Equals(b.projectilePrefabs) && a.gameModePrefabs.Equals(b.gameModePrefabs) && a.networkedObjectPrefabs.Equals(b.networkedObjectPrefabs) && a.skillDefs.Equals(b.skillDefs) && a.skillFamilies.Equals(b.skillFamilies) && a.sceneDefs.Equals(b.sceneDefs) && a.itemDefs.Equals(b.itemDefs) && a.itemTierDefs.Equals(b.itemTierDefs) && a.itemRelationshipProviders.Equals(b.itemRelationshipProviders) && a.equipmentDefs.Equals(b.equipmentDefs) && a.buffDefs.Equals(b.buffDefs) && a.eliteDefs.Equals(b.eliteDefs) && a.unlockableDefs.Equals(b.unlockableDefs) && a.survivorDefs.Equals(b.survivorDefs) && a.artifactDefs.Equals(b.artifactDefs) && a.effectDefs.Equals(b.effectDefs) && a.surfaceDefs.Equals(b.surfaceDefs) && a.networkSoundEventDefs.Equals(b.networkSoundEventDefs) && a.musicTrackDefs.Equals(b.musicTrackDefs) && a.gameEndingDefs.Equals(b.gameEndingDefs) && a.entityStateConfigurations.Equals(b.entityStateConfigurations) && a.entityStateTypes.Equals(b.entityStateTypes) && a.expansionDefs.Equals(b.expansionDefs) && a.entitlementDefs.Equals(b.entitlementDefs)) { return a.miscPickupDefs.Equals(b.miscPickupDefs); } return false; } private NamedAssetCollection FindAssetCollection(string collectionName) { return collectionName switch { "bodyPrefabs" => bodyPrefabs, "masterPrefabs" => masterPrefabs, "projectilePrefabs" => projectilePrefabs, "gameModePrefabs" => gameModePrefabs, "networkedObjectPrefabs" => networkedObjectPrefabs, "skillDefs" => skillDefs, "skillFamilies" => skillFamilies, "sceneDefs" => sceneDefs, "itemDefs" => itemDefs, "itemTierDefs" => itemTierDefs, "itemRelationshipProviders" => itemRelationshipProviders, "itemRelationshipTypes" => itemRelationshipTypes, "equipmentDefs" => equipmentDefs, "buffDefs" => buffDefs, "eliteDefs" => eliteDefs, "unlockableDefs" => unlockableDefs, "survivorDefs" => survivorDefs, "artifactDefs" => artifactDefs, "effectDefs" => effectDefs, "surfaceDefs" => surfaceDefs, "networkSoundEventDefs" => networkSoundEventDefs, "musicTrackDefs" => musicTrackDefs, "gameEndingDefs" => gameEndingDefs, "entityStateConfigurations" => entityStateConfigurations, "expansionDefs" => expansionDefs, "entitlementDefs" => entitlementDefs, "miscPickupDefs" => miscPickupDefs, _ => null, }; } public bool FindAsset(string collectionName, string assetName, out object result) { NamedAssetCollection namedAssetCollection = FindAssetCollection(collectionName); if (namedAssetCollection != null) { return namedAssetCollection.Find(assetName, out result); } result = null; return false; } }