using System;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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: AssemblyTitle("OutwardModTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModTemplate")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace EnchantingVisualizer;
[BepInPlugin("johbenji.enchantingvisualizer", "Enchanting Visualizer", "1.0.0")]
public class EnchantingVisualizerPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(EnchantmentTable), "StartInit")]
public class EnchantmentTable_StartInit_Patch
{
private static void Postfix(EnchantmentTable __instance)
{
GameObject gameObject = ((Component)__instance).gameObject;
if ((Object)(object)gameObject != (Object)null)
{
Instance.AddDecoration(gameObject, __instance);
}
else
{
Log.LogWarning((object)"Main GameObject of Enchanting Table instance not found in StartInit!");
}
}
}
public const string GUID = "johbenji.enchantingvisualizer";
public const string NAME = "Enchanting Visualizer";
public const string VERSION = "1.0.0";
internal static ManualLogSource Log;
public static ConfigEntry<bool> ExampleConfig;
private static readonly Color[] CardinalColors = (Color[])(object)new Color[4]
{
new Color(1f, 1f, 1f, 1f),
new Color(1f, 1f, 1f, 1f),
new Color(0.9f, 0.2f, 0.85f, 1f),
new Color(0.2f, 0.6f, 1f, 1f)
};
private const float NearAlpha = 0.1f;
private const float FarAlpha = 0.03f;
private const int SegmentsPerSector = 12;
private Material _cachedTransparentMaterial;
public static EnchantingVisualizerPlugin Instance { get; private set; }
internal void Awake()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
ExampleConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Sector", "Activate Help Sectors", false, "Shows the sectors where the pillars can be placed.");
new Harmony("johbenji.enchantingvisualizer").PatchAll();
}
private GameObject GetFX()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(5000301);
Transform itemVisual = itemPrefab.GetItemVisual();
if ((Object)(object)itemVisual != (Object)null)
{
foreach (Transform item in itemVisual)
{
Transform val = item;
if (((Object)val).name == "FX")
{
return ((Component)val).gameObject;
}
}
Log.LogWarning((object)"Could not find child named 'FX' in GhostDrums prefab");
}
else
{
Log.LogWarning((object)"Could not find GhostDrums prefab for FX");
}
return null;
}
public void AddDecoration(GameObject mainObject, EnchantmentTable table)
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: 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_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_026c: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_029f: Unknown result type (might be due to invalid IL or missing references)
//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0304: Unknown result type (might be due to invalid IL or missing references)
//IL_0325: Unknown result type (might be due to invalid IL or missing references)
//IL_0385: Unknown result type (might be due to invalid IL or missing references)
//IL_038c: Expected O, but got Unknown
//IL_0444: Unknown result type (might be due to invalid IL or missing references)
//IL_0480: Unknown result type (might be due to invalid IL or missing references)
//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)mainObject == (Object)null)
{
Log.LogWarning((object)"AddDecoration called with null mainObject");
return;
}
if ((Object)(object)table == (Object)null)
{
Log.LogWarning((object)"AddDecoration called with null EnchantmentTable");
return;
}
GameObject val = new GameObject("Decorations");
val.transform.SetParent(mainObject.transform, false);
val.transform.localPosition = new Vector3(0f, 0.03f, 0f);
if (ExampleConfig.Value)
{
float num = table.PillarMinRange + (table.PillarDetectionRange - table.PillarMinRange) * 0.5f;
(int, float, float)[] array = new(int, float, float)[4]
{
(0, -45f, 45f),
(2, 45f, 135f),
(1, 135f, 225f),
(3, 225f, 315f)
};
(int, float, float)[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
(int, float, float) tuple = array2[i];
CreateRegion(val.transform, tuple.Item1, 0, tuple.Item2, tuple.Item3, table.PillarMinRange, num, 0.1f);
CreateRegion(val.transform, tuple.Item1, 1, tuple.Item2, tuple.Item3, num, table.PillarDetectionRange, 0.03f);
}
}
GameObject fX = GetFX();
if ((Object)(object)fX != (Object)null)
{
GameObject val2 = Object.Instantiate<GameObject>(fX, val.transform, true);
((Object)val2).name = "FXFar";
val2.transform.localPosition = new Vector3(0f, -0.8f, 0f);
val2.transform.localRotation = Quaternion.identity;
val2.transform.localScale = new Vector3(1.22f, 1f, 1.22f);
}
GameObject fX2 = GetFX();
if ((Object)(object)fX2 != (Object)null)
{
GameObject val3 = Object.Instantiate<GameObject>(fX2, val.transform, true);
((Object)val3).name = "FXNear";
val3.transform.localPosition = new Vector3(0f, -0.8f, 0f);
val3.transform.localRotation = Quaternion.identity;
val3.transform.localScale = new Vector3(0.64f, 1f, 0.64f);
}
GameObject fX3 = GetFX();
if ((Object)(object)fX3 != (Object)null)
{
GameObject val4 = Object.Instantiate<GameObject>(fX3, val.transform, true);
((Object)val4).name = "FXTooClose";
val4.transform.localPosition = new Vector3(0f, -0.8f, 0f);
val4.transform.localRotation = Quaternion.identity;
val4.transform.localScale = new Vector3(0.08f, 0.75f, 0.08f);
}
else if ((Object)(object)fX == (Object)null || (Object)(object)fX2 == (Object)null || (Object)(object)fX3 == (Object)null)
{
Log.LogWarning((object)"FXCopies are null, cannot instantiate VFX");
return;
}
foreach (Transform item in val.transform)
{
Transform val5 = item;
if (!(((Object)val5).name == "FXFar") && !(((Object)val5).name == "FXNear") && !(((Object)val5).name == "FXTooClose"))
{
continue;
}
ParticleSystemRenderer component = ((Component)val5).GetComponent<ParticleSystemRenderer>();
if (!((Object)(object)component != (Object)null))
{
continue;
}
Material val6 = (((Renderer)component).sharedMaterial = Object.Instantiate<Material>(((Renderer)component).sharedMaterial));
if ((Object)(object)val6 != (Object)null)
{
if (((Object)val5).name == "FXFar")
{
val6.color = new Color(3f, 2f, 2f, 1f);
}
else if (((Object)val5).name == "FXNear")
{
val6.color = new Color(0f, 3.5f, 1f, 1f);
}
else if (((Object)val5).name == "FXTooClose")
{
val6.color = new Color(1.6f, 3.1f, 0.7f, 1f);
}
}
}
}
private void CreateRegion(Transform parent, int cardinalIndex, int distanceIndex, float startAngle, float endAngle, float innerRadius, float outerRadius, float alpha)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
//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_0039: 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_0045: 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)
GameObject val = new GameObject($"Region_Cardinal{cardinalIndex}_Distance{distanceIndex}");
val.transform.SetParent(parent, false);
Color val2 = CardinalColors[cardinalIndex];
Color color = default(Color);
((Color)(ref color))..ctor(val2.r, val2.g, val2.b, alpha);
Mesh mesh = BuildSectorMesh(startAngle, endAngle, innerRadius, outerRadius, color, 12);
MeshFilter val3 = val.AddComponent<MeshFilter>();
val3.mesh = mesh;
MeshRenderer val4 = val.AddComponent<MeshRenderer>();
((Renderer)val4).sharedMaterial = GetTransparentVertexColorMaterial();
((Renderer)val4).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)val4).receiveShadows = false;
}
private Mesh BuildSectorMesh(float startAngle, float endAngle, float innerRadius, float outerRadius, Color color, int segments)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Expected O, but got Unknown
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: 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_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
Mesh val = new Mesh
{
name = "SectorMesh"
};
int num = (segments + 1) * 2;
Vector3[] array = (Vector3[])(object)new Vector3[num];
Color[] array2 = (Color[])(object)new Color[num];
int[] array3 = new int[segments * 6];
float num2 = (endAngle - startAngle) / (float)segments;
Vector3 val2 = default(Vector3);
for (int i = 0; i <= segments; i++)
{
float num3 = startAngle + num2 * (float)i;
float num4 = num3 * ((float)Math.PI / 180f);
((Vector3)(ref val2))..ctor(Mathf.Sin(num4), 0f, Mathf.Cos(num4));
int num5 = i * 2;
int num6 = i * 2 + 1;
array[num5] = val2 * innerRadius;
array[num6] = val2 * outerRadius;
array2[num5] = color;
array2[num6] = color;
if (i < segments)
{
int num7 = i * 6;
array3[num7] = num5;
array3[num7 + 1] = num6;
array3[num7 + 2] = num5 + 2;
array3[num7 + 3] = num6;
array3[num7 + 4] = num6 + 2;
array3[num7 + 5] = num5 + 2;
}
}
val.vertices = array;
val.colors = array2;
val.triangles = array3;
val.RecalculateNormals();
val.RecalculateBounds();
return val;
}
private Material GetTransparentVertexColorMaterial()
{
//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_0033: Expected O, but got Unknown
if ((Object)(object)_cachedTransparentMaterial == (Object)null)
{
_cachedTransparentMaterial = new Material(Shader.Find("Sprites/Default"))
{
name = "DecorationVertexColorMaterial"
};
}
return _cachedTransparentMaterial;
}
}