Skip to content

Commit

Permalink
Merge pull request #225 from BUTR/dev
Browse files Browse the repository at this point in the history
v2.2.9
  • Loading branch information
Aragas authored Oct 23, 2022
2 parents 3146fe8 + d0a2505 commit e9586d9
Show file tree
Hide file tree
Showing 7 changed files with 542 additions and 63 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!--Development Variables-->
<PropertyGroup>
<!--Module Version-->
<Version>2.2.8</Version>
<Version>2.2.9</Version>
<!--Harmony Version-->
<HarmonyVersion>2.2.2</HarmonyVersion>
<HarmonyExtensionsVersion>3.1.0.67</HarmonyExtensionsVersion>
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 2.2.9
Game Versions: e1.7.2,e1.8.0,e1.8.1,e1.9.0
* Crash Reporter now has info about the launcher and BUTRLoader
* Reduced size of minidumps
---------------------------------------------------------------------------------------------------
Version: 2.2.8
Game Versions: e1.7.2,e1.8.0,e1.8.1,e1.9.0
* Added External metadata to Crash Report, states that module is from Workshop
Expand Down
2 changes: 1 addition & 1 deletion src/Bannerlord.ButterLib/Bannerlord.ButterLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Nullable>enable</Nullable>
<Platforms>x64</Platforms>
<BUTRUploadUrl>$(BANNERLORD_BUTR_UPLOAD_URL)</BUTRUploadUrl>
<DefineConstants>$(DefineConstants);BANNERLORDBUTRSHARED_BUTTERLIB;HARMONYEXTENSIONS_DISABLE_2_0_4</DefineConstants>
<DefineConstants>$(DefineConstants);BANNERLORDBUTRSHARED_BUTTERLIB;HARMONYEXTENSIONS_DISABLE_2_0_4;X64</DefineConstants>
<GameVersion>1.7.2</GameVersion>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Bannerlord.ButterLib/ExceptionHandler/CrashReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class CrashReport
public Guid Id { get; } = Guid.NewGuid();
public Exception Exception { get; }
public List<StacktraceEntry> Stacktrace { get; }
public List<ModuleInfoExtended> LoadedModules { get; } = ModuleInfoHelper.GetLoadedModules().ToList();
public List<ModuleInfoExtendedWithMetadata> LoadedModules { get; } = ModuleInfoHelper.GetLoadedModules().OfType<ModuleInfoExtendedWithMetadata>().ToList();
public List<Assembly> ModuleLoadedAssemblies { get; } = new();
public List<Assembly> ExternalLoadedAssemblies { get; } = new();
public Dictionary<MethodBase, Patches> LoadedHarmonyPatches { get; } = new();
Expand Down
71 changes: 65 additions & 6 deletions src/Bannerlord.ButterLib/ExceptionHandler/HtmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
using Bannerlord.ModuleManager;

using HarmonyLib;
using HarmonyLib.BUTR.Extensions;

