Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Added custom avatar reset for actionmenuutils
Browse files Browse the repository at this point in the history
  • Loading branch information
gompoc committed Oct 3, 2021
1 parent e060b9a commit 1da300e
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 624 deletions.
474 changes: 0 additions & 474 deletions ActionMenuUtils/ActionMenuAPI.cs

This file was deleted.

2 changes: 1 addition & 1 deletion ActionMenuUtils/ActionMenuUtils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<VrcReferences>true</VrcReferences>
<Version>1.3.11.0</Version>
<Version>2.0.0.0</Version>
<LangVersion>9</LangVersion>
<CopyToMods>true</CopyToMods>
<GenerateJson>true</GenerateJson>
Expand Down
174 changes: 36 additions & 138 deletions ActionMenuUtils/Main.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using ActionMenuApi.Api;
using MelonLoader;
using ModJsonGenerator;
using UIExpansionKit.API;
using UnhollowerRuntimeLib;
using UnhollowerRuntimeLib.XrefScans;
using UnityEngine;
using UnityEngine.UI;
using VRC.Animation;
using VRC.Core;
using VRC.SDKBase;
using VRC;
using Main = ActionMenuUtils.Main;

[assembly: MelonGame("VRChat", "VRChat")]
[assembly: MelonOptionalDependencies("ActionMenuApi")]
[assembly: MelonInfo(typeof(Main), "ActionMenuUtils", "1.3.11", "gompo", "https://github.com/gompoc/VRChatMods/releases/")]
[assembly: VerifyLoaderVersion(0, 4, 2, true)]
[assembly: MelonInfo(typeof(Main), "ActionMenuUtils", "2.0.0", "gompo", "https://github.com/gompoc/VRChatMods/releases/")]
[assembly: VerifyLoaderVersion(0, 4, 3, true)]
[assembly: ModJsonInfo(
140,
"Lets you respawn using the action menu\n" +
"Lets you go home for when respawning wont save you such as in broken worlds with no floors\n" +
"Additionally lets you reset avatar or rejoin instance",
new []{"action menu", "respawn", "go home", "reset avatar"},
null,
null,
new []{"[ActionMenuApi](https://api.vrcmg.com/v0/mods/201/ActionMenuApi.dll)", "[UIExpansionKit](https://api.vrcmg.com/v0/mods/55/UIExpansionKit.dll)"},
"- Mod now depends on ActionMenuApi & UIExpansionKit, this just makes maintaining it easier for me when/if something breaks\n"+
"- New setting added that you can enable so you can now select which avatar you want to reset into. You can select avatar by going to the AvatarMenu and clicking the UIExpansionKit button on the left",
"#2ad9f7"
)
]
Expand All @@ -40,14 +36,9 @@ public partial class Main : MelonMod
private static Texture2D goHomeIcon;
private static Texture2D resetAvatarIcon;
private static Texture2D rejoinInstanceIcon;
private static ActionMenuAPI actionMenuApi;
private static MelonMod instance;
public new static HarmonyLib.Harmony HarmonyInstance => instance.HarmonyInstance;



public override void OnApplicationStart()
{
instance = this;
try
{
if (string.IsNullOrEmpty(ID)) return;
Expand Down Expand Up @@ -77,21 +68,36 @@ public override void OnApplicationStart()
}
ModSettings.RegisterSettings();
ModSettings.Apply();
if(MelonHandler.Mods.Any(m => m.Info.Name.Equals("ActionMenuApi"))) {
SetupButtonsForAMAPI();
}
else
{
actionMenuApi = new ActionMenuAPI();
SetupButtons();
}
SetupAMAPIButtons();
SetupUIXButtons();
}

private static void SetupUIXButtons()
{
ExpansionKitApi.GetExpandedMenu(ExpandedMenu.AvatarMenu).AddSimpleButton("Set as reset avatar for ActionMenuUtils",
() =>
{
var avatarId = GameObject.Find("UserInterface/MenuContent/Screens/Avatar/AvatarPreviewBase/MainRoot/MainModel").GetComponent<SimpleAvatarPedestal>().field_Internal_ApiAvatar_0.id;
var fallbackAvatarId =GameObject.Find("UserInterface/MenuContent/Screens/Avatar/AvatarPreviewBase/FallbackRoot/FallbackModel").GetComponent<SimpleAvatarPedestal>().field_Internal_ApiAvatar_0.id;
ModSettings.customAvatarId = avatarId;
ModSettings.fallbackAvatarId = fallbackAvatarId;
ModSettings.Save();
#if DEBUG
MelonLogger.Msg($"{avatarId},{fallbackAvatarId}");
#endif

},
g =>
{
UIXAvatarMenuButton = g;
UIXAvatarMenuButton.active = ModSettings.enableCustomAvatarReset;
});

}




