Skip to content

Commit

Permalink
Merge pull request #230 from BUTR/dev
Browse files Browse the repository at this point in the history
v2.3.0
  • Loading branch information
Aragas authored Oct 27, 2022
2 parents ed6e2ab + 731d7e7 commit 38a8d69
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 84 deletions.
6 changes: 3 additions & 3 deletions 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.10</Version>
<Version>2.3.0</Version>
<!--Harmony Version-->
<HarmonyVersion>2.2.2</HarmonyVersion>
<HarmonyExtensionsVersion>3.1.0.67</HarmonyExtensionsVersion>
Expand All @@ -14,8 +14,8 @@
<ExtensionVersion>2.0.0</ExtensionVersion>
<!--BuildResources Version-->
<BuildResourcesVersion>1.0.1.68</BuildResourcesVersion>
<BUTRSharedVersion>2.0.0.115</BUTRSharedVersion>
<BUTRModuleManagerVersion>4.0.148</BUTRModuleManagerVersion>
<BUTRSharedVersion>3.0.0.118</BUTRSharedVersion>
<BUTRModuleManagerVersion>4.0.149</BUTRModuleManagerVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---------------------------------------------------------------------------------------------------
Version: 2.3.0
Game Versions: v1.0.0
* Adapted for v1.0.0, removed legacy code
---------------------------------------------------------------------------------------------------
Version: 2.2.10
Game Versions: e1.7.2,e1.8.0,e1.8.1,e1.9.0
* Quick update for e1.9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

<PackageReference Include="Lib.Harmony" Version="$(HarmonyVersion)" IncludeAssets="compile" />

<PackageReference Include="Bannerlord.ReferenceAssemblies.Core.EarlyAccess" Version="$(GameVersion).*" PrivateAssets="all" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Native.EarlyAccess" Version="$(GameVersion).*" PrivateAssets="all" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.StoryMode.EarlyAccess" Version="$(GameVersion).*" PrivateAssets="all" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Core" Version="$(GameVersion).*" PrivateAssets="all" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Native" Version="$(GameVersion).*" PrivateAssets="all" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.StoryMode" Version="$(GameVersion).*" PrivateAssets="all" />

