using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;
using UnityEngine.Rendering;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BigFit")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+6c33c99b2b5b1ff73854da0a7b0ce4e28433fe97")]
[assembly: AssemblyProduct("BigFit")]
[assembly: AssemblyTitle("BigFit")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace BigFit
{
public class Cosmetic
{
public string name;
public string id;
public string parent;
public GameObject model;
}
internal class CosmeticData
{
internal PlayerCharacter pc;
internal Transform armature;
internal Dictionary<string, Transform> meshes = new Dictionary<string, Transform>();
internal List<Cosmetic> activeCosmetics = new List<Cosmetic>();
internal List<GameObject> spawnedCosmetics = new List<GameObject>();
internal void SendCosmetics()
{
List<string> list = new List<string>(1) { ((NetworkBehaviour)pc).netId.ToString() };
for (int i = 0; i < activeCosmetics.Count; i++)
{
list.Add(activeCosmetics[i].id);
}
string text = "BigFit:" + string.Join(",", list);
Enumerator<PlayerCharacter> enumerator = PlayerCharacter.allPlayerCharacters.GetEnumerator();
bool flag = default(bool);
while (enumerator.MoveNext())
{
enumerator.Current.texter.CompleteInput(text, ref flag);
}
}
internal void ClearCosmetics()
{
HashSet<Renderer> hashSet = new HashSet<Renderer>();
for (int i = 0; i < spawnedCosmetics.Count; i++)
{
GameObject val = spawnedCosmetics[i];
Il2CppArrayBase<Renderer> componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
for (int j = 0; j < componentsInChildren.Count; j++)
{
if ((Object)(object)componentsInChildren[j] != (Object)null)
{
hashSet.Add(componentsInChildren[j]);
}
}
Object.Destroy((Object)(object)val);
}
spawnedCosmetics.Clear();
pc.looks.headRenderers = FilterLooksRenderers(pc.looks.headRenderers, hashSet);
pc.looks.torsoRenderers = FilterLooksRenderers(pc.looks.torsoRenderers, hashSet);
pc.looks.legsRenderers = FilterLooksRenderers(pc.looks.legsRenderers, hashSet);
}
internal void UpdateCosmetics()
{
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Expected O, but got Unknown
ClearCosmetics();
Shader shader = Shader.Find("Universal Render Pipeline/Lit");
int num = LayerMask.NameToLayer("Player");
foreach (Cosmetic activeCosmetic in activeCosmetics)
{
Transform val = meshes[activeCosmetic.parent];
GameObject val2 = Object.Instantiate<GameObject>(activeCosmetic.model, val, false);
spawnedCosmetics.Add(val2);
Il2CppArrayBase<Transform> componentsInChildren = val2.GetComponentsInChildren<Transform>(true);
for (int i = 0; i < componentsInChildren.Length; i++)
{
Transform val3 = componentsInChildren[i];
if (!((Object)(object)val3 == (Object)null))
{
((Component)val3).gameObject.SetActive(true);
if (num >= 0)
{
((Component)val3).gameObject.layer = num;
}
}
}
Il2CppArrayBase<MeshRenderer> componentsInChildren2 = val2.GetComponentsInChildren<MeshRenderer>(true);
List<LooksRenderer> list = new List<LooksRenderer>();
for (int j = 0; j < componentsInChildren2.Count; j++)
{
MeshRenderer val4 = componentsInChildren2[j];
((Renderer)val4).enabled = true;
((Renderer)val4).shadowCastingMode = (ShadowCastingMode)1;
Il2CppArrayBase<Material> sharedMaterials = (Il2CppArrayBase<Material>)(object)((Renderer)val4).sharedMaterials;
for (int k = 0; k < sharedMaterials.Count; k++)
{
if (sharedMaterials[k].GetColor("_Color").a <= 0.001f)
{
sharedMaterials[k] = ((Renderer)((Component)meshes[activeCosmetic.parent]).GetComponent<MeshRenderer>()).material;
}
else
{
ConvertShader(sharedMaterials[k], shader);
}
}
((Renderer)val4).sharedMaterials = sharedMaterials as Il2CppReferenceArray<Material>;
LooksRenderer val5 = new LooksRenderer
{
renderer = (Renderer)(object)val4
};
val5.SetLocal(activeCosmetic.parent == "head" || activeCosmetic.parent == "torso");
val5.remote = true;
if (!((NetworkBehaviour)pc).isLocalPlayer)
{
val5.SetRemote();
}
GC.KeepAlive(val5);
list.Add(val5);
}
if (activeCosmetic.parent == "head")
{
pc.looks.headRenderers = AppendLooksRenderers(pc.looks.headRenderers, list);
}
else if (activeCosmetic.parent == "torso")
{
pc.looks.torsoRenderers = AppendLooksRenderers(pc.looks.torsoRenderers, list);
}
else
{
pc.looks.legsRenderers = AppendLooksRenderers(pc.looks.legsRenderers, list);
}
}
}
private static void ConvertShader(Material mat, Shader shader)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0146: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_0236: Unknown result type (might be due to invalid IL or missing references)
//IL_0309: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)mat == (Object)null || (Object)(object)shader == (Object)null)
{
return;
}
Color val = (mat.HasProperty("_Color") ? mat.GetColor("_Color") : Color.white);
Texture val2 = (mat.HasProperty("_MainTex") ? mat.GetTexture("_MainTex") : null);
Vector2 val3 = (mat.HasProperty("_MainTex") ? mat.GetTextureScale("_MainTex") : Vector2.one);
Vector2 val4 = (mat.HasProperty("_MainTex") ? mat.GetTextureOffset("_MainTex") : Vector2.zero);
float num = (mat.HasProperty("_Glossiness") ? mat.GetFloat("_Glossiness") : 0.5f);
float num2 = (mat.HasProperty("_Metallic") ? mat.GetFloat("_Metallic") : 0f);
Texture val5 = (mat.HasProperty("_MetallicGlossMap") ? mat.GetTexture("_MetallicGlossMap") : null);
Texture val6 = (mat.HasProperty("_BumpMap") ? mat.GetTexture("_BumpMap") : null);
float num3 = (mat.HasProperty("_BumpScale") ? mat.GetFloat("_BumpScale") : 1f);
Color val7 = (mat.HasProperty("_EmissionColor") ? mat.GetColor("_EmissionColor") : Color.black);
Texture val8 = (mat.HasProperty("_EmissionMap") ? mat.GetTexture("_EmissionMap") : null);
Texture val9 = (mat.HasProperty("_OcclusionMap") ? mat.GetTexture("_OcclusionMap") : null);
float num4 = (mat.HasProperty("_OcclusionStrength") ? mat.GetFloat("_OcclusionStrength") : 1f);
float num5 = (mat.HasProperty("_Cutoff") ? mat.GetFloat("_Cutoff") : 0.5f);
int num6 = (mat.HasProperty("_Mode") ? Mathf.RoundToInt(mat.GetFloat("_Mode")) : 0);
mat.shader = shader;
if (mat.HasProperty("_BaseColor"))
{
mat.SetColor("_BaseColor", val);
}
if (mat.HasProperty("_BaseMap"))
{
mat.SetTexture("_BaseMap", val2);
mat.SetTextureScale("_BaseMap", val3);
mat.SetTextureOffset("_BaseMap", val4);
}
if (mat.HasProperty("_Smoothness"))
{
mat.SetFloat("_Smoothness", num);
}
if (mat.HasProperty("_Metallic"))
{
mat.SetFloat("_Metallic", num2);
}
if ((Object)(object)val5 != (Object)null && mat.HasProperty("_MetallicGlossMap"))
{
mat.SetTexture("_MetallicGlossMap", val5);
}
if ((Object)(object)val6 != (Object)null && mat.HasProperty("_BumpMap"))
{
mat.SetTexture("_BumpMap", val6);
if (mat.HasProperty("_BumpScale"))
{
mat.SetFloat("_BumpScale", num3);
}
}
if ((Object)(object)val8 != (Object)null && mat.HasProperty("_EmissionMap"))
{
mat.SetTexture("_EmissionMap", val8);
}
if (mat.HasProperty("_EmissionColor"))
{
mat.SetColor("_EmissionColor", val7);
}
if (((Color)(ref val7)).maxColorComponent > 0.001f || (Object)(object)val8 != (Object)null)
{
mat.EnableKeyword("_EMISSION");
}
if ((Object)(object)val9 != (Object)null && mat.HasProperty("_OcclusionMap"))
{
mat.SetTexture("_OcclusionMap", val9);
if (mat.HasProperty("_OcclusionStrength"))
{
mat.SetFloat("_OcclusionStrength", num4);
}
}
bool flag = num6 == 2 || num6 == 3;
bool flag2 = num6 == 1;
if (mat.HasProperty("_Surface"))
{
mat.SetFloat("_Surface", flag ? 1f : 0f);
}
if (mat.HasProperty("_AlphaClip"))
{
mat.SetFloat("_AlphaClip", flag2 ? 1f : 0f);
}
if (mat.HasProperty("_Cutoff"))
{
mat.SetFloat("_Cutoff", num5);
}
if (mat.HasProperty("_ZWrite"))
{
mat.SetFloat("_ZWrite", flag ? 0f : 1f);
}
if (mat.HasProperty("_SrcBlend"))
{
mat.SetFloat("_SrcBlend", flag ? 5f : 1f);
}
if (mat.HasProperty("_DstBlend"))
{
mat.SetFloat("_DstBlend", flag ? 10f : 0f);
}
}
private static Il2CppReferenceArray<LooksRenderer> AppendLooksRenderers(Il2CppReferenceArray<LooksRenderer> existing, List<LooksRenderer> additions)
{
int num = ((Il2CppArrayBase<LooksRenderer>)(object)existing)?.Length ?? 0;
Il2CppReferenceArray<LooksRenderer> val = new Il2CppReferenceArray<LooksRenderer>((long)(num + additions.Count));
for (int i = 0; i < num; i++)
{
((Il2CppArrayBase<LooksRenderer>)(object)val)[i] = ((Il2CppArrayBase<LooksRenderer>)(object)existing)[i];
}
for (int j = 0; j < additions.Count; j++)
{
((Il2CppArrayBase<LooksRenderer>)(object)val)[num + j] = additions[j];
}
return val;
}
private static Il2CppReferenceArray<LooksRenderer> FilterLooksRenderers(Il2CppReferenceArray<LooksRenderer> existing, HashSet<Renderer> removedRenderers)
{
if (existing == null || ((Il2CppArrayBase<LooksRenderer>)(object)existing).Length == 0)
{
return existing;
}
List<LooksRenderer> list = new List<LooksRenderer>();
for (int i = 0; i < ((Il2CppArrayBase<LooksRenderer>)(object)existing).Length; i++)
{
LooksRenderer val = ((Il2CppArrayBase<LooksRenderer>)(object)existing)[i];
if (!removedRenderers.Contains(val.renderer))
{
list.Add(val);
}
}
Il2CppReferenceArray<LooksRenderer> val2 = new Il2CppReferenceArray<LooksRenderer>((long)list.Count);
for (int j = 0; j < list.Count; j++)
{
((Il2CppArrayBase<LooksRenderer>)(object)val2)[j] = list[j];
}
return val2;
}
internal void FindArmature(PlayerCharacter character)
{
pc = character;
armature = FindChild(((Component)((Component)character).transform.root).gameObject.transform, "Armature");
}
internal void FindMeshes()
{
meshes.Add("head", FindChild(armature, "head_mesh"));
meshes.Add("torso", FindChild(armature, "torso_mesh"));
meshes.Add("bottom", FindChild(armature, "bottom_mesh"));
meshes.Add("footL", FindChild(armature, "left_foot_mesh"));
meshes.Add("footR", FindChild(armature, "right_foot_mesh"));
meshes.Add("handL", FindChild(armature, "left_hand_mesh"));
meshes.Add("handR", FindChild(armature, "right_hand_mesh"));
}
internal static Transform FindChild(Transform parent, string childName)
{
Transform result = null;
foreach (Transform componentsInChild in ((Component)parent).GetComponentsInChildren<Transform>())
{
if (((Object)componentsInChild).name == childName)
{
result = componentsInChild;
break;
}
}
return result;
}
}
[HarmonyPatch]
internal static class PlayerCharacterPatch
{
internal static PlayerCharacter myPlayerChar;
internal static List<CosmeticData> playerCosmetics = new List<CosmeticData>();
internal static CosmeticData myCosmetics;
[HarmonyPrefix]
[HarmonyPatch(typeof(TextChatSource), "AddMessage")]
private static bool MessagePatch(ref TextChatMessage message)
{
if (message.message.StartsWith("BigFit:"))
{
string message2 = message.message;
UpdateCosmetics(message2.Substring(7, message2.Length - 7).Split(","));
return false;
}
return true;
}
private static void UpdateCosmetics(string[] list)
{
if (!(((NetworkBehaviour)myPlayerChar).netId.ToString() == list[0]))
{
return;
}
myCosmetics.activeCosmetics = new List<Cosmetic>();
int i;
for (i = 1; i < list.Length; i++)
{
Cosmetic cosmetic = Plugin.cosmetics.Find((Cosmetic c) => c.id == list[i]);
if (cosmetic != null)
{
myCosmetics.activeCosmetics.Add(cosmetic);
}
myCosmetics.UpdateCosmetics();
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerCharacter), "Start")]
private static void InitializeDataPatch(PlayerCharacter __instance)
{
if (((NetworkBehaviour)__instance).isLocalPlayer)
{
playerCosmetics = new List<CosmeticData>();
}
CosmeticData cosmeticData = new CosmeticData();
cosmeticData.FindArmature(__instance);
cosmeticData.FindMeshes();
playerCosmetics.Add(cosmeticData);
Enumerator<PlayerCharacter> enumerator = PlayerCharacter.allPlayerCharacters.GetEnumerator();
while (enumerator.MoveNext())
{
PlayerCharacter current = enumerator.Current;
bool flag = false;
foreach (CosmeticData playerCosmetic in playerCosmetics)
{
if (playerCosmetic != null && (Object)(object)playerCosmetic.pc == (Object)(object)current)
{
flag = true;
break;
}
}
if (!flag)
{
CosmeticData cosmeticData2 = new CosmeticData();
cosmeticData2.FindArmature(current);
cosmeticData2.FindMeshes();
playerCosmetics.Add(cosmeticData2);
}
}
if (((NetworkBehaviour)__instance).isLocalPlayer)
{
myCosmetics = cosmeticData;
myPlayerChar = __instance;
cosmeticData.SendCosmetics();
}
}
}
internal class CosmeticUI : MonoBehaviour
{
private bool _showMenu;
private KeyCode _toggleKey = (KeyCode)287;
private Rect _windowRect = new Rect(20f, 20f, 340f, 420f);
private Vector2 _scrollPos = Vector2.zero;
private readonly HashSet<string> _selectedIds = new HashSet<string>();
private bool _initializedSelection;
private void Update()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(_toggleKey))
{
_showMenu = !_showMenu;
}
}
private void OnGUI()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
if (_showMenu)
{
if (PlayerCharacterPatch.myCosmetics == null || (Object)(object)PlayerCharacterPatch.myPlayerChar == (Object)null)
{
_windowRect = GUI.Window(98421, _windowRect, WindowFunction.op_Implicit((Action<int>)DrawWaitingWindow), "BigFit");
return;
}
SyncInitialSelectionFromActive();
_windowRect = GUI.Window(98421, _windowRect, WindowFunction.op_Implicit((Action<int>)DrawCosmeticsWindow), "BigFit");
}
}
private void DrawWaitingWindow(int windowId)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
GUILayout.Space(8f);
GUILayout.Label("Join a game first", (Il2CppReferenceArray<GUILayoutOption>)null);
GUI.DragWindow(new Rect(0f, 0f, 10000f, 24f));
}
private void DrawCosmeticsWindow(int windowId)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
GUILayout.Space(6f);
_scrollPos = GUILayout.BeginScrollView(_scrollPos, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) });
if (Plugin.cosmetics == null || Plugin.cosmetics.Count == 0)
{
GUILayout.Label("No cosmetics available", (Il2CppReferenceArray<GUILayoutOption>)null);
}
else
{
for (int i = 0; i < Plugin.cosmetics.Count; i++)
{
Cosmetic cosmetic = Plugin.cosmetics[i];
if (cosmetic == null)
{
continue;
}
bool flag = _selectedIds.Contains(cosmetic.id);
bool flag2 = GUILayout.Toggle(flag, cosmetic.name ?? "", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(22f) });
if (flag2 != flag)
{
if (flag2)
{
_selectedIds.Add(cosmetic.id);
}
else
{
_selectedIds.Remove(cosmetic.id);
}
ApplyAndSyncCosmetics();
}
}
}
GUILayout.EndScrollView();
GUI.DragWindow(new Rect(0f, 0f, 10000f, 24f));
}
[HideFromIl2Cpp]
private void SyncInitialSelectionFromActive()
{
if (_initializedSelection)
{
return;
}
_selectedIds.Clear();
List<Cosmetic> activeCosmetics = PlayerCharacterPatch.myCosmetics.activeCosmetics;
if (activeCosmetics != null)
{
for (int i = 0; i < activeCosmetics.Count; i++)
{
if (activeCosmetics[i] != null && !string.IsNullOrEmpty(activeCosmetics[i].id))
{
_selectedIds.Add(activeCosmetics[i].id);
}
}
}
_initializedSelection = true;
}
[HideFromIl2Cpp]
private void ApplyAndSyncCosmetics()
{
CosmeticData myCosmetics = PlayerCharacterPatch.myCosmetics;
if (myCosmetics == null)
{
return;
}
List<Cosmetic> list = new List<Cosmetic>();
for (int i = 0; i < Plugin.cosmetics.Count; i++)
{
Cosmetic cosmetic = Plugin.cosmetics[i];
if (cosmetic != null && !string.IsNullOrEmpty(cosmetic.id) && _selectedIds.Contains(cosmetic.id))
{
list.Add(cosmetic);
}
}
myCosmetics.activeCosmetics = list;
myCosmetics.UpdateCosmetics();
myCosmetics.SendCosmetics();
}
}
[BepInPlugin("owomay.bigfit", "Big Fit", "1.0.0")]
public class Plugin : BasePlugin
{
public const string Guid = "owomay.bigfit";
public const string Name = "Big Fit";
public const string Version = "1.0.0";
internal static ManualLogSource Logger;
public static List<Cosmetic> cosmetics = new List<Cosmetic>();
public override void Load()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Expected O, but got Unknown
Logger = ((BasePlugin)this).Log;
new Harmony("owomay.bigfit").PatchAll();
ClassInjector.RegisterTypeInIl2Cpp<CosmeticUI>();
GameObject val = new GameObject("BigFit_CosmeticUI")
{
hideFlags = (HideFlags)61
};
Object.DontDestroyOnLoad((Object)val);
val.AddComponent<CosmeticUI>();
ManualLogSource logger = Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(7, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("Big Fit");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" loaded");
}
logger.LogInfo(val2);
}
public static void RegisterCosmetic(Cosmetic cosm)
{
Object.DontDestroyOnLoad((Object)(object)cosm.model);
((Object)cosm.model).hideFlags = (HideFlags)61;
cosmetics.Add(cosm);
}
}
public static class NativeBundle
{
private struct ManagedSpanWrapper
{
public IntPtr begin;
public int length;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate IntPtr LoadFromFileDelegate(ref ManagedSpanWrapper path, uint crc, ulong offset);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate IntPtr LoadAssetDelegate(IntPtr self, ref ManagedSpanWrapper name, IntPtr type);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void UnloadDelegate(IntPtr self, [MarshalAs(UnmanagedType.U1)] bool unloadAllLoadedObjects);
[DllImport("GameAssembly", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr il2cpp_gchandle_get_target(IntPtr gchandle);
private static T Resolve<T>(string name) where T : Delegate
{
IntPtr intPtr = IL2CPP.il2cpp_resolve_icall(name);
if (intPtr == IntPtr.Zero)
{
throw new MissingMethodException("icall '" + name + "' does not exist in this game build");
}
return Marshal.GetDelegateForFunctionPointer<T>(intPtr);
}
public static AssetBundle LoadFromFile(string path)
{
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
LoadFromFileDelegate loadFromFileDelegate = Resolve<LoadFromFileDelegate>("UnityEngine.AssetBundle::LoadFromFile_Internal_Injected");
IntPtr intPtr = Marshal.StringToHGlobalUni(path);
try
{
ManagedSpanWrapper path2 = new ManagedSpanWrapper
{
begin = intPtr,
length = path.Length
};
IntPtr intPtr2 = loadFromFileDelegate(ref path2, 0u, 0uL);
if (intPtr2 == IntPtr.Zero)
{
return null;
}
IntPtr intPtr3 = il2cpp_gchandle_get_target(intPtr2);
return (intPtr3 == IntPtr.Zero) ? ((AssetBundle)null) : new AssetBundle(intPtr3);
}
finally
{
Marshal.FreeHGlobal(intPtr);
}
}
public static GameObject LoadGameObject(AssetBundle bundle, string name)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
IntPtr intPtr = LoadAssetPointer(bundle, name, Il2CppType.Of<GameObject>());
if (!(intPtr == IntPtr.Zero))
{
return new GameObject(intPtr);
}
return null;
}
public static IntPtr LoadAssetPointer(AssetBundle bundle, string name, Type type)
{
LoadAssetDelegate loadAssetDelegate = Resolve<LoadAssetDelegate>("UnityEngine.AssetBundle::LoadAsset_Internal_Injected");
IntPtr intPtr = Marshal.StringToHGlobalUni(name);
try
{
ManagedSpanWrapper name2 = new ManagedSpanWrapper
{
begin = intPtr,
length = name.Length
};
IntPtr intPtr2 = loadAssetDelegate(((Object)bundle).m_CachedPtr, ref name2, ((Il2CppObjectBase)type).Pointer);
if (intPtr2 == IntPtr.Zero)
{
return IntPtr.Zero;
}
return il2cpp_gchandle_get_target(intPtr2);
}
finally
{
Marshal.FreeHGlobal(intPtr);
}
}
public static void Unload(AssetBundle bundle, bool unloadAllLoadedObjects)
{
Resolve<UnloadDelegate>("UnityEngine.AssetBundle::Unload_Injected")(((Object)bundle).m_CachedPtr, unloadAllLoadedObjects);
}
}
}