Skip to content

Commit

Permalink
Merge pull request #68 from yhl452493373/version-label-3.9-dev
Browse files Browse the repository at this point in the history
Add Offical version option and raid code
  • Loading branch information
Lacyway authored Jun 18, 2024
2 parents b1d472c + cebca2a commit c3cae3b
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 8 deletions.
23 changes: 22 additions & 1 deletion Fika.Core/Coop/Utils/FikaBackendUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Fika.Core.Networking.Http.Models;
using System;
using System.Reflection;
using Fika.Core.EssentialPatches;

namespace Fika.Core.Coop.Utils
{
Expand Down Expand Up @@ -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;
}
}
}
15 changes: 14 additions & 1 deletion Fika.Core/FikaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public class FikaPlugin : BaseUnityPlugin
// Hidden
public static ConfigEntry<bool> AcceptedTOS { get; set; }

//Advanced
public static ConfigEntry<bool> OfficialVersion { get; set; }

// Coop
public static ConfigEntry<bool> ShowNotifications { get; set; }
public static ConfigEntry<bool> AutoExtract { get; set; }
Expand Down Expand Up @@ -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();
Expand All @@ -206,7 +210,8 @@ protected void Awake()
#if GOLDMASTER
new TOS_Patch().Enable();
#endif

OfficialVersion.SettingChanged += OfficialVersion_SettingChanged;

DisableSPTPatches();
EnableOverridePatches();

Expand Down Expand Up @@ -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 }));
Expand Down Expand Up @@ -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()
{
Expand Down
6 changes: 5 additions & 1 deletion Fika.Core/Networking/Models/CreateMatchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
40 changes: 40 additions & 0 deletions Fika.Core/UI/Patches/FikaVersionLabelUpdate_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Reflection;
using EFT;
using EFT.UI;
using HarmonyLib;
using SPT.Reflection.Patching;

namespace Fika.Core.EssentialPatches
{
/// <summary>
/// Update version label with raid code when game started
/// </summary>
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<PreloaderUI>.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();
}
}
}
}
45 changes: 40 additions & 5 deletions Fika.Core/UI/Patches/FikaVersionLabel_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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<PreloaderUI>.Instance);
Traverse preloaderUiTraverse= Traverse.Create(MonoBehaviourSingleton<PreloaderUI>.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<PreloaderUI>.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();
}
}
}

0 comments on commit c3cae3b

Please sign in to comment.