using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("NoSmokeSimplified")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("06f77987-3f97-4fc3-9f43-44a9412fbbfd")]
[assembly: AssemblyFileVersion("1.0.9")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.9.0")]
[module: UnverifiableCode]
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;
}
}
}
namespace NoSmokeSimplified
{
[BepInPlugin("TastyChickenLegs.NoSmokeSimplified", "NoSmokeSimplified", "1.0.9")]
[BepInProcess("valheim.exe")]
[BepInIncompatibility("Tastychickenlegs.NoSmokeStayLit")]
public class NoSmokeSimplifiedMain : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("Tastychickenlegs.NoSmokeSimplified");
internal const string ModName = "NoSmokeSimplified";
internal const string ModVersion = "1.0.9";
internal const string Author = "TastyChickenLegs";
private const string ModGUID = "TastyChickenLegs.NoSmokeSimplified";
private static string ConfigFileName = "TastyChickenLegs.NoSmokeSimplified.cfg";
private static string ConfigFileFullPath;
public static readonly ManualLogSource TastyLogger;
public static NoSmokeSimplifiedMain context;
private static ConfigEntry<bool> _configEnabled;
internal static ConfigEntry<bool> fe_piece_brazierfloor01;
internal static ConfigEntry<bool> fe_piece_brazierceiling01;
public static ConfigEntry<bool> fe_fire_pit;
internal static ConfigEntry<bool> fe_bonfire;
internal static ConfigEntry<bool> fe_hearth;
internal static ConfigEntry<bool> fe_smelter;
internal static ConfigEntry<bool> keepOnInRain;
internal static ConfigEntry<bool> fe_oven;
private void Awake()
{
_configEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Mod Enabled", true, "Sets the mod to be enabled or not.");
fe_fire_pit = ((BaseUnityPlugin)this).Config.Bind<bool>("Really, I Want Smoke", "Camp Fire Enable Smoke", false, "Enable eternal Smoke for Bonfire");
fe_hearth = ((BaseUnityPlugin)this).Config.Bind<bool>("Really, I Want Smoke", "Hearth Enable Smoke", false, "Enable Smoke for Hearth");
fe_piece_brazierfloor01 = ((BaseUnityPlugin)this).Config.Bind<bool>("Really, I Want Smoke", "Standing Brazier Enable Smoke", false, "Enable for Standing brazier");
fe_piece_brazierceiling01 = ((BaseUnityPlugin)this).Config.Bind<bool>("Really, I Want Smoke", "Ceiling Brazier Enable Smoke", false, "Enable timer for Hanging brazier");
fe_smelter = ((BaseUnityPlugin)this).Config.Bind<bool>("Really, I Want Smoke", "Smelter Enable Smoke", false, "Enable Smoke for Smelter. This disables Smelter Stacking");
fe_bonfire = ((BaseUnityPlugin)this).Config.Bind<bool>("Really, I Want Smoke", "Bonfire Enable Smoke", false, "Enable Smoke for Bonefire");
keepOnInRain = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Keep on in Rain", true, "Keep items from going out in the rain");
fe_oven = ((BaseUnityPlugin)this).Config.Bind<bool>("Really, I Want Smoke", "Oven Enable Smoke", false, "Enable Smoke for Cooking Station.");
if (_configEnabled.Value)
{
harmony.PatchAll();
SetupWatcher();
}
}
private void OnDestroy()
{
((BaseUnityPlugin)this).Config.Save();
harmony.UnpatchSelf();
}
private void SetupWatcher()
{
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
fileSystemWatcher.Changed += ReadConfigValues;
fileSystemWatcher.Created += ReadConfigValues;
fileSystemWatcher.Renamed += ReadConfigValues;
fileSystemWatcher.IncludeSubdirectories = true;
fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
fileSystemWatcher.EnableRaisingEvents = true;
}
private void ReadConfigValues(object sender, FileSystemEventArgs e)
{
if (!File.Exists(ConfigFileFullPath))
{
return;
}
try
{
TastyLogger.LogDebug((object)"ReadConfigValues called");
((BaseUnityPlugin)this).Config.Reload();
TastyLogger.LogInfo((object)"NoSmokeSimplifiedConfig Reloaded");
}
catch
{
TastyLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
TastyLogger.LogError((object)"Please check your config entries for spelling and format!");
}
}
static NoSmokeSimplifiedMain()
{
string configPath = Paths.ConfigPath;
char directorySeparatorChar = Path.DirectorySeparatorChar;
ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
TastyLogger = Logger.CreateLogSource("NoSmokeSimplified");
_configEnabled = null;
}
}
}
namespace NoSmokeSimplified.Patches
{
internal class Case
{
public static bool ConfigCheckGiveMeSmoke(string instanceName)
{
bool result = false;
switch (instanceName)
{
case "fire_pit(Clone)":
result = NoSmokeSimplifiedMain.fe_fire_pit.Value;
break;
case "hearth(Clone)":
result = NoSmokeSimplifiedMain.fe_hearth.Value;
break;
case "piece_brazierfloor01(Clone)":
result = NoSmokeSimplifiedMain.fe_piece_brazierfloor01.Value;
break;
case "piece_brazierceiling01(Clone)":
result = NoSmokeSimplifiedMain.fe_piece_brazierceiling01.Value;
break;
case "smelter(Clone)":
result = NoSmokeSimplifiedMain.fe_smelter.Value;
break;
case "piece_oven(Clone)":
result = NoSmokeSimplifiedMain.fe_oven.Value;
break;
case "fire_pit_planned":
result = NoSmokeSimplifiedMain.fe_fire_pit.Value;
break;
case "hearth_planned":
result = NoSmokeSimplifiedMain.fe_hearth.Value;
break;
case "piece_brazierfloor01_planned":
result = NoSmokeSimplifiedMain.fe_piece_brazierfloor01.Value;
break;
case "piece_brazierceiling01_planned":
result = NoSmokeSimplifiedMain.fe_piece_brazierceiling01.Value;
break;
case "smelter_planned":
result = NoSmokeSimplifiedMain.fe_smelter.Value;
break;
case "piece_oven_planned":
result = NoSmokeSimplifiedMain.fe_oven.Value;
break;
}
return result;
}
}
internal class CookingStationPatch
{
[HarmonyPatch(typeof(CookingStation), "UpdateVisual")]
private class CookingStationSmoke_Patch
{
private static void Postfix(CookingStation __instance, ref bool fireLit)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
string text = default(string);
float num = default(float);
Status val = default(Status);
for (int i = 0; i < __instance.m_slots.Length; i++)
{
__instance.GetSlot(i, ref text, ref num, ref val);
__instance.SetSlotVisual(i, text, fireLit, val);
}
if (__instance.m_useFuel)
{
bool active = __instance.GetFuel() > 0f;
if (Object.op_Implicit((Object)(object)__instance.m_haveFireObject))
{
__instance.m_haveFireObject.SetActive(fireLit);
}
if (Object.op_Implicit((Object)(object)__instance.m_haveFuelObject))
{
__instance.m_haveFuelObject.SetActive(active);
}
}
if (((Object)__instance).name.StartsWith("piece_oven(Clone)"))
{
if (Case.ConfigCheckGiveMeSmoke(((Object)__instance).name))
{
((Behaviour)((Component)Utils.FindChild(((Component)__instance).transform, "SmokeSpawner", (IterativeSearchType)0)).gameObject.GetComponent<SmokeSpawner>()).enabled = true;
}
else
{
((Behaviour)((Component)Utils.FindChild(((Component)__instance).transform, "SmokeSpawner", (IterativeSearchType)0)).gameObject.GetComponent<SmokeSpawner>()).enabled = false;
}
}
}
}
}
internal class FirePlacePatch
{
[HarmonyPatch(typeof(Fireplace), "IsBurning")]
private class FireplaceIsBurning_Patch
{
private static void Postfix(Fireplace __instance, ref bool __result, ref GameObject ___m_enabledObjectHigh)
{
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
try
{
if (Case.ConfigCheckGiveMeSmoke(((Object)__instance).name))
{
if ((Object)(object)__instance.m_smokeSpawner != (Object)null)
{
((Behaviour)__instance.m_smokeSpawner).enabled = true;
}
if (((Object)__instance).name.StartsWith("piece_brazier"))
{
((Behaviour)((Component)Utils.FindChild(((Component)__instance).transform, "SmokeSpawner", (IterativeSearchType)0)).gameObject.GetComponent<SmokeSpawner>()).enabled = true;
}
if (NoSmokeSimplifiedMain.keepOnInRain.Value)
{
__instance.m_wet = false;
}
}
else
{
if ((Object)(object)__instance.m_smokeSpawner != (Object)null)
{
((Behaviour)__instance.m_smokeSpawner).enabled = false;
if (NoSmokeSimplifiedMain.keepOnInRain.Value)
{
__instance.m_wet = false;
}
}
if (((Object)__instance).name.StartsWith("piece_brazier"))
{
((Behaviour)((Component)Utils.FindChild(((Component)__instance).transform, "SmokeSpawner", (IterativeSearchType)0)).gameObject.GetComponent<SmokeSpawner>()).enabled = false;
if (NoSmokeSimplifiedMain.keepOnInRain.Value)
{
__instance.m_wet = false;
}
}
}
if (NoSmokeSimplifiedMain.keepOnInRain.Value)
{
__instance.m_wet = false;
}
float liquidLevel = Floating.GetLiquidLevel(__instance.m_enabledObject.transform.position, 1f, (LiquidType)10);
__result = __instance.m_enabledObject.transform.position.y >= liquidLevel && __instance.m_nview.GetZDO().GetFloat("fuel", 0f) > 0f;
}
catch (Exception ex)
{
NoSmokeSimplifiedMain.TastyLogger.LogWarning((object)("NoSmokeSimplified" + ex));
}
}
}
}
internal class SmelterPatch
{
[HarmonyPatch(typeof(Smelter), "UpdateSmoke")]
private class SmelterUpdateSmoke_Patch
{
private static void Postfix(Smelter __instance)
{
try
{
if (Case.ConfigCheckGiveMeSmoke(((Object)__instance).name))
{
if ((Object)(object)__instance.m_smokeSpawner != (Object)null)
{
((Behaviour)__instance.m_smokeSpawner).enabled = true;
}
}
else if ((Object)(object)__instance.m_smokeSpawner != (Object)null)
{
((Behaviour)__instance.m_smokeSpawner).enabled = false;
__instance.m_blockedSmoke = false;
}
}
catch (Exception ex)
{
NoSmokeSimplifiedMain.TastyLogger.LogWarning((object)("NoSmokeSimplified" + ex));
}
}
}
}
}