using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+84ecdf67601019596bca6ee59e7c1b3bb50936f4")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GrassTweaks;
[BepInPlugin("aedenthorn.GrassTweaks", "Grass Tweaks", "0.4.0")]
public class BepInExPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(ClutterSystem), "Awake")]
private static class ClutterSystem_Awake_Patch
{
private static void Prefix(ClutterSystem __instance)
{
if (modEnabled.Value)
{
__instance.m_amountScale *= amountMult.Value;
__instance.m_distance = clutterDistance.Value;
__instance.m_grassPatchSize = grassPatchSize.Value;
__instance.m_playerPushFade = playerPushFade.Value;
for (int i = 0; i < __instance.m_clutter.Count; i++)
{
Clutter obj = __instance.m_clutter[i];
obj.m_scaleMin *= scaleMinMult.Value;
Clutter obj2 = __instance.m_clutter[i];
obj2.m_scaleMax *= scaleMaxMult.Value;
}
}
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
private static class MonoBehaviour_Patch
{
private static void Postfix(MonoBehaviour __instance)
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
if (modEnabled.Value && __instance is InstanceRenderer)
{
InstanceRenderer val = (InstanceRenderer)(object)((__instance is InstanceRenderer) ? __instance : null);
val.m_lodMinDistance *= lodMinDistanceMult.Value;
val.m_lodMaxDistance *= lodMaxDistanceMult.Value;
val.m_shadowCasting = shadowCastingMode.Value;
val.m_useLod = useLod.Value;
val.m_useXZLodDistance = useXZLodDistance.Value;
}
}
}
[HarmonyPatch(typeof(Terminal), "InputText")]
private static class InputText_Patch
{
private static bool Prefix(Terminal __instance)
{
if (!modEnabled.Value)
{
return true;
}
string text = ((TMP_InputField)__instance.m_input).text;
if (text.ToLower().Equals("grasstweaks reset"))
{
ClutterSystem instance = ClutterSystem.instance;
instance.m_amountScale /= amountMult.Value;
for (int i = 0; i < ClutterSystem.instance.m_clutter.Count; i++)
{
Clutter obj = ClutterSystem.instance.m_clutter[i];
obj.m_scaleMin /= scaleMinMult.Value;
Clutter obj2 = ClutterSystem.instance.m_clutter[i];
obj2.m_scaleMax /= scaleMaxMult.Value;
}
((BaseUnityPlugin)context).Config.Reload();
((BaseUnityPlugin)context).Config.Save();
ClutterSystem instance2 = ClutterSystem.instance;
instance2.m_amountScale *= amountMult.Value;
for (int j = 0; j < ClutterSystem.instance.m_clutter.Count; j++)
{
Clutter obj3 = ClutterSystem.instance.m_clutter[j];
obj3.m_scaleMin *= scaleMinMult.Value;
Clutter obj4 = ClutterSystem.instance.m_clutter[j];
obj4.m_scaleMax *= scaleMaxMult.Value;
}
ClutterSystem.instance.m_distance = clutterDistance.Value;
ClutterSystem.instance.m_grassPatchSize = grassPatchSize.Value;
ClutterSystem.instance.m_playerPushFade = playerPushFade.Value;
Traverse.Create((object)__instance).Method("AddString", new object[1] { text }).GetValue();
Traverse.Create((object)__instance).Method("AddString", new object[1] { "Grass Tweaks config reloaded" }).GetValue();
return false;
}
return true;
}
}
private static readonly bool isDebug = true;
private static BepInExPlugin context;
public static ConfigEntry<bool> modEnabled;
public static ConfigEntry<int> nexusID;
public static ConfigEntry<bool> useLod;
public static ConfigEntry<bool> useXZLodDistance;
private static ConfigEntry<float> lodMinDistanceMult;
private static ConfigEntry<float> lodMaxDistanceMult;
private static ConfigEntry<float> scaleMinMult;
private static ConfigEntry<float> scaleMaxMult;
private static ConfigEntry<float> amountMult;
private static ConfigEntry<float> clutterDistance;
private static ConfigEntry<float> grassPatchSize;
private static ConfigEntry<float> playerPushFade;
private static ConfigEntry<ShadowCastingMode> shadowCastingMode;
public static void Dbgl(string str = "", bool pref = true)
{
if (isDebug)
{
Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
}
}
private void Awake()
{
context = this;
modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 306, "Nexus mod ID for updates");
useLod = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "UseLod", true, "Use LOD");
useXZLodDistance = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "UseXZLodDistance", true, "Use XZ LOD Distance");
lodMinDistanceMult = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "LodMinDistanceMult", 1f, "Min LOD distance multiplier");
lodMaxDistanceMult = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "LodMaxDistanceMult", 1f, "Max LOD distance multiplier");
scaleMinMult = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "ScaleMinMult", 1f, "Clutter scale minimum multiplier");
scaleMaxMult = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "ScaleMaxMult", 1f, "Clutter scale maximum multiplier");
amountMult = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "AmountMult", 1f, "Clutter amount multiplier");
clutterDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "ClutterDistance", 40f, "Clutter distance");
grassPatchSize = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "GrassPatchSize", 8f, "Grass patch size");
playerPushFade = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "PlayerPushFade", 0.05f, "Player push fade");
shadowCastingMode = ((BaseUnityPlugin)this).Config.Bind<ShadowCastingMode>("Settings", "ShadowCastingMode", (ShadowCastingMode)1, "Shadow Casting Mode");
if (modEnabled.Value)
{
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
}
}
}