From 6ae0a87979ec3dc7d2656658097e11fceb18e4bc Mon Sep 17 00:00:00 2001 From: CWX Date: Sun, 8 Oct 2023 09:49:57 +0100 Subject: [PATCH] add new menuItem when hovering over locked door to picklock, currently just opens it --- Live/CWX_LockPicking/CWX_LockPicking.csproj | 6 + Live/CWX_LockPicking/LockPicker.cs | 26 ++-- Live/CWX_LockPicking/LockPickerButtonPatch.cs | 13 -- Live/CWX_LockPicking/LockPickerMenuPatch.cs | 112 ++++++++++++++++++ Live/CWX_LockPicking/LockPickerUIPatch.cs | 22 ---- 5 files changed, 131 insertions(+), 48 deletions(-) delete mode 100644 Live/CWX_LockPicking/LockPickerButtonPatch.cs create mode 100644 Live/CWX_LockPicking/LockPickerMenuPatch.cs delete mode 100644 Live/CWX_LockPicking/LockPickerUIPatch.cs diff --git a/Live/CWX_LockPicking/CWX_LockPicking.csproj b/Live/CWX_LockPicking/CWX_LockPicking.csproj index 5cfb411..395cfbd 100644 --- a/Live/CWX_LockPicking/CWX_LockPicking.csproj +++ b/Live/CWX_LockPicking/CWX_LockPicking.csproj @@ -23,6 +23,12 @@ ..\..\..\Shared\Newtonsoft.Json.dll + + ..\..\..\Shared\UnityEngine.dll + + + ..\..\..\Shared\UnityEngine.AssetBundleModule.dll + ..\..\..\Shared\UnityEngine.CoreModule.dll diff --git a/Live/CWX_LockPicking/LockPicker.cs b/Live/CWX_LockPicking/LockPicker.cs index 58c0faf..1c53725 100644 --- a/Live/CWX_LockPicking/LockPicker.cs +++ b/Live/CWX_LockPicking/LockPicker.cs @@ -1,14 +1,14 @@ -// using BepInEx; -// -// namespace CWX_LockPicking -// { -// [BepInPlugin("com.CWX.LockPicker", "CWX-LockPicker", "1.0.0")] -// public class LockPicker : BaseUnityPlugin -// { -// private void Awake() -// { -// -// } -// } -// } +using BepInEx; + +namespace CWX_LockPicking +{ + [BepInPlugin("com.CWX.LockPicker", "CWX-LockPicker", "1.0.0")] + public class LockPicker : BaseUnityPlugin + { + private void Awake() + { + new LockPickerMenuPatch().Enable(); + } + } +} diff --git a/Live/CWX_LockPicking/LockPickerButtonPatch.cs b/Live/CWX_LockPicking/LockPickerButtonPatch.cs deleted file mode 100644 index 631a308..0000000 --- a/Live/CWX_LockPicking/LockPickerButtonPatch.cs +++ /dev/null @@ -1,13 +0,0 @@ -// using System.Reflection; -// using Aki.Reflection.Patching; -// -// namespace CWX_LockPicking -// { -// public class LockPickerButtonPatch : ModulePatch -// { -// protected override MethodBase GetTargetMethod() -// { -// throw new System.NotImplementedException(); -// } -// } -// } \ No newline at end of file diff --git a/Live/CWX_LockPicking/LockPickerMenuPatch.cs b/Live/CWX_LockPicking/LockPickerMenuPatch.cs new file mode 100644 index 0000000..4de392f --- /dev/null +++ b/Live/CWX_LockPicking/LockPickerMenuPatch.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections; +using System.Linq; +using System.Reflection; +using Aki.Reflection.Patching; +using Aki.Reflection.Utils; +using EFT; +using UnityEngine; +using System.Threading.Tasks; +using EFT.Interactive; + +namespace CWX_LockPicking +{ + public class LockPickerMenuPatch : ModulePatch + { + // TODO: Make Version Agnostic + private static Type playerActionClass; // GClass1726 - smethod_9 on this class + private static Type menuClass; // GClass2804 + private static Type menuItemClass; // GClass2803 + + protected override MethodBase GetTargetMethod() + { + return typeof(GClass1726).GetMethod("smethod_9", BindingFlags.Static | BindingFlags.NonPublic); + } + + [PatchPostfix] + public static void PatchPostFix(ref GClass2804 __result, GamePlayerOwner owner, Door door) + { + // always do this to get rid of the useless interactions + __result.Actions.RemoveAll( + x => x.Name == "Bang & clear" || x.Name == "Flash & clear" || x.Name == "Move in"); + + // make sure its a locked and a door that can be unlocked + if (door.DoorState != EDoorState.Locked || door.KeyId == null || door.KeyId == "") return; + + // add action to unlock door - currently no animation + __result.Actions.Add(new GClass2803 + { + Name = "LockPicking", + Action = () => { door.DoorState = EDoorState.Shut; }, + Disabled = false + }); + } + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + public class TestLock : MonoBehaviour + { + private string _BundlePath = "BepInEx/plugins/CWX/Test/lockpick.bundle"; + public AssetBundle assetBundle; + public async Task LoadLock() + { + var bundleLoadRequest = AssetBundle.LoadFromFileAsync(_BundlePath); + + while (!bundleLoadRequest.isDone) + await Task.Yield(); + + assetBundle = bundleLoadRequest.assetBundle; + + var assetLoadRequest = assetBundle.LoadAllAssetsAsync(); + + while (!assetLoadRequest.isDone) + await Task.Yield(); + + var requestedGo = assetLoadRequest.allAssets[0] as GameObject; + + return requestedGo; + } + + public async void Init() + { + Instantiate(await LoadLock(), new Vector3(0, 0, 0), Quaternion.Euler(new Vector3(0, 0, 0))); + } + } +} \ No newline at end of file diff --git a/Live/CWX_LockPicking/LockPickerUIPatch.cs b/Live/CWX_LockPicking/LockPickerUIPatch.cs deleted file mode 100644 index c5c983e..0000000 --- a/Live/CWX_LockPicking/LockPickerUIPatch.cs +++ /dev/null @@ -1,22 +0,0 @@ -// using System.Reflection; -// using Aki.Reflection.Patching; -// using Aki.Reflection.Utils; -// using EFT.UI; -// -// namespace CWX_LockPicking -// { -// public class LockPickerUIPatch : ModulePatch -// { -// protected override MethodBase GetTargetMethod() -// { -// return typeof(ItemUiContext).GetMethod("GetItemContextInteractions", PatchConstants.PublicFlags); -// } -// -// [PatchPostfix] -// private static void PostFixPatch(ref ItemInfoInteractions __result, ItemUiContext __instance, -// ItemContext itemContext) -// { -// -// } -// } -// } \ No newline at end of file