Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BSIPA 4.3.0 #57

Merged
merged 4 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions SiraUtil.Suite/Tests/Sabers/TestSaberModelController.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
using SiraUtil.Interfaces;
using UnityEngine;
using Zenject;

namespace SiraUtil.Suite.Tests.Sabers
{
internal class TestSaberModelController : SaberModelController, IColorable
internal class TestSaberModelController : SaberModelController, IColorable, IPreSaberModelInit
{
public Color Color { get; set; }

public override void Init(Transform parent, Saber saber)
[Inject]
private readonly ColorManager _colorManager = null!;

public void PreInit(Transform parent, Saber saber)
{
Color = _colorManager.ColorForSaberType(saber.saberType);
GameObject g = GameObject.CreatePrimitive(PrimitiveType.Sphere);
g.transform.localScale *= 0.1f;
g.transform.SetParent(transform);
g.transform.localPosition = new Vector3(0f, 0f, 1f);
base.Init(parent, saber);
}
}
}
1 change: 1 addition & 0 deletions SiraUtil/Installers/SiraInitializationInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public SiraInitializationInstaller(Zenjector siraUtil, ZenjectManager zenjectMan
public override void InstallBindings()
{
Container.BindInterfacesTo<FPFCFixDaemon>().AsSingle();
Container.BindInterfacesTo<InputSpoofFPFCListener>().AsSingle();

// Install all UBinders
foreach (var zenjector in _zenjectManager.ActiveZenjectors)
Expand Down
17 changes: 17 additions & 0 deletions SiraUtil/Interfaces/IPostSaberModelInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEngine;

namespace SiraUtil.Interfaces
{
/// <summary>
/// Defines for something to be run after a saber model initializes.
/// </summary>
public interface IPostSaberModelInit
{
/// <summary>
/// Runs after model initialization.
/// </summary>
/// <param name="parent">The parent of the saber model.</param>
/// <param name="saber">The saber component associated with the current model.</param>
void PostInit(Transform parent, Saber saber);
}
}
18 changes: 18 additions & 0 deletions SiraUtil/Interfaces/IPreSaberModelInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using UnityEngine;

namespace SiraUtil.Interfaces
{
/// <summary>
/// Defines for something to be run before a saber model initializes.
/// </summary>
public interface IPreSaberModelInit
{
/// <summary>
/// Runs before model initialization.
/// </summary>
/// <param name="parent">The parent of the saber model.</param>
/// <param name="saber">The saber component associated with the current model.</param>
/// <returns>Do you want the original Init to run?</returns>
bool PreInit(Transform parent, Saber saber);
}
}
51 changes: 26 additions & 25 deletions SiraUtil/Sabers/Effects/SiraSaberClashChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@

namespace SiraUtil.Sabers.Effects
{
internal class SiraSaberClashChecker : SaberClashChecker
internal interface ISiraClashChecker
{
event Action<Saber, Saber>? NewSabersClashed;

bool ExtraSabersDetected { get; }

bool AreSabersClashing(ref bool sabersAreClashing, ref Vector3 localClashingPoint, ref int prevGetFrameNum, out Vector3 clashingPoint);
}

internal class SiraSaberClashChecker : SaberClashChecker, ISiraClashChecker
{
private Saber? _lastSaberA;
private Saber? _lastSaberB;
private bool _extraSabersDetected;
private readonly HashSet<Saber> _sabers = new();
public event Action<Saber, Saber>? NewSabersClashed;

protected readonly DiContainer _container;
protected readonly SaberManager _saberManager;
protected readonly SiraSaberFactory _siraSaberFactory;

public bool ExtraSabersDetected { get; private set; }

public SiraSaberClashChecker(DiContainer container, SaberManager saberManager, SiraSaberFactory siraSaberFactory)
{
_container = container;
Expand All @@ -30,7 +40,7 @@ public SiraSaberClashChecker(DiContainer container, SaberManager saberManager, S

private void SiraSaberFactory_SaberCreated(SiraSaber siraSaber)
{
_extraSabersDetected = true;
ExtraSabersDetected = true;
_sabers.Add(siraSaber.Saber);
}

Expand All @@ -39,28 +49,19 @@ private void SiraSaberFactory_SaberCreated(SiraSaber siraSaber)
_siraSaberFactory.SaberCreated -= SiraSaberFactory_SaberCreated;
}

/// <summary>
/// Checks if any of the registered sabers are clashing.
/// </summary>
/// <param name="clashingPoint">The point that the sabers are clashing at.</param>
/// <returns>Are any sabers clashing?</returns>
public override bool AreSabersClashing(out Vector3 clashingPoint)
public bool AreSabersClashing(ref bool sabersAreClashing, ref Vector3 localClashingPoint, ref int prevGetFrameNum, out Vector3 clashingPoint)
{
if (!_extraSabersDetected)
{
return base.AreSabersClashing(out clashingPoint);
}
if (_leftSaber.movementData.lastAddedData.time < 0.1f)
{
clashingPoint = _clashingPoint;
clashingPoint = localClashingPoint;
return false;
}
if (_prevGetFrameNum == Time.frameCount)
if (prevGetFrameNum == Time.frameCount)
{
clashingPoint = _clashingPoint;
return _sabersAreClashing;
clashingPoint = localClashingPoint;
return sabersAreClashing;
}
_prevGetFrameNum = Time.frameCount;
prevGetFrameNum = Time.frameCount;
for (int i = 0; i < _sabers.Count; i++)
{
for (int h = 0; h < _sabers.Count; h++)
Expand All @@ -86,22 +87,22 @@ public override bool AreSabersClashing(out Vector3 clashingPoint)
_lastSaberB = saberB;
NewSabersClashed?.Invoke(_lastSaberA, _lastSaberB);
}
_clashingPoint = clashingPoint2;
clashingPoint = _clashingPoint;
_sabersAreClashing = true;
return _sabersAreClashing;
localClashingPoint = clashingPoint2;
clashingPoint = localClashingPoint;
sabersAreClashing = true;
return sabersAreClashing;
}
else
{
_lastSaberA = null;
_lastSaberB = null;
_sabersAreClashing = false;
sabersAreClashing = false;
}
}
}
}
clashingPoint = _clashingPoint;
return _sabersAreClashing;
clashingPoint = localClashingPoint;
return sabersAreClashing;
}
}
}
17 changes: 17 additions & 0 deletions SiraUtil/Sabers/Effects/SiraSaberClashCheckerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using UnityEngine;
using Zenject;

