Decompiled source of ValheimPlus Grantapher Temporary v9.15.0
BepInEx/plugins/ValheimPlus.dll
Decompiled 2 months ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Net; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Cryptography; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using System.Timers; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using IniParser; using IniParser.Exceptions; using IniParser.Model; using IniParser.Model.Configuration; using IniParser.Model.Formatting; using IniParser.Parser; using JetBrains.Annotations; using Microsoft.CodeAnalysis; using ServerSync; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.SceneManagement; using UnityEngine.UI; using Valheim.SettingsGui; using ValheimPlus.Configurations; using ValheimPlus.Configurations.Sections; using ValheimPlus.GameClasses; using ValheimPlus.RPC; using ValheimPlus.UI; using ValheimPlus.Utility; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("ValheimPlus")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ValheimPlus")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("2a837100-a030-4d0c-bffb-b38356118d9a")] [assembly: AssemblyFileVersion("0.9.15.0")] [assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.9.15.0")] [module: UnverifiableCode] public static class ZNetExtensions { public enum ZNetInstanceType { Local, Client, Server } public static bool IsLocalInstance(this ZNet znet) { return znet.IsServer() && !znet.IsDedicated(); } public static bool IsClientInstance(this ZNet znet) { return !znet.IsServer() && !znet.IsDedicated(); } public static bool IsServerInstance(this ZNet znet) { return znet.IsServer() && znet.IsDedicated(); } public static ZNetInstanceType GetInstanceType(this ZNet znet) { if (znet.IsLocalInstance()) { return ZNetInstanceType.Local; } if (znet.IsClientInstance()) { return ZNetInstanceType.Client; } return ZNetInstanceType.Server; } } namespace ValheimPlus { internal class ABM { public static bool isActive; private static Player PlayerInstance; private static bool controlFlag; private static bool shiftFlag; private static bool altFlag; public static bool exitOnNextIteration; private static Piece component; private const float BASE_TRANSLATION_DISTANCE = 0.1f; private const float BASE_ROTATION_ANGLE_DEGREES = 3f; private static float currentModificationSpeed = 1f; private const float MIN_MODIFICATION_SPEED = 1f; private const float MAX_MODIFICATION_SPEED = 30f; private static Quaternion savedRotation; public static void Run(ref Player __instance) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) PlayerInstance = __instance; if (AEM.isActive) { if (isActive) { exitMode(); } return; } if (Input.GetKeyDown(Configuration.Current.AdvancedBuildingMode.exitAdvancedBuildingMode)) { if (isActive) { exitMode(); } return; } if (exitOnNextIteration) { isActive = false; exitOnNextIteration = false; component = null; } if (isActive && (Object)(object)component == (Object)null) { exitMode(); } else if ((Object)(object)selectedPrefab() == (Object)null || (Object)(object)PlayerInstance.m_placementGhost == (Object)null) { if (isActive) { exitMode(); } } else if (isInBuildMode() && IsHoeOrTerrainTool(selectedPrefab())) { if (isActive) { exitMode(); } } else if (isActive) { if (Vector3.Distance(((Component)PlayerInstance).transform.position, ((Component)component).transform.position) > PlayerInstance.m_maxPlaceDistance) { exitMode(); } isRunning(); listenToHotKeysAndDoWork(); } else if (Input.GetKeyDown(Configuration.Current.AdvancedBuildingMode.enterAdvancedBuildingMode)) { startMode(); } } private static void listenToHotKeysAndDoWork() { //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_02a5: Unknown result type (might be due to invalid IL or missing references) //IL_02b9: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02c8: Unknown result type (might be due to invalid IL or missing references) //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_01eb: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_03e6: Unknown result type (might be due to invalid IL or missing references) //IL_03ed: Unknown result type (might be due to invalid IL or missing references) //IL_03c6: Unknown result type (might be due to invalid IL or missing references) //IL_03cd: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0355: Unknown result type (might be due to invalid IL or missing references) //IL_036d: Unknown result type (might be due to invalid IL or missing references) //IL_0377: Unknown result type (might be due to invalid IL or missing references) //IL_037c: Unknown result type (might be due to invalid IL or missing references) //IL_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_0302: Unknown result type (might be due to invalid IL or missing references) //IL_0316: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_0389: Unknown result type (might be due to invalid IL or missing references) //IL_0470: Unknown result type (might be due to invalid IL or missing references) //IL_0477: Unknown result type (might be due to invalid IL or missing references) //IL_0441: Unknown result type (might be due to invalid IL or missing references) //IL_0448: Unknown result type (might be due to invalid IL or missing references) //IL_0421: Unknown result type (might be due to invalid IL or missing references) //IL_0428: Unknown result type (might be due to invalid IL or missing references) //IL_049e: Unknown result type (might be due to invalid IL or missing references) //IL_04a5: Unknown result type (might be due to invalid IL or missing references) float num = 0f; float num2 = 0f; float num3 = 0f; if (Input.GetKeyDown((KeyCode)306)) { controlFlag = true; } if (Input.GetKeyUp((KeyCode)306)) { controlFlag = false; } if (Input.GetKeyDown((KeyCode)304)) { shiftFlag = true; } if (Input.GetKeyUp((KeyCode)304)) { shiftFlag = false; } if (Input.GetKeyDown((KeyCode)308)) { altFlag = true; } if (Input.GetKeyUp((KeyCode)308)) { altFlag = false; } changeModificationSpeed(); if (Input.GetKeyUp(Configuration.Current.AdvancedBuildingMode.copyObjectRotation)) { savedRotation = ((Component)component).transform.rotation; } if (Input.GetKeyUp(Configuration.Current.AdvancedBuildingMode.pasteObjectRotation)) { ((Component)component).transform.rotation = savedRotation; } float num4 = 3f * currentModificationSpeed; if (Input.GetAxis("Mouse ScrollWheel") > 0f) { Quaternion rotation; if (controlFlag) { num += 1f; rotation = Quaternion.Euler(((Component)component).transform.eulerAngles.x + num4 * num, ((Component)component).transform.eulerAngles.y, ((Component)component).transform.eulerAngles.z); } else if (altFlag) { num2 += 1f; rotation = Quaternion.Euler(((Component)component).transform.eulerAngles.x, ((Component)component).transform.eulerAngles.y, ((Component)component).transform.eulerAngles.z + num4 * num2); } else { num3 += 1f; rotation = Quaternion.Euler(((Component)component).transform.eulerAngles.x, ((Component)component).transform.eulerAngles.y + num4 * num3, ((Component)component).transform.eulerAngles.z); } ((Component)component).transform.rotation = rotation; } if (Input.GetAxis("Mouse ScrollWheel") < 0f) { Quaternion rotation2; if (controlFlag) { num -= 1f; rotation2 = Quaternion.Euler(((Component)component).transform.eulerAngles.x + num4 * num, ((Component)component).transform.eulerAngles.y, ((Component)component).transform.eulerAngles.z); } else if (altFlag) { num2 -= 1f; rotation2 = Quaternion.Euler(((Component)component).transform.eulerAngles.x, ((Component)component).transform.eulerAngles.y, ((Component)component).transform.eulerAngles.z + num4 * num2); } else { num3 -= 1f; rotation2 = Quaternion.Euler(((Component)component).transform.eulerAngles.x, ((Component)component).transform.eulerAngles.y + num4 * num3, ((Component)component).transform.eulerAngles.z); } ((Component)component).transform.rotation = rotation2; } float num5 = 0.1f * currentModificationSpeed; if (Input.GetKeyDown((KeyCode)273)) { if (controlFlag) { ((Component)component).transform.Translate(Vector3.up * num5); } else { ((Component)component).transform.Translate(Vector3.forward * num5); } } if (Input.GetKeyDown((KeyCode)274)) { if (controlFlag) { ((Component)component).transform.Translate(Vector3.down * num5); } else { ((Component)component).transform.Translate(Vector3.back * num5); } } if (Input.GetKeyDown((KeyCode)276)) { ((Component)component).transform.Translate(Vector3.left * num5); } if (Input.GetKeyDown((KeyCode)275)) { ((Component)component).transform.Translate(Vector3.right * num5); } try { isValidPlacement(); } catch { } } private static void isValidPlacement() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Invalid comparison between Unknown and I4 //IL_01d0: Unknown result type (might be due to invalid IL or missing references) PlayerInstance.m_placementStatus = (PlacementStatus)0; if (component.m_groundOnly || component.m_groundPiece || component.m_cultivatedGroundOnly) { PlayerInstance.m_placementMarkerInstance.SetActive(false); } StationExtension val = ((Component)component).GetComponent<StationExtension>(); if ((Object)(object)val != (Object)null) { CraftingStation val2 = val.FindClosestStationInRange(((Component)component).transform.position); if (Object.op_Implicit((Object)(object)val2)) { val.StartConnectionEffect(val2, 1f); } else { val.StopConnectionEffect(); PlayerInstance.m_placementStatus = (PlacementStatus)7; } if (val.OtherExtensionInRange(component.m_spaceRequirement)) { PlayerInstance.m_placementStatus = (PlacementStatus)5; } } if (component.m_onlyInTeleportArea && !Object.op_Implicit((Object)(object)EffectArea.IsPointInsideArea(((Component)component).transform.position, (Type)16, 0f))) { PlayerInstance.m_placementStatus = (PlacementStatus)6; } if (!component.m_allowedInDungeons && ((Component)component).transform.position.y > 3000f) { PlayerInstance.m_placementStatus = (PlacementStatus)11; } if (Location.IsInsideNoBuildLocation(PlayerInstance.m_placementGhost.transform.position)) { PlayerInstance.m_placementStatus = (PlacementStatus)3; } float num = (Object.op_Implicit((Object)(object)((Component)component).GetComponent<PrivateArea>()) ? ((Component)component).GetComponent<PrivateArea>().m_radius : 0f); if (!PrivateArea.CheckAccess(PlayerInstance.m_placementGhost.transform.position, num, true, false)) { PlayerInstance.m_placementStatus = (PlacementStatus)4; } if ((int)PlayerInstance.m_placementStatus > 0) { component.SetInvalidPlacementHeightlight(true); } else { component.SetInvalidPlacementHeightlight(false); } } private static void startMode() { notifyUser("Starting ABM", (MessageType)1); isActive = true; component = PlayerInstance.m_placementGhost.GetComponent<Piece>(); } private static void exitMode() { notifyUser("Exiting ABM", (MessageType)1); exitOnNextIteration = true; isActive = false; component = null; } private static bool isInBuildMode() { return ((Character)PlayerInstance).InPlaceMode(); } private static GameObject selectedPrefab() { if ((Object)(object)PlayerInstance.m_buildPieces != (Object)null) { try { return PlayerInstance.m_buildPieces.GetSelectedPrefab(); } catch { return null; } } return null; } private static bool IsHoeOrTerrainTool(GameObject selectedPrefab) { string[] source = new string[4] { "paved_road", "mud_road", "raise", "path" }; string[] source2 = new string[2] { "cultivate", "replant" }; if (((Object)selectedPrefab).name.ToLower().Contains("sapling")) { return true; } if (source.Contains(((Object)selectedPrefab).name) || source2.Contains(((Object)selectedPrefab).name)) { return true; } return false; } private static void notifyUser(string Message, MessageType position = 1) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) MessageHud.instance.ShowMessage(position, "ABM: " + Message, 0, (Sprite)null); } private static void isRunning() { if (isActive) { MessageHud.instance.ShowMessage((MessageType)2, "ABM is active", 0, (Sprite)null); } } private static void changeModificationSpeed() { //IL_0022: 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) float num = 1f; if (shiftFlag) { num = 10f; } if (Input.GetKeyDown(Configuration.Current.AdvancedBuildingMode.increaseScrollSpeed)) { currentModificationSpeed = Mathf.Clamp(currentModificationSpeed + num, 1f, 30f); notifyUser("Modification Speed: " + currentModificationSpeed, (MessageType)1); } if (Input.GetKeyDown(Configuration.Current.AdvancedBuildingMode.decreaseScrollSpeed)) { currentModificationSpeed = Mathf.Clamp(currentModificationSpeed - num, 1f, 30f); notifyUser("Modification Speed: " + currentModificationSpeed, (MessageType)1); } } } internal class AEM { public static bool isActive; public static Player PlayerInstance; private static bool controlFlag; private static bool shiftFlag; private static bool altFlag; public static Vector3 HitPoint; public static Vector3 HitNormal; public static Piece HitPiece; public static GameObject HitObject; public static Heightmap HitHeightmap; private static Quaternion InitialRotation; private static Vector3 InitialPosition; private static bool isInExistence; private const float BASE_TRANSLATION_DISTANCE = 0.1f; private const float BASE_ROTATION_ANGLE_DEGREES = 3f; private static float currentModificationSpeed = 1f; private const float MIN_MODIFICATION_SPEED = 1f; private const float MAX_MODIFICATION_SPEED = 30f; private static Quaternion savedRotation; public static bool forceExitNextIteration; public static bool ExecuteRayCast(Player playerInstance) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) //IL_0061: 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) int placeRayMask = playerInstance.m_placeRayMask; RaycastHit val = default(RaycastHit); if (Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref val, 50f, placeRayMask) && Object.op_Implicit((Object)(object)((RaycastHit)(ref val)).collider) && !Object.op_Implicit((Object)(object)((RaycastHit)(ref val)).collider.attachedRigidbody) && Vector3.Distance(Helper.getPlayerCharacter(playerInstance).m_eye.position, ((RaycastHit)(ref val)).point) < playerInstance.m_maxPlaceDistance) { HitPoint = ((RaycastHit)(ref val)).point; HitNormal = ((RaycastHit)(ref val)).normal; HitPiece = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Piece>(); HitObject = ((Component)((RaycastHit)(ref val)).collider).gameObject; HitHeightmap = ((Component)((RaycastHit)(ref val)).collider).GetComponent<Heightmap>(); InitialRotation = ((Component)HitPiece).transform.rotation; InitialPosition = ((Component)HitPiece).transform.position; return isValidRayCastTarget(); } resetObjectInfo(); return false; } public static bool checkForObject() { if ((Object)(object)PlayerInstance == (Object)null) { return false; } if (!ExecuteRayCast(PlayerInstance)) { return false; } return true; } public static void run() { //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) if (forceExitNextIteration) { forceExitNextIteration = false; resetObjectInfo(); isActive = false; return; } if (isInBuildMode()) { if (isActive) { exitMode(); resetObjectTransform(); } return; } if (ABM.isActive) { if (isActive) { exitMode(); resetObjectTransform(); } return; } if (!isActive && Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.enterAdvancedEditingMode)) { if (checkForObject()) { startMode(); } return; } if (Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.abortAndExitAdvancedEditingMode)) { exitMode(); resetObjectTransform(); } if (!isActive) { return; } if (hitPieceStillExists()) { try { ZNetView component = ((Component)HitPiece).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null) { ValheimPlusPlugin.Logger.LogWarning((object)"AEM: Error, network object empty. Code: 2."); exitMode(); return; } } catch { ValheimPlusPlugin.Logger.LogWarning((object)"AEM: Error, network object empty. Code: 3."); exitMode(); } isRunning(); listenToHotKeysAndDoWork(); } else { exitMode(); } } private static void listenToHotKeysAndDoWork() { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: 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_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_02c3: Unknown result type (might be due to invalid IL or missing references) //IL_02db: Unknown result type (might be due to invalid IL or missing references) //IL_02ef: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_02fe: Unknown result type (might be due to invalid IL or missing references) //IL_0401: Unknown result type (might be due to invalid IL or missing references) //IL_0419: Unknown result type (might be due to invalid IL or missing references) //IL_042d: Unknown result type (might be due to invalid IL or missing references) //IL_0437: Unknown result type (might be due to invalid IL or missing references) //IL_043c: Unknown result type (might be due to invalid IL or missing references) //IL_0377: Unknown result type (might be due to invalid IL or missing references) //IL_038b: Unknown result type (might be due to invalid IL or missing references) //IL_03a3: Unknown result type (might be due to invalid IL or missing references) //IL_03ad: Unknown result type (might be due to invalid IL or missing references) //IL_03b2: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_0338: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_035a: Unknown result type (might be due to invalid IL or missing references) //IL_035f: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_055a: Unknown result type (might be due to invalid IL or missing references) //IL_0561: Unknown result type (might be due to invalid IL or missing references) //IL_053a: Unknown result type (might be due to invalid IL or missing references) //IL_0541: Unknown result type (might be due to invalid IL or missing references) //IL_04b5: Unknown result type (might be due to invalid IL or missing references) //IL_04c9: Unknown result type (might be due to invalid IL or missing references) //IL_04e1: Unknown result type (might be due to invalid IL or missing references) //IL_04eb: Unknown result type (might be due to invalid IL or missing references) //IL_04f0: Unknown result type (might be due to invalid IL or missing references) //IL_0462: Unknown result type (might be due to invalid IL or missing references) //IL_0476: Unknown result type (might be due to invalid IL or missing references) //IL_048a: Unknown result type (might be due to invalid IL or missing references) //IL_0498: Unknown result type (might be due to invalid IL or missing references) //IL_049d: Unknown result type (might be due to invalid IL or missing references) //IL_04fd: Unknown result type (might be due to invalid IL or missing references) //IL_05e4: Unknown result type (might be due to invalid IL or missing references) //IL_05eb: Unknown result type (might be due to invalid IL or missing references) //IL_05b5: Unknown result type (might be due to invalid IL or missing references) //IL_05bc: Unknown result type (might be due to invalid IL or missing references) //IL_0595: Unknown result type (might be due to invalid IL or missing references) //IL_059c: Unknown result type (might be due to invalid IL or missing references) //IL_0612: Unknown result type (might be due to invalid IL or missing references) //IL_0619: Unknown result type (might be due to invalid IL or missing references) float num = 0f; float num2 = 0f; float num3 = 0f; if (Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.resetAdvancedEditingMode)) { resetObjectTransform(); } if (Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.confirmPlacementOfAdvancedEditingMode)) { if (isContainer()) { dropContainerContents(); } GameObject val = Object.Instantiate<GameObject>(((Component)HitPiece).gameObject, ((Component)HitPiece).transform.position, ((Component)HitPiece).transform.rotation); HitPiece.m_placeEffect.Create(((Component)HitPiece).transform.position, ((Component)HitPiece).transform.rotation, val.transform, 1f, -1); ZNetView component = ((Component)HitPiece).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null) { ValheimPlusPlugin.Logger.LogWarning((object)"AEM: Error, network object empty."); resetObjectTransform(); exitMode(); } else { component.ClaimOwnership(); ZNetScene.instance.Destroy(((Component)HitPiece).gameObject); ValheimPlusPlugin.Logger.LogInfo((object)"AEM: Executed."); exitMode(); } return; } if (Input.GetKeyDown((KeyCode)306)) { controlFlag = true; } if (Input.GetKeyUp((KeyCode)306)) { controlFlag = false; } if (Input.GetKeyDown((KeyCode)304)) { shiftFlag = true; } if (Input.GetKeyUp((KeyCode)304)) { shiftFlag = false; } if (Input.GetKeyDown((KeyCode)308)) { altFlag = true; } if (Input.GetKeyUp((KeyCode)308)) { altFlag = false; } changeModificationSpeed(); if (Input.GetKeyUp(Configuration.Current.AdvancedEditingMode.copyObjectRotation)) { savedRotation = ((Component)HitPiece).transform.rotation; } if (Input.GetKeyUp(Configuration.Current.AdvancedEditingMode.pasteObjectRotation)) { ((Component)HitPiece).transform.rotation = savedRotation; } if (Vector3.Distance(((Component)PlayerInstance).transform.position, ((Component)HitPiece).transform.position) > PlayerInstance.m_maxPlaceDistance) { resetObjectTransform(); exitMode(); } float num4 = 3f * currentModificationSpeed; if (Input.GetAxis("Mouse ScrollWheel") > 0f) { Quaternion rotation; if (controlFlag) { num += 1f; rotation = Quaternion.Euler(((Component)HitPiece).transform.eulerAngles.x + num4 * num, ((Component)HitPiece).transform.eulerAngles.y, ((Component)HitPiece).transform.eulerAngles.z); } else if (altFlag) { num2 += 1f; rotation = Quaternion.Euler(((Component)HitPiece).transform.eulerAngles.x, ((Component)HitPiece).transform.eulerAngles.y, ((Component)HitPiece).transform.eulerAngles.z + num4 * num2); } else { num3 += 1f; rotation = Quaternion.Euler(((Component)HitPiece).transform.eulerAngles.x, ((Component)HitPiece).transform.eulerAngles.y + num4 * num3, ((Component)HitPiece).transform.eulerAngles.z); } ((Component)HitPiece).transform.rotation = rotation; } if (Input.GetAxis("Mouse ScrollWheel") < 0f) { Quaternion rotation2; if (controlFlag) { num -= 1f; rotation2 = Quaternion.Euler(((Component)HitPiece).transform.eulerAngles.x + num4 * num, ((Component)HitPiece).transform.eulerAngles.y, ((Component)HitPiece).transform.eulerAngles.z); } else if (altFlag) { num2 -= 1f; rotation2 = Quaternion.Euler(((Component)HitPiece).transform.eulerAngles.x, ((Component)HitPiece).transform.eulerAngles.y, ((Component)HitPiece).transform.eulerAngles.z + num4 * num2); } else { num3 -= 1f; rotation2 = Quaternion.Euler(((Component)HitPiece).transform.eulerAngles.x, ((Component)HitPiece).transform.eulerAngles.y + num4 * num3, ((Component)HitPiece).transform.eulerAngles.z); } ((Component)HitPiece).transform.rotation = rotation2; } float num5 = 0.1f * currentModificationSpeed; if (Input.GetKeyDown((KeyCode)273)) { if (controlFlag) { ((Component)HitPiece).transform.Translate(Vector3.up * num5); } else { ((Component)HitPiece).transform.Translate(Vector3.forward * num5); } } if (Input.GetKeyDown((KeyCode)274)) { if (controlFlag) { ((Component)HitPiece).transform.Translate(Vector3.down * num5); } else { ((Component)HitPiece).transform.Translate(Vector3.back * num5); } } if (Input.GetKeyDown((KeyCode)276)) { ((Component)HitPiece).transform.Translate(Vector3.left * num5); } if (Input.GetKeyDown((KeyCode)275)) { ((Component)HitPiece).transform.Translate(Vector3.right * num5); } } private static bool hitPieceStillExists() { try { if (isActive) { isInExistence = true; } } catch { isInExistence = false; } return isInExistence; } private static bool isValidRayCastTarget() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) bool result = true; if (HitPiece.m_onlyInTeleportArea && !Object.op_Implicit((Object)(object)EffectArea.IsPointInsideArea(((Component)HitPiece).transform.position, (Type)16, 0f))) { result = false; } if (!HitPiece.m_allowedInDungeons && ((Component)HitPiece).transform.position.y > 3000f) { result = false; } if (Location.IsInsideNoBuildLocation(((Component)HitPiece).transform.position)) { result = false; } float num = (Object.op_Implicit((Object)(object)((Component)HitPiece).GetComponent<PrivateArea>()) ? ((Component)HitPiece).GetComponent<PrivateArea>().m_radius : 0f); if (!PrivateArea.CheckAccess(((Component)HitPiece).transform.position, num, true, false)) { result = false; } return result; } private static bool isInBuildMode() { return ((Character)PlayerInstance).InPlaceMode(); } private static void resetObjectTransform() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) notifyUser("Object has been reset to initial position & rotation.", (MessageType)1); ((Component)HitPiece).transform.position = InitialPosition; ((Component)HitPiece).transform.rotation = InitialRotation; } private static void resetObjectInfo() { //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_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) HitPoint = Vector3.zero; HitNormal = Vector3.zero; HitObject = null; HitPiece = null; HitHeightmap = null; InitialRotation = default(Quaternion); InitialPosition = default(Vector3); } private static void startMode() { notifyUser("Entering AEM", (MessageType)1); isActive = true; } private static void exitMode() { notifyUser("Exiting AEM", (MessageType)1); forceExitNextIteration = true; } private static void notifyUser(string Message, MessageType position = 1) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) MessageHud.instance.ShowMessage(position, "AEM: " + Message, 0, (Sprite)null); } private static void isRunning() { if (isActive) { MessageHud.instance.ShowMessage((MessageType)2, "AEM is active", 0, (Sprite)null); } } private static bool isContainer() { Container component = ((Component)HitPiece).GetComponent<Container>(); return (Object)(object)component != (Object)null; } private static void dropContainerContents() { Container component = ((Component)HitPiece).GetComponent<Container>(); component.DropAllItems(); } private static void changeModificationSpeed() { //IL_0022: 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) float num = 1f; if (shiftFlag) { num = 10f; } if (Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.increaseScrollSpeed)) { currentModificationSpeed = Mathf.Clamp(currentModificationSpeed + num, 1f, 30f); notifyUser("Modification Speed: " + currentModificationSpeed, (MessageType)1); } if (Input.GetKeyDown(Configuration.Current.AdvancedEditingMode.decreaseScrollSpeed)) { currentModificationSpeed = Mathf.Clamp(currentModificationSpeed - num, 1f, 30f); notifyUser("Modification Speed: " + currentModificationSpeed, (MessageType)1); } } } [HarmonyPatch(typeof(Player), "UpdatePlacementGhost")] public static class Player_UpdatePlacementGhost_Transpile { private static readonly MethodInfo Method_Quaternion_Euler = AccessTools.Method(typeof(Quaternion), "Euler", new Type[3] { typeof(float), typeof(float), typeof(float) }, (Type[])null); private static readonly MethodInfo Method_GetRotation = AccessTools.Method(typeof(Player_UpdatePlacementGhost_Transpile), "GetRotation", (Type[])null, (Type[])null); [UsedImplicitly] [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Expected O, but got Unknown //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Expected O, but got Unknown if (!Configuration.Current.FreePlacementRotation.IsEnabled) { return instructions; } List<CodeInstruction> list = instructions.ToList(); for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.Calls(list[i], Method_Quaternion_Euler) && list[i + 1].opcode == OpCodes.Stloc_S) { object operand = list[i + 1].operand; list.InsertRange(i + 2, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[4] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldloc_S, operand), new CodeInstruction(OpCodes.Call, (object)Method_GetRotation), new CodeInstruction(OpCodes.Stloc_S, operand) }); return list.AsEnumerable(); } } ValheimPlusPlugin.Logger.LogError((object)"Couldn't transpile `Player.UpdatePlacementGhost`!"); return list.AsEnumerable(); } public static Quaternion GetRotation(Player __instance, Quaternion quaternion) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_002f: 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) //IL_003c: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) if (ABM.isActive) { return quaternion; } FreePlacementRotation.PlayerData value; Vector3 val = (FreePlacementRotation.PlayersData.TryGetValue(__instance, out value) ? value.PlaceRotation : ((float)__instance.m_placeRotation * 22.5f * Vector3.up)); return Quaternion.Euler(val); } } public static class FreePlacementRotation { public class PlayerData { public Vector3 PlaceRotation = Vector3.zero; public bool Opposite; public Piece LastPiece; public KeyCode LastKeyCode; } [HarmonyPatch(typeof(Player), "UpdatePlacement")] public static class ModifyPUpdatePlacement { [UsedImplicitly] private static void Postfix(Player __instance, bool takeInput, float dt) { //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) FreePlacementRotationConfiguration freePlacementRotation = Configuration.Current.FreePlacementRotation; if (freePlacementRotation.IsEnabled && !ABM.isActive && ((Character)__instance).InPlaceMode() && takeInput && !Hud.IsPieceSelectionVisible()) { if (!PlayersData.ContainsKey(__instance)) { PlayersData[__instance] = new PlayerData(); } RotateWithWheel(__instance); SyncRotationWithTargetInFront(__instance, freePlacementRotation.copyRotationParallel, perpendicular: false); SyncRotationWithTargetInFront(__instance, freePlacementRotation.copyRotationPerpendicular, perpendicular: true); } } private static void RotateWithWheel(Player __instance) { //IL_0049: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_016b: 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_0144: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) float axis = Input.GetAxis("Mouse ScrollWheel"); PlayerData playerData = PlayersData[__instance]; if (!axis.Equals(0f) || ZInput.GetButton("JoyRotate")) { if (Input.GetKey(Configuration.Current.FreePlacementRotation.rotateY)) { playerData.PlaceRotation += Vector3.up * Mathf.Sign(axis); __instance.m_placeRotation = (int)(playerData.PlaceRotation.y / 22.5f); } else if (Input.GetKey(Configuration.Current.FreePlacementRotation.rotateX)) { playerData.PlaceRotation += Vector3.right * Mathf.Sign(axis); } else if (Input.GetKey(Configuration.Current.FreePlacementRotation.rotateZ)) { playerData.PlaceRotation += Vector3.forward * Mathf.Sign(axis); } else { __instance.m_placeRotation = ClampPlaceRotation(__instance.m_placeRotation); playerData.PlaceRotation = new Vector3(0f, (float)__instance.m_placeRotation * 22.5f, 0f); } playerData.PlaceRotation = ClampAngles(playerData.PlaceRotation); ManualLogSource logger = ValheimPlusPlugin.Logger; Vector3 placeRotation = playerData.PlaceRotation; logger.LogInfo((object)("Angle " + ((object)(Vector3)(ref placeRotation)).ToString())); } } private static void SyncRotationWithTargetInFront(Player __instance, KeyCode keyCode, bool perpendicular) { //IL_0016: 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_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00db: 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) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) Vector3 val = default(Vector3); Vector3 placeRotation = default(Vector3); Piece val2 = default(Piece); Heightmap val3 = default(Heightmap); Collider val4 = default(Collider); if (!((Object)(object)__instance.m_placementGhost == (Object)null) && Input.GetKeyUp(keyCode) && __instance.PieceRayTest(ref val, ref placeRotation, ref val2, ref val3, ref val4, false) && !((Object)(object)val2 == (Object)null)) { PlayerData playerData = PlayersData[__instance]; Quaternion val5 = ((Component)val2).transform.rotation; if (perpendicular) { val5 *= Quaternion.Euler(0f, 90f, 0f); } if (playerData.LastKeyCode != keyCode || (Object)(object)playerData.LastPiece != (Object)(object)val2) { playerData.Opposite = false; } playerData.LastKeyCode = keyCode; playerData.LastPiece = val2; if (playerData.Opposite) { val5 *= Quaternion.Euler(0f, 180f, 0f); } playerData.Opposite = !playerData.Opposite; playerData.PlaceRotation = ((Quaternion)(ref val5)).eulerAngles; ManualLogSource logger = ValheimPlusPlugin.Logger; placeRotation = playerData.PlaceRotation; logger.LogInfo((object)("Sync Angle " + ((object)(Vector3)(ref placeRotation)).ToString())); } } } public static readonly Dictionary<Player, PlayerData> PlayersData = new Dictionary<Player, PlayerData>(); private const int MaxIndex = 16; private static Vector3 ClampAngles(Vector3 angles) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) return new Vector3(ClampAngle(angles.x), ClampAngle(angles.y), ClampAngle(angles.z)); } private static int ClampPlaceRotation(int index) { if (1 == 0) { } int result = ((index < 0) ? (16 + index) : ((index < 16) ? index : (index - 16))); if (1 == 0) { } return result; } private static float ClampAngle(float angle) { if (1 == 0) { } float result = ((angle < 0f) ? (360f + angle) : ((!(angle >= 360f)) ? angle : (angle - 360f))); if (1 == 0) { } return result; } } [HarmonyPatch(typeof(CharacterDrop), "GenerateDropList")] public static class CharacterDrop_GenerateDropList_Patch { private static void Prefix(ref List<Drop> ___m_drops, ref List<Drop> __state) { if (Configuration.Current.LootDrop.IsEnabled) { __state = ___m_drops; ItemDrop val = default(ItemDrop); ___m_drops = ___m_drops.ConvertAll((Drop originalDrop) => (Drop)((!originalDrop.m_prefab.TryGetComponent<ItemDrop>(ref val)) ? ((object)originalDrop) : ((object)new Drop { m_prefab = originalDrop.m_prefab, m_amountMin = (int)Helper.applyModifierValue(originalDrop.m_amountMin, Configuration.Current.LootDrop.lootDropAmountMultiplier), m_amountMax = (int)Helper.applyModifierValue(originalDrop.m_amountMax, Configuration.Current.LootDrop.lootDropAmountMultiplier), m_chance = Helper.applyModifierValue(originalDrop.m_chance, Configuration.Current.LootDrop.lootDropChanceMultiplier), m_onePerPlayer = originalDrop.m_onePerPlayer, m_levelMultiplier = originalDrop.m_levelMultiplier }))); } } private static void Postfix(ref List<Drop> ___m_drops, List<Drop> __state) { if (Configuration.Current.LootDrop.IsEnabled) { ___m_drops = __state; } } } [HarmonyPatch(typeof(Piece), "DropResources")] public static class Piece_DropResources_Transpiler { private static MethodInfo method_Piece_IsPlacedByPlayer = AccessTools.Method(typeof(Piece), "IsPlacedByPlayer", (Type[])null, (Type[])null); private static FieldInfo field_Requirement_m_recover = AccessTools.Field(typeof(Requirement), "m_recover"); [HarmonyTranspiler] public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Expected O, but got Unknown if (!Configuration.Current.Building.IsEnabled) { return instructions; } List<CodeInstruction> list = instructions.ToList(); if (Configuration.Current.Building.alwaysDropResources) { for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.Calls(list[i], method_Piece_IsPlacedByPlayer)) { list[i] = new CodeInstruction(OpCodes.Ldc_I4_1, (object)null); list.RemoveAt(i - 1); } } } if (Configuration.Current.Building.alwaysDropExcludedResources) { for (int j = 0; j < list.Count; j++) { if (CodeInstructionExtensions.LoadsField(list[j], field_Requirement_m_recover, false)) { list.RemoveRange(j - 1, 3); } } } return list.AsEnumerable(); } } [HarmonyPatch(typeof(StationExtension), "Awake")] public static class StationExtension_Awake_Patch { [HarmonyPrefix] public static void Prefix(ref float ___m_maxStationDistance) { if (Configuration.Current.Workbench.IsEnabled) { ___m_maxStationDistance = Configuration.Current.Workbench.workbenchAttachmentRange; } } } internal static class InventoryAssistant { public static List<Container> GetNearbyChests(GameObject target, float range, bool checkWard = true) { //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) string[] array = new string[1] { "piece" }; if (Configuration.Current.CraftFromChest.allowCraftingFromCarts || Configuration.Current.CraftFromChest.allowCraftingFromShips) { array = new string[3] { "piece", "item", "vehicle" }; } Collider[] source = Physics.OverlapSphere(target.transform.position, range, LayerMask.GetMask(array)); IOrderedEnumerable<Collider> orderedEnumerable = source.OrderBy((Collider x) => Vector3.Distance(((Component)x).gameObject.transform.position, target.transform.position)); List<Container> list = new List<Container>(); foreach (Collider item in orderedEnumerable) { try { Container componentInParent = ((Component)item).GetComponentInParent<Container>(); if (Object.op_Implicit((Object)(object)componentInParent) && !list.Contains(componentInParent)) { bool flag = componentInParent.CheckAccess(Player.m_localPlayer.GetPlayerID()); if (checkWard) { flag = flag && PrivateArea.CheckAccess(((Component)item).gameObject.transform.position, 0f, false, true); } Piece componentInParent2 = ((Component)componentInParent).GetComponentInParent<Piece>(); bool flag2 = (Object)(object)((Component)componentInParent).GetComponentInParent<Vagon>() != (Object)null; bool flag3 = (Object)(object)((Component)componentInParent).GetComponentInParent<Ship>() != (Object)null; if ((Object)(object)componentInParent2 != (Object)null && flag && componentInParent.GetInventory() != null && (!flag2 || Configuration.Current.CraftFromChest.allowCraftingFromCarts) && (!flag3 || Configuration.Current.CraftFromChest.allowCraftingFromShips) && (componentInParent2.IsPlacedByPlayer() || (flag3 && Configuration.Current.CraftFromChest.allowCraftingFromShips))) { list.Add(componentInParent); } } } catch { } } return list; } public static List<Container> GetNearbyChestsWithItem(GameObject target, float range, ItemData itemInfo, bool checkWard = true) { List<Container> nearbyChests = GetNearbyChests(target, range, checkWard); List<Container> list = new List<Container>(); foreach (Container item in nearbyChests) { if (ChestContainsItem(item, itemInfo)) { list.Add(item); } } return list; } public static bool ChestContainsItem(Container chest, ItemData needle) { List<ItemData> allItems = chest.GetInventory().GetAllItems(); foreach (ItemData item in allItems) { if (item.m_shared.m_name == needle.m_shared.m_name) { return true; } } return false; } public static bool ChestContainsItem(Container chest, string needle) { List<ItemData> allItems = chest.GetInventory().GetAllItems(); foreach (ItemData item in allItems) { if (item.m_shared.m_name == needle) { return true; } } return false; } public static List<ItemData> GetNearbyChestItems(GameObject target, float range = 10f, bool checkWard = true) { List<ItemData> list = new List<ItemData>(); List<Container> nearbyChests = GetNearbyChests(target, range, checkWard); foreach (Container item in nearbyChests) { List<ItemData> allItems = item.GetInventory().GetAllItems(); foreach (ItemData item2 in allItems) { list.Add(item2); } } return list; } public static List<ItemData> GetNearbyChestItemsByContainerList(List<Container> nearbyChests) { List<ItemData> list = new List<ItemData>(); foreach (Container nearbyChest in nearbyChests) { List<ItemData> allItems = nearbyChest.GetInventory().GetAllItems(); foreach (ItemData item in allItems) { list.Add(item); } } return list; } public static int GetItemAmountInItemList(List<ItemData> itemList, ItemData item, int quality = -1, bool matchWorldLevel = true) { return itemList.Where((ItemData current) => current.m_shared.m_name == item.m_shared.m_name && (quality < 0 || quality == current.m_quality) && (!matchWorldLevel || current.m_worldLevel >= Game.m_worldLevel)).Sum((ItemData current) => current.m_stack); } public static int GetItemAmountInItemList(List<ItemData> itemList, string name, int quality = -1, bool matchWorldLevel = true) { return itemList.Where((ItemData current) => current.m_shared.m_name == name && (quality < 0 || quality == current.m_quality) && (!matchWorldLevel || current.m_worldLevel >= Game.m_worldLevel)).Sum((ItemData current) => current.m_stack); } public static int RemoveItemInAmountFromAllNearbyChests(GameObject target, float range, ItemData needle, int amount, bool checkWard = true) { List<Container> nearbyChests = GetNearbyChests(target, range, checkWard); List<ItemData> nearbyChestItemsByContainerList = GetNearbyChestItemsByContainerList(nearbyChests); int itemAmountInItemList = GetItemAmountInItemList(nearbyChestItemsByContainerList, needle); if (amount == 0) { return 0; } int num = 0; foreach (Container item in nearbyChests) { if (num != amount) { int num2 = RemoveItemFromChest(item, needle, amount); num += num2; amount -= num2; } } return num; } public static int RemoveItemInAmountFromAllNearbyChests(GameObject target, float range, string needle, int amount, bool checkWard = true) { List<Container> nearbyChests = GetNearbyChests(target, range, checkWard); List<ItemData> nearbyChestItemsByContainerList = GetNearbyChestItemsByContainerList(nearbyChests); int itemAmountInItemList = GetItemAmountInItemList(nearbyChestItemsByContainerList, needle); if (amount == 0) { return 0; } int num = 0; foreach (Container item in nearbyChests) { if (num != amount) { int num2 = RemoveItemFromChest(item, needle, amount); num += num2; amount -= num2; } } return num; } public static int RemoveItemFromChest(Container chest, ItemData needle, int amount = 1) { if (!ChestContainsItem(chest, needle)) { return 0; } int num = 0; List<ItemData> allItems = chest.GetInventory().GetAllItems(); foreach (ItemData item in allItems) { if (item.m_shared.m_name == needle.m_shared.m_name) { int num2 = Mathf.Min(item.m_stack, amount); item.m_stack -= num2; amount -= num2; num += num2; if (amount <= 0) { break; } } } if (num == 0) { return 0; } allItems.RemoveAll((ItemData x) => x.m_stack <= 0); chest.m_inventory.m_inventory = allItems; ConveyContainerToNetwork(chest); return num; } public static int RemoveItemFromChest(Container chest, string needle, int amount = 1) { if (!ChestContainsItem(chest, needle)) { return 0; } int num = 0; List<ItemData> allItems = chest.GetInventory().GetAllItems(); foreach (ItemData item in allItems) { if (item.m_shared.m_name == needle) { int num2 = Mathf.Min(item.m_stack, amount); item.m_stack -= num2; amount -= num2; num += num2; if (amount <= 0) { break; } } } if (num == 0) { return 0; } allItems.RemoveAll((ItemData x) => x.m_stack <= 0); chest.m_inventory.m_inventory = allItems; ConveyContainerToNetwork(chest); return num; } public static void ConveyContainerToNetwork(Container c) { c.Save(); c.GetInventory().Changed(); } } [BepInPlugin("org.bepinex.plugins.valheim_plus", "Valheim Plus", "0.9.15.0")] public class ValheimPlusPlugin : BaseUnityPlugin { private const string ValheimPlusGuid = "org.bepinex.plugins.valheim_plus"; private const string ValheimPlusName = "Valheim Plus"; public const string NumericVersion = "0.9.15.0"; private const string VersionExtra = ""; public const string FullVersion = "0.9.15.0"; private const string MinRequiredNumericVersion = "0.9.15.0"; private static readonly GameVersion MinSupportedGameVersion = new GameVersion(0, 219, 10); private static readonly GameVersion TargetGameVersion = new GameVersion(0, 219, 13); private static readonly Dictionary<GameVersion, string> ExcludeGameVersions = new Dictionary<GameVersion, string>(); public static readonly Timer MapSyncSaveTimer = new Timer(TimeSpan.FromMinutes(5.0).TotalMilliseconds); public static readonly string VPlusDataDirectoryPath; private static readonly Harmony Harmony; public const string Repository = "https://github.com/Grantapher/ValheimPlus/releases/latest"; private const string ApiRepository = "https://api.github.com/repos/grantapher/valheimPlus/releases/latest"; internal static readonly string IniFile; private static readonly object VersionCheck; internal static string newestVersion { get; private set; } = ""; internal static bool isUpToDate { get; private set; } public static ManualLogSource Logger { get; private set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Logger.LogInfo((object)("Valheim game version: " + Version.GetVersionString(false))); Logger.LogInfo((object)"Valheim Plus full version: 0.9.15.0"); Logger.LogInfo((object)("Valheim Plus dll file location: '" + ((object)this).GetType().Assembly.Location + "'")); bool flag = IsGameVersionTooOld(); if (flag) { LogTooOld(); } bool flag2 = CheckIsGameVersionExcluded(); if (flag || flag2) { Logger.LogFatal((object)"Aborting loading of Valheim Plus due to incompatible version."); return; } Logger.LogInfo((object)"Trying to load the configuration file"); if (!ConfigurationExtra.LoadSettings()) { Logger.LogError((object)"Error while loading configuration file."); return; } Logger.LogInfo((object)"Configuration file loaded successfully."); PatchAll(); isUpToDate = !IsNewVersionAvailable(); if (!isUpToDate) { Logger.LogWarning((object)"There is a newer version available of ValheimPlus. Please visit https://github.com/Grantapher/ValheimPlus/releases/latest."); } else { Logger.LogInfo((object)"ValheimPlus [0.9.15.0] is up to date."); } if (!Directory.Exists(VPlusDataDirectoryPath)) { Directory.CreateDirectory(VPlusDataDirectoryPath); } VPlusMainMenu.Load(); VPlusSettings.Load(); if (ZNet.m_isServer && Configuration.Current.Map.IsEnabled && Configuration.Current.Map.shareMapProgression) { MapSyncSaveTimer.AutoReset = true; MapSyncSaveTimer.Elapsed += delegate { VPlusMapSync.SaveMapDataToDisk(); }; } Logger.LogInfo((object)"ValheimPlus done loading."); } private static bool IsGameVersionTooOld() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) return Version.CurrentVersion < MinSupportedGameVersion; } private static bool IsGameVersionNewerThanTarget() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) return Version.CurrentVersion > TargetGameVersion; } private static bool CheckIsGameVersionExcluded() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) string value; bool flag = ExcludeGameVersions.TryGetValue(Version.CurrentVersion, out value); if (flag) { Logger.LogError((object)value); } return flag; } private static bool IsNewVersionAvailable() { WebClient webClient = new WebClient(); webClient.Headers.Add("User-Agent: V+ Server"); try { string input = webClient.DownloadString("https://api.github.com/repos/grantapher/valheimPlus/releases/latest"); newestVersion = new Regex("\"tag_name\":\"([^\"]*)?\"").Match(input).Groups[1].Value; } catch { Logger.LogWarning((object)"The newest version could not be determined."); newestVersion = "Unknown"; } if (Version.TryParse(newestVersion, out Version result)) { if (Version.TryParse("0.9.15.0", out Version result2)) { if (result2 < result) { return true; } } else { Logger.LogWarning((object)"Couldn't parse current version"); } } else { Logger.LogWarning((object)"Couldn't parse newest version, comparing version strings with equality."); if (newestVersion != "0.9.15.0") { return true; } } return false; } public static void PatchAll() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Expected O, but got Unknown //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown Logger.LogInfo((object)"Applying patches."); try { Harmony.PatchAll(); Harmony.Patch((MethodBase)typeof(ZPlayFabMatchmaking).GetMethod("CreateLobby", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ZPlayFabMatchmaking_CreateLobby_Transpiler).GetMethod("Transpiler")), (HarmonyMethod)null, (HarmonyMethod)null); if (AppDomain.CurrentDomain.GetAssemblies().Any((Assembly assembly) => assembly.FullName.Contains("assembly_steamworks"))) { Harmony.Patch((MethodBase)AccessTools.TypeByName("SteamGameServer").GetMethod("SetMaxPlayerCount"), new HarmonyMethod(typeof(ChangeSteamServerVariables).GetMethod("Prefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } ((VersionCheck)VersionCheck).ModRequired = Configuration.Current.Server.enforceMod; Logger.LogInfo((object)"Patches successfully applied."); } catch (Exception) { Logger.LogError((object)"Failed to apply patches."); if (IsGameVersionTooOld()) { LogTooOld(); } else if (IsGameVersionNewerThanTarget()) { Logger.LogWarning((object)("This version of Valheim Plus (0.9.15.0) was compiled with a game version of " + $"\"{TargetGameVersion}\", but this game version is newer at \"{Version.CurrentVersion}\". " + "If you are using the PTB, you likely need to use the non-beta version of the game. Otherwise, the errors seen above likely will require the Valheim Plus mod to be updated. If a game update just came out for Valheim, this may take some time for the mod to be updated. See https://github.com/Grantapher/ValheimPlus/blob/grantapher-development/COMPATIBILITY.md for what game versions are compatible with what mod versions.")); } else { Logger.LogWarning((object)("Valheim Plus failed to apply patches. Please ensure the game version (" + Version.GetVersionString(false) + ") is compatible with the Valheim Plus version (0.9.15.0) at https://github.com/Grantapher/ValheimPlus/blob/grantapher-development/COMPATIBILITY.md. If it already is, please report a bug at https://github.com/Grantapher/ValheimPlus/issues.")); } throw; } } private static void LogTooOld() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) Logger.LogError((object)("This version of Valheim Plus (0.9.15.0) expects a minimum game version of " + $"\"{MinSupportedGameVersion}\", but this game version is older at \"{Version.CurrentVersion}\". " + "Please either update the Valheim game, or use an older version of Valheim Plus as per https://github.com/Grantapher/ValheimPlus/blob/grantapher-development/COMPATIBILITY.md.")); } public static void UnpatchSelf() { Logger.LogInfo((object)"Unpatching."); try { Harmony.UnpatchSelf(); Logger.LogInfo((object)"Successfully unpatched."); } catch (Exception arg) { Logger.LogError((object)$"Failed to unpatch. Exception: {arg}"); } } static ValheimPlusPlugin() { //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_001a: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown string bepInExRootPath = Paths.BepInExRootPath; char directorySeparatorChar = Path.DirectorySeparatorChar; VPlusDataDirectoryPath = bepInExRootPath + directorySeparatorChar + "vplus-data"; Harmony = new Harmony("mod.valheim_plus"); IniFile = "https://github.com/Grantapher/ValheimPlus/releases/download/0.9.15.0/valheim_plus.cfg"; VersionCheck = new VersionCheck("org.bepinex.plugins.valheim_plus") { DisplayName = "Valheim Plus", CurrentVersion = "0.9.15.0", MinimumRequiredVersion = "0.9.15.0" }; } } internal static class Helper { private const BindingFlags FieldBindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; public static Character getPlayerCharacter(Player __instance) { return (Character)(object)__instance; } public static Player getPlayerBySenderId(long id) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0026: 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) List<Player> allPlayers = Player.GetAllPlayers(); foreach (Player item in allPlayers) { ZDOID zDOID = getPlayerCharacter(item).GetZDOID(); if (zDOID != new ZDOID(0L, 0u) && ((ZDOID)(ref zDOID)).UserID == id) { return item; } } return null; } public static List<CodeInstruction> removeForcedCaseFunctionCalls(List<CodeInstruction> il) { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Expected O, but got Unknown //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected O, but got Unknown for (int i = 0; i < il.Count; i++) { if (il[i].operand != null) { string text = il[i].operand.ToString(); if (text.Contains("ToUpper") || text.Contains("ToLower") || text.Contains("ToLowerInvariant")) { il[i] = new CodeInstruction(OpCodes.Nop, (object)null); il[i - 1] = new CodeInstruction(OpCodes.Nop, (object)null); il[i + 1] = new CodeInstruction(OpCodes.Nop, (object)null); } } } return il; } public static float tFloat(this float value, int digits) { double num = Math.Pow(10.0, digits); double num2 = Math.Truncate(num * (double)value) / num; return (float)num2; } public static float applyModifierValue(float targetValue, float value) { return (value <= -100f) ? 0f : (targetValue + targetValue / 100f * value); } public static int applyModifierValueWithChance(float targetValue, float value) { float num = applyModifierValue(targetValue, value); if (num == 0f) { return 0; } int num2 = (int)Math.Floor(num); return num2 + (((double)(num - (float)num2) > 1.0 - new Random().NextDouble()) ? 1 : 0); } public static Texture2D LoadPng(Stream fileStream) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown Texture2D val = null; if (fileStream != null) { using MemoryStream memoryStream = new MemoryStream(); fileStream.CopyTo(memoryStream); val = new Texture2D(2, 2); ImageConversion.LoadImage(val, memoryStream.ToArray()); } return val; } public static string CreateMD5(string input) { using MD5 mD = MD5.Create(); byte[] bytes = Encoding.ASCII.GetBytes(input); byte[] array = mD.ComputeHash(bytes); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < array.Length; i++) { stringBuilder.Append(array[i].ToString("X2")); } return stringBuilder.ToString(); } public static void ResizeChildEffectArea(MonoBehaviour parent, Type includedTypes, float newRadius) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Invalid comparison between Unknown and I4 if (!((Object)(object)parent != (Object)null)) { return; } EffectArea componentInChildren = ((Component)parent).GetComponentInChildren<EffectArea>(); if ((Object)(object)componentInChildren != (Object)null && (componentInChildren.m_type & includedTypes) > 0) { SphereCollider component = ((Component)componentInChildren).GetComponent<SphereCollider>(); if ((Object)(object)component != (Object)null) { component.radius = newRadius; } } } public static int Clamp(int value, int min, int max) { return Math.Min(max, Math.Max(min, value)); } public static float Clamp(float value, float min, float max) { return Math.Min(max, Math.Max(min, value)); } public static bool SetFieldIfFound(object obj, string field, object value) { FieldInfo field2 = obj.GetType().GetField(field, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (field2 == null) { return false; } field2.SetValue(obj, value); return true; } } public static class VPlusDataObjects { public class MapRange { public int StartingX; public int EndingX; public int Y; } } } namespace ValheimPlus.Utility { internal static class GameObjectAssistant { private static readonly ConcurrentDictionary<float, Stopwatch> Stopwatches = new ConcurrentDictionary<float, Stopwatch>(); public static Stopwatch GetStopwatch(GameObject o) { float gameObjectPositionHash = GetGameObjectPositionHash(o); if (Stopwatches.TryGetValue(gameObjectPositionHash, out var value)) { return value; } value = new Stopwatch(); Stopwatches.TryAdd(gameObjectPositionHash, value); return value; } public static float GetGameObjectPositionHash(GameObject obj) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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_0025: Unknown result type (might be due to invalid IL or missing references) Vector3 position = obj.transform.position; return 1000f * position.x + position.y + 0.001f * position.z; } public static T GetChildComponentByName<T>(string name, GameObject objected) where T : Component { T[] componentsInChildren = objected.GetComponentsInChildren<T>(true); foreach (T val in componentsInChildren) { if (((Object)((Component)val).gameObject).name == name) { return val; } } return default(T); } } public static class ListExtensions { public static List<List<T>> ChunkBy<T>(this List<T> source, int chunkSize) { return (from x in source.Select((T x, int i) => new { Index = i, Value = x }) group x by x.Index / chunkSize into x select x.Select(v => v.Value).ToList()).ToList(); } } public class RpcData { public string Name; public long Target = ZRoutedRpc.Everybody; public object[] Payload; } public static class RpcQueue { private static Queue<RpcData> _rpcQueue = new Queue<RpcData>(); private static bool _ack = true; public static void Enqueue(RpcData rpc) { _rpcQueue.Enqueue(rpc); } public static bool SendNextRpc() { if (_rpcQueue.Count == 0 || !_ack) { return false; } RpcData rpcData = _rpcQueue.Dequeue(); if (Utility.IsNullOrWhiteSpace(rpcData.Name) || rpcData.Payload == null) { return false; } ZRoutedRpc.instance.InvokeRoutedRPC(rpcData.Target, rpcData.Name, rpcData.Payload); _ack = false; return true; } public static void GotAck() { _ack = true; } } public static class ZPackageExtensions { public static VPlusDataObjects.MapRange ReadVPlusMapRange(this ZPackage pkg) { return new VPlusDataObjects.MapRange { StartingX = pkg.m_reader.ReadInt32(), EndingX = pkg.m_reader.ReadInt32(), Y = pkg.m_reader.ReadInt32() }; } public static void WriteVPlusMapRange(this ZPackage pkg, VPlusDataObjects.MapRange mapRange) { pkg.m_writer.Write(mapRange.StartingX); pkg.m_writer.Write(mapRange.EndingX); pkg.m_writer.Write(mapRange.Y); } } public static class EmbeddedAsset { public static Stream LoadEmbeddedAsset(string assetPath) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string[] manifestResourceNames = executingAssembly.GetManifestResourceNames(); if (executingAssembly.GetManifestResourceInfo(executingAssembly.GetName().Name + "." + assetPath) != null) { return executingAssembly.GetManifestResourceStream(executingAssembly.GetName().Name + "." + assetPath); } return null; } } } namespace ValheimPlus.UI { [HarmonyPatch(typeof(HotkeyBar), "UpdateIcons")] public static class HotkeyBar_UpdateIcons_Patch { private const string hudObjectNamePrefix = "BowAmmoCounts"; private const string noAmmoDisplay = "No Ammo"; private static readonly GameObject[] ammoCounters = (GameObject[])(object)new GameObject[8]; private static int elementCount = -1; private static bool IsEnabled() { return Configuration.Current.Hud.IsEnabled && Configuration.Current.Hud.displayBowAmmoCounts > 0; } private static void Prefix(HotkeyBar __instance, Player player) { if (IsEnabled()) { elementCount = __instance.m_elements.Count; if ((Object)(object)player == (Object)null || ((Character)player).IsDead()) { DestroyAllAmmoCounters(); } } } private static void Postfix(HotkeyBar __instance, Player player) { if (IsEnabled()) { if (elementCount != __instance.m_elements.Count) { DestroyAllAmmoCounters(); } if (!((Object)(object)player == (Object)null) && !((Character)player).IsDead()) { DisplayAmmoCountsUnderBowHotbarIcons(__instance, player); } } } private static void DisplayAmmoCountsUnderBowHotbarIcons(HotkeyBar __instance, Player player) { HashSet<int> hashSet = new HashSet<int> { 0, 1, 2, 3, 4, 5, 6, 7 }; foreach (ItemData item in __instance.m_items) { if (item != null) { hashSet.Remove(item.m_gridPos.x); DisplayAmmoCountsUnderBowHotbarIcon(__instance, player, item); } } foreach (int item2 in hashSet) { DestroyAmmoCounter(item2); } } private static void DisplayAmmoCountsUnderBowHotbarIcon(HotkeyBar __instance, Player player, ItemData item) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Invalid comparison between Unknown and I4 //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Invalid comparison between Unknown and I4 //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0213: Invalid comparison between Unknown and I4 int x = item.m_gridPos.x; GameObject val = ammoCounters[x]; if ((int)item.m_shared.m_itemType != 4 || (Configuration.Current.Hud.displayBowAmmoCounts == 1 && !((Humanoid)player).IsItemEquiped(item)) || x >= __instance.m_elements.Count || x < 0) { DestroyAmmoCounter(x); return; } ElementData val2 = __instance.m_elements[x]; TMP_Text componentInChildren; if ((Object)(object)val == (Object)null) { GameObject gameObject = ((Component)val2.m_amount).gameObject; val = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent, false); ((Object)val).name = "BowAmmoCounts" + x; val.SetActive(true); Vector3 val3 = gameObject.transform.position - ((Component)val2.m_icon).transform.position - new Vector3(0f, 15f); val.transform.Translate(val3); componentInChildren = val.GetComponentInChildren<TMP_Text>(); TMP_Text obj = componentInChildren; obj.fontSize -= 2f; ammoCounters[x] = val; } else { componentInChildren = val.GetComponentInChildren<TMP_Text>(); } val.gameObject.transform.SetParent(((Component)val2.m_amount).gameObject.transform.parent, false); ItemData ammoItem = ((Humanoid)player).m_ammoItem; if (ammoItem == null || ammoItem.m_shared.m_ammoType != item.m_shared.m_ammoType) { ammoItem = ((Humanoid)player).GetInventory().GetAmmoItem(item.m_shared.m_ammoType, (string)null); } int num = 0; int num2 = 0; List<ItemData> allItems = ((Humanoid)player).GetInventory().GetAllItems(); foreach (ItemData item2 in allItems) { if (item2.m_shared.m_ammoType == item.m_shared.m_ammoType && ((int)item2.m_shared.m_itemType == 9 || (int)item2.m_shared.m_itemType == 2)) { num2 += item2.m_stack; if (item2.m_shared.m_name == ammoItem.m_shared.m_name) { num += item2.m_stack; } } } if (num2 == 0) { componentInChildren.text = "No Ammo"; return; } componentInChildren.text = ammoItem.m_shared.m_name.Split(new char[1] { '_' }).Last() + "\n" + num + "/" + num2; } private static void DestroyAllAmmoCounters() { for (int i = 0; i < 8; i++) { DestroyAmmoCounter(i); } } private static void DestroyAmmoCounter(int index) { GameObject val = ammoCounters[index]; if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); ammoCounters[index] = null; } } } public static class VPlusSettings { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static Func<Font, bool> <>9__23_0; public static Func<Font, bool> <>9__25_0; public static UnityAction <>9__25_1; public static UnityAction <>9__25_2; public static Func<PropertyInfo, string> <>9__25_5; public static Func<OptionData, string> <>9__25_3; public static UnityAction<int> <>9__25_4; internal bool <Load>b__23_0(Font fnt) { return ((Object)fnt).name == "Norse"; } internal bool <Show>b__25_0(Font fnt) { return ((Object)fnt).name == "Norse"; } internal void <Show>b__25_1() { int value = dropper.value; dropper.value = 0; Apply(); Show(); dropper.value = value; } internal void <Show>b__25_2() { //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) Apply(); modSettingsPanel.SetActive(false); Scene activeScene = SceneManager.GetActiveScene(); SceneManager.LoadScene(((Scene)(ref activeScene)).name); } internal string <Show>b__25_5(PropertyInfo prop) { return prop.Name; } internal string <Show>b__25_3(OptionData option) { return option.text; } internal void <Show>b__25_4(int <p0>) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown foreach (Transform item in settingsContentPanel.transform) { Transform val = item; ((Component)val).gameObject.SetActive(false); } foreach (GameObject item2 in settingFamillySettings[availableSettings[dropper.value]]) { item2.SetActive(true); } } } public static bool haveAddedModMenu = false; public static GameObject modSettingsPanel = null; public static GameObject modSettingsPanelCloner = null; public static AssetBundle modSettingsBundle = null; public static GameObject enableToggle = null; public static Font norseFont; public static Color32 vplusYellow = new Color32(byte.MaxValue, (byte)164, (byte)0, byte.MaxValue); public static GameObject settingsContentPanel; public static Dictionary<string, List<GameObject>> settingFamillySettings; public static Button applyButton; public static Button okButton; public static Dropdown dropper; public static GameObject uiTooltipPrefab = null; public static string[] keycodeNames; public static List<string> availableSettings { get; private set; } public static object GetPropValue(object src, string propName) { return src.GetType().GetProperty(propName).GetValue(src, null); } public static GameObject CreateEnableToggle(string settingName, string value, Transform parent, string comments) { bool isOn = bool.Parse(value); GameObject val = Object.Instantiate<GameObject>(enableToggle); val.GetComponentInChildren<Toggle>().isOn = isOn; val.transform.SetParent(parent, false); val.SetActive(false); return val; } public static GameObject CreateTextSettingEntry(string name, string value, Transform parent, string comments) { GameObject val = Object.Instantiate<GameObject>(modSettingsBundle.LoadAsset<GameObject>("SettingEntry_Text")); ((Object)val).name = name; ((Component)val.transform.GetChild(0)).GetComponent<Text>().text = "Setting: " + name + "\nCurrent value: " + value; val.transform.SetParent(parent, false); val.SetActive(false); return val; } public static GameObject CreateKeyCodeSettingEntry(string name, string value, Transform parent, string comments) { //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown GameObject val = Object.Instantiate<GameObject>(modSettingsBundle.LoadAsset<GameObject>("SettingEntry_KeyCode")); ((Object)val).name = name; ((Component)val.transform.GetChild(0)).GetComponent<Text>().text = "Setting: " + name; val.transform.SetParent(parent, false); Dropdown componentInChildren = val.GetComponentInChildren<Dropdown>(); componentInChildren.options.Clear(); string[] array = keycodeNames; foreach (string text in array) { componentInChildren.options.Add(new OptionData(text)); } componentInChildren.value = keycodeNames.ToList().IndexOf(value); val.SetActive(false); return val; } public static GameObject CreateBoolSettingEntry(string name, string value, Transform parent, string comments) { //IL_007f: Unknown result type (might be due to invalid IL or missing references) GameObject val = Object.Instantiate<GameObject>(modSettingsBundle.LoadAsset<GameObject>("SettingEntry_Toggle")); ((Object)val).name = name; ((Component)val.transform.GetChild(0)).GetComponent<Text>().text = "Setting: " + name; val.GetComponentInChildren<Toggle>().isOn = bool.Parse(value); val.transform.SetParent(parent, false); ((Transform)((Component)val.GetComponentInChildren<Toggle>()).gameObject.GetComponent<RectTransform>()).localPosition = new Vector3(0f, -12.5f, 0f); val.SetActive(false); return val; } public static void Load() { norseFont = ((IEnumerable<Font>)Resources.FindObjectsOfTypeAll<Font>()).FirstOrDefault((Func<Font, bool>)((Font fnt) => ((Object)fnt).name == "Norse")); modSettingsBundle = AssetBundle.LoadFromStream(EmbeddedAsset.LoadEmbeddedAsset("Assets.Bundles.settings-ui")); modSettingsPanelCloner = modSettingsBundle.LoadAsset<GameObject>("Mod Settings"); enableToggle = modSettingsBundle.LoadAsset<GameObject>("Toggle_Enable"); uiTooltipPrefab = modSettingsBundle.LoadAsset<GameObject>("SettingsTooltip"); keycodeNames = Enum.GetNames(typeof(KeyCode)); modSettingsPanelCloner.SetActive(false); } public static void Apply() { //IL_03b3: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) if (!File.Exists(ConfigurationExtra.ConfigIniPath)) { return; } ValheimPlusPlugin.Logger.LogInfo((object)"Applying values to config file..."); FileIniDataParser fileIniDataParser = new FileIniDataParser(); IniData iniData = fileIniDataParser.ReadFile(ConfigurationExtra.ConfigIniPath); foreach (KeyValuePair<string, List<GameObject>> settingFamillySetting in settingFamillySettings) { foreach (GameObject item in settingFamillySetting.Value) { PropertyInfo property = Configuration.Current.GetType().GetProperty(settingFamillySetting.Key); object value = property.GetValue(Configuration.Current, null); Type type = value.GetType(); if (((Object)item).name.Contains("Toggle_Enable")) { Toggle componentInChildren = item.GetComponentInChildren<Toggle>(); PropertyInfo property2 = type.GetProperty("IsEnabled"); property2.SetValue(value, componentInChildren.isOn); iniData[settingFamillySetting.Key]["enabled"] = componentInChildren.isOn.ToString(); continue; } InputField componentInChildren2 = item.GetComponentInChildren<InputField>(); Toggle componentInChildren3 = item.GetComponentInChildren<Toggle>(); Dropdown componentInChildren4 = item.GetComponentInChildren<Dropdown>(); if ((Object)(object)componentInChildren2 != (Object)null) { string text = componentInChildren2.text; if (!(text == "")) { PropertyInfo property3 = type.GetProperty(((Object)item).name.Replace("(Clone)", "")); if (property3.PropertyType == typeof(float)) { iniData[settingFamillySetting.Key][((Object)item).name.Replace("(Clone)", "")] = text; } else if (property3.PropertyType == typeof(int)) { iniData[settingFamillySetting.Key][((Object)item).name.Replace("(Clone)", "")] = text; } else if (property3.PropertyType == typeof(bool)) { iniData[settingFamillySetting.Key][((Object)item).name.Replace("(Clone)", "")] = text; } else if (property3.PropertyType == typeof(KeyCode) && (!VPlusConfigSync.SyncRemote || Configuration.Current.Server.serverSyncHotkeys)) { iniData[settingFamillySetting.Key][((Object)item).name.Replace("(Clone)", "")] = text; } else { settingFamillySettings[settingFamillySetting.Key][settingFamillySettings[settingFamillySetting.Key].IndexOf(item)] = CreateTextSettingEntry(((Object)item).name.Replace("(Clone)", ""), text, item.transform.parent, string.Join("\n", iniData[settingFamillySetting.Key].GetKeyData(((Object)item).name.Replace("(Clone)", "")).Comments)); } } } else if ((Object)(object)componentInChildren4 != (Object)null) { PropertyInfo property4 = type.GetProperty(((Object)item).name.Replace("(Clone)", "")); string text2 = keycodeNames[componentInChildren4.value]; KeyCode val = (KeyCode)property4.GetValue(value, null); if (!(text2 == ((object)(KeyCode)(ref val)).ToString()) && property4.PropertyType == typeof(KeyCode) && (!VPlusConfigSync.SyncRemote || Configuration.Current.Server.serverSyncHotkeys)) { iniData[settingFamillySetting.Key][((Object)item).name.Replace("(Clone)", "")] = text2; } } else { PropertyInfo property5 = type.GetProperty(((Object)item).name.Replace("(Clone)", "")); iniData[settingFamillySetting.Key][((Object)item).name.Replace("(Clone)", "")] = componentInChildren3.isOn.ToString(); } } } fileIniDataParser.WriteFile(ConfigurationExtra.ConfigIniPath, iniData); ValheimPlusPlugin.Logger.LogInfo((object)"Values written to config file. Reloading it..."); Configuration.Current = ConfigurationExtra.LoadFromIni(ConfigurationExtra.ConfigIniPath, verbose: false); ValheimPlusPlugin.Logger.LogInfo((object)"Config reloaded. Re-patching..."); ValheimPlusPlugin.UnpatchSelf(); ValheimPlusPlugin.PatchAll(); ValheimPlusPlugin.Logger.LogInfo((object)"Re-patched. Done applying config."); } public static void Show() { //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Expected O, but got Unknown //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Expected O, but got Unknown //IL_04f4: Unknown result type (might be due to invalid IL or missing references) //IL_04fe: Expected O, but got Unknown norseFont = ((IEnumerable<Font>)Resources.FindObjectsOfTypeAll<Font>()).FirstOrDefault((Func<Font, bool>)((Font fnt) => ((Object)fnt).name == "Norse")); settingFamillySettings = new Dictionary<string, List<GameObject>>(); if ((Object)(object)modSettingsPanelCloner == (Object)null) { Load(); } if ((Object)(object)modSettingsPanel == (Object)null) { modSettingsPanel = Object.Instantiate<GameObject>(modSettingsPanelCloner); modSettingsPanel.transform.SetParent(FejdStartup.instance.m_mainMenu.transform, false); modSettingsPanel.transform.localPosition = Vector3.zero; applyButton = GameObjectAssistant.GetChildComponentByName<Button>("Apply", modSettingsPanel); dropper = modSettingsPanel.GetComponentInChildren<Dropdown>(); okButton = GameObjectAssistant.GetChildComponentByName<Button>("OK", modSettingsPanel); ButtonClickedEvent onClick = applyButton.onClick; object obj = <>c.<>9__25_1; if (obj == null) { UnityAction val = delegate { int value3 = dropper.value; dropper.value = 0; Apply(); Show(); dropper.value = value3; }; <>c.<>9__25_1 = val; obj = (object)val; } ((UnityEvent)onClick).AddListener((UnityAction)obj); ButtonClickedEvent onClick2 = okButton.onClick; object obj2 = <>c.<>9__25_2; if (obj2 == null) { UnityAction val2 = delegate { //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) Apply(); modSettingsPanel.SetActive(false); Scene activeScene = SceneManager.GetActiveScene(); SceneManager.LoadScene(((Scene)(ref activeScene)).name); }; <>c.<>9__25_2 = val2; obj2 = (object)val2; } ((UnityEvent)onClick2).AddListener((UnityAction)obj2); ((Component)applyButton).gameObject.SetActive(false); } settingsContentPanel = ((Component)GameObjectAssistant.GetChildComponentByName<Transform>("SettingsContent", modSettingsPanel)).gameObject; ((Component)settingsContentPanel.transform.parent.parent).gameObject.GetComponentInChildren<Scrollbar>().direction = (Direction)2; dropper.options.Clear(); FileIniDataParser fileIniDataParser = new FileIniDataParser(); IniData iniData = fileIniDataParser.ReadFile(ConfigurationExtra.ConfigIniPath); foreach (PropertyInfo item2 in from prop in typeof(Configuration).GetProperties() orderby prop.Name select prop) { string name = item2.Name; if (name == "Current" || name == "Settings" || name == "Deconstruct") { continue; } settingFamillySettings.Add(name, new List<GameObject>()); object value = Configuration.Current.GetType().GetProperty(item2.Name).GetValue(Configuration.Current, null); string? value2 = value.GetType().GetProperty("IsEnabled").GetValue(value) .ToString(); Transform transform = settingsContentPanel.transform; KeyDataCollection keyDataCollection = iniData[name]; object comments; if (keyDataCollection == null) { comments = null; } else { KeyData keyData = keyDataCollection.GetKeyData("enabled"); if (keyData == null) { comments = null; } else { List<string> comments2 = keyData.Comments; comments = ((comments2 != null) ? GeneralExtensions.Join<string>((IEnumerable<string>)comments2, (Func<string, string>)null, "\n") : null); } } GameObject item = CreateEnableToggle(name, value2, transform, (string)comments); settingFamillySettings[name].Add(item); string text = ""; PropertyInfo[] properties = item2.PropertyType.GetProperties(); foreach (PropertyInfo propertyInfo in properties) { string name2 = propertyInfo.Name; if ((!(name2 == "NeedsServerSync") && !(name2 == "IsEnabled")) || 1 == 0) { KeyData keyData2 = iniData[name].GetKeyData(propertyInfo.Name); string text2 = ""; if (keyData2 != null) { List<string> comments3 = keyData2.Comments; text2 = ((comments3 != null) ? GeneralExtensions.Join<string>((IEnumerable<string>)comments3, (Func<string, string>)null, "\n") : null); text = text2; } else { text2 = text; } if (value.GetType().GetProperty(propertyInfo.Name).PropertyType == typeof(bool)) { settingFamillySettings[name].Add(CreateBoolSettingEntry(propertyInfo.Name, value.GetType().GetProperty(propertyInfo.Name).GetValue(value, null) .ToString(), settingsContentPanel.transform, text2)); } else if (value.GetType().GetProperty(propertyInfo.Name).PropertyType == typeof(KeyCode)) { settingFamillySettings[name].Add(CreateKeyCodeSettingEntry(propertyInfo.Name, value.GetType().GetProperty(propertyInfo.Name).GetValue(value, null) .ToString(), settingsContentPanel.transform, text2)); } else { settingFamillySettings[name].Add(CreateTextSettingEntry(propertyInfo.Name, value.GetType().GetProperty(propertyInfo.Name).GetValue(value, null) .ToString(), settingsContentPanel.transform, text2)); } } } dropper.options.Add(new OptionData(name)); } availableSettings = dropper.options.Select((OptionData option) => option.text).ToList(); ((UnityEvent<int>)(object)dropper.onValueChanged).AddListener((UnityAction<int>)delegate { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown foreach (Transform item3 in settingsContentPanel.transform) { Transform val3 = item3; ((Component)val3).gameObject.SetActive(false); } foreach (GameObject item4 in settingFamillySettings[availableSettings[dropper.value]]) { item4.SetActive(true); } }); dropper.value = availableSettings.IndexOf("ValheimPlus"); modSettingsPanel.SetActive(true); } } [HarmonyPatch(typeof(FejdStartup), "Update")] internal class PatchUI { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static UnityAction <>9__1_1; internal void <Postfix>b__1_1() { VPlusSettings.Show(); } } private static Transform newStart; private static void Postfix(ref GameObject ___m_mainMenu, ref GameObject ___m_settingsPrefab) { if (Input.GetKeyDown((KeyCode)291)) { if ((Object)(object)newStart == (Object)null && !VPlusSettings.haveAddedModMenu) { FindAndAddSettings(null, ___m_mainMenu.transform); } else { VPlusSettings.haveAddedModMenu = false; } } static bool FindAndAddSettings(Transform parent, Transform current) { //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Expected O, but got Unknown //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Expected O, but got Unknown if (((Object)current).name == "Start game" && !VPlusSettings.haveAddedModMenu) { newStart = Object.Instantiate<Transform>(current); ((Object)newStart).name = "V+ Settings"; newStart.SetParent(parent); newStart.SetSiblingIndex(3); newStart.localScale = current.localScale; TextMeshProUGUI componentInChildren = ((Component)current).GetComponentInChildren<TextMeshProUGUI>(); TextMeshProUGUI componentInChildren2 = ((Component)newStart).GetComponentInChildren<TextMeshProUGUI>(); ((TMP_Text)componentInChildren2).SetText("V+ Settings"); Object.DestroyImmediate((Object)(object)((Component)newStart).gameObject.GetComponent<Button>()); Button val = ((Component)newStart).gameObject.AddComponent<Button>(); ((Selectable)val).transition = (Transition)3; ButtonClickedEvent onClick = val.onClick; object obj = <>c.<>9__1_1; if (obj == null) { UnityAction val2 = delegate { VPlusSettings.Show(); }; <>c.<>9__1_1 = val2; obj = (object)val2; } ((UnityEvent)onClick).AddListene