Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/knah/VRCMods
Browse files Browse the repository at this point in the history
  • Loading branch information
xAstroBoy committed Jun 20, 2022
2 parents 071965b + 72bd9f0 commit 9b4e748
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 125 deletions.
2 changes: 1 addition & 1 deletion AdvancedSafety/AdvancedSafety.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<VrcReferences>true</VrcReferences>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<Version>1.6.1.0</Version>
<Version>1.6.2.0</Version>
<UsesNativePatches>true</UsesNativePatches>
</PropertyGroup>

Expand Down
25 changes: 2 additions & 23 deletions AdvancedSafety/AdvancedSafetyMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using Object = UnityEngine.Object;

[assembly:MelonGame("VRChat", "VRChat")]
[assembly:MelonInfo(typeof(AdvancedSafetyMod), "Advanced Safety", "1.6.1", "knah, Requi, Ben", "https://github.com/xAstroBoy/VRCMods-Unchained")]
[assembly:MelonInfo(typeof(AdvancedSafetyMod), "Advanced Safety", "1.6.2", "knah, Requi, Ben", "https://github.com/knah/VRCMods")]
[assembly:MelonOptionalDependencies("UIExpansionKit")]

namespace AdvancedSafety
Expand All @@ -31,31 +31,10 @@ internal partial class AdvancedSafetyMod : MelonMod

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void VoidDelegate(IntPtr thisPtr, IntPtr nativeMethodInfo);
private static readonly Func<VRCUiManager> ourGetUiManager;

static AdvancedSafetyMod()
{
ourGetUiManager = (Func<VRCUiManager>)Delegate.CreateDelegate(typeof(Func<VRCUiManager>), typeof(VRCUiManager)
.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly)
.First(it => it.PropertyType == typeof(VRCUiManager)).GetMethod);
}

internal static VRCUiManager GetUiManager() => ourGetUiManager();

private static void DoAfterUiManagerInit(Action code)
{
MelonCoroutines.Start(OnUiManagerInitCoro(code));
}

private static IEnumerator OnUiManagerInitCoro(Action code)
{
while (GetUiManager() == null)
yield return null;
code();
}

public override void OnApplicationStart()
{
if (!CheckWasSuccessful || !MustStayTrue || MustStayFalse) return;

AdvancedSafetySettings.RegisterSettings();
ClassInjector.RegisterTypeInIl2Cpp<SortingOrderHammerer>();
Expand Down
Binary file modified AdvancedSafety/BundleVerifier/BundleVerifier.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion AdvancedSafety/BundleVerifier/BundleVerifierMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static IEnumerator CheckInstanceType()
MelonDebug.Msg($"Got instance, intercept state: {BundleDlInterceptor.ShouldIntercept}");
}

private const string VerifierVersion = "1.2-2019.4.31";
private const string VerifierVersion = "1.4-2019.4.31";
internal const string SettingsCategory = "ASBundleVerifier";

private static void PrepareVerifierDir()
Expand Down
12 changes: 3 additions & 9 deletions FavCat/FavCat.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VrcReferences>true</VrcReferences>
<TargetFramework>net48</TargetFramework>
<TargetFramework>net472</TargetFramework>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<ClearOutputDirectory>False</ClearOutputDirectory>
<AssemblyVersion>1.1.15.0</AssemblyVersion>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ClearOutputDirectory>False</ClearOutputDirectory>
<VRChatFolder>D:\SteamLibrary\steamapps\common\VRChat</VRChatFolder>
<MelonManaged>$(VRChatFolder)\MelonLoader\Managed</MelonManaged>
<MelonLoader>$(VRChatFolder)\MelonLoader</MelonLoader>
<AssemblyVersion>1.1.16.0</AssemblyVersion>
<UsesNativePatches>true</UsesNativePatches>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -41,8 +36,7 @@
<InputAssemblies Include="$(OutputPath)/System.Runtime.CompilerServices.Unsafe.dll" />

