Skip to content

Commit

Permalink
Merge pull request #61 from BUTR/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Aragas authored Jun 18, 2022
2 parents b2f8e03 + 0ea6e0f commit 5f3b222
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 34 deletions.
10 changes: 9 additions & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<!--Module Version-->
<Version>0.0.1.0</Version>
<!--Harmony Version-->
<HarmonyExtensionsVersion>3.1.0.61</HarmonyExtensionsVersion>
<HarmonyVersion>2.2.1</HarmonyVersion>
<!--BuildResources Version-->
<HarmonyAnalyzerVersion>1.0.1.42</HarmonyAnalyzerVersion>
<BuildResourcesVersion>1.0.1.68</BuildResourcesVersion>
<BUTRAnalyzerVersion>1.0.1.12</BUTRAnalyzerVersion>
<BUTRSharedVersion>2.0.0.82</BUTRSharedVersion>
Expand Down Expand Up @@ -59,4 +60,11 @@
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(GITHUB_ACTIONS)' != 'true'">
<PackageReference Include="BUTR.Harmony.Analyzer" Version="$(HarmonyAnalyzerVersion)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Bannerlord.Harmony/Bannerlord.Harmony.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<PackageReference Include="Bannerlord.BUTR.Shared" Version="$(BUTRSharedVersion)" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Bannerlord.ModuleManager.Source" Version="$(BUTRModuleManagerVersion)" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Core.EarlyAccess" Version="$(GameVersion).*" PrivateAssets="All" />
<PackageReference Include="Harmony.Extensions" Version="3.0.0.58" />
<PackageReference Include="Harmony.Extensions" Version="$(HarmonyExtensionsVersion)" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Lib.Harmony" Version="$(HarmonyVersion)" />
<PackageReference Include="IsExternalInit" Version="1.0.2" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Nullable" Version="1.3.0" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
Expand Down
14 changes: 0 additions & 14 deletions src/Bannerlord.Harmony/Helpers/InformationMessageWrapper.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Bannerlord.Harmony/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"Bannerlord": {
"commandName": "Executable",
"executablePath": "$(GameFolder)\\bin\\Win64_Shipping_Client\\Bannerlord.exe",
"commandLineArgs": "/singleplayer _MODULES_*Bannerlord.Harmony*Native*SandBoxCore*CustomBattle*Sandbox*StoryMode*_MODULES_",
"commandLineArgs": "/singleplayer _MODULES_*$(ModuleId)*Native*SandBoxCore*CustomBattle*Sandbox*StoryMode*_MODULES_",
"workingDirectory": "$(GameFolder)\\bin\\Win64_Shipping_Client"
},
"BannerlordWithMCM": {
"commandName": "Executable",
"executablePath": "$(GameFolder)\\bin\\Win64_Shipping_Client\\Bannerlord.exe",
"commandLineArgs": "/singleplayer _MODULES_*Bannerlord.Harmony*Bannerlord.ButterLib*Bannerlord.UIExtenderEx*Bannerlord.MBOptionScreen*Native*SandBoxCore*CustomBattle*Sandbox*StoryMode*_MODULES_",
"commandLineArgs": "/singleplayer _MODULES_*$(ModuleId)*Bannerlord.ButterLib*Bannerlord.UIExtenderEx*Bannerlord.MBOptionScreen*Native*SandBoxCore*CustomBattle*Sandbox*StoryMode*_MODULES_",
"workingDirectory": "$(GameFolder)\\bin\\Win64_Shipping_Client"
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Bannerlord.Harmony/SubModule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Bannerlord.BUTR.Shared.Helpers;
using Bannerlord.Harmony.Helpers;
using Bannerlord.Harmony.Utils;

using HarmonyLib;

Expand Down Expand Up @@ -96,11 +96,11 @@ private static void CheckLoadOrder()
var harmonyModule = loadedModules.SingleOrDefault(x => x.Id == "Bannerlord.Harmony");
var harmonyModuleIndex = harmonyModule is not null ? loadedModules.IndexOf(harmonyModule) : -1;
if (harmonyModuleIndex == -1)
InformationManagerHelper.DisplayMessage(InformationMessageHelper.Create(TextObjectHelper.Create(SErrorHarmonyNotFound)?.ToString() ?? "ERROR", Color.FromUint(COLOR_RED)));
InformationManagerUtils.DisplayMessage(InformationMessageUtils.Create(TextObjectHelper.Create(SErrorHarmonyNotFound)?.ToString() ?? "ERROR", Color.FromUint(COLOR_RED)));
if (harmonyModuleIndex != 0)
{
var textObject = TextObjectHelper.Create(SErrorHarmonyNotFirst)?.SetTextVariable2("EXPECT_ISSUES_WARNING", GetExpectIssuesWarning());
InformationManagerHelper.DisplayMessage(InformationMessageHelper.Create(textObject?.ToString() ?? "ERROR", Color.FromUint(COLOR_RED)));
InformationManagerUtils.DisplayMessage(InformationMessageUtils.Create(textObject?.ToString() ?? "ERROR", Color.FromUint(COLOR_RED)));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
using HarmonyLib.BUTR.Extensions;

using System;
using System.Linq;
using System.Reflection;

namespace Bannerlord.Harmony.Helpers
namespace Bannerlord.Harmony.Utils
{
internal static class InformationManagerHelper
internal static class InformationManagerUtils
{
private delegate void DisplayMessageV1Delegate(object data);

private static readonly DisplayMessageV1Delegate? DisplayMessageV1;

static InformationManagerHelper()
static InformationManagerUtils()
{
var type = AccessTools2.TypeByName("TaleWorlds.Core.InformationManager") ?? AccessTools2.TypeByName("TaleWorlds.Library.InformationManager");
foreach (var methodInfo in HarmonyLib.AccessTools.GetDeclaredMethods(type))
var type = AccessTools2.TypeByName("TaleWorlds.Core.InformationManager") ??
AccessTools2.TypeByName("TaleWorlds.Library.InformationManager");
foreach (var methodInfo in HarmonyLib.AccessTools.GetDeclaredMethods(type) ?? Enumerable.Empty<MethodInfo>())
{
var @params = methodInfo.GetParameters();
if (@params.Length == 1 && @params[0].ParameterType.Name.Equals("InformationMessage", StringComparison.Ordinal))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
using HarmonyLib;
using HarmonyLib.BUTR.Extensions;

using System.Linq;
using System.Reflection;

using TaleWorlds.Library;

namespace Bannerlord.Harmony.Helpers
namespace Bannerlord.Harmony.Utils
{
internal static class InformationMessageHelper
internal static class InformationMessageUtils
{
private delegate object V1Delegate(string information, Color color);
private static readonly V1Delegate? V1;

static InformationMessageHelper()
static InformationMessageUtils()
{
var type = AccessTools2.TypeByName("TaleWorlds.Core.InformationMessage") ?? AccessTools2.TypeByName("TaleWorlds.Library.InformationMessage");
foreach (var constructorInfo in AccessTools.GetDeclaredConstructors(type, false))
var type = AccessTools2.TypeByName("TaleWorlds.Core.InformationMessage") ??
AccessTools2.TypeByName("TaleWorlds.Library.InformationMessage");
foreach (var constructorInfo in AccessTools.GetDeclaredConstructors(type, false) ?? Enumerable.Empty<ConstructorInfo>())
{
var @params = constructorInfo.GetParameters();
if (@params.Length == 9)
if (@params.Length == 2 && @params[0].ParameterType == typeof(string) && @params[1].ParameterType == typeof(Color))
{
V1 = AccessTools2.GetDelegate<V1Delegate>(constructorInfo);
}
Expand All @@ -27,8 +31,7 @@ static InformationMessageHelper()
{
if (V1 is not null)
{
var obj = V1(information, color);
return InformationMessageWrapper.Create(obj);
return InformationMessageWrapper.Create(V1(information, color));
}

return null;
Expand Down
7 changes: 7 additions & 0 deletions src/Bannerlord.Harmony/Utils/InformationMessageWrapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Bannerlord.Harmony.Utils
{
internal record InformationMessageWrapper(object Object)
{
public static InformationMessageWrapper Create(object @object) => new(@object);
}
}

0 comments on commit 5f3b222

Please sign in to comment.