Skip to content

Commit

Permalink
Huge Feature sort & rearranging
Browse files Browse the repository at this point in the history
Sorted most features into new groups
FeatureGroups can now have additional data

FeaturesAPI:
- Removed Store and Retrieve in FeaturesAPI
- Added Is.A5 and Is.A5OrLater
- PlaceSettingsInSubMenu marked obsolete
- Settings get placed into submenus by default now
  • Loading branch information
AuriRex committed Jun 20, 2023
1 parent 5453ca8 commit 55ad847
Show file tree
Hide file tree
Showing 60 changed files with 598 additions and 624 deletions.
32 changes: 10 additions & 22 deletions TheArchive.Core/Core/FeaturesAPI/Feature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public abstract class Feature
public bool IsHidden => FeatureInternal.HideInModSettings;
public bool BelongsToGroup => Group != null;
public bool HasAdditionalSettings => FeatureInternal.HasAdditionalSettings;
public bool AllAdditionalSettingsAreHidden => FeatureInternal.AllAdditionalSettingsAreHidden;
public IEnumerable<FeatureSettingsHelper> SettingsHelpers => FeatureInternal.Settings;
public void RequestRestart() => FeatureManager.RequestRestart(this);
public void RevokeRestartRequest() => FeatureManager.RevokeRestartRequest(this);
Expand Down Expand Up @@ -89,10 +90,13 @@ public abstract class Feature
/// </summary>
public virtual bool RequiresUnityAudioListener => false;

[Obsolete($"Remove or use {nameof(InlineSettingsIntoParentMenu)} instead if inlining is intended")]
public virtual bool PlaceSettingsInSubMenu => false;

/// <summary>
/// If this <see cref="Feature"/>s settings should be put into a sub menu inside of the Mod Settings menu
/// If this <see cref="Feature"/>s settings should be put inside of íts parent menu in the Mod Settings menu
/// </summary>
public virtual bool PlaceSettingsInSubMenu => false;
public virtual bool InlineSettingsIntoParentMenu => false;

/// <summary>
/// Called once upon application start before <see cref="Init"/> and before any patches have been loaded
Expand Down Expand Up @@ -217,24 +221,6 @@ public virtual void OnQuit()

}

/// <summary>
/// Store a value
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="obj"></param>
/// <returns>true if the value has been stored successfully</returns>
public bool TryStore<T>(string key, T obj) => FeatureInternal.Store(key, obj);

/// <summary>
/// Retrieve a stored value via a key
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns>true if a value has been returned</returns>
public bool TryRetrieve<T>(string key, out T value) => FeatureInternal.Retrieve(key, out value);

internal FeatureInternal FeatureInternal { get; set; }
public static bool IsPlayingModded => ArchiveMod.IsPlayingModded;
public static bool DevMode => ArchiveMod.Settings.FeatureDevMode;
Expand Down Expand Up @@ -271,6 +257,8 @@ internal static void SetupIs()
Is.A3OrLater = BuildInfo.Rundown.IsIncludedIn(RundownFlags.RundownAltThree.ToLatest());
Is.A4 = BuildInfo.Rundown.IsIncludedIn(RundownFlags.RundownAltFour);
Is.A4OrLater = BuildInfo.Rundown.IsIncludedIn(RundownFlags.RundownAltFour.ToLatest());
Is.A5 = BuildInfo.Rundown.IsIncludedIn(RundownFlags.RundownAltFive);
Is.A5OrLater = BuildInfo.Rundown.IsIncludedIn(RundownFlags.RundownAltFive.ToLatest());
}

/// <summary>
Expand Down Expand Up @@ -300,8 +288,8 @@ public static class Is
public static bool A3OrLater { get; internal set; }
public static bool A4 { get; internal set; }
public static bool A4OrLater { get; internal set; }
public static bool A5 { get; internal set; }
public static bool A5OrLater { get; internal set; }
}


}
}
9 changes: 6 additions & 3 deletions TheArchive.Core/Core/FeaturesAPI/FeatureGroups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ public override string ToString()
}

