using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppExitGames.Client.Photon;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppPhoton.Pun;
using Il2CppPhoton.Realtime;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using MelonLoader;
using Microsoft.CodeAnalysis;
using RumbleModdingAPI;
using RumbleModdingLibrary;
using RumbleModdingLibrary.Utilities;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "Rumble Modding Library", "1.0.0", "elmish", null)]
[assembly: MelonGame(null, null)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("RumbleModdingLibrary")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RumbleModdingLibrary")]
[assembly: AssemblyTitle("RumbleModdingLibrary")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace RumbleModdingLibrary
{
public static class BuildInfo
{
public const string Name = "Rumble Modding Library";
public const string Description = "a general library for rumble";
public const string Author = "elmish";
public const string Company = null;
public const string Version = "1.0.0";
public const string DownloadLink = null;
}
public class Main : MelonMod
{
public GameObject manager;
public override void OnLateInitializeMelon()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
PhotonRpcInjector.Initialize();
manager = new GameObject("Manager component holder (Rumble Modding Library)");
manager.AddComponent<RaiseEventManager>();
manager.AddComponent<ControllerInputManager>();
Object.DontDestroyOnLoad((Object)(object)manager);
}
}
}
namespace RumbleModdingLibrary.Utilities
{
[RegisterTypeInIl2Cpp]
internal class ControllerInputManager : MonoBehaviour
{
private float rPrimaryFloat;
private bool rPrimaryBool;
private bool rPrimaryPrevBool;
private float rSecondaryFloat;
private bool rSecondaryBool;
private bool rSecondaryPrevBool;
private float rStickFloat;
private bool rStickBool;
private bool rStickPrevBool;
private float rTriggerFloat;
private bool rTriggerBool;
private bool rTriggerPrevBool;
private float rGripFloat;
private bool rGripBool;
private bool rGripPrevBool;
private float lPrimaryFloat;
private bool lPrimaryBool;
private bool lPrimaryPrevBool;
private float lSecondaryFloat;
private bool lSecondaryBool;
private bool lSecondaryPrevBool;
private float lStickFloat;
private bool lStickBool;
private bool lStickPrevBool;
private float lTriggerFloat;
private bool lTriggerBool;
private bool lTriggerPrevBool;
private float lGripFloat;
private bool lGripBool;
private bool lGripPrevBool;
private void Update()
{
GetFloats();
UpdateFloats();
GetAndUpdateBooleans();
UpdateJoysticks();
UpdatePressedOrReleasedThisFrame();
}
private void GetFloats()
{
rPrimaryFloat = RightController.GetPrimary();
rSecondaryFloat = RightController.GetSecondary();
rStickFloat = RightController.GetJoystickClick();
rTriggerFloat = RightController.GetTrigger();
rGripFloat = RightController.GetGrip();
lPrimaryFloat = LeftController.GetPrimary();
lSecondaryFloat = LeftController.GetSecondary();
lStickFloat = LeftController.GetJoystickClick();
lTriggerFloat = LeftController.GetTrigger();
lGripFloat = LeftController.GetGrip();
}
private void GetAndUpdateBooleans()
{
rPrimaryPrevBool = rPrimaryBool;
rPrimaryBool = rPrimaryFloat > 0.25f;
ControllerInputPoller.RightController.primaryButton.pressed = rPrimaryBool;
rSecondaryPrevBool = rSecondaryBool;
rSecondaryBool = rSecondaryFloat > 0.25f;
ControllerInputPoller.RightController.secondaryButton.pressed = rSecondaryBool;
rStickPrevBool = rStickBool;
rStickBool = rStickFloat > 0.25f;
ControllerInputPoller.RightController.joystickClick.pressed = rStickBool;
rTriggerPrevBool = rTriggerBool;
rTriggerBool = rTriggerFloat > 0.25f;
ControllerInputPoller.RightController.trigger.pressed = rTriggerBool;
rGripPrevBool = rGripBool;
rGripBool = rGripFloat > 0.25f;
ControllerInputPoller.RightController.grip.pressed = rGripBool;
lPrimaryPrevBool = lPrimaryBool;
lPrimaryBool = lPrimaryFloat > 0.25f;
ControllerInputPoller.LeftController.primaryButton.pressed = lPrimaryBool;
lSecondaryPrevBool = lSecondaryBool;
lSecondaryBool = lSecondaryFloat > 0.25f;
ControllerInputPoller.LeftController.secondaryButton.pressed = lSecondaryBool;
lStickPrevBool = lStickBool;
lStickBool = lStickFloat > 0.25f;
ControllerInputPoller.LeftController.joystickClick.pressed = lStickBool;
lTriggerPrevBool = lTriggerBool;
lTriggerBool = lTriggerFloat > 0.25f;
ControllerInputPoller.LeftController.trigger.pressed = lTriggerBool;
lGripPrevBool = lGripBool;
lGripBool = lGripFloat > 0.25f;
ControllerInputPoller.LeftController.grip.pressed = lGripBool;
}
private void UpdateFloats()
{
ControllerInputPoller.RightController.primaryButton.value = rPrimaryFloat;
ControllerInputPoller.RightController.secondaryButton.value = rSecondaryFloat;
ControllerInputPoller.RightController.joystickClick.value = rStickFloat;
ControllerInputPoller.RightController.trigger.value = rTriggerFloat;
ControllerInputPoller.RightController.grip.value = rGripFloat;
ControllerInputPoller.LeftController.primaryButton.value = lPrimaryFloat;
ControllerInputPoller.LeftController.secondaryButton.value = lSecondaryFloat;
ControllerInputPoller.LeftController.joystickClick.value = lStickFloat;
ControllerInputPoller.LeftController.trigger.value = lTriggerFloat;
ControllerInputPoller.LeftController.grip.value = lGripFloat;
}
private void UpdateJoysticks()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
ControllerInputPoller.RightController.joystickPosition = RightController.GetJoystick();
ControllerInputPoller.LeftController.joystickPosition = LeftController.GetJoystick();
}
private void UpdatePressedOrReleasedThisFrame()
{
ControllerInputPoller.RightController.primaryButton.wasPressedThisFrame = rPrimaryBool && !rPrimaryPrevBool;
ControllerInputPoller.RightController.primaryButton.wasReleasedThisFrame = !rPrimaryBool && rPrimaryPrevBool;
ControllerInputPoller.RightController.secondaryButton.wasPressedThisFrame = rSecondaryBool && !rSecondaryPrevBool;
ControllerInputPoller.RightController.secondaryButton.wasReleasedThisFrame = !rSecondaryBool && rSecondaryPrevBool;
ControllerInputPoller.RightController.joystickClick.wasPressedThisFrame = rStickBool && !rStickPrevBool;
ControllerInputPoller.RightController.joystickClick.wasReleasedThisFrame = !rStickBool && rStickPrevBool;
ControllerInputPoller.RightController.trigger.wasPressedThisFrame = rTriggerBool && !rTriggerPrevBool;
ControllerInputPoller.RightController.trigger.wasReleasedThisFrame = !rTriggerBool && rTriggerPrevBool;
ControllerInputPoller.RightController.grip.wasPressedThisFrame = rGripBool && !rGripPrevBool;
ControllerInputPoller.RightController.grip.wasReleasedThisFrame = !rGripBool && rGripPrevBool;
ControllerInputPoller.LeftController.primaryButton.wasPressedThisFrame = lPrimaryBool && !lPrimaryPrevBool;
ControllerInputPoller.LeftController.primaryButton.wasReleasedThisFrame = !lPrimaryBool && lPrimaryPrevBool;
ControllerInputPoller.LeftController.secondaryButton.wasPressedThisFrame = lSecondaryBool && !lSecondaryPrevBool;
ControllerInputPoller.LeftController.secondaryButton.wasReleasedThisFrame = !lSecondaryBool && lSecondaryPrevBool;
ControllerInputPoller.LeftController.joystickClick.wasPressedThisFrame = lStickBool && !lStickPrevBool;
ControllerInputPoller.LeftController.joystickClick.wasReleasedThisFrame = !lStickBool && lStickPrevBool;
ControllerInputPoller.LeftController.trigger.wasPressedThisFrame = lTriggerBool && !lTriggerPrevBool;
ControllerInputPoller.LeftController.trigger.wasReleasedThisFrame = !lTriggerBool && lTriggerPrevBool;
ControllerInputPoller.LeftController.grip.wasPressedThisFrame = lGripBool && !lGripPrevBool;
ControllerInputPoller.LeftController.grip.wasReleasedThisFrame = !lGripBool && lGripPrevBool;
}
}
public static class ControllerInputPoller
{
public class Button
{
public bool wasPressedThisFrame;
public bool wasReleasedThisFrame;
public bool pressed;
public float value;
}
public class Controller
{
public Button? primaryButton = new Button();
public Button? secondaryButton = new Button();
public Button? joystickClick = new Button();
public Button? trigger = new Button();
public Button? grip = new Button();
public Vector2 joystickPosition = default(Vector2);
}
public static Controller? RightController = new Controller();
public static Controller? LeftController = new Controller();
}
[AttributeUsage(AttributeTargets.Method)]
public class PunRPC : Attribute
{
}
public static class PhotonRpcInjector
{
public static Dictionary<string, List<MethodInfo>> methodsInType = new Dictionary<string, List<MethodInfo>>();
public static void Initialize()
{
MelonLogger.Msg("initializing RPC Manager");
ReadOnlyCollection<MelonMod> registeredMelons = MelonTypeBase<MelonMod>.RegisteredMelons;
foreach (MelonMod item in registeredMelons)
{
Assembly assembly = ((MelonBase)item).MelonAssembly.Assembly;
Type[] types = assembly.GetTypes();
Type[] array = types;
foreach (Type type in array)
{
MethodInfo[] methods = type.GetMethods();
foreach (MethodInfo methodInfo in methods)
{
PunRPC customAttribute = methodInfo.GetCustomAttribute<PunRPC>();
if (customAttribute != null)
{
MelonLogger.Msg("found RPC attribute at " + methodInfo.Name);
RegisterMethod(type, methodInfo);
}
}
}
}
}
public static void RegisterMethod(Type type, MethodInfo method)
{
string fullName = type.FullName;
if (!methodsInType.ContainsKey(fullName))
{
methodsInType[fullName] = new List<MethodInfo>();
}
methodsInType[fullName].Add(method);
RegisterRpc(method.Name);
MelonLogger.Msg($"Successfully registered: {fullName}.{method.Name} as an RPC");
}
public static void RegisterRpc(string methodName)
{
Dictionary<string, int> rpcShortcuts = PhotonNetwork.rpcShortcuts;
List<string> rpcList = PhotonNetwork.PhotonServerSettings.RpcList;
if (!rpcShortcuts.ContainsKey(methodName) && !rpcList.Contains(methodName))
{
int count = rpcShortcuts.Count;
rpcShortcuts.Add(methodName, count);
rpcList.Add(methodName);
MelonLogger.Msg($"Registered RPC '{methodName}' with shortcut ID {count}");
}
else
{
MelonLogger.Msg("RPC '" + methodName + "' already registered.");
}
}
}
[HarmonyPatch(typeof(SupportClass), "GetMethods")]
public static class GetMethodsPatch
{
public static void Postfix(Type type, ref List<MethodInfo> __result)
{
string fullName = type.FullName;
if (!PhotonRpcInjector.methodsInType.ContainsKey(fullName))
{
return;
}
List<MethodInfo> list = PhotonRpcInjector.methodsInType[fullName];
Il2CppReferenceArray<MethodInfo> methods = type.GetMethods();
foreach (MethodInfo item in (Il2CppArrayBase<MethodInfo>)(object)methods)
{
foreach (MethodInfo item2 in list)
{
if (((MemberInfo)item).Name == item2.Name)
{
__result.Add(item);
}
}
}
}
}
[RegisterTypeInIl2Cpp]
public class RaiseEventManager : MonoBehaviour
{
internal static RaiseEventManager instance;
internal Dictionary<string, RumbleMod> RegisteredMods = new Dictionary<string, RumbleMod>();
public static Object BoxListToObject(List<Object> data)
{
Il2CppReferenceArray<Object> val = new Il2CppReferenceArray<Object>((long)data.Count);
for (int i = 0; i < data.Count; i++)
{
((Il2CppArrayBase<Object>)(object)val)[i] = data[i];
}
return ((Il2CppObjectBase)val).Cast<Object>();
}
public void Start()
{
instance = this;
LoadBalancingClient networkingClient = PhotonNetwork.NetworkingClient;
networkingClient.EventReceived += Action<EventData>.op_Implicit((Action<EventData>)OnEvent);
}
public void RegisterMod(RumbleMod mod)
{
RegisteredMods.Add(((MelonBase)mod).Info.Name + "|" + ((MelonBase)mod).Info.Author, mod);
}
public void OnEvent(EventData eventData)
{
if (eventData.Code == 18)
{
Object customData = eventData.CustomData;
Il2CppReferenceArray<Object> val = ((Il2CppObjectBase)customData).Cast<Il2CppReferenceArray<Object>>();
MelonLogger.Msg($"unboxing data with length of {((Il2CppArrayBase<Object>)(object)val).Length}");
List<Object> list = new List<Object>();
for (int i = 1; i < ((Il2CppArrayBase<Object>)(object)val).Count; i++)
{
list.Add(((Il2CppArrayBase<Object>)(object)val)[i]);
}
string text = ((Il2CppArrayBase<Object>)(object)val)[0].ToString();
MelonLogger.Msg("RaiseEvent received and is being sent to '" + text + "'");
RegisteredMods[text].OnEvent(list);
}
}
}
public class RumbleMod : MelonMod
{
public bool EventsRegisted;
public void RegisterEvents()
{
if (!EventsRegisted)
{
RaiseEventManager.instance.RegisterMod(this);
EventsRegisted = true;
}
}
public void RaiseEvent(List<Object> data, RaiseEventOptions raiseEventOptions, SendOptions sendOptions)
{
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
data.Insert(0, Object.op_Implicit(((MelonBase)this).Info.Name + "|" + ((MelonBase)this).Info.Author));
Il2CppReferenceArray<Object> val = new Il2CppReferenceArray<Object>((long)data.Count);
for (int i = 0; i < data.Count; i++)
{
((Il2CppArrayBase<Object>)(object)val)[i] = data[i];
}
Object val2 = ((Il2CppObjectBase)val).Cast<Object>();
PhotonNetwork.RaiseEvent((byte)18, val2, raiseEventOptions, sendOptions);
}
public virtual void OnEvent(List<Object> data)
{
}
}
}