<IlRepackLibs Include="$(OutputPath)" />
<IlRepackLibs Include="$(MelonManaged)" />
<IlRepackLibs Include="$(MelonLoader)" />
<IlRepackLibs Include="$(MsBuildThisFileDirectory)/../Libs" />
</ItemGroup>
<Message Text="MERGING: @(InputAssemblies->'%(Filename)') into $(OutputAssembly)" Importance="High" />
<ILRepack Internalize="true" LibraryPath="@(IlRepackLibs)" OutputFile="$(OutputPath)/$(AssemblyName)-merged.dll" InputAssemblies="@(InputAssemblies)" />
Expand Down
78 changes: 32 additions & 46 deletions FavCat/FavCatMod.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -11,7 +10,6 @@
using HarmonyLib;
using MelonLoader;
using UIExpansionKit.API;
using UnhollowerBaseLib;
using UnhollowerRuntimeLib;
using UnityEngine;
using UnityEngine.Networking;
Expand All @@ -20,7 +18,7 @@
using ImageDownloaderClosure = ImageDownloader.__c__DisplayClass11_0;
using Object = UnityEngine.Object;

[assembly:MelonInfo(typeof(FavCatMod), "FavCat Unchained", "1.1.15~unchained", "knah & xAstroBoy", "https://github.com/xAstroBoy/VRCMods-Unchained")]
[assembly:MelonInfo(typeof(FavCatMod), "FavCat", "1.1.16", "knah", "https://github.com/knah/VRCMods")]
[assembly:MelonGame("VRChat", "VRChat")]

namespace FavCat
Expand All @@ -35,32 +33,11 @@ internal partial class FavCatMod : MelonMod
internal PlayersModule? PlayerModule;

internal static PageUserInfo PageUserInfo;
private static readonly Func<VRCUiManager> ourGetUiManager;

static FavCatMod()
{
ourGetUiManager = (Func<VRCUiManager>)Delegate.CreateDelegate(typeof(Func<VRCUiManager>), typeof(VRCUiManager)
.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly)
.First(it => it.PropertyType == typeof(VRCUiManager)).GetMethod);
}

internal static VRCUiManager GetUiManager() => ourGetUiManager();

private static void DoAfterUiManagerInit(Action code)
{
MelonCoroutines.Start(OnUiManagerInitCoro(code));
}

private static IEnumerator OnUiManagerInitCoro(Action code)
{
while (GetUiManager() == null)
yield return null;
code();
}


