using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AwesomeTechnologies.VegetationSystem;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Fusion;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using SSSGame;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AskaPlantGrass")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.2")]
[assembly: AssemblyInformationalVersion("0.2.2+0f510b939832cc886f63e65129ebe2d0ac495506")]
[assembly: AssemblyProduct("Aska Plant Grass")]
[assembly: AssemblyTitle("AskaPlantGrass")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 AskaPlantGrass
{
[HarmonyPatch(typeof(Character))]
public static class CharacterSpawnPatch
{
[HarmonyPostfix]
[HarmonyPatch("Spawned")]
public static void Spawned(Character __instance)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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_0057: 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)
if (__instance.IsPlayer() && ((NetworkBehaviour)__instance).GetLocalAuthorityMask() == 1 && !((Object)(object)((Component)__instance).GetComponentInChildren<PlantGrassTool>() != (Object)null))
{
GameObject val = new GameObject("AskaPlantGrass_Tool");
val.transform.SetParent(((Component)__instance).gameObject.transform, false);
val.transform.localPosition = new Vector3(0f, 0f, 2f);
val.AddComponent<HeightmapTool>();
val.AddComponent<PlantGrassTool>();
Plugin.Log.LogInfo((object)"PlantGrassTool attached to local player.");
}
}
}
public class PlantGrassTool : MonoBehaviour
{
private const float RadiusMeters = 1f;
private HeightmapTool _heightmapTool;
private void Start()
{
_heightmapTool = ((Component)this).GetComponent<HeightmapTool>();
if ((Object)(object)_heightmapTool == (Object)null)
{
Plugin.Log.LogError((object)"PlantGrassTool: HeightmapTool component missing!");
}
}
private void Update()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Expected O, but got Unknown
//IL_0060: 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_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Expected O, but got Unknown
//IL_00d0: 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)
if ((Object)(object)_heightmapTool == (Object)null || !Plugin.ConfigEnabled.Value || !Input.GetKeyDown(Plugin.ConfigKey.Value))
{
return;
}
Vector3 position = ((Component)this).transform.position;
if (BlockedByBuilding(position))
{
return;
}
bool flag = default(bool);
if (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303))
{
Paint(position, (TerrainType)0, clearVegetation: true);
Paint(position, (TerrainType)1, clearVegetation: true);
ManualLogSource log = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(14, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Lawn laid at ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Vector3>(position);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
}
log.LogInfo(val);
}
else
{
Paint(position, (TerrainType)1, clearVegetation: false);
ManualLogSource log2 = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(19, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Grass restored at ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Vector3>(position);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
}
log2.LogInfo(val);
}
}
private bool BlockedByBuilding(Vector3 position)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
//IL_0063: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
bool flag = default(bool);
foreach (Collider item in (Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(position, 1f))
{
if (!((Component)item).CompareTag(Structure.c_FootprintTag))
{
continue;
}
Structure componentInParent = ((Component)item).GetComponentInParent<Structure>();
if ((Object)(object)componentInParent != (Object)null)
{
ManualLogSource log = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(73, 5, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Skipped at ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Vector3>(position);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": blocked by structure '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(componentInParent.GetName());
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' ");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("(footprint collider '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)((Component)item).gameObject).name);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' at ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Vector3>(((Component)item).transform.position);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(Vector3.Distance(position, ((Component)item).transform.position), "F2");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("m away).");
}
log.LogInfo(val);
return true;
}
}
return false;
}
private void Paint(Vector3 position, TerrainType sourceType, bool clearVegetation)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: 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)
_heightmapTool.radius = 1f;
_heightmapTool.clearVegetation = clearVegetation;
_heightmapTool.setTerrainType = true;
_heightmapTool.terrainType = (TerrainType)0;
_heightmapTool.requiresTerrainType = true;
_heightmapTool.requiredTerrainType = sourceType;
_heightmapTool.biasTerraformingWeights = true;
_heightmapTool.setBiomeType = Plugin.ConfigPaintBiome.Value;
_heightmapTool.biomeType = (BiomeType)0;
_heightmapTool.Run((TerraformingToolOperation)3, position);
_heightmapTool.PaintHere();
}
}
[BepInPlugin("smithio.aska.plantgrass", "Aska Plant Grass", "0.2.2")]
public class Plugin : BasePlugin
{
public const string PluginGuid = "smithio.aska.plantgrass";
public const string PluginName = "Aska Plant Grass";
public const string PluginVersion = "0.2.2";
internal static ManualLogSource Log;
internal static ConfigEntry<bool> ConfigEnabled;
internal static ConfigEntry<KeyCode> ConfigKey;
internal static ConfigEntry<bool> ConfigPaintBiome;
internal static readonly bool DebugLogging;
public override void Load()
{
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
ConfigEnabled = ((BasePlugin)this).Config.Bind<bool>("PlantGrass", "Enabled", true, "Master on/off switch for the tool.");
ConfigKey = ((BasePlugin)this).Config.Bind<KeyCode>("PlantGrass", "Key", (KeyCode)93, "Key that paints grass at your feet. Press alone to restore grass; hold Shift to lay a mowed lawn (grass with the 3D blades removed).");
ConfigPaintBiome = ((BasePlugin)this).Config.Bind<bool>("PlantGrass", "PaintGrassBiome", true, "Also mark the painted spot as grassland biome so grass reliably appears even in rocky areas (the same trick the game's sapling planting uses). Turn off to only repaint the surface - naturally rocky ground may then stay rocky.");
ClassInjector.RegisterTypeInIl2Cpp<PlantGrassTool>();
Harmony.CreateAndPatchAll(typeof(CharacterSpawnPatch), (string)null);
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Aska Plant Grass");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" v");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.2.2");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
}
log.LogInfo(val);
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "AskaPlantGrass";
public const string PLUGIN_NAME = "Aska Plant Grass";
public const string PLUGIN_VERSION = "0.2.2";
}
}