Add bugfix attributes and info

This commit is contained in:
NGnius (Graham) 2020-12-23 12:55:53 -05:00
parent e4a1c0c607
commit 42029cf0fd
4 changed files with 130 additions and 0 deletions

View file

@ -39,6 +39,7 @@ namespace CLre
// misc
LogIPAPlugins();
Fixes.BugfixAttributeUtility.LogBugfixes();
// Log info
API.Utility.Logging.MetaLog($"{Name} init complete.");

View file

@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace CLre.Fixes
{
[AttributeUsage(AttributeTargets.Class)]
public class BugfixAttribute : Attribute
{
public string name { get; set; }
public string description { get; set; }
public Type target { get; set; }
public string more { get; set; }
public uint id { get; set; }
public BugfixType component { get; set; }
}
public enum BugfixType : byte
{
Miscellaneous = 0x00,
HarmonyPatch,
Initialiser,
Workaround,
Debug
}
internal static class BugfixAttributeUtility
{
public static void LogBugfixes()
{
List<uint> keys = new List<uint>();
Dictionary<uint, BugfixStruct> fixes = new Dictionary<uint, BugfixStruct>();
foreach (Type t in Assembly.GetExecutingAssembly().GetTypes())
{
BugfixAttribute b = t.GetCustomAttribute<BugfixAttribute>(true);
if (b != null)
{
if (!fixes.ContainsKey(b.id))
{
BugfixStruct bugfixStruct = new BugfixStruct{id = b.id};
bugfixStruct.Merge(b);
fixes[b.id] = bugfixStruct;
keys.Add(b.id);
}
else
{
BugfixStruct bugfixStruct = fixes[b.id];
bugfixStruct.Merge(b);
fixes[b.id] = bugfixStruct;
}
}
}
keys.Sort();
//keys.Sort((u, u1) => u.CompareTo(u1));
StringBuilder sb = new StringBuilder();
sb.AppendFormat("Applying {0} CLre fixes\n", keys.Count);
sb.AppendFormat("-----------------------------\n");
foreach (uint i in keys)
{
sb.Append(fixes[i].ToString());
sb.Append("\n");
}
sb.AppendFormat("-----------------------------\n");
API.Utility.Logging.Log(sb.ToString());
}
private struct BugfixStruct
{
public string name;
public string description;
public Type target;
public string more;
public uint id;
private uint total;
private uint[] bugfixTypeCount;
public void Merge(BugfixAttribute b)
{
if (name == null && b.name != null) name = b.name;
if (description == null && b.description != null) description = b.description;
if (target == null && b.target != null) target = b.target;
if (more == null && b.more != null) more = b.more;
total++;
if (bugfixTypeCount == null) bugfixTypeCount = new uint[Enum.GetNames(typeof(BugfixType)).Length];
bugfixTypeCount[(byte) b.component]++;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat(" {0}: ", name);
if (more != null)
{
sb.AppendFormat("[MORE: {0}] ", more);
}
else if (description != null)
{
sb.Append(description);
sb.Append(" ");
}
if (target != null)
{
sb.AppendFormat("[TARGET: {0}] ", target.FullName);
}
sb.AppendFormat("[ID: {0}] ", id);
sb.AppendFormat("({0}M/{1}P/{2}I/{3}W/{4}D/{5}T)", bugfixTypeCount[(byte) BugfixType.Miscellaneous], bugfixTypeCount[(byte) BugfixType.HarmonyPatch], bugfixTypeCount[(byte) BugfixType.Initialiser], bugfixTypeCount[(byte) BugfixType.Workaround], bugfixTypeCount[(byte) BugfixType.Debug], total);
return sb.ToString();
}
}
}
}

View file

@ -10,6 +10,10 @@ namespace CLre.Fixes
}
[Bugfix(name = "EnchantmentTableFloatParseFix",
description = "Make all float parsing culture-invariant",
more = "https://trello.com/c/qawBFb7P/1-enchantment-table-fails-to-work",
component = BugfixType.HarmonyPatch, id = 1)]
[HarmonyPatch]
class Float_TryParse_Patch
{
@ -37,6 +41,9 @@ namespace CLre.Fixes
}
}
[Bugfix(name = "EnchantmentTableFloatParseFix",
description = "Make all float parsing culture-invariant",
component = BugfixType.HarmonyPatch, id = 1)]
[HarmonyPatch(typeof(float), "Parse", new Type[] {typeof(string)})]
class Float_Parse_Patch
{

View file

@ -7,6 +7,9 @@ using HarmonyLib;
namespace CLre.Fixes
{
[Bugfix(name = "InitLogSooner",
description = "Start the logger slightly sooner than Cardlife does",
component = BugfixType.Initialiser, id = 0)]
public static class InitLogSooner
{
public static int millisecondsTimeout = 5000;
@ -33,6 +36,9 @@ namespace CLre.Fixes
}
[Bugfix(name = "InitLogSooner",
target = typeof(CustomLoggerThread),
component = BugfixType.HarmonyPatch, id = 0)]
[HarmonyPatch(typeof(CustomLoggerThread), "CreateGameObject")]
class CustomLoggerThread_CreateGameObject_Patch
{
@ -44,6 +50,8 @@ namespace CLre.Fixes
}
}
[Bugfix(name = "InitLogSooner",
component = BugfixType.HarmonyPatch, id = 0)]
[HarmonyPatch(typeof(CustomLoggerThread), "StartQueue")]
class CustomLoggerThread_StartQueue_Patch
{