using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.AddressableAssets.ResourceLocators;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("Ultrapit")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Ultrapit")]
[assembly: AssemblyTitle("Ultrapit")]
[assembly: AssemblyVersion("1.0.0.0")]
public static class ShaderManager
{
public class ShaderInfo
{
public string Name { get; set; }
}
public static Dictionary<string, Shader> shaderDictionary = new Dictionary<string, Shader>();
private static HashSet<Material> modifiedMaterials = new HashSet<Material>();
public static IEnumerator LoadShadersAsync()
{
AsyncOperationHandle<IResourceLocator> handle = Addressables.InitializeAsync();
while (!handle.IsDone)
{
yield return null;
}
if ((int)handle.Status == 1)
{
IResourceLocator locator = handle.Result;
foreach (string addressEntry in ((ResourceLocationMap)locator).Keys)
{
if (!addressEntry.EndsWith(".shader"))
{
continue;
}
AsyncOperationHandle<Shader> shaderHandle = Addressables.LoadAssetAsync<Shader>((object)addressEntry);
while (!shaderHandle.IsDone)
{
yield return null;
}
if ((int)shaderHandle.Status == 1)
{
Shader ingameShader = shaderHandle.Result;
if ((Object)(object)ingameShader != (Object)null && ((Object)ingameShader).name != "ULTRAKILL/PostProcessV2" && !shaderDictionary.ContainsKey(((Object)ingameShader).name))
{
shaderDictionary[((Object)ingameShader).name] = ingameShader;
}
}
else
{
Debug.LogError((object)("Failed to load shader: " + shaderHandle.OperationException));
}
}
}
else
{
Debug.LogError((object)("Addressables initialization failed: " + handle.OperationException));
}
}
public static string ModPath()
{
return Assembly.GetExecutingAssembly().Location.Substring(0, Assembly.GetExecutingAssembly().Location.LastIndexOf(Path.DirectorySeparatorChar));
}
public static IEnumerator ApplyShadersAsync(GameObject[] allGameObjects)
{
if (allGameObjects == null)
{
yield break;
}
foreach (GameObject go in allGameObjects)
{
if ((Object)(object)go == (Object)null)
{
continue;
}
Renderer[] meshRenderers = go.GetComponentsInChildren<Renderer>(true);
Renderer[] array = meshRenderers;
foreach (Renderer renderer in array)
{
if ((Object)(object)renderer == (Object)null)
{
continue;
}
Material[] newMaterials = (Material[])(object)new Material[renderer.sharedMaterials.Length];
for (int i = 0; i < renderer.sharedMaterials.Length; i++)
{
Material sharedMat = (newMaterials[i] = renderer.sharedMaterials[i]);
if (!((Object)(object)sharedMat == (Object)null) && !((Object)(object)sharedMat.shader == (Object)null) && !modifiedMaterials.Contains(sharedMat) && !(((Object)sharedMat.shader).name == "ULTRAKILL/PostProcessV2") && shaderDictionary.TryGetValue(((Object)sharedMat.shader).name, out var realShader))
{
newMaterials[i].shader = realShader;
modifiedMaterials.Add(sharedMat);
realShader = null;
}
}
renderer.materials = newMaterials;
}
yield return null;
}
}
public static IEnumerator ApplyShadersAsyncContinuously()
{
GameObject shaderManagerObject = new GameObject("ShaderManagerObject");
ShaderManagerRunner shaderManagerRunner = shaderManagerObject.AddComponent<ShaderManagerRunner>();
shaderManagerRunner.StartApplyingShaders();
yield return null;
}
public static void CreateShaderDictionary()
{
List<ShaderInfo> list = new List<ShaderInfo>();
Shader[] array = Resources.FindObjectsOfTypeAll<Shader>();
foreach (Shader shader in array)
{
if (!list.Any((ShaderInfo s) => s.Name == ((Object)shader).name))
{
list.Add(new ShaderInfo
{
Name = ((Object)shader).name
});
}
}
string contents = JsonConvert.SerializeObject((object)list, (Formatting)1);
File.WriteAllText(Path.Combine(ModPath(), "ShaderList.json"), contents);
}
public static IEnumerator LoadShadersFromDictionaryAsync()
{
string shaderListPath = Path.Combine(ModPath(), "ShaderList.json");
if (!File.Exists(shaderListPath))
{
yield break;
}
Task<string> shaderDataTask = ReadAllTextAsync(shaderListPath);
while (!shaderDataTask.IsCompleted)
{
yield return null;
}
string json = shaderDataTask.Result;
List<ShaderInfo> shaderData = JsonConvert.DeserializeObject<List<ShaderInfo>>(json);
Dictionary<string, Shader> shaderLookup = new Dictionary<string, Shader>();
foreach (ShaderInfo shaderInfo in shaderData)
{
Shader foundShader = Shader.Find(shaderInfo.Name);
if ((Object)(object)foundShader != (Object)null)
{
if (!shaderLookup.ContainsKey(shaderInfo.Name))
{
shaderLookup[shaderInfo.Name] = foundShader;
}
else
{
Debug.LogWarning((object)("Duplicate shader name found: " + shaderInfo.Name));
}
}
}
Material[] array = Resources.FindObjectsOfTypeAll<Material>();
foreach (Material material in array)
{
if (shaderLookup.TryGetValue(((Object)material.shader).name, out var newShader) && (Object)(object)material.shader != (Object)(object)newShader)
{
material.shader = newShader;
}
newShader = null;
}
}
private static async Task<string> ReadAllTextAsync(string path)
{
using StreamReader reader = new StreamReader(path);
return await reader.ReadToEndAsync();
}
}
public class ShaderManagerRunner : MonoBehaviour
{
public void StartApplyingShaders()
{
((MonoBehaviour)this).StartCoroutine(ApplyShadersContinuously());
}
private IEnumerator ApplyShadersContinuously()
{
while (true)
{
yield return (object)new WaitForSeconds(0.15f);
Scene activeScene = SceneManager.GetActiveScene();
yield return ShaderManager.ApplyShadersAsync(((Scene)(ref activeScene)).GetRootGameObjects());
yield return ShaderManager.LoadShadersFromDictionaryAsync();
}
}
}
namespace Ultrapit
{
[BepInPlugin("Ultrapit.draghtnim.ultrakill", "Ultrapit", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
private AssetBundle terminal;
public static bool IsCustomLevel;
private Scene scene;
private GameObject pitobj;
private GameObject newpitobj;
private AssetBundle bundlepit;
private static Plugin _instance;
private string assemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
public static Plugin Instance => _instance;
public static string getConfigPath()
{
string[] array = new string[1];
string configPath = Paths.ConfigPath;
char directorySeparatorChar = Path.DirectorySeparatorChar;
array[0] = configPath + directorySeparatorChar + "EnvyLevels";
return Path.Combine(array);
}
public static GameObject FindObjectEvenIfDisabled(string rootName, string objPath = null, int childNum = 0, bool useChildNum = false)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
GameObject val = null;
Scene activeScene = SceneManager.GetActiveScene();
GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
bool flag = false;
GameObject[] array = rootGameObjects;
foreach (GameObject val2 in array)
{
if (((Object)val2).name == rootName)
{
val = val2;
flag = true;
}
}
if (flag)
{
GameObject val3 = val;
if (objPath != null)
{
val3 = ((Component)val.transform.Find(objPath)).gameObject;
if (!useChildNum)
{
val = val3;
}
}
if (useChildNum)
{
GameObject gameObject = ((Component)val3.transform.GetChild(childNum)).gameObject;
val = gameObject;
}
}
return val;
}
private async void Awake()
{
_instance = this;
SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
SceneManager.sceneUnloaded -= OnSceneUnloaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
bool flag = SceneHelper.CurrentScene != "Bootstrap" && SceneHelper.CurrentScene != "Intro";
if (SceneHelper.CurrentScene == "Main Menu")
{
pitobj = GameObject.Find("Pit (2)");
pitobj.SetActive(false);
pitobj = GameObject.Find("Music");
pitobj.SetActive(false);
pitobj = GameObject.Find("Player");
pitobj.transform.position = Vector3.zero;
Debug.Log((object)("okay the path is: " + assemblyLocation));
AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(assemblyLocation, "UltrapitBundle.resource"));
if ((Object)(object)val == (Object)null)
{
Debug.Log((object)"Failed to load AssetBundle!");
return;
}
Debug.Log((object)"Loaded something.");
GameObject[] array = val.LoadAllAssets<GameObject>();
int num = Random.Range(0, array.Length);
GameObject val2 = array[num];
Debug.Log((object)"your random gameobject");
Debug.Log((object)((Object)val2).name);
Object.Instantiate<GameObject>(val2);
val.Unload(false);
ShaderManager.CreateShaderDictionary();
((MonoBehaviour)_instance).StartCoroutine(ShaderManager.ApplyShadersAsyncContinuously());
Debug.Log((object)"envy???");
}
if (ShaderManager.shaderDictionary.Count <= 0)
{
((MonoBehaviour)this).StartCoroutine(ShaderManager.LoadShadersAsync());
}
}
private void OnSceneUnloaded(Scene scene)
{
if (SceneHelper.CurrentScene == "Main Menu")
{
ShaderManager.CreateShaderDictionary();
}
}
private void InstantiateEnvyScreen(bool mainMenu)
{
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
GameObject val = terminal.LoadAsset<GameObject>("EnvyScreen.prefab");
if ((Object)(object)val == (Object)null)
{
Debug.LogError((object)"EnvyScreen prefab not found in the terminal bundle.");
return;
}
GameObject val2 = GameObject.Find("/Canvas/Main Menu (1)");
if (!mainMenu)
{
val2 = FindObjectEvenIfDisabled("Canvas", "PauseMenu");
}
if (!((Object)(object)val2 == (Object)null))
{
GameObject val3 = Object.Instantiate<GameObject>(val);
val3.transform.SetParent(val2.transform, false);
val3.transform.localPosition = Vector3.zero;
val3.transform.localScale = new Vector3(1f, 1f, 1f);
}
}
}
}
namespace Ultrapit.Properties
{
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resources
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
ResourceManager resourceManager = new ResourceManager("Ultrapit.Properties.Resources", typeof(Resources).Assembly);
resourceMan = resourceManager;
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal static byte[] Crusher1
{
get
{
object @object = ResourceManager.GetObject("Crusher1", resourceCulture);
return (byte[])@object;
}
}
internal Resources()
{
}
}
}