diff --git a/Fika.Core/Coop/Utils/FikaBackendUtils.cs b/Fika.Core/Coop/Utils/FikaBackendUtils.cs index 6813f601..80e049a6 100644 --- a/Fika.Core/Coop/Utils/FikaBackendUtils.cs +++ b/Fika.Core/Coop/Utils/FikaBackendUtils.cs @@ -4,6 +4,7 @@ using Fika.Core.Networking.Http.Models; using System; using System.Reflection; +using Fika.Core.EssentialPatches; namespace Fika.Core.Coop.Utils { @@ -69,18 +70,38 @@ public static bool JoinMatch(string profileId, string serverId, out CreateMatch return false; } + FikaVersionLabelUpdate_Patch.raidCode = result.RaidCode; + return true; } public static void CreateMatch(string profileId, string hostUsername, RaidSettings raidSettings) { long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); - var body = new CreateMatch(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); SetGroupId(profileId); MatchingType = EMatchmakerType.GroupLeader; + + FikaVersionLabelUpdate_Patch.raidCode = raidCode; + } + + private static string GenerateRaidCode(int length) + { + 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 c6203b29..b324fe5e 100644 --- a/Fika.Core/FikaPlugin.cs +++ b/Fika.Core/FikaPlugin.cs @@ -91,6 +91,9 @@ public class FikaPlugin : BaseUnityPlugin // Hidden public static ConfigEntry AcceptedTOS { get; set; } + //Advanced + public static ConfigEntry OfficialVersion { get; set; } + // Coop public static ConfigEntry ShowNotifications { get; set; } public static ConfigEntry AutoExtract { get; set; } @@ -188,6 +191,7 @@ protected void Awake() SetupConfig(); new FikaVersionLabel_Patch().Enable(); + new FikaVersionLabelUpdate_Patch().Enable(); new DisableReadyButton_Patch().Enable(); new DisableInsuranceReadyButton_Patch().Enable(); new DisableMatchSettingsReadyButton_Patch().Enable(); @@ -206,7 +210,8 @@ protected void Awake() #if GOLDMASTER new TOS_Patch().Enable(); #endif - + OfficialVersion.SettingChanged += OfficialVersion_SettingChanged; + DisableSPTPatches(); EnableOverridePatches(); @@ -263,6 +268,9 @@ 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 })); + // Coop ShowNotifications = Instance.Config.Bind("Coop", "Show Feed", true, new ConfigDescription("Enable custom notifications when a player dies, extracts, kills a boss, etc.", tags: new ConfigurationManagerAttributes() { Order = 6 })); @@ -401,6 +409,11 @@ private void SetupConfig() DisableBotMetabolism = Config.Bind("Gameplay", "Disable Bot Metabolism", false, new ConfigDescription("Disables metabolism on bots, preventing them from dying from loss of energy/hydration during long raids.", tags: new ConfigurationManagerAttributes() { Order = 1 })); } + + private void OfficialVersion_SettingChanged(object sender, EventArgs e) + { + FikaVersionLabel_Patch.UpdateVersionLabel(); + } private string[] GetLocalAddresses() { diff --git a/Fika.Core/Networking/Models/CreateMatchRequest.cs b/Fika.Core/Networking/Models/CreateMatchRequest.cs index 0ffb2d7d..7d679d3a 100644 --- a/Fika.Core/Networking/Models/CreateMatchRequest.cs +++ b/Fika.Core/Networking/Models/CreateMatchRequest.cs @@ -9,6 +9,9 @@ namespace Fika.Core.Networking.Http.Models [DataContract] public struct CreateMatch { + [DataMember(Name = "raidCode")] + public string RaidCode; + [DataMember(Name = "serverId")] public string ServerId; @@ -36,8 +39,9 @@ public struct CreateMatch [DataMember(Name = "time")] public EDateTime Time; - public CreateMatch(string serverId, string hostUsername, long timestamp, RaidSettings settings, int expectedNumberOfPlayers, ESideType side, EDateTime time) + public CreateMatch(string raidCode, string serverId, string hostUsername, long timestamp, RaidSettings settings, int expectedNumberOfPlayers, ESideType side, EDateTime time) { + RaidCode = raidCode; ServerId = serverId; HostUsername = hostUsername; Timestamp = timestamp; diff --git a/Fika.Core/UI/Patches/FikaVersionLabelUpdate_Patch.cs b/Fika.Core/UI/Patches/FikaVersionLabelUpdate_Patch.cs new file mode 100644 index 00000000..2a359322 --- /dev/null +++ b/Fika.Core/UI/Patches/FikaVersionLabelUpdate_Patch.cs @@ -0,0 +1,40 @@ +using System; +using System.Reflection; +using EFT; +using EFT.UI; +using HarmonyLib; +using SPT.Reflection.Patching; + +namespace Fika.Core.EssentialPatches +{ + /// + /// Update version label with raid code when game started + /// + public class FikaVersionLabelUpdate_Patch : ModulePatch + { + public static string raidCode; + + protected override MethodBase GetTargetMethod() + { + return typeof(GameWorld).GetMethod(nameof(GameWorld.OnGameStarted), + BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); + } + + [PatchPostfix] + private static void Postfix(GameWorld __instance) + { + if (!string.IsNullOrEmpty(raidCode)) + { + Traverse preloaderUiTraverse = Traverse.Create(MonoBehaviourSingleton.Instance); + //Game version + // preloaderUiTraverse.Field("string_2").SetValue($"Game version"); + //Raid code + preloaderUiTraverse.Field("string_3").SetValue($"{raidCode}"); + //Game mode + // preloaderUiTraverse.Field("string_4").SetValue("PvE"); + //Update version label + preloaderUiTraverse.Method("method_6").GetValue(); + } + } + } +} \ No newline at end of file diff --git a/Fika.Core/UI/Patches/FikaVersionLabel_Patch.cs b/Fika.Core/UI/Patches/FikaVersionLabel_Patch.cs index ed4cda89..eadb935b 100644 --- a/Fika.Core/UI/Patches/FikaVersionLabel_Patch.cs +++ b/Fika.Core/UI/Patches/FikaVersionLabel_Patch.cs @@ -15,9 +15,16 @@ public class FikaVersionLabel_Patch : ModulePatch { private static string versionLabel; + private static Traverse versionNumberTraverse; + + private static string fikaVersion; + + private static string officalVersion; + protected override MethodBase GetTargetMethod() { - return typeof(VersionNumberClass).GetMethod(nameof(VersionNumberClass.Create), BindingFlags.Static | BindingFlags.Public); + return typeof(VersionNumberClass).GetMethod(nameof(VersionNumberClass.Create), + BindingFlags.Static | BindingFlags.Public); } [PatchPostfix] @@ -32,13 +39,41 @@ internal static void PatchPostfix(string major, object __result) Logger.LogInfo($"Server version: {versionLabel}"); } - string fikaVersion = Assembly.GetAssembly(typeof(FikaVersionLabel_Patch)).GetName().Version.ToString(); + fikaVersion = Assembly.GetAssembly(typeof(FikaVersionLabel_Patch)).GetName().Version.ToString(); - Traverse preloaderUiTraverse = Traverse.Create(MonoBehaviourSingleton.Instance); + Traverse preloaderUiTraverse= Traverse.Create(MonoBehaviourSingleton.Instance); preloaderUiTraverse.Field("_alphaVersionLabel").Property("LocalizationKey").SetValue("{0}"); - preloaderUiTraverse.Field("string_2").SetValue($"FIKA BETA {fikaVersion} | {versionLabel}"); - Traverse.Create(__result).Field("Major").SetValue($"{fikaVersion} {versionLabel}"); + + versionNumberTraverse = Traverse.Create(__result); + + officalVersion = (string)versionNumberTraverse.Field("Major").GetValue(); + + UpdateVersionLabel(); + } + + public static void UpdateVersionLabel() + { + Traverse preloaderUiTraverse= Traverse.Create(MonoBehaviourSingleton.Instance); + if (FikaPlugin.OfficialVersion.Value) + { + preloaderUiTraverse.Field("string_2").SetValue($"{officalVersion} Beta version"); + versionNumberTraverse.Field("Major").SetValue(officalVersion); + } + else + { + preloaderUiTraverse.Field("string_2").SetValue($"FIKA BETA {fikaVersion} | {versionLabel}"); + versionNumberTraverse.Field("Major").SetValue($"{fikaVersion} {versionLabel}"); + } + + //Game version + // preloaderUiTraverse.Field("string_2").SetValue($"Game version"); + //Raid code + // preloaderUiTraverse.Field("string_3").SetValue($"Raid code"); + //Game mode + preloaderUiTraverse.Field("string_4").SetValue("PvE"); + //Update version label + preloaderUiTraverse.Method("method_6").GetValue(); } } } \ No newline at end of file