Skip to content

Commit b514696

Browse files
committed
v1.3.1
1 parent 89254d1 commit b514696

19 files changed

+50
-150
lines changed

1.5/Assemblies/VisualExceptions.dll

-2 KB
Binary file not shown.
-366 KB
Binary file not shown.

About/About.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<li>brrainz.harmony</li>
2424
</loadAfter>
2525
<packageId>brrainz.visualexceptions</packageId>
26-
<modVersion>1.3.0.0</modVersion>
26+
<modVersion>1.3.1.0</modVersion>
2727
<steamAppId>2538411704</steamAppId>
2828
<url>https://github.com/pardeike/VisualExceptions</url>
2929
<description>A tool to display exceptions in a graphical way with all involved mods visualized</description>

About/Manifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
22
<Manifest>
33
<identifier>net.pardeike.rimworld.mod.visualexceptions</identifier>
4-
<version>1.3.0.0</version>
4+
<version>1.3.1.0</version>
55
<targetVersions>
66
<li>1.2.0</li>
77
<li>1.3.0</li>

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<ModName>Visual Exceptions</ModName>
55
<ModFileName>VisualExceptions</ModFileName>
66
<Repository>https://github.com/pardeike/VisualExceptions</Repository>
7-
<ModVersion>1.3.0.0</ModVersion>
7+
<ModVersion>1.3.1.0</ModVersion>
88
<ProjectGuid>{B0D46BB5-08FF-4E04-9EFD-3E32E38A9CC2}</ProjectGuid>
99
</PropertyGroup>
1010

Source/Assets.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.IO;
2-
using System.Linq;
32
using UnityEngine;
43
using Verse;
54

@@ -32,17 +31,12 @@ static Texture2D LoadTexture(string name, bool makeReadonly = true)
3231
var data = File.ReadAllBytes(fullPath);
3332
if (data == null || data.Length == 0) return new Texture2D(1, 1);
3433
var tex = new Texture2D(2, 2, TextureFormat.RGBA32, false, true);
35-
tex.LoadRawTextureData(data);
34+
tex.LoadImage(data);
3635
tex.Compress(true);
3736
tex.wrapMode = TextureWrapMode.Clamp;
3837
tex.filterMode = FilterMode.Trilinear;
3938
tex.Apply(true, makeReadonly);
4039
return tex;
4140
}
42-
43-
static Texture2D[] LoadTextures(params string[] paths)
44-
{
45-
return paths.Select(path => LoadTexture(path)).ToArray();
46-
}
4741
}
4842
}

Source/Columns.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace VisualExceptions
1111
{
1212
static class Columns
1313
{
14-
static readonly Dictionary<string, string> truncatedModNamesCache = new Dictionary<string, string>();
14+
static readonly Dictionary<string, string> truncatedModNamesCache = [];
1515

1616
internal const float spacing = 8;
1717
const float iconDim = 16;

Source/ExceptionDetails.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal Mod(MethodBase method, ModMetaData metaData = null)
2424
var assembly = declaringType.Assembly;
2525
meta = Mods.GetModMetaData(assembly);
2626
}
27-
this.methods = new List<MethodBase> { method };
27+
this.methods = [method];
2828
}
2929

3030
internal void OpenSteam()

Source/ExceptionHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ internal static class ExceptionHelper
3535
internal static readonly GetClassName getClassName = AccessTools.MethodDelegate<GetClassName>(m_GetClassName);
3636

3737
internal delegate string ToStringBoolBool(Exception instance, bool needFileLineInfo, bool needMessage);
38-
internal static readonly MethodInfo m_ToString = AccessTools.Method(typeof(Exception), "ToString", new[] { typeof(bool), typeof(bool) });
38+
internal static readonly MethodInfo m_ToString = AccessTools.Method(typeof(Exception), "ToString", [typeof(bool), typeof(bool)]);
3939
internal static readonly ToStringBoolBool toString = AccessTools.MethodDelegate<ToStringBoolBool>(m_ToString);
4040

