This repository has been archived by the owner on Mar 12, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from d-mageek/master
vai pra puta que pariu vai pra casa do caralho vai se foder vai tomar no cu vai se arrombar vai da essa bunda vai chupar uma rola vai pro quinto dos inferno mamar a piroca do capeta vai pra porra vai pra merda vai engolir uma pica vai sugar um caralho vai cair de boca num piru
- Loading branch information
Showing
7 changed files
with
220 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,125 @@ | ||
using MelonLoader; | ||
using UIExpansionKit.API; | ||
using UnityEngine; | ||
using System.Linq; | ||
using UnhollowerRuntimeLib; | ||
using System.Collections; | ||
using TrackingRotator.Utils; | ||
using Il2CppSystem.Reflection; | ||
|
||
namespace TrackingRotator { | ||
|
||
namespace TrackingRotator | ||
{ | ||
public static class ModBuildInfo { | ||
public const string Name = "TrackingRotator"; | ||
public const string Author = "nitro."; | ||
public const string Version = "1.0.1"; | ||
public const string Author = "Davi & nitro."; // <3 | ||
public const string Version = "1.0.2"; | ||
public const string DownloadLink = "https://github.com/nitrog0d/TrackingRotator/releases/latest/download/TrackingRotator.dll"; | ||
public const string GameDeveloper = "VRChat"; | ||
public const string Game = "VRChat"; | ||
} | ||
|
||
public class TrackingRotatorMod : MelonMod { | ||
public class TrackingRotatorMod : MelonMod | ||
{ | ||
|
||
private const string ModCategory = "TrackingRotator"; | ||
private const string UIXIntegration = "UIXIntegration"; | ||
private const string AMAPIIntegration = "AMAPIIntegration"; | ||
private const string RotationValuePref = "RotationValue"; | ||
private const string HighPrecisionRotationValuePref = "HighPrecisionRotationValue"; | ||
private const string ResetRotationOnSceneChangePref = "ResetRotationOnSceneChange"; | ||
|
||
private static float rotationValue = 0f; | ||
private static float highPrecisionRotationValue = 0f; | ||
private static bool highPrecision = false; | ||
private static bool resetRotationOnSceneChange = false; | ||
private static bool resetRotationOnSceneChange, IsUsingUIX, IsUsingAMAPI = false; | ||
private static bool UIXintegration, AMAPIintegration = true; | ||
|
||
private static Transform cameraTransform = null; | ||
private static Quaternion originalRotation; | ||
public static bool highPrecision = false; | ||
public static Transform transform; | ||
public static Transform cameraTransform; | ||
public static Quaternion originalRotation; | ||
|
||
public override void OnApplicationStart() { | ||
MelonLogger.Msg("Mod loaded."); | ||
public override void OnApplicationStart() | ||
{ | ||
MelonPreferences.CreateCategory(ModCategory, "Tracking Rotator"); | ||
MelonPreferences.CreateEntry(ModCategory, UIXIntegration, true, "Integrate with UiExpansionKit?"); | ||
MelonPreferences.CreateEntry(ModCategory, AMAPIIntegration, true, "Integrate with Action Menu?"); | ||
MelonPreferences.CreateEntry(ModCategory, RotationValuePref, 22.5f, "Rotation value"); | ||
MelonPreferences.CreateEntry(ModCategory, HighPrecisionRotationValuePref, 1f, "High precision rotation value"); | ||
MelonPreferences.CreateEntry(ModCategory, ResetRotationOnSceneChangePref, false, "Reset rotation when a new world loads"); | ||
ExpansionKitApi.GetExpandedMenu(ExpandedMenu.QuickMenu).AddSimpleButton("Tracking rotation", ShowRotationMenu); | ||
OnPreferencesSaved(); | ||
} | ||
|
||
public override void OnSceneWasLoaded(int buildIndex, string sceneName) { | ||
if (resetRotationOnSceneChange && cameraTransform) cameraTransform.localRotation = originalRotation; | ||
Integrations(); | ||
|
||
MelonLogger.Msg("Mod loaded."); | ||
} | ||
|
||
public override void OnPreferencesSaved() { | ||
public override void OnPreferencesSaved() | ||
{ | ||
UIXintegration = MelonPreferences.GetEntryValue<bool>(ModCategory, UIXIntegration); | ||
AMAPIintegration = MelonPreferences.GetEntryValue<bool>(ModCategory, AMAPIIntegration); | ||
rotationValue = MelonPreferences.GetEntryValue<float>(ModCategory, RotationValuePref); | ||
highPrecisionRotationValue = MelonPreferences.GetEntryValue<float>(ModCategory, HighPrecisionRotationValuePref); | ||
resetRotationOnSceneChange = MelonPreferences.GetEntryValue<bool>(ModCategory, ResetRotationOnSceneChangePref); | ||
} | ||
|
||
public override void VRChat_OnUiManagerInit() { | ||
var camera = Object.FindObjectOfType<VRCVrCamera>(); | ||
var transform = camera.GetIl2CppType().GetFields(BindingFlags.Public | BindingFlags.Instance).Where(f => f.FieldType == Il2CppType.Of<Transform>()).ToArray()[0]; | ||
cameraTransform = transform.GetValue(camera).Cast<Transform>(); | ||
originalRotation = cameraTransform.localRotation; | ||
} | ||
|
||
private static ICustomShowableLayoutedMenu rotationMenu = null; | ||
public override void OnSceneWasLoaded(int buildIndex, string sceneName) | ||
{ | ||
if (resetRotationOnSceneChange && cameraTransform) cameraTransform.localRotation = originalRotation; | ||
} | ||
|
||
// Based on knah's ViewPointTweaker mod, https://github.com/knah/VRCMods/blob/master/ViewPointTweaker | ||
private void ShowRotationMenu() { | ||
if (rotationMenu == null) { | ||
rotationMenu = ExpansionKitApi.CreateCustomQuickMenuPage(LayoutDescription.QuickMenu4Columns); | ||
public static IEnumerator WaitForUiInit() | ||
{ | ||
while (Object.FindObjectOfType<VRCVrCamera>() == null) | ||
yield return null; | ||
|
||
void Move(Vector3 direction) { | ||
cameraTransform.Rotate(direction, highPrecision ? highPrecisionRotationValue : rotationValue, Space.World); | ||
} | ||
var camera = Object.FindObjectOfType<VRCVrCamera>(); | ||
var Transform = camera.GetIl2CppType().GetFields(BindingFlags.Public | BindingFlags.Instance).Where(f => f.FieldType == Il2CppType.Of<Transform>()).ToArray()[0]; | ||
cameraTransform = Transform.GetValue(camera).Cast<Transform>(); | ||
originalRotation = cameraTransform.localRotation; | ||
transform = Camera.main.transform; | ||
|
||
var transform = Camera.main.transform; | ||
if (IsUsingAMAPI) typeof(AMAPIManager).GetMethod("ActionMenuIntegration").Invoke(null, null); | ||
} | ||
|
||
rotationMenu.AddSpacer(); | ||
rotationMenu.AddSimpleButton("Forward", () => Move(transform.right)); | ||
rotationMenu.AddSpacer(); | ||
rotationMenu.AddSpacer(); | ||
public static void Move(Vector3 direction) | ||
{ | ||
cameraTransform.Rotate(direction, highPrecision ? highPrecisionRotationValue : rotationValue, Space.World); | ||
} | ||
|
||
rotationMenu.AddSimpleButton("Tilt Left", () => Move(transform.forward)); | ||
rotationMenu.AddSimpleButton("Reset", () => cameraTransform.localRotation = originalRotation); | ||
rotationMenu.AddSimpleButton("Tilt Right", () => Move(-transform.forward)); | ||
rotationMenu.AddSpacer(); | ||
private static void Integrations() | ||
{ | ||
if (AMAPIintegration) | ||
{ | ||
if (MelonHandler.Mods.Any(x => x.Info.Name.Equals("ActionMenuApi"))) | ||
{ | ||
Assets.OnApplicationStart(); | ||
IsUsingAMAPI = true; | ||
} | ||
else MelonLogger.Warning("For a better experience, please consider using ActionMenuApi."); | ||
} | ||
else MelonLogger.Warning("Integration with ActionMenuApi has been deactivated on Settings."); | ||
|
||
if (UIXintegration) | ||
{ | ||
if (MelonHandler.Mods.Any(x => x.Info.Name.Equals("UI Expansion Kit"))) | ||
{ | ||
typeof(UIXManager).GetMethod("OnApplicationStart").Invoke(null, null); | ||
IsUsingUIX = true; | ||
} | ||
else MelonLogger.Warning("For a better experience, please consider using UIExpansionKit."); | ||
} | ||
else MelonLogger.Warning("Integration with UIExpansionKit has been deactivated on Settings."); | ||
|
||
rotationMenu.AddSpacer(); | ||
rotationMenu.AddSimpleButton("Backward", () => Move(-transform.right)); | ||
rotationMenu.AddSimpleButton("Left", () => Move(-transform.up)); | ||
rotationMenu.AddSimpleButton("Right", () => Move(transform.up)); | ||
if (!AMAPIintegration && !UIXintegration) | ||
MelonLogger.Warning("Both integrations (Action Menu and UiExpansionKit) have been deactivated. " + | ||
"The mod cannot run without those, therefore, expect it to fail. If this was not intended, " + | ||
"please consider activating at least one of the integrations on Settings."); | ||
|
||
rotationMenu.AddToggleButton("High precision", b => highPrecision = b, () => highPrecision); | ||
rotationMenu.AddSpacer(); | ||
rotationMenu.AddSpacer(); | ||
rotationMenu.AddSimpleButton("Back", rotationMenu.Hide); | ||
if (!IsUsingAMAPI && !IsUsingUIX) | ||
{ | ||
MelonLogger.Error("Failed to load both integrations with UIExpansionKit and ActionMenuApi! The mod will not be loaded."); | ||
} | ||
|
||
rotationMenu.Show(); | ||
else MelonCoroutines.Start(WaitForUiInit()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using UnityEngine; | ||
using ActionMenuApi.Api; | ||
using UnhollowerRuntimeLib; | ||
using System.Collections; | ||
using MelonLoader; | ||
using System.IO; | ||
using System.Reflection; | ||
using static TrackingRotator.TrackingRotatorMod; | ||
|
||
namespace TrackingRotator.Utils | ||
{ | ||
internal static class AMAPIManager | ||
{ | ||
public static void ActionMenuIntegration() | ||
{ | ||
VRCActionMenuPage.AddSubMenu(ActionMenuPage.Main, "<color=#00a2ff>Tracking Rotator</color>", () => | ||
{ | ||
CustomSubMenu.AddButton("Forward", () => Move(transform.right), Assets.Forward); //X+ | ||
CustomSubMenu.AddButton("Backward", () => Move(-transform.right), Assets.Backward); //X- | ||
CustomSubMenu.AddButton("Tilt Left", () => Move(transform.forward), Assets.TLeft); //Z+ | ||
CustomSubMenu.AddButton("Tilt Right", () => Move(-transform.forward), Assets.TRight); //Z- | ||
CustomSubMenu.AddButton("Left", () => Move(-transform.up), Assets.Left); //Y- | ||
CustomSubMenu.AddButton("Right", () => Move(transform.up), Assets.Right); //Y+ | ||
CustomSubMenu.AddSubMenu("Other", () => | ||
{ | ||
CustomSubMenu.AddButton("Reset", () => cameraTransform.localRotation = originalRotation, Assets.Reset); | ||
CustomSubMenu.AddToggle("High precision", highPrecision, b => highPrecision = b, Assets.HP); | ||
}, Assets.Other); | ||
}, Assets.Main); | ||
} | ||
} | ||
|
||
// The code below was based on Lily's... | ||
// https://github.com/KortyBoi/VRChat-TeleporterVR/blob/main/Utils/ResourceManager.cs | ||
// And also knah's! | ||
// https://github.com/knah/VRCMods/blob/master/UIExpansionKit | ||
internal static class Assets | ||
{ | ||
private static AssetBundle Bundle; | ||
public static Texture2D Main, Forward, Backward, TLeft, TRight, Left, Right, Other, Reset, HP; | ||
|
||
public static void OnApplicationStart() { MelonCoroutines.Start(LoadAssets()); } | ||
|
||
private static IEnumerator LoadAssets() | ||
{ | ||
try | ||
{ | ||
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TrackingRotator.trackingrotator")) | ||
{ | ||
using (var memoryStream = new MemoryStream((int)stream.Length)) | ||
{ | ||
stream.CopyTo(memoryStream); | ||
Bundle = AssetBundle.LoadFromMemory_Internal(memoryStream.ToArray(), 0); | ||
Bundle.hideFlags |= HideFlags.DontUnloadUnusedAsset; | ||
try { Main = LoadTexture("Main.png"); } catch { MelonLogger.Error("Failed to load image from asset bundle: Main.png"); } | ||
try { Forward = LoadTexture("Forward.png"); } catch { MelonLogger.Error("Failed to load image from asset bundle: Forward.png"); } | ||
try { Backward = LoadTexture("Backward.png"); } catch { MelonLogger.Error("Failed to load image from asset bundle: Backward.png"); } | ||
try { TLeft = LoadTexture("TLeft.png"); } catch { MelonLogger.Error("Failed to load image from asset bundle: TLeft.png"); } | ||
try { TRight = LoadTexture("TRight.png"); } catch { MelonLogger.Error("Failed to load image from asset bundle: TRight.png"); } | ||
try { Left = LoadTexture("Left.png"); } catch { MelonLogger.Error("Failed to load image from asset bundle: Left.png"); } | ||
try { Right = LoadTexture("Right.png"); } catch { MelonLogger.Error("Failed to load image from asset bundle: Right.png"); } | ||
try { Other = LoadTexture("Other.png"); } catch { MelonLogger.Error("Failed to load image from asset bundle: Other.png"); } | ||
try { Reset = LoadTexture("Reset.png"); } catch { MelonLogger.Error("Failed to load image from asset bundle: Reset.png"); } | ||
try { HP = LoadTexture("HP.png"); } catch { MelonLogger.Error("Failed to load image from asset bundle: HP.png"); } | ||
} | ||
} | ||
} catch { MelonLogger.Warning("Failed to load AssetBundle! ActionMenuApi will have its icons completely broken."); } | ||
yield break; | ||
} | ||
|
||
private static Texture2D LoadTexture(string Texture) | ||
{ | ||
Texture2D Texture2 = Bundle.LoadAsset_Internal(Texture, Il2CppType.Of<Texture2D>()).Cast<Texture2D>(); | ||
Texture2.hideFlags |= HideFlags.DontUnloadUnusedAsset; | ||
Texture2.hideFlags = HideFlags.HideAndDontSave; | ||
return Texture2; | ||
} | ||
} | ||
} |
Oops, something went wrong.