using Microsoft.Extensions.DependencyInjection;

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
Expand All @@ -25,7 +27,7 @@ namespace Bannerlord.ButterLib.ExceptionHandler
{
internal static class HtmlBuilder
{
private const int Version = 6;
private const int Version = 7;
private static readonly string NL = Environment.NewLine;

public static void BuildAndShow(CrashReport crashReport)
Expand All @@ -34,12 +36,19 @@ public static void BuildAndShow(CrashReport crashReport)
form.ShowDialog();
}

public static string Build(CrashReport crashReport, string miniDump) => @$"
public static string Build(CrashReport crashReport, string miniDump)
{
var launcherType = GetLauncherType();
var launcherVersion = GetLauncherVersion();
var butrLoaderVersion = GetBUTRLoaderVersion();
return @$"
<html>
<head>
<title>Bannerlord Crash Report</title>
<meta charset='utf-8'>
<game version='{ApplicationVersionHelper.GameVersionStr()}'>
<launcher type='{launcherType}' version='{launcherVersion}'>
{(string.IsNullOrEmpty(butrLoaderVersion) ? "" : $"<butrloader version='{butrLoaderVersion}'>")}
<report id='{crashReport.Id}' version='{Version}'>
<style>
.headers {{
Expand Down Expand Up @@ -116,6 +125,10 @@ Most likely this error was caused by a custom installed module.
<br/>
If you were in the middle of something, the progress might be lost.
<br/>
<br/>
Launcher: {launcherType} ({launcherVersion})
<br/>
{(string.IsNullOrEmpty(butrLoaderVersion) ? "" : $"<butrloader version='{butrLoaderVersion}'>")}
</div>
</td>
<td>
Expand Down Expand Up @@ -255,6 +268,53 @@ function minidump(element) {{
</script>
</body>
</html>";
}

private static string GetBUTRLoaderVersion()
{
if (AccessTools2.AllAssemblies().FirstOrDefault(x => x.GetName().Name == "Bannerlord.BUTRLoader") is { } bAssembly)
return bAssembly.GetName().Version.ToString();

return string.Empty;
}

private static string GetLauncherType()
{
if (Process.GetCurrentProcess().ParentProcess() is { } pProcess)
{
if (Process.GetCurrentProcess().ParentProcess()?.ProcessName == "Vortex")
return "vortex";
if (Process.GetCurrentProcess().ParentProcess()?.ProcessName == "BannerLordLauncher")
return "bannerlordlauncher";
if (Process.GetCurrentProcess().ParentProcess()?.ProcessName == "steam")
return "steam";
if (Process.GetCurrentProcess().ParentProcess()?.ProcessName == "GalaxyClient")
return "gog";
if (Process.GetCurrentProcess().ParentProcess()?.ProcessName == "EpicGamesLauncher")
return "epicgames";
if (Process.GetCurrentProcess().ParentProcess()?.ProcessName == "devenv")
return "debuggervisualstudio";
if (Process.GetCurrentProcess().ParentProcess()?.ProcessName == "JetBrains.Debugger.Worker64c")
return "debuggerjetbrains";
return $"unknown launcher - {pProcess.ProcessName}";
}

if (!string.IsNullOrEmpty(GetBUTRLoaderVersion()))
return "butrloader";

return "vanilla";
}

private static string GetLauncherVersion()
{
if (Process.GetCurrentProcess().ParentProcess() is { } pProcess)
return pProcess.MainModule?.FileVersionInfo.FileVersion ?? "0";

if (GetBUTRLoaderVersion() is { } bVersion && !string.IsNullOrEmpty(bVersion))
return bVersion;

return "0";
}

private static string GetRecursiveExceptionHtml(Exception ex) => new StringBuilder()
.AppendLine("Exception information")
Expand Down Expand Up @@ -483,20 +543,19 @@ void AppendAdditionalAssemblies(ModuleInfoExtended module)
AppendSubModules(module);
AppendAdditionalAssemblies(module);

var moduleMetadata = module as ModuleInfoExtendedWithMetadata;
var isExternal = moduleMetadata?.IsExternal == true;
moduleBuilder.AppendLine("<li>")
.AppendLine(module.IsOfficial
? "<div class=\"modules-official-container\">"
: isExternal
: module.IsExternal
? "<div class=\"modules-external-container\">"
: "<div class=\"modules-container\">")
.Append($"<b><a href='javascript:;' onclick='showHideById(this, \"{module.Id}\")'>").Append("+ ").Append(module.Name).Append(" (").Append(module.Id).Append(", ").Append(module.Version).Append(")").AppendLine("</a></b>")
.AppendLine($"<div id='{module.Id}' style='display: none'>")
.Append("Id: ").Append(module.Id).AppendLine("</br>")
.Append("Name: ").Append(module.Name).AppendLine("</br>")
.Append("Version: ").Append(module.Version).AppendLine("</br>")
.Append("External: ").Append(isExternal).AppendLine("</br>")
.Append("External: ").Append(module.IsExternal).AppendLine("</br>")
.Append("Vortex: ").Append(File.Exists(Path.Combine(module.Path, "__folder_managed_by_vortex"))).AppendLine("</br>")
.Append("Official: ").Append(module.IsOfficial).AppendLine("</br>")
.Append("Singleplayer: ").Append(module.IsSingleplayerModule).AppendLine("</br>")
.Append("Multiplayer: ").Append(module.IsMultiplayerModule).AppendLine("</br>")
Expand Down
Loading

0 comments on commit e9586d9

Please sign in to comment.