public override void OnApplicationStart()
{
Instance = this;
if (!CheckWasSuccessful || !MustStayTrue || MustStayFalse) return;

Directory.CreateDirectory("./UserData/FavCatImport");

Expand Down Expand Up @@ -164,6 +141,7 @@ public class ApiSnifferPatch
private delegate void ImageDownloaderOnDoneDelegate(IntPtr thisPtr, IntPtr asyncOperationPtr, IntPtr methodInfo);

private static ApiPopulateDelegate ourOriginalApiPopulate = (_, _, _, _) => 0;
private static ApiPopulateDelegate ourOriginalApiPopulateTokens = (_, _, _, _) => 0;
private static ImageDownloaderOnDoneDelegate ourOriginalOnDone = (_, _, _) => { };

private static readonly Type ImageDownloaderClosureType;
Expand All @@ -183,24 +161,18 @@ static ApiSnifferPatch()

public static void DoPatch()
{
unsafe
{
var originalMethodPointer = *(IntPtr*)(IntPtr)UnhollowerUtils
.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(
typeof(ApiModel).GetMethods().Single(it =>
it.Name == nameof(ApiModel.SetApiFieldsFromJson) && it.GetParameters().Length == 2 && it.GetParameters()[0].ParameterType.GenericTypeArguments[1] == typeof(Il2CppSystem.Object)))
.GetValue(null);
MelonUtils.NativeHookAttach((IntPtr)(&originalMethodPointer), typeof(ApiSnifferPatch).GetMethod(nameof(ApiSnifferStatic))!.MethodHandle.GetFunctionPointer());
ourOriginalApiPopulate = Marshal.GetDelegateForFunctionPointer<ApiPopulateDelegate>(originalMethodPointer);
}

unsafe
{
var originalMethodPointer = *(IntPtr*)(IntPtr)UnhollowerUtils.GetIl2CppMethodInfoPointerFieldForGeneratedMethod(ImageDownloaderClosureType.GetMethod(nameof(ImageDownloaderClosure._DownloadImageInternal_b__0))).GetValue(null);
MelonUtils.NativeHookAttach((IntPtr)(&originalMethodPointer), typeof(ApiSnifferPatch).GetMethod(nameof(ImageSnifferPatch))!.MethodHandle.GetFunctionPointer());
ourOriginalOnDone = Marshal.GetDelegateForFunctionPointer<ImageDownloaderOnDoneDelegate>(originalMethodPointer);
}
NativePatchUtils.NativePatch(typeof(ApiModel).GetMethods().Single(it =>
it.Name == nameof(ApiModel.SetApiFieldsFromJson) && it.GetParameters().Length == 2 && it.GetParameters()[0].ParameterType.GenericTypeArguments[1] == typeof(Il2CppSystem.Object)),
out ourOriginalApiPopulate, ApiSnifferStatic);

NativePatchUtils.NativePatch(typeof(ApiModel).GetMethods().Single(it =>
it.Name == nameof(ApiModel.SetApiFieldsFromJson) && it.GetParameters().Length == 2 && it.GetParameters()[0].ParameterType.GenericTypeArguments[1] != typeof(Il2CppSystem.Object)),
out ourOriginalApiPopulateTokens, ApiSnifferStaticTokens);

NativePatchUtils.NativePatch(ImageDownloaderClosureType.GetMethod(nameof(ImageDownloaderClosure
._DownloadImageInternal_b__0))!, out ourOriginalOnDone, ImageSnifferPatch);
}

private static readonly object[] EmptyObjectArray = new object[0];

public static void ImageSnifferPatch(IntPtr instancePtr, IntPtr asyncOperationPtr, IntPtr methodInfo)
Expand Down Expand Up @@ -238,10 +210,26 @@ public static byte ApiSnifferStatic(IntPtr @this, IntPtr dictionary, IntPtr some
{
var result = ourOriginalApiPopulate(@this, dictionary, someRef, methodInfo);

ApiSnifferBody(@this);

return result;
}

public static byte ApiSnifferStaticTokens(IntPtr @this, IntPtr dictionary, IntPtr someRef, IntPtr methodInfo)
{
var result = ourOriginalApiPopulateTokens(@this, dictionary, someRef, methodInfo);

ApiSnifferBody(@this);

return result;
}

private static void ApiSnifferBody(IntPtr @this)
{
try
{
var apiModel = new ApiModel(@this);
if (!apiModel.Populated) return result;
if (!apiModel.Populated) return;

var maybeUser = apiModel.TryCast<APIUser>();
if (maybeUser != null) FavCatMod.Database?.UpdateStoredPlayer(maybeUser);
Expand All @@ -252,8 +240,6 @@ public static byte ApiSnifferStatic(IntPtr @this, IntPtr dictionary, IntPtr some
{
MelonLogger.Error($"Exception in API sniffer patch: {ex}");
}

return result;
}
}
}
6 changes: 6 additions & 0 deletions IKTweaks/CachedSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public struct CachedSolver
public readonly IKSolverVR.Arm RightArm;
public readonly IKSolverVR.Locomotion Locomotion;

public readonly IKSolverVR.VirtualBone[] LeftLegBones;
public readonly IKSolverVR.VirtualBone[] RightLegBones;

public CachedSolver(IKSolverVR solver)
{
Solver = solver;
Expand All @@ -21,6 +24,9 @@ public CachedSolver(IKSolverVR solver)
RightArm = solver.rightArm;
RightLeg = solver.rightLeg;
Locomotion = solver.locomotion;

LeftLegBones = LeftLeg.bones;
RightLegBones = RightLeg.bones;
}
}
}
2 changes: 1 addition & 1 deletion IKTweaks/IKTweaks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<VrcReferences>true</VrcReferences>
<AssemblyVersion>2.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0</AssemblyVersion>
<UsesNativePatches>true</UsesNativePatches>
</PropertyGroup>
<ItemGroup>
Expand Down
33 changes: 31 additions & 2 deletions IKTweaks/IKTweaksMod.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
Expand All @@ -9,7 +10,7 @@
using UIExpansionKit.Components;
using UnityEngine;

[assembly:MelonInfo(typeof(IKTweaksMod), "IKTweaks", "2.0.0", "knah", "https://github.com/xAstroBoy/VRCMods-Unchained")]
[assembly:MelonInfo(typeof(IKTweaksMod), "IKTweaks", "2.1.0", "knah", "https://github.com/knah/VRCMods")]
[assembly:MelonGame("VRChat", "VRChat")]
[assembly:MelonOptionalDependencies("UIExpansionKit")]

