From cebca2a829b32207e1c00f8e32ad1b47b0f0a7f5 Mon Sep 17 00:00:00 2001 From: yanghuanglin Date: Tue, 18 Jun 2024 14:12:00 +0800 Subject: [PATCH] optimize code --- Fika.Core/Coop/Utils/FikaBackendUtils.cs | 20 ++++++++++++------- Fika.Core/FikaPlugin.cs | 2 +- .../UI/Patches/FikaVersionLabel_Patch.cs | 5 ++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Fika.Core/Coop/Utils/FikaBackendUtils.cs b/Fika.Core/Coop/Utils/FikaBackendUtils.cs index c20610d8..80e049a6 100644 --- a/Fika.Core/Coop/Utils/FikaBackendUtils.cs +++ b/Fika.Core/Coop/Utils/FikaBackendUtils.cs @@ -3,7 +3,6 @@ using Fika.Core.Networking.Http; using Fika.Core.Networking.Http.Models; using System; -using System.Linq; using System.Reflection; using Fika.Core.EssentialPatches; @@ -79,8 +78,9 @@ public static bool JoinMatch(string profileId, string serverId, out CreateMatch public static void CreateMatch(string profileId, string hostUsername, RaidSettings raidSettings) { long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); - var raidCode = GenerateRaidCode(6); - var body = new CreateMatch(raidCode, profileId, hostUsername, timestamp, raidSettings, HostExpectedNumberOfPlayers, raidSettings.Side, raidSettings.SelectedDateTime); + string raidCode = GenerateRaidCode(6); + CreateMatch body = new CreateMatch(raidCode, profileId, hostUsername, timestamp, raidSettings, + HostExpectedNumberOfPlayers, raidSettings.Side, raidSettings.SelectedDateTime); FikaRequestHandler.RaidCreate(body); @@ -92,10 +92,16 @@ public static void CreateMatch(string profileId, string hostUsername, RaidSettin private static string GenerateRaidCode(int length) { - var random = new Random(); - const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - return new string(Enumerable.Repeat(chars, length) - .Select(s => s[random.Next(s.Length)]).ToArray()); + Random random = new Random(); + char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray(); + string raidCode = ""; + for (int i = 0; i < length; i++) + { + int charIndex = random.Next(chars.Length); + raidCode += chars[charIndex]; + } + + return raidCode; } } } diff --git a/Fika.Core/FikaPlugin.cs b/Fika.Core/FikaPlugin.cs index d8ce4630..b324fe5e 100644 --- a/Fika.Core/FikaPlugin.cs +++ b/Fika.Core/FikaPlugin.cs @@ -269,7 +269,7 @@ private void SetupConfig() AcceptedTOS = Config.Bind("Hidden", "Accepted TOS", false, new ConfigDescription("Has accepted TOS", tags: new ConfigurationManagerAttributes() { Browsable = false })); // Advanced - OfficialVersion = Config.Bind("Advanced", "Official Version", false, new ConfigDescription("Show official version instead of fika version.", tags: new ConfigurationManagerAttributes() { IsAdvanced = true })); + OfficialVersion = Config.Bind("Advanced", "Official Version", false, new ConfigDescription("Show official version instead of Fika version.", tags: new ConfigurationManagerAttributes() { IsAdvanced = true })); // Coop diff --git a/Fika.Core/UI/Patches/FikaVersionLabel_Patch.cs b/Fika.Core/UI/Patches/FikaVersionLabel_Patch.cs index 0bb76139..eadb935b 100644 --- a/Fika.Core/UI/Patches/FikaVersionLabel_Patch.cs +++ b/Fika.Core/UI/Patches/FikaVersionLabel_Patch.cs @@ -15,8 +15,6 @@ public class FikaVersionLabel_Patch : ModulePatch { private static string versionLabel; - private static Traverse preloaderUiTraverse; - private static Traverse versionNumberTraverse; private static string fikaVersion; @@ -43,7 +41,7 @@ internal static void PatchPostfix(string major, object __result) fikaVersion = Assembly.GetAssembly(typeof(FikaVersionLabel_Patch)).GetName().Version.ToString(); - preloaderUiTraverse = Traverse.Create(MonoBehaviourSingleton.Instance); + Traverse preloaderUiTraverse= Traverse.Create(MonoBehaviourSingleton.Instance); preloaderUiTraverse.Field("_alphaVersionLabel").Property("LocalizationKey").SetValue("{0}"); @@ -56,6 +54,7 @@ internal static void PatchPostfix(string major, object __result) public static void UpdateVersionLabel() { + Traverse preloaderUiTraverse= Traverse.Create(MonoBehaviourSingleton.Instance); if (FikaPlugin.OfficialVersion.Value) { preloaderUiTraverse.Field("string_2").SetValue($"{officalVersion} Beta version");