Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
New mod! PreviewScroller
Browse files Browse the repository at this point in the history
  • Loading branch information
loukylor committed Apr 20, 2021
1 parent 99e55c7 commit 8c3b6d6
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
40 changes: 40 additions & 0 deletions PreviewScroller/PreviewScroller.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AssemblyName>PreviewScroller</AssemblyName>
<RootNamespace>PreviewScroller</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Il2Cppmscorlib">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\Il2Cppmscorlib.dll</HintPath>
</Reference>
<Reference Include="Il2CppSystem">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\Il2CppSystem.dll</HintPath>
</Reference>
<Reference Include="Il2CppSystem.Core">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\Il2CppSystem.Core.dll</HintPath>
</Reference>
<Reference Include="MelonLoader">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\MelonLoader.dll</HintPath>
</Reference>
<Reference Include="UnhollowerBaseLib">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnhollowerBaseLib.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="move &quot;bin\Debug\net472\PreviewScroller.dll&quot; &quot;C:\Program Files (x86)\Steam\steamapps\common\VRChat\Mods&quot;" />
</Target>

</Project>
92 changes: 92 additions & 0 deletions PreviewScroller/PreviewScrollerMod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System;
using System.Linq;
using System.Reflection;
using Harmony;
using MelonLoader;
using UnhollowerRuntimeLib;
using UnityEngine;
using UnityEngine.UI;
using VRC.UI;

[assembly: MelonInfo(typeof(PreviewScroller.PreviewScrollerMod), "PreviewScroller", "0.0.1", "loukylor", "https://github.com/loukylor/VRC-Mods")]
[assembly: MelonGame("VRChat", "VRChat")]

namespace PreviewScroller
{
public class PreviewScrollerMod : MelonMod
{
public override void VRChat_OnUiManagerInit()
{
foreach (MethodInfo method in typeof(PageAvatar).GetMethods().Where(mi => mi.Name.StartsWith("Method_Private_Void_String_GameObject_AvatarPerformanceStats_")))
Harmony.Patch(method, null, new HarmonyMethod(typeof(PreviewScrollerMod).GetMethod(nameof(OnPedestalAvatarInstantiated), BindingFlags.NonPublic | BindingFlags.Static)));
GameObject scrollerContainer = new GameObject("ScrollerContainer", new UnhollowerBaseLib.Il2CppReferenceArray<Il2CppSystem.Type>(new Il2CppSystem.Type[2] { Il2CppType.Of<RectMask2D>(), Il2CppType.Of<RectTransform>() }));
RectTransform scrollerContainerRect = scrollerContainer.GetComponent<RectTransform>();
scrollerContainerRect.SetParent(GameObject.Find("UserInterface/MenuContent/Screens/Avatar").transform);
scrollerContainerRect.anchoredPosition3D = new Vector3(-565, 20, 1);
scrollerContainerRect.localScale = Vector3.one;
scrollerContainerRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 400);
scrollerContainerRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 650);

GameObject scrollerContent = new GameObject("ScrollerContent", new UnhollowerBaseLib.Il2CppReferenceArray<Il2CppSystem.Type>(new Il2CppSystem.Type[2] { Il2CppType.Of<Image>(), Il2CppType.Of<RectTransform>() }));
RectTransform scrollerContentRect = scrollerContent.GetComponent<RectTransform>();
scrollerContentRect.SetParent(scrollerContainerRect);

scrollerContentRect.anchoredPosition3D = Vector3.zero;
scrollerContentRect.localScale = Vector3.one;
scrollerContentRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 800);
scrollerContentRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 1300);
//scrollerContentRect.GetComponent<Image>().sprite = GameObject.Find("UserInterface/QuickMenu/UIElementsMenu/NameplatesOnButton").GetComponent<Image>().sprite;
scrollerContentRect.GetComponent<Image>().color = new Color(0, 0, 0, 0);

ScrollRect scrollRect = scrollerContainer.AddComponent<ScrollRect>();
scrollRect.content = scrollerContentRect;
scrollRect.movementType = ScrollRect.MovementType.Unrestricted;
scrollRect.decelerationRate = 0.03f;
scrollRect.onValueChanged = new ScrollRect.ScrollRectEvent();
GameObject pedestal = GameObject.Find("UserInterface/MenuContent/Screens/Avatar/AvatarPreviewBase/MainRoot/MainModel");
pedestal.transform.localPosition += new Vector3(0, 0.5f);
MonoBehaviour autoTurn = pedestal.GetComponents<MonoBehaviour>().First(c => c.GetIl2CppType().FullName == "UnityStandardAssets.Utility.AutoMoveAndRotate");
UnityEngine.Object.DestroyImmediate(autoTurn);

Vector2 lastPos = Vector2.zero;

scrollRect.onValueChanged.AddListener(new Action<Vector2>((pos) =>
{
Vector2 velocity = pos - lastPos;
lastPos = pos;
Vector2 scrollRectVelocity = scrollRect.velocity;
if (scrollRect.verticalNormalizedPosition > 1 && velocity.y > 0)
{
scrollRect.verticalNormalizedPosition = 0;
lastPos.y = 0;
}
else if (scrollRect.verticalNormalizedPosition < 0 && velocity.y < 0)
{
scrollRect.verticalNormalizedPosition = 1;
lastPos.y = 1;
}
if (scrollRect.horizontalNormalizedPosition > 1 && velocity.x > 0)
{
scrollRect.horizontalNormalizedPosition = 0;
lastPos.x = 0;
}
else if (scrollRect.horizontalNormalizedPosition < 0 && velocity.x < 0)
{
scrollRect.horizontalNormalizedPosition = 1;
lastPos.x = 1;
}
pedestal.transform.Rotate(new Vector2(velocity.normalized.y, velocity.normalized.x), velocity.magnitude * 375 * Time.deltaTime);
pedestal.transform.parent.localPosition = new Vector3(0, -0.5f);
scrollRect.velocity = scrollRectVelocity;
}));
}
private static void OnPedestalAvatarInstantiated(GameObject __1)
{
if (__1 == null) return;

__1.transform.localPosition = new Vector3(0, -0.5f);
__1.transform.parent.localRotation = new Quaternion();
}
}
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ More detailed instructions and more mods can be found in the [VRChat Modding Gro
- [CloningBeGone](#cloningbegone)
- [InstanceHistory](#instancehistory)
- [PlayerList](#playerlist)
- [PreviewScroller](#previewscroller)
- [ReloadAvatars](#reloadavatars)
- [UserInfoExtensions](#userinfoextensions)

Expand Down Expand Up @@ -99,6 +100,9 @@ Oh yea, also report any errors to me. You can make an issue or ping/DM me.
## Picture of List
![Picture of List](https://i.imgur.com/Tt6ZYqB.png)

# PreviewScroller
A mod that let's you sort of scroll the avatar preview so you can control where it's facing

# ReloadAvatars
Adds buttons to reload a single user's avatar or all users' avatar.

Expand Down

0 comments on commit 8c3b6d6

Please sign in to comment.