Skip to content

Commit

Permalink
Merge pull request #201 from project-fika/fix/patch-VFS
Browse files Browse the repository at this point in the history
Fix/patch VFS
  • Loading branch information
Lacyway authored Nov 29, 2024
2 parents e15d8a6 + 183d2c6 commit 40a8898
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
29 changes: 29 additions & 0 deletions Fika.Core/Coop/Patches/SPTBugs/FixVFSDeleteFilePatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using SPT.Reflection.Patching;
using System.Reflection;
using SPT.Common.Utils;

namespace Fika.Core.Coop.Patches.SPTBugs
{
// This patch fixes a bug in SPT 3.10.0 where SPT's git history was out of date thus causing it to run this code early.
// It will be fixed in SPT 3.10.1, but to keep backwards compatibility keep this patch in until 3.11 for players that refuse to update their SPT version.
internal class FixVFSDeleteFilePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(VFS).GetMethod(nameof(VFS.DeleteFile));
}

[PatchPrefix]
public static bool Prefix(string filepath)
{
if (VFS.Exists(filepath))
{
// Run the orginal method.
return true;
}

// Skip method
return false;
}
}
}
2 changes: 2 additions & 0 deletions Fika.Core/FikaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ protected void Awake()
SetupConfigEventHandlers();

DisableSPTPatches();
FixSPTBugPatches();
EnableOverridePatches();

GetClientConfig();
Expand Down Expand Up @@ -742,6 +743,7 @@ public void FixSPTBugPatches()
{
new FixAirdropCrashPatch().Disable();
new FixAirdropCrashPatch_Override().Enable();
new FixVFSDeleteFilePatch().Enable();
}
}

Expand Down
12 changes: 6 additions & 6 deletions Fika.Core/Utils/FikaModHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public class FikaModHandler

public Version SPTCoreVersion { get; private set; }

public FikaModHandler()
{
Chainloader.PluginInfos.TryGetValue("com.SPT.core", out PluginInfo pluginInfo);
SPTCoreVersion = pluginInfo.Metadata.Version;
}

public void VerifyMods()
{
PluginInfo[] pluginInfos = [.. Chainloader.PluginInfos.Values];
Expand All @@ -45,12 +51,6 @@ public void VerifyMods()
loadedMods.Add(pluginInfo.Metadata.GUID, crc32);
logger.LogInfo($"Loaded plugin: [{pluginInfo.Metadata.Name}] with GUID [{pluginInfo.Metadata.GUID}] and crc32 [{crc32}]");

if (pluginInfo.Metadata.GUID == "com.SPT.core")
{
SPTCoreVersion = pluginInfo.Metadata.Version;
FikaPlugin.Instance.FixSPTBugPatches();
}

CheckSpecialMods(pluginInfo.Metadata.GUID);
}

Expand Down

0 comments on commit 40a8898

Please sign in to comment.