diff --git a/Projects/SamSWAT.ReflexSightsRework/BundleLoader.cs b/Projects/SamSWAT.ReflexSightsRework/BundleLoader.cs new file mode 100644 index 0000000..767b26f --- /dev/null +++ b/Projects/SamSWAT.ReflexSightsRework/BundleLoader.cs @@ -0,0 +1,33 @@ +using System.Reflection; +using Aki.Bundles.Models; +using Aki.Bundles.Utils; +using Aki.Common.Utils; +using Aki.Reflection.Patching; +using Newtonsoft.Json.Linq; + +namespace SamSWAT.ReflexSightsRework +{ + public class BundleLoader : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return typeof(BundleManager).GetMethod(nameof(BundleManager.GetBundles)); + } + + [PatchPostfix] + private static void PatchPostfix() + { + var json = VFS.ReadTextFile(Plugin.Directory + "bundles.json"); + var jArray = JArray.Parse(json); + + foreach (var jObj in jArray) + { + var key = jObj["key"].ToString(); + var path = jObj["path"].ToString(); + var bundle = new BundleInfo(key, path, jObj["dependencyKeys"].ToObject()); + + BundleManager.Bundles.Add(key, bundle); + } + } + } +} \ No newline at end of file diff --git a/Projects/SamSWAT.ReflexSightsRework/Patch.cs b/Projects/SamSWAT.ReflexSightsRework/Patch.cs new file mode 100644 index 0000000..d175979 --- /dev/null +++ b/Projects/SamSWAT.ReflexSightsRework/Patch.cs @@ -0,0 +1,42 @@ +using System.Linq; +using System.Reflection; +using Aki.Reflection.Patching; +using EFT; +using EFT.Animations; +using UnityEngine; + +namespace SamSWAT.ReflexSightsRework +{ + public class Patch : ModulePatch + { + public static float TotalErgonomics; + public static float Overweight; + private static Transform _currentWeapon; + private static SightSwitch[] _instances; + + protected override MethodBase GetTargetMethod() + { + return typeof(ProceduralWeaponAnimation).GetMethod("set_IsAiming"); + } + + [PatchPostfix] + private static void PatchPostfix(bool value, ProceduralWeaponAnimation __instance, + Player.FirearmController ___firearmController_0) + { + if (___firearmController_0 == null) return; + + if (_currentWeapon != ___firearmController_0.WeaponRoot || _instances.Any(x => x.gameObject.activeSelf == false)) + { + _currentWeapon = ___firearmController_0.WeaponRoot; + _instances = _currentWeapon.GetComponentsInChildren(); + } + + if (_instances.Length == 0) return; + + TotalErgonomics = ___firearmController_0.TotalErgonomics; + Overweight = __instance.Overweight; + + foreach (var instance in _instances) instance.enabled = value; + } + } +} \ No newline at end of file diff --git a/Projects/SamSWAT.ReflexSightsRework/Plugin.cs b/Projects/SamSWAT.ReflexSightsRework/Plugin.cs new file mode 100644 index 0000000..583cc29 --- /dev/null +++ b/Projects/SamSWAT.ReflexSightsRework/Plugin.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using Aki.Common.Utils; +using BepInEx; + +namespace SamSWAT.ReflexSightsRework +{ + [BepInPlugin("com.samswat.reflexsightsrework", "SamSWAT.ReflexSightsRework", "1.0.0")] + public class Plugin : BaseUnityPlugin + { + public static string Directory { get; private set; } + + private void Awake() + { + Directory = Assembly.GetExecutingAssembly().Location.GetDirectory() + @"\"; + + new BundleLoader().Enable(); + new Patch().Enable(); + } + } +} \ No newline at end of file diff --git a/Projects/SamSWAT.ReflexSightsRework/Properties/AssemblyInfo.cs b/Projects/SamSWAT.ReflexSightsRework/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c75e2cf --- /dev/null +++ b/Projects/SamSWAT.ReflexSightsRework/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SamSWAT.ReflexSightsRework")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SamSWAT.ReflexSightsRework")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("07713760-1520-42C4-8C6A-1AAEB7445659")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/Projects/SamSWAT.ReflexSightsRework/SamSWAT.ReflexSightsRework.csproj b/Projects/SamSWAT.ReflexSightsRework/SamSWAT.ReflexSightsRework.csproj new file mode 100644 index 0000000..803b033 --- /dev/null +++ b/Projects/SamSWAT.ReflexSightsRework/SamSWAT.ReflexSightsRework.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {07713760-1520-42C4-8C6A-1AAEB7445659} + Library + Properties + SamSWAT.ReflexSightsRework + SamSWAT.ReflexSightsRework + v4.7.2 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\References\aki-bundles.dll + + + ..\..\References\Aki.Common.dll + + + ..\..\References\Aki.Reflection.dll + + + ..\..\References\Assembly-CSharp.dll + + + ..\..\References\BepInEx.dll + + + ..\..\References\Comfort.dll + + + ..\..\References\Newtonsoft.Json.dll + + + + ..\..\References\UnityEngine.dll + + + ..\..\References\UnityEngine.CoreModule.dll + + + + + + + + + + + + + diff --git a/Projects/SamSWAT.ReflexSightsRework/SamSWAT.ReflexSightsRework.sln b/Projects/SamSWAT.ReflexSightsRework/SamSWAT.ReflexSightsRework.sln new file mode 100644 index 0000000..c17afcd --- /dev/null +++ b/Projects/SamSWAT.ReflexSightsRework/SamSWAT.ReflexSightsRework.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamSWAT.ReflexSightsRework", "SamSWAT.ReflexSightsRework.csproj", "{07713760-1520-42C4-8C6A-1AAEB7445659}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {07713760-1520-42C4-8C6A-1AAEB7445659}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07713760-1520-42C4-8C6A-1AAEB7445659}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07713760-1520-42C4-8C6A-1AAEB7445659}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07713760-1520-42C4-8C6A-1AAEB7445659}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Projects/SamSWAT.ReflexSightsRework/SightSwitch.cs b/Projects/SamSWAT.ReflexSightsRework/SightSwitch.cs new file mode 100644 index 0000000..5e341e6 --- /dev/null +++ b/Projects/SamSWAT.ReflexSightsRework/SightSwitch.cs @@ -0,0 +1,36 @@ +using System.Collections; +using EFT; +using UnityEngine; + +namespace SamSWAT.ReflexSightsRework +{ + public class SightSwitch : MonoBehaviour + { + [SerializeField] private GameObject normalMesh; + [SerializeField] private GameObject adsMesh; + + private void OnEnable() + { + var delay = Patch.Overweight > 0 || Patch.TotalErgonomics < 30 ? 0.12f : 0f; + StaticManager.BeginCoroutine(DelayCoroutine(delay)); + } + + private void OnDisable() + { + SwitchMeshes(); + } + + private void SwitchMeshes() + { + if (normalMesh == null) return; + normalMesh.SetActive(!normalMesh.activeSelf); + adsMesh.SetActive(!adsMesh.activeSelf); + } + + private IEnumerator DelayCoroutine(float delay) + { + yield return new WaitForSeconds(delay); + SwitchMeshes(); + } + } +} \ No newline at end of file diff --git a/References/Assembly-CSharp.dll b/References/Assembly-CSharp.dll index 23cbaaa..52df8ce 100644 Binary files a/References/Assembly-CSharp.dll and b/References/Assembly-CSharp.dll differ diff --git a/References/aki-bundles.dll b/References/aki-bundles.dll new file mode 100644 index 0000000..b25c40e Binary files /dev/null and b/References/aki-bundles.dll differ