using System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Dorfistain-BetterJournalist")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("Dorfistain-BetterJournalist")] [assembly: AssemblyTitle("Dorfistain-BetterJournalist")] [assembly: AssemblyVersion("1.0.0.0")] [BepInPlugin("Dorfistain.BetterJournalist", "BetterJournalist", "1.0.0")] public class BetterJournalistPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(Draw), "EnableDrawing")] private static class Patch_Enable { private static void Postfix(Draw __instance) { _draw = __instance; _penActive = true; _isDrawing = true; _customPickerEnabled = false; ((Rect)(ref _win)).width = 0f; } } [HarmonyPatch(typeof(Draw), "DisableDrawing")] private static class Patch_Disable { private static void Postfix() { _draw = null; _isDrawing = false; } } [HarmonyPatch(typeof(DrawUI), "OnPenToolClicked")] private static class Patch_Pen { private static void Postfix() { _penActive = true; } } [HarmonyPatch(typeof(DrawUI), "OnEraseToolClicked")] private static class Patch_Erase { private static void Postfix() { _penActive = false; } } [HarmonyPatch(typeof(ColorTool), "Select")] private static class Patch_ColorSelect { private static void Postfix(ColorTool __instance) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) Color.RGBToHSV(Traverse.Create((object)__instance).Field("color").GetValue(), ref _hue, ref _sat, ref _val); _customPickerEnabled = false; } } [HarmonyPatch(typeof(SizeTool), "Select")] private static class Patch_SizeSelect { private static void Postfix(SizeTool __instance) { _size = Traverse.Create((object)__instance).Field("size").GetValue(); _customPickerEnabled = false; } } [HarmonyPatch(typeof(Draw), "Update")] private static class Patch_DrawUpdate { private static bool Prefix() { return !_pickerMouseDown; } } [HarmonyPatch(typeof(ArticleCreationUICanvas), "Publish")] private static class Patch_Publish { private static void Postfix() { _isDrawing = false; } } private static Draw _draw; private static bool _penActive = true; private static bool _isDrawing; private static float _hue = 0f; private static float _sat = 1f; private static float _val = 1f; private static float _size = 4f; private static Texture2D _svTex; private static Texture2D _hueTex; private static Texture2D _handleTex; private static Texture2D _backgroundTex; private static float _builtSvForHue = -1f; private static bool _customPickerEnabled = false; private const int WIN_W = 471; private const int WIN_H = 442; private const int SV = 260; private const int HW = 31; private const int HD = 18; private const int SV_X = 85; private const int SV_Y = 56; private const int HUE_X = 355; private const int HUE_Y = 56; private const int SZ_Y = 374; private const int SZ_LBL_X = 48; private const int SZ_SLIDER_X = 82; private const int SZ_VAL_X = 381; private const int SZ_SLIDER_W = 299; private static Rect _win; private static bool _dragSV; private static bool _dragHue; private static bool _pickerMouseDown; private static GUIStyle _noChrome; private static GUIStyle _szLabelStyle; private static GUIStyle _sliderBg; private static GUIStyle _sliderThumb; private void Awake() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); new Harmony("Dorfistain.BetterJournalist").PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"BetterJournalist v1.0.0 loaded — Synced HSV picker!"); } private void OnGUI() { //IL_0056: 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) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Expected O, but got Unknown //IL_0143: 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) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Expected O, but got Unknown //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Expected O, but got Unknown //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Expected O, but got Unknown if (_isDrawing && !((Object)(object)_draw == (Object)null)) { EnsureTex(); if (((Rect)(ref _win)).width == 0f) { _win = new Rect((float)(Screen.width - 471 - 15), (float)(Screen.height - 442) * 0.5f, 471f, 442f); } if (_noChrome == null) { _noChrome = new GUIStyle(GUI.skin.window); _noChrome.normal.background = null; _noChrome.onNormal.background = null; _szLabelStyle = new GUIStyle(GUI.skin.label) { fontSize = 17 }; _szLabelStyle.normal.textColor = Color.black; _sliderBg = new GUIStyle(GUI.skin.horizontalSlider); _sliderBg.fixedHeight = 0f; _sliderThumb = new GUIStyle(GUI.skin.horizontalSliderThumb); _sliderThumb.fixedWidth = 28f; _sliderThumb.fixedHeight = 28f; } _win = GUI.Window(12482533, _win, new WindowFunction(DrawWindow), GUIContent.none, _noChrome); } } private static void DrawWindow(int _) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0035: 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_00a5: 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) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Invalid comparison between Unknown and I4 //IL_00bb: 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_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_022b: Unknown result type (might be due to invalid IL or missing references) //IL_0245: Unknown result type (might be due to invalid IL or missing references) //IL_0254: 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_02ab: 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_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Invalid comparison between Unknown and I4 //IL_02f9: 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_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Invalid comparison between Unknown and I4 //IL_035f: Unknown result type (might be due to invalid IL or missing references) //IL_0339: Unknown result type (might be due to invalid IL or missing references) Event current = Event.current; if ((int)current.type == 0) { _pickerMouseDown = true; } if ((Object)(object)_backgroundTex != (Object)null) { GUI.DrawTexture(new Rect(0f, 0f, 471f, 442f), (Texture)(object)_backgroundTex); } Rect val = default(Rect); ((Rect)(ref val))..ctor(85f, 56f, 260f, 260f); Rect val2 = default(Rect); ((Rect)(ref val2))..ctor(355f, 56f, 31f, 260f); if (!Mathf.Approximately(_builtSvForHue, _hue)) { BuildSVTex(); _builtSvForHue = _hue; } GUI.DrawTexture(val, (Texture)(object)_svTex); GUI.DrawTexture(val2, (Texture)(object)_hueTex); if ((int)current.type == 0) { if (((Rect)(ref val)).Contains(current.mousePosition)) { _dragSV = true; _customPickerEnabled = true; current.Use(); } if (((Rect)(ref val2)).Contains(current.mousePosition)) { _dragHue = true; _customPickerEnabled = true; current.Use(); } } if ((int)current.type == 1) { _pickerMouseDown = false; _dragSV = (_dragHue = false); } if (_dragSV && ((int)current.type == 0 || (int)current.type == 3)) { _sat = Mathf.Clamp01((current.mousePosition.x - ((Rect)(ref val)).x) / ((Rect)(ref val)).width); _val = Mathf.Clamp01(1f - (current.mousePosition.y - ((Rect)(ref val)).y) / ((Rect)(ref val)).height); current.Use(); } if (_dragHue && ((int)current.type == 0 || (int)current.type == 3)) { _hue = Mathf.Clamp01((current.mousePosition.y - ((Rect)(ref val2)).y) / ((Rect)(ref val2)).height); current.Use(); } DrawHandle(((Rect)(ref val)).x + _sat * ((Rect)(ref val)).width, ((Rect)(ref val)).y + (1f - _val) * ((Rect)(ref val)).height); DrawHandle(370.5f, 56f + _hue * 260f); Color color = (GUI.color = Color.HSVToRGB(_hue, _sat, _val)); GUI.DrawTexture(new Rect(355f, 318f, 31f, 8f), (Texture)(object)Texture2D.whiteTexture); GUI.color = Color.white; int brushSize = Mathf.RoundToInt(_size); GUI.Label(new Rect(48f, 374f, 34f, 24f), "Sz:", _szLabelStyle); float size = _size; _size = GUI.HorizontalSlider(new Rect(82f, 376f, 299f, 20f), _size, 1f, 100f, _sliderBg, _sliderThumb); if (!Mathf.Approximately(size, _size)) { _customPickerEnabled = true; } GUI.Label(new Rect(381f, 374f, 47f, 24f), brushSize + "px", _szLabelStyle); if (_customPickerEnabled && (Object)(object)_draw != (Object)null) { if (_penActive) { _draw.SetColor(color); } _draw.SetBrushSize(brushSize); } GUI.DragWindow(new Rect(0f, 0f, 471f, 442f)); } private static void DrawHandle(float cx, float cy) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) int num = 9; GUI.DrawTexture(new Rect(cx - (float)num, cy - (float)num, 18f, 18f), (Texture)(object)_handleTex); } private static void BuildSVTex() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_svTex == (Object)null) { _svTex = new Texture2D(260, 260, (TextureFormat)3, false) { filterMode = (FilterMode)1 }; } Color[] array = (Color[])(object)new Color[67600]; for (int i = 0; i < 260; i++) { float num = (float)i / 259f; for (int j = 0; j < 260; j++) { array[i * 260 + j] = Color.HSVToRGB(_hue, (float)j / 259f, num); } } _svTex.SetPixels(array); _svTex.Apply(); } private static void EnsureTex() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0195: 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_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_017f: 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) if ((Object)(object)_svTex == (Object)null) { BuildSVTex(); _builtSvForHue = _hue; } if ((Object)(object)_hueTex == (Object)null) { _hueTex = new Texture2D(31, 260, (TextureFormat)3, false) { filterMode = (FilterMode)1 }; Color[] array = (Color[])(object)new Color[8060]; for (int i = 0; i < 260; i++) { Color val = Color.HSVToRGB(1f - (float)i / 259f, 1f, 1f); for (int j = 0; j < 31; j++) { array[i * 31 + j] = val; } } _hueTex.SetPixels(array); _hueTex.Apply(); } if ((Object)(object)_handleTex == (Object)null) { _handleTex = new Texture2D(18, 18, (TextureFormat)5, false) { filterMode = (FilterMode)1 }; Color[] array2 = (Color[])(object)new Color[324]; float num = 9f; for (int k = 0; k < 18; k++) { for (int l = 0; l < 18; l++) { float num2 = (float)l - num + 0.5f; float num3 = (float)k - num + 0.5f; float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3); if (num4 >= num - 3f && num4 < num) { array2[k * 18 + l] = Color.white; } else if (num4 >= num - 5f && num4 < num - 3f) { array2[k * 18 + l] = new Color(0f, 0f, 0f, 0.8f); } else { array2[k * 18 + l] = Color.clear; } } } _handleTex.SetPixels(array2); _handleTex.Apply(); } if ((Object)(object)_backgroundTex == (Object)null) { _backgroundTex = LoadBackgroundImage(); } } private static Texture2D LoadBackgroundImage() { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Expected O, but got Unknown try { string directoryName = Path.GetDirectoryName(typeof(BetterJournalistPlugin).Assembly.Location); string[] array = new string[3] { Path.Combine(directoryName, "ColorPickerGUI.png"), Path.Combine(directoryName, "..", "ColorPickerGUI.png"), Path.Combine(directoryName, "..\\..\\BetterJournalist", "ColorPickerGUI.png") }; foreach (string path in array) { if (File.Exists(path)) { byte[] array2 = File.ReadAllBytes(path); Texture2D val = new Texture2D(256, 256, (TextureFormat)4, false); if (ImageConversion.LoadImage(val, array2)) { return val; } } } } catch (Exception) { } return null; } }