4141
internal static MethodBase GetExpandedMethod(this StackFrame frame, out Patches patches)
4242
{
43-
patches = new Patches(new Patch[0], new Patch[0], new Patch[0], new Patch[0]);
43+
patches = new Patches([], [], [], []);
4444
var method = Harmony.GetMethodFromStackframe(frame);
4545
if (method != null && method is MethodInfo replacement)
4646
{

Source/ExceptionInfo.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ internal ExceptionDetails GetReport()
2929
details = new ExceptionDetails()
3030
{
3131
exceptionMessage = GetMessage(exception),
32-
mods = new List<ExceptionDetails.Mod>()
32+
mods = []
3333
};
3434
Assembly lastAssembly = null;
3535
var previousMethods = new HashSet<MethodBase>();
@@ -62,8 +62,10 @@ internal string GetStacktrace()
6262
var trace = new StackTrace(exception);
6363
if (trace != null && trace.FrameCount > 0)
6464
{
65-
var method = trace.GetFrame(trace.FrameCount - 1).GetExpandedMethod(out _);
66-
_ = sb.Append($" in {method.DeclaringType.FullName}.{method.Name}");
65+
var frame = trace.GetFrame(trace.FrameCount - 1);
66+
var method = frame.GetExpandedMethod(out _);
67+
if (method != null)
68+
_ = sb.Append($" in {method.DeclaringType.FullName}.{method.Name}");
6769
}
6870
_ = sb.Append($": {ExceptionHelper.getClassName(exception)}");
6971

Source/ExceptionInspector.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ public ExceptionInspector() : base()
1616
def = Tab.instance;
1717
base.resizer = new WindowResizer()
1818
{
19-
minWindowSize = new Vector2(520, 160)
19+
minWindowSize = new(520, 160)
2020
};
2121
}
2222

23-
public override Vector2 InitialSize => new Vector2(600, 600);
23+
public override Vector2 InitialSize => new(600, 600);
2424
public override Vector2 RequestedTabSize => InitialSize;
2525
public override float Margin => Columns.spacing;
2626

@@ -65,16 +65,16 @@ public override void DoWindowContents(Rect inRect)
6565
viewHeight += Columns.spacing;
6666
}
6767

68-
widths = new float[] { 0 };
68+
widths = [0];
6969
Columns.Row(viewWidth, ref viewHeight, 0, 0, widths, null, exInfo.Key.ExceptionColumn(() => exInfo.Key.GetStacktrace(), count));
7070
Columns.Row(viewWidth, ref viewHeight, Columns.spacing / 2, Columns.spacing / 2, widths, null, details.topMethod.IconColumn(Assets.location));
7171

72-
widths = new[]
73-
{
72+
widths =
73+
[
7474
details.mods.Select((_, i) => (i + 1).Column(false)).MaxWidth(),
7575
details.mods.Select(mod => mod.Column()).MaxWidth(),
7676
0
77-
};
77+
];
7878

7979
details.mods.Iterate((mod, i) => Columns.Row(viewWidth, ref viewHeight, Columns.spacing / 2, 0, widths, () => ChooseMod(mod),
8080
(i + 1).Column(mod.IsUnpatched()),
@@ -96,14 +96,14 @@ static void ChooseMod(ExceptionDetails.Mod mod)
9696
var onOff = mod.meta.Active ? "Deactivate this mod (needs restart)" : "Reactivate this mod";
9797
var options = new List<FloatMenuOption>();
9898
if (mod.meta.OnSteamWorkshop)
99-
options.Add(Tools.NewFloatMenuOption("Open Workshop Page", mod.OpenSteam, MenuOptionPriority.High));
99+
options.Add(new FloatMenuOption("Open Workshop Page", mod.OpenSteam, MenuOptionPriority.High));
100100
if (mod.meta.Url.NullOrEmpty() == false)
101-
options.Add(Tools.NewFloatMenuOption("Open Website", mod.OpenURL, MenuOptionPriority.High));
102-
options.Add(Tools.NewFloatMenuOption(onOff, () => mod.ToggleActive(), mod.meta.Active ? Assets.disableMenu : Assets.enableMenu, Color.white));
101+
options.Add(new FloatMenuOption("Open Website", mod.OpenURL, MenuOptionPriority.High));
102+
options.Add(new FloatMenuOption(onOff, () => mod.ToggleActive(), mod.meta.Active ? Assets.disableMenu : Assets.enableMenu, Color.white));
103103
if (mod.IsUnpatched() == false)
104-
options.Add(Tools.NewFloatMenuOption("Remove Harmony Patches", () => mod.Unpatch(), Assets.unpatchMenu, Color.white));
105-
options.Add(Tools.NewFloatMenuOption(mod.meta.Name, null));
106-
options.Add(Tools.NewFloatMenuOption("VersionIndicator".Translate(mod.version), null));
104+
options.Add(new FloatMenuOption("Remove Harmony Patches", () => mod.Unpatch(), Assets.unpatchMenu, Color.white));
105+
options.Add(new FloatMenuOption(mod.meta.Name, null));
106+
options.Add(new FloatMenuOption("VersionIndicator".Translate(mod.version), null));
107107
Find.WindowStack.Add(new FloatMenu(options));
108108
}
109109

@@ -115,7 +115,6 @@ public override void SetInitialSizeAndPosition()
115115
resizeable = true;
116116
if (ExceptionState.configuration.TabToTheRight)
117117
windowRect.x = UI.screenWidth - windowRect.width;
118-
Log.Warning($"{windowRect}");
119118
}
120119

