add SamSWAT.WatchAnims

This commit is contained in:
SamSWAT 2023-02-06 23:14:01 +03:00
parent 1cee7c22ae
commit aa5279cdef
5 changed files with 271 additions and 0 deletions

View File

@ -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

View File

@ -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<GameWorld>.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<string>();
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;
}
}
}

View File

@ -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<IAnimator, AnimatorOverrideController> Controllers;
internal static Dictionary<string, int> SuitsLookup;
internal static AnimationClip[] AnimationClips;
private void Awake()
{
new GamePlayerOwnerPatch().Enable();
Controllers = new Dictionary<IAnimator, AnimatorOverrideController>();
SuitsLookup = new Dictionary<string, int>
{
//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<AnimationClip>();
GameWorld.OnDispose += () => Controllers.Clear();
}
}
}

View File

@ -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")]

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{12AB59CE-2023-43D3-9D2C-C9E71748212A}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SamSWAT.WatchAnims</RootNamespace>
<AssemblyName>SamSWAT.WatchAnims</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\..\References\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Aki.Reflection">
<HintPath>..\..\References\Aki.Reflection.dll</HintPath>
</Reference>
<Reference Include="AnimationSystem.Types">
<HintPath>..\..\References\AnimationSystem.Types.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\References\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>..\..\References\BepInEx.dll</HintPath>
</Reference>
<Reference Include="Comfort">
<HintPath>..\..\References\Comfort.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="UnityEngine">
<HintPath>..\..\References\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AnimationModule">
<HintPath>..\..\References\UnityEngine.AnimationModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AssetBundleModule">
<HintPath>..\..\References\UnityEngine.AssetBundleModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\References\UnityEngine.CoreModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="GamePlayerOwnerPatch.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>