Skip to content

Commit

Permalink
v1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Mar 19, 2024
1 parent 89254d1 commit b514696
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 150 deletions.
Binary file modified 1.5/Assemblies/VisualExceptions.dll
Binary file not shown.
Binary file removed 1.5/Assemblies/com.rlabrecque.steamworks.net.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<li>brrainz.harmony</li>
</loadAfter>
<packageId>brrainz.visualexceptions</packageId>
<modVersion>1.3.0.0</modVersion>
<modVersion>1.3.1.0</modVersion>
<steamAppId>2538411704</steamAppId>
<url>https://github.com/pardeike/VisualExceptions</url>
<description>A tool to display exceptions in a graphical way with all involved mods visualized</description>
Expand Down
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>net.pardeike.rimworld.mod.visualexceptions</identifier>
<version>1.3.0.0</version>
<version>1.3.1.0</version>
<targetVersions>
<li>1.2.0</li>
<li>1.3.0</li>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ModName>Visual Exceptions</ModName>
<ModFileName>VisualExceptions</ModFileName>
<Repository>https://github.com/pardeike/VisualExceptions</Repository>
<ModVersion>1.3.0.0</ModVersion>
<ModVersion>1.3.1.0</ModVersion>
<ProjectGuid>{B0D46BB5-08FF-4E04-9EFD-3E32E38A9CC2}</ProjectGuid>
</PropertyGroup>

Expand Down
8 changes: 1 addition & 7 deletions Source/Assets.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.Linq;
using UnityEngine;
using Verse;

Expand Down Expand Up @@ -32,17 +31,12 @@ static Texture2D LoadTexture(string name, bool makeReadonly = true)
var data = File.ReadAllBytes(fullPath);
if (data == null || data.Length == 0) return new Texture2D(1, 1);
var tex = new Texture2D(2, 2, TextureFormat.RGBA32, false, true);
tex.LoadRawTextureData(data);
tex.LoadImage(data);
tex.Compress(true);
tex.wrapMode = TextureWrapMode.Clamp;
tex.filterMode = FilterMode.Trilinear;
tex.Apply(true, makeReadonly);
return tex;
}

static Texture2D[] LoadTextures(params string[] paths)
{
return paths.Select(path => LoadTexture(path)).ToArray();
}
}
}
2 changes: 1 addition & 1 deletion Source/Columns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace VisualExceptions
{
static class Columns
{
static readonly Dictionary<string, string> truncatedModNamesCache = new Dictionary<string, string>();
static readonly Dictionary<string, string> truncatedModNamesCache = [];

internal const float spacing = 8;
const float iconDim = 16;
Expand Down
2 changes: 1 addition & 1 deletion Source/ExceptionDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal Mod(MethodBase method, ModMetaData metaData = null)
var assembly = declaringType.Assembly;
meta = Mods.GetModMetaData(assembly);
}
this.methods = new List<MethodBase> { method };
this.methods = [method];
}

internal void OpenSteam()
Expand Down
4 changes: 2 additions & 2 deletions Source/ExceptionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ internal static class ExceptionHelper
internal static readonly GetClassName getClassName = AccessTools.MethodDelegate<GetClassName>(m_GetClassName);

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

internal static MethodBase GetExpandedMethod(this StackFrame frame, out Patches patches)
{
patches = new Patches(new Patch[0], new Patch[0], new Patch[0], new Patch[0]);
patches = new Patches([], [], [], []);
var method = Harmony.GetMethodFromStackframe(frame);
if (method != null && method is MethodInfo replacement)
{
Expand Down
8 changes: 5 additions & 3 deletions Source/ExceptionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal ExceptionDetails GetReport()
details = new ExceptionDetails()
{
exceptionMessage = GetMessage(exception),
mods = new List<ExceptionDetails.Mod>()
mods = []
};
Assembly lastAssembly = null;
var previousMethods = new HashSet<MethodBase>();
Expand Down Expand Up @@ -62,8 +62,10 @@ internal string GetStacktrace()
var trace = new StackTrace(exception);
if (trace != null && trace.FrameCount > 0)
{
var method = trace.GetFrame(trace.FrameCount - 1).GetExpandedMethod(out _);
_ = sb.Append($" in {method.DeclaringType.FullName}.{method.Name}");
var frame = trace.GetFrame(trace.FrameCount - 1);
var method = frame.GetExpandedMethod(out _);
if (method != null)
_ = sb.Append($" in {method.DeclaringType.FullName}.{method.Name}");
}
_ = sb.Append($": {ExceptionHelper.getClassName(exception)}");

Expand Down
25 changes: 12 additions & 13 deletions Source/ExceptionInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public ExceptionInspector() : base()
def = Tab.instance;
base.resizer = new WindowResizer()
{
minWindowSize = new Vector2(520, 160)
minWindowSize = new(520, 160)
};
}

public override Vector2 InitialSize => new Vector2(600, 600);
public override Vector2 InitialSize => new(600, 600);
public override Vector2 RequestedTabSize => InitialSize;
public override float Margin => Columns.spacing;

Expand Down Expand Up @@ -65,16 +65,16 @@ public override void DoWindowContents(Rect inRect)
viewHeight += Columns.spacing;
}

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