121120
public override void Close(bool doCloseSound = true)

Source/ExceptionState.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ namespace VisualExceptions
99
static class ExceptionState
1010
{
1111
static readonly string configurationPath = Path.Combine(GenFilePaths.ConfigFolderPath, "VisualExceptionsSettings.json");
12-
internal static Configuration configuration = new Configuration();
12+
internal static Configuration configuration = new();
1313

14-
static readonly Dictionary<ExceptionInfo, int> exceptions = new Dictionary<ExceptionInfo, int>(new ExceptionInfo.Comparer());
15-
static readonly HashSet<ExceptionInfo> bannedExceptions = new HashSet<ExceptionInfo>(new ExceptionInfo.Comparer());
14+
static readonly Dictionary<ExceptionInfo, int> exceptions = new(new ExceptionInfo.Comparer());
15+
static readonly HashSet<ExceptionInfo> bannedExceptions = new(new ExceptionInfo.Comparer());
1616
internal static Dictionary<ExceptionInfo, int> Exceptions => exceptions;
1717

1818
internal static Exception Handle(Exception exception)

Source/Geometry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace VisualExceptions
55
{
66
static class Geometry
77
{
8-
static readonly GUIContent tmpTextGUIContent = new GUIContent();
8+
static readonly GUIContent tmpTextGUIContent = new();
99

1010
internal static Vector2 Size(this string text)
1111
{

Source/Main.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace VisualExceptions
88
{
99
[StaticConstructorOnStartup]
10-
class HarmonyMain : Mod
10+
class HarmonyMain(ModContentPack content) : Mod(content)
1111
{
1212
static HarmonyMain() // loads earliest
1313
{
@@ -18,8 +18,6 @@ static HarmonyMain() // loads earliest
1818
CrossPromotion.Install(76561197973010050);
1919
}
2020

21-
public HarmonyMain(ModContentPack content) : base(content) { }
22-
2321
public override void DoSettingsWindowContents(Rect inRect)
2422
{
2523
var list = new Listing_Standard { ColumnWidth = inRect.width / 2f };

Source/Mods.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ struct ModInfo
1616

1717
static class Mods
1818
{
19-
internal static readonly Dictionary<Assembly, string> ActiveHarmonyIDs = new Dictionary<Assembly, string>();
20-
internal static readonly HashSet<string> UnpatchedMods = new HashSet<string>();
21-
static readonly Dictionary<Assembly, ModMetaData> MetaDataCache = new Dictionary<Assembly, ModMetaData>();
19+
internal static readonly Dictionary<Assembly, string> ActiveHarmonyIDs = [];
20+
internal static readonly HashSet<string> UnpatchedMods = [];
21+
static readonly Dictionary<Assembly, ModMetaData> MetaDataCache = [];
2222

2323
internal static ModMetaData GetMetadataIfMod(MethodBase method)
2424
{

Source/Patcher.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ static class Patcher
1515
internal static bool patchesApplied = false;
1616
internal static string harmony_id = "net.pardeike.rimworld.lib.harmony";
1717

18-
internal static HashSet<MethodBase> ignoredMethods = new HashSet<MethodBase>()
19-
{
18+
internal static HashSet<MethodBase> ignoredMethods =
19+
[
2020
SymbolExtensions.GetMethodInfo(() => ParseHelper.FromString("", typeof(void)))
21-
};
21+
];
2222

2323
internal static void Apply()
2424
{
@@ -38,7 +38,7 @@ static class ExceptionsAndActivatorHandler
3838
{
3939
static readonly MethodInfo Handle = SymbolExtensions.GetMethodInfo(() => ExceptionState.Handle(null));
4040

41-
static readonly Dictionary<MethodInfo, MethodInfo> createInstanceMethods = new Dictionary<MethodInfo, MethodInfo>
41+
static readonly Dictionary<MethodInfo, MethodInfo> createInstanceMethods = new()
4242
{
4343
{ SymbolExtensions.GetMethodInfo(() => Activator.CreateInstance(typeof(void))), SymbolExtensions.GetMethodInfo(() => PatchedActivator.CreateInstance(typeof(void), null)) },
4444
{ SymbolExtensions.GetMethodInfo(() => Activator.CreateInstance(typeof(void), new object[0])), SymbolExtensions.GetMethodInfo(() => PatchedActivator.CreateInstance(typeof(void), new object[0], null)) },
@@ -123,8 +123,8 @@ internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruct
123123
continue;
124124
}
125125
list.Insert(idx, new CodeInstruction(OpCodes.Call, Handle) { blocks = code.blocks, labels = code.labels });
126-
code.labels = new List<Label>();
127-
code.blocks = new List<ExceptionBlock>();
126+
code.labels = [];
127+
code.blocks = [];
128128
found = true;
129129
idx += 2;
130130
}

Source/Tab.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace VisualExceptions
55
{
66
public class Tab : MainButtonDef
77
{
8-
internal static Tab instance = new Tab();
8+
internal static Tab instance = new();
99

1010
public Tab() : base()
1111
{
@@ -27,7 +27,7 @@ internal static void AddExceptions()
2727
return;
2828
}
2929

30-
if (root is UIRoot_Entry rootEntry)
30+
if (root is UIRoot_Entry)
3131
{
3232
AddExceptions_Entry();
3333
return;

Source/Tools.cs

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -97,62 +97,6 @@ internal static string ShortDescription(this MethodBase member)
9797
return result.ToString();
9898
}
9999

100-
// 1.2 public FloatMenuOption(string label, Action action, MenuOptionPriority priority = MenuOptionPriority.Default, Action mouseoverGuiAction = null, Thing revalidateClickTarget = null, float extraPartWidth = 0f, Func<Rect, bool> extraPartOnGUI = null, WorldObject revalidateWorldClickTarget = null)
101-
// 1.3 public FloatMenuOption(string label, Action action, MenuOptionPriority priority = MenuOptionPriority.Default, Action<Rect> mouseoverGuiAction = null, Thing revalidateClickTarget = null, float extraPartWidth = 0f, Func<Rect, bool> extraPartOnGUI = null, WorldObject revalidateWorldClickTarget = null, bool playSelectionSound = true, int orderInPriority = 0)
102-
//
103-
private static ConstructorInfo cFloatMenuOption1 = null;
104-
private static object[] floatMenuOptionDefaults1 = new object[0];
105-
internal static FloatMenuOption NewFloatMenuOption(string label, Action action, MenuOptionPriority priority = MenuOptionPriority.Default, Action mouseoverGuiAction = null, Thing revalidateClickTarget = null, float extraPartWidth = 0f, Func<Rect, bool> extraPartOnGUI = null, WorldObject revalidateWorldClickTarget = null)
106-
{
107-
if (cFloatMenuOption1 == null)
108-
{
109-
cFloatMenuOption1 = AccessTools.GetDeclaredConstructors(typeof(FloatMenuOption), false)
110-
.First(c => c.GetParameters().ToList().Any(p => p.ParameterType == typeof(MenuOptionPriority)));
111-
floatMenuOptionDefaults1 = cFloatMenuOption1.GetParameters().Select(p => AccessTools.GetDefaultValue(p.ParameterType)).ToArray();
112-
}
113-
var parameters = floatMenuOptionDefaults1;
114-
var isActionRect = cFloatMenuOption1.GetParameters()[3].ParameterType == typeof(Action<Rect>);
115-
void actionRect(Rect r) { mouseoverGuiAction?.Invoke(); }
116-
parameters[0] = label;
117-
parameters[1] = action;
118-
parameters[2] = priority;
119-
parameters[3] = isActionRect ? (object)(Action<Rect>)actionRect : mouseoverGuiAction;
120-
parameters[4] = revalidateClickTarget;
121-
parameters[5] = extraPartWidth;
122-
parameters[6] = extraPartOnGUI;
123-
parameters[7] = revalidateWorldClickTarget;
124-
return (FloatMenuOption)cFloatMenuOption1.Invoke(parameters);
125-
}
126-
127-
// 1.2 public FloatMenuOption(string label, Action action, Texture2D itemIcon, Color iconColor, MenuOptionPriority priority = MenuOptionPriority.Default, Action mouseoverGuiAction = null, Thing revalidateClickTarget = null, float extraPartWidth = 0f, Func<Rect, bool> extraPartOnGUI = null, WorldObject revalidateWorldClickTarget = null)
128-
// 1.3 public FloatMenuOption(string label, Action action, Texture2D itemIcon, Color iconColor, MenuOptionPriority priority = MenuOptionPriority.Default, Action<Rect> mouseoverGuiAction = null, Thing revalidateClickTarget = null, float extraPartWidth = 0f, Func<Rect, bool> extraPartOnGUI = null, WorldObject revalidateWorldClickTarget = null, bool playSelectionSound = true, int orderInPriority = 0)
129-
//
130-
private static ConstructorInfo cFloatMenuOption2 = null;
131-
private static object[] floatMenuOptionDefaults2 = new object[0];
132-
internal static FloatMenuOption NewFloatMenuOption(string label, Action action, Texture2D itemIcon, Color iconColor, MenuOptionPriority priority = MenuOptionPriority.Default, Action mouseoverGuiAction = null, Thing revalidateClickTarget = null, float extraPartWidth = 0f, Func<Rect, bool> extraPartOnGUI = null, WorldObject revalidateWorldClickTarget = null)
133-
{
134-
if (cFloatMenuOption2 == null)
135-
{
136-
cFloatMenuOption2 = AccessTools.GetDeclaredConstructors(typeof(FloatMenuOption), false)
137-
.First(c => c.GetParameters().ToList().Any(p => p.ParameterType == typeof(Texture2D)));
138-
floatMenuOptionDefaults2 = cFloatMenuOption2.GetParameters().Select(p => AccessTools.GetDefaultValue(p.ParameterType)).ToArray();
139-
}
140-
var parameters = floatMenuOptionDefaults2;
141-
var isActionRect = cFloatMenuOption2.GetParameters()[5].ParameterType == typeof(Action<Rect>);
142-
void actionRect(Rect r) { mouseoverGuiAction?.Invoke(); }
143-
parameters[0] = label;
144-
parameters[1] = action;
145-
parameters[2] = itemIcon;
146-
parameters[3] = iconColor;
147-
parameters[4] = priority;
148-
parameters[5] = isActionRect ? (object)(Action<Rect>)actionRect : mouseoverGuiAction;
149-
parameters[6] = revalidateClickTarget;
150-
parameters[7] = extraPartWidth;
151-
parameters[8] = extraPartOnGUI;
152-
parameters[9] = revalidateWorldClickTarget;
153-
return (FloatMenuOption)cFloatMenuOption2.Invoke(parameters);
154-
}
155-
156100
internal static void Button(Texture2D texture, Rect rect, string tipKey, bool highlight, Action action)
157101
{
158102
_ = highlight;

0 commit comments

Comments
 (0)