public static Group Accessibility { get; private set; } = Group.GetOrCreate("Accessibility");
public static Group Backport { get; private set; } = Group.GetOrCreate("Backport");
public static Group Cosmetic { get; private set; } = Group.GetOrCreate("Cosmetic");
public static Group Dev { get; private set; } = Group.GetOrCreate("Developer");
public static Group Fixes { get; private set; } = Group.GetOrCreate("Fixes");
public static Group Hud { get; private set; } = Group.GetOrCreate("HUD / UI");
public static Group LocalProgression { get; private set; } = Group.GetOrCreate("Local Progression"); // , group => group.InlineSettings = true
public static Group Special { get; private set; } = Group.GetOrCreate("Misc");
public static Group Dev { get; private set; } = Group.GetOrCreate("Developer");
public static Group Backport { get; private set; } = Group.GetOrCreate("Backport");
public static Group Presence { get; private set; } = Group.GetOrCreate("Discord / Steam Presence");
public static Group Security { get; private set; } = Group.GetOrCreate("Security / Anti Cheat");
public static Group QualityOfLife { get; private set; } = Group.GetOrCreate("Quality of Life");
public static Group LocalProgression { get; private set; } = Group.GetOrCreate("Local Progression"); // , group => group.InlineSettings = true
}
}
4 changes: 4 additions & 0 deletions TheArchive.Core/Core/FeaturesAPI/FeatureInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal class FeatureInternal
internal bool AutomatedFeature { get; private set; }
internal bool DisableModSettingsButton { get; private set; }
internal bool HasAdditionalSettings => _settingsHelpers.Count > 0;
internal bool AllAdditionalSettingsAreHidden { get; private set; } = true;
internal bool InitialEnabledState { get; private set; } = false;
internal IEnumerable<FeatureSettingsHelper> Settings => _settingsHelpers;
internal Utils.RundownFlags Rundowns { get; private set; } = Utils.RundownFlags.None;
Expand Down Expand Up @@ -499,6 +500,9 @@ internal void LoadFeatureSettings()
var configInstance = LocalFiles.LoadFeatureConfig($"{_feature.Identifier}_{settingsHelper.PropertyName}", settingsHelper.SettingType);

settingsHelper.SetupViaFeatureInstance(configInstance);

if (settingsHelper.Settings.Any(fs => !fs.HideInModSettings))
AllAdditionalSettingsAreHidden = false;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using TheArchive.Core.Attributes;
using TheArchive.Core.FeaturesAPI;
using TheArchive.Features.Special;
using TheArchive.Features.Dev;
using static TheArchive.Utilities.Utils;

namespace TheArchive.Features.Accessibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class DynamicVolumeOverride : Feature

public override string Description => "Lower the game volume during loud sections:\n- game intro\n- elevator drop";

public override bool PlaceSettingsInSubMenu => true;

public static bool IsOverrideActive { get; private set; } = false;
public static bool IsLerpActive { get; private set; } = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ internal class GlassLiquidOverride : Feature

public override string Description => "Adjust the games \"Glass Liquid System\"\nThe thing that renders the blood splatters etc on your visor.";

public override bool PlaceSettingsInSubMenu => true;

[FeatureConfig]
public static GlassLiquidOverrideSettings Settings { get; set; }

Expand Down
2 changes: 0 additions & 2 deletions TheArchive.IL2CPP/Features/Accessibility/Nickname.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class Nickname : Feature

public override string Description => "Nickname related settings.";

public override bool PlaceSettingsInSubMenu => true;

