using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Extensions;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
using Zen.Config;
using Zen.Lib;
using Zen.Logging;
using ZenWorldSettings.Sections;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ZenWorldSettings")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ZenWorldSettings")]
[assembly: AssemblyCopyright("Copyright \ufffd 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
[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 ZenWorldSettings
{
[BepInPlugin("ZenDragon.ZenWorldSettings", "ZenWorldSettings", "0.3.5")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class Plugin : ZenMod<Plugin>
{
public const string PluginName = "ZenWorldSettings";
public const string PluginVersion = "0.3.5";
public const string PluginGUID = "ZenDragon.ZenWorldSettings";
protected override void Setup()
{
((ZenMod)this).RunOnServer = true;
}
protected override void TitleScene(bool isFirstBoot)
{
}
protected override void WorldStart()
{
ZenWorldSettings.Sections.Environment.Init();
TurretRules.Start();
ShieldGen.Start();
}
protected override void Shutdown()
{
TurretRules.Shutdown();
ShieldGen.Shutdown();
}
}
}
namespace ZenWorldSettings.Sections
{
[HarmonyPatch]
public static class Candle
{
internal static class Configs
{
private const string SECTION_CANDLE = "Candle";
public static readonly ConfigEntry<bool> EnableRefill = Config.Define<bool>(true, "Candle", "Enable Refill", true, "When enabled the candle can be refilled after it is empty. (Vanilla: false)");
}
private static Fireplace? _refuelCandle;
private static bool IsCandle(this Fireplace fireplace)
{
return fireplace.m_nview.GetPrefabName() == "Candle_resin";
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Fireplace), "GetHoverText")]
private static void Fireplace_GetHoverText(Fireplace __instance)
{
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Fireplace), "UpdateState")]
private static void Fireplace_UpdateState(Fireplace __instance)
{
if (__instance.IsCandle() && Configs.EnableRefill.Value)
{
__instance.m_canTurnOff = !(__instance.m_canRefill = FireplaceExt.IsFuelEmpty(__instance));
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Fireplace), "Interact")]
private static void Fireplace_Interact_Prefix(Fireplace __instance, bool alt, bool hold)
{
if (__instance.IsCandle() && !(alt || hold))
{
_refuelCandle = (__instance.m_canRefill ? __instance : null);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Fireplace), "Interact")]
private static void Fireplace_Interact_Postfix()
{
_refuelCandle = null;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(Fireplace), "Interact")]
private static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> codes)
{
MethodInfo methodInfo = AccessTools.Method(typeof(ZNetView), "InvokeRPC", new Type[2]
{
typeof(string),
typeof(object[])
}, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(Candle), "Interact_InvokeRPC_Intercept", (Type[])null, (Type[])null);
return Transpilers.MethodReplacer(codes, (MethodBase)methodInfo, (MethodBase)methodInfo2);
}
private static void Interact_InvokeRPC_Intercept(ZNetView nview, string method, params object[] parameters)
{
if (Object.op_Implicit((Object)(object)_refuelCandle) && method == "RPC_AddFuel")
{
nview.InvokeRPC("RPC_SetFuelAmount", new object[1] { _refuelCandle.m_startFuel });
}
else
{
nview.InvokeRPC(method, parameters);
}
}
}
[HarmonyPatch]
public static class CartRules
{
internal static class Configs
{
private const string SECTION_CART = "Cart";
internal static readonly ConfigEntry<bool> SnapToPlayer = Config.Define<bool>(true, "Cart", "Snap To Player", true, "When true the cart attaches to the player much more easily.");
internal static readonly ConfigEntry<float> AttachDistance = Config.Define<float>(true, "Cart", "Attach Distance", 7f, Config.AcceptRange<float>(1f, 10f), "Minimum distance the player must be from the cart in order to attach it.");
internal static readonly ConfigEntry<bool> IgnoreUpsideDown = Config.Define<bool>(true, "Cart", "Ignore Upside Down", true, "If true the cart will not prevent attach when upside down.");
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Vagon), "CanAttach")]
private static void Vagon_CanAttach(Vagon __instance, GameObject go, ref bool __result, ref bool __runOriginal)
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
if (Configs.SnapToPlayer.Value)
{
Catapult val = default(Catapult);
if (((Component)__instance).TryGetComponent<Catapult>(ref val) && val.m_lockedLegs)
{
__result = false;
__runOriginal = false;
}
else if (Configs.IgnoreUpsideDown.Value || !(((Component)__instance).transform.up.y < 0.1f))
{
Humanoid component = go.GetComponent<Humanoid>();
bool flag = MathExt.AlignmentRatioTo(((Component)__instance).transform, ((Component)component).transform.position) > 0f;
__result = !Object.op_Implicit((Object)(object)component) || ((flag & !((Character)component).IsTeleporting()) && !((Character)component).InDodge() && !((Character)component).IsBlocking() && !((Character)component).InAttack() && !((Character)component).IsCrouching() && !((Character)component).InEmote() && !((Character)component).IsDrawingBow() && !ZInput.GetButtonDown("JoyButtonB") && MathExt.DistanceTo((MonoBehaviour)(object)component, ((Component)__instance).transform.position) < Configs.AttachDistance.Value);
__runOriginal = false;
}
}
}
}
[HarmonyPatch]
public static class DoorKeys
{
public static class Configs
{
private const string SECTION_DOORKEYS = "DoorKeys";
public static readonly ConfigEntry<bool> SingleUseDoorKeys = Config.Define<bool>(true, "DoorKeys", "Single Use Door Keys", false, "Door keys are spent after a single use. Example: The Swamp Key can only be used once. (Vanilla: false)");
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Door), "Interact")]
private static void Door_Interact(Door __instance, Humanoid character, bool __result)
{
if (Configs.SingleUseDoorKeys.Value && __result && Object.op_Implicit((Object)(object)__instance.m_keyItem) && __instance.HaveKey(character, true))
{
character.GetInventory().RemoveItem(ItemDataExt.GetName(__instance.m_keyItem), 1, -1, true);
((Character)character).ShowRemovedMessage(__instance.m_keyItem.m_itemData, 1);
}
}
}
[HarmonyPatch]
public static class NoCraftNoTeleport
{
internal static class Configs
{
private const string NO_CRAFT = "NoCraft";
public static readonly ConfigEntry<StringList> NoCraftItems = Config.Define<StringList>(true, "NoCraft", "NoCraft Items", StringList.Empty, "List of items to remove from crafting.\nRecipies are removed and new instances of the item can't be crafted.\nHowever, any existing items will still remain. Additionlly any loot drops of the item will still be possible.");
public static readonly ConfigEntry<StringList> NoCraftPieces = Config.Define<StringList>(true, "NoCraft", "NoCraft Pieces", StringList.Empty, "List of pieces which can not be crafted.\nHowever, nocost flag will still allow them to be built. Existing instances of pieces will still remain.");
private const string NO_TELEPORT = "NoTeleport";
public static readonly ConfigEntry<StringList> NoTeleportItems = Config.Define<StringList>(true, "NoTeleport", "NoTeleport Items", StringList.Empty, "List of items which can not be teleported.\nNote, this does not remove items from vanilla's list it only adds to the list of items which can not be teleported.");
}
private static bool _once;
[HarmonyPostfix]
[HarmonyPatch(typeof(Player), "OnSpawned")]
[HarmonyPriority(0)]
private static void Player_OnSpawned()
{
if (!_once)
{
DisableItems();
DisablePieces();
DisableTeleportItems();
_once = true;
}
}
private static void DisableTeleportItems()
{
GameObject val = default(GameObject);
foreach (string item in (List<string>)(object)Configs.NoTeleportItems.Value)
{
if (ObjectDB.instance.TryGetItemPrefab(item, ref val))
{
val.GetComponent<ItemDrop>().m_itemData.m_shared.m_teleportable = false;
Log.Info((object)("NoTeleport Item: " + ((Object)val).name), (ushort)0);
}
}
}
private static void DisableItems()
{
if (((List<string>)(object)Configs.NoCraftItems.Value).Count == 0)
{
return;
}
foreach (Recipe recipe in ObjectDB.instance.m_recipes)
{
string text = ((Object)recipe).name.Replace("Recipe_", "");
if (Configs.NoCraftItems.Value.Contains(text, true))
{
recipe.m_enabled = false;
Log.Info((object)("NoCraft Item: " + text), (ushort)0);
}
}
}
private static void DisablePieces()
{
Piece val = default(Piece);
foreach (string item in (List<string>)(object)Configs.NoCraftPieces.Value)
{
GameObject prefab = ZNetScene.instance.GetPrefab(item);
if (Object.op_Implicit((Object)(object)prefab) && prefab.TryGetComponent<Piece>(ref val))
{
val.m_enabled = false;
Log.Info((object)("NoCraft Piece: " + ((Object)val).name), (ushort)0);
}
}
}
}
[HarmonyPatch]
public static class ShieldGen
{
public static class Configs
{
private const string SECTION_SHIELDGEN = "Shield Generator";
public static readonly ConfigEntry<bool> EnableEjectFuel = Config.Define<bool>(true, "Shield Generator", "Enable Eject Fuel", true, "Add an option to eject the fuel on shield generators and cause them to shutdown.");
public static readonly ConfigEntry<bool> ShieldProtectsFireFromRain = Config.Define<bool>(true, "Shield Generator", "Shield Protects Fire From Rain", true, "Shield Generator protects fireplaces from the rain so they stay lit without a roof. (Vanilla: False)");
}
internal static void Start()
{
ZRoutedRpc.instance.Register<ZDOID>("RPC_EjectShieldFuel", (Action<long, ZDOID>)RPC_EjectShieldFuel);
}
internal static void Shutdown()
{
ZRoutedRpcExt.Unregister(ZRoutedRpc.instance, "RPC_EjectShieldFuel");
}
private static void RPC_EjectShieldFuel(long sender, ZDOID shieldGenID)
{
//IL_0005: 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)
GameObject val = ZNetScene.instance.FindInstance(shieldGenID);
if (!Object.op_Implicit((Object)(object)val))
{
Log.Error((object)$"Shield Generator not found for ZDOID: {shieldGenID}", (ushort)0);
}
else
{
EjectFuel(val.GetComponent<ShieldGenerator>());
}
}
private static GameObject GetFuelPrefab(ShieldGenerator shieldGenerator)
{
return ZNetScene.instance.GetPrefab("BoneFragments");
}
private static void EjectFuel(ShieldGenerator shieldGenerator)
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: 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_00be: Unknown result type (might be due to invalid IL or missing references)
if (shieldGenerator.m_nview.IsOwner())
{
int num = Mathf.CeilToInt(shieldGenerator.GetFuel());
GameObject fuelPrefab = GetFuelPrefab(shieldGenerator);
Transform transform = ((Component)shieldGenerator).transform;
for (int i = 0; i < num; i++)
{
Vector3 val = transform.position + transform.forward + Vector3.up + Random.insideUnitSphere * 0.3f;
Quaternion val2 = Quaternion.Euler(0f, (float)Random.Range(0, 360), 0f);
Object.Instantiate<GameObject>(fuelPrefab, val, val2).GetComponent<ItemDrop>().m_autoPickup = false;
}
shieldGenerator.m_nview.GetZDO().Set(ZDOVars.s_fuel, 0f);
shieldGenerator.m_fuelAddedEffects.Create(transform.position, transform.rotation, transform, 1f, -1);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Switch), "GetHoverText")]
private static void Switch_ShieldGenerator_GetHoverText(Switch __instance, ref string __result)
{
if (Configs.EnableEjectFuel.Value && WardAccessExt.CanAccessWard((MonoBehaviour)(object)__instance, false))
{
ShieldGenerator componentInParent = ((Component)__instance).GetComponentInParent<ShieldGenerator>();
if (Object.op_Implicit((Object)(object)componentInParent) && componentInParent.GetFuel() > 0f)
{
__result += Localization.instance.Localize("\n" + UI.PromptInteractAlt + " $hud_remove $piece_shieldgenerator_fuelname");
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Switch), "Interact")]
private static void Switch_ShieldGenerator_Interact(Switch __instance, bool alt, ref bool __result, ref bool __runOriginal)
{
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
if (!Configs.EnableEjectFuel.Value || !alt)
{
return;
}
if (!WardAccessExt.CanAccessWard((MonoBehaviour)(object)__instance, false))
{
__result = false;
__runOriginal = false;
return;
}
ShieldGenerator componentInParent = ((Component)__instance).GetComponentInParent<ShieldGenerator>();
if (Object.op_Implicit((Object)(object)componentInParent))
{
ZDO zDO = componentInParent.m_nview.GetZDO();
ZRoutedRpc.instance.InvokeRoutedRPC(zDO.GetOwner(), "RPC_EjectShieldFuel", new object[1] { zDO.m_uid });
__runOriginal = false;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Fireplace), "CheckWet")]
private static void Fireplace_CheckWet(Fireplace __instance)
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
if (__instance.m_wet && Configs.ShieldProtectsFireFromRain.Value)
{
__instance.m_wet = !ShieldGenerator.IsInsideShield(((Component)__instance).transform.position);
}
}
}
[HarmonyPatch]
public static class TurretRules
{
public static class Configs
{
private const string SECTION_TURRET = "Turret";
public static readonly ConfigEntry<bool> TargetPlayers;
public static readonly ConfigEntry<bool> TargetTamed;
public static readonly ConfigEntry<int> MaxAmmo;
public static readonly ConfigEntry<int> MaxTargets;
public static readonly ConfigEntry<bool> StackAmmoOnDestroy;
static Configs()
{
TargetPlayers = Config.Define<bool>(true, "Turret", "Target Players", true, "Can turrets target players? (Vanilla: true)\nVanilla behavior is to target players unless a trophy is set.\nIf this is disabled then turrets can be used to be easily cheese boss fights and push into in\nunexplored areas because all the undefeated monsters will be targeted and the player will not.\nPlacing a trophy to limit which creature type the turret attacks is a sensible balance as it\nmakes it a bit more difficult to use the turrets to cheese into unexplored areas since you\nneed to kill the creature once before it can be targeted and the turret can only kill a single type\nof monster, therefor multiple turrets would need to be built in order to defend against multiple types.\nIf this option is false then the turret will always ignore the Player and kill anything else...\nThat will result in an easier run since less turrets would need to be built.");
TargetTamed = Config.Define<bool>(true, "Turret", "Target Tamed", true, "Can turrets target tamed creatures? (Vanilla: true)\nPopulation control...");
MaxAmmo = Config.Define<int>(true, "Turret", "Max Ammo", 40, Config.AcceptRange<int>(1, 100), "Max ammo capacity (Vanilla: 40)");
MaxTargets = Config.Define<int>(true, "Turret", "Max Targets", 3, Config.AcceptRange<int>(1, 10), "Max number of target trophies that can be set at once. (Vanilla: 1)");
StackAmmoOnDestroy = Config.Define<bool>(true, "Turret", "Stack Ammo On Destroy", false, "When the turret dies should the ammo be returned as a stack or as a bunch of individual bolts on the ground?\nCaution: if Max Ammo is high this can kill the framerate as it tries to dump a ton of ammo objects on the ground unstacked. (Vanilla: false)");
}
}
internal static void Start()
{
ZRoutedRpc.instance.Register<ZDOID>("RPC_ResetTurret", (Action<long, ZDOID>)RPC_ResetTurret);
}
internal static void Shutdown()
{
ZRoutedRpcExt.Unregister(ZRoutedRpc.instance, "RPC_ResetTurret");
}
private static bool ClearTrophies(this Turret turret)
{
if (turret.m_targetItems.Count == 0)
{
return false;
}
turret.m_targetItems.Clear();
turret.SetTargets();
return true;
}
private static bool EjectAmmo(this Turret turret)
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: 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_0079: 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_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
if (!turret.HasAmmo())
{
Log.Info((object)"Turret is empty", (ushort)0);
return false;
}
Log.Info((object)"Eject Ammo", (ushort)0);
int ammo = turret.GetAmmo();
string ammoType = turret.GetAmmoType();
GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(ammoType);
Quaternion rotation = turret.m_turretBody.transform.rotation;
Vector3 val = turret.m_eye.transform.position + turret.m_eye.transform.forward * 2f;
Quaternion val2 = rotation * Quaternion.Euler(0f, 180f, 0f);
ItemDrop component = Object.Instantiate<GameObject>(itemPrefab, val, val2).GetComponent<ItemDrop>();
component.SetStack(ammo);
ItemDrop.OnCreateNew(component);
turret.m_addAmmoEffect.Create(turret.m_turretBody.transform.position, rotation, (Transform)null, 1f, -1);
ZDO zDO = turret.m_nview.GetZDO();
if (zDO.IsOwner())
{
zDO.Set(ZDOVars.s_ammo, 0, false);
zDO.Set(ZDOVars.s_ammoType, string.Empty);
}
((Character)Player.m_localPlayer).Message((MessageType)1, "$hud_remove " + ItemDataExt.GetName(component), ammo, ItemDataExt.GetIcon(component));
return true;
}
private static void RPC_ResetTurret(long sender, ZDOID turretID)
{
//IL_0005: 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)
GameObject val = ZNetScene.instance.FindInstance(turretID);
if (!Object.op_Implicit((Object)(object)val))
{
Log.Error((object)$"Turret not found for ZDOID: {turretID}", (ushort)0);
return;
}
Turret component = val.GetComponent<Turret>();
if (component.EjectAmmo() || component.ClearTrophies())
{
((Character)Player.m_localPlayer).Message((MessageType)2, "$menu_modifier_default", 0, (Sprite)null);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Turret), "Awake")]
private static void Turret_Awake(Turret __instance)
{
__instance.m_targetPlayers = Configs.TargetPlayers.Value;
__instance.m_targetTamed = Configs.TargetTamed.Value;
__instance.m_maxAmmo = Configs.MaxAmmo.Value;
__instance.m_maxConfigTargets = Configs.MaxTargets.Value;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Turret), "OnDestroyed")]
private static void Turret_OnDestroyed(Turret __instance, ref bool __runOriginal)
{
if (Configs.StackAmmoOnDestroy.Value)
{
__runOriginal = false;
if (__instance.m_nview.IsOwner() && __instance.m_returnAmmoOnDestroy)
{
__instance.EjectAmmo();
}
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Turret), "Interact")]
private static void Turret_Interact(Turret __instance, bool alt, bool hold, ref bool __result, ref bool __runOriginal)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
if (!WardAccessExt.CanAccessWard((MonoBehaviour)(object)__instance, true))
{
__result = true;
__runOriginal = false;
}
else if (!(!alt || hold))
{
ZDO zDO = __instance.m_nview.GetZDO();
ZRoutedRpc.instance.InvokeRoutedRPC(zDO.GetOwner(), "RPC_ResetTurret", new object[1] { zDO.m_uid });
__runOriginal = false;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Turret), "UseItem")]
private static void Turret_UseItem(Turret __instance, ItemData? item, ref bool __result, ref bool __runOriginal)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Invalid comparison between Unknown and I4
if (item != null && (int)item.m_shared.m_itemType == 13 && !WardAccessExt.CanAccessWard((MonoBehaviour)(object)__instance, true))
{
__runOriginal = false;
__result = true;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Turret), "GetHoverText")]
private static void Turret_GetHoverText(Turret __instance, ref string __result, ref bool __runOriginal)
{
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: 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_0209: Unknown result type (might be due to invalid IL or missing references)
//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
__runOriginal = false;
if (!__instance.m_nview.IsValid())
{
__result = "";
return;
}
if (!__instance.m_targetEnemies)
{
__result = Localization.instance.Localize(__instance.m_name);
return;
}
HudExt.UpdateHoverIcons(Hud.instance, __instance.m_targetItems.Select((ItemDrop item) => ItemDataExt.GetIcon(item)).ToArray());
__instance.sb.Clear();
__instance.sb.Append((!__instance.HasAmmo()) ? (__instance.m_name + " ($piece_turret_noammo)") : $"{__instance.m_name} ({__instance.GetAmmo()}/{__instance.m_maxAmmo})");
if (!WardAccessExt.CanAccessWard((MonoBehaviour)(object)__instance, false))
{
__instance.sb.Append("\n$piece_noaccess");
}
else
{
__instance.sb.Append("\n" + UI.PromptInteract + " $piece_turret_addammo");
if (__instance.HasAmmo() || __instance.m_targetItems.Count > 0)
{
__instance.sb.Append("\n" + UI.PromptInteractAlt + " $settings_resetcontrols");
}
__instance.sb.Append("\n" + UI.PromptUseItem + " $piece_turret_target_set");
if (Configs.MaxTargets.Value > 1)
{
__instance.sb.Append($" ({__instance.m_targetItems.Count}/{Configs.MaxTargets.Value})");
}
}
__instance.sb.Append("\n");
__instance.sb.Append($"<color={UIColor.Gray}>$piece_turret_target ");
if (__instance.m_targetCharacters.Count == 0)
{
ZColor val = ((Configs.TargetPlayers.Value || Configs.TargetTamed.Value) ? UIColor.MajorInfo : UIColor.Teal);
__instance.sb.Append($"<color={val}>");
__instance.sb.Append(StringExtensions.CapitalizeFirstLetter(StringExt.Localize("$piece_turret_target_everything")));
__instance.sb.Append("</color>");
}
else
{
__instance.sb.Append(__instance.m_targetsText);
}
__instance.sb.Append("</color>");
__result = Localization.instance.Localize(__instance.sb.ToString());
}
[HarmonyPostfix]
[HarmonyPatch(typeof(Localization), "Localize", new Type[] { typeof(string) })]
private static void Localization_Localize(Localization __instance, string text, ref string __result)
{
if (text == "$msg_turretotherammo")
{
__result += " ";
}
}
}
[HarmonyPatch]
public static class Environment
{
public static class Configs
{
private const string SECTION_ENVIRONMENT = "Environment";
public static readonly ConfigEntry<bool> ShowSkyTree;
public static readonly ConfigEntry<bool> ShowWindPixels;
public static readonly ConfigEntry<int> DayLengthSeconds;
public static readonly ConfigEntry<bool> ShowDayNumber;
static Configs()
{
ShowSkyTree = Config.Define<bool>(true, "Environment", "Show Sky Tree", false, "Navigate with only the sun and stars.");
ShowWindPixels = Config.Define<bool>(true, "Environment", "Show Wind Pixels", false, "Enable the chunky wind pixels");
DayLengthSeconds = Config.Define<int>(true, "Environment", "Day Length Seconds", 0, Config.AcceptRange<int>(0, 10800), "Length of an in game day in seconds. (Vanilla: 1800)\r\nSet to 0 to disable this setting.");
ShowDayNumber = Config.Define<bool>(true, "Environment", "Show Day Number", false, "Display the day number each morning. (Vanilla: true)");
ShowSkyTree.SettingChanged += delegate
{
SetSkyTree();
};
ShowWindPixels.SettingChanged += delegate
{
SetWindPixels();
};
DayLengthSeconds.SettingChanged += delegate
{
SetDayLength();
};
}
}
private static bool IsMainScene
{
get
{
//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)
Scene activeScene = SceneManager.GetActiveScene();
return ((Scene)(ref activeScene)).name == "main";
}
}
internal static void Init()
{
SetDayLength();
SetSkyTree();
SetWindPixels();
}
private static void SetSkyTree()
{
if (IsMainScene)
{
GameObject.Find("_GameMain/_Environment/YggdrasilBranch").SetActive(Configs.ShowSkyTree.Value);
}
}
private static void SetWindPixels()
{
if (IsMainScene)
{
GameObject.Find("_GameMain/_Environment/FollowPlayer/GlobalWindParticles/particles_pixel").SetActive(Configs.ShowWindPixels.Value);
}
}
private static void SetDayLength()
{
if (IsMainScene)
{
EnvMan instance = EnvMan.instance;
if (Configs.DayLengthSeconds.Value > 0)
{
instance.m_dayLengthSec = Configs.DayLengthSeconds.Value;
}
Log.Message((object)$"Day Length: {instance.m_dayLengthSec} seconds", (ushort)0);
}
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(EnvMan), "OnMorning")]
private static IEnumerable<CodeInstruction> EnvMan_OnMorning_Transpile(IEnumerable<CodeInstruction> codes)
{
MethodInfo methodInfo = AccessTools.Method(typeof(Character), "Message", (Type[])null, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(Environment), "MorningMessageIntercept", (Type[])null, (Type[])null);
return Transpilers.MethodReplacer(codes, (MethodBase)methodInfo, (MethodBase)methodInfo2);
}
private static void MorningMessageIntercept(Character p, MessageType type, string msg, int amount, Sprite sprite)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
if (Configs.ShowDayNumber.Value)
{
p.Message(type, msg, amount, sprite);
}
else
{
Log.Message((object)("Morning message suppressed: " + msg), (ushort)0);
}
}
}
}