using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Enums;
using GreenHellVR_Core;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Valve.VR.InteractionSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("Thalium")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Core mod for GHVR")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+fe5618975be6c8d0675e46930b7b8257840cffbb")]
[assembly: AssemblyProduct("GreenHellVR_Core")]
[assembly: AssemblyTitle("GreenHellVR_Core")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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;
}
}
}
[HarmonyPatch(typeof(MainMenu), "Start")]
internal class MainMenu_Start_Fix
{
private static void Postfix(MainMenu __instance)
{
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_021e: Unknown result type (might be due to invalid IL or missing references)
//IL_0230: Unknown result type (might be due to invalid IL or missing references)
//IL_023a: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
Plugin.Log.LogInfo((object)"Setting up MainMenu fix");
if ((Object)(object)GHVRC_UI.defaultFontAsset == (Object)null)
{
GHVRC_UI.defaultFontAsset = ((TMP_Text)((Component)__instance.m_Options).GetComponentInChildren<TextMeshProUGUI>()).font;
}
Plugin.Log.LogInfo((object)"Setting up MainMenu fix");
Dictionary<string, PluginInfo> pluginInfos = Chainloader.PluginInfos;
bool value = ConfigManager.Instance.ConfigFullUI.Value;
((Component)__instance.m_Singleplayer).gameObject.SetActive(value);
((Component)__instance.m_Multiplayer).gameObject.SetActive(value);
((Component)__instance.m_StartStory).gameObject.SetActive(!value);
((Component)__instance.m_StartSurvival).gameObject.SetActive(!value);
((Component)__instance.m_StartChallenge).gameObject.SetActive(!value);
((Component)__instance.m_LoadGame).gameObject.SetActive(!value);
GameObject val = GHVRC_UI.CreateText("Loaded Mods :", __instance.m_Buttons.transform.parent);
TMP_Text destination = val.GetComponent<TMP_Text>();
val.transform.rotation = __instance.m_Buttons.transform.rotation;
val.transform.position = ((Component)__instance.m_Continue).transform.position;
GHVRC_UI.CopyTextProperties(((Component)__instance.m_Quit).GetComponentInChildren<TMP_Text>(), ref destination);
val.transform.Translate(Vector3.left * 0.5f, (Space)1);
Plugin.Log.LogInfo((object)$"Adding Title to the mods list at coords [{val.transform.position}]");
int num = 1;
foreach (KeyValuePair<string, PluginInfo> item in pluginInfos)
{
GameObject val2 = GHVRC_UI.CreateText("- " + item.Key, __instance.m_Buttons.transform.parent);
TMP_Text destination2 = val2.GetComponent<TMP_Text>();
val2.transform.rotation = __instance.m_Buttons.transform.rotation;
val2.transform.position = ((Component)__instance.m_Continue).transform.position;
GHVRC_UI.CopyTextProperties(((Component)__instance.m_Quit).GetComponentInChildren<TMP_Text>(), ref destination2);
val2.transform.Translate(Vector3.down * (float)num * 0.05f, (Space)1);
val2.transform.Translate(Vector3.left * 0.6f, (Space)1);
Plugin.Log.LogInfo((object)$"Adding [{item.Key}] {item.Value} to the mods list at coords [{val2.transform.position}]");
num++;
}
ManualLogSource log = Plugin.Log;
Vector3 position = __instance.m_Buttons.transform.position;
log.LogDebug((object)((object)(Vector3)(ref position)).ToString());
Text gameVersion = __instance.m_GameVersion;
gameVersion.text += $" (MODDED)\n{pluginInfos.Count} mods loaded";
}
}
[HarmonyPatch(typeof(MainMenu), "UpdateState")]
internal class MainMenu_UpdateState_Fix
{
private static bool Prefix(ref MainMenuState ___m_State, MainMenu __instance)
{
//IL_0054: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
bool value = ConfigManager.Instance.ConfigSkipIntro.Value;
if (value && ((int)___m_State == 0 || (int)___m_State == 1 || (int)___m_State == 2))
{
___m_State = (MainMenuState)3;
((Behaviour)VrInputManager.Get(true)).enabled = false;
GreenHellGame.GetVRCanvasHelper().SetVrCanvasToPositon(MainMenuManager.Get().m_RectTransform, new Vector3(82.178f, 97.683f, 182.291f), new Vector3(0f, -135f, 0f));
((Component)__instance.m_BG).gameObject.SetActive(true);
((Component)__instance.m_CompanyLogo).gameObject.SetActive(false);
((Component)__instance.m_SecondCompanyLogo).gameObject.SetActive(false);
((Component)__instance.m_GameLogo).gameObject.SetActive(false);
__instance.m_Buttons.SetActive(true);
Color color = ((Graphic)__instance.m_BG).color;
color.a = 1f;
((Graphic)__instance.m_BG).color = color;
GreenHellGame.Instance.m_Settings.ApplySettings();
GreenHellGame.Instance.m_InitialSequenceComplete = value;
Plugin.Log.LogInfo((object)"Intro skipped");
}
return true;
}
}
[HarmonyPatch(typeof(Player), "Die")]
internal class Player_Die_OnDie
{
private static void Postfix()
{
Plugin.instance.OnDie();
}
}
namespace GreenHellVR_Core
{
internal class ConfigManager
{
public ConfigEntry<bool> ConfigSkipIntro;
public ConfigEntry<bool> ConfigFullUI;
private Plugin plugin;
public static ConfigManager Instance { get; private set; }
public static void Awake()
{
if (Instance == null)
{
Instance = new ConfigManager();
}
ConfigManager instance = Instance;
if (instance.plugin == null)
{
instance.plugin = Plugin.instance;
}
}
public static void LoadConfig()
{
Instance.ConfigSkipIntro = ((BaseUnityPlugin)Instance.plugin).Config.Bind<bool>("Miscellaneous", "SkipIntro", true, (ConfigDescription)null);
Instance.ConfigFullUI = ((BaseUnityPlugin)Instance.plugin).Config.Bind<bool>("Extra", "FullUI", false, (ConfigDescription)null);
}
}
public class CoreModObject : MonoBehaviour
{
private CoreModObject instance;
private AssetBundle assetBundle;
private GameObject monkey;
public CoreModObject Get()
{
return instance;
}
public void Awake()
{
if ((Object)(object)instance != (Object)null)
{
Object.Destroy((Object)(object)((Component)this).gameObject);
}
instance = this;
}
public void Start()
{
if (assetBundle == null)
{
assetBundle = GHVRC_Objects.LoadAssetBundle("GreenHellVR_Core.monkeybundle");
}
if ((Object)(object)assetBundle != (Object)null && (Object)(object)monkey == (Object)null)
{
((MonoBehaviour)this).StartCoroutine(GHVRC_Objects.LoadAssetFromBundleAsync<GameObject>(assetBundle, "monkey", (Action<GameObject>)OnMonkeyLoaded));
}
}
public void OnMonkeyLoaded(GameObject monkey)
{
this.monkey = monkey;
}
private void SpawnMonkey()
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: 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_006d: 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)
if ((Object)(object)monkey == (Object)null)
{
Plugin.Log.LogError((object)"no monkey");
return;
}
Transform headTransform = ((Being)Player.Get()).GetHeadTransform();
float num = 1f;
GameObject obj = monkey;
Vector3 position = headTransform.position;
Vector3 forward = headTransform.forward;
Object.Instantiate<GameObject>(obj, position + num * ((Vector3)(ref forward)).normalized, Quaternion.identity * Quaternion.Euler(new Vector3(-90f, 0f, 0f))).AddComponent<SphereCollider>().radius = 1f;
}
public void Update()
{
if (Input.GetKeyDown((KeyCode)109))
{
SpawnMonkey();
}
}
}
public static class GHVRC_Objects
{
private static readonly string BundlesFolder = Path.Combine(Directory.GetParent(Plugin.instance.modPath).FullName, "Bundles");
private static void CheckAssetBundle()
{
Plugin.Log.LogInfo((object)"Checking for the bundle folder");
if (!Directory.Exists(BundlesFolder))
{
Plugin.Log.LogInfo((object)"Creating the bundles folder");
Directory.CreateDirectory(BundlesFolder);
}
}
public static void ExtractEmbeddedRessources()
{
CheckAssetBundle();
Assembly callingAssembly = Assembly.GetCallingAssembly();
Plugin.Log.LogInfo((object)("Extracting Assets from " + callingAssembly.FullName));
string[] manifestResourceNames = callingAssembly.GetManifestResourceNames();
foreach (string text in manifestResourceNames)
{
Plugin.Log.LogInfo((object)("Extracting " + text));
Stream manifestResourceStream = callingAssembly.GetManifestResourceStream(text);
FileStream fileStream = new FileStream(Path.Combine(BundlesFolder, text), FileMode.Create);
for (int j = 0; j < manifestResourceStream.Length; j++)
{
fileStream.WriteByte((byte)manifestResourceStream.ReadByte());
}
fileStream.Close();
}
}
[Obsolete("it's not really obselete but async methods just doesn't work for now")]
public static IEnumerator LoadAssetBundleAsync(string path, Action<AssetBundle> callback = null)
{
string fullPath = Path.Combine(BundlesFolder, path);
Plugin.Log.LogInfo((object)("Checking for bundle: " + fullPath));
if (path == null || !File.Exists(fullPath))
{
yield return null;
}
AssetBundleCreateRequest bundleRequest = AssetBundle.LoadFromFileAsync(fullPath);
yield return (object)new WaitUntil((Func<bool>)(() => ((AsyncOperation)bundleRequest).isDone));
Plugin.Log.LogInfo((object)("Bundle " + ((Object)bundleRequest.assetBundle).name + " loaded"));
callback?.Invoke(bundleRequest.assetBundle);
yield return null;
}
public static AssetBundle LoadAssetBundle(string path)
{
string text = Path.Combine(BundlesFolder, path);
Plugin.Log.LogInfo((object)("Checking for bundle: " + text));
if (path == null || !File.Exists(text))
{
return null;
}
AssetBundle val = AssetBundle.LoadFromFile(text);
Plugin.Log.LogInfo((object)("Bundle " + ((Object)val).name + " loaded"));
return val;
}
public static IEnumerator LoadAssetFromBundleAsync<T>(AssetBundle bundle, string AssetName, Action<T> callback) where T : Object
{
AssetBundleRequest request = bundle.LoadAssetAsync<T>(AssetName);
yield return (object)new WaitUntil((Func<bool>)(() => ((AsyncOperation)request).isDone));
Plugin.Log.LogInfo((object)"Asset loaded");
callback?.Invoke((T)(object)request.asset);
yield return null;
}
public static T LoadAssetFromBundle<T>(AssetBundle bundle, string AssetName) where T : Object
{
T result = bundle.LoadAsset<T>(AssetName);
Plugin.Log.LogInfo((object)("Asset " + AssetName + " loaded"));
return result;
}
public static Object LoadAssetFromBundle(AssetBundle bundle, string AssetName)
{
Object result = bundle.LoadAsset(AssetName);
Plugin.Log.LogInfo((object)("Asset " + AssetName + " loaded"));
return result;
}
public static Item SpawnGHVRItem(ItemID id, Transform pos)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
Item result = ItemsManager.Get().CreateItem(id, true, pos);
Plugin.Log.LogInfo((object)(((object)(ItemID)(ref id)).ToString() + " has been created"));
return result;
}
public static Item SpawnGHVRItem(ItemID id, Vector3 pos, Quaternion rot)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: 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)
Item result = ItemsManager.Get().CreateItem(id, true, pos, rot);
Plugin.Log.LogInfo((object)(((object)(ItemID)(ref id)).ToString() + " has been created"));
return result;
}
}
public static class GHVRC_UI
{
private static readonly Font ArialFont = (Font)Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
public static TMP_FontAsset defaultFontAsset = TMP_FontAsset.CreateFontAsset(ArialFont);
public static GameObject CreateText(string text, Transform parent = null)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
GameObject val = new GameObject("Text")
{
layer = LayerMask.NameToLayer("UI")
};
TextMeshProUGUI obj = val.AddComponent<TextMeshProUGUI>();
((TMP_Text)obj).text = text;
((TMP_Text)obj).font = defaultFontAsset;
((TMP_Text)obj).fontSize = ((TMP_Text)obj).fontSize * 0.75f;
if ((Object)(object)parent != (Object)null)
{
val.transform.parent = parent;
}
return val;
}
public static GameObject CreateCanvas(Transform parent = null)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
GameObject val = new GameObject("Canvas")
{
layer = LayerMask.NameToLayer("UI")
};
val.AddComponent<Canvas>();
if ((Object)(object)parent != (Object)null)
{
val.transform.parent = parent;
}
return val;
}
public static void ToggleActive(GameObject go)
{
if (!((Object)(object)go == (Object)null))
{
go.SetActive(!go.activeSelf);
Plugin.Log.LogInfo((object)(((Object)go).name + " is now " + (go.activeSelf ? "active" : "inactive")));
}
}
public static GameObject CreateButton(string text, Transform Parent = null, UnityAction buttonAction = null)
{
//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)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
GameObject val = new GameObject(text);
RectTransform val2 = val.AddComponent<RectTransform>();
Button val3 = val.AddComponent<Button>();
if ((Object)(object)Parent != (Object)null)
{
((Transform)val2).SetParent(Parent);
}
if (buttonAction != null)
{
((UnityEvent)val3.onClick).AddListener(buttonAction);
}
CreateText(text, (Transform)(object)val2);
Plugin.Log.LogInfo((object)"Button created");
return val;
}
public static void CopyTextProperties(TMP_Text source, ref TMP_Text destination)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
destination.fontSize = source.fontSize;
destination.font = source.font;
destination.fontStyle = source.fontStyle;
destination.fontWeight = source.fontWeight;
destination.transform.localScale = source.transform.localScale;
((Graphic)destination).color = Util.ColorWithAlpha(((Graphic)source).color, 1f);
}
}
[BepInPlugin("GreenHellVR_Core", "GreenHellVR_Core", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
public static Plugin instance;
public string modPath;
public Assembly assembly;
internal static ManualLogSource Log;
[Header("Events")]
public Action OnDie;
public UnityAction<Scene, LoadSceneMode> SceneManager_sceneLoaded { get; private set; }
public void Awake()
{
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
instance = this;
Log = ((BaseUnityPlugin)this).Logger;
modPath = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
assembly = Assembly.GetExecutingAssembly();
GHVRC_Objects.ExtractEmbeddedRessources();
Harmony val = new Harmony("com.thalium.ghvr_core");
SceneManager.sceneLoaded += OnSceneLoaded;
val.PatchAll(Assembly.GetExecutingAssembly());
ConfigManager.Awake();
ConfigManager.LoadConfig();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin GreenHellVR_Core is loaded!");
InstatiateModManager();
}
private void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("Scene " + ((Scene)(ref scene)).name + " loaded"));
InstatiateModManager();
}
public void InstatiateModManager()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
((BaseUnityPlugin)this).Logger.LogInfo((object)"Instantiating Manager gameobject");
GameObject obj = Object.Instantiate<GameObject>(new GameObject("[ModManager] CoreMod"));
obj.AddComponent<CoreModObject>();
Object.DontDestroyOnLoad((Object)(object)obj);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Manager gameobject created");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "GreenHellVR_Core";
public const string PLUGIN_NAME = "GreenHellVR_Core";
public const string PLUGIN_VERSION = "0.1.0";
}
}