widths = new[]
{
widths =
[
details.mods.Select((_, i) => (i + 1).Column(false)).MaxWidth(),
details.mods.Select(mod => mod.Column()).MaxWidth(),
0
};
];

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

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

public override void Close(bool doCloseSound = true)
Expand Down
6 changes: 3 additions & 3 deletions Source/ExceptionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ namespace VisualExceptions
static class ExceptionState
{
static readonly string configurationPath = Path.Combine(GenFilePaths.ConfigFolderPath, "VisualExceptionsSettings.json");
internal static Configuration configuration = new Configuration();
internal static Configuration configuration = new();

static readonly Dictionary<ExceptionInfo, int> exceptions = new Dictionary<ExceptionInfo, int>(new ExceptionInfo.Comparer());
static readonly HashSet<ExceptionInfo> bannedExceptions = new HashSet<ExceptionInfo>(new ExceptionInfo.Comparer());
static readonly Dictionary<ExceptionInfo, int> exceptions = new(new ExceptionInfo.Comparer());
static readonly HashSet<ExceptionInfo> bannedExceptions = new(new ExceptionInfo.Comparer());
internal static Dictionary<ExceptionInfo, int> Exceptions => exceptions;

internal static Exception Handle(Exception exception)
Expand Down
2 changes: 1 addition & 1 deletion Source/Geometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace VisualExceptions
{
static class Geometry
{
static readonly GUIContent tmpTextGUIContent = new GUIContent();
static readonly GUIContent tmpTextGUIContent = new();

internal static Vector2 Size(this string text)
{
Expand Down
4 changes: 1 addition & 3 deletions Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace VisualExceptions
{
[StaticConstructorOnStartup]
class HarmonyMain : Mod
class HarmonyMain(ModContentPack content) : Mod(content)
{
static HarmonyMain() // loads earliest
{
Expand All @@ -18,8 +18,6 @@ static HarmonyMain() // loads earliest
CrossPromotion.Install(76561197973010050);
}

public HarmonyMain(ModContentPack content) : base(content) { }

public override void DoSettingsWindowContents(Rect inRect)
{
var list = new Listing_Standard { ColumnWidth = inRect.width / 2f };
Expand Down
6 changes: 3 additions & 3 deletions Source/Mods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ struct ModInfo

static class Mods
{
internal static readonly Dictionary<Assembly, string> ActiveHarmonyIDs = new Dictionary<Assembly, string>();
internal static readonly HashSet<string> UnpatchedMods = new HashSet<string>();
static readonly Dictionary<Assembly, ModMetaData> MetaDataCache = new Dictionary<Assembly, ModMetaData>();
internal static readonly Dictionary<Assembly, string> ActiveHarmonyIDs = [];
internal static readonly HashSet<string> UnpatchedMods = [];
static readonly Dictionary<Assembly, ModMetaData> MetaDataCache = [];

internal static ModMetaData GetMetadataIfMod(MethodBase method)
{
Expand Down
12 changes: 6 additions & 6 deletions Source/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ static class Patcher
internal static bool patchesApplied = false;
internal static string harmony_id = "net.pardeike.rimworld.lib.harmony";

internal static HashSet<MethodBase> ignoredMethods = new HashSet<MethodBase>()
{
internal static HashSet<MethodBase> ignoredMethods =
[
SymbolExtensions.GetMethodInfo(() => ParseHelper.FromString("", typeof(void)))
};
];

internal static void Apply()
{
Expand All @@ -38,7 +38,7 @@ static class ExceptionsAndActivatorHandler
{
static readonly MethodInfo Handle = SymbolExtensions.GetMethodInfo(() => ExceptionState.Handle(null));

static readonly Dictionary<MethodInfo, MethodInfo> createInstanceMethods = new Dictionary<MethodInfo, MethodInfo>
static readonly Dictionary<MethodInfo, MethodInfo> createInstanceMethods = new()
{
{ SymbolExtensions.GetMethodInfo(() => Activator.CreateInstance(typeof(void))), SymbolExtensions.GetMethodInfo(() => PatchedActivator.CreateInstance(typeof(void), null)) },
{ SymbolExtensions.GetMethodInfo(() => Activator.CreateInstance(typeof(void), new object[0])), SymbolExtensions.GetMethodInfo(() => PatchedActivator.CreateInstance(typeof(void), new object[0], null)) },
Expand Down Expand Up @@ -123,8 +123,8 @@ internal static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruct
continue;
}
list.Insert(idx, new CodeInstruction(OpCodes.Call, Handle) { blocks = code.blocks, labels = code.labels });
code.labels = new List<Label>();
code.blocks = new List<ExceptionBlock>();
code.labels = [];
code.blocks = [];
found = true;
idx += 2;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Tab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace VisualExceptions
{
public class Tab : MainButtonDef
{
internal static Tab instance = new Tab();
internal static Tab instance = new();

public Tab() : base()
{
Expand All @@ -27,7 +27,7 @@ internal static void AddExceptions()
return;
}

if (root is UIRoot_Entry rootEntry)
if (root is UIRoot_Entry)
{
AddExceptions_Entry();
return;
Expand Down
56 changes: 0 additions & 56 deletions Source/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,62 +97,6 @@ internal static string ShortDescription(this MethodBase member)
return result.ToString();
}

// 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)
// 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)
//
private static ConstructorInfo cFloatMenuOption1 = null;
private static object[] floatMenuOptionDefaults1 = new object[0];
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)
{
if (cFloatMenuOption1 == null)
{
cFloatMenuOption1 = AccessTools.GetDeclaredConstructors(typeof(FloatMenuOption), false)
.First(c => c.GetParameters().ToList().Any(p => p.ParameterType == typeof(MenuOptionPriority)));
floatMenuOptionDefaults1 = cFloatMenuOption1.GetParameters().Select(p => AccessTools.GetDefaultValue(p.ParameterType)).ToArray();
}
var parameters = floatMenuOptionDefaults1;
var isActionRect = cFloatMenuOption1.GetParameters()[3].ParameterType == typeof(Action<Rect>);
void actionRect(Rect r) { mouseoverGuiAction?.Invoke(); }
parameters[0] = label;
parameters[1] = action;
parameters[2] = priority;
parameters[3] = isActionRect ? (object)(Action<Rect>)actionRect : mouseoverGuiAction;
parameters[4] = revalidateClickTarget;
parameters[5] = extraPartWidth;
parameters[6] = extraPartOnGUI;
parameters[7] = revalidateWorldClickTarget;
return (FloatMenuOption)cFloatMenuOption1.Invoke(parameters);
}

// 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)
// 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)
//
private static ConstructorInfo cFloatMenuOption2 = null;
private static object[] floatMenuOptionDefaults2 = new object[0];
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)
{
if (cFloatMenuOption2 == null)
{
cFloatMenuOption2 = AccessTools.GetDeclaredConstructors(typeof(FloatMenuOption), false)
.First(c => c.GetParameters().ToList().Any(p => p.ParameterType == typeof(Texture2D)));
floatMenuOptionDefaults2 = cFloatMenuOption2.GetParameters().Select(p => AccessTools.GetDefaultValue(p.ParameterType)).ToArray();
}
var parameters = floatMenuOptionDefaults2;
var isActionRect = cFloatMenuOption2.GetParameters()[5].ParameterType == typeof(Action<Rect>);
void actionRect(Rect r) { mouseoverGuiAction?.Invoke(); }
parameters[0] = label;
parameters[1] = action;
parameters[2] = itemIcon;
parameters[3] = iconColor;
parameters[4] = priority;
parameters[5] = isActionRect ? (object)(Action<Rect>)actionRect : mouseoverGuiAction;
parameters[6] = revalidateClickTarget;
parameters[7] = extraPartWidth;
parameters[8] = extraPartOnGUI;
parameters[9] = revalidateWorldClickTarget;
return (FloatMenuOption)cFloatMenuOption2.Invoke(parameters);
}

internal static void Button(Texture2D texture, Rect rect, string tipKey, bool highlight, Action action)
{
_ = highlight;
Expand Down
Loading

0 comments on commit b514696

Please sign in to comment.