diff --git a/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims.sln b/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims.sln new file mode 100644 index 0000000..0d44806 --- /dev/null +++ b/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamSWAT.WatchAnims", "SamSWAT.WatchAnims\SamSWAT.WatchAnims.csproj", "{12AB59CE-2023-43D3-9D2C-C9E71748212A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {12AB59CE-2023-43D3-9D2C-C9E71748212A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {12AB59CE-2023-43D3-9D2C-C9E71748212A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {12AB59CE-2023-43D3-9D2C-C9E71748212A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {12AB59CE-2023-43D3-9D2C-C9E71748212A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims/GamePlayerOwnerPatch.cs b/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims/GamePlayerOwnerPatch.cs new file mode 100644 index 0000000..56833d5 --- /dev/null +++ b/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims/GamePlayerOwnerPatch.cs @@ -0,0 +1,71 @@ +using System.Collections; +using System.Reflection; +using Aki.Reflection.Patching; +using Comfort.Common; +using EFT; +using EFT.InputSystem; +using HarmonyLib; +using UnityEngine; + +namespace SamSWAT.WatchAnims +{ + public class GamePlayerOwnerPatch : ModulePatch + { + private const string STATE_NAME = "hand_nv_on"; + private static AnimationClip _defaultClip; + private static Coroutine _coroutine; + + protected override MethodBase GetTargetMethod() + { + return AccessTools.Method(typeof(GamePlayerOwner), "TranslateCommand"); + } + + [PatchPostfix] + private static void PatchPostfix(ECommand command) + { + if (command != ECommand.DisplayTimer && command != ECommand.DisplayTimerAndExits) return; + + var player = Singleton.Instance.AllPlayers[0]; + + if (player.Side == EPlayerSide.Savage) return; + + var animator = player.HandsController.FirearmsAnimator.Animator; + var animIndex = GetAnimIndex(player); + + if (Plugin.Controllers.TryGetValue(animator, out var overrideController)) + { + StaticManager.KillCoroutine(_coroutine); + overrideController[STATE_NAME] = Plugin.AnimationClips[animIndex]; + } + else + { + overrideController = CreateOverrideController(animator, animIndex); + } + + player.HandsController.Interact(true, 21); + _coroutine = StaticManager.BeginCoroutine(Wait(Plugin.AnimationClips[animIndex].length, overrideController)); + } + + private static AnimatorOverrideController CreateOverrideController(IAnimator animator, int animIndex) + { + var overrideController = new AnimatorOverrideController(animator.runtimeAnimatorController); + _defaultClip = overrideController[STATE_NAME]; + overrideController[STATE_NAME] = Plugin.AnimationClips[animIndex]; + Plugin.Controllers.Add(animator, overrideController); + animator.runtimeAnimatorController = overrideController; + return overrideController; + } + + private static int GetAnimIndex(Player player) + { + var suit = Traverse.Create(player.PlayerBody.BodyCustomizationId).Method("get_Value").GetValue(); + return Plugin.SuitsLookup.TryGetValue(suit, out var index) ? index : 0; + } + + private static IEnumerator Wait(float time, AnimatorOverrideController controller) + { + yield return new WaitForSecondsRealtime(time + 0.3f); + controller[STATE_NAME] = _defaultClip; + } + } +} \ No newline at end of file diff --git a/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims/Plugin.cs b/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims/Plugin.cs new file mode 100644 index 0000000..10106d6 --- /dev/null +++ b/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims/Plugin.cs @@ -0,0 +1,68 @@ +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using BepInEx; +using EFT; +using UnityEngine; + +namespace SamSWAT.WatchAnims +{ + [BepInPlugin("com.samswat.watchanims", "SamSWAT.WatchAnims", "1.0.0")] + public class Plugin : BaseUnityPlugin + { + internal static Dictionary Controllers; + internal static Dictionary SuitsLookup; + internal static AnimationClip[] AnimationClips; + + private void Awake() + { + new GamePlayerOwnerPatch().Enable(); + Controllers = new Dictionary(); + SuitsLookup = new Dictionary + { + //bear + {"5cc0858d14c02e000c6bea66", 0}, + {"5fce3e47fe40296c1d5fd784", 0}, + {"6377266693a3b4967208e42b", 0}, + {"5d1f565786f7743f8362bcd5", 0}, + {"5fce3e0cfe40296c1d5fd782", 0}, + {"5d1f566d86f7744bcd13459a", 0}, + {"5d1f568486f7744bca3f0b98", 0}, + {"5f5e401747344c2e4f6c42c5", 0}, + {"5d1f567786f7744bcc04874f", 0}, + {"5d1f564b86f7744bcb0acd16", 0}, + {"6295e698e9de5e7b3751c47a", 0}, + {"5e4bb31586f7740695730568", 0}, + {"5e9d9fa986f774054d6b89f2", 0}, + {"5df89f1f86f77412631087ea", 0}, + {"617bca4b4013b06b0b78df2a", 0}, + {"6033a31e9ec839204e6a2f3e", 0}, + + //usec + {"5cde95d97d6c8b647a3769b0", 1}, + {"5d1f56f186f7744bcb0acd1a", 0}, + {"637b945722e2a933ed0e33c8", 1}, + {"6033a35f80ae5e2f970ba6bb", 0}, + {"5fd3e9f71b735718c25cd9f8", 1}, + {"5d1f56c686f7744bcd13459c", 0}, + {"618109c96d7ca35d076b3363", 1}, + {"6295e8c3e08ed747e64aea00", 1}, + {"5d4da0cb86f77450fe0a6629", 0}, + {"5d1f56e486f7744bce0ee9ed", 0}, + {"5e9da17386f774054b6f79a3", 0}, + {"5d1f56ff86f7743f8362bcd7", 0}, + {"5d1f56a686f7744bce0ee9eb", 0}, + {"5fcf63da5c287f01f22bf245", 1}, + {"5e4bb35286f77406a511c9bc", 1}, + {"5f5e4075df4f3100376a8138", 1}, + + //??? + {"5cdea33e7d6c8b0474535dac", 0} + //default = 0 + }; + var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); + AnimationClips = AssetBundle.LoadFromFile($"{directory}/bundles/watch animations.bundle").LoadAllAssets(); + GameWorld.OnDispose += () => Controllers.Clear(); + } + } +} \ No newline at end of file diff --git a/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims/Properties/AssemblyInfo.cs b/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..84ee413 --- /dev/null +++ b/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims/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.WatchAnims")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SamSWAT.WatchAnims")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[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("12AB59CE-2023-43D3-9D2C-C9E71748212A")] + +// 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.WatchAnims/SamSWAT.WatchAnims/SamSWAT.WatchAnims.csproj b/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims/SamSWAT.WatchAnims.csproj new file mode 100644 index 0000000..cf30cbb --- /dev/null +++ b/Projects/SamSWAT.WatchAnims/SamSWAT.WatchAnims/SamSWAT.WatchAnims.csproj @@ -0,0 +1,81 @@ + + + + + Debug + AnyCPU + {12AB59CE-2023-43D3-9D2C-C9E71748212A} + Library + Properties + SamSWAT.WatchAnims + SamSWAT.WatchAnims + v4.7.2 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\References\0Harmony.dll + + + ..\..\References\Aki.Reflection.dll + + + ..\..\References\AnimationSystem.Types.dll + + + ..\..\References\Assembly-CSharp.dll + + + ..\..\References\BepInEx.dll + + + ..\..\References\Comfort.dll + + + + ..\..\References\UnityEngine.dll + + + ..\..\References\UnityEngine.AnimationModule.dll + + + ..\..\References\UnityEngine.AssetBundleModule.dll + + + ..\..\References\UnityEngine.CoreModule.dll + + + + + + + + + + +