<PackageReference Include="IsExternalInit" Version="1.0.3" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ public override IReadOnlyList<HotKeyBase> Build()
{
var hotKeyCategoryContainer = new HotKeyCategoryContainer(_subModName, _hotKeys);

#if e172
TWHotKeyManager.Initialize(new PlatformFilePath(EngineFilePaths.ConfigsPath, "BannerlordGameKeys.xml"), new List<TaleWorlds.InputSystem.GameKeyContext> { hotKeyCategoryContainer }, true);
#elif e180 || e181 || e190
TWHotKeyManager.Initialize(new PlatformFilePath(EngineFilePaths.ConfigsPath, "BannerlordGameKeys.xml"), true);
#endif

var keys = hotKeyCategoryContainer.RegisteredGameKeys;
foreach (var hotKey in _hotKeys)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,10 @@ public void RenderDebugSphere(Vec3 position, float radius, uint color = 42949672
public void RenderDebugText(float screenX, float screenY, string text, uint color = 4294967295, float time = 0) =>
OriginalDebugManager.RenderDebugText(screenX, screenY, text, color, time);

#if !e172
public void RenderDebugRectWithColor(float left, float bottom, float right, float top, uint color = 4294967295) =>
public void RenderDebugRectWithColor(float left, float bottom, float right, float top, uint color = 4294967295) =>
OriginalDebugManager.RenderDebugRectWithColor(left, bottom, right, top, color);
#endif
#if e190

public void ReportMemoryBookmark(string message) => OriginalDebugManager.ReportMemoryBookmark(message);
#endif

public void WatchVariable(string name, object value) => OriginalDebugManager.WatchVariable(name, value);

Expand All @@ -134,6 +131,5 @@ public void ShowError(string message)

public void RenderDebugText3D(Vec3 position, string text, uint color = uint.MaxValue, int screenPosOffsetX = 0, int screenPosOffsetY = 0, float time = 0) =>
OriginalDebugManager.RenderDebugText3D(position, text, color, screenPosOffsetX, screenPosOffsetY, time);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ public void Enable()
{
IsEnabled = true;

if (ApplicationVersionHelper.GameVersion() is { Major: >= 1, Minor: >= 7 })
{
BehaviourNamePatch.Enable(_harmony);
}

BehaviourNamePatch.Enable(_harmony);
TypeExtensionsPatch.Enable(_harmony); // Adds support for saving many more container types
DefinitionContextPatch.Enable(_harmony); // Fixes save corruption & crashes when duplicate types are defined
}
Expand All @@ -40,11 +36,7 @@ public void Disable()
{
IsEnabled = false;

if (ApplicationVersionHelper.GameVersion() is { Major: >= 1, Minor: >= 7 })
{
BehaviourNamePatch.Disable(_harmony);
}

BehaviourNamePatch.Disable(_harmony);
TypeExtensionsPatch.Disable(_harmony);
DefinitionContextPatch.Disable(_harmony);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Bannerlord.ButterLib/Bannerlord.ButterLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
<Platforms>x64</Platforms>
<BUTRUploadUrl>$(BANNERLORD_BUTR_UPLOAD_URL)</BUTRUploadUrl>
<DefineConstants>$(DefineConstants);BANNERLORDBUTRSHARED_BUTTERLIB;HARMONYEXTENSIONS_DISABLE_2_0_4;X64</DefineConstants>
<GameVersion>1.7.2</GameVersion>
<DefineConstants>$(DefineConstants);BANNERLORDBUTRSHARED_BUTTERLIB;X64</DefineConstants>
<GameVersion>1.0.0</GameVersion>
</PropertyGroup>

<!--NuGet Package-->
Expand Down Expand Up @@ -41,9 +41,9 @@
<PackageReference Include="IsExternalInit" Version="1.0.3" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Harmony.Extensions" Version="$(HarmonyExtensionsVersion)" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Lib.Harmony" Version="$(HarmonyVersion)" IncludeAssets="compile" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Core.EarlyAccess" Version="$(GameVersion).*" PrivateAssets="All" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Native.EarlyAccess" Version="$(GameVersion).*" PrivateAssets="All" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.StoryMode.EarlyAccess" Version="$(GameVersion).*" PrivateAssets="All" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Core" Version="$(GameVersion).*" PrivateAssets="All" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Native" Version="$(GameVersion).*" PrivateAssets="All" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.StoryMode" Version="$(GameVersion).*" PrivateAssets="All" />
<PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(ExtensionVersion)" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="$(ExtensionVersion)" />
Expand Down
27 changes: 0 additions & 27 deletions src/Bannerlord.ButterLib/ButterLibSubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,7 @@ public ButterLibSubModule()
{
Instance = this;

ValidateGameVersion();
ValidateLoadOrder();

if (ApplicationVersionHelper.GameVersion() is { } gameVersion)
{
if (gameVersion.Major is 1 && gameVersion.Minor is 8 && gameVersion.Revision >= 0)
{
LocalizedTextManagerHelper.LoadLanguageData(ModuleInfoHelper.GetModuleByType(typeof(ButterLibSubModule)));
}
}
}

public void OnServiceRegistration()
Expand Down Expand Up @@ -182,24 +173,6 @@ public override void OnGameEnd(Game game)
Logger.LogTrace("OnGameEnd: Done");
}


private static void ValidateGameVersion()
{
var e172 = ApplicationVersionHelper.TryParse("e1.7.2", out var e172Val) ? e172Val : ApplicationVersion.Empty;
if (ApplicationVersionHelper.GameVersion() is { } gameVersion && gameVersion < e172)
{
var sb = new StringBuilder();
sb.AppendLine(new TextObject(SMessageWrongGameVersion, new() { { "GAMEVERSION", ApplicationVersionHelper.ToString(gameVersion) } }).ToString());
sb.AppendLine();
sb.AppendLine(new TextObject(SMessageContinue).ToString());
switch (MessageBox.Show(sb.ToString(), new TextObject(SWarningTitle).ToString(), MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, (MessageBoxOptions) 0x40000))
{
case DialogResult.Yes:
Environment.Exit(1);
break;
}
}
}
private static void ValidateLoadOrder()
{
var loadedModules = ModuleInfoHelper.GetLoadedModules().ToList();
Expand Down
2 changes: 2 additions & 0 deletions src/Bannerlord.ButterLib/ExceptionHandler/HtmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ private static string GetLauncherType()
return "debuggervisualstudio";
if (Process.GetCurrentProcess().ParentProcess()?.ProcessName == "JetBrains.Debugger.Worker64c")
return "debuggerjetbrains";
if (Process.GetCurrentProcess().ParentProcess()?.ProcessName == "explorer")
return "explorer";
return $"unknown launcher - {pProcess.ProcessName}";
}

Expand Down
8 changes: 4 additions & 4 deletions src/Bannerlord.ButterLib/ExceptionHandler/MiniDump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static extern bool MiniDumpWriteDump(IntPtr hProcess, uint ProcessId, Saf
[In] ref MINIDUMP_CALLBACK_INFORMATION CallbackParam);

[Flags]
public enum MINIDUMP_TYPE: int
public enum MINIDUMP_TYPE : int
{
MiniDumpNormal = 0x00000000,
MiniDumpWithDataSegs = 0x00000001,
Expand Down Expand Up @@ -132,9 +132,9 @@ public struct MINIDUMP_USER_STREAM_INFORMATION
{
public MINIDUMP_USER_STREAM_INFORMATION(params MINIDUMP_USER_STREAM[] streams)
{
UserStreamCount = (uint)streams.Length;
UserStreamCount = (uint) streams.Length;
int sizeOfStream = Marshal.SizeOf(typeof(MINIDUMP_USER_STREAM));
UserStreamArray = Marshal.AllocHGlobal((int)(UserStreamCount * sizeOfStream));
UserStreamArray = Marshal.AllocHGlobal((int) (UserStreamCount * sizeOfStream));
for (int i = 0; i < streams.Length; ++i)
{
Marshal.StructureToPtr(streams[i], UserStreamArray + (i * sizeOfStream), false);
Expand Down Expand Up @@ -406,7 +406,7 @@ public struct Info
{
public uint ThreadId;
}

private static bool Write(SafeHandle file, MINIDUMP_TYPE dumpType, MINIDUMP_CALLBACK_ROUTINE callbackRoutine)
{
using var process = Process.GetCurrentProcess();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Bannerlord.BUTR.Shared.Helpers;
using Bannerlord.ButterLib.Logger;
using Bannerlord.ButterLib.Logger;
using Bannerlord.ButterLib.Options;
using Bannerlord.ButterLib.SubSystems;

Expand All @@ -25,6 +24,8 @@

using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
using TaleWorlds.Engine;
using TaleWorlds.Library;
using TaleWorlds.MountAndBlade;

using Path = System.IO.Path;
Expand Down Expand Up @@ -58,7 +59,7 @@ public static class DependencyInjectionExtensions
/// </summary>
public static IServiceProvider? GetTempServiceProvider(this MBSubModuleBase _) => ButterLibSubModule.Services?.BuildServiceProvider();

private static readonly string ModLogsPath = Path.Combine(FSIOHelper.GetConfigPath()!, "ModLogs");
private static readonly string ModLogsPath = Path.Combine(EngineFilePaths.ConfigsPath.Path, "ModLogs");
private static readonly string OutputTemplate = "[{Timestamp:o}] [{SourceContext}] [{Level:u3}]: {Message:lj}{NewLine}{Exception}";

internal static IServiceCollection? AddDefaultSerilogLogger(this MBSubModuleBase subModule)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static void SetNumericVariable(TextObject? textObject, string tag, float
}
}

private static Dictionary<string, TextObject?> GetListAttributes(IEnumerable<string> valuesList, string separator = ", ", bool useDistinctValues = true)
private static Dictionary<string, object?> GetListAttributes(IEnumerable<string> valuesList, string separator = ", ", bool useDistinctValues = true)
{
var localValues = (useDistinctValues ? valuesList.Distinct() : valuesList).ToList();
return localValues.Any()
Expand Down Expand Up @@ -345,7 +345,7 @@ public static void SetListVariable(TextObject? textObject, string tag, List<stri
return;
}
var attributes = GetListAttributes(valuesList, separator, useDistinctValues);
var explainedTextObject = TextObjectHelper.Create(BUILT_IN_AGGREGATION_STRING, attributes);
var explainedTextObject = new TextObject(BUILT_IN_AGGREGATION_STRING, attributes);
if (textObject is null)
{
MBTextManager.SetTextVariable(tag, explainedTextObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void LogAndDisplay(this ILogger logger, LogLevel logLevel, Excepti
{
var formattedValues = new FormattedLogValues(message, args);
logger.Log(logLevel, 0, formattedValues, exception, MessageFormatter);
InformationManagerHelper.DisplayMessage($"{logLevel}: {formattedValues}", logLevel switch
InformationManager.DisplayMessage(new InformationMessage($"{logLevel}: {formattedValues}", logLevel switch
{
LogLevel.Trace => Color.FromUint(0x00FFFFFF), // white
LogLevel.Debug => Color.FromUint(0x00808080), // grey
Expand All @@ -30,7 +30,7 @@ public static void LogAndDisplay(this ILogger logger, LogLevel logLevel, Excepti
LogLevel.Critical => Color.FromUint(0x008B0000), // dark red
LogLevel.None => Color.White,
_ => throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, null)
});
}));
}

public static void LogTraceAndDisplay(this ILogger logger, string message, params object[] args) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
using System;
using System.IO;

using TaleWorlds.Engine;

namespace Bannerlord.ButterLib.Options
{
[JsonObject(MemberSerialization.OptIn)]
internal sealed class JsonButterLibOptionsModel
{
//private static readonly string Path = System.IO.Path.Combine(Utilities.GetConfigsPath(), "ModSettings/Global/ButterLib/ButterLib_v1.json");
private static readonly string Path = System.IO.Path.Combine(FSIOHelper.GetConfigPath()!, "ModSettings/ButterLib/Options.json");
private static readonly string Path = System.IO.Path.Combine(EngineFilePaths.ConfigsPath.Path, "ModSettings/ButterLib/Options.json");

[JsonProperty("MinLogLevel", DefaultValueHandling = DefaultValueHandling.Populate)]
public int MinLogLevel { get; private set; } = (int) LogLevel.Information;
Expand Down
5 changes: 1 addition & 4 deletions supported-game-versions.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
e1.9.0
e1.8.1
e1.8.0
e1.7.2
v1.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ private static bool MockedGetSettlementAll(ref MBReadOnlyList<Settlement> __resu
public void Setup()
{
var harmony = new Harmony($"{nameof(DependencyInjectionTests)}.{nameof(Setup)}");
harmony.Patch(SymbolExtensions2.GetMethodInfo(() => FSIOHelper.GetConfigPath()),
prefix: new HarmonyMethod(DelegateHelper.GetMethodInfo(MockedGetConfigPath)));
//harmony.Patch(SymbolExtensions2.GetMethodInfo(() => FSIOHelper.GetConfigPath()),
// prefix: new HarmonyMethod(DelegateHelper.GetMethodInfo(MockedGetConfigPath)));
harmony.Patch(SymbolExtensions2.GetPropertyInfo(() => TWCommon.ConfigName!)!.GetMethod,
prefix: new HarmonyMethod(DelegateHelper.GetMethodInfo(MockedGetConfigName)));
var engineUtilitiesType = Type.GetType("TaleWorlds.Engine.Utilities, TaleWorlds.Engine", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ namespace Bannerlord.ButterLib.Tests
public class ApplicationVersionUtilsTests
{
private static readonly string TestAppVersionStr = "e1.4.3.231432";
#if e172
private static readonly ApplicationVersion TestAppVersion = ApplicationVersion.FromString("e1.4.3.231432", TaleWorlds.Library.ApplicationVersionGameType.Singleplayer);
#elif e180 || e181 || e190
private static readonly ApplicationVersion TestAppVersion = ApplicationVersion.FromString("e1.4.3.231432");
#endif

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool MockedGetVersionStr(ref string __result)
Expand All @@ -39,7 +35,7 @@ public void GameVersion_Test()
{
var gameVersion = ApplicationVersionHelper.GameVersion();
Assert.NotNull(gameVersion);
Assert.AreEqual(TestAppVersion, gameVersion);
Assert.AreEqual(TestAppVersion, gameVersion.Value);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ private static bool MockedGetConfigPath(ref string __result)
public void Setup()
{
var harmony = new Harmony($"{nameof(JsonSerializationTests)}.{nameof(Setup)}");
harmony.Patch(SymbolExtensions.GetMethodInfo(() => FSIOHelper.GetConfigPath()),
prefix: new HarmonyMethod(DelegateHelper.GetMethodInfo(MockedGetConfigPath)));
//harmony.Patch(SymbolExtensions.GetMethodInfo(() => FSIOHelper.GetConfigPath()),
// prefix: new HarmonyMethod(DelegateHelper.GetMethodInfo(MockedGetConfigPath)));

var binFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
var d1 = Directory.GetFiles(binFolder, "TaleWorlds*.dll");
var d2 = Directory.GetFiles(binFolder, "StoryMode*.dll");
var d3 = Directory.GetFiles(binFolder, "SandBox*.dll");

foreach (string dll in d1.Concat(d2).Concat(d3))
foreach (var dll in d1.Concat(d2).Concat(d3))
Assembly.LoadFile(dll);
}

Expand Down

0 comments on commit 38a8d69

Please sign in to comment.