diff --git a/Immersion/Trackers/Backseating.cs b/Immersion/Trackers/Backseating.cs index 38a4be3b..3a3b146c 100644 --- a/Immersion/Trackers/Backseating.cs +++ b/Immersion/Trackers/Backseating.cs @@ -95,15 +95,15 @@ private void UpdateBaseGameAlerts() CoroutineHost.StartCoroutine(ToggleHypothermiaAlerts(!enabled)); } - private void ToggleSurvivalAlerts(bool enabled) + private void ToggleSurvivalAlerts(bool enable) { - SurvivalAlertPatches.EnableSurvivalAlerts = enabled; + SurvivalAlertPatches.EnableSurvivalAlerts = enable; } - private IEnumerator ToggleHypothermiaAlerts(bool enabled) + private IEnumerator ToggleHypothermiaAlerts(bool enable) { yield return new WaitUntil(() => bodyTemp); PDANotification notif = bodyTemp.hypothermiaWarningNotification; - notif.nextPlayTime = enabled ? 0 : float.PositiveInfinity; + notif.nextPlayTime = enable ? 0 : float.PositiveInfinity; } public void FixedUpdate() diff --git a/Immersion/Trackers/JukeboxTrackUnlocked.cs b/Immersion/Trackers/JukeboxTrackUnlocked.cs index cf66cfe4..5dcef525 100644 --- a/Immersion/Trackers/JukeboxTrackUnlocked.cs +++ b/Immersion/Trackers/JukeboxTrackUnlocked.cs @@ -5,17 +5,17 @@ namespace Immersion.Trackers; [HarmonyPatch] public sealed class JukeboxTrackUnlocked : Tracker { - internal static HashSet _allowlist = new(StringComparer.InvariantCultureIgnoreCase) + internal static readonly HashSet _allowlist = new(StringComparer.InvariantCultureIgnoreCase) { "truckersfm" }; internal void NotifyUnlocked(Jukebox.UnlockableTrack track) { - if (!Jukebox.unlockableMusic.TryGetValue(track, out string name)) return; - if (!_allowlist.Contains(name)) return; + if (!Jukebox.unlockableMusic.TryGetValue(track, out string trackId)) return; + if (!_allowlist.Contains(trackId)) return; - React(Priority.Low, Format.FormatPlayer($"{{player}} has unlocked a new jukebox track: {Jukebox.GetInfo(name).label}")); + React(Priority.Low, Format.FormatPlayer($"{{player}} has unlocked a new jukebox track: {Jukebox.GetInfo(trackId).label}")); } [HarmonyPatch(typeof(Jukebox), nameof(Jukebox.OnUnlock))] diff --git a/Immersion/Trackers/NewScans.cs b/Immersion/Trackers/NewScans.cs index 2c3ab3c4..49bdccce 100644 --- a/Immersion/Trackers/NewScans.cs +++ b/Immersion/Trackers/NewScans.cs @@ -16,8 +16,8 @@ public void OnScanned(PDAScanner.Entry entry) internal void NotifyScanned(TechType techType) { - string name = Language.main.TryGet(techType, out string nameMaybe) ? nameMaybe : Format.ToTitleCase(techType); - string message = Format.FormatPlayer($"{{player}} has discovered a new creature: {name}."); + string techName = Language.main.TryGet(techType, out string nameMaybe) ? nameMaybe : Format.ToTitleCase(techType); + string message = Format.FormatPlayer($"{{player}} has discovered a new creature: {techName}."); string encyKey = PDAScanner.GetEntryData(techType).encyclopedia; if (!PDAEncyclopedia.GetEntryData(encyKey, out PDAEncyclopedia.EntryData data)) return; diff --git a/Immersion/Trackers/StoryGoals.Descriptions.cs b/Immersion/Trackers/StoryGoals.Descriptions.cs index c4f884da..377319a1 100644 --- a/Immersion/Trackers/StoryGoals.Descriptions.cs +++ b/Immersion/Trackers/StoryGoals.Descriptions.cs @@ -4,12 +4,12 @@ namespace Immersion.Trackers; partial class StoryGoals { - private record class Description(string Message, bool IsImportant = false) + private record Description(string Message, bool IsImportant = false) { public Priority Priority => IsImportant ? Priority.High : Priority.Low; public static implicit operator Description(string Message) => new(Message); } - private static Dictionary StoryGoalDescriptions = new(StoryGoal.KeyComparer) + private static readonly Dictionary StoryGoalDescriptions = new(StoryGoal.KeyComparer) { // sorted roughly in story order diff --git a/Immersion/Trackers/Tracker.cs b/Immersion/Trackers/Tracker.cs index b8666d7d..9fb4b54b 100644 --- a/Immersion/Trackers/Tracker.cs +++ b/Immersion/Trackers/Tracker.cs @@ -19,7 +19,7 @@ protected internal enum Priority public static bool ForceLowPriority { get => PlayerPrefsExtra.GetBool(forceLowPrioPrefsKey, false); - set => PlayerPrefsExtra.SetBool(forceLowPrioPrefsKey, false); + set => PlayerPrefsExtra.SetBool(forceLowPrioPrefsKey, value); } private string startEnabledPrefsKey => $"{GetType().FullName}_Enabled"; internal bool startEnabled diff --git a/SCHIZO/Commands/Attributes/CommandAttribute.cs b/SCHIZO/Commands/Attributes/CommandAttribute.cs index e21a17d8..fe43c201 100644 --- a/SCHIZO/Commands/Attributes/CommandAttribute.cs +++ b/SCHIZO/Commands/Attributes/CommandAttribute.cs @@ -1,8 +1,10 @@ using System; +using JetBrains.Annotations; namespace SCHIZO.Commands.Attributes; [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] +[MeansImplicitUse] public class CommandAttribute : Attribute { public required string Name { get; set; } diff --git a/SCHIZO/Commands/Base/MethodCommand.cs b/SCHIZO/Commands/Base/MethodCommand.cs index 2eeaffe1..40fa0617 100644 --- a/SCHIZO/Commands/Base/MethodCommand.cs +++ b/SCHIZO/Commands/Base/MethodCommand.cs @@ -14,15 +14,15 @@ internal class MethodCommand : Command, IParameters private readonly MethodInfo _method; private readonly object? _instance; private readonly bool _lastTakeAll; - public IReadOnlyList Parameters { get; protected set; } = []; + public IReadOnlyList Parameters { get; protected set; } public MethodCommand(MethodInfo method, object? instance = null) { if (method.IsStatic && instance is { }) throw new ArgumentException("Static method does not need instance"); - else if (!method.IsStatic && instance is null) + if (!method.IsStatic && instance is null) throw new ArgumentException("Non-static method needs instance"); - else if (method.Name.IndexOf('>') >= 0) // mangled (delegate, lambda, inner function, etc...) + if (method.Name.IndexOf('>') >= 0) // mangled (delegate, lambda, inner function, etc...) throw new ArgumentException($"Use {nameof(DelegateCommand)} instead of {nameof(MethodCommand)} for delegate methods (lambda, inner function, etc.)"); _method = method; _instance = instance; @@ -105,7 +105,7 @@ internal static ArgParseResult TryParseNamedArgs(Dictionary? ar return new(consumed == args.Count, parsed == parameters.Count, parsedArgs); } - internal static ArgParseResult TryParsePositionalArgs(IReadOnlyList args, IReadOnlyList parameters, bool lastTakeAll = false) + internal static ArgParseResult TryParsePositionalArgs(IReadOnlyList? args, IReadOnlyList parameters, bool lastTakeAll = false) { if (args is null) return new(true, parameters.All(p => p.IsOptional), []); diff --git a/SCHIZO/Commands/Base/NautilusCommandWrapper.cs b/SCHIZO/Commands/Base/NautilusCommandWrapper.cs index d8e17dd4..e0fa5bb5 100644 --- a/SCHIZO/Commands/Base/NautilusCommandWrapper.cs +++ b/SCHIZO/Commands/Base/NautilusCommandWrapper.cs @@ -34,6 +34,7 @@ public static NautilusCommandWrapper Register(Command command) } NautilusCommandWrapper wrapper = new(command); wrapper.RegisterWithNautilus(); + _registered[command.Name] = wrapper; return wrapper; } diff --git a/SCHIZO/Commands/DevCommands.cs b/SCHIZO/Commands/DevCommands.cs index c5511723..e0ad00de 100644 --- a/SCHIZO/Commands/DevCommands.cs +++ b/SCHIZO/Commands/DevCommands.cs @@ -99,7 +99,7 @@ public static object PrintField(string typeName, string memberName) Type type = ReflectionCache.GetType(typeName); if (type is null) return $"Could not find type '{typeName}'"; MemberInfo[] member = type.GetMember(memberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); - if (member is null) return $"Could not find '{memberName}' in type '{typeName}' (must be static)"; + if (member.Length == 0) return $"Could not find '{memberName}' in type '{typeName}' (must be static)"; return ReflectionHelpers.GetStaticMemberValue(member.Single()); } @@ -111,7 +111,7 @@ public static object SetField(string typeName, string memberName, string valueSt { Type type = ReflectionCache.GetType(typeName); if (type is null) return $"Could not find type '{typeName}'"; - MemberInfo member = type.GetMember(memberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).Single(); + MemberInfo member = type.GetMember(memberName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).SingleOrDefault(); if (member is null) return $"Could not find '{memberName}' in type '{typeName}' (must be static)"; Type memberType = member switch { diff --git a/SCHIZO/Commands/Input/Conversion.cs b/SCHIZO/Commands/Input/Conversion.cs index 16b27df6..253f9c2b 100644 --- a/SCHIZO/Commands/Input/Conversion.cs +++ b/SCHIZO/Commands/Input/Conversion.cs @@ -18,7 +18,7 @@ public static bool TryParseOrConvert(object? val, [MaybeNullWhen(false)] out return false; } - public static bool TryParseOrConvert(object? val, Type type, [MaybeNullWhen(false)] out object? value) + public static bool TryParseOrConvert(object? val, Type type, out object? value) { value = default; if (type.IsEnum) @@ -27,7 +27,7 @@ public static bool TryParseOrConvert(object? val, Type type, [MaybeNullWhen(fals } if (val is null) return false; - if (type.IsAssignableFrom(val.GetType())) + if (type.IsInstanceOfType(val)) { value = val; return true; @@ -64,7 +64,7 @@ public static bool TryParseEnum(object? val, [MaybeNullWhen(false)] out T return false; } - public static bool TryParseEnum(object? val, Type type, [MaybeNullWhen(false)] out object? value) + public static bool TryParseEnum(object? val, Type type, out object? value) { value = default; if (val is null) diff --git a/SCHIZO/Commands/Input/JsonInputModel.cs b/SCHIZO/Commands/Input/JsonInputModel.cs index d7d7a1c8..6516dfdf 100644 --- a/SCHIZO/Commands/Input/JsonInputModel.cs +++ b/SCHIZO/Commands/Input/JsonInputModel.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using SwarmControl.Models.Game.Messages; +using SCHIZO.SwarmControl.Models.Game.Messages; namespace SCHIZO.Commands.Input; diff --git a/SCHIZO/Commands/Input/RemoteInput.cs b/SCHIZO/Commands/Input/RemoteInput.cs index 9e8e5a5c..e9735f1d 100644 --- a/SCHIZO/Commands/Input/RemoteInput.cs +++ b/SCHIZO/Commands/Input/RemoteInput.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Linq; -using SwarmControl.Models.Game.Messages; using SCHIZO.Commands.Base; using SCHIZO.Helpers; +using SCHIZO.SwarmControl.Models.Game.Messages; namespace SCHIZO.Commands.Input; @@ -12,7 +12,7 @@ public class RemoteInput : CommandInput public required RedeemMessage Model { get; init; } public override string GetSubCommandName() - => Model.Command.Split([' '], 3).ElementAtOrDefault(1); + => Model.Command.Split([' '], 3).ElementAtOrDefault(1) ?? ""; public override IEnumerable GetPositionalArguments() { @@ -31,7 +31,7 @@ public override string GetSubCommandName() public override NamedArgs GetNamedArguments() => new(Model.Args ?? []); public override CommandInput GetSubCommandInput(Command subCommand) - => new RemoteInput() + => new RemoteInput { Command = subCommand, Model = Model with { Command = Model.Command.SplitOnce(' ').After } diff --git a/SCHIZO/Commands/Input/Vector3Converter.cs b/SCHIZO/Commands/Input/Vector3Converter.cs index a6d0bfb5..ddaff224 100644 --- a/SCHIZO/Commands/Input/Vector3Converter.cs +++ b/SCHIZO/Commands/Input/Vector3Converter.cs @@ -49,7 +49,7 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati return destinationType == typeof(Vector3); } - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) + public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object? value) { if (value is string[] arr && TryConvertStringArray(arr, out Vector3 v)) return v; diff --git a/SCHIZO/DataStructures/SavedRandomList.cs b/SCHIZO/DataStructures/SavedRandomList.cs index 6ada19b5..992dca45 100644 --- a/SCHIZO/DataStructures/SavedRandomList.cs +++ b/SCHIZO/DataStructures/SavedRandomList.cs @@ -21,8 +21,7 @@ public bool Register(IdentifiableItem item) { string identifier = item.Identifier; - if (_identifiers.Contains(identifier)) throw new InvalidOperationException($"Duplicate identifier: {identifier}"); - _identifiers.Add(identifier); + if (!_identifiers.Add(identifier)) throw new InvalidOperationException($"Duplicate identifier: {identifier}"); // possible gotcha to look out for: PlayerPrefsExtra stores some values like Vectors in multiple keys, so HasKey might return false even if the keys exist // not the case for booleans though diff --git a/SCHIZO/Events/ErmfishDefenseForce/ErmfishDefenseForce.cs b/SCHIZO/Events/ErmfishDefenseForce/ErmfishDefenseForce.cs index 17c7a168..6dabd6b9 100644 --- a/SCHIZO/Events/ErmfishDefenseForce/ErmfishDefenseForce.cs +++ b/SCHIZO/Events/ErmfishDefenseForce/ErmfishDefenseForce.cs @@ -48,7 +48,7 @@ protected override void Start() { instance = this; - _techTypes = new(protectedSpecies.Select(data => (TechType)data.ModItem)); + _techTypes = [..protectedSpecies.Select(data => (TechType) data.ModItem)]; ActiveDefenders = []; } @@ -200,8 +200,8 @@ private IEnumerator SpawnDefenderGroup(Defender defender) if (blockingHit.point != default) spawnPos = blockingHit.point + blockingHit.normal * 0.1f; - GameObject instance = GameObject.Instantiate(prefab); - instance.transform.position = spawnPos; + GameObject spawnInstance = GameObject.Instantiate(prefab); + spawnInstance.transform.position = spawnPos; if (debugSpawns) { if (blockingHit.point != default) @@ -211,13 +211,13 @@ private IEnumerator SpawnDefenderGroup(Defender defender) spawnMarker.transform.position = spawnPos; Destroy(spawnMarker, 10f); } - instance.transform.LookAt(player.transform); + spawnInstance.transform.LookAt(player.transform); - ActiveDefenders.Add(instance); + ActiveDefenders.Add(spawnInstance); spawned++; // don't save - LargeWorldEntity lwe = instance.GetComponent(); + LargeWorldEntity lwe = spawnInstance.GetComponent(); if (lwe) LargeWorldStreamer.main.cellManager.UnregisterEntity(lwe); } if (debugSpawns) LOGGER.LogDebug($"(EDF) spawned {spawned} {defender.ClassId}"); @@ -226,12 +226,11 @@ private IEnumerator SpawnDefenderGroup(Defender defender) private bool CanSpawn() { - bool canSpawn; - canSpawn = player && !player.currentSub + bool canSpawn = player && !player.currentSub #if BELOWZERO - && player.currentInterior is null // don't spawn indoors + && player.currentInterior is null // don't spawn indoors #endif - && player.IsUnderwaterForSwimming(); // there are no land kill squads... yet + && player.IsUnderwaterForSwimming(); // there are no land kill squads... yet return canSpawn; } diff --git a/SCHIZO/Helpers/ObjectHelpers.cs b/SCHIZO/Helpers/ObjectHelpers.cs index c24ef81e..f702a4b3 100644 --- a/SCHIZO/Helpers/ObjectHelpers.cs +++ b/SCHIZO/Helpers/ObjectHelpers.cs @@ -14,8 +14,7 @@ public static bool Exists(this object obj) public static T Or(this T obj, T other) where T : UnityEngine.Object { - if (obj) return obj; - return other; + return obj ? obj : other; } /// @@ -25,7 +24,6 @@ public static T Or(this T obj, T other) public static T Or(this T obj, Func other) where T : UnityEngine.Object { - if (obj) return obj; - return other(); + return obj ? obj : other(); } } diff --git a/SCHIZO/Helpers/StringHelpers.cs b/SCHIZO/Helpers/StringHelpers.cs index 8103b200..8972d374 100644 --- a/SCHIZO/Helpers/StringHelpers.cs +++ b/SCHIZO/Helpers/StringHelpers.cs @@ -15,7 +15,7 @@ public static (string Before, string After) SplitOnce(this string src, char deli // splitting w/o span makes me want to take up woodworking int split = src.IndexOf(delimiter); - if (split is < 0 || split == src.Length - 1) + if (split < 0 || split == src.Length - 1) return (src, ""); return (src[..split], src[(split + 1)..]); diff --git a/SCHIZO/Items/ModItem.cs b/SCHIZO/Items/ModItem.cs index 04be6298..41e2de1e 100644 --- a/SCHIZO/Items/ModItem.cs +++ b/SCHIZO/Items/ModItem.cs @@ -18,8 +18,7 @@ public ModItem(ItemData data) { LOGGER.LogDebug("Creating ModItem " + data.classId + " with name " + data.displayName); - if (_registeredItems.Contains(data.classId)) throw new Exception("Item with classId " + data.classId + " has already been created!"); - _registeredItems.Add(data.classId); + if (!_registeredItems.Add(data.classId)) throw new Exception("Item with classId " + data.classId + " has already been created!"); if (data.ModItem != null) throw new Exception("ItemData with classId " + data.classId + " has already been created!"); data.ModItem = this; diff --git a/SCHIZO/SwarmControl/ControlWebSocket.Plumbing.cs b/SCHIZO/SwarmControl/ControlWebSocket.Plumbing.cs index 27e4bda7..1f046cd3 100644 --- a/SCHIZO/SwarmControl/ControlWebSocket.Plumbing.cs +++ b/SCHIZO/SwarmControl/ControlWebSocket.Plumbing.cs @@ -9,8 +9,8 @@ using System.Threading.Tasks; using Newtonsoft.Json; using SCHIZO.Helpers; -using SwarmControl.Models.Game.Messages; using SCHIZO.Commands.Input; +using SCHIZO.SwarmControl.Models.Game.Messages; namespace SCHIZO.SwarmControl; @@ -77,7 +77,7 @@ private async Task SendThread() LOGGER.LogWarning($"Re-queueing {msg.GetType().Name} ({msg.Guid})"); _sendQueue.Enqueue(msg); } - if (e is WebSocketException we) + if (e is WebSocketException) { _socket.Dispose(); OnClose?.Invoke((WebSocketCloseStatus)1006, null); @@ -144,12 +144,12 @@ public void SendMessage(GameMessage message) ArraySegment buffer = new(rent.Array); WebSocketReceiveResult? result = null; - int totalBytes = 0; + // int totalBytes = 0; while (result is not { EndOfMessage: true }) { result = await _socket.ReceiveAsync(buffer, killSocketCt); ms.Write(buffer.Array, 0, result.Count); - totalBytes += result.Count; + // totalBytes += result.Count; } // LOGGER.LogDebug($"Received {result.MessageType} ({totalBytes} bytes)"); switch (result.MessageType) diff --git a/SCHIZO/SwarmControl/ControlWebSocket.cs b/SCHIZO/SwarmControl/ControlWebSocket.cs index bcf5002b..5cb746af 100644 --- a/SCHIZO/SwarmControl/ControlWebSocket.cs +++ b/SCHIZO/SwarmControl/ControlWebSocket.cs @@ -3,7 +3,7 @@ using System.Net.WebSockets; using System.Threading; using System.Threading.Tasks; -using SwarmControl.Models.Game.Messages; +using SCHIZO.SwarmControl.Models.Game.Messages; namespace SCHIZO.SwarmControl; @@ -52,7 +52,9 @@ then enter "{SwarmControlManager.COMMAND_URL} " { int timeout = BaseUri.IsLoopback ? 1 : 5; - using HttpClient client = new() { BaseAddress = BaseUri, Timeout = TimeSpan.FromSeconds(timeout) }; + using HttpClient client = new(); + client.BaseAddress = BaseUri; + client.Timeout = TimeSpan.FromSeconds(timeout); HttpRequestMessage request = new(HttpMethod.Options, "/"); await client.SendAsync(request, ct); } diff --git a/SCHIZO/SwarmControl/EggTimer.cs b/SCHIZO/SwarmControl/EggTimer.cs index a2f7af22..b6cd30f1 100644 --- a/SCHIZO/SwarmControl/EggTimer.cs +++ b/SCHIZO/SwarmControl/EggTimer.cs @@ -9,14 +9,12 @@ namespace SCHIZO.SwarmControl; internal class EggTimer : IDisposable { private readonly Coroutine _timerCoro; - private readonly Action _onStart; - private readonly Action _onEnd; + private readonly Action? _onStart; + private readonly Action? _onEnd; private readonly Action? _onTick; - private bool _active; - private float _timeLeft; - public bool IsActive => _active; - public float TimeLeft => _timeLeft; + public bool IsActive { get; private set; } + public float TimeLeft { get; private set; } public EggTimer(Action onStart, Action onEnd, Action? onTick = null) { @@ -28,8 +26,8 @@ public EggTimer(Action onStart, Action onEnd, Action? onTick = null) public void AddTime(float seconds) { - _timeLeft += seconds; - if (_timeLeft > 0) + TimeLeft += seconds; + if (TimeLeft > 0) Start(); } @@ -38,13 +36,13 @@ private IEnumerator TimerCoro() while (true) { yield return new WaitForFixedUpdate(); - if (!_active) continue; + if (!IsActive) continue; _onTick?.Invoke(); - _timeLeft -= Time.fixedDeltaTime; - if (_timeLeft <= 0) + TimeLeft -= Time.fixedDeltaTime; + if (TimeLeft <= 0) { - _timeLeft = 0; + TimeLeft = 0; End(); } } @@ -52,14 +50,14 @@ private IEnumerator TimerCoro() public void Start() { - if (_active) return; - _active = true; + if (IsActive) return; + IsActive = true; _onStart?.Invoke(); } public void End() { - if (!_active) return; - _active = false; + if (!IsActive) return; + IsActive = false; _onEnd?.Invoke(); } diff --git a/SCHIZO/SwarmControl/MessageProcessor.cs b/SCHIZO/SwarmControl/MessageProcessor.cs index 46abab25..d04bfd43 100644 --- a/SCHIZO/SwarmControl/MessageProcessor.cs +++ b/SCHIZO/SwarmControl/MessageProcessor.cs @@ -6,7 +6,7 @@ using SCHIZO.Commands.Input; using SCHIZO.Commands.Output; using SCHIZO.Helpers; -using SwarmControl.Models.Game.Messages; +using SCHIZO.SwarmControl.Models.Game.Messages; namespace SCHIZO.SwarmControl; diff --git a/SCHIZO/SwarmControl/Models/Game/HostAuthInfo.cs b/SCHIZO/SwarmControl/Models/Game/HostAuthInfo.cs deleted file mode 100644 index 2fd61216..00000000 --- a/SCHIZO/SwarmControl/Models/Game/HostAuthInfo.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace SwarmControl.Models.Game; - -/// -/// Authentication information for a "host" connection to the backend. -/// -/// Identity of the user that logged into the backend. -/// Opaque token. -public readonly struct HostAuthInfo(string twitchUsername, string token) -{ - public string TwitchUsername { get; } = twitchUsername; - public string Token { get; } = token; -} diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/CommandInvocationSource.cs b/SCHIZO/SwarmControl/Models/Game/Messages/CommandInvocationSource.cs index db41f2b9..0bef11a4 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/CommandInvocationSource.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/CommandInvocationSource.cs @@ -1,4 +1,4 @@ -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; public enum CommandInvocationSource { diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/ConsoleInputMessage.cs b/SCHIZO/SwarmControl/Models/Game/Messages/ConsoleInputMessage.cs index 43746641..d559004e 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/ConsoleInputMessage.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/ConsoleInputMessage.cs @@ -1,4 +1,4 @@ -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; public sealed record ConsoleInputMessage : BackendMessage { diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/HelloBackMessage.cs b/SCHIZO/SwarmControl/Models/Game/Messages/HelloBackMessage.cs index 6424cbc4..310fe7f0 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/HelloBackMessage.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/HelloBackMessage.cs @@ -1,4 +1,4 @@ -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; public sealed record HelloBackMessage : BackendMessage { diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/HelloMessage.cs b/SCHIZO/SwarmControl/Models/Game/Messages/HelloMessage.cs index 5f15a380..5d968401 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/HelloMessage.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/HelloMessage.cs @@ -1,9 +1,9 @@ using System.Diagnostics.CodeAnalysis; -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; [method: SetsRequiredMembers] -public sealed record HelloMessage() : GameMessage() +public sealed record HelloMessage() : GameMessage { public override MessageType MessageType => MessageType.Hello; public string Version { get; init; } diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/IngameStateChangedMessage.cs b/SCHIZO/SwarmControl/Models/Game/Messages/IngameStateChangedMessage.cs index 08682ccd..0ba52772 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/IngameStateChangedMessage.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/IngameStateChangedMessage.cs @@ -1,4 +1,4 @@ -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; internal record IngameStateChangedMessage : GameMessage { diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/LogMessage.cs b/SCHIZO/SwarmControl/Models/Game/Messages/LogMessage.cs index 2014751d..4760f598 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/LogMessage.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/LogMessage.cs @@ -1,4 +1,4 @@ -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; #nullable enable internal record LogMessage : GameMessage diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/MessageType.cs b/SCHIZO/SwarmControl/Models/Game/Messages/MessageType.cs index d3b6cba6..625f75f7 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/MessageType.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/MessageType.cs @@ -1,7 +1,7 @@ //using Newtonsoft.Json; //using Newtonsoft.Json.Converters; -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; //[JsonConverter(typeof(StringEnumConverter))] public enum MessageType diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/PingMessage.cs b/SCHIZO/SwarmControl/Models/Game/Messages/PingMessage.cs index 8e7802b6..d354f333 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/PingMessage.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/PingMessage.cs @@ -1,4 +1,4 @@ -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; internal record PingMessage : GameMessage { public override MessageType MessageType => MessageType.Ping; diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/PongMessage.cs b/SCHIZO/SwarmControl/Models/Game/Messages/PongMessage.cs index 11faf988..445f45d6 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/PongMessage.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/PongMessage.cs @@ -1,4 +1,4 @@ -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; internal record PongMessage : BackendMessage { diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/RedeemMessage.cs b/SCHIZO/SwarmControl/Models/Game/Messages/RedeemMessage.cs index 5ef7198f..2bc16e84 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/RedeemMessage.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/RedeemMessage.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; #nullable enable public sealed record RedeemMessage : BackendMessage diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/ResultMessage.cs b/SCHIZO/SwarmControl/Models/Game/Messages/ResultMessage.cs index e93b758f..c69701c8 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/ResultMessage.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/ResultMessage.cs @@ -3,7 +3,7 @@ using Newtonsoft.Json.Converters; using Newtonsoft.Json.Serialization; -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; #nullable enable public sealed record ResultMessage : GameMessage diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/SocketMessage.cs b/SCHIZO/SwarmControl/Models/Game/Messages/SocketMessage.cs index 31bf73e4..6c1611cf 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/SocketMessage.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/SocketMessage.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; #nullable enable [JsonObject(MemberSerialization = MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))] @@ -11,14 +11,8 @@ public abstract record SocketMessage [JsonRequired] public abstract MessageType MessageType { get; } - public Guid Guid { get; init; } - public long Timestamp { get; } - - public SocketMessage() - { - Timestamp = Now(); - Guid = Guid.NewGuid(); - } + public Guid Guid { get; init; } = Guid.NewGuid(); + public long Timestamp { get; } = Now(); private static long Now() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); } diff --git a/SCHIZO/SwarmControl/Models/Game/Messages/TwitchUser.cs b/SCHIZO/SwarmControl/Models/Game/Messages/TwitchUser.cs index b3cac2a1..fd79ebae 100644 --- a/SCHIZO/SwarmControl/Models/Game/Messages/TwitchUser.cs +++ b/SCHIZO/SwarmControl/Models/Game/Messages/TwitchUser.cs @@ -1,4 +1,4 @@ -namespace SwarmControl.Models.Game.Messages; +namespace SCHIZO.SwarmControl.Models.Game.Messages; #nullable enable /// diff --git a/SCHIZO/SwarmControl/Redeems/Annoying/DeadPixelRedeem.cs b/SCHIZO/SwarmControl/Redeems/Annoying/DeadPixelRedeem.cs index 4a578c66..61ea1b2c 100644 --- a/SCHIZO/SwarmControl/Redeems/Annoying/DeadPixelRedeem.cs +++ b/SCHIZO/SwarmControl/Redeems/Annoying/DeadPixelRedeem.cs @@ -20,9 +20,8 @@ internal class DeadPixelRedeem : Command, IParameters protected override object? ExecuteCore(CommandExecutionContext ctx) { Vector2 coords = new(Random.Range(0, 1920), Random.Range(0, 1080)); - GameObject instance = GameObject.Instantiate(Assets.Mod_SwarmControl_DeadPixel); + GameObject instance = GameObject.Instantiate(Assets.Mod_SwarmControl_DeadPixel, uGUI.main.screenCanvas.transform, false); instance.EnsureComponent().duration = Duration; - instance.transform.SetParent(uGUI.main.screenCanvas.transform, false); instance.transform.localPosition = new Vector2(coords.x-960, coords.y-540); return $"Your pixel is at {coords}"; } diff --git a/SCHIZO/SwarmControl/Redeems/Helpful/SeaMonkeyDeliverySystem.BelowZero.cs b/SCHIZO/SwarmControl/Redeems/Helpful/SeaMonkeyDeliverySystem.BelowZero.cs index 262da153..00fc1b0c 100644 --- a/SCHIZO/SwarmControl/Redeems/Helpful/SeaMonkeyDeliverySystem.BelowZero.cs +++ b/SCHIZO/SwarmControl/Redeems/Helpful/SeaMonkeyDeliverySystem.BelowZero.cs @@ -69,6 +69,7 @@ private IEnumerator DeliverCoro(TechType item) yield break; } LOGGER.LogDebug("(SMDS) Got prefab"); + _itemPrefabCache[item] = itemPrefab; } SeaMonkeyBringGift gift = monke.GetComponent(); diff --git a/SCHIZO/SwarmControl/Redeems/PayAttentionToMeStreamer/AddSignalRedeem.cs b/SCHIZO/SwarmControl/Redeems/PayAttentionToMeStreamer/AddSignalRedeem.cs index f4f030c5..dac01660 100644 --- a/SCHIZO/SwarmControl/Redeems/PayAttentionToMeStreamer/AddSignalRedeem.cs +++ b/SCHIZO/SwarmControl/Redeems/PayAttentionToMeStreamer/AddSignalRedeem.cs @@ -4,8 +4,8 @@ using SCHIZO.Commands.Context; using SCHIZO.Commands.Input; using SCHIZO.Commands.Output; +using SCHIZO.SwarmControl.Models.Game.Messages; using SCHIZO.Twitch; -using SwarmControl.Models.Game.Messages; using UnityEngine; using UWE; diff --git a/SCHIZO/SwarmControl/Redeems/PayAttentionToMeStreamer/Hint.cs b/SCHIZO/SwarmControl/Redeems/PayAttentionToMeStreamer/Hint.cs index 3b42206f..142e17c7 100644 --- a/SCHIZO/SwarmControl/Redeems/PayAttentionToMeStreamer/Hint.cs +++ b/SCHIZO/SwarmControl/Redeems/PayAttentionToMeStreamer/Hint.cs @@ -5,7 +5,7 @@ using SCHIZO.Commands.Context; using SCHIZO.Commands.Input; using SCHIZO.Commands.Output; -using SwarmControl.Models.Game.Messages; +using SCHIZO.SwarmControl.Models.Game.Messages; using UnityEngine; using UWE; diff --git a/SCHIZO/SwarmControl/Redeems/PayAttentionToMeStreamer/NameTagErmfish.cs b/SCHIZO/SwarmControl/Redeems/PayAttentionToMeStreamer/NameTagErmfish.cs index 86304b9c..950afeb9 100644 --- a/SCHIZO/SwarmControl/Redeems/PayAttentionToMeStreamer/NameTagErmfish.cs +++ b/SCHIZO/SwarmControl/Redeems/PayAttentionToMeStreamer/NameTagErmfish.cs @@ -8,8 +8,8 @@ using SCHIZO.Commands.Input; using SCHIZO.Commands.Output; using SCHIZO.Helpers; +using SCHIZO.SwarmControl.Models.Game.Messages; using SCHIZO.Twitch; -using SwarmControl.Models.Game.Messages; using UnityEngine; using UWE; @@ -55,7 +55,7 @@ protected override object ExecuteCore(CommandExecutionContext ctx) RemoteInput? input = ctx.Input as RemoteInput; TwitchUser? user = input?.Model.User; - if (user is not { DisplayName: { } dispName }) + if (user is null) return CommonResults.Error("Could not get username"); if (ermfish) diff --git a/SCHIZO/SwarmControl/Redeems/Redeem.cs b/SCHIZO/SwarmControl/Redeems/Redeem.cs index 8a11a509..9eb7fd51 100644 --- a/SCHIZO/SwarmControl/Redeems/Redeem.cs +++ b/SCHIZO/SwarmControl/Redeems/Redeem.cs @@ -11,8 +11,8 @@ internal sealed class Redeem(RedeemAttribute attr, Command command) public string Id { get; set; } = attr.Name; public string Title { get; set; } = attr.DisplayName; public string Description { get; set; } = attr.Description; - public ParameterModel[] Args { get; set; } = command is not IParameters p ? [] - : p.Parameters.Select(p => new ParameterModel(p)).ToArray(); + public ParameterModel[] Args { get; set; } = command is not IParameters hasParams ? [] + : hasParams.Parameters.Select(p => new ParameterModel(p)).ToArray(); [DefaultValue(true)] public bool Announce { get; set; } = attr.Announce; diff --git a/SCHIZO/SwarmControl/Redeems/Spawns/Isekai.cs b/SCHIZO/SwarmControl/Redeems/Spawns/Isekai.cs index 7b555bec..780939b7 100644 --- a/SCHIZO/SwarmControl/Redeems/Spawns/Isekai.cs +++ b/SCHIZO/SwarmControl/Redeems/Spawns/Isekai.cs @@ -12,7 +12,7 @@ namespace SCHIZO.SwarmControl.Redeems.Spawns; DisplayName = "Remove Entities", Description = "Snap a specific type of entity around the player. Does not include inventory/containers." )] -internal class Isekai : ProxyCommand +internal class Isekai() : ProxyCommand("isekai") { public enum IsekaiTechType { @@ -30,14 +30,9 @@ public enum IsekaiTechType Diamond, Ruby, } - public Isekai() : base("isekai") - { - Parameters = [ - new(new("creature", "Type", "Which entities to remove."), typeof(IsekaiTechType)), - ]; - } public override IReadOnlyList Parameters { get; } + = [new(new("creature", "Type", "Which entities to remove."), typeof(IsekaiTechType))]; protected override Dictionary? GetTargetArgs(Dictionary? proxyArgs) { diff --git a/SCHIZO/SwarmControl/SwarmControlManager.cs b/SCHIZO/SwarmControl/SwarmControlManager.cs index 150fe119..88bfe98a 100644 --- a/SCHIZO/SwarmControl/SwarmControlManager.cs +++ b/SCHIZO/SwarmControl/SwarmControlManager.cs @@ -8,7 +8,7 @@ using SCHIZO.Commands.Attributes; using SCHIZO.Helpers; using SCHIZO.Resources; -using SwarmControl.Models.Game.Messages; +using SCHIZO.SwarmControl.Models.Game.Messages; using TMPro; using UnityEngine; diff --git a/SCHIZO/Tweaks/Doom/DoomEngine.cs b/SCHIZO/Tweaks/Doom/DoomEngine.cs index 24d5f2e0..62e62146 100644 --- a/SCHIZO/Tweaks/Doom/DoomEngine.cs +++ b/SCHIZO/Tweaks/Doom/DoomEngine.cs @@ -83,7 +83,7 @@ internal void RunOnUnityThread(Action action) else ScheduleUnityThread(action); } - private ConcurrentQueue _unityThreadQueue = new(); + private readonly ConcurrentQueue _unityThreadQueue = new(); internal void ScheduleUnityThread(Action action) { _unityThreadQueue.Enqueue(action); @@ -173,7 +173,7 @@ private void Update() } // without the lock, the main thread randomly freezes (presumably due to simultaneous access to _XXXKeys) - private object _inputSync = new(); + private readonly object _inputSync = new(); // holding input state until the doom thread consumes it private readonly HashSet _pressedKeys = []; private readonly HashSet _heldKeys = []; diff --git a/SCHIZO/Tweaks/Doom/SeatruckDoomPlayer.cs b/SCHIZO/Tweaks/Doom/SeatruckDoomPlayer.cs index baa33be8..5c6621af 100644 --- a/SCHIZO/Tweaks/Doom/SeatruckDoomPlayer.cs +++ b/SCHIZO/Tweaks/Doom/SeatruckDoomPlayer.cs @@ -216,7 +216,7 @@ private void FreecamToScreen(bool looking) _ghost.tr.LookAt(center); } - private Queue _escapePresses = []; + private readonly Queue _escapePresses = []; private float _escapeHeld; private void Update() { diff --git a/SCHIZO/Twitch/TwitchIntegration.cs b/SCHIZO/Twitch/TwitchIntegration.cs index cd0d39be..6ca5cd63 100644 --- a/SCHIZO/Twitch/TwitchIntegration.cs +++ b/SCHIZO/Twitch/TwitchIntegration.cs @@ -9,7 +9,7 @@ using SCHIZO.Commands.Attributes; using SCHIZO.Helpers; using SCHIZO.SwarmControl; -using SwarmControl.Models.Game.Messages; +using SCHIZO.SwarmControl.Models.Game.Messages; using TwitchLib.Client; using TwitchLib.Client.Events; using TwitchLib.Client.Models; diff --git a/Unity/Assets/Scripts/SCHIZO/Helpers/ReflectionCache.cs b/Unity/Assets/Scripts/SCHIZO/Helpers/ReflectionCache.cs index d9d2a16f..a0d2e5b5 100644 --- a/Unity/Assets/Scripts/SCHIZO/Helpers/ReflectionCache.cs +++ b/Unity/Assets/Scripts/SCHIZO/Helpers/ReflectionCache.cs @@ -12,7 +12,6 @@ public static class ReflectionCache private class Cache(Func getValueFunc) { - private readonly Func getValueFunc = getValueFunc; private readonly Dictionary _cache = []; public TValue GetCached(TKey key)