Skip to content

Commit

Permalink
Updated ContentManagement systems to SurvivorsOfTheVoid (#341)
Browse files Browse the repository at this point in the history
* ArtifactCodeAPI changes

* Added hide in inspector attribute to ArtifactCompounds list

* Added a header with the constant that says how to find a list of accepted vanilla compound values-

* Added R2API Content Manager

* Removed comments, added logger messages, modified UnlockableAPI.

* Cleaned code.

* Fixed typo and version issue

* Added check to ensure there isnt an asset with whitespace, empty, or null as its name

* Made LoadROR2ContentEarly public, Added Public methods to R2APIContentManager

* Added missing documentation.

* Made it so ContentPacks can opt out from r2api loading the pack automatically.

* code cleanup

* Moved content related classes to R2APIContentManagment, fixed typos and issues.

* Fixed silent letter typo

* Marked a bunch of classes & methods as obsolete

* fixed another "entires" typo

* Added ContentAdditionHelpers

Also removed AddContent() and AddentityState() from R2APIContentManager

* Added missing documentation

* Added CatalogBlockers

* updated obsolete messages to redirect to the ContentAdditionHelpers

* Moved 3.x changelogs to archived, Added my PR to the readme

* Security Updates to Content Management

* cleanup

* Revert "cleanup"

This reverts commit a7674b5.

* Revert "Security Updates to Content Management"

This reverts commit a6ecccd.

* Updated ContentManagement system to SurvivorsOfTheVoid

* Cleanup

* updated csproj with newest NuGet packages

* Fixed missing references

* Delete MMHOOK_Assembly-CSharp.dll

* Fixed dumb csproj file
  • Loading branch information
Nebby1999 authored Mar 2, 2022
1 parent 7f4753a commit 423a6b3
Show file tree
Hide file tree
Showing 8 changed files with 478 additions and 75 deletions.
55 changes: 51 additions & 4 deletions R2API/ContentManagement/CatalogBlockers.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using EntityStates;
using RoR2;
using RoR2.EntitlementManagement;
using RoR2.ExpansionManagement;
using RoR2.Projectile;
using RoR2.Skills;
using System;
Expand All @@ -19,6 +21,9 @@ internal static class CatalogBlockers {
{typeof(SkillFamily), true },
{typeof(SceneDef), true },
{typeof(ItemDef), true },
{typeof(ItemTierDef), true },
{typeof(ItemRelationshipProvider), true },
{typeof(ItemRelationshipType), true },
{typeof(EquipmentDef), true },
{typeof(BuffDef), true },
{typeof(EliteDef), true },
Expand All @@ -31,6 +36,9 @@ internal static class CatalogBlockers {
{typeof(GameEndingDef), true },
{typeof(EntityStateConfiguration), true },
{typeof(EntityState), true },
{typeof(ExpansionDef), true },
{typeof(EntitlementDef), true },
{typeof(MiscPickupDef), true }

//The rest are catalogs that arent added by scriptable objects or game objects yet.
};
Expand All @@ -57,49 +65,88 @@ private static void SetAvailability<T>(bool availability) {
#region CatalogBlocker Methods
[SystemInitializer(typeof(BodyCatalog))]
private static void BlockBodies() => SetAvailability<CharacterBody>(false);

[SystemInitializer(typeof(MasterCatalog))]
private static void BlockMasters() => SetAvailability<CharacterMaster>(false);

[SystemInitializer(typeof(ProjectileCatalog))]
private static void BlockProjectiles() => SetAvailability<ProjectileController>(false);

[SystemInitializer(typeof(GameModeCatalog))]
private static void BlockGameModes() => SetAvailability<Run>(false);
[SystemInitializer(typeof(RoR2.Networking.GameNetworkManager))]

[SystemInitializer(typeof(RoR2.Networking.NetworkManagerSystem))]
private static void BlockNetworkedPrefabs() => SetAvailability<NetworkIdentity>(false);
[SystemInitializer(typeof(EffectCatalog))]
private static void BlockEffects() => SetAvailability<EffectComponent>(false);

[SystemInitializer(typeof(SkillCatalog))]
private static void BlockSkills() => SetAvailability<SkillDef>(false);

[SystemInitializer(typeof(SkillCatalog))]
private static void BlockSkillFamilies() => SetAvailability<SkillFamily>(false);

[SystemInitializer(typeof(SceneCatalog))]
private static void BlockScenes() => SetAvailability<SceneDef>(false);

[SystemInitializer(typeof(ItemCatalog))]
private static void BlockItems() => SetAvailability<ItemDef>(false);

[SystemInitializer(typeof(ItemTierCatalog))]
private static void BlockItemTiers() => SetAvailability<ItemTierDef>(false);

[SystemInitializer(typeof(ItemCatalog))]
private static void BlockItemRelationshipProviders() => SetAvailability<ItemRelationshipProvider>(false);

[SystemInitializer(typeof(ItemCatalog))]
private static void BlockItemRelationshipTypes() => SetAvailability<ItemRelationshipType>(false);

[SystemInitializer(typeof(EquipmentCatalog))]
private static void BlockEquipments() => SetAvailability<EquipmentDef>(false);

[SystemInitializer(typeof(BuffCatalog))]
private static void BlockBuffs() => SetAvailability<BuffDef>(false);

[SystemInitializer(typeof(EliteCatalog))]
private static void BlockElites() => SetAvailability<EliteDef>(false);

[SystemInitializer(typeof(UnlockableCatalog))]
private static void BlockUnlockables() => SetAvailability<UnlockableDef>(false);

[SystemInitializer(typeof(SurvivorCatalog))]
private static void BlockSurvivors() => SetAvailability<SurvivorDef>(false);

[SystemInitializer(typeof(ArtifactCatalog))]
private static void BlockArtifacts() => SetAvailability<ArtifactDef>(false);

[SystemInitializer(typeof(EffectCatalog))]
private static void BlockEffects() => SetAvailability<EffectComponent>(false);

[SystemInitializer(typeof(SurfaceDefCatalog))]
private static void BlockSurfaceDefs() => SetAvailability<SurfaceDef>(false);

[SystemInitializer(typeof(RoR2.Audio.NetworkSoundEventCatalog))]
private static void BlockNetworkSoundEvent() => SetAvailability<NetworkSoundEventDef>(false);

[SystemInitializer(typeof(MusicTrackCatalog))]
private static void BlockMusicTracks() => SetAvailability<MusicTrackDef>(false);

[SystemInitializer(typeof(GameEndingCatalog))]
private static void BlockGameEndings() => SetAvailability<GameEndingDef>(false);

[SystemInitializer(typeof(EntityStateCatalog))]
private static void BlockEntityStateConfigurations() => SetAvailability<EntityStateConfiguration>(false);

[SystemInitializer(typeof(ExpansionCatalog))]
private static void BlockExpansionDefs() => SetAvailability<ExpansionDef>(false);

[SystemInitializer(typeof(EntitlementCatalog))]
private static void BlockEntitlementDefs() => SetAvailability<EntitlementDef>(false);

[SystemInitializer(typeof(MiscPickupCatalog))]
private static void BlockMiscPickupDefs() => SetAvailability<MiscPickupDef>(false);

[SystemInitializer(typeof(EntityStateCatalog))]
private static void BlockEntityStates() => SetAvailability<EntityState>(false);

#endregion
//The rest are catalogs that arent added by scriptable objects or game objects yet.
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using EntityStates;
using R2API.ContentManagement;
using RoR2;
using RoR2.EntitlementManagement;
using RoR2.ExpansionManagement;
using RoR2.Projectile;
using RoR2.Skills;
using System;
Expand All @@ -9,11 +12,12 @@
using UnityEngine;
using UnityEngine.Networking;

namespace R2API.ContentManagement {
namespace R2API {
/// <summary>
/// Class for adding Content Assets to your Mod's ContentPack.
/// </summary>
public static class ContentAdditionHelpers {
public static class ContentAddition {

#region Add Prefab Methods
/// <summary>
/// Adds a BodyPrefab to your Mod's ContentPack
Expand Down Expand Up @@ -143,6 +147,9 @@ public static bool AddEffect(GameObject effectPrefab) {
RejectContent(effectPrefab, asm, "EffectPrefab", "but the EffectCatalog has already initialized!");
return false;
}
#endregion

#region Add Scriptable Methods
/// <summary>
/// Adds a SkillDef to your Mod's ContentPack
/// <para>SkillDef Requires a valid activationState</para>
Expand Down Expand Up @@ -213,14 +220,63 @@ public static bool AddSceneDef(SceneDef sceneDef) {
public static bool AddItemDef(ItemDef itemDef) {
var asm = Assembly.GetCallingAssembly();
if (CatalogBlockers.GetAvailability<ItemDef>()) {
R2API.Logger.LogInfo($"Assembly {asm.GetName().Name} is adding an {itemDef} via {nameof(ContentAdditionHelpers)}.{nameof(AddItemDef)}()" +
R2API.Logger.LogInfo($"Assembly {asm.GetName().Name} is adding an {itemDef} via {nameof(ContentAddition)}.{nameof(AddItemDef)}()" +
$"The assembly should ideally add them via {nameof(ItemAPI)} so that they can use ItemAPI's IDRS systems, adding anyways.");
ItemAPI.Add(new CustomItem(itemDef, Array.Empty<ItemDisplayRule>()));
return true;
}
RejectContent(itemDef, asm, "ItemDef", "but the ItemCatalog has already initialized!");
return false;
}

/// <summary>
/// Adds an ItemTierDef to your Mod's ContentPack
/// </summary>
/// <param name="itemTierDef">The ItemTierDef to add</param>
/// <returns>True if valid and added, false if one of the requirements is not met</returns>
public static bool AddItemTierDef(ItemTierDef itemTierDef) {
//Todo: finds what makes an itemTierDef invalid
var asm = Assembly.GetCallingAssembly();
if (CatalogBlockers.GetAvailability<ItemTierDef>()) {
R2APIContentManager.HandleContentAddition(asm, itemTierDef);
return true;
}
RejectContent(itemTierDef, asm, "ItemTierDef", "but the ItemTierCatalog has already initialized!");
return false;
}

/// <summary>
/// Adds an ItemRelationshipProvider to your Mod's ContentPack
/// </summary>
/// <param name="itemRelationshipProvider">The ItemRelationshipProvider to add</param>
/// <returns>True if valid and added, false if one of the requirements is not met</returns>
public static bool AddItemRelationshipProvider(ItemRelationshipProvider itemRelationshipProvider) {
//Todo: Find what makes an ItemRelationshipProvider invalid
var asm = Assembly.GetCallingAssembly();
if (CatalogBlockers.GetAvailability<ItemRelationshipProvider>()) {
R2APIContentManager.HandleContentAddition(asm, itemRelationshipProvider);
return true;
}
RejectContent(itemRelationshipProvider, asm, "ItemRelationshipProvider", "but the ItemCatalog has already initialized!");
return false;
}

/// <summary>
/// Adds an ItemRelationshipType to your Mod's ContentPack
/// </summary>
/// <param name="itemRelationshipType">The ItemRelationshipType to add</param>
/// <returns>True if valid and added, false if one of the requirements is not met</returns>
public static bool AddItemRelationshipType(ItemRelationshipType itemRelationshipType) {
//Todo: Find what makes an ItemRelationshipType invalid
var asm = Assembly.GetCallingAssembly();
if (CatalogBlockers.GetAvailability<ItemRelationshipType>()) {
R2APIContentManager.HandleContentAddition(asm, itemRelationshipType);
return true;
}
RejectContent(itemRelationshipType, asm, "ItemRelationshipType", "but the ItemCatalog has already initialized!");
return false;
}

//EquipmentDefs should be added by ItemAPI, but this method is here purely for completion sake.
/// <summary>
/// Adds an EquipmentDef to your Mod's ContentPack
Expand All @@ -231,7 +287,7 @@ public static bool AddItemDef(ItemDef itemDef) {
public static bool AddEquipmentDef(EquipmentDef equipmentDef) {
var asm = Assembly.GetCallingAssembly();
if (CatalogBlockers.GetAvailability<EquipmentDef>()) {
R2API.Logger.LogInfo($"Assembly {asm.GetName().Name} is adding an {equipmentDef} via {nameof(ContentAdditionHelpers)}.{nameof(AddEquipmentDef)}()" +
R2API.Logger.LogInfo($"Assembly {asm.GetName().Name} is adding an {equipmentDef} via {nameof(ContentAddition)}.{nameof(AddEquipmentDef)}()" +
$"The assembly should ideally add them via {nameof(ItemAPI)} so that they can use ItemAPI's IDRS systems, adding anyways.");
ItemAPI.Add(new CustomEquipment(equipmentDef, Array.Empty<ItemDisplayRule>()));
return true;
Expand Down Expand Up @@ -271,7 +327,7 @@ public static bool AddBuffDef(BuffDef buffDef) {
public static bool AddEliteDef(EliteDef eliteDef) {
var asm = Assembly.GetCallingAssembly();
if (CatalogBlockers.GetAvailability<EliteDef>()) {
R2API.Logger.LogInfo($"Assembly {asm.GetName().Name} is adding an {eliteDef} via {nameof(ContentAdditionHelpers)}.{nameof(AddEliteDef)}()" +
R2API.Logger.LogInfo($"Assembly {asm.GetName().Name} is adding an {eliteDef} via {nameof(ContentAddition)}.{nameof(AddEliteDef)}()" +
$"The assembly should ideally add them via {nameof(EliteAPI)} so that they can use EliteAPI's elite tier systems, adding the elite anyways as Tier1 elite.");
EliteAPI.Add(new CustomElite(eliteDef, new List<CombatDirector.EliteTierDef> { EliteAPI.VanillaEliteTiers[1], EliteAPI.VanillaEliteTiers[2] }));
return true;
Expand Down Expand Up @@ -435,6 +491,54 @@ public static bool AddEntityStateConfiguration(EntityStateConfiguration entitySt
return false;

}

/// <summary>
/// Adds an ExpansionDef to your Mod's ContentPack
/// </summary>
/// <param name="expansionDef">The ExpansionDef to Add</param>
/// <returns>true if valid and added, false if one of the requirements is not met</returns>
public static bool AddExpansionDef(ExpansionDef expansionDef) {
//Todo: Find what makes an ExpansionDef invalid
var asm = Assembly.GetCallingAssembly();
if (CatalogBlockers.GetAvailability<ExpansionDef>()) {
R2APIContentManager.HandleContentAddition(asm, expansionDef);
return true;
}
RejectContent(expansionDef, asm, "ExpansionDef", "But the ExpansionCatalog has already initialized!");
return false;
}

/// <summary>
/// Adds an EntitlementDef to your Mod's ContentPack
/// </summary>
/// <param name="entitlementDef">The EntitlementDef to Add</param>
/// <returns>true if valid and added, false if one of the requirements is not met</returns>
public static bool AddEntitlementDef(EntitlementDef entitlementDef) {
//Todo: Find what makes an EntitlementDef invalid
var asm = Assembly.GetCallingAssembly();
if (CatalogBlockers.GetAvailability<EntitlementDef>()) {
R2APIContentManager.HandleContentAddition(asm, entitlementDef);
return true;
}
RejectContent(entitlementDef, asm, "EntitlementDef", "But the EntitlementCatalog has already initialized!");
return false;
}

/// <summary>
/// Adds a MiscPickupDef to your Mod's ContentPack
/// </summary>
/// <param name="miscPickupDef">The MiscPickupDef to Add</param>
/// <returns>true if valid and added, false if one of the requirements is not met</returns>
public static bool AddMiscPickupDef(MiscPickupDef miscPickupDef) {
var asm = Assembly.GetCallingAssembly();
if (CatalogBlockers.GetAvailability<MiscPickupDef>()) {
R2APIContentManager.HandleContentAddition(asm, miscPickupDef);
return true;
}
RejectContent(miscPickupDef, asm, "MiscPickupDef", "But the MiscPickupCatalog has already initailized!");
return false;
}

/// <summary>
/// Adds an EntitySateType to your Mod's ContentPack
/// <para>State Type cannot be abstract</para>
Expand Down
Loading

0 comments on commit 423a6b3

Please sign in to comment.