Please disclose if your mod was created primarily 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 SteveCore v3.1.0
plugins/BadgersShadingOverhaul.dll
Decompiled a year agousing System; using System.CodeDom.Compiler; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using Badgers_Shading_Overhaul.Gui; using Badgers_Shading_Overhaul.Gui.GUIScriptComponents; using Badgers_Shading_Overhaul.Properties; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("Badgers_Shading_Overhaul")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Badgers_Shading_Overhaul")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("d972bffe-cbf4-4b17-8276-007e986e6195")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace Badgers_Shading_Overhaul { internal class BVTAssets { private AssetBundle GUIAssetBundle; private Dictionary<string, Mesh> bvtMeshes = new Dictionary<string, Mesh>(); private GameObject BVTCanvas = null; private GameObject BVTSliderWidget = null; private GameObject BVTButtonWidget = null; private GameObject BVTLabelWidget = null; private GameObject BVTToggleWidget = null; private GameObject ClockWidget = null; public bool assetsLoaded = false; public BVTAssets() { LoadAssets(); } public void LoadAssets() { byte[] guiassets = Resources.guiassets; GUIAssetBundle = AssetBundle.LoadFromMemory(guiassets); if (!((Object)(object)GUIAssetBundle != (Object)null)) { return; } bLog.Log("Loading GUI Assets", force: true); string[] allAssetNames = GUIAssetBundle.GetAllAssetNames(); foreach (string text in allAssetNames) { GameObject val = GUIAssetBundle.LoadAsset<GameObject>(text); switch (((Object)val).name) { case "Canvas": BVTCanvas = val; break; case "SliderWidget": BVTSliderWidget = val; break; case "ButtonWidget": BVTButtonWidget = val; break; case "LabelWidget": BVTLabelWidget = val; break; case "ToggleWidget": BVTToggleWidget = val; break; } } assetsLoaded = true; GUIAssetBundle.Unload(false); guiassets = null; } public GameObject GetCanvas() { if ((Object)(object)BVTCanvas != (Object)null) { return BVTCanvas; } return null; } public GameObject GetSliderWidget() { if ((Object)(object)BVTSliderWidget != (Object)null) { return BVTSliderWidget; } return null; } public GameObject GetButtonWidget() { if ((Object)(object)BVTButtonWidget != (Object)null) { return BVTButtonWidget; } return null; } public GameObject GetLabelWidget() { if ((Object)(object)BVTLabelWidget != (Object)null) { return BVTLabelWidget; } return null; } public GameObject GetToggleWidget() { if ((Object)(object)BVTToggleWidget != (Object)null) { return BVTToggleWidget; } return null; } public GameObject GetClockWidget() { if ((Object)(object)ClockWidget != (Object)null) { return ClockWidget; } return null; } } public class CameraPostProcess : MonoBehaviour { private RenderTexture rt = null; private void OnPreRender() { Mod.mainCamera.targetTexture = rt; } private void OnRenderImage(RenderTexture src, RenderTexture dest) { if ((Object)(object)Mod.PostProcessMaterial != (Object)null && Mod.config.CleanShadingOn.Value) { Mod.mainCamera.targetTexture = null; Graphics.Blit((Texture)(object)src, (RenderTexture)null, Mod.PostProcessMaterial); } else { Graphics.Blit((Texture)(object)src, dest); } } } internal class Config { private ConfigFile cf = new ConfigFile(Mod.ConfigFile, true); public ConfigEntry<float> AmbientLight; public ConfigEntry<bool> CleanShadingOn; public ConfigEntry<KeyCode> ModToggleKey; public ConfigEntry<bool> DebugInfo; public ConfigEntry<float> SpecularIntensity; public ConfigEntry<float> ColorTemp; public ConfigEntry<float> ColorSaturation; public Config() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown CleanShadingOn = cf.Bind<bool>("Mod", "Enable Smooth Shading", true, "Enable Smooth Shading"); ModToggleKey = cf.Bind<KeyCode>("Mod", "Key to enable/disable mod", (KeyCode)281, "Mod Toggle Key"); DebugInfo = cf.Bind<bool>("Mod", "Enable debug information", false, "Enable debug information"); SpecularIntensity = cf.Bind<float>("Visual", "Specular Intensity", 0f, "Specular Intensity"); AmbientLight = cf.Bind<float>("Visual", "Ambient Light Modifier", 0.9f, "Ambient Light Modifier"); ColorTemp = cf.Bind<float>("Visual", "Colour Temperature", 0f, "Colour Temperature"); ColorSaturation = cf.Bind<float>("Visual", "Colour Saturation", 1f, "Colour Saturation"); } } internal class MouseDragComponent : MonoBehaviour, IDragHandler, IEventSystemHandler, IBeginDragHandler, IEndDragHandler { private Vector2 dragStartPosition; private Vector2 menuPos; private Vector2 pointerOffset; public void OnBeginDrag(PointerEventData eventData) { //IL_0008: 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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: 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_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) menuPos = Vector2.op_Implicit(((Transform)((Component)this).GetComponent<RectTransform>()).position); dragStartPosition = eventData.position; pointerOffset = dragStartPosition - menuPos; } public void OnDrag(PointerEventData eventData) { //IL_0002: 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) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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_0046: Unknown result type (might be due to invalid IL or missing references) Vector2 position = eventData.position; Vector2 val = position - dragStartPosition; menuPos += val; ((Transform)((Component)this).GetComponent<RectTransform>()).position = Vector2.op_Implicit(menuPos + val); dragStartPosition = position; } public void OnEndDrag(PointerEventData eventData) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) ((Transform)((Component)this).GetComponent<RectTransform>()).position = Vector2.op_Implicit(eventData.position - pointerOffset); } } internal class HarmonyPatches { [HarmonyPatch(typeof(Player), "Awake")] private class Player_Awake { private static void Postfix(Player __instance) { Mod.UpdateShader(); Mod.AddConsoleCommands(); Mod.CreateUI(); Mod.AddCameraComponents(); Mod.CreatePostProcessShader(); Mod.SetShaderProperties(); } } [HarmonyPatch(typeof(EnvMan), "Awake")] private class EnvMan_Awake { [HarmonyPriority(0)] private static void Postfix(EnvMan __instance) { Mod.envMan = __instance; bLog.Log("Preparing envs"); Mod.dayIntensities.Clear(); Mod.nightIntensities.Clear(); bLog.Log("Existing envs"); foreach (EnvSetup environment in __instance.m_environments) { bLog.Log("Preparing env " + environment.m_name); if (!Mod.dayIntensities.ContainsKey(environment)) { Mod.dayIntensities.Add(environment, environment.m_lightIntensityDay); Mod.nightIntensities.Add(environment, environment.m_lightIntensityNight); } else { bLog.Log("Couldn't add environment " + environment.m_name + " as it has already been added."); } } } } [HarmonyPatch(typeof(EnvMan), "SetEnv")] private class EnvMan_SetEnv { private static void Postfix(EnvMan __instance) { Mod.UpdateEnvs(__instance); } } private readonly Harmony harmony = new Harmony("Badgers.ShadingOverhaul"); public HarmonyPatches() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown harmony.PatchAll(); } } internal class bLog { public static bool debugEnabled = Mod.config.DebugInfo.Value; public static string logLabel = "BSO"; public static void Log(string LogMessage, bool force = false) { if (debugEnabled || force) { Debug.Log((object)(logLabel + ": " + LogMessage)); } } } [BepInPlugin("Badgers.ShadingOverhaul", "Badgers Shading Overhaul", "0.3.4")] [BepInProcess("valheim.exe")] public class Badgers_Shading_Overhaul : BaseUnityPlugin { private HarmonyPatches ShadingOverhaul; private byte[] abBytes; private AssetBundle ab; private void Awake() { ShadingOverhaul = new HarmonyPatches(); abBytes = Resources.deferredshaders; ab = AssetBundle.LoadFromMemory(abBytes); Mod.ReplacementShader = ab.LoadAsset<Shader>("Internal-DeferredShading"); Mod.PostProcessShader = ab.LoadAsset<Shader>("PostProcess"); ab.Unload(false); abBytes = null; Mod.OriginalShader = GraphicsSettings.GetCustomShader((BuiltinShaderType)0); } private void Update() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)Player.m_localPlayer == (Object)null) || Mod.DevMode) { if (Input.GetKeyDown(Mod.config.ModToggleKey.Value)) { Mod.UI.ToggleMenu(); } if (Input.GetKeyDown((KeyCode)27) && Mod.UI.showMenu) { Mod.UI.ToggleMenu(); } } } } internal static class Mod { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__16_0; internal void <AddConsoleCommands>b__16_0(ConsoleEventArgs args) { float value = default(float); args.TryParameterFloat(1, ref value); config.AmbientLight.Value = value; } } public static string ConfigPath = Paths.ConfigPath; public static string PluginPath = Paths.PluginPath; public static string ConfigFile = Path.Combine(ConfigPath, "BadgersShadingOverhaul.cfg"); public static Config config = new Config(); private static BVTAssets bvtAssets = new BVTAssets(); public static BVTUI UI; private static List<string> Category = new List<string> { "Mod Config" }; public static Dictionary<EnvSetup, float> dayIntensities = new Dictionary<EnvSetup, float>(); public static Dictionary<EnvSetup, float> nightIntensities = new Dictionary<EnvSetup, float>(); public static Shader ReplacementShader; public static Shader OriginalShader; public static Shader PostProcessShader; public static Material PostProcessMaterial; public static Camera mainCamera; public static EnvMan envMan; public static bool DevMode = false; public static void AddConsoleCommands() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_002a: Expected O, but got Unknown object obj = <>c.<>9__16_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { float value = default(float); args.TryParameterFloat(1, ref value); config.AmbientLight.Value = value; }; <>c.<>9__16_0 = val; obj = (object)val; } new ConsoleCommand("setambientlight", "Set the ambient light modifier", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } public static void UpdateEnvs(EnvMan instance) { if ((Object)(object)instance != (Object)null && dayIntensities.ContainsKey(instance.m_currentEnv)) { if (config.CleanShadingOn.Value) { instance.m_currentEnv.m_lightIntensityDay = dayIntensities[instance.m_currentEnv] * config.AmbientLight.Value; instance.m_currentEnv.m_lightIntensityNight = nightIntensities[instance.m_currentEnv] * config.AmbientLight.Value; } else { instance.m_currentEnv.m_lightIntensityDay = dayIntensities[instance.m_currentEnv]; instance.m_currentEnv.m_lightIntensityNight = nightIntensities[instance.m_currentEnv]; } } } public static void SetShaderProperties() { Shader.SetGlobalFloat("_BSOSpecularIntensity", 1f + config.SpecularIntensity.Value * 0.05f); } public static void UpdateShader() { bLog.Log("Updating Shader"); if (config.CleanShadingOn.Value) { bLog.Log("Using New Shader"); GraphicsSettings.SetCustomShader((BuiltinShaderType)0, ReplacementShader); } else { GraphicsSettings.SetCustomShader((BuiltinShaderType)0, OriginalShader); } } public static void CreateUI() { UI = new BVTUI(bvtAssets); if (!UI.UICreated) { return; } bLog.Log("Creating UI Panels", force: true); UI.SetupMainPanel(HandleCanvasDropDown, Category, "Shading Overhaul Configuration"); foreach (string item in Category) { string text = item; string text2 = text; if (text2 == "Mod Config") { CreateModConfig(item); } } } private static void CreateModConfig(string PanelName) { UIPanel uIPanel = UI.CreateUIPanel(PanelName); if (uIPanel != null) { uIPanel.AddToggleWidget("Mod Enabled", config.CleanShadingOn.Value, HandleModToggle); uIPanel.AddSliderWidget(ref config.SpecularIntensity, -1f, 1f, HandleSpecIntensity); uIPanel.AddSliderWidget(ref config.AmbientLight, 0f, 2f, HandleAmbientLight); uIPanel.AddSliderWidget(ref config.ColorTemp, -1f, 1f, HandleColorTemp); uIPanel.AddSliderWidget(ref config.ColorSaturation, 0f, 2f, HandleColorSaturation); UI.AddUIPanel(uIPanel, SetActive: true); } } private static void HandleColorSaturation(float value, string title) { if ((Object)(object)PostProcessMaterial != (Object)null) { PostProcessMaterial.SetFloat("_Saturation", value); } } private static void HandleColorTemp(float value, string title) { if ((Object)(object)PostProcessMaterial != (Object)null) { PostProcessMaterial.SetFloat("_Temperature", value); } } private static void HandleAmbientLight(float value, string title) { config.AmbientLight.Value = value; UpdateEnvs(envMan); } private static void HandleSpecIntensity(float value, string title) { config.SpecularIntensity.Value = value; SetShaderProperties(); } private static void HandleModToggle(Toggle t) { config.CleanShadingOn.Value = t.isOn; UpdateShader(); } private static void HandleCanvasDropDown(Dropdown dd) { bLog.Log("setting " + Category[dd.value] + " panel active"); UI.SetActiveUIPanel(Category[dd.value]); } public static void AddCameraComponents() { mainCamera = Utils.GetMainCamera(); if ((Object)(object)mainCamera != (Object)null) { ((Component)mainCamera).gameObject.AddComponent<CameraPostProcess>(); } } public static void CreatePostProcessShader() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown PostProcessMaterial = new Material(PostProcessShader); ((Object)PostProcessMaterial).name = "BSOPostProcessMaterial"; ((Object)PostProcessMaterial).hideFlags = (HideFlags)61; PostProcessMaterial.SetFloat("_Temperature", config.ColorTemp.Value); PostProcessMaterial.SetFloat("_Saturation", config.ColorSaturation.Value); } } } namespace Badgers_Shading_Overhaul.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("Badgers_Shading_Overhaul.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[] deferredshaders { get { object @object = ResourceManager.GetObject("deferredshaders", resourceCulture); return (byte[])@object; } } internal static byte[] guiassets { get { object @object = ResourceManager.GetObject("guiassets", resourceCulture); return (byte[])@object; } } internal Resources() { } } } namespace Badgers_Shading_Overhaul.Gui { public delegate void DropdownHandler(Dropdown dd); public enum WidgetType { Slider, Button } internal class BVTUI { private GameObject BVTCanvas; private BVTAssets bvtAssets; private GameObject widgetSpace = null; private GameObject mainCanvas = null; private GameObject mainPanel = null; private Dictionary<string, UIPanel> UIPanels = new Dictionary<string, UIPanel>(); private string ActiveUIPanelName; public bool showMenu = false; public bool UICreated = false; public BVTUI(BVTAssets AssetBundle) { bLog.Log("Attempting to create UI"); if (AssetBundle.assetsLoaded) { bvtAssets = AssetBundle; if (CreateUI()) { AddUIComponents(); } bLog.Log("UI created"); UICreated = true; } else { bLog.Log("Unable to create UI due to missing assets"); } } private bool CreateUI() { mainCanvas = bvtAssets.GetCanvas(); if ((Object)(object)mainCanvas != (Object)null) { BVTCanvas = Object.Instantiate<GameObject>(mainCanvas); widgetSpace = ((Component)((Transform)BVTCanvas.GetComponent<RectTransform>()).Find("Panel/ScrollView/Viewport/Content/WidgetSpace")).gameObject; widgetSpace.SetActive(false); BVTCanvas.SetActive(false); return true; } BVTCanvas = null; return false; } public void SetupMainPanel(DropdownHandler dropDownHandler, List<string> Category, string Title) { mainPanel.GetComponent<DropdownComponent>().PopulateItems(Category); mainPanel.GetComponent<DropdownComponent>().ValueChangedHandler(dropDownHandler); ((Component)mainPanel.transform.Find("TitleText")).GetComponent<Text>().text = Title; } public UIPanel CreateUIPanel(string Name) { if ((Object)(object)widgetSpace != (Object)null) { UIPanel uIPanel = new UIPanel(Name, widgetSpace, BVTCanvas, bvtAssets); if (uIPanel != null) { return uIPanel; } } return null; } public void AddUIPanel(UIPanel Panel, bool SetActive = false) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) if (SetActive) { Panel.panel.SetActive(true); ActiveUIPanelName = ((Object)Panel.panel).name; } Panel.panel.GetComponent<RectTransform>().sizeDelta = new Vector2(0f, Panel.totalHeight / 2f); UIPanels.Add(Panel.name, Panel); } public void SetActiveUIPanel(string PanelName) { if (!(PanelName != ActiveUIPanelName)) { return; } foreach (UIPanel value in UIPanels.Values) { if (PanelName == value.name) { value.panel.SetActive(true); ActiveUIPanelName = PanelName; } else { value.panel.SetActive(false); } } } public void ToggleMenu() { if (!((Object)(object)BVTCanvas != (Object)null)) { return; } if (!showMenu) { Cursor.lockState = (CursorLockMode)0; Cursor.visible = true; if ((Object)(object)Player.m_localPlayer != (Object)null) { ((Behaviour)((Component)Player.m_localPlayer).GetComponent<PlayerController>()).enabled = false; ((Behaviour)GameCamera.instance).enabled = false; } showMenu = true; BVTCanvas.SetActive(true); } else { Cursor.lockState = (CursorLockMode)1; Cursor.visible = false; if ((Object)(object)Player.m_localPlayer != (Object)null) { ((Behaviour)((Component)Player.m_localPlayer).GetComponent<PlayerController>()).enabled = true; ((Behaviour)GameCamera.instance).enabled = true; } showMenu = false; BVTCanvas.SetActive(false); } } private void AddUIComponents() { mainPanel = ((Component)((Transform)BVTCanvas.GetComponent<RectTransform>()).Find("Panel")).gameObject; if ((Object)(object)mainPanel != (Object)null) { mainPanel.AddComponent<MouseDragComponent>(); mainPanel.AddComponent<DropdownComponent>(); } } } internal class DropdownComponent : MonoBehaviour { private Dropdown dropDown; public void PopulateItems(List<string> Items) { dropDown = ((Component)((Transform)((Component)this).GetComponent<RectTransform>()).Find("CatSelector")).GetComponent<Dropdown>(); dropDown.AddOptions(Items); } public void ValueChangedHandler(DropdownHandler dropDownHandler) { ((UnityEvent<int>)(object)dropDown.onValueChanged).AddListener((UnityAction<int>)delegate { dropDownHandler(dropDown); }); } } internal class UIPanel { public GameObject panel = null; public string name; private BVTAssets bvtAssets; private float lastWidgetHeight; private float widgetPanelOffset; private float widgetPanelSpacing = 80f; public float totalHeight = 0f; private List<Toggle> Toggles = new List<Toggle>(); public UIPanel(string Name, GameObject SourcePanel, GameObject MainCanvas, BVTAssets Assets) { panel = Object.Instantiate<GameObject>(SourcePanel, ((Component)((Transform)MainCanvas.GetComponent<RectTransform>()).Find("Panel/ScrollView/Viewport/Content")).transform); name = Name; bvtAssets = Assets; } public bool AddSliderWidget(ref ConfigEntry<float> bvtConfigValue, float MinValue, float MaxValue, SliderHandlerMethod sliderHandlerMethod = null, string precision = "0.00") { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005d: 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) GameObject sliderWidget = bvtAssets.GetSliderWidget(); if ((Object)(object)sliderWidget != (Object)null) { GameObject val = Object.Instantiate<GameObject>(((Component)((Transform)sliderWidget.GetComponent<RectTransform>()).Find("Widget")).gameObject, panel.transform); if ((Object)(object)val != (Object)null) { Rect rect = val.GetComponent<RectTransform>().rect; lastWidgetHeight = ((Rect)(ref rect)).height; val.AddComponent<SliderWidgetController>(); val.transform.localPosition = new Vector3(0f, widgetPanelOffset, 0f); widgetPanelOffset = lastWidgetHeight + widgetPanelSpacing; totalHeight += widgetPanelOffset; SliderWidgetController component = val.GetComponent<SliderWidgetController>(); if ((Object)(object)component != (Object)null) { bLog.Log("Widget Controller added"); component.SetParameters(ref bvtConfigValue, MinValue, MaxValue, sliderHandlerMethod, precision); } return true; } } return false; } public bool AddBUttonWidget(string Text, handlerMethod HandlerMethod) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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) GameObject buttonWidget = bvtAssets.GetButtonWidget(); if ((Object)(object)buttonWidget != (Object)null) { GameObject val = Object.Instantiate<GameObject>(((Component)((Transform)buttonWidget.GetComponent<RectTransform>()).Find("Widget")).gameObject, panel.transform); if ((Object)(object)val != (Object)null) { val.AddComponent<ButtonWidgetController>(); Rect rect = val.GetComponent<RectTransform>().rect; lastWidgetHeight = ((Rect)(ref rect)).height; val.transform.localPosition = new Vector3(0f, widgetPanelOffset, 0f); widgetPanelOffset = lastWidgetHeight + widgetPanelSpacing; ButtonWidgetController component = val.GetComponent<ButtonWidgetController>(); if ((Object)(object)component != (Object)null) { bLog.Log("Widget controller addded"); component.SetParameters(Text, HandlerMethod); } return true; } } return false; } public bool AddLabelWidget(string Text) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) GameObject labelWidget = bvtAssets.GetLabelWidget(); if ((Object)(object)labelWidget != (Object)null) { GameObject val = Object.Instantiate<GameObject>(((Component)((Transform)labelWidget.GetComponent<RectTransform>()).Find("Widget")).gameObject, panel.transform); if ((Object)(object)val != (Object)null) { val.AddComponent<LabelWidgetController>(); bLog.Log("Added label widget to UI"); Rect rect = val.GetComponent<RectTransform>().rect; lastWidgetHeight = ((Rect)(ref rect)).height; val.transform.localPosition = new Vector3(0f, widgetPanelOffset, 0f); widgetPanelOffset = lastWidgetHeight + widgetPanelSpacing; LabelWidgetController component = val.GetComponent<LabelWidgetController>(); if ((Object)(object)component != (Object)null) { component.SetParameters(Text); } return true; } } return false; } public bool AddToggleWidget(string Text, bool state, ToggleHandler toggleHandler) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) GameObject toggleWidget = bvtAssets.GetToggleWidget(); if ((Object)(object)toggleWidget != (Object)null) { GameObject val = Object.Instantiate<GameObject>(((Component)((Transform)toggleWidget.GetComponent<RectTransform>()).Find("Widget")).gameObject, panel.transform); if ((Object)(object)val != (Object)null) { val.AddComponent<ToggleWidgetController>(); Toggles.Add(((Component)val.transform.Find("Toggle")).GetComponent<Toggle>()); bLog.Log("Added toggle widget to UI"); Rect rect = val.GetComponent<RectTransform>().rect; lastWidgetHeight = ((Rect)(ref rect)).height; val.transform.localPosition = new Vector3(0f, widgetPanelOffset, 0f); widgetPanelOffset = lastWidgetHeight + widgetPanelSpacing; ToggleWidgetController component = val.GetComponent<ToggleWidgetController>(); if ((Object)(object)component != (Object)null) { component.SetParameters(Text, state, toggleHandler); } return true; } } return false; } public void ClearToggles() { foreach (Toggle toggle in Toggles) { toggle.isOn = false; } } } } namespace Badgers_Shading_Overhaul.Gui.GUIScriptComponents { public delegate void handlerMethod(); internal class ButtonWidgetController : MonoBehaviour { public void SetParameters(string Text, handlerMethod HandlerMethod) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown ((Component)((Component)this).transform.Find("Button/Text")).GetComponent<Text>().text = Text; ((UnityEvent)((Component)((Component)this).transform.Find("Button")).GetComponent<Button>().onClick).AddListener((UnityAction)delegate { HandlerMethod(); }); } } internal class LabelWidgetController : MonoBehaviour { public void SetParameters(string Text) { ((Component)((Component)this).transform.Find("Text")).GetComponent<Text>().text = Text; } } public delegate void SliderHandlerMethod(float value, string title); internal class SliderWidgetController : MonoBehaviour { private string titleText; private Text title; private Slider slider; private InputField textInput; private float sliderValue; private float sliderMinValue; private float sliderMaxValue; private ConfigEntry<float> bvtConfigItem; private string precision = "0.00"; public void SetParameters(ref ConfigEntry<float> ConfigValue, float MinSliderValue, float MaxSliderValue, SliderHandlerMethod sliderHandlerMethod = null, string Precision = "0.00") { bvtConfigItem = ConfigValue; titleText = ((ConfigEntryBase)ConfigValue).Description.Description + ", Default Value: " + ((ConfigEntryBase)ConfigValue).DefaultValue.ToString(); sliderMinValue = MinSliderValue; sliderMaxValue = MaxSliderValue; sliderValue = ConfigValue.Value; precision = Precision; title = ((Component)((Component)this).transform.Find("Title")).GetComponent<Text>(); if ((Object)(object)title != (Object)null) { title.text = titleText; } SetValues(sliderMinValue, sliderMaxValue, sliderValue, sliderHandlerMethod); } private void SetValues(float MinValue, float MaxValue, float Value, SliderHandlerMethod m = null) { textInput = ((Component)((Component)this).transform.Find("TextInput")).GetComponent<InputField>(); if ((Object)(object)textInput != (Object)null) { ((UnityEvent<string>)(object)textInput.onEndEdit).AddListener((UnityAction<string>)delegate { OnTextInputChanged(textInput); }); } slider = ((Component)((Component)this).transform.Find("Slider")).GetComponent<Slider>(); if (!((Object)(object)slider != (Object)null)) { return; } ((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)delegate { OnSliderChanged(slider); }); if (m != null) { ((UnityEvent<float>)(object)slider.onValueChanged).AddListener((UnityAction<float>)delegate { m(slider.value, ((ConfigEntryBase)bvtConfigItem).Description.Description); }); } slider.minValue = MinValue; slider.maxValue = MaxValue; slider.value = Value; textInput.text = Value.ToString(precision); } private void OnTextInputChanged(InputField textInput) { slider.value = float.Parse(textInput.text); } private void OnSliderChanged(Slider slider) { sliderValue = slider.value; textInput.text = sliderValue.ToString(precision); bvtConfigItem.Value = sliderValue; } } public delegate void ToggleHandler(Toggle t); internal class ToggleWidgetController : MonoBehaviour { public void SetParameters(string Text, bool state, ToggleHandler toggleHandler) { ((Component)((Component)this).transform.Find("Toggle/Label")).GetComponent<Text>().text = Text; Toggle tg = ((Component)((Component)this).transform.Find("Toggle")).GetComponent<Toggle>(); tg.isOn = state; if (toggleHandler != null) { ((UnityEvent<bool>)(object)((Component)((Component)this).transform.Find("Toggle")).GetComponent<Toggle>().onValueChanged).AddListener((UnityAction<bool>)delegate { toggleHandler(tg); }); } } } }
plugins/ValheimHDTerrain.dll
Decompiled a year agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Serialization.Json; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using UnityEngine; using ValheimHDTerrain.Logging; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("FindObjectTexture")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("FindObjectTexture")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("26565f84-978a-4666-88ca-4465f43cb131")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace ValheimHDTerrain { internal class Config { private ConfigFile cf = new ConfigFile(Mod.ConfigFile, true); public ConfigEntry<bool> EnableExtendedDebug; public ConfigEntry<bool> DeveloperMode; public ConfigEntry<KeyCode> ReloadTextureKey; public ConfigEntry<KeyCode> ReloadShaderKey; public ConfigEntry<float> GrassDrawDistance; public ConfigEntry<float> GrassAmountModifier; public ConfigEntry<float> WaterCausticsEnabled; public Config() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown EnableExtendedDebug = cf.Bind<bool>("Mod", "EnableExtendedDebug", false, "Enable Extended Debug Information"); DeveloperMode = cf.Bind<bool>("Mod", "EnableDeveloperMode", false, "Enable Developer Mode"); ReloadTextureKey = cf.Bind<KeyCode>("Keybinds", "ReloadTexturesKey", (KeyCode)287, "Key to hot reload textures"); ReloadShaderKey = cf.Bind<KeyCode>("Keybinds", "ReloadShaderKey", (KeyCode)289, "Key to reload shader"); GrassDrawDistance = cf.Bind<float>("Clutter", "GrassDrawDistance", 40f, "Grass Draw Distance"); GrassAmountModifier = cf.Bind<float>("Clutter", "GrassAmountModifier", 1f, "Modifier for grass amount"); WaterCausticsEnabled = cf.Bind<float>("Shader Effects", "WaterCausticsEnabled", 1f, "Enable/Disable Water Caustics"); } } internal class HarmonyPatches { [HarmonyPatch(typeof(Terminal), "InitTerminal")] private class Terminal_InitTerminal { private static void Postfix() { Mod.AddConsoleCommands(); } } [HarmonyPatch(typeof(Player), "Update")] private class Player_Update { private static void Prefix() { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) if (Input.GetKeyDown(Mod.Config.ReloadShaderKey.Value) && Mod.Config.DeveloperMode.Value) { bLog.Log("Reloading Shader"); Mod.LoadShader(); Mod.ApplyShader(); } if (!Input.GetKeyDown(Mod.Config.ReloadTextureKey.Value) || !Mod.Config.DeveloperMode.Value) { return; } Mod.CreateTerrainArrays(); Mod.LoadAdditionalTextures(); foreach (Heightmap allHeightmap in Heightmap.GetAllHeightmaps()) { if ((Object)(object)allHeightmap.m_materialInstance != (Object)null) { bLog.Log("Replacing heightmap shader"); if (!allHeightmap.m_isDistantLod) { allHeightmap.m_materialInstance.SetTexture("_DiffuseArrayTex", (Texture)(object)Mod.DiffuseArray); allHeightmap.m_materialInstance.SetTexture("_NormalArrayTex", (Texture)(object)Mod.NormalArray); allHeightmap.m_materialInstance.SetTexture("_WaterCaustics", (Texture)(object)Mod.WaterCaustics); } else if (allHeightmap.m_isDistantLod) { allHeightmap.m_materialInstance.SetTexture("_DiffuseArrayTex", (Texture)(object)Mod.DiffuseArrayLod); allHeightmap.m_materialInstance.SetTexture("_NormalArrayTex", (Texture)(object)Mod.NormalArrayLod); } } } } } [HarmonyPatch(typeof(Heightmap), "Awake")] private class HeightMap_Awake { private static void Prefix(Heightmap __instance) { if ((Object)(object)Mod.TerrainShader != (Object)null && Mod.UseShader) { bLog.Log($"Is Distant Lod: {__instance.m_isDistantLod}"); if ((Object)(object)__instance.m_material != (Object)null) { bLog.Log("Replacing Terrain Shader"); __instance.m_material.shader = Mod.TerrainShader; } else { bLog.Log("heightmap does not have material"); } } else { bLog.Log("Terrain shader is null, will not replace."); } } } [HarmonyPatch(typeof(Heightmap), "Initialize")] private class Heightmap_Initialize { private static void Postfix(Heightmap __instance) { if (Mod.ReplaceTextures) { if (!__instance.m_isDistantLod) { __instance.m_material.SetTexture("_DiffuseArrayTex", (Texture)(object)Mod.DiffuseArray); __instance.m_material.SetTexture("_NormalArrayTex", (Texture)(object)Mod.NormalArray); __instance.m_material.SetTexture("_WaterCaustics", (Texture)(object)Mod.WaterCaustics); } else if (__instance.m_isDistantLod) { __instance.m_material.SetTexture("_DiffuseArrayTex", (Texture)(object)Mod.DiffuseArrayLod); __instance.m_material.SetTexture("_NormalArrayTex", (Texture)(object)Mod.NormalArrayLod); } } } } [HarmonyPatch(typeof(Heightmap), "RebuildCollisionMesh")] private class Heightmap_RebuildCollisionMesh { private static bool Prefix(Heightmap __instance) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown //IL_0066: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance.m_collisionMesh == (Object)null) { __instance.m_collisionMesh = new Mesh(); ((Object)__instance.m_collisionMesh).name = "___Heightmap m_collisionMesh"; } int num = __instance.m_width + 1; Heightmap.s_tempVertices.Clear(); Heightmap.s_tempIndices.Clear(); for (int i = 0; i < num; i++) { for (int j = 0; j < num; j++) { Heightmap.s_tempVertices.Add(__instance.CalcVertex(j, i)); if (i != 0 && j != 0) { Heightmap.s_tempIndices.Add(num * (i - 1) + j - 1); Heightmap.s_tempIndices.Add(num * i + j - 1); Heightmap.s_tempIndices.Add(num * (i - 1) + j); Heightmap.s_tempIndices.Add(num * i + j - 1); Heightmap.s_tempIndices.Add(num * i + j); Heightmap.s_tempIndices.Add(num * (i - 1) + j); } } } __instance.m_collisionMesh.SetVertices(Heightmap.s_tempVertices); __instance.m_collisionMesh.SetIndices(Heightmap.s_tempIndices.ToArray(), (MeshTopology)0, 0); if (Object.op_Implicit((Object)(object)__instance.m_collider)) { __instance.m_collider.sharedMesh = __instance.m_collisionMesh; } return false; } } [HarmonyPatch(typeof(ClutterSystem), "Awake")] private class ClutterSystem_AwakePatch { [HarmonyPostfix] [HarmonyPriority(0)] private static void Postfix(ClutterSystem __instance) { if (Mod.TweaksInstalled) { return; } for (int i = 0; i < __instance.m_clutter.Count; i++) { if (__instance.m_clutter[i].m_instanced) { __instance.m_clutter[i].m_prefab.GetComponent<InstanceRenderer>().m_useLod = false; __instance.m_clutter[i].m_prefab.GetComponent<InstanceRenderer>().m_useXZLodDistance = false; } } __instance.m_distance = Mod.Config.GrassDrawDistance.Value; __instance.m_amountScale = Mod.Config.GrassAmountModifier.Value; } } [HarmonyPatch(typeof(ClutterSystem), "LateUpdate")] private class ClutterSysten_LateUpdatePatch { [HarmonyPrefix] private static void Prefix(ClutterSystem __instance) { if (!Mod.TweaksInstalled) { __instance.m_distance = Mod.Config.GrassDrawDistance.Value; if (Mod.ForceUpdateClutter) { __instance.m_amountScale = Mod.Config.GrassAmountModifier.Value; Mod.ForceUpdateClutter = false; __instance.ClearAll(); bLog.Log("Rebuilding Grass"); } } } } private Harmony harmony = new Harmony("Badgers.ValheimHDTerrain"); public HarmonyPatches() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown harmony.PatchAll(); } } [DataContract] internal class TerrainConfig { [DataMember] public float cliffLowThreshold = 0.8f; [DataMember] public float cliffHighThreshold = 0.9f; [DataMember] public float rockLowThreshold = 0.7f; [DataMember] public float rockHighThreshold = 0.86f; [DataMember] public float cliffLowThresholdForest = 0.7f; [DataMember] public float cliffHighThresholdForest = 0.95f; [DataMember] public float rockLowThresholdForest = 0.65f; [DataMember] public float rockHighThresholdForest = 0.8f; [DataMember] public float cliffLowThresholdMountain = 0.6f; [DataMember] public float cliffHighThresholdMountain = 0.8f; [DataMember] public float rockLowThresholdMountain = 0.4f; [DataMember] public float rockHighThresholdMountain = 0.6f; [DataMember] public float cliffLowThresholdPlains = 0.7f; [DataMember] public float cliffHighThresholdPlains = 1f; [DataMember] public float rockLowThresholdPlains = 0.55f; [DataMember] public float rockHighThresholdPlains = 0.7f; [DataMember] public int tilingAmount = 8; public static TerrainConfig Load(string Path) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown TerrainConfig result = new TerrainConfig(); using (FileStream fileStream = new FileStream(Path, FileMode.Open)) { DataContractJsonSerializer val = new DataContractJsonSerializer(typeof(TerrainConfig)); result = (TerrainConfig)((XmlObjectSerializer)val).ReadObject((Stream)fileStream); } return result; } public void Save(string FileName) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown using FileStream fileStream = new FileStream(FileName, FileMode.Create, FileAccess.Write); DataContractJsonSerializer val = new DataContractJsonSerializer(typeof(TerrainConfig)); ((XmlObjectSerializer)val).WriteObject((Stream)fileStream, (object)this); } } [BepInPlugin("Badgers.ValheimHDTerrain", "ValheimHDTerrain", "0.1.0")] [BepInProcess("valheim.exe")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class HDTerrain : BaseUnityPlugin { private HarmonyPatches DefaultPatches; private void Awake() { DefaultPatches = new HarmonyPatches(); if (HasConflictingMods()) { Mod.TweaksInstalled = true; } Mod.Init(); } private bool HasConflictingMods() { foreach (KeyValuePair<string, PluginInfo> pluginInfo in Chainloader.PluginInfos) { if (pluginInfo.Value.Metadata.GUID == "Badgers.ValheimTweaksLite") { bLog.Log("Valheim Tweaks mod is loaded, clutter changes will not be enabled.", extendedlog: true); return true; } } return false; } } internal static class Mod { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static ConsoleEvent <>9__33_0; public static ConsoleEvent <>9__33_1; public static ConsoleEvent <>9__33_2; public static ConsoleEvent <>9__33_3; public static ConsoleEvent <>9__33_4; public static ConsoleEvent <>9__33_5; public static ConsoleEvent <>9__33_6; public static ConsoleEvent <>9__33_7; public static ConsoleEvent <>9__33_8; internal void <AddConsoleCommands>b__33_0(ConsoleEventArgs args) { if (args.Length == 2) { string text = args[1].ToString(); string text2 = text.ToLower(); string text3 = text2; if (!(text3 == "enabled")) { if (text3 == "disabled") { Config.WaterCausticsEnabled.Value = 0f; Shader.SetGlobalFloat("_WaterCausticsEnabled", Config.WaterCausticsEnabled.Value); } } else { Config.WaterCausticsEnabled.Value = 1f; Shader.SetGlobalFloat("_WaterCausticsEnabled", Config.WaterCausticsEnabled.Value); } } else { MonoBehaviour.print((object)"Not enough arguments to set water caustics"); } } internal void <AddConsoleCommands>b__33_1(ConsoleEventArgs args) { if (args.Length == 2) { Config.GrassDrawDistance.Value = float.Parse(args[1], CultureInfo.InvariantCulture); } else { MonoBehaviour.print((object)"Not enough arguments to set grass draw distance"); } } internal void <AddConsoleCommands>b__33_2(ConsoleEventArgs args) { if (args.Length == 2) { Config.GrassAmountModifier.Value = float.Parse(args[1], CultureInfo.InvariantCulture); ForceUpdateClutter = true; } else { MonoBehaviour.print((object)"Not enough arguments to set grass amount"); } } internal void <AddConsoleCommands>b__33_3(ConsoleEventArgs args) { if (args.Length == 3) { switch (Convert.ToString(args[1])) { case "meadows": TerrainConfig.rockLowThreshold = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockLowThreshold", TerrainConfig.rockLowThreshold); break; case "forest": TerrainConfig.rockLowThresholdForest = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockLowThresholdForest", TerrainConfig.rockLowThresholdForest); break; case "mountains": TerrainConfig.rockLowThresholdMountain = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockLowThresholdMountain", TerrainConfig.rockLowThresholdMountain); break; case "plains": TerrainConfig.rockLowThresholdPlains = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockLowThresholdPlains", TerrainConfig.rockLowThresholdPlains); break; } } else { MonoBehaviour.print((object)"Not enough arguments to set threshold"); } } internal void <AddConsoleCommands>b__33_4(ConsoleEventArgs args) { if (args.Length == 3) { switch (Convert.ToString(args[1])) { case "meadows": TerrainConfig.rockHighThreshold = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockHighThreshold", TerrainConfig.rockHighThreshold); break; case "forest": TerrainConfig.rockHighThresholdForest = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockHighThresholdForest", TerrainConfig.rockHighThresholdForest); break; case "mountains": TerrainConfig.rockHighThresholdMountain = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockHighThresholdMountain", TerrainConfig.rockHighThresholdMountain); break; case "plains": TerrainConfig.rockHighThresholdPlains = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockHighThresholdPlains", TerrainConfig.rockHighThresholdPlains); break; } } else { MonoBehaviour.print((object)"Not enough arguments to set threshold"); } } internal void <AddConsoleCommands>b__33_5(ConsoleEventArgs args) { if (args.Length == 3) { switch (Convert.ToString(args[1])) { case "meadows": TerrainConfig.cliffLowThreshold = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffLowThreshold", TerrainConfig.cliffLowThreshold); break; case "forest": TerrainConfig.cliffLowThresholdForest = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffLowThresholdForest", TerrainConfig.cliffLowThresholdForest); break; case "mountains": TerrainConfig.cliffLowThresholdMountain = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffLowThresholdMountain", TerrainConfig.cliffLowThresholdMountain); break; case "plains": TerrainConfig.cliffLowThresholdPlains = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffLowThresholdPlains", TerrainConfig.cliffLowThresholdPlains); break; } } else { MonoBehaviour.print((object)"Not enough arguments to set threshold"); } } internal void <AddConsoleCommands>b__33_6(ConsoleEventArgs args) { if (args.Length == 3) { switch (Convert.ToString(args[1])) { case "meadows": TerrainConfig.cliffHighThreshold = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffHighThreshold", TerrainConfig.cliffHighThreshold); break; case "forest": TerrainConfig.cliffHighThresholdForest = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffHighThresholdForest", TerrainConfig.cliffHighThresholdForest); break; case "mountains": TerrainConfig.cliffHighThresholdMountain = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffHighThresholdMountain", TerrainConfig.cliffHighThresholdMountain); break; case "plains": TerrainConfig.cliffHighThresholdPlains = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffHighThresholdPlains", TerrainConfig.cliffHighThresholdPlains); break; } } else { MonoBehaviour.print((object)"Not enough arguments to set threshold"); } } internal void <AddConsoleCommands>b__33_7(ConsoleEventArgs args) { if (args.Length == 1) { TerrainConfig.Save(TerrainConfigFile); } else { MonoBehaviour.print((object)"Not enough arguments to set threshold"); } } internal void <AddConsoleCommands>b__33_8(ConsoleEventArgs args) { if (args.Length == 2) { TerrainConfig.tilingAmount = int.Parse(args[1]); Shader.SetGlobalFloat("_TileAmount", (float)TerrainConfig.tilingAmount); } else { MonoBehaviour.print((object)"Not enough arguments to set threshold"); } } } public static string ConfigPath = Paths.ConfigPath; public static string PluginPath = Paths.PluginPath; public static string ConfigFile = Path.Combine(ConfigPath, "ValheimHDTerrain.cfg"); public static string DataPath = Path.Combine(PluginPath, "HDTerrainData"); public static string TerrainTiles = Path.Combine(DataPath, "Terrain"); public static string TerrainTilesLod = Path.Combine(DataPath, "TerrainLod"); public static string AssetBundleFile = Path.Combine(DataPath, "hdterrain"); public static string TerrainConfigFile = Path.Combine(DataPath, "TerrainConfig.json"); public static Config Config = new Config(); public static bool isMaterialChanged = false; public static Shader TerrainShader; public static bool IsOriginalShaderSaved = false; public static bool UseShader = true; public static bool ReplaceTextures = true; private static bool consoleCommandsAdded = false; public static Texture2DArray DiffuseArray = null; public static Texture2DArray NormalArray = null; public static Texture2DArray DiffuseArrayLod = null; public static Texture2DArray NormalArrayLod = null; public static Texture2D WaterCaustics = null; public static TerrainConfig TerrainConfig = null; public static bool ForceUpdateClutter = false; public static bool TweaksInstalled = false; private static int ArraySize = 17; public static void Init() { LoadConfig(); LoadShader(); LoadAdditionalTextures(); CreateTerrainArrays(); } private static void LoadConfig() { if (File.Exists(TerrainConfigFile)) { bLog.Log("Loading Terrain Config", extendedlog: true); TerrainConfig = TerrainConfig.Load(TerrainConfigFile); } else { bLog.Log("Creating Default Config", extendedlog: true); TerrainConfig = new TerrainConfig(); } } public static void LoadAdditionalTextures() { WaterCaustics = LoadTexture(Path.Combine(TerrainTiles, "WaterCaustics.png"), linear: false, mipMaps: true); WaterCaustics.Apply(); } public static void CreateTerrainArrays() { bLog.Log("Creating HD Terrain texture arrays"); for (int i = 0; i < ArraySize; i++) { Texture2D val = LoadTexture(Path.Combine(TerrainTiles, $"terraintile{i}.png"), linear: false, mipMaps: true); Texture2D val2 = LoadTexture(Path.Combine(TerrainTiles, $"terraintilen{i}.png"), linear: true, mipMaps: true); Texture2D val3 = null; Texture2D val4 = null; if (i <= 15) { val3 = LoadTexture(Path.Combine(TerrainTilesLod, $"terraintile{i}.png"), linear: false, mipMaps: false); val4 = LoadTexture(Path.Combine(TerrainTilesLod, $"terraintilen{i}.png"), linear: true, mipMaps: false); } if (i == 0) { bLog.Log($"Creating diffuse terrain array with image size {((Texture)val).width}x{((Texture)val).height}", extendedlog: true); bLog.Log($"Creating normal terrain array with image size {((Texture)val2).width}x{((Texture)val2).height}", extendedlog: true); bLog.Log($"Creating diffuse terrain lod array with image size {((Texture)val3).width}x{((Texture)val3).height}", extendedlog: true); bLog.Log($"Creating normal terrain lod array with image size {((Texture)val4).width}x{((Texture)val4).height}", extendedlog: true); DiffuseArray = CreateTextureArray(((Texture)val).width, ArraySize, linear: false, mipMaps: true); NormalArray = CreateTextureArray(((Texture)val2).width, ArraySize, linear: true, mipMaps: true); DiffuseArrayLod = CreateTextureArray(((Texture)val3).width, ArraySize, linear: false, mipMaps: false); NormalArrayLod = CreateTextureArray(((Texture)val4).width, ArraySize, linear: true, mipMaps: false); } if ((Object)(object)DiffuseArray != (Object)null && (Object)(object)NormalArray != (Object)null) { for (int j = 0; j < ((Texture)val).mipmapCount; j++) { bLog.Log($"Adding diffuse tile {i} mipmap level {j} image to diffuse terrain array", extendedlog: true); Graphics.CopyTexture((Texture)(object)val, 0, j, (Texture)(object)DiffuseArray, i, j); bLog.Log($"Adding normal tile {i} mipmap level {j} image to normal terrain array", extendedlog: true); Graphics.CopyTexture((Texture)(object)val2, 0, j, (Texture)(object)NormalArray, i, j); if (j == 0 && (Object)(object)val3 != (Object)null && (Object)(object)val4 != (Object)null) { bLog.Log($"Adding terrain lod tile {i} to terrain lod array", extendedlog: true); Graphics.CopyTexture((Texture)(object)val3, 0, 0, (Texture)(object)DiffuseArrayLod, i, 0); bLog.Log($"Adding normal lod tile {i} to normal lod array", extendedlog: true); Graphics.CopyTexture((Texture)(object)val4, 0, 0, (Texture)(object)NormalArrayLod, i, 0); } } Object.DestroyImmediate((Object)(object)val); Object.DestroyImmediate((Object)(object)val2); Object.DestroyImmediate((Object)(object)val3); Object.DestroyImmediate((Object)(object)val4); continue; } bLog.Log("Problem creating terrain arrays, HD Terrain will be disabled", extendedlog: true); Object.DestroyImmediate((Object)(object)val); Object.DestroyImmediate((Object)(object)val2); Object.DestroyImmediate((Object)(object)val3); Object.DestroyImmediate((Object)(object)val4); ReplaceTextures = false; return; } Graphics.CopyTexture((Texture)(object)DiffuseArrayLod, 4, (Texture)(object)DiffuseArrayLod, 2); DiffuseArray.Apply(false, true); NormalArray.Apply(false, true); DiffuseArrayLod.Apply(false, true); NormalArrayLod.Apply(false, true); } private static Texture2D LoadTexture(string path, bool linear, bool mipMaps) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown bLog.Log("Loading texture " + Path.GetFileName(path), extendedlog: true); Texture2D val = new Texture2D(4, 4, (TextureFormat)5, mipMaps, linear); ((Texture)val).filterMode = (FilterMode)2; ((Texture)val).anisoLevel = 16; ImageConversion.LoadImage(val, File.ReadAllBytes(path)); val.Compress(true); return val; } private static Texture2DArray CreateTextureArray(int imagesize, int arraySize, bool linear, bool mipMaps) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Expected O, but got Unknown Texture2DArray val = new Texture2DArray(imagesize, imagesize, arraySize, (TextureFormat)12, mipMaps, linear); ((Texture)val).wrapMode = (TextureWrapMode)0; ((Texture)val).filterMode = (FilterMode)2; ((Texture)val).anisoLevel = 16; return val; } public static void LoadShader() { if (UseShader) { AssetBundle val = AssetBundle.LoadFromFile(AssetBundleFile); TerrainShader = val.LoadAsset<Shader>("HDTerrain"); val.Unload(false); if ((Object)(object)TerrainShader != (Object)null) { bLog.Log("Loaded Terrain Shader", extendedlog: true); } UpdateTerrainShaderValues(); } } public static void UpdateTerrainShaderValues() { Shader.SetGlobalFloat("_RockLowThreshold", TerrainConfig.rockLowThreshold); Shader.SetGlobalFloat("_RockHighThreshold", TerrainConfig.rockHighThreshold); Shader.SetGlobalFloat("_CliffLowThreshold", TerrainConfig.cliffLowThreshold); Shader.SetGlobalFloat("_CliffHighThreshold", TerrainConfig.cliffHighThreshold); Shader.SetGlobalFloat("_RockLowThresholdForest", TerrainConfig.rockLowThresholdForest); Shader.SetGlobalFloat("_RockHighThresholdForest", TerrainConfig.rockHighThresholdForest); Shader.SetGlobalFloat("_CliffLowThresholdForest", TerrainConfig.cliffLowThresholdForest); Shader.SetGlobalFloat("_CliffHighThresholdForest", TerrainConfig.cliffHighThresholdForest); Shader.SetGlobalFloat("_RockLowThresholdMountain", TerrainConfig.rockLowThresholdMountain); Shader.SetGlobalFloat("_RockHighThresholdMountain", TerrainConfig.rockHighThresholdMountain); Shader.SetGlobalFloat("_CliffLowThresholdMountain", TerrainConfig.cliffLowThresholdMountain); Shader.SetGlobalFloat("_CliffHighThresholdMountain", TerrainConfig.cliffHighThresholdMountain); Shader.SetGlobalFloat("_RockLowThresholdPlains", TerrainConfig.rockLowThresholdPlains); Shader.SetGlobalFloat("_RockHighThresholdPlains", TerrainConfig.rockHighThresholdPlains); Shader.SetGlobalFloat("_CliffLowThresholdPlains", TerrainConfig.cliffLowThresholdPlains); Shader.SetGlobalFloat("_CliffHighThresholdPlains", TerrainConfig.cliffHighThresholdPlains); Shader.SetGlobalFloat("_TileAmount", (float)TerrainConfig.tilingAmount); Shader.SetGlobalFloat("_WaterCausticsEnabled", Config.WaterCausticsEnabled.Value); } public static void ApplyShader() { foreach (Heightmap allHeightmap in Heightmap.GetAllHeightmaps()) { if (!allHeightmap.IsDistantLod && (Object)(object)allHeightmap.m_materialInstance != (Object)null) { bLog.Log("Replacing heightmap shader"); allHeightmap.m_materialInstance.shader = TerrainShader; allHeightmap.Regenerate(); } } } public static void AddConsoleCommands() { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_001f: 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_002a: Expected O, but got Unknown //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0064: 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_006f: Expected O, but got Unknown //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Expected O, but got Unknown //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Expected O, but got Unknown //IL_0186: 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_0177: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Expected O, but got Unknown //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01af: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Expected O, but got Unknown //IL_01f6: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Expected O, but got Unknown //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Expected O, but got Unknown object obj = <>c.<>9__33_0; if (obj == null) { ConsoleEvent val = delegate(ConsoleEventArgs args) { if (args.Length == 2) { string text = args[1].ToString(); string text2 = text.ToLower(); string text3 = text2; if (!(text3 == "enabled")) { if (text3 == "disabled") { Config.WaterCausticsEnabled.Value = 0f; Shader.SetGlobalFloat("_WaterCausticsEnabled", Config.WaterCausticsEnabled.Value); } } else { Config.WaterCausticsEnabled.Value = 1f; Shader.SetGlobalFloat("_WaterCausticsEnabled", Config.WaterCausticsEnabled.Value); } } else { MonoBehaviour.print((object)"Not enough arguments to set water caustics"); } }; <>c.<>9__33_0 = val; obj = (object)val; } new ConsoleCommand("watercaustics", "Enable / Disable water caustics", (ConsoleEvent)obj, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); if (!TweaksInstalled) { object obj2 = <>c.<>9__33_1; if (obj2 == null) { ConsoleEvent val2 = delegate(ConsoleEventArgs args) { if (args.Length == 2) { Config.GrassDrawDistance.Value = float.Parse(args[1], CultureInfo.InvariantCulture); } else { MonoBehaviour.print((object)"Not enough arguments to set grass draw distance"); } }; <>c.<>9__33_1 = val2; obj2 = (object)val2; } new ConsoleCommand("grassdrawdistance", "Set grass draw distance", (ConsoleEvent)obj2, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj3 = <>c.<>9__33_2; if (obj3 == null) { ConsoleEvent val3 = delegate(ConsoleEventArgs args) { if (args.Length == 2) { Config.GrassAmountModifier.Value = float.Parse(args[1], CultureInfo.InvariantCulture); ForceUpdateClutter = true; } else { MonoBehaviour.print((object)"Not enough arguments to set grass amount"); } }; <>c.<>9__33_2 = val3; obj3 = (object)val3; } new ConsoleCommand("grassamount", "Set grass amount", (ConsoleEvent)obj3, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } if (consoleCommandsAdded || !Config.DeveloperMode.Value) { return; } bLog.Log("Adding console commands"); object obj4 = <>c.<>9__33_3; if (obj4 == null) { ConsoleEvent val4 = delegate(ConsoleEventArgs args) { if (args.Length == 3) { switch (Convert.ToString(args[1])) { case "meadows": TerrainConfig.rockLowThreshold = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockLowThreshold", TerrainConfig.rockLowThreshold); break; case "forest": TerrainConfig.rockLowThresholdForest = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockLowThresholdForest", TerrainConfig.rockLowThresholdForest); break; case "mountains": TerrainConfig.rockLowThresholdMountain = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockLowThresholdMountain", TerrainConfig.rockLowThresholdMountain); break; case "plains": TerrainConfig.rockLowThresholdPlains = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockLowThresholdPlains", TerrainConfig.rockLowThresholdPlains); break; } } else { MonoBehaviour.print((object)"Not enough arguments to set threshold"); } }; <>c.<>9__33_3 = val4; obj4 = (object)val4; } new ConsoleCommand("setrocklow", "Set low transition threshold for rock", (ConsoleEvent)obj4, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj5 = <>c.<>9__33_4; if (obj5 == null) { ConsoleEvent val5 = delegate(ConsoleEventArgs args) { if (args.Length == 3) { switch (Convert.ToString(args[1])) { case "meadows": TerrainConfig.rockHighThreshold = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockHighThreshold", TerrainConfig.rockHighThreshold); break; case "forest": TerrainConfig.rockHighThresholdForest = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockHighThresholdForest", TerrainConfig.rockHighThresholdForest); break; case "mountains": TerrainConfig.rockHighThresholdMountain = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockHighThresholdMountain", TerrainConfig.rockHighThresholdMountain); break; case "plains": TerrainConfig.rockHighThresholdPlains = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_RockHighThresholdPlains", TerrainConfig.rockHighThresholdPlains); break; } } else { MonoBehaviour.print((object)"Not enough arguments to set threshold"); } }; <>c.<>9__33_4 = val5; obj5 = (object)val5; } new ConsoleCommand("setrockhigh", "Set high transition threshold for rock", (ConsoleEvent)obj5, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj6 = <>c.<>9__33_5; if (obj6 == null) { ConsoleEvent val6 = delegate(ConsoleEventArgs args) { if (args.Length == 3) { switch (Convert.ToString(args[1])) { case "meadows": TerrainConfig.cliffLowThreshold = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffLowThreshold", TerrainConfig.cliffLowThreshold); break; case "forest": TerrainConfig.cliffLowThresholdForest = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffLowThresholdForest", TerrainConfig.cliffLowThresholdForest); break; case "mountains": TerrainConfig.cliffLowThresholdMountain = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffLowThresholdMountain", TerrainConfig.cliffLowThresholdMountain); break; case "plains": TerrainConfig.cliffLowThresholdPlains = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffLowThresholdPlains", TerrainConfig.cliffLowThresholdPlains); break; } } else { MonoBehaviour.print((object)"Not enough arguments to set threshold"); } }; <>c.<>9__33_5 = val6; obj6 = (object)val6; } new ConsoleCommand("setclifflow", "Set low transition threshold for cliff", (ConsoleEvent)obj6, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj7 = <>c.<>9__33_6; if (obj7 == null) { ConsoleEvent val7 = delegate(ConsoleEventArgs args) { if (args.Length == 3) { switch (Convert.ToString(args[1])) { case "meadows": TerrainConfig.cliffHighThreshold = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffHighThreshold", TerrainConfig.cliffHighThreshold); break; case "forest": TerrainConfig.cliffHighThresholdForest = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffHighThresholdForest", TerrainConfig.cliffHighThresholdForest); break; case "mountains": TerrainConfig.cliffHighThresholdMountain = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffHighThresholdMountain", TerrainConfig.cliffHighThresholdMountain); break; case "plains": TerrainConfig.cliffHighThresholdPlains = float.Parse(args[2], CultureInfo.InvariantCulture); Shader.SetGlobalFloat("_CliffHighThresholdPlains", TerrainConfig.cliffHighThresholdPlains); break; } } else { MonoBehaviour.print((object)"Not enough arguments to set threshold"); } }; <>c.<>9__33_6 = val7; obj7 = (object)val7; } new ConsoleCommand("setcliffhigh", "Set high transition threshold for cliff", (ConsoleEvent)obj7, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj8 = <>c.<>9__33_7; if (obj8 == null) { ConsoleEvent val8 = delegate(ConsoleEventArgs args) { if (args.Length == 1) { TerrainConfig.Save(TerrainConfigFile); } else { MonoBehaviour.print((object)"Not enough arguments to set threshold"); } }; <>c.<>9__33_7 = val8; obj8 = (object)val8; } new ConsoleCommand("saveterrainconfig", "Save the current terrain config", (ConsoleEvent)obj8, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); object obj9 = <>c.<>9__33_8; if (obj9 == null) { ConsoleEvent val9 = delegate(ConsoleEventArgs args) { if (args.Length == 2) { TerrainConfig.tilingAmount = int.Parse(args[1]); Shader.SetGlobalFloat("_TileAmount", (float)TerrainConfig.tilingAmount); } else { MonoBehaviour.print((object)"Not enough arguments to set threshold"); } }; <>c.<>9__33_8 = val9; obj9 = (object)val9; } new ConsoleCommand("settilingamount", "Set amount of times each texture tiles in a terrain chunk", (ConsoleEvent)obj9, false, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); } } } namespace ValheimHDTerrain.Logging { internal class bLog { private static bool extendedDebugEnabled = false; private static string logLabel = "HD Terrain"; public static void Log(string LogMessage, bool extendedlog = false) { if (extendedlog || extendedDebugEnabled) { Debug.Log((object)(logLabel + ": " + LogMessage)); } } } }