using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Interaction;
using Il2CppSLZ.Marrow.Pool;
using Il2CppSLZ.Marrow.PuppetMasta;
using Il2CppSLZ.Marrow.Warehouse;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using WritingSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(WritingMod), "WritingSystem", "1.0.0", "erive", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("WritingSystem")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WritingSystem")]
[assembly: AssemblyTitle("WritingSystem")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 WritingSystem
{
public enum ItemKind
{
Gun,
Melee,
Mag
}
public class LiveItem
{
public Transform Root;
public int RootId;
public string Barcode;
public string Title;
public ItemKind Kind;
public bool SavedChecked;
public readonly List<Stroke> Strokes = new List<Stroke>();
public bool IsAlive => (Object)(object)Root != (Object)null;
public void ClearStrokes()
{
for (int i = 0; i < Strokes.Count; i++)
{
Strokes[i].Destroy();
}
Strokes.Clear();
}
}
internal static class ItemResolver
{
public static bool TryResolve(GameObject go, out Transform root, out ItemKind kind)
{
root = null;
kind = ItemKind.Melee;
if ((Object)(object)go == (Object)null)
{
return false;
}
Transform transform = go.transform;
if (IsPlayer(transform))
{
return false;
}
Poolee componentInParent = ((Component)transform).GetComponentInParent<Poolee>();
if ((Object)(object)componentInParent != (Object)null)
{
root = ((Component)componentInParent).transform;
}
else
{
MarrowEntity componentInParent2 = ((Component)transform).GetComponentInParent<MarrowEntity>();
if ((Object)(object)componentInParent2 == (Object)null)
{
return false;
}
root = ((Component)componentInParent2).transform;
}
if (IsPlayer(root))
{
return false;
}
if ((Object)(object)((Component)root).GetComponentInChildren<Gun>() != (Object)null)
{
kind = ItemKind.Gun;
return true;
}
if ((Object)(object)((Component)root).GetComponentInChildren<Magazine>() != (Object)null)
{
kind = ItemKind.Mag;
return true;
}
if ((Object)(object)((Component)root).GetComponentInChildren<PuppetMaster>() != (Object)null)
{
return false;
}
if ((Object)(object)((Component)root).GetComponentInChildren<InteractableHost>() != (Object)null)
{
kind = ItemKind.Melee;
return true;
}
return false;
}
public static void Describe(Transform root, out string barcode, out string title)
{
barcode = null;
title = (((Object)(object)root != (Object)null) ? CleanName(((Object)root).name) : "Item");
if ((Object)(object)root == (Object)null)
{
return;
}
Poolee val = ((Component)root).GetComponent<Poolee>();
if ((Object)(object)val == (Object)null)
{
val = ((Component)root).GetComponentInParent<Poolee>();
}
if (!((Object)(object)val == (Object)null) && !((Object)(object)val.SpawnableCrate == (Object)null))
{
SpawnableCrate spawnableCrate = val.SpawnableCrate;
if (((Scannable)spawnableCrate).Barcode != (Barcode)null)
{
barcode = ((Scannable)spawnableCrate).Barcode.ID;
}
if (!string.IsNullOrEmpty(((Scannable)spawnableCrate).Title))
{
title = ((Scannable)spawnableCrate).Title;
}
}
}
private static string CleanName(string name)
{
int num = name.IndexOf(" [");
if (num > 0)
{
name = name.Substring(0, num);
}
return name.Replace("(Clone)", "").Trim();
}
private static bool IsPlayer(Transform t)
{
RigManager rigManager = Player.RigManager;
if ((Object)(object)rigManager != (Object)null)
{
return t.IsChildOf(((Component)rigManager).transform);
}
return false;
}
}
internal static class InkMaterials
{
public enum Style
{
Marker,
NeonCore,
NeonGlow,
Laser
}
private const float NeonIntensity = 4f;
private const float GlowIntensity = 1.6f;
private const float MarkerSmoothness = 0.35f;
private static Shader _unlit;
private static Shader _lit;
private static bool _litSearched;
private static Texture2D _markerTexture;
private static readonly Dictionary<int, Material> _cache = new Dictionary<int, Material>();
public static Material Get(Color color, Style style = Style.Marker)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: 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)
int key = ((int)style << 24) | ((int)(color.r * 255f) << 16) | ((int)(color.g * 255f) << 8) | (int)(color.b * 255f);
if (_cache.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
{
return value;
}
value = ((style == Style.Marker) ? CreateMarker(color) : CreateNeon(color, style));
((Object)value).hideFlags = (HideFlags)32;
Object.DontDestroyOnLoad((Object)(object)value);
_cache[key] = value;
return value;
}
private static Material CreateMarker(Color color)
{
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Expected O, but got Unknown
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: 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)
Shader val = FindLitShader();
Material val2;
if ((Object)(object)val != (Object)null)
{
val2 = new Material(val);
SetColor(val2, color);
SetTexture(val2, MarkerTexture());
SetFloat(val2, "_Smoothness", 0.35f);
SetFloat(val2, "_Glossiness", 0.35f);
SetFloat(val2, "_Metallic", 0f);
SetFloat(val2, "_Cull", 0f);
SetFloat(val2, "_EnvironmentReflections", 1f);
}
else
{
Shader obj = FindUnlitShader();
val2 = new Material(obj);
bool flag = !((Object)obj).name.StartsWith("Universal Render Pipeline");
SetColor(val2, flag ? Color.white : color);
SetTexture(val2, MarkerTexture());
if (!flag)
{
MakeUrpTransparent(val2);
}
}
((Object)val2).name = "WritingSystem_Marker";
return val2;
}
private static Texture2D MarkerTexture()
{
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Expected O, but got Unknown
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_markerTexture != (Object)null)
{
return _markerTexture;
}
Color32[] array = (Color32[])(object)new Color32[4096];
for (int i = 0; i < 32; i++)
{
float num = Mathf.Abs(((float)i + 0.5f) / 32f - 0.5f) * 2f;
float num2 = 0.9f + 0.1f * Smooth1D((float)i * 0.55f, 17);
for (int j = 0; j < 128; j++)
{
float num3 = 0.95f + 0.05f * Smooth1D((float)j * 0.08f, 91);
float num4 = 0.97f + 0.03f * Hash(j * 31 + i * 197);
float num5 = num2 * num3 * num4;
if (num > 0.72f)
{
num5 *= Mathf.Lerp(1f, 0.78f, (num - 0.72f) / 0.28f);
}
float num6 = ((num > 0.88f) ? Mathf.Lerp(1f, 0.45f, (num - 0.88f) / 0.12f) : 1f);
byte b = (byte)(Mathf.Clamp01(num5) * 255f);
array[i * 128 + j] = new Color32(b, b, b, (byte)(num6 * 255f));
}
}
_markerTexture = new Texture2D(128, 32, (TextureFormat)4, true);
((Object)_markerTexture).name = "WritingSystem_MarkerTex";
((Texture)_markerTexture).wrapModeU = (TextureWrapMode)0;
((Texture)_markerTexture).wrapModeV = (TextureWrapMode)1;
((Texture)_markerTexture).filterMode = (FilterMode)2;
((Texture)_markerTexture).anisoLevel = 4;
_markerTexture.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
_markerTexture.Apply(true, false);
((Object)_markerTexture).hideFlags = (HideFlags)32;
Object.DontDestroyOnLoad((Object)(object)_markerTexture);
return _markerTexture;
}
private static float Hash(int n)
{
n = (n << 13) ^ n;
return 1f - (float)((n * (n * n * 15731 + 789221) + 1376312589) & 0x7FFFFFFF) / 1.0737418E+09f * 0.5f;
}
private static float Smooth1D(float x, int seed)
{
int num = Mathf.FloorToInt(x);
float num2 = x - (float)num;
num2 = num2 * num2 * (3f - 2f * num2);
return Mathf.Lerp(Hash(num + seed * 1013), Hash(num + 1 + seed * 1013), num2);
}
private static Material CreateNeon(Color color, Style style)
{
//IL_0065: 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_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: 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_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Expected O, but got Unknown
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
Shader obj = FindUnlitShader();
bool flag = !((Object)obj).name.StartsWith("Universal Render Pipeline");
float num = style switch
{
Style.NeonGlow => 1.6f,
Style.NeonCore => 4f,
_ => 1f,
};
Color c = (flag ? new Color(num, num, num, 1f) : new Color(color.r * num, color.g * num, color.b * num, color.a));
Material val = new Material(obj);
((Object)val).name = "WritingSystem_Neon_" + style;
SetColor(val, c);
if (style == Style.NeonGlow)
{
if (!flag)
{
MakeUrpTransparent(val);
}
val.renderQueue = 3001;
}
return val;
}
private static void SetColor(Material m, Color c)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
if (m.HasProperty("_BaseColor"))
{
m.SetColor("_BaseColor", c);
}
if (m.HasProperty("_Color"))
{
m.SetColor("_Color", c);
}
}
private static void SetTexture(Material m, Texture2D t)
{
if (m.HasProperty("_BaseMap"))
{
m.SetTexture("_BaseMap", (Texture)(object)t);
}
if (m.HasProperty("_MainTex"))
{
m.SetTexture("_MainTex", (Texture)(object)t);
}
}
private static void SetFloat(Material m, string name, float value)
{
if (m.HasProperty(name))
{
m.SetFloat(name, value);
}
}
private static void MakeUrpTransparent(Material material)
{
material.SetFloat("_Surface", 1f);
material.SetFloat("_Blend", 0f);
material.SetFloat("_SrcBlend", 5f);
material.SetFloat("_DstBlend", 10f);
material.SetFloat("_ZWrite", 0f);
material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
material.SetOverrideTag("RenderType", "Transparent");
material.renderQueue = 3000;
}
private static Shader FindLitShader()
{
if (_litSearched)
{
return _lit;
}
_litSearched = true;
string[] array = new string[2] { "Universal Render Pipeline/Lit", "Universal Render Pipeline/Simple Lit" };
for (int i = 0; i < array.Length; i++)
{
Shader val = Shader.Find(array[i]);
if ((Object)(object)val != (Object)null && val.isSupported)
{
_lit = val;
break;
}
}
WritingMod instance = WritingMod.Instance;
if (instance != null)
{
((MelonBase)instance).LoggerInstance.Msg("WritingSystem: marker ink uses " + (((Object)(object)_lit != (Object)null) ? (((Object)_lit).name + " (lit)") : (((Object)FindUnlitShader()).name + " (unlit fallback)")));
}
return _lit;
}
private static Shader FindUnlitShader()
{
if ((Object)(object)_unlit != (Object)null)
{
return _unlit;
}
string[] array = new string[3] { "Sprites/Default", "UI/Default", "Universal Render Pipeline/Unlit" };
for (int i = 0; i < array.Length; i++)
{
Shader val = Shader.Find(array[i]);
if ((Object)(object)val != (Object)null && val.isSupported)
{
_unlit = val;
return _unlit;
}
}
_unlit = Shader.Find("Standard");
return _unlit;
}
}
public class SavedItem
{
public string Barcode;
public string Title;
public ItemKind Kind;
public readonly List<Stroke> Strokes = new List<Stroke>();
}
public class InkStore
{
private readonly Instance _log;
private readonly string _path;
private readonly Dictionary<int, LiveItem> _live = new Dictionary<int, LiveItem>();
private readonly Dictionary<string, SavedItem> _saved = new Dictionary<string, SavedItem>();
private readonly List<int> _deadIds = new List<int>();
private readonly HashSet<int> _scannedIds = new HashSet<int>();
public int SavedCount => _saved.Count;
public IEnumerable<SavedItem> SavedItems => _saved.Values;
public InkStore(Instance log)
{
_log = log;
string text = Path.Combine(MelonEnvironment.UserDataDirectory, "WritingSystem");
Directory.CreateDirectory(text);
_path = Path.Combine(text, "saved_writing.txt");
}
public LiveItem GetLiveItem(GameObject go)
{
if (!ItemResolver.TryResolve(go, out var root, out var _))
{
return null;
}
if (!_live.TryGetValue(((Object)root).GetInstanceID(), out var value))
{
return null;
}
return value;
}
public LiveItem GetOrCreate(Transform root, ItemKind kind)
{
int instanceID = ((Object)root).GetInstanceID();
if (_live.TryGetValue(instanceID, out var value))
{
return value;
}
value = new LiveItem
{
Root = root,
RootId = instanceID,
Kind = kind
};
ItemResolver.Describe(root, out value.Barcode, out value.Title);
_live[instanceID] = value;
ApplySaved(value);
return value;
}
public void Maintain()
{
if (_live.Count == 0)
{
return;
}
_deadIds.Clear();
foreach (KeyValuePair<int, LiveItem> item in _live)
{
LiveItem value = item.Value;
if ((Object)(object)value.Root == (Object)null || !((Component)value.Root).gameObject.activeInHierarchy)
{
_deadIds.Add(item.Key);
}
}
for (int i = 0; i < _deadIds.Count; i++)
{
LiveItem liveItem = _live[_deadIds[i]];
if ((Object)(object)liveItem.Root != (Object)null)
{
liveItem.ClearStrokes();
}
_live.Remove(_deadIds[i]);
_scannedIds.Remove(_deadIds[i]);
}
}
public void ForgetLiveItems()
{
_live.Clear();
_scannedIds.Clear();
}
public void ApplySavedTo(GameObject heldObject)
{
if (!((Object)(object)heldObject == (Object)null) && _saved.Count != 0 && ItemResolver.TryResolve(heldObject, out var root, out var kind))
{
GetOrCreate(root, kind);
}
}
public void ScanLevelForSavedItems()
{
if (_saved.Count == 0)
{
return;
}
Il2CppArrayBase<Poolee> val = Object.FindObjectsOfType<Poolee>();
for (int i = 0; i < val.Length; i++)
{
Poolee val2 = val[i];
if ((Object)(object)val2 == (Object)null)
{
continue;
}
int instanceID = ((Object)((Component)val2).transform).GetInstanceID();
if (!_live.ContainsKey(instanceID) && _scannedIds.Add(instanceID))
{
SpawnableCrate spawnableCrate = val2.SpawnableCrate;
if (!((Object)(object)spawnableCrate == (Object)null) && !(((Scannable)spawnableCrate).Barcode == (Barcode)null) && _saved.ContainsKey(((Scannable)spawnableCrate).Barcode.ID) && ItemResolver.TryResolve(((Component)val2).gameObject, out var root, out var kind))
{
GetOrCreate(root, kind);
}
}
}
}
private void ApplySaved(LiveItem item)
{
//IL_0059: 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)
if (item.SavedChecked)
{
return;
}
item.SavedChecked = true;
if (item.Barcode == null || !_saved.TryGetValue(item.Barcode, out var value) || item.Strokes.Count > 0)
{
return;
}
foreach (Stroke stroke2 in value.Strokes)
{
Stroke stroke = new Stroke
{
Color = stroke2.Color,
Width = stroke2.Width,
Neon = stroke2.Neon
};
stroke.Points.AddRange(stroke2.Points);
stroke.Normals.AddRange(stroke2.Normals);
stroke.Build(item.Root);
item.Strokes.Add(stroke);
}
}
public void Save(LiveItem item)
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
SavedItem savedItem = new SavedItem
{
Barcode = item.Barcode,
Title = item.Title,
Kind = item.Kind
};
foreach (Stroke stroke2 in item.Strokes)
{
if (stroke2.Points.Count >= 1)
{
Stroke stroke = new Stroke
{
Color = stroke2.Color,
Width = stroke2.Width,
Neon = stroke2.Neon
};
stroke.Points.AddRange(stroke2.Points);
stroke.Normals.AddRange(stroke2.Normals);
savedItem.Strokes.Add(stroke);
}
}
_saved[item.Barcode] = savedItem;
_scannedIds.Clear();
foreach (LiveItem value in _live.Values)
{
if (value != item && value.Barcode == item.Barcode && value.IsAlive)
{
value.ClearStrokes();
value.SavedChecked = false;
ApplySaved(value);
}
}
WriteFile();
}
public bool DeleteSaved(string barcode, bool clearLive)
{
if (string.IsNullOrEmpty(barcode))
{
return false;
}
bool flag = _saved.Remove(barcode);
if (clearLive)
{
foreach (LiveItem value in _live.Values)
{
if (value.Barcode == barcode && value.IsAlive)
{
value.ClearStrokes();
}
}
}
if (flag)
{
WriteFile();
}
return flag;
}
public void Load()
{
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
_saved.Clear();
if (!File.Exists(_path))
{
return;
}
try
{
SavedItem savedItem = null;
string[] array = File.ReadAllLines(_path);
for (int i = 0; i < array.Length; i++)
{
string[] array2 = array[i].Split('\t');
if (array2[0] == "I" && array2.Length >= 4)
{
Enum.TryParse<ItemKind>(array2[3], out var result);
savedItem = new SavedItem
{
Barcode = array2[1],
Title = array2[2],
Kind = result
};
_saved[savedItem.Barcode] = savedItem;
}
else
{
if (!(array2[0] == "S") || array2.Length < 4 || savedItem == null)
{
continue;
}
Stroke stroke = new Stroke
{
Color = ParseColor(array2[1]),
Width = F(array2[2]),
Neon = (array2.Length >= 5 && array2[4] == "N")
};
string[] array3 = array2[3].Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
for (int j = 0; j < array3.Length; j++)
{
string[] array4 = array3[j].Split(',');
if (array4.Length == 3)
{
stroke.Points.Add(new Vector3(F(array4[0]), F(array4[1]), F(array4[2])));
}
}
if (array2.Length >= 6)
{
array3 = array2[5].Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
for (int j = 0; j < array3.Length; j++)
{
string[] array5 = array3[j].Split(',');
if (array5.Length == 3)
{
stroke.Normals.Add(new Vector3(F(array5[0]), F(array5[1]), F(array5[2])));
}
}
if (stroke.Normals.Count != stroke.Points.Count)
{
stroke.Normals.Clear();
}
}
savedItem.Strokes.Add(stroke);
}
}
}
catch (Exception ex)
{
_log.Error("WritingSystem: could not read saved writing: " + ex.Message);
}
}
private void WriteFile()
{
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01ce: 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_01fe: Unknown result type (might be due to invalid IL or missing references)
try
{
StringBuilder stringBuilder = new StringBuilder();
foreach (SavedItem value in _saved.Values)
{
stringBuilder.Append("I\t").Append(value.Barcode).Append('\t')
.Append((value.Title ?? "Item").Replace('\t', ' '))
.Append('\t')
.Append(value.Kind)
.Append('\n');
foreach (Stroke stroke in value.Strokes)
{
stringBuilder.Append("S\t").Append(S(stroke.Color.r)).Append(',')
.Append(S(stroke.Color.g))
.Append(',')
.Append(S(stroke.Color.b))
.Append('\t')
.Append(S(stroke.Width))
.Append('\t');
foreach (Vector3 point in stroke.Points)
{
stringBuilder.Append(S(point.x)).Append(',').Append(S(point.y))
.Append(',')
.Append(S(point.z))
.Append(';');
}
stringBuilder.Append('\t').Append(stroke.Neon ? 'N' : 'M');
stringBuilder.Append('\t');
foreach (Vector3 normal in stroke.Normals)
{
stringBuilder.Append(S(normal.x)).Append(',').Append(S(normal.y))
.Append(',')
.Append(S(normal.z))
.Append(';');
}
stringBuilder.Append('\n');
}
}
File.WriteAllText(_path, stringBuilder.ToString());
}
catch (Exception ex)
{
_log.Error("WritingSystem: could not save writing: " + ex.Message);
}
}
private static string S(float v)
{
return v.ToString("0.#####", CultureInfo.InvariantCulture);
}
private static float F(string s)
{
float.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out var result);
return result;
}
private static Color ParseColor(string s)
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
string[] array = s.Split(',');
if (array.Length != 3)
{
return Color.white;
}
return new Color(F(array[0]), F(array[1]), F(array[2]), 1f);
}
}
public enum InkColor
{
White,
Black,
Yellow,
Red
}
public enum WritingStyle
{
NormalMarker,
Neon
}
public class WritingMod : MelonMod
{
public const string Version = "1.0.0";
internal static WritingMod Instance;
private Page _rootPage;
private Page _savedPage;
private bool _menuCreated;
private int _menuWaitFrames;
private bool _warnedMissingMenu;
private bool _writing;
private InkColor _color;
private WritingStyle _style;
private float _sizeMm = 4f;
private MelonPreferences_Category _prefs;
private MelonPreferences_Entry<string> _laserDirection;
private Pen _pen;
private InkStore _store;
private float _nextScan;
public static Color ToColor(InkColor c)
{
//IL_002a: 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_005e: 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)
return (Color)(c switch
{
InkColor.Black => new Color(0.04f, 0.04f, 0.04f, 1f),
InkColor.Yellow => new Color(1f, 0.88f, 0.1f, 1f),
InkColor.Red => new Color(0.9f, 0.08f, 0.08f, 1f),
_ => new Color(0.97f, 0.97f, 0.97f, 1f),
});
}
public override void OnInitializeMelon()
{
Instance = this;
_prefs = MelonPreferences.CreateCategory("WritingSystem");
_laserDirection = _prefs.CreateEntry<string>("LaserDirection", "Forward", (string)null, "Which way the laser points out of your hand if it feels off: Forward, Up, Down, Back, Left, Right", false, false, (ValueValidator)null, (string)null);
_store = new InkStore(((MelonBase)this).LoggerInstance);
_store.Load();
_pen = new Pen(_store);
((MelonBase)this).LoggerInstance.Msg($"WritingSystem {"1.0.0"} loaded ({_store.SavedCount} saved writings)");
}
public override void OnUpdate()
{
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
if (!_menuCreated)
{
TryCreateMenu();
}
if (!Player.HandsExist)
{
_pen.SetLaserVisible(visible: false);
return;
}
_store.Maintain();
_store.ApplySavedTo(Player.GetObjectInHand(Player.LeftHand));
_store.ApplySavedTo(Player.GetObjectInHand(Player.RightHand));
if (Time.time >= _nextScan)
{
_nextScan = Time.time + 1.5f;
_store.ScanLevelForSavedItems();
}
if (_writing)
{
_pen.Tick(ToColor(_color), _sizeMm / 1000f, _style == WritingStyle.Neon, _laserDirection.Value);
}
}
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
{
_store.ForgetLiveItems();
_pen.Reset();
}
private void TryCreateMenu()
{
//IL_005c: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
if (Page.Root == null)
{
_menuWaitFrames++;
if (!_warnedMissingMenu && _menuWaitFrames > 900)
{
_warnedMissingMenu = true;
((MelonBase)this).LoggerInstance.Warning("WritingSystem: BoneMenu root never appeared - is BoneLib installed?");
}
return;
}
_rootPage = Page.Root.CreatePage("WritingSystem", new Color(1f, 0.85f, 0.3f), 0, true);
_rootPage.CreateFunction("Start Writing", new Color(0.5f, 1f, 0.5f), (Action)StartWriting);
_rootPage.CreateFunction("Stop Writing", new Color(1f, 0.45f, 0.45f), (Action)StopWriting);
_rootPage.CreateEnum("Color Mode", Color.white, (Enum)_color, (Action<Enum>)delegate(Enum value)
{
_color = (InkColor)(object)value;
});
_rootPage.CreateEnum("Writing Mode", new Color(0.4f, 1f, 1f), (Enum)_style, (Action<Enum>)delegate(Enum value)
{
_style = (WritingStyle)(object)value;
});
_rootPage.CreateFunction("Undo Last Stroke", new Color(0.8f, 0.8f, 0.8f), (Action)delegate
{
if (!_pen.UndoLastStroke())
{
Notify("Nothing to undo", (NotificationType)0);
}
});
_savedPage = _rootPage.CreatePage("Saved Writing", new Color(0.45f, 0.8f, 1f), 0, true);
RebuildSavedPage();
_rootPage.CreatePage("Writing Size", new Color(0.85f, 0.6f, 1f), 0, true).CreateFloat("Pen Size (mm)", Color.white, _sizeMm, 1f, 1f, 20f, (Action<float>)delegate(float value)
{
_sizeMm = value;
});
_menuCreated = true;
}
internal void RebuildSavedPage()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
if (_savedPage == null)
{
return;
}
_savedPage.RemoveAll();
_savedPage.CreateFunction("Save Writing On Held Item", new Color(0.5f, 1f, 0.5f), (Action)SaveHeld);
_savedPage.CreateFunction("Remove Writing From Held Item", new Color(1f, 0.45f, 0.45f), (Action)RemoveHeld);
foreach (SavedItem saved in _store.SavedItems)
{
string barcode = saved.Barcode;
string text = $"Remove: {saved.Title} ({saved.Kind}, {saved.Strokes.Count} strokes)";
_savedPage.CreateFunction(text, new Color(1f, 0.7f, 0.4f), (Action)delegate
{
_store.DeleteSaved(barcode, clearLive: true);
Notify("Removed saved writing from " + saved.Title, (NotificationType)3);
RebuildSavedPage();
});
}
}
private void StartWriting()
{
_writing = true;
Notify("Writing on - point your free hand at a gun, melee or mag and hold trigger", (NotificationType)0);
}
private void StopWriting()
{
_writing = false;
_pen.Reset();
_pen.SetLaserVisible(visible: false);
}
private void SaveHeld()
{
LiveItem liveItem = FindHeldOrLastItem();
if (liveItem == null)
{
Notify("Hold the item you wrote on (or write on one first)", (NotificationType)1);
return;
}
if (string.IsNullOrEmpty(liveItem.Barcode))
{
Notify("This item has no barcode, so it can't be saved", (NotificationType)2);
return;
}
if (liveItem.Strokes.Count == 0)
{
Notify("There is no writing on " + liveItem.Title, (NotificationType)1);
return;
}
_store.Save(liveItem);
Notify("Saved writing on " + liveItem.Title, (NotificationType)3);
RebuildSavedPage();
}
private void RemoveHeld()
{
LiveItem liveItem = FindHeldOrLastItem();
if (liveItem == null)
{
Notify("Hold the item you want to clear", (NotificationType)1);
return;
}
bool num = _store.DeleteSaved(liveItem.Barcode, clearLive: true);
liveItem.ClearStrokes();
Notify((num ? "Removed saved writing from " : "Cleared writing on ") + liveItem.Title, (NotificationType)3);
RebuildSavedPage();
}
private LiveItem FindHeldOrLastItem()
{
LiveItem liveItem = _store.GetLiveItem(Player.GetObjectInHand(Player.LeftHand));
if (liveItem == null)
{
liveItem = _store.GetLiveItem(Player.GetObjectInHand(Player.RightHand));
}
if (liveItem == null)
{
liveItem = _pen.LastItem;
}
if (liveItem == null || !liveItem.IsAlive)
{
return null;
}
return liveItem;
}
internal static void Notify(string message, NotificationType type)
{
//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)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: 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_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: 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: Expected O, but got Unknown
try
{
Notifier.Send(new Notification
{
Title = new NotificationText("WritingSystem"),
Message = new NotificationText(message),
Type = type,
PopupLength = 2.5f,
ShowTitleOnPopup = true
});
}
catch (Exception ex)
{
WritingMod instance = Instance;
if (instance != null)
{
((MelonBase)instance).LoggerInstance.Msg(message + " (" + ex.Message + ")");
}
}
}
}
public class Pen
{
private const float LaserLength = 0.45f;
private const float LaserStartOffset = 0.06f;
private const float SurfaceOffset = 0.0015f;
private const float MarkerSurfaceOffset = 0.0005f;
private const float MaxJump = 0.03f;
private const int MaxPointsPerStroke = 600;
private readonly InkStore _store;
private readonly List<KeyValuePair<LiveItem, Stroke>> _history = new List<KeyValuePair<LiveItem, Stroke>>();
private GameObject _laserGo;
private LineRenderer _laser;
private LiveItem _strokeItem;
private Stroke _stroke;
private Vector3 _lastWorld;
public LiveItem LastItem { get; private set; }
public Pen(InkStore store)
{
_store = store;
}
public void Reset()
{
_stroke = null;
_strokeItem = null;
}
public void Tick(Color color, float width, bool neon, string directionMode)
{
//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_002c: 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_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: 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_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: 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)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: 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_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_022d: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_023d: Unknown result type (might be due to invalid IL or missing references)
//IL_0242: Unknown result type (might be due to invalid IL or missing references)
//IL_024d: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
Hand val = PickHand();
if ((Object)(object)val == (Object)null)
{
SetLaserVisible(visible: false);
Reset();
return;
}
Transform transform = ((Component)val).transform;
Vector3 val2 = Direction(transform, directionMode);
Vector3 val3 = transform.position + val2 * 0.06f;
RaycastHit best;
bool num = TryHit(val3, val2, out best);
Transform root = null;
ItemKind kind = ItemKind.Melee;
bool flag = num && ItemResolver.TryResolve(((Component)((RaycastHit)(ref best)).collider).gameObject, out root, out kind);
Vector3 to = (num ? ((RaycastHit)(ref best)).point : (val3 + val2 * 0.45f));
DrawLaser(val3, to, (Color)(flag ? color : new Color(0.6f, 0.6f, 0.6f, 0.5f)), neon && flag);
if (!(val.GetIndexTriggerAxis() > 0.55f) || !flag)
{
Reset();
return;
}
LiveItem orCreate = _store.GetOrCreate(root, kind);
Vector3 val4 = ((RaycastHit)(ref best)).point + ((RaycastHit)(ref best)).normal * (neon ? 0.0015f : 0.0005f);
float num2 = Mathf.Max(0.0015f, width * 0.35f);
if (_stroke == null || _strokeItem != orCreate || !orCreate.IsAlive || _stroke.Points.Count >= 600 || Vector3.Distance(val4, _lastWorld) > 0.03f || _stroke.Color != color || _stroke.Neon != neon || !Mathf.Approximately(_stroke.Width, width))
{
_stroke = new Stroke
{
Color = color,
Width = width,
Neon = neon
};
_stroke.Build(orCreate.Root);
orCreate.Strokes.Add(_stroke);
_strokeItem = orCreate;
_history.Add(new KeyValuePair<LiveItem, Stroke>(orCreate, _stroke));
LastItem = orCreate;
}
else if (Vector3.Distance(val4, _lastWorld) < num2)
{
return;
}
_stroke.AddPoint(orCreate.Root.InverseTransformPoint(val4), orCreate.Root.InverseTransformDirection(((RaycastHit)(ref best)).normal));
_lastWorld = val4;
}
public bool UndoLastStroke()
{
for (int num = _history.Count - 1; num >= 0; num--)
{
KeyValuePair<LiveItem, Stroke> keyValuePair = _history[num];
_history.RemoveAt(num);
if (keyValuePair.Key.IsAlive && keyValuePair.Key.Strokes.Remove(keyValuePair.Value))
{
keyValuePair.Value.Destroy();
if (_stroke == keyValuePair.Value)
{
Reset();
}
return true;
}
}
return false;
}
public void SetLaserVisible(bool visible)
{
if ((Object)(object)_laserGo != (Object)null && _laserGo.activeSelf != visible)
{
_laserGo.SetActive(visible);
}
}
private static Hand PickHand()
{
Hand rightHand = Player.RightHand;
Hand leftHand = Player.LeftHand;
if ((Object)(object)rightHand != (Object)null && (Object)(object)Player.GetObjectInHand(rightHand) == (Object)null)
{
return rightHand;
}
if ((Object)(object)leftHand != (Object)null && (Object)(object)Player.GetObjectInHand(leftHand) == (Object)null)
{
return leftHand;
}
return null;
}
private static Vector3 Direction(Transform t, string mode)
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: 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_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
return (Vector3)((mode ?? "").Trim().ToLowerInvariant() switch
{
"up" => t.up,
"down" => -t.up,
"back" => -t.forward,
"left" => -t.right,
"right" => t.right,
_ => t.forward,
});
}
private static bool TryHit(Vector3 origin, Vector3 dir, out RaycastHit best)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: 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)
best = default(RaycastHit);
Il2CppStructArray<RaycastHit> val = Physics.RaycastAll(origin, dir, 0.45f, -1, (QueryTriggerInteraction)1);
if (val == null || ((Il2CppArrayBase<RaycastHit>)(object)val).Length == 0)
{
return false;
}
Transform val2 = (((Object)(object)Player.RigManager != (Object)null) ? ((Component)Player.RigManager).transform : null);
float num = float.MaxValue;
bool result = false;
for (int i = 0; i < ((Il2CppArrayBase<RaycastHit>)(object)val).Length; i++)
{
RaycastHit val3 = ((Il2CppArrayBase<RaycastHit>)(object)val)[i];
if (!((Object)(object)((RaycastHit)(ref val3)).collider == (Object)null) && (!((Object)(object)val2 != (Object)null) || !((Component)((RaycastHit)(ref val3)).collider).transform.IsChildOf(val2)) && ((RaycastHit)(ref val3)).distance < num)
{
num = ((RaycastHit)(ref val3)).distance;
best = val3;
result = true;
}
}
return result;
}
private void DrawLaser(Vector3 from, Vector3 to, Color color, bool neon)
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
//IL_00ac: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_laserGo == (Object)null)
{
_laserGo = new GameObject("WritingSystem_Laser");
Object.DontDestroyOnLoad((Object)(object)_laserGo);
_laser = _laserGo.AddComponent<LineRenderer>();
_laser.useWorldSpace = true;
_laser.positionCount = 2;
_laser.widthMultiplier = 0.0025f;
_laser.numCapVertices = 2;
((Renderer)_laser).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)_laser).receiveShadows = false;
}
SetLaserVisible(visible: true);
((Renderer)_laser).sharedMaterial = InkMaterials.Get(color, neon ? InkMaterials.Style.NeonCore : InkMaterials.Style.Laser);
_laser.startColor = color;
_laser.endColor = color;
_laser.SetPosition(0, from);
_laser.SetPosition(1, to);
}
}
public class Stroke
{
public Color Color;
public float Width;
public bool Neon;
public readonly List<Vector3> Points = new List<Vector3>();
public readonly List<Vector3> Normals = new List<Vector3>();
private GameObject _go;
private LineRenderer _line;
private LineRenderer _glow;
private Mesh _mesh;
private float _halfWidthLocal;
public bool HasRenderer => (Object)(object)_go != (Object)null;
public static Color MarkerTone(Color c)
{
//IL_0000: 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)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
return new Color(c.r * 0.8f, c.g * 0.8f, c.b * 0.8f, 1f);
}
public void Build(Transform parent)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//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_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_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Expected O, but got Unknown
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Expected O, but got Unknown
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
_go = new GameObject("WritingSystem_Stroke");
_go.transform.SetParent(parent, false);
if (Neon)
{
Color color = Color.Lerp(Color, Color.white, 0.35f);
_line = CreateLine(_go, InkMaterials.Get(color, InkMaterials.Style.NeonCore), color, Width * 0.6f);
GameObject val = new GameObject("WritingSystem_Glow");
val.transform.SetParent(_go.transform, false);
Color color2 = default(Color);
((Color)(ref color2))..ctor(Color.r, Color.g, Color.b, 0.35f);
_glow = CreateLine(val, InkMaterials.Get(color2, InkMaterials.Style.NeonGlow), color2, Width * 2.6f);
}
else if (Normals.Count == Points.Count)
{
float num = Mathf.Max(0.0001f, parent.lossyScale.x);
_halfWidthLocal = Width * 0.5f / num;
_mesh = new Mesh();
((Object)_mesh).name = "WritingSystem_Ink";
_mesh.MarkDynamic();
_go.AddComponent<MeshFilter>().sharedMesh = _mesh;
MeshRenderer obj = _go.AddComponent<MeshRenderer>();
((Renderer)obj).sharedMaterial = InkMaterials.Get(MarkerTone(Color));
((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)obj).receiveShadows = true;
RebuildMesh();
}
else
{
Color color3 = MarkerTone(Color);
_line = CreateLine(_go, InkMaterials.Get(color3), color3, Width);
}
}
public void AddPoint(Vector3 local, Vector3 localNormal)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
Points.Add(local);
Normals.Add(((Vector3)(ref localNormal)).normalized);
Append(_line, local);
Append(_glow, local);
if ((Object)(object)_mesh != (Object)null)
{
RebuildMesh();
}
}
public void Destroy()
{
if ((Object)(object)_go != (Object)null)
{
Object.Destroy((Object)(object)_go);
}
if ((Object)(object)_mesh != (Object)null)
{
Object.Destroy((Object)(object)_mesh);
}
_go = null;
_line = null;
_glow = null;
_mesh = null;
}
private LineRenderer CreateLine(GameObject host, Material material, Color color, float width)
{
//IL_0016: 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_0065: Unknown result type (might be due to invalid IL or missing references)
LineRenderer val = host.AddComponent<LineRenderer>();
val.useWorldSpace = false;
((Renderer)val).sharedMaterial = material;
val.startColor = color;
val.endColor = color;
val.widthMultiplier = width;
val.numCapVertices = 4;
val.numCornerVertices = 2;
((Renderer)val).shadowCastingMode = (ShadowCastingMode)0;
((Renderer)val).receiveShadows = false;
val.positionCount = Points.Count;
for (int i = 0; i < Points.Count; i++)
{
val.SetPosition(i, Points[i]);
}
return val;
}
private void Append(LineRenderer line, Vector3 local)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)line != (Object)null)
{
line.positionCount = Points.Count;
line.SetPosition(Points.Count - 1, local);
}
}
private void RebuildMesh()
{
//IL_0018: 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_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: 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_0047: 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)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0238: Unknown result type (might be due to invalid IL or missing references)
//IL_023d: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_025e: Unknown result type (might be due to invalid IL or missing references)
//IL_0263: Unknown result type (might be due to invalid IL or missing references)
//IL_0277: Unknown result type (might be due to invalid IL or missing references)
//IL_027c: 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_0283: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: 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_0075: 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_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: 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_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: 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_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_015a: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_0295: Unknown result type (might be due to invalid IL or missing references)
//IL_029a: 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_02d1: Unknown result type (might be due to invalid IL or missing references)
//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0301: Unknown result type (might be due to invalid IL or missing references)
//IL_0306: Unknown result type (might be due to invalid IL or missing references)
//IL_030b: Unknown result type (might be due to invalid IL or missing references)
//IL_0349: Unknown result type (might be due to invalid IL or missing references)
//IL_034b: Unknown result type (might be due to invalid IL or missing references)
//IL_034d: Unknown result type (might be due to invalid IL or missing references)
//IL_0352: Unknown result type (might be due to invalid IL or missing references)
//IL_035a: Unknown result type (might be due to invalid IL or missing references)
//IL_035c: Unknown result type (might be due to invalid IL or missing references)
//IL_035e: Unknown result type (might be due to invalid IL or missing references)
//IL_0363: Unknown result type (might be due to invalid IL or missing references)
//IL_036b: Unknown result type (might be due to invalid IL or missing references)
//IL_036d: Unknown result type (might be due to invalid IL or missing references)
//IL_0375: Unknown result type (might be due to invalid IL or missing references)
//IL_0377: Unknown result type (might be due to invalid IL or missing references)
//IL_038a: Unknown result type (might be due to invalid IL or missing references)
//IL_038f: Unknown result type (might be due to invalid IL or missing references)
//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
//IL_031c: Unknown result type (might be due to invalid IL or missing references)
//IL_032b: Unknown result type (might be due to invalid IL or missing references)
int count = Points.Count;
if (count == 0)
{
return;
}
float halfWidthLocal = _halfWidthLocal;
Color val = MarkerTone(Color);
val.a = 0.96f;
Vector3[] array;
Vector3[] array2;
Vector2[] array3;
Color[] array4;
int[] array5;
if (count == 1)
{
Vector3 val2 = Normals[0];
Vector3 val3 = Vector3.Cross(val2, (Mathf.Abs(val2.y) < 0.9f) ? Vector3.up : Vector3.right);
Vector3 val4 = ((Vector3)(ref val3)).normalized * halfWidthLocal;
val3 = Vector3.Cross(val4, val2);
Vector3 val5 = ((Vector3)(ref val3)).normalized * halfWidthLocal;
Vector3 val6 = Points[0];
array = (Vector3[])(object)new Vector3[4]
{
val6 - val4 - val5,
val6 + val4 - val5,
val6 - val4 + val5,
val6 + val4 + val5
};
array2 = (Vector3[])(object)new Vector3[4] { val2, val2, val2, val2 };
array3 = (Vector2[])(object)new Vector2[4]
{
new Vector2(0f, 0f),
new Vector2(0f, 1f),
new Vector2(0.25f, 0f),
new Vector2(0.25f, 1f)
};
array4 = (Color[])(object)new Color[4] { val, val, val, val };
array5 = new int[6] { 0, 2, 3, 0, 3, 1 };
}
else
{
array = (Vector3[])(object)new Vector3[count * 2];
array2 = (Vector3[])(object)new Vector3[count * 2];
array3 = (Vector2[])(object)new Vector2[count * 2];
array4 = (Color[])(object)new Color[count * 2];
array5 = new int[(count - 1) * 6];
float num = 0f;
float num2 = 1f / Mathf.Max(0.0001f, halfWidthLocal * 8f);
for (int i = 0; i < count; i++)
{
Vector3 val7 = Points[i];
Vector3 val8 = Normals[i];
Vector3 val9 = Points[Mathf.Max(0, i - 1)];
Vector3 val10 = Points[Mathf.Min(count - 1, i + 1)] - val9;
if (((Vector3)(ref val10)).sqrMagnitude < 1E-12f)
{
val10 = Vector3.Cross(val8, Vector3.up);
}
((Vector3)(ref val10)).Normalize();
Vector3 val11 = Vector3.Cross(val8, val10);
if (((Vector3)(ref val11)).sqrMagnitude < 1E-12f)
{
val11 = Vector3.Cross(val8, Vector3.right);
}
val11 = ((Vector3)(ref val11)).normalized * halfWidthLocal;
if (i == 0)
{
val7 -= val10 * halfWidthLocal;
}
else if (i == count - 1)
{
val7 += val10 * halfWidthLocal;
}
if (i > 0)
{
num += Vector3.Distance(Points[i], Points[i - 1]);
}
int num3 = i * 2;
int num4 = i * 2 + 1;
array[num3] = val7 + val11;
array[num4] = val7 - val11;
array2[num3] = val8;
array2[num4] = val8;
array3[num3] = new Vector2(num * num2, 1f);
array3[num4] = new Vector2(num * num2, 0f);
array4[num3] = val;
array4[num4] = val;
if (i < count - 1)
{
int num5 = i * 6;
int num6 = num3 + 2;
int num7 = num4 + 2;
array5[num5] = num4;
array5[num5 + 1] = num7;
array5[num5 + 2] = num6;
array5[num5 + 3] = num4;
array5[num5 + 4] = num6;
array5[num5 + 5] = num3;
}
}
}
_mesh.Clear();
_mesh.vertices = Il2CppStructArray<Vector3>.op_Implicit(array);
_mesh.normals = Il2CppStructArray<Vector3>.op_Implicit(array2);
_mesh.uv = Il2CppStructArray<Vector2>.op_Implicit(array3);
_mesh.colors = Il2CppStructArray<Color>.op_Implicit(array4);
_mesh.triangles = Il2CppStructArray<int>.op_Implicit(array5);
_mesh.RecalculateBounds();
}
}
}