Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of JeffREX v1.0.0
JeffREX.dll
Decompiled 17 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using MonoMod.RuntimeDetour.HookGen; using RoR2; using RoR2.ContentManagement; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace JeffREX; [BepInPlugin("com.miminisusuki.JeffREX", "JeffREX", "1.0.0")] public class JeffREXPlugin : BaseUnityPlugin { private static AssetBundle assetBundle; private static readonly List<Material> materialsWithRoRShader = new List<Material>(); internal static JeffREXPlugin Instance { get; private set; } internal static ManualLogSource InstanceLogger { get { JeffREXPlugin instance = Instance; if (instance == null) { return null; } return ((BaseUnityPlugin)instance).Logger; } } private void Start() { Instance = this; using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("JeffREX.miminisusukijeffrex")) { assetBundle = AssetBundle.LoadFromStream(stream); } ((ResourceAvailability)(ref BodyCatalog.availability)).CallWhenAvailable((Action)BodyCatalogInit); HookEndpointManager.Add((MethodBase)typeof(Language).GetMethod("LoadStrings"), (Delegate)new Action<Action<Language>, Language>(LanguageLoadStrings)); ReplaceShaders(); } private static void ReplaceShaders() { LoadMaterialsWithReplacedShader("RoR2/Base/Shaders/HGStandard.shader", "Assets/JeffREX/JeffREXMat.mat"); } private static void LoadMaterialsWithReplacedShader(string shaderPath, params string[] materialPaths) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) Shader shader = Addressables.LoadAssetAsync<Shader>((object)shaderPath).WaitForCompletion(); foreach (string text in materialPaths) { Material val = assetBundle.LoadAsset<Material>(text); val.shader = shader; materialsWithRoRShader.Add(val); } } private static void LanguageLoadStrings(Action<Language> orig, Language self) { orig(self); self.SetStringByToken("MIMINISUSUKI_SKIN_JEFFREXDEF_NAME", "Jeff The Land Shark"); } private static void BodyCatalogInit() { AddTreebotBodyJeffREXDefSkin(); } private static SkinDef CreateTreebotBodyJeffREXDefSkin(GameObject mdl, ModelSkinController skinController) { Renderer[] renderers = mdl.GetComponentsInChildren<Renderer>(true); mdl.GetComponentsInChildren<Light>(true); SkinDef skin = ScriptableObject.CreateInstance<SkinDef>(); SkinDefParams skinParams = ScriptableObject.CreateInstance<SkinDefParams>(); skin.skinDefParams = skinParams; ((Object)skin).name = "JeffREXDef"; skin.nameToken = "MIMINISUSUKI_SKIN_JEFFREXDEF_NAME"; skin.rootObject = mdl; Helpers.TryCatchThrow("Icon", delegate { skin.icon = assetBundle.LoadAsset<Sprite>("Assets\\SkinMods\\JeffREX\\Icons\\JeffREXDefIcon.png"); }); Helpers.TryCatchThrow("Unlockable Name", delegate { skin.unlockableDef = ((IEnumerable<UnlockableDef>)ContentManager.unlockableDefs).FirstOrDefault((Func<UnlockableDef, bool>)((UnlockableDef def) => def.cachedName == "Jeff The Land Shark")); }); Helpers.TryCatchThrow("Base Skins", delegate { skin.baseSkins = Array.Empty<SkinDef>(); }); Helpers.TryCatchThrow("Game Object Activations", delegate { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) skinParams.gameObjectActivations = (GameObjectActivation[])(object)new GameObjectActivation[6] { new GameObjectActivation { gameObject = ((Component)Helpers.ThrowIfNull<Renderer>(0, "There is no renderer with the name \"TreebotFlowerMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "TreebotFlowerMesh")))).gameObject, shouldActivate = false, spawnPrefabOnModelObject = false }, new GameObjectActivation { gameObject = ((Component)Helpers.ThrowIfNull<Renderer>(1, "There is no renderer with the name \"Dust\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "Dust")))).gameObject, shouldActivate = false, spawnPrefabOnModelObject = false }, new GameObjectActivation { gameObject = ((Component)Helpers.ThrowIfNull<Renderer>(2, "There is no renderer with the name \"TreebotLeafletMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "TreebotLeafletMesh")))).gameObject, shouldActivate = false, spawnPrefabOnModelObject = false }, new GameObjectActivation { gameObject = ((Component)Helpers.ThrowIfNull<Renderer>(3, "There is no renderer with the name \"TreebotRootMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "TreebotRootMesh")))).gameObject, shouldActivate = false, spawnPrefabOnModelObject = false }, new GameObjectActivation { gameObject = ((Component)Helpers.ThrowIfNull<Renderer>(4, "There is no renderer with the name \"Debris\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "Debris")))).gameObject, shouldActivate = false, spawnPrefabOnModelObject = false }, new GameObjectActivation { gameObject = ((Component)Helpers.ThrowIfNull<Renderer>(5, "There is no renderer with the name \"Roots\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "Roots")))).gameObject, shouldActivate = false, spawnPrefabOnModelObject = false } }; }); Helpers.TryCatchThrow("Renderer Infos", delegate { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0088: 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) skinParams.rendererInfos = (RendererInfo[])(object)new RendererInfo[1] { new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/JeffREX/JeffREXMat.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = false, renderer = Helpers.ThrowIfNull<Renderer>(0, "There is no renderer with the name \"TreebotBotMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "TreebotBotMesh"))), hideOnDeath = false, ignoresMaterialOverrides = false } }; }); Helpers.TryCatchThrow("MeshReplacements", delegate { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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) skinParams.meshReplacements = (MeshReplacement[])(object)new MeshReplacement[1] { new MeshReplacement { mesh = assetBundle.LoadAsset<Mesh>("Assets\\SkinMods\\JeffREX\\Meshes\\SK_1047_1047001.mo.mesh"), renderer = Helpers.ThrowIfNull<Renderer>(0, "There is no renderer with the name \"TreebotBotMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "TreebotBotMesh"))) } }; }); Helpers.TryCatchThrow("Light Infos", delegate { skinParams.lightReplacements = Array.Empty<LightInfo>(); }); Helpers.TryCatchThrow("Minion Skin Replacements", delegate { skinParams.minionSkinReplacements = Array.Empty<MinionSkinReplacement>(); }); Helpers.TryCatchThrow("Projectile Ghost Replacements", delegate { skinParams.projectileGhostReplacements = Array.Empty<ProjectileGhostReplacement>(); }); return skin; } private static SkinDef CreateTreebotBodyJeffREXDefLobbySkin(GameObject mdl, ModelSkinController skinController) { Renderer[] renderers = mdl.GetComponentsInChildren<Renderer>(true); mdl.GetComponentsInChildren<Light>(true); SkinDef skin = ScriptableObject.CreateInstance<SkinDef>(); SkinDefParams skinParams = ScriptableObject.CreateInstance<SkinDefParams>(); skin.skinDefParams = skinParams; ((Object)skin).name = "JeffREXDef"; skin.nameToken = "MIMINISUSUKI_SKIN_JEFFREXDEF_NAME"; skin.rootObject = mdl; Helpers.TryCatchThrow("Icon", delegate { skin.icon = assetBundle.LoadAsset<Sprite>("Assets\\SkinMods\\JeffREX\\Icons\\JeffREXDefIcon.png"); }); Helpers.TryCatchThrow("Unlockable Name", delegate { skin.unlockableDef = ((IEnumerable<UnlockableDef>)ContentManager.unlockableDefs).FirstOrDefault((Func<UnlockableDef, bool>)((UnlockableDef def) => def.cachedName == "Jeff The Land Shark")); }); Helpers.TryCatchThrow("Base Skins", delegate { skin.baseSkins = Array.Empty<SkinDef>(); }); Helpers.TryCatchThrow("Game Object Activations", delegate { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) skinParams.gameObjectActivations = (GameObjectActivation[])(object)new GameObjectActivation[3] { new GameObjectActivation { gameObject = ((Component)Helpers.ThrowIfNull<Renderer>(0, "There is no renderer with the name \"TreebotFlowerMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "TreebotFlowerMesh")))).gameObject, shouldActivate = false, spawnPrefabOnModelObject = false }, new GameObjectActivation { gameObject = ((Component)Helpers.ThrowIfNull<Renderer>(1, "There is no renderer with the name \"TreebotLeafletMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "TreebotLeafletMesh")))).gameObject, shouldActivate = false, spawnPrefabOnModelObject = false }, new GameObjectActivation { gameObject = ((Component)Helpers.ThrowIfNull<Renderer>(2, "There is no renderer with the name \"TreebotRootMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "TreebotRootMesh")))).gameObject, shouldActivate = false, spawnPrefabOnModelObject = false } }; }); Helpers.TryCatchThrow("Renderer Infos", delegate { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0088: 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) skinParams.rendererInfos = (RendererInfo[])(object)new RendererInfo[1] { new RendererInfo { defaultMaterial = assetBundle.LoadAsset<Material>("Assets/JeffREX/JeffREXMat.mat"), defaultShadowCastingMode = (ShadowCastingMode)1, ignoreOverlays = false, renderer = Helpers.ThrowIfNull<Renderer>(0, "There is no renderer with the name \"TreebotBotMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "TreebotBotMesh"))), hideOnDeath = false, ignoresMaterialOverrides = false } }; }); Helpers.TryCatchThrow("MeshReplacements", delegate { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0068: 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) skinParams.meshReplacements = (MeshReplacement[])(object)new MeshReplacement[1] { new MeshReplacement { mesh = assetBundle.LoadAsset<Mesh>("Assets\\SkinMods\\JeffREX\\Meshes\\SK_1047_1047001.mo.mesh"), renderer = Helpers.ThrowIfNull<Renderer>(0, "There is no renderer with the name \"TreebotBotMesh\"", ((IEnumerable<Renderer>)renderers).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => ((Object)r).name == "TreebotBotMesh"))) } }; }); Helpers.TryCatchThrow("Light Infos", delegate { skinParams.lightReplacements = Array.Empty<LightInfo>(); }); Helpers.TryCatchThrow("Minion Skin Replacements", delegate { skinParams.minionSkinReplacements = Array.Empty<MinionSkinReplacement>(); }); Helpers.TryCatchThrow("Projectile Ghost Replacements", delegate { skinParams.projectileGhostReplacements = Array.Empty<ProjectileGhostReplacement>(); }); return skin; } private static void AddTreebotBodyJeffREXDefSkin() { string text = "TreebotBody"; string text2 = "JeffREXDef"; GameObject bodyPrefab = BodyCatalog.FindBodyPrefab(text); if (!Object.op_Implicit((Object)(object)bodyPrefab)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin because \"" + text + "\" doesn't exist")); return; } try { ModelLocator component = bodyPrefab.GetComponent<ModelLocator>(); if (!Object.op_Implicit((Object)(object)component)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\" because it doesn't have \"ModelLocator\" component")); return; } GameObject gameObject = ((Component)component.modelTransform).gameObject; ModelSkinController val = (Object.op_Implicit((Object)(object)gameObject) ? gameObject.GetComponent<ModelSkinController>() : null); if (!Object.op_Implicit((Object)(object)val)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\" because it doesn't have \"ModelSkinController\" component")); return; } SkinDef val2 = CreateTreebotBodyJeffREXDefSkin(gameObject, val); Array.Resize(ref val.skins, val.skins.Length + 1); val.skins[val.skins.Length - 1] = val2; } catch (FieldException ex) { if (ex.InnerException is ElementException ex2) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\"")); InstanceLogger.LogWarning((object)$"Field causing issue: {ex.Message}, element: {ex2.Index}"); InstanceLogger.LogWarning((object)ex2.Message); InstanceLogger.LogError((object)ex.InnerException); } else { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\"")); InstanceLogger.LogWarning((object)("Field causing issue: " + ex.Message)); InstanceLogger.LogError((object)ex.InnerException); } } catch (Exception ex3) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" skin to \"" + text + "\"")); InstanceLogger.LogError((object)ex3); } try { SurvivorDef val3 = ((IEnumerable<SurvivorDef>)ContentManager.survivorDefs).FirstOrDefault((Func<SurvivorDef, bool>)((SurvivorDef d) => (Object)(object)d.bodyPrefab == (Object)(object)bodyPrefab)); if (!Object.op_Implicit((Object)(object)val3)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" lobby skin to \"" + text + "\" because SurvivorDef doesn't exist")); return; } ModelSkinController componentInChildren = val3.displayPrefab.GetComponentInChildren<ModelSkinController>(); if (!Object.op_Implicit((Object)(object)componentInChildren)) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" lobby skin to \"" + text + "\" because it doesn't have \"ModelSkinController\" component")); } else { SkinDef val4 = CreateTreebotBodyJeffREXDefLobbySkin(((Component)componentInChildren).gameObject, componentInChildren); Array.Resize(ref componentInChildren.skins, componentInChildren.skins.Length + 1); componentInChildren.skins[^1] = val4; } } catch (FieldException ex4) { if (ex4.InnerException is ElementException ex5) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" lobby skin to \"" + text + "\"")); InstanceLogger.LogWarning((object)$"Field causing issue: {ex4.Message}, element: {ex5.Index}"); InstanceLogger.LogWarning((object)ex5.Message); InstanceLogger.LogError((object)ex4.InnerException); } else { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" lobby skin to \"" + text + "\"")); InstanceLogger.LogWarning((object)("Field causing issue: " + ex4.Message)); InstanceLogger.LogError((object)ex4.InnerException); } } catch (Exception ex6) { InstanceLogger.LogWarning((object)("Failed to add \"" + text2 + "\" lobby skin to \"" + text + "\"")); InstanceLogger.LogError((object)ex6); } } } public static class Helpers { private static GameObject prefabHolder; public static GameObject ClonePrefab(GameObject gameObject) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown if (!Object.op_Implicit((Object)(object)prefabHolder)) { prefabHolder = new GameObject("PrefabHolder"); Object.DontDestroyOnLoad((Object)(object)prefabHolder); prefabHolder.SetActive(false); } GameObject obj = Object.Instantiate<GameObject>(gameObject, prefabHolder.transform); obj.AddComponent<RemoveClone>(); ((Object)obj).name = ((Object)gameObject).name; return obj; } public static Transform GetChild(this Transform transform, int index, out Transform child) { return child = transform.GetChild(index); } public static GameObject WithComponent<T>(this GameObject gameObject, Action<T> modifier = null) where T : Component { T obj = gameObject.AddComponent<T>(); modifier?.Invoke(obj); return gameObject; } public static GameObject WithTryComponent<T>(this GameObject gameObject, Action<T> modifier = null) where T : Component { if (Object.op_Implicit((Object)(object)gameObject) && !Object.op_Implicit((Object)(object)gameObject.GetComponent<T>())) { T obj = gameObject.AddComponent<T>(); modifier?.Invoke(obj); } return gameObject; } public static T ThrowIfEquals<T>(int index, string message, T value, T expected) where T : Enum { if (value.Equals(expected)) { throw new ElementException(index, message); } return value; } public static T ThrowIfOutOfBounds<T>(int index, string message, T[] array, int elementIndex) where T : class { if (array == null || array.Length <= elementIndex) { throw new ElementException(index, message); } return array[elementIndex]; } public static T ThrowIfNull<T>(int index, string message, T value) where T : class { if (value == null) { throw new ElementException(index, message); } return value; } public static void TryCatchThrow(string message, Action action) { try { action?.Invoke(); } catch (Exception innerException) { throw new FieldException(message, innerException); } } } public class RemoveClone : MonoBehaviour { public void Awake() { ((Object)this).name = ((Object)this).name[..^7]; } } public class FieldException : Exception { public FieldException(string message, Exception innerException) : base(message, innerException) { } } public class ElementException : Exception { public int Index { get; } public ElementException(int index, string message) : base(message) { Index = index; } } public class InsertBones : MonoBehaviour { private readonly List<SkinnedMeshRenderer> modifiedRenderers = new List<SkinnedMeshRenderer>(); public List<string> rendererPaths = new List<string>(); public List<Transform> newBones = new List<Transform>(); public string afterPath; public void Awake() { Transform transform = ((Component)((Component)this).GetComponentInParent<ModelSkinController>()).transform; Transform value = ((Component)transform).transform.Find(afterPath); foreach (string rendererPath in rendererPaths) { Transform obj = transform.Find(rendererPath); SkinnedMeshRenderer val = ((obj != null) ? ((Component)obj).GetComponent<SkinnedMeshRenderer>() : null); if (Object.op_Implicit((Object)(object)val)) { Transform[] array = val.bones; int num = Array.IndexOf(array, value) + 1; if (num != 0) { Array.Resize(ref array, array.Length + newBones.Count); Array.Copy(array, num, array, num + newBones.Count, array.Length - newBones.Count - num); newBones.CopyTo(array, num); val.bones = array; modifiedRenderers.Add(val); } } } } public void OnDestroy() { foreach (SkinnedMeshRenderer modifiedRenderer in modifiedRenderers) { if (Object.op_Implicit((Object)(object)modifiedRenderer)) { Transform[] array = modifiedRenderer.bones; int num = Array.IndexOf(array, ((Component)this).transform); Array.Copy(array, num + newBones.Count, array, num, array.Length - num - newBones.Count); Array.Resize(ref array, array.Length - newBones.Count); modifiedRenderer.bones = array; } } modifiedRenderers.Clear(); } } public class AddDynamicColliders : MonoBehaviour { public List<string> paths = new List<string>(); public void Awake() { Transform transform = ((Component)((Component)this).GetComponentInParent<ModelSkinController>()).transform; List<DynamicBoneCollider> list = new List<DynamicBoneCollider>(); foreach (string path in paths) { Transform val = transform.Find(path); if (Object.op_Implicit((Object)(object)val)) { list.AddRange(((Component)val).GetComponents<DynamicBoneCollider>()); } } DynamicBone[] components = ((Component)this).GetComponents<DynamicBone>(); for (int i = 0; i < components.Length; i++) { components[i].m_Colliders.AddRange(list); } } }