add SamSWAT.ReflexSightsRework

This commit is contained in:
SamSWAT 2022-11-20 02:37:52 +03:00
parent 2b575cf5b4
commit 3b32320cd9
9 changed files with 262 additions and 0 deletions

View File

@ -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<string[]>());
BundleManager.Bundles.Add(key, bundle);
}
}
}
}

View File

@ -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<SightSwitch>();
}
if (_instances.Length == 0) return;
TotalErgonomics = ___firearmController_0.TotalErgonomics;
Overweight = __instance.Overweight;
foreach (var instance in _instances) instance.enabled = value;
}
}
}

View File

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

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

View File

@ -0,0 +1,80 @@
<?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>{07713760-1520-42C4-8C6A-1AAEB7445659}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SamSWAT.ReflexSightsRework</RootNamespace>
<AssemblyName>SamSWAT.ReflexSightsRework</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="aki-bundles, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\References\aki-bundles.dll</HintPath>
</Reference>
<Reference Include="Aki.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\References\Aki.Common.dll</HintPath>
</Reference>
<Reference Include="Aki.Reflection, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\References\Aki.Reflection.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\References\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="BepInEx, Version=5.4.21.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\References\BepInEx.dll</HintPath>
</Reference>
<Reference Include="Comfort, Version=1.0.0.4, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\References\Comfort.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
<HintPath>..\..\References\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System"/>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\References\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\References\UnityEngine.CoreModule.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Patch.cs"/>
<Compile Include="SightSwitch.cs"/>
<Compile Include="Plugin.cs"/>
<Compile Include="Properties\AssemblyInfo.cs"/>
<Compile Include="BundleLoader.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>

View File

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

View File

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

Binary file not shown.

BIN
References/aki-bundles.dll Normal file

Binary file not shown.