using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using CustomPMS;
using CustomPMS.Utils;
using MelonLoader;
using RUMBLE.Managers;
using RumbleModdingFramework;
using UnhollowerBaseLib;
using UnhollowerBaseLib.Attributes;
using UnhollowerRuntimeLib;
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(PmsMain), "CustomPlayerModels", "1.0.0", "Hazzy", null)]
[assembly: AssemblyTitle("CustomPMS")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CustomPMS")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2671BA59-3AD6-433E-9734-8BD77C3B537A")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomPMS
{
public class PmsMain : MelonMod
{
public List<Transform> playerBones = new List<Transform>();
public List<Transform> importedBones = new List<Transform>();
public PlayerManager playerManager;
public ApplySkin playerModelScript;
private bool initialized = false;
public Transform playerRoot;
public bool doingProcess;
public bool ran = false;
public Dictionary<string, Object> pmBundles = new Dictionary<string, Object>();
public override void OnApplicationStart()
{
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Expected O, but got Unknown
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Expected O, but got Unknown
Directory.CreateDirectory(MelonUtils.UserDataDirectory + "\\CustomPMS");
string[] files = Directory.GetFiles($"{MelonUtils.UserDataDirectory}\\CustomPMS", "*.rpm");
VrMenuPageBuilder val = VrMenuPageBuilder.Builder();
int num = 0;
string[] array = files;
foreach (string pmName in array)
{
int num2 = num;
val.AddButton(new VrMenuButton(Path.GetFileNameWithoutExtension(files[num]), (Action)delegate
{
MelonCoroutines.Start(playerModelScript.Delay(pmName));
}));
num++;
}
VrMenuPage customPMSPage = val.Build();
VrMenu.RegisterMainButton(new VrMenuButton("PlayerModels", (Action)delegate
{
customPMSPage.Open();
}));
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
if (!(sceneName == "CustomArena0") && !(sceneName == "CustomArena1") && !ran)
{
ran = true;
MelonLogger.Msg("Loading Models");
AddModelChangeScript();
}
}
private void AddModelChangeScript()
{
GameObject val = GameObject.Find("Game Instance/Initializable/PlayerManager");
if ((Object)(object)val == (Object)null)
{
MelonLogger.Msg("playerManagerGO is null");
}
playerModelScript = val.AddComponent<ApplySkin>();
}
}
[RegisterTypeInIl2Cpp]
public class ApplySkin : MonoBehaviour
{
public PlayerManager playerManager;
public List<Transform> playerBones = new List<Transform>();
public List<Transform> importedBones = new List<Transform>();
public bool prevRun = false;
public AssetBundle oldPM;
public GameObject prevPM;
public GameObject prevVisuals;
public GameObject prevVisualsObj;
public List<GameObject> needDestroy = new List<GameObject>();
public bool prevRan = false;
public ApplySkin(IntPtr intPtr)
: base(intPtr)
{
}
private void Start()
{
playerManager = ((Component)this).gameObject.GetComponent<PlayerManager>();
}
public IEnumerator Delay(string modelPath)
{
yield return (object)new WaitForFixedUpdate();
yield return (object)new WaitForFixedUpdate();
yield return (object)new WaitForFixedUpdate();
yield return (object)new WaitForFixedUpdate();
yield return (object)new WaitForFixedUpdate();
yield return (object)new WaitForFixedUpdate();
yield return (object)new WaitForFixedUpdate();
yield return (object)new WaitForFixedUpdate();
yield return (object)new WaitForFixedUpdate();
yield return (object)new WaitForFixedUpdate();
yield return (object)new WaitForFixedUpdate();
yield return (object)new WaitForFixedUpdate();
GameObject playerObj = ((Component)playerManager.LocalPlayer.Controller).gameObject;
ChangeModel(playerObj, modelPath);
}
private void ChangeModel(GameObject playerObj, string modelPath)
{
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_0222: Unknown result type (might be due to invalid IL or missing references)
Transform val = playerObj.transform.Find("Visuals");
Transform val2 = playerObj.transform.Find("Visuals/RIG");
if (prevRan)
{
foreach (GameObject item in needDestroy)
{
Object.Destroy((Object)(object)item);
}
}
foreach (SkinnedMeshRenderer componentsInChild in ((Component)val).GetComponentsInChildren<SkinnedMeshRenderer>())
{
((Component)componentsInChild).gameObject.SetActive(false);
}
importedBones.Clear();
GameObject val3 = null;
AssetBundle assetBundle = (oldPM = AssetBundle.LoadFromFile(modelPath));
val3 = assetBundle.LoadAsset<GameObject>("CustomPM");
Transform transform = Object.Instantiate<GameObject>(val3).transform;
assetBundle.Unload(unloadAllLoadedObjects: false);
prevPM = ((Component)transform).gameObject;
Transform val4 = transform.Find("RIG");
MelonLogger.Msg((object)val4);
transform.position = val2.position;
Transform val5 = transform.Find("Visuals");
prevVisuals = ((Component)val5).gameObject;
val5.parent = val;
val5.localPosition = Vector3.zero;
foreach (GameObject componentsInChild2 in ((Component)transform).GetComponentsInChildren<GameObject>())
{
needDestroy.Add(componentsInChild2);
}
needDestroy.Add(((Component)transform).gameObject);
Transform[] array = Il2CppArrayBase<Transform>.op_Implicit(((Component)val4).GetComponentsInChildren<Transform>());
Transform[] second = Il2CppArrayBase<Transform>.op_Implicit(((Component)val2).GetComponentsInChildren<Transform>());
IEnumerable<Transform> enumerable = array.Intersect(second);
foreach (Transform componentsInChild3 in ((Component)val2).GetComponentsInChildren<Transform>())
{
Transform[] array2 = array;
foreach (Transform val6 in array2)
{
if (((Object)componentsInChild3).name.Equals(((Object)val6).name))
{
componentsInChild3.position = val6.position;
componentsInChild3.rotation = val6.rotation;
val6.parent = componentsInChild3;
importedBones.Add(val6);
}
}
}
prevRan = true;
MelonLogger.Msg("Replaced bones!");
}
}
}
namespace CustomPMS.Utils
{
public class AssetBundle : Object
{
internal delegate IntPtr d_LoadFromFile(IntPtr path, uint crc, ulong offset);
private delegate IntPtr d_LoadFromMemory(IntPtr binary, uint crc);
public delegate IntPtr d_GetAllLoadedAssetBundles_Native();
internal delegate IntPtr d_LoadAssetWithSubAssets_Internal(IntPtr _this, IntPtr name, IntPtr type);
internal delegate IntPtr d_LoadAsset_Internal(IntPtr _this, IntPtr name, IntPtr type);
internal delegate void d_Unload(IntPtr _this, bool unloadAllLoadedObjects);
public readonly IntPtr m_bundlePtr = IntPtr.Zero;
static AssetBundle()
{
ClassInjector.RegisterTypeInIl2Cpp<AssetBundle>();
}
[HideFromIl2Cpp]
public static AssetBundle LoadFromFile(string path)
{
IntPtr intPtr = ICallManager.GetICallUnreliable<d_LoadFromFile>(new string[2] { "UnityEngine.AssetBundle::LoadFromFile_Internal", "UnityEngine.AssetBundle::LoadFromFile" })(IL2CPP.ManagedStringToIl2Cpp(path), 0u, 0uL);
return (intPtr != IntPtr.Zero) ? new AssetBundle(intPtr) : null;
}
[HideFromIl2Cpp]
public static AssetBundle LoadFromMemory(byte[] binary, uint crc = 0u)
{
IntPtr intPtr = ICallManager.GetICallUnreliable<d_LoadFromMemory>(new string[2] { "UnityEngine.AssetBundle::LoadFromMemory_Internal", "UnityEngine.AssetBundle::LoadFromMemory" })(((Il2CppObjectBase)Il2CppStructArray<byte>.op_Implicit(binary)).Pointer, crc);
return (intPtr != IntPtr.Zero) ? new AssetBundle(intPtr) : null;
}
[HideFromIl2Cpp]
public static AssetBundle[] GetAllLoadedAssetBundles()
{
IntPtr intPtr = ICallManager.GetICall<d_GetAllLoadedAssetBundles_Native>("UnityEngine.AssetBundle::GetAllLoadedAssetBundles_Native")();
return (intPtr != IntPtr.Zero) ? Il2CppArrayBase<AssetBundle>.op_Implicit((Il2CppArrayBase<AssetBundle>)(object)new Il2CppReferenceArray<AssetBundle>(intPtr)) : null;
}
public AssetBundle(IntPtr ptr)
: base(ptr)
{
m_bundlePtr = ptr;
}
[HideFromIl2Cpp]
public Object[] LoadAllAssets()
{
IntPtr intPtr = ICallManager.GetICall<d_LoadAssetWithSubAssets_Internal>("UnityEngine.AssetBundle::LoadAssetWithSubAssets_Internal")(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(""), ((Il2CppObjectBase)Il2CppType.Of<Object>()).Pointer);
return (Object[])((intPtr != IntPtr.Zero) ? ((Array)Il2CppArrayBase<Object>.op_Implicit((Il2CppArrayBase<Object>)(object)new Il2CppReferenceArray<Object>(intPtr))) : ((Array)new Object[0]));
}
[HideFromIl2Cpp]
public T LoadAsset<T>(string name) where T : Object
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
IntPtr intPtr = ICallManager.GetICall<d_LoadAsset_Internal>("UnityEngine.AssetBundle::LoadAsset_Internal")(m_bundlePtr, IL2CPP.ManagedStringToIl2Cpp(name), ((Il2CppObjectBase)Il2CppType.Of<T>()).Pointer);
return (intPtr != IntPtr.Zero) ? ((Il2CppObjectBase)new Object(intPtr)).TryCast<T>() : default(T);
}
[HideFromIl2Cpp]
public void Unload(bool unloadAllLoadedObjects)
{
ICallManager.GetICall<d_Unload>("UnityEngine.AssetBundle::Unload")(m_bundlePtr, unloadAllLoadedObjects);
}
}
public static class ICallManager
{
private static readonly Dictionary<string, Delegate> iCallCache = new Dictionary<string, Delegate>();
private static readonly Dictionary<string, Delegate> unreliableCache = new Dictionary<string, Delegate>();
public static T GetICall<T>(string signature) where T : Delegate
{
if (iCallCache.ContainsKey(signature))
{
return (T)iCallCache[signature];
}
IntPtr intPtr = IL2CPP.il2cpp_resolve_icall(signature);
if (intPtr == IntPtr.Zero)
{
throw new MissingMethodException("Could not find any iCall with the signature '" + signature + "'!");
}
Delegate delegateForFunctionPointer = Marshal.GetDelegateForFunctionPointer(intPtr, typeof(T));
iCallCache.Add(signature, delegateForFunctionPointer);
return (T)delegateForFunctionPointer;
}
public static T GetICallUnreliable<T>(params string[] possibleSignatures) where T : Delegate
{
string text = possibleSignatures.First();
if (unreliableCache.ContainsKey(text))
{
return (T)unreliableCache[text];
}
foreach (string text2 in possibleSignatures)
{
IntPtr intPtr = IL2CPP.il2cpp_resolve_icall(text2);
if (intPtr != IntPtr.Zero)
{
T val = (T)Marshal.GetDelegateForFunctionPointer(intPtr, typeof(T));
unreliableCache.Add(text, val);
return val;
}
}
throw new MissingMethodException("Could not find any iCall from list of provided signatures starting with '" + text + "'!");
}
}
}