private static void SetupButtonsForAMAPI()
public static GameObject UIXAvatarMenuButton;

private static void SetupAMAPIButtons()
{
VRCActionMenuPage.AddSubMenu(ActionMenuPage.Options, "SOS",
() =>
Expand Down Expand Up @@ -138,115 +144,7 @@ private static void SetupButtonsForAMAPI()

public override void OnPreferencesLoaded() => ModSettings.Apply();
public override void OnPreferencesSaved() => ModSettings.Apply();


private static void SetupButtons()
{

actionMenuApi.AddPedalToExistingMenu(ActionMenuAPI.ActionMenuPageType.Options, delegate
{
actionMenuApi.CreateSubMenu(() => {

if (ModSettings.confirmRespawn)
actionMenuApi.AddPedalToCustomMenu(() =>

actionMenuApi.CreateSubMenu(() =>
actionMenuApi.AddPedalToCustomMenu(Utils.Respawn, "Confirm Respawn", respawnIcon)
), "Respawn", respawnIcon
);
else
actionMenuApi.AddPedalToCustomMenu(Utils.Respawn, "Respawn", respawnIcon);

if (ModSettings.confirmGoHome)
actionMenuApi.AddPedalToCustomMenu(() =>
actionMenuApi.CreateSubMenu( () =>
actionMenuApi.AddPedalToCustomMenu(Utils.Home, "Confirm Go Home", goHomeIcon)
), "Go Home", goHomeIcon
);
else
actionMenuApi.AddPedalToCustomMenu(Utils.Home, "Go Home", goHomeIcon);

if (ModSettings.confirmAvatarReset)
actionMenuApi.AddPedalToCustomMenu(() =>
actionMenuApi.CreateSubMenu(() =>
actionMenuApi.AddPedalToCustomMenu(Utils.ResetAvatar, "Confirm Reset Avatar", resetAvatarIcon)
), "Reset Avatar", resetAvatarIcon
);
else
actionMenuApi.AddPedalToCustomMenu(Utils.ResetAvatar, "Reset Avatar", resetAvatarIcon);

if (ModSettings.confirmInstanceRejoin)
{
actionMenuApi.AddPedalToCustomMenu(() =>

actionMenuApi.CreateSubMenu(() =>
actionMenuApi.AddPedalToCustomMenu(Utils.RejoinInstance, "Confirm Instance Rejoin", rejoinInstanceIcon)
), "Rejoin Instance", rejoinInstanceIcon
);
}
else
actionMenuApi.AddPedalToCustomMenu(Utils.RejoinInstance, "Rejoin Instance", rejoinInstanceIcon);

});
}, "Help", helpIcon);
}

private static string ID = "gompo";
}

static class Utils
{
//Gracefully taken from Advanced Invites https://github.com/Psychloor/AdvancedInvites/blob/master/AdvancedInvites/Utilities.cs#L356
private static bool XRefScanFor(this MethodBase methodBase, string searchTerm)
{
return XrefScanner.XrefScan(methodBase).Any(
xref => xref.Type == XrefType.Global && xref.ReadAsObject()?.ToString().IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) >= 0);
}

private static GoHomeDelegate GetGoHomeDelegate
{
get
{
if (goHomeDelegate != null) return goHomeDelegate;
MethodInfo goHomeMethod = typeof(VRCFlowManager).GetMethods(BindingFlags.Public | BindingFlags.Instance).First(
m => m.GetParameters().Length == 0 && m.ReturnType == typeof(void) && m.XRefScanFor("Going to Home Location: "));

goHomeDelegate = (GoHomeDelegate)Delegate.CreateDelegate(
typeof(GoHomeDelegate),
VRCFlowManager.prop_VRCFlowManager_0,
goHomeMethod);
return goHomeDelegate;
}
}

private static void GoHome() => GetGoHomeDelegate();
private static GoHomeDelegate goHomeDelegate;

private delegate void GoHomeDelegate();

public static void Respawn()
{
GameObject.Find("UserInterface/QuickMenu/ShortcutMenu/RespawnButton").GetComponent<Button>().onClick.Invoke();
VRCPlayer.field_Internal_Static_VRCPlayer_0.GetComponent<VRCMotionState>().Reset();
}

public static void RejoinInstance()
{
var instance = RoomManager.field_Internal_Static_ApiWorldInstance_0;
Networking.GoToRoom($"{instance.world.id}:{instance.instanceId}");
}

public static void Home()
{
if (ModSettings.forceGoHome)
GoHome();
else
GameObject.Find("UserInterface/QuickMenu/ShortcutMenu/GoHomeButton").GetComponent<Button>().onClick.Invoke();
}

public static void ResetAvatar()
{
//TODO: Pick your own avatar for reset
ObjectPublicAbstractSealedApObApStApApUnique.Method_Public_Static_Void_ApiAvatar_String_ApiAvatar_0(API.Fetch<ApiAvatar>("avtr_c38a1615-5bf5-42b4-84eb-a8b6c37cbd11"), "fallbackAvatar");
}
}
}
53 changes: 42 additions & 11 deletions ActionMenuUtils/ModSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,54 @@ public static class ModSettings
public static bool confirmInstanceRejoin { get; private set; } = true;
public static bool forceGoHome { get; private set; } = false;

