Skip to content

Commit

Permalink
Remove VRChat_OnUIManagerInit - Wait for ActionMenuDriver now
Browse files Browse the repository at this point in the history
  • Loading branch information
gompocp committed May 21, 2021
1 parent a539a5d commit 040a13f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 21 deletions.
23 changes: 18 additions & 5 deletions ActionMenuApi/ActionMenuApi.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using ActionMenuApi.Managers;
using System;
using System.Collections;
using ActionMenuApi.Managers;
using MelonLoader;
#pragma warning disable 1591
[assembly: MelonInfo(typeof(ActionMenuApi.ActionMenuApi), "ActionMenuApi", "0.2.0", "gompo", "https://github.com/gompocp/ActionMenuApi/releases")]
[assembly: MelonInfo(typeof(ActionMenuApi.ActionMenuApi), "ActionMenuApi", "0.2.1", "gompo", "https://github.com/gompocp/ActionMenuApi/releases")]
[assembly: MelonGame("VRChat", "VRChat")]

namespace ActionMenuApi
Expand All @@ -10,16 +12,27 @@ public class ActionMenuApi : MelonMod
{
public override void OnApplicationStart()
{
Patches.PatchAll(Harmony);
ResourcesManager.LoadTextures();
MelonCoroutines.Start(WaitForActionMenuInit());
try
{
Patches.PatchAll(Harmony);
}
catch (Exception e)
{
MelonLogger.Error($"Patching failed with exception: {e.Message}");
}
}

public override void VRChat_OnUiManagerInit()
IEnumerator WaitForActionMenuInit()
{
while (ActionMenuDriver.prop_ActionMenuDriver_0 == null)
yield return null;
ResourcesManager.InitLockGameObject();
RadialPuppetManager.Setup();
FourAxisPuppetManager.Setup();
ResourcesManager.InitLockGameObject();
}


public override void OnUpdate()
{
Expand Down
12 changes: 6 additions & 6 deletions ActionMenuApi/Api/CustomSubMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public static PedalOption AddButton(string text, Action triggerEvent, Texture2D
ActionMenuOpener actionMenuOpener = Utilities.GetActionMenuOpener();
if (actionMenuOpener == null) return null;
PedalOption pedalOption = actionMenuOpener.GetActionMenu().AddOption();
pedalOption.SetText(text);
pedalOption.SetIcon(icon);
pedalOption.SetText(text);
pedalOption.SetForegroundIcon(icon);
if (!locked) pedalOption.SetPedalTriggerEvent(DelegateSupport.ConvertDelegate<PedalOptionTriggerEvent>(triggerEvent));
else ResourcesManager.AddLockChildIcon(pedalOption.GetActionButton().gameObject.GetChild("Inner"));
return pedalOption;
Expand All @@ -52,7 +52,7 @@ public static PedalOption AddRadialPuppet(string text, Action<float> onUpdate, f
if (actionMenuOpener == null) return null;
PedalOption pedalOption = actionMenuOpener.GetActionMenu().AddOption();
pedalOption.SetText(text);
pedalOption.SetIcon(icon);
pedalOption.SetBackgroundIcon(icon);
pedalOption.SetButtonPercentText($"{Math.Round(startingValue*100)}%");
pedalOption.SetPedalTypeIcon(Utilities.GetExpressionsIcons().typeRadial);
if(!locked) pedalOption.SetPedalTriggerEvent(
Expand Down Expand Up @@ -89,7 +89,7 @@ public static PedalOption AddFourAxisPuppet(string text, Action<Vector2> onUpdat
if (actionMenuOpener == null) return null;
PedalOption pedalOption = actionMenuOpener.GetActionMenu().AddOption();
pedalOption.SetText(text);
pedalOption.SetIcon(icon);
pedalOption.SetBackgroundIcon(icon);
pedalOption.SetPedalTypeIcon(Utilities.GetExpressionsIcons().typeAxis);
if(!locked) pedalOption.SetPedalTriggerEvent(
DelegateSupport.ConvertDelegate<PedalOptionTriggerEvent>(new Action(delegate
Expand Down Expand Up @@ -120,7 +120,7 @@ public static PedalOption AddSubMenu(string text, Action openFunc, Texture2D ico
if (actionMenuOpener == null) return null;
PedalOption pedalOption = actionMenuOpener.GetActionMenu().AddOption();
pedalOption.SetText(text);
pedalOption.SetIcon(icon);
pedalOption.SetForegroundIcon(icon);
//pedalOption.SetPedalTypeIcon(Utilities.GetExpressionsIcons().typeFolder);
if(!locked) pedalOption.SetPedalTriggerEvent(
DelegateSupport.ConvertDelegate<PedalOptionTriggerEvent>(new Action(delegate
Expand All @@ -147,7 +147,7 @@ public static PedalOption AddToggle(string text, bool startingState, Action<bool
if (actionMenuOpener == null) return null;
PedalOption pedalOption = actionMenuOpener.GetActionMenu().AddOption();
pedalOption.SetText(text);
pedalOption.SetIcon(icon);
pedalOption.SetBackgroundIcon(icon);
if (startingState) pedalOption.SetPedalTypeIcon(Utilities.GetExpressionsIcons().typeToggleOn);
else pedalOption.SetPedalTypeIcon(Utilities.GetExpressionsIcons().typeToggleOff);
if(!locked) pedalOption.SetPedalTriggerEvent(
Expand Down
4 changes: 2 additions & 2 deletions ActionMenuApi/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ public static void PatchAll(HarmonyInstance harmonyInstance)
PatchMethod(openOptionsPageKeyWords, "OpenOptionsPre", "OpenOptionsPost");

//Special Child
harmonyInstance.Patch(
/*harmonyInstance.Patch(
typeof(ActionMenu).GetMethods().Single(
m => Utilities.checkXref(m, openNameplatesSizePageKeyWords)
&& m.CheckStringsCount(5)
),
new HarmonyMethod(typeof(Patches).GetMethod("OpenNameplatesSizePre")),
new HarmonyMethod(typeof(Patches).GetMethod("OpenNameplatesSizePost"))
);
);*/
MelonLogger.Msg("Patches Applied");
}

Expand Down
7 changes: 5 additions & 2 deletions ActionMenuApi/Stuff/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ private static PushPageDelegate GetPushPageDelegate
private static PushPageDelegate pushPageDelegate;
private delegate ActionMenuPage PushPageDelegate(ActionMenu actionMenu, Il2CppSystem.Action openFunc, Il2CppSystem.Action closeFunc = null, Texture2D icon = null, string text = null);



public static void SetBackgroundIcon(this PedalOption pedal, Texture2D icon) => pedal.GetActionButton().prop_Texture2D_0 = icon;

//Only texture2d prop on PedalOption. shouldnt change unless drastic changes are made to the action menu
public static void SetForegroundIcon(this PedalOption pedal, Texture2D icon) => pedal.prop_Texture2D_0 = icon;

public static Texture2D SetIcon(this PedalOption pedal, Texture2D icon) => pedal.prop_Texture2D_0 = icon;
public static Texture2D GetIcon(this PedalOption pedal) => pedal.prop_Texture2D_0; //Only texture2d prop on PedalOption. shouldnt change unless drastic changes are made to the action menu
public static bool isOpen(this ActionMenuOpener actionMenuOpener) => actionMenuOpener.field_Private_Boolean_0; //only bool on action menu opener, shouldnt change

private static PropertyInfo actionButtonPercentProperty;
Expand Down
7 changes: 6 additions & 1 deletion ActionMenuApi/Stuff/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public static void AddPedalsInList(List<PedalStruct> list, ActionMenu instance)
if(!pedalStruct.shouldAdd) continue;
PedalOption pedalOption = instance.AddOption();
pedalOption.SetText(pedalStruct.text);
pedalOption.SetIcon(pedalStruct.icon);
if(!pedalStruct.locked) pedalOption.SetPedalTriggerEvent(DelegateSupport.ConvertDelegate<PedalOptionTriggerEvent>(pedalStruct.triggerEvent));
else ResourcesManager.AddLockChildIcon(pedalOption.GetActionButton().gameObject.GetChild("Inner"));
//Additional setup for pedals
Expand All @@ -80,6 +79,7 @@ public static void AddPedalsInList(List<PedalStruct> list, ActionMenu instance)
pedalOption.SetPedalTypeIcon(GetExpressionsIcons().typeRadial);
pedalOption.SetButtonPercentText($"{Math.Round(pedalRadial.currentValue)}%");
pedalRadial.pedal = pedalOption;
pedalOption.SetBackgroundIcon(pedalStruct.icon);
break;
case PedalType.Toggle:
PedalToggle pedalToggle = (PedalToggle) pedalStruct;
Expand All @@ -88,9 +88,14 @@ public static void AddPedalsInList(List<PedalStruct> list, ActionMenu instance)
else
pedalOption.SetPedalTypeIcon(GetExpressionsIcons().typeToggleOff);
pedalToggle.pedal = pedalOption;
pedalOption.SetBackgroundIcon(pedalStruct.icon);
break;
case PedalType.FourAxisPuppet:
pedalOption.SetPedalTypeIcon(GetExpressionsIcons().typeAxis);
pedalOption.SetBackgroundIcon(pedalStruct.icon);
break;
default:
pedalOption.SetForegroundIcon(pedalStruct.icon);
break;
}
}
Expand Down
10 changes: 5 additions & 5 deletions ActionMenuTestMod/ActionMenuTestMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public override void OnApplicationStart()
AMUtils.RefreshActionMenu(); //Refresh menu to update the locked state of the pedal
});
//No properties here are saved because I'm lazy af
CustomSubMenu.AddToggle("Enable Hax", false, b => { }, null,riskyFunctionsAllowed);
CustomSubMenu.AddRadialPuppet("Volume", f => { }, 0, null, riskyFunctionsAllowed);
CustomSubMenu.AddSubMenu("Whatever", () => { }, null, riskyFunctionsAllowed);
CustomSubMenu.AddToggle("Enable Hax", false, b => { }, buttonIcon,riskyFunctionsAllowed);
CustomSubMenu.AddRadialPuppet("Volume", f => { }, 0, buttonIcon, riskyFunctionsAllowed);
CustomSubMenu.AddSubMenu("Whatever", () => { }, buttonIcon, riskyFunctionsAllowed);
CustomSubMenu.AddButton("Risky Function", () =>
{
MelonLogger.Msg("Locked Pedal Func ran");
}, buttonIcon, riskyFunctionsAllowed);
CustomSubMenu.AddFourAxisPuppet("Move", vector2 => { }, null, riskyFunctionsAllowed);
CustomSubMenu.AddFourAxisPuppet("Move", vector2 => { }, toggleIcon, riskyFunctionsAllowed);
},
subMenuIcon
);
Expand All @@ -82,7 +82,7 @@ public override void OnApplicationStart()
"New Cube Stuff",
delegate
{
CustomSubMenu.AddFourAxisPuppet("Reposition cube X/Y", (v) => RePositionCubeXY(v), toggleIcon);
CustomSubMenu.AddFourAxisPuppet("Reposition cube X/Y", (v) => RePositionCubeXY(v), buttonIcon);
CustomSubMenu.AddFourAxisPuppet("Reposition cube Z/Y", RePositionCubeZY, toggleIcon);
CustomSubMenu.AddFourAxisPuppet("Reposition cube X/Z", RePositionCubeXZ, toggleIcon);
CustomSubMenu.AddRadialPuppet("X",RotateCubeX, x,radialIcon); //Rotation a bit borked
Expand Down

0 comments on commit 040a13f

Please sign in to comment.