Expand All @@ -19,6 +20,8 @@ internal partial class IKTweaksMod : MelonMod
{
public override void OnApplicationStart()
{
if (!CheckWasSuccessful || !MustStayTrue || MustStayFalse) return;

IkTweaksSettings.RegisterSettings();

VrIkHandling.HookVrIkInit();
Expand All @@ -31,6 +34,32 @@ public override void OnApplicationStart()
private static void AddUixActions()
{
ExpansionKitApi.GetExpandedMenu(ExpandedMenu.SettingsMenu).AddSimpleButton("More IKTweaks...", ShowIKTweaksMenu);

var settingNameList = new[]
{
nameof(IkTweaksSettings.StraightSpineAngle),
nameof(IkTweaksSettings.StraightSpinePower),
nameof(IkTweaksSettings.DoHipShifting),
nameof(IkTweaksSettings.PreStraightenSpine),
nameof(IkTweaksSettings.StraightenNeck),
nameof(IkTweaksSettings.PinHipRotation),
nameof(IkTweaksSettings.NeckPriority),
nameof(IkTweaksSettings.SpineRelaxIterations),
nameof(IkTweaksSettings.MaxNeckAngleBack),
nameof(IkTweaksSettings.MaxNeckAngleFwd),
nameof(IkTweaksSettings.MaxSpineAngleBack),
nameof(IkTweaksSettings.MaxSpineAngleFwd),
};
var updateCallbacks = new List<Action>();

foreach (var s in settingNameList)
updateCallbacks.Add(ExpansionKitApi.RegisterSettingsVisibilityCallback(
IkTweaksSettings.IkTweaksCategory, s, () => IkTweaksSettings.FullBodyVrIk.Value));

IkTweaksSettings.FullBodyVrIk.OnValueChangedUntyped += () =>
{
foreach (var it in updateCallbacks) it();
};
}

private static void ShowIKTweaksMenu()
Expand All @@ -39,7 +68,7 @@ private static void ShowIKTweaksMenu()

menu.AddSpacer();
menu.AddSpacer();
menu.AddSimpleButton("Open documentation in browser", () => Process.Start("https://github.com/xAstroBoy/VRCMods-Unchained#iktweaks"));
menu.AddSimpleButton("Open documentation in browser", () => Process.Start("https://github.com/knah/VRCMods#iktweaks"));
menu.AddSpacer();

menu.AddSimpleButton("Adjust hand offsets",
Expand Down
13 changes: 13 additions & 0 deletions IKTweaks/IkTweaksSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal static void RegisterSettings()
NoWallFreeze = category.CreateEntry(nameof(NoWallFreeze), true, "Don't freeze head/hands inside walls");

DisableElbowAvoidance = category.CreateEntry(nameof(DisableElbowAvoidance), false, "Disable IK2 elbow-chest avoidance");
IktKneeMode = category.CreateEntry(nameof(IktKneeMode), KneeBendNormalMode.Natural, "Knee angle mode (with no trackers)");

ExperimentalSettingOne = category.CreateEntry(nameof(ExperimentalSettingOne), false, "Experimental setting", dont_save_default: true, is_hidden: true);

Expand Down Expand Up @@ -73,6 +74,8 @@ internal static void RegisterSettings()
public static MelonPreferences_Entry<bool> Unrestrict3PointHeadRotation;
public static MelonPreferences_Entry<bool> NoWallFreeze;
public static MelonPreferences_Entry<bool> DisableElbowAvoidance;
public static MelonPreferences_Entry<KneeBendNormalMode> IktKneeMode;

public static MelonPreferences_Entry<bool> ExperimentalSettingOne;

public static MelonPreferences_Entry<Vector3> HandAngleOffset;
Expand All @@ -97,4 +100,14 @@ public enum IgnoreAnimationsMode
[Description("Ignore all (always slide around)")]
All = HandAndHead | Others
}

public enum KneeBendNormalMode
{
[Description("IK2 Default")]
Default,
[Description("IKT Classic")]
Classic,
[Description("IKT Natural")]
Natural
}
}
3 changes: 3 additions & 0 deletions IKTweaks/Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public static Float3 ProjectOnPlane(Float3 a, Float3 planeNormal)
planeNormal = planeNormal.normalized;
return a - planeNormal * Dot(planeNormal, a);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Float3 Lerp(Float3 a, Float3 b, float t) => a * (1 - t) + b * t;

public override string ToString()
{
Expand Down
Loading

0 comments on commit 9b4e748

Please sign in to comment.