public static bool enableCustomAvatarReset { get; private set; } = false;

public static string customAvatarId;
public static string fallbackAvatarId;


private static MelonPreferences_Entry<bool> ConfirmRespawn,
ConfirmGoHome,
ConfirmAvatarReset,
ConfirmInstanceRejoin,
ForceGoHome,
EnableCustomAvatarReset;

private static MelonPreferences_Entry<string> CustomAvatarId, FallbackAvatarId;

public static void RegisterSettings()
{
MelonPreferences.CreateCategory(categoryName, categoryDisplayName);
MelonPreferences.CreateEntry(categoryName, "ConfirmRespawn", confirmRespawn, "Add a confirmation for respawn");
MelonPreferences.CreateEntry(categoryName, "ConfirmGoHome", confirmGoHome, "Add a confirmation for go home");
MelonPreferences.CreateEntry(categoryName, "ForceGoHome", forceGoHome, "Skip the go home popup");
MelonPreferences.CreateEntry(categoryName, "ConfirmAvatarReset", confirmAvatarReset, "Add a confirmation for avatar reset");
MelonPreferences.CreateEntry(categoryName, "ConfirmInstanceReJoin", confirmInstanceRejoin, "Add a confirmation for rejoin instance");
var category = MelonPreferences.CreateCategory(categoryName, categoryDisplayName);
ConfirmRespawn = category.CreateEntry("ConfirmRespawn", confirmRespawn, "Add a confirmation for respawn");
ConfirmGoHome = category.CreateEntry( "ConfirmGoHome", confirmGoHome, "Add a confirmation for go home");
ForceGoHome = category.CreateEntry("ForceGoHome", forceGoHome, "Skip the go home popup");
ConfirmAvatarReset = category.CreateEntry("ConfirmAvatarReset", confirmAvatarReset, "Add a confirmation for avatar reset");
ConfirmInstanceRejoin = category.CreateEntry("ConfirmInstanceReJoin", confirmInstanceRejoin, "Add a confirmation for rejoin instance");
EnableCustomAvatarReset = category.CreateEntry("EnableCustomAvatarReset", enableCustomAvatarReset, "Use custom avatar when resetting");
CustomAvatarId = category.CreateEntry("CustomAvatarId", customAvatarId, "", true) as MelonPreferences_Entry<string>;
FallbackAvatarId = category.CreateEntry("FallbackAvatarId", fallbackAvatarId, "", true) as MelonPreferences_Entry<string>;
}

public static void Apply()
{
confirmRespawn = MelonPreferences.GetEntryValue<bool>(categoryName, "ConfirmRespawn");
confirmGoHome = MelonPreferences.GetEntryValue<bool>(categoryName, "ConfirmGoHome");
forceGoHome = MelonPreferences.GetEntryValue<bool>(categoryName, "ForceGoHome");
confirmAvatarReset = MelonPreferences.GetEntryValue<bool>(categoryName, "ConfirmAvatarReset");
confirmInstanceRejoin = MelonPreferences.GetEntryValue<bool>(categoryName, "ConfirmInstanceReJoin");
confirmRespawn = ConfirmRespawn.Value;
confirmGoHome = ConfirmGoHome.Value;
forceGoHome = ForceGoHome.Value;
confirmAvatarReset = ConfirmAvatarReset.Value;
confirmInstanceRejoin = ConfirmInstanceRejoin.Value;
enableCustomAvatarReset = EnableCustomAvatarReset.Value;
customAvatarId = CustomAvatarId.Value;
fallbackAvatarId = FallbackAvatarId.Value;

if(Main.UIXAvatarMenuButton is {})
Main.UIXAvatarMenuButton.active = enableCustomAvatarReset;
}

public static void Save()
{
CustomAvatarId.Value = customAvatarId;
FallbackAvatarId.Value = fallbackAvatarId;
MelonPreferences.Save();
}
}
}
Loading

0 comments on commit 1da300e

Please sign in to comment.