diff --git a/SCHIZO/Creatures/Ermfish/ErmStack.cs b/SCHIZO/Creatures/Ermfish/ErmStack.cs index 3424c579..23bee26b 100644 --- a/SCHIZO/Creatures/Ermfish/ErmStack.cs +++ b/SCHIZO/Creatures/Ermfish/ErmStack.cs @@ -92,8 +92,8 @@ ErmStack FindNearest_TechType() { return PhysicsHelpers.ObjectsInRange(gameObject.transform.position, 20f) .OfTechType(selfTechType) - .OrderByDistanceTo(gameObject.transform.position) .SelectComponentInParent() + .OrderByDistanceTo(gameObject.transform.position) .FirstOrDefault(s => !s.nextSocket && s != this); } } @@ -140,7 +140,7 @@ public static void Disconnect(ErmStack node, bool plugSide = true) public bool Connect(ErmStack node, bool nodeIsPlug) => nodeIsPlug ? Connect(node, this) : Connect(this, node); public void Disconnect(bool plugSide = true) => Disconnect(this, plugSide); - public bool ShouldAttach(Carryable plug, CarryCreature socket) + public bool ShouldAttach(Carryable _, CarryCreature socket) { ErmStack socketStack = socket.GetComponent(); if (!socketStack) return true; diff --git a/SCHIZO/Events/Ermcon/Ermcon.cs b/SCHIZO/Events/Ermcon/Ermcon.cs index 98a37563..3cfc6ed2 100644 --- a/SCHIZO/Events/Ermcon/Ermcon.cs +++ b/SCHIZO/Events/Ermcon/Ermcon.cs @@ -33,8 +33,8 @@ public partial class Ermcon private void Start() { instance = this; - conMembers = new List(); - targets = new HashSet(); + conMembers = []; + targets = []; // let's not wait the whole cooldown on load _eventEndTime = -cooldown / 2; @@ -123,7 +123,7 @@ public override void StartEvent() return; } LOGGER.LogMessage($"The upcoming Ermcon will be visited by {totalAttendance} afficionados"); - conMembers.AddRange(erms.Take(totalAttendance)); + conMembers = erms.Take(totalAttendance).ToList(); conMembers.ForEach(erm => erm.enabled = true); _eventEndTime = Time.time + maxDuration; @@ -136,12 +136,10 @@ public override void EndEvent() targets.Clear(); foreach (ErmconAttendee ermEnthusiast in conMembers) { - if (!ermEnthusiast) continue; - ermEnthusiast.enabled = false; + if (ermEnthusiast) ermEnthusiast.enabled = false; } conMembers.Clear(); - _eventEndTime = Time.time; _isOccurring = false; base.EndEvent(); diff --git a/SCHIZO/Events/Ermcon/ErmconAttendee.cs b/SCHIZO/Events/Ermcon/ErmconAttendee.cs index 524166c6..5fa01f77 100644 --- a/SCHIZO/Events/Ermcon/ErmconAttendee.cs +++ b/SCHIZO/Events/Ermcon/ErmconAttendee.cs @@ -16,7 +16,7 @@ public partial class ErmconAttendee : IHandTarget new Keyframe(90f, 20f), new Keyframe(120f, 1000f) ); - private List<(HandTarget target, bool wasEnabled)> _otherHandTargets; + private List _disabledHandTargets; /// /// A value that increases the longer the creature is focused on one target.
@@ -68,8 +68,8 @@ public override void OnEnable() LogSelf($"enabled\npatience: {patience}"); creature.actions.Clear(); creature.actions.Add(this); - _otherHandTargets = GetComponents().Select(ht => (ht, ht.enabled)).ToList(); - _otherHandTargets.ForEach(pair => pair.target.enabled = false); + _disabledHandTargets = GetComponents().Where(ht => ht.enabled).ToList(); + _disabledHandTargets.ForEach(ht => ht.enabled = false); } public void OnDisable() @@ -79,7 +79,7 @@ public void OnDisable() _visited.Clear(); creature.ScanCreatureActions(); creature.GetComponent().LookForward(); - _otherHandTargets.ForEach(pair => pair.target.enabled = pair.wasEnabled); + _disabledHandTargets.ForEach(ht => ht.enabled = true); } public void OnTargetRemoved(GameObject removedBy) diff --git a/SCHIZO/Events/Ermcon/ErmconPatches.cs b/SCHIZO/Events/Ermcon/ErmconPatches.cs index b7d0358d..2ac893ee 100644 --- a/SCHIZO/Events/Ermcon/ErmconPatches.cs +++ b/SCHIZO/Events/Ermcon/ErmconPatches.cs @@ -11,7 +11,7 @@ namespace SCHIZO.Events.Ermcon; [HarmonyPatch] public static class ErmconPatches { - private static readonly MethodInfo GetComponentOfIHandTarget = AccessTools.Method(typeof(GameObject), nameof(GameObject.GetComponent), null, new[] { typeof(IHandTarget) }); + private static readonly MethodInfo GetComponentOfIHandTarget = AccessTools.Method(typeof(GameObject), nameof(GameObject.GetComponent), null, [typeof(IHandTarget)]); [HarmonyPatch(typeof(GUIHand), nameof(GUIHand.Send))] [HarmonyTranspiler] diff --git a/SCHIZO/Events/GameEvent.cs b/SCHIZO/Events/GameEvent.cs index df125bdb..fa33cb43 100644 --- a/SCHIZO/Events/GameEvent.cs +++ b/SCHIZO/Events/GameEvent.cs @@ -4,10 +4,10 @@ namespace SCHIZO.Events; public partial class GameEvent : IStoryGoalListener { - public record StoryGoals(GameEvent evt) + public readonly record struct StoryGoals(GameEvent evt) { - public string Unlock => $"{evt.Name}.UnlockedAutoStart"; - public string FirstTime => $"{evt.Name}.FirstTime"; + public readonly string Unlock => $"{evt.EventName}.UnlockedAutoStart"; + public readonly string FirstTime => $"{evt.EventName}.FirstTime"; } public abstract bool IsOccurring { get; } public bool IsFirstTime { get; private set; } = true; @@ -16,7 +16,7 @@ public record StoryGoals(GameEvent evt) protected string RequiredStoryGoal => RetargetHelpers.Pick(requiredStoryGoal_SN, requiredStoryGoal_BZ); protected bool IsUnlocked { get; private set; } public StoryGoals Goals { get; private set; } - public string Name => GetType().Name; + public string EventName => GetType().Name; protected void Awake() { @@ -24,20 +24,26 @@ protected void Awake() player = Player.main; StoryGoalManager.main.AddListener(this); - if (StoryGoalHelpers.IsCompleted(Goals.FirstTime)) IsFirstTime = false; } #region Unlock goals - // TODO: can/should this be improved? public void NotifyGoalComplete(string goal) { if (string.Equals(goal, RequiredStoryGoal, System.StringComparison.OrdinalIgnoreCase)) Unlock(); } - public void NotifyGoalReset(string key) => Lock(); + public void NotifyGoalReset(string goal) + { + if (string.Equals(goal, RequiredStoryGoal, System.StringComparison.OrdinalIgnoreCase)) + Lock(); + } - public void NotifyGoalsDeserialized() { } + public void NotifyGoalsDeserialized() + { + if (StoryGoalHelpers.IsCompleted(Goals.FirstTime)) IsFirstTime = false; + if (StoryGoalHelpers.IsCompleted(Goals.Unlock)) IsUnlocked = true; + } public void Unlock() { @@ -59,19 +65,19 @@ private void OnDestroy() public virtual void StartEvent() { - string firstTimeMsg = ""; + string msg = $"{EventName} started"; IsFirstTime = !StoryGoalHelpers.IsCompleted(Goals.FirstTime); if (IsFirstTime) { StoryGoalHelpers.Trigger(Goals.FirstTime); - firstTimeMsg = " (first time)"; + msg += " (first time)"; } - LOGGER.LogMessage($"{Name} started{firstTimeMsg}"); + LOGGER.LogMessage(msg); } public virtual void EndEvent() { - LOGGER.LogMessage($"{Name} ended"); + LOGGER.LogMessage($"{EventName} ended"); } /// diff --git a/SCHIZO/Events/GameEventsManager.cs b/SCHIZO/Events/GameEventsManager.cs index d327a528..5d82d844 100644 --- a/SCHIZO/Events/GameEventsManager.cs +++ b/SCHIZO/Events/GameEventsManager.cs @@ -25,24 +25,26 @@ private void Awake() { if (Instance) Destroy(Instance); Instance = this; + } + private void Start() + { gameObject.GetComponents(Events); } [ConsoleCommand("autoevents"), UsedImplicitly] - public static void OnConsoleCommand_autoevents(bool? action = null) + public static string OnConsoleCommand_autoevents(bool? arg = null) { - if (action == null) + if (arg is not { } value) { - MessageHelpers.WriteCommandOutput($"Events are currently {FormatAutoStart(AutoStart)}"); - return; + return $"Events are currently {FormatAutoStart(AutoStart)}"; } - AutoStart = action.Value; + AutoStart = value; - MessageHelpers.WriteCommandOutput($"Events are now {FormatAutoStart(action.Value)}"); + return MessageHelpers.GetCommandOutput($"Events are now {FormatAutoStart(arg.Value)}"); } -#if DEBUG +#if DEBUG_ERMCON public void Update() { if (!Input.GetKeyDown(KeyCode.LeftControl)) return; @@ -58,7 +60,7 @@ public void Update() [ConsoleCommand("event"), UsedImplicitly] public static string OnConsoleCommand_event(string eventName, bool start) { - GameEvent @event = Events.FirstOrDefault(e => e.Name.Equals(eventName, System.StringComparison.OrdinalIgnoreCase)); + GameEvent @event = Events.FirstOrDefault(e => e.EventName.Equals(eventName, System.StringComparison.OrdinalIgnoreCase)); if (!@event) return MessageHelpers.GetCommandOutput($"No event named '{eventName}'"); if (start) @event.StartEvent(); diff --git a/SCHIZO/Helpers/StaticHelpers.cs b/SCHIZO/Helpers/StaticHelpers.cs index ff3c836f..4e77acf4 100644 --- a/SCHIZO/Helpers/StaticHelpers.cs +++ b/SCHIZO/Helpers/StaticHelpers.cs @@ -64,7 +64,7 @@ private static bool TryGetCached(string name, out T value) private static void Cache(string fieldOrPropertyColonName) { string[] splits = fieldOrPropertyColonName.Split(':'); - Type type = AccessTools.TypeByName(splits[0]); + Type type = ReflectionCache.GetType(splits[0]); FieldInfo f = type.GetField(splits[1], BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); diff --git a/SCHIZO/HullPlates/HullPlatePrefab.cs b/SCHIZO/HullPlates/HullPlatePrefab.cs index 20dbe071..d1aa5cbf 100644 --- a/SCHIZO/HullPlates/HullPlatePrefab.cs +++ b/SCHIZO/HullPlates/HullPlatePrefab.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Diagnostics.CodeAnalysis; using Nautilus.Assets; using Nautilus.Assets.Gadgets; @@ -24,7 +24,7 @@ public HullPlatePrefab(HullPlate hullPlate, HullPlateLoader loader) : base(hullP if (!_hullPlate.deprecated) { - Texture2D overrideIcon = hullPlate.overrideIcon ! ?? hullPlate.texture; + Texture2D overrideIcon = hullPlate.overrideIcon !?? hullPlate.texture; overrideIcon = overrideIcon.Scale(177, 176).Translate(-21, -38).Crop(loader.hiddenIcon.width, loader.hiddenIcon.height); Texture2D newIcon = hullPlate.hidden ? loader.hiddenIcon : TextureHelpers.BlendAlpha(loader.hiddenIcon, overrideIcon); Info.WithIcon(ImageUtils.LoadSpriteFromTexture(newIcon)); diff --git a/SCHIZO/Jukebox/CustomJukeboxTrackPatches.BelowZero.cs b/SCHIZO/Jukebox/CustomJukeboxTrackPatches.BelowZero.cs index f26c20f7..cf980be6 100644 --- a/SCHIZO/Jukebox/CustomJukeboxTrackPatches.BelowZero.cs +++ b/SCHIZO/Jukebox/CustomJukeboxTrackPatches.BelowZero.cs @@ -23,6 +23,7 @@ static CustomJukeboxTrackPatches() { CoroutineHost.StartCoroutine(GetJukeboxDiskPrefab()); CoroutineHost.StartCoroutine(InitJukebox()); + SaveUtils.RegisterOnQuitEvent(() => CoroutineHost.StartCoroutine(InitJukebox())); } private static IEnumerator GetJukeboxDiskPrefab() { diff --git a/SCHIZO/Registering/ComponentAdder.cs b/SCHIZO/Registering/ComponentAdder.cs index fc8a020f..7dc10cc8 100644 --- a/SCHIZO/Registering/ComponentAdder.cs +++ b/SCHIZO/Registering/ComponentAdder.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using HarmonyLib; +using SCHIZO.Helpers; using UnityEngine; namespace SCHIZO.Registering; @@ -24,8 +25,8 @@ protected override void Register() return; } - Type targetType = AccessTools.TypeByName(typeName); - Type actualTargetType = _isBaseType ? AccessTools.TypeByName(targetTypeName) : targetType; + Type targetType = ReflectionCache.GetType(typeName); + Type actualTargetType = _isBaseType ? ReflectionCache.GetType(targetTypeName) : targetType; if (scanForExisting) { foreach (Component o in FindObjectsOfType(actualTargetType).Cast()) @@ -34,9 +35,8 @@ protected override void Register() } } - MethodInfo targetMethod = AccessTools.Method(targetType, methodName); - if (targetMethod == null) throw new MissingMethodException(typeName, methodName); - + MethodInfo targetMethod = AccessTools.Method(targetType, methodName) + ?? throw new MissingMethodException(typeName, methodName); Target target = CreateTarget(targetMethod, mode); Entry entry = new(actualTargetType, prefab); diff --git a/SCHIZO/Twitch/TwitchIntegration.cs b/SCHIZO/Twitch/TwitchIntegration.cs index dd4fc2af..486d9b60 100644 --- a/SCHIZO/Twitch/TwitchIntegration.cs +++ b/SCHIZO/Twitch/TwitchIntegration.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.Collections.Concurrent; +using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; using Nautilus.Commands; @@ -22,9 +23,11 @@ partial class TwitchIntegration private TwitchClient _client; private readonly ConcurrentQueue _msgQueue = new(); + private HashSet _allowedUsersSet; private void Awake() { + _allowedUsersSet = new(whitelistedUsers, StringComparer.OrdinalIgnoreCase); ClientOptions clientOptions = new() { MessagesAllowedInPeriod = 750, @@ -69,7 +72,7 @@ private void Client_OnMessageReceived(object _, OnMessageReceivedArgs evt) private bool IsUserWhitelisted(string username) { - return whitelistedUsers.Any(user => user.Equals(username, StringComparison.InvariantCultureIgnoreCase)); + return _allowedUsersSet.Contains(username); } private bool CheckPrefix(string message) @@ -79,7 +82,7 @@ private bool CheckPrefix(string message) private void FixedUpdate() { - if (_msgQueue.Count > 0 && _msgQueue.TryDequeue(out string message)) HandleMessage(message); + if (_msgQueue.TryDequeue(out string message)) HandleMessage(message); } private static void HandleMessage(string message) diff --git a/SCHIZO/_old/Creatures/Ermfish/ErmfishLoader.cs b/SCHIZO/_old/Creatures/Ermfish/ErmfishLoader.cs deleted file mode 100644 index c6664290..00000000 --- a/SCHIZO/_old/Creatures/Ermfish/ErmfishLoader.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Collections.Generic; -using ECCLibrary.Data; -using Nautilus.Handlers; -using SCHIZO.Attributes; -using SCHIZO.Helpers; -using SCHIZO.Resources; -using SCHIZO.Sounds; -using SCHIZO.Unity.Creatures; -using UnityEngine; - -namespace SCHIZO.Creatures.Ermfish; - -[LoadCreature] -public sealed class ErmfishLoader : PickupableCreatureLoader -{ - // todo: test BZ bus path when SoundPlayers are fixed - public static readonly SoundPlayer PlayerDeathSounds = new(Assets.Erm_Sounds_PlayerDeath_ErmfishPlayerDeath, - IS_BELOWZERO ? "bus:/master/SFX_for_pause" : "bus:/master/SFX_for_pause/nofilter"); -} diff --git a/Unity/Assets/Mod/Anneel/Databank/Databank.txt b/Unity/Assets/Mod/Anneel/Databank/Databank.txt index e69de29b..d09864b7 100644 --- a/Unity/Assets/Mod/Anneel/Databank/Databank.txt +++ b/Unity/Assets/Mod/Anneel/Databank/Databank.txt @@ -0,0 +1 @@ +someone please fill this in before vedal plays the mod i'm begging you \ No newline at end of file diff --git a/Unity/Assets/Mod/Erm Bed/Erm Bed.asset b/Unity/Assets/Mod/Erm Bed/Erm Bed.asset index 076c3069..252d60e5 100644 --- a/Unity/Assets/Mod/Erm Bed/Erm Bed.asset +++ b/Unity/Assets/Mod/Erm Bed/Erm Bed.asset @@ -17,7 +17,7 @@ MonoBehaviour: id: 0 classId: ermbed displayName: Erm Bed - tooltip: '[PH] What if..we hold hands..under the Erm blanket tonight? :flushed: + tooltip: 'What if..we hold hands..under the Erm blanket tonight? :flushed: Haha just kidding... unless..? :pleading_face: :point_right::point_left:' diff --git a/Unity/Assets/Mod/Events/Event Manager.prefab b/Unity/Assets/Mod/Events/Event Manager.prefab index 6ac8760a..a50f79e1 100644 --- a/Unity/Assets/Mod/Events/Event Manager.prefab +++ b/Unity/Assets/Mod/Events/Event Manager.prefab @@ -44,8 +44,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 78315918d0514014d864600fb981a894, type: 3} m_Name: m_EditorClassIdentifier: - autoStartEvents: 1 - overridePlayerPrefs: 0 --- !u!114 &2221432346329158674 MonoBehaviour: m_ObjectHideFlags: 0 @@ -60,7 +58,7 @@ MonoBehaviour: m_EditorClassIdentifier: canAutoStart: 1 requiredStoryGoal_SN: - requiredStoryGoal_BZ: + requiredStoryGoal_BZ: SanctuaryCompleted ticketsSold: {x: 10, y: 50} attendeeSearchRadius: 250 panelistSearchRadius: 30 diff --git a/Unity/Assets/Mod/Green Screen/Green Screens.asset b/Unity/Assets/Mod/Green Screen/Green Screens.asset index 3bf3fbd7..819ea280 100644 --- a/Unity/Assets/Mod/Green Screen/Green Screens.asset +++ b/Unity/Assets/Mod/Green Screen/Green Screens.asset @@ -12,4 +12,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c08c4776b89c430d985e9557dc60112d, type: 3} m_Name: Green Screens m_EditorClassIdentifier: - registryItems: [] + registryItems: + - {fileID: 11400000, guid: ac6932989e512cc43a944ca4fc5924f0, type: 2} + - {fileID: 11400000, guid: 6710c9cdea33a7f4ab8ba37ee479c8e8, type: 2} diff --git a/Unity/Assets/Scripts/SCHIZO/Helpers/ReflectionCache.cs b/Unity/Assets/Scripts/SCHIZO/Helpers/ReflectionCache.cs index 1d3b8e07..d9d2a16f 100644 --- a/Unity/Assets/Scripts/SCHIZO/Helpers/ReflectionCache.cs +++ b/Unity/Assets/Scripts/SCHIZO/Helpers/ReflectionCache.cs @@ -10,14 +10,11 @@ public static class ReflectionCache { private const BindingFlags ALL = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; - private class Cache + private class Cache(Func getValueFunc) { - private readonly Func getValueFunc; - private readonly Dictionary _cache = new Dictionary(); - public Cache(Func getValueFunc) - { - this.getValueFunc = getValueFunc; - } + private readonly Func getValueFunc = getValueFunc; + private readonly Dictionary _cache = []; + public TValue GetCached(TKey key) { if (!_cache.TryGetValue(key, out TValue value)) @@ -25,27 +22,26 @@ public TValue GetCached(TKey key) return value; } } - private static readonly Cache _types = new Cache(AccessTools.TypeByName); - private static readonly Cache> _allFields = new Cache>( - // AccessTools + private static readonly Cache _types = new(AccessTools.TypeByName); + private static readonly Cache> _allFields = new( type => ReflectionHelpers.WalkTypeHierarchy(type).SelectMany(t => t.GetFields(ALL)).ToList() ); - private static readonly Cache<(Type type, string name), FieldInfo> _fieldByName = new Cache<(Type type, string name), FieldInfo>( + private static readonly Cache<(Type type, string name), FieldInfo> _fieldByName = new( pair => AccessTools.Field(pair.type, pair.name) ); - private static readonly Cache> _allMethods = new Cache>( + private static readonly Cache> _allMethods = new( type => ReflectionHelpers.WalkTypeHierarchy(type).SelectMany(t => t.GetMethods(ALL)).ToList() ); - private static readonly Cache<(Type type, string name), MethodInfo> _methodByName = new Cache<(Type type, string name), MethodInfo>( + private static readonly Cache<(Type type, string name), MethodInfo> _methodByName = new( pair => AccessTools.Method(pair.type, pair.name) ); - private static readonly Cache> _allProperties = new Cache>( + private static readonly Cache> _allProperties = new( type => ReflectionHelpers.WalkTypeHierarchy(type).SelectMany(t => t.GetProperties(ALL)).ToList() ); - private static readonly Cache<(Type type, string name), PropertyInfo> _propertyByName = new Cache<(Type type, string name), PropertyInfo>( + private static readonly Cache<(Type type, string name), PropertyInfo> _propertyByName = new( pair => AccessTools.Property(pair.type, pair.name) ); - private static readonly Cache> _memberAttrs = new Cache>(member => member.GetCustomAttributes().ToList()); + private static readonly Cache> _memberAttrs = new(member => member.GetCustomAttributes().ToList()); public static Type GetType(string typeName) => _types.GetCached(typeName); public static List GetAllFields(Type type) => _allFields.GetCached(type);