using System;
using System.Collections.Generic;
using System.Diagnostics;
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.Logging;
using HarmonyLib;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("VentureValheim.PathsideAssistance")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VentureValheim.PathsideAssistance")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("FC0132A3-175E-41F5-9E4D-7E9C74401203")]
[assembly: AssemblyFileVersion("0.2.3")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.3.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 VentureValheim.PathsideAssistance
{
[BepInPlugin("com.orianaventure.mod.PathsideAssistance", "PathsideAssistance", "0.2.3")]
public class PathsideAssistancePlugin : BaseUnityPlugin
{
private const string ModName = "PathsideAssistance";
private const string ModVersion = "0.2.3";
private const string Author = "com.orianaventure.mod";
private const string ModGUID = "com.orianaventure.mod.PathsideAssistance";
private readonly Harmony HarmonyInstance = new Harmony("com.orianaventure.mod.PathsideAssistance");
public static readonly ManualLogSource PathsideAssistanceLogger = Logger.CreateLogSource("PathsideAssistance");
public static GameObject Root;
public void Awake()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
PathsideAssistanceLogger.LogInfo((object)"Thank you for your call, help is on the way.");
Root = new GameObject("PathsideRoot");
Root.SetActive(false);
Object.DontDestroyOnLoad((Object)(object)Root);
Assembly executingAssembly = Assembly.GetExecutingAssembly();
HarmonyInstance.PatchAll(executingAssembly);
}
}
public class IconMerge
{
private static readonly IconMerge _instance;
private static AssetBundle _iconBundle;
private static Sprite _overlay;
public static IconMerge Instance => _instance;
static IconMerge()
{
_instance = new IconMerge();
_iconBundle = null;
_overlay = null;
}
private IconMerge()
{
}
private static Texture2D DuplicateTexture(Sprite sprite)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: 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_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Expected O, but got Unknown
if ((Object)(object)sprite == (Object)null)
{
return null;
}
Rect textureRect = sprite.textureRect;
int num = (int)((Rect)(ref textureRect)).width;
textureRect = sprite.textureRect;
int num2 = (int)((Rect)(ref textureRect)).height;
textureRect = sprite.textureRect;
int num3 = (int)((Rect)(ref textureRect)).x;
textureRect = sprite.textureRect;
int num4 = (int)((Rect)(ref textureRect)).y;
RenderTexture active = RenderTexture.active;
RenderTexture temporary = RenderTexture.GetTemporary(((Texture)sprite.texture).width, ((Texture)sprite.texture).height, 0, (RenderTextureFormat)7, (RenderTextureReadWrite)2);
Graphics.Blit((Texture)(object)sprite.texture, temporary);
RenderTexture.active = temporary;
Texture2D val = new Texture2D(num, num2);
val.ReadPixels(new Rect((float)num3, (float)num4, (float)num, (float)num2), 0, 0);
val.Apply();
RenderTexture.active = active;
RenderTexture.ReleaseTemporary(temporary);
return val;
}
private static Sprite MergeTextures(string name, Texture2D baseTexture, Texture2D overlayTexture)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: 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_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: 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_0070: Unknown result type (might be due to invalid IL or missing references)
int width = ((Texture)baseTexture).width;
int height = ((Texture)baseTexture).height;
Texture2D val = new Texture2D(width, height);
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
val.SetPixel(i, j, Color.clear);
Color pixel = overlayTexture.GetPixel(i, j);
if (pixel.a != 0f)
{
val.SetPixel(i, j, pixel);
continue;
}
Color pixel2 = baseTexture.GetPixel(i, j);
if (pixel2.a != 0f)
{
val.SetPixel(i, j, pixel2);
}
}
}
val.Apply();
Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)width, (float)height), new Vector2(0.5f, 0.5f));
((Object)obj).name = name;
return obj;
}
public static void AddSpriteOverlay(ref GameObject item)
{
if ((Object)(object)_iconBundle == (Object)null)
{
try
{
_iconBundle = AssetUtils.LoadAssetBundleFromResources("pathside_icon", Assembly.GetExecutingAssembly());
_overlay = _iconBundle.LoadAsset<Sprite>("VV_PA_Icon");
}
catch (Exception ex)
{
PathsideAssistancePlugin.PathsideAssistanceLogger.LogError((object)"Exception Caught! This mod might not behave as expected.");
PathsideAssistancePlugin.PathsideAssistanceLogger.LogInfo((object)ex);
return;
}
}
if (!((Object)(object)_overlay == (Object)null))
{
Piece component = item.GetComponent<Piece>();
if ((Object)(object)component != (Object)null && (Object)(object)component.m_icon != (Object)null)
{
Sprite icon = component.m_icon;
Sprite icon2 = MergeTextures(baseTexture: (Texture2D)((!((Texture)icon.texture).isReadable) ? ((object)DuplicateTexture(icon)) : ((object)icon.texture)), name: "VV_PA_" + ((Object)item).name, overlayTexture: _overlay.texture);
component.m_icon = icon2;
}
}
}
}
public class PathsideAssistance
{
[HarmonyPatch(typeof(ObjectDB), "Awake")]
public static class Patch_ObjectDB_Awake
{
[HarmonyPriority(200)]
private static void Postfix(ObjectDB __instance)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
if (!Configured)
{
Scene activeScene = SceneManager.GetActiveScene();
if (((Scene)(ref activeScene)).name.Equals("main"))
{
UpdatePieceTable(__instance.GetItemPrefab(StringExtensionMethods.GetStableHashCode("Hoe")));
UpdatePieceTable(__instance.GetItemPrefab(StringExtensionMethods.GetStableHashCode("Cultivator")));
PathsideAssistancePlugin.PathsideAssistanceLogger.LogInfo((object)"Done adding additional options.");
Configured = true;
}
}
}
}
private static readonly PathsideAssistance _instance;
private static bool Configured;
public static PathsideAssistance Instance => _instance;
static PathsideAssistance()
{
_instance = new PathsideAssistance();
Configured = false;
}
private PathsideAssistance()
{
}
private static void UpdatePieceTable(GameObject piece)
{
if (!((Object)(object)piece != (Object)null))
{
return;
}
ItemDrop component = piece.GetComponent<ItemDrop>();
if (!((Object)(object)component != (Object)null))
{
return;
}
PieceTable buildPieces = component.m_itemData.m_shared.m_buildPieces;
if (!((Object)(object)buildPieces != (Object)null))
{
return;
}
List<GameObject> list = new List<GameObject>();
foreach (GameObject piece2 in buildPieces.m_pieces)
{
list.Add(piece2);
GameObject item = GetPaintOnlyCopy(piece2);
if ((Object)(object)item != (Object)null)
{
IconMerge.AddSpriteOverlay(ref item);
list.Add(item);
}
}
component.m_itemData.m_shared.m_buildPieces.m_pieces = list;
}
private static GameObject GetPaintOnlyCopy(GameObject piece)
{
if ((Object)(object)piece.GetComponent<TerrainOp>() != (Object)null)
{
GameObject val = Object.Instantiate<GameObject>(piece, PathsideAssistancePlugin.Root.transform, false);
((Object)val).name = Utils.GetPrefabName(val) + "_ALT";
Piece component = val.GetComponent<Piece>();
if ((Object)(object)component != (Object)null)
{
component.m_name = Localization.instance.Localize(component.m_name ?? "") + " ALT";
}
TerrainOp component2 = val.GetComponent<TerrainOp>();
if (!component2.m_settings.m_raise && (component2.m_settings.m_level || component2.m_settings.m_smooth))
{
component2.m_settings.m_raise = false;
component2.m_settings.m_level = false;
component2.m_settings.m_smooth = false;
}
else
{
Settings settings = component2.m_settings;
settings.m_raiseRadius *= 2f;
Settings settings2 = component2.m_settings;
settings2.m_levelRadius *= 2f;
Settings settings3 = component2.m_settings;
settings3.m_smoothRadius *= 2f;
Settings settings4 = component2.m_settings;
settings4.m_paintRadius *= 2f;
if (component.m_resources != null)
{
for (int i = 0; i < component.m_resources.Length; i++)
{
Requirement obj = component.m_resources[i];
obj.m_amount *= 4;
}
}
}
return val;
}
return null;
}
}
}