using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("Narolith.HearthFix")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Fixes newly placed fireplaces and wisp torches not lighting when NoSmokeSimplified is installed")] [assembly: AssemblyFileVersion("1.1.0.0")] [assembly: AssemblyInformationalVersion("1.1.0+4689178b3258a9751dfe6bf8232e196d40d13d19")] [assembly: AssemblyProduct("Narolith.HearthFix")] [assembly: AssemblyTitle("Narolith.HearthFix")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace HearthFix { [BepInPlugin("Narolith.HearthFix", "Narolith.HearthFix", "1.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { [HarmonyPatch(typeof(Fireplace), "IsBurning")] [HarmonyPriority(200)] private static class FireplaceIsBurning_Fix { private static PropertyInfo? _vplusCurrentProp; private static PropertyInfo? _vplusFireSourceProp; private static MemberInfo? _vplusFireSourceEnabledMember; private static PropertyInfo? _vplusFireSourceFiresProp; private static bool _vplusReflectionAttempted; private static void Postfix(Fireplace __instance, ref bool __result) { if (__result) { return; } ZNetView nview = __instance.m_nview; if (((nview != null) ? nview.GetZDO() : null) != null) { if (__instance.m_nview.GetZDO().GetFloat("fuel", -1f) < 0f && __instance.m_startFuel > 0f) { __result = true; } else if (IsVPlusInfiniteFires()) { __result = true; } } } private static bool IsVPlusInfiniteFires() { if (!_vplusReflectionAttempted) { _vplusReflectionAttempted = true; try { Type type = null; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; i++) { type = assemblies[i].GetType("ValheimPlus.Configurations.Configuration"); if (type != null) { break; } } if (type == null) { Log.LogDebug((object)"[HearthFix] V+ not loaded, skipping FireSource check"); return false; } _vplusCurrentProp = type.GetProperty("Current"); object obj = _vplusCurrentProp?.GetValue(null); if (obj == null) { return false; } _vplusFireSourceProp = obj.GetType().GetProperty("FireSource"); object obj2 = _vplusFireSourceProp?.GetValue(obj); if (obj2 == null) { return false; } Type type2 = obj2.GetType(); Type type3 = type2; while (type3 != null && _vplusFireSourceEnabledMember == null) { _vplusFireSourceEnabledMember = (MemberInfo?)(((object)type3.GetProperty("enabled", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public)) ?? ((object)type3.GetField("enabled", BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public))); type3 = type3.BaseType; } _vplusFireSourceFiresProp = type2.GetProperty("fires"); } catch (Exception ex) { Log.LogWarning((object)("[HearthFix] Failed to reflect V+ config: " + ex.Message)); } } try { if (_vplusCurrentProp == null || _vplusFireSourceProp == null || _vplusFireSourceFiresProp == null) { return false; } object value = _vplusCurrentProp.GetValue(null); object value2 = _vplusFireSourceProp.GetValue(value); if (_vplusFireSourceFiresProp.GetValue(value2) as bool? != true) { return false; } if (_vplusFireSourceEnabledMember is PropertyInfo propertyInfo) { object value3 = propertyInfo.GetValue(value2); return value3 is bool && (bool)value3; } if (_vplusFireSourceEnabledMember is FieldInfo fieldInfo) { object value3 = fieldInfo.GetValue(value2); return value3 is bool && (bool)value3; } return true; } catch { return false; } } } internal static ManualLogSource Log; private static Harmony? _harmony; private void Awake() { Log = ((BaseUnityPlugin)this).Logger; Log.LogInfo((object)"HearthFix v1.1.0 loading..."); _harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null); Log.LogInfo((object)"HearthFix loaded."); } private void OnDestroy() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } public static class PluginInfo { public const string PLUGIN_GUID = "Narolith.HearthFix"; public const string PLUGIN_NAME = "Narolith.HearthFix"; public const string PLUGIN_VERSION = "1.1.0"; } }