public class NicknameSettings
{
[FSDescription($"Modes explained using <#C21F4E>this</color> as the character color and <#404>this</color> as the custom color:\n\n<#E4A818>{nameof(NicknameMode.Normal)}</color>:\n <#C21F4E>> > Nickname</color>: Some chat message here.\n<#E4A818>{nameof(NicknameMode.Color)}</color>:\n <#C21F4E>> > <#404>Nickname</color>: Some chat message here.\n</color><#E4A818>{nameof(NicknameMode.TerminatedColor)}</color>:\n <#C21F4E>> > <#404>Nickname</color></color>: Some chat message here.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class PlayerColorOverride : Feature

public override string Description => "Override the built in player colors.";

public override bool PlaceSettingsInSubMenu => true;

public override bool SkipInitialOnEnable => true;

[FeatureConfig]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public class SentryMarkerTweaks : Feature

public override string Description => "Add hud markers onto placed down sentry guns and tweak how those are shown.";

public override bool PlaceSettingsInSubMenu => true;

public override bool SkipInitialOnEnable => true;

[FeatureConfig]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
using TheArchive.Core.FeaturesAPI;
using static TheArchive.Utilities.Utils;

namespace TheArchive.Features.QoL
namespace TheArchive.Features.Backport
{
[EnableFeatureByDefault]
[RundownConstraint(RundownFlags.RundownOne, RundownFlags.RundownFive)]
internal class UnreadyButtonPatches : Feature
{
public override string Name => "Unready Button";

public override string Group => FeatureGroups.QualityOfLife;
public override string Group => FeatureGroups.Backport;

public override string Description => "Allows you to unready in the lobby.";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@
using TheArchive.Utilities;
using UnityEngine;

namespace TheArchive.Features.Special
namespace TheArchive.Features.Cosmetic
{
[RundownConstraint(Utils.RundownFlags.RundownSix, Utils.RundownFlags.Latest)]
public class BotCustomization : Feature
{
public override string Name => "Bot Customization";

public override string Group => FeatureGroups.Special;
public override string Group => FeatureGroups.Cosmetic;

public override string Description => "Customize your bots!";

public override bool PlaceSettingsInSubMenu => true;

public override bool SkipInitialOnEnable => true;

public new static IArchiveLogger FeatureLogger { get; set; }
Expand Down Expand Up @@ -53,7 +51,7 @@ public class NamedBotsSettings

public VanitySettings GetVanity(int characterIndex)
{
switch(characterIndex % 4)
switch (characterIndex % 4)
{
default:
case 0:
Expand All @@ -78,7 +76,7 @@ public class VanitySettings
#if IL2CPP
public uint Get(ClothesType type)
{
switch(type)
switch (type)
{
default:
return 0;
Expand Down Expand Up @@ -146,7 +144,7 @@ public static void SetAllBotNamesAndVanity(bool setToDefault = false)
if (!SNet.IsInLobby)
return;

foreach(var slot in SNet.Slots.PlayerSlots)
foreach (var slot in SNet.Slots.PlayerSlots)
{
var player = slot.player;

Expand Down Expand Up @@ -186,7 +184,7 @@ public static void SetBotName(PlayerAgent agent, bool setToDefault = false)
break;
}

if(agent.Owner.NickName != name)
if (agent.Owner.NickName != name)
agent.Owner.NickName = name;
}

Expand All @@ -211,7 +209,7 @@ public static void SetVanity(PlayerAgent agent, bool setToDefault = false)

var vanity = Settings.GetVanity(agent.Owner.CharacterIndex);

foreach(var type in _vanity)
foreach (var type in _vanity)
{
// ItemID 0 is considered default
backpack.EquipVanityItem(type, setToDefault ? 0 : vanity.Get(type));
Expand All @@ -229,7 +227,7 @@ public static GameObject GetOrCreateClothesButton(CM_PlayerLobbyBar playerLobbyB

if (newClothesButton == null)
{
newClothesButton = GameObject.Instantiate(playerLobbyBar.m_clothesButton.gameObject);
newClothesButton = UnityEngine.Object.Instantiate(playerLobbyBar.m_clothesButton.gameObject);
newClothesButton.transform.SetParent(playerLobbyBar.m_clothesButton.transform.parent);
newClothesButton.name = CLOTHES_BUTTON_NAME;
newClothesButton.transform.position = playerLobbyBar.m_clothesButton.transform.position + new Vector3(0, 100);
Expand Down Expand Up @@ -273,7 +271,7 @@ public static void Postfix(CM_PlayerLobbyBar __instance, SNet_Player player)
}
}

#region cursed_workaround
#region cursed_workaround
public static SNet_Player BotPlayerToSync { get; set; } = null;
public static bool WantsToSyncBotPlayer { get; private set; } = false;

Expand Down Expand Up @@ -340,7 +338,7 @@ public static void WithBotAsLocalInput(SNet_Player botPlayer, Action action)
WantsToSyncBotPlayer = false;
}

#endregion cursed_workaround
#endregion cursed_workaround

[ArchivePatch(typeof(PlayerBackpackManager), nameof(PlayerBackpackManager.ForceSyncBotInventory))]
public static class PlayerBackpackManager_ForceSyncBotInventory_Patch
Expand Down Expand Up @@ -376,7 +374,7 @@ public static unsafe void ForceSyncBotInventoryWithVanity(SNet_Player botPlayer,
return;

// This would work instead of the cursed patch bs above if the game would properly read (& send) the values set below ...

/*PlayerBackpack backpack = PlayerBackpackManager.GetBackpack(botPlayer);
pInventorySync data = new pInventorySync(LoaderWrapper.ClassInjector.DerivedConstructorPointer<pInventorySync>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@
using IL2ColGen = System.Collections.Generic;
#endif

namespace TheArchive.Features.Special
namespace TheArchive.Features.Cosmetic
{
internal class CustomWeaponFOV : Feature
{
public override string Name => "Weapon FOV Adjustments";

public override string Group => FeatureGroups.Special;
public override string Group => FeatureGroups.Cosmetic;

public override string Description => "Adjust the Field of View of weapons, consumables and big items.";

public override bool PlaceSettingsInSubMenu => true;

public new static IArchiveLogger FeatureLogger { get; set; }

private static Dictionary<string, CustomItemFPSSettingsEntry> _defaultItemFPSSettings;
Expand All @@ -33,12 +31,12 @@ internal class CustomWeaponFOV : Feature

public override void OnEnable()
{

if (DataBlocksReady)
{
SetupDefaultData();
SetCustomValues();
}
}
}

public override void OnDisable()
Expand Down Expand Up @@ -139,7 +137,7 @@ private void SetupDefaultData()
}
}

foreach(var defaultSettings in _defaultItemFPSSettings)
foreach (var defaultSettings in _defaultItemFPSSettings)
{
if (!Settings.ItemFPSSettings.ContainsKey(defaultSettings.Key))
{
Expand All @@ -152,7 +150,7 @@ public class WeaponFOVSettings
{
[FSDisplayName("Override Sights Settings")]
public bool IgnoreSightSettings { get; set; } = true;

[FSDisplayName("Item FPS Settings"), FSReadOnly(recursive: false)]
public Dictionary<string, CustomItemFPSSettingsEntry> ItemFPSSettings { get; set; } = new Dictionary<string, CustomItemFPSSettingsEntry>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
using TheArchive.Interfaces;
using static TheArchive.Utilities.Utils;

namespace TheArchive.Features.Special
namespace TheArchive.Features.Cosmetic
{
[RundownConstraint(RundownFlags.RundownSix, RundownFlags.Latest)]
public class EnableLegacyHammers : Feature
{
public override string Name => "Enable old Hammers";

public override string Group => FeatureGroups.Special;
public override string Group => FeatureGroups.Cosmetic;

public override string Description => "Re-enable the pre-R6 Hammers:\nMaul, Gavel, Sledge and Mallet";

Expand All @@ -38,11 +38,11 @@ public override void OnEnable()

public static void Transform(List<PlayerOfflineGearDataBlock> allPlayerOfflineGearDataBlocks)
{
if(Is.A2OrLater)
if (Is.A2OrLater)
{
// The OG hammers have been removed from the DataBlocks.

foreach( var kvp in _oldHammers)
foreach (var kvp in _oldHammers)
{
FeatureLogger.Debug($"Adding old hammer '{kvp.Key}' as new block ...");
PlayerOfflineGearDataBlock.AddBlock(new PlayerOfflineGearDataBlock
Expand All @@ -59,9 +59,9 @@ public static void Transform(List<PlayerOfflineGearDataBlock> allPlayerOfflineGe

var blocksToEnable = _oldHammers.Keys.ToList();

foreach(var block in allPlayerOfflineGearDataBlocks)
foreach (var block in allPlayerOfflineGearDataBlocks)
{
if(blocksToEnable.Contains(block.name))
if (blocksToEnable.Contains(block.name))
{
FeatureLogger.Success($" > Enabling block: ID: {block.persistentID}, Name: '{block.name}'");
block.internalEnabled = true;
Expand Down
Loading

0 comments on commit 55ad847

Please sign in to comment.