namespace SiraUtil.Sabers.Effects
Expand Down Expand Up @@ -39,6 +40,22 @@ public static IEnumerable<CodeInstruction> Upgrade(IEnumerable<CodeInstruction>

}

[HarmonyPatch(typeof(SaberClashChecker), nameof(SaberClashChecker.AreSabersClashing))]
private class DefaultOverride
{
[HarmonyPrefix]
public static bool OverrideDefault(ref SaberClashChecker __instance, ref bool ____sabersAreClashing, ref Vector3 ____clashingPoint, ref int ____prevGetFrameNum, ref bool __result, out Vector3 clashingPoint)
{
if (__instance is not ISiraClashChecker customClashChecker || !customClashChecker.ExtraSabersDetected)
{
clashingPoint = Vector3.zero;
return true;
}
__result = customClashChecker.AreSabersClashing(ref ____sabersAreClashing, ref ____clashingPoint, ref ____prevGetFrameNum, out clashingPoint);
return false;
}
}

internal static void Upgrade(ref List<CodeInstruction> codes)
{
for (int i = 0; i < codes.Count; i++)
Expand Down
24 changes: 24 additions & 0 deletions SiraUtil/Sabers/SaberModelProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using IPA.Utilities;
using SiraUtil.Affinity;
using SiraUtil.Extras;
using SiraUtil.Interfaces;
using SiraUtil.Logging;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -168,5 +169,28 @@ private void DefaultSaberPrefabSwap(ref SaberModelContainer __instance, ref Sabe

____saberModelControllerPrefab = NewModel(____saber.saberType);
}

[AffinityPrefix]
[AffinityPatch(typeof(SaberModelController), nameof(SaberModelController.Init))]
private bool PreInit(ref SaberModelController __instance, Transform parent, Saber saber)
{
var runner = __instance.GetComponent<IPreSaberModelInit>();
if (runner == null)
return true;

return runner.PreInit(parent, saber);
}


[AffinityPostfix]
[AffinityPatch(typeof(SaberModelController), nameof(SaberModelController.Init))]
private void PostInit(ref SaberModelController __instance, Transform parent, Saber saber)
{
var runner = __instance.GetComponent<IPostSaberModelInit>();
if (runner == null)
return;

runner.PostInit(parent, saber);
}
}
}
42 changes: 23 additions & 19 deletions SiraUtil/SiraUtil.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<AssemblyName>SiraUtil</AssemblyName>
<RootNamespace>SiraUtil</RootNamespace>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<BSMTProjectType>BSIPA</BSMTProjectType>
<SignAssembly>false</SignAssembly>
</PropertyGroup>

Expand Down Expand Up @@ -92,18 +93,22 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Rendering.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Unity.TextMeshPro">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Unity.TextMeshPro.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.AudioModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.AudioModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
<Private>False</Private>
Expand All @@ -112,14 +117,14 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.ParticleSystemModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.SpatialTracking">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.SpatialTracking.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UIElementsModule">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.UIElementsModule.dll</HintPath>
<Private>False</Private>
Expand All @@ -142,6 +147,7 @@
</Reference>
<Reference Include="Main">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Main.dll</HintPath>
<Publicize>True</Publicize>
<Private>False</Private>
</Reference>
<Reference Include="HMLib">
Expand All @@ -162,6 +168,7 @@
</Reference>
<Reference Include="VRUI">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\VRUI.dll</HintPath>
<Publicize>True</Publicize>
<Private>False</Private>
</Reference>
<Reference Include="Zenject">
Expand All @@ -184,23 +191,20 @@
</ItemGroup>

<ItemGroup>
<None Include="SiraUtil.csproj.user"
Condition="Exists('SiraUtil.csproj.user')"
Visible="false" />
<None Include="Directory.Build.props"
Condition="Exists('Directory.Build.props')"
Visible="false" />
<None Include="Directory.Build.targets"
Condition="Exists('Directory.Build.targets')"
Visible="false" />
<None Include="SiraUtil.csproj.user" Condition="Exists('SiraUtil.csproj.user')" Visible="false" />
<None Include="Directory.Build.props" Condition="Exists('Directory.Build.props')" Visible="false" />
<None Include="Directory.Build.targets" Condition="Exists('Directory.Build.targets')" Visible="false" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BeatSaberModdingTools.Tasks"
Version="1.3.2">
<PackageReference Include="BeatSaberModdingTools.Tasks" Version="2.0.0-beta7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
Loading