Skip to content

Commit

Permalink
Merge pull request #52 from BUTR/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Aragas authored Jun 11, 2022
2 parents ac2a148 + 31807de commit b2f8e03
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 43 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/check-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ jobs:
with:
github-token: ${{secrets.GITHUB_TOKEN}}

- name: Run VersionChecker (Release)
- name: Run VersionChecker
id: status
run: >-
dotnet build ./build/VersionChecker/VersionChecker.csproj --configuration Release;
$status = dotnet run --project ./build/VersionChecker/VersionChecker.csproj --no-build --configuration Release ;
$status = dotnet run --project ./build/VersionChecker/VersionChecker.csproj --no-build --configuration Release;
echo "::set-env name=newer_version_status::$status";
shell: pwsh

- name: Log has_newer_version
run: echo "::warning ::newer_version_status=${{steps.status.outputs.newer_version_status}}"
shell: pwsh

- name: Trigger publish-on-nexusmods
- name: Trigger publish
if: steps.status.outputs.newer_version_status == '0'
uses: peter-evans/repository-dispatch@v2
with:
token: ${{secrets.REPO_ACCESS_TOKEN}}
repository: BUTR/Bannerlord.Harmony
event-type: publish-on-nexusmods
event-type: publish
client-payload: '{"github": ${{ toJson(github) }}}'
12 changes: 6 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- 'build/**'
- 'src/Bannerlord.Harmony/**'
repository_dispatch:
types: publish-on-nexusmods
types: publish

env:
# Disable the .NET logo in the console output.
Expand All @@ -28,14 +28,14 @@ jobs:
with:
github-token: ${{secrets.GITHUB_TOKEN}}

- name: Build Bannerlord.Harmony (Release)
- name: Build Bannerlord.Harmony
run: >-
mkdir bannerlord;
dotnet build src/Bannerlord.Harmony/Bannerlord.Harmony.csproj --configuration Release -p:GameFolder="$PWD/bannerlord";
shell: pwsh

- name: Upload Bannerlord folder
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: bannerlord
path: ./bannerlord/
Expand All @@ -55,7 +55,7 @@ jobs:
github-token: ${{secrets.GITHUB_TOKEN}}

- name: Download bannerlord folder
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: bannerlord
path: ./bannerlord
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
shell: pwsh

- name: Upload Screenshots Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: Screenshots
path: Screenshots.7z
Expand All @@ -113,7 +113,7 @@ jobs:
github-token: ${{secrets.GITHUB_TOKEN}}

- name: Download bannerlord folder
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: bannerlord
path: ./bannerlord
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<a href="https://www.nexusmods.com/mountandblade2bannerlord/mods/2006" alt="NexusMods Harmony">
<img src="https://img.shields.io/endpoint?url=https%3A%2F%2Fnexusmods-downloads-ayuqql60xfxb.runkit.sh%2F%3Ftype%3Dviews%26gameId%3D3174%26modId%3D2006" />
</a>
</br>
<img src="https://staticdelivery.nexusmods.com/mods/3174/images/2006/2006-1615240039-1903390080.png" width="800">
</p>

This is an unofficial distribution of the [Harmony](https://github.com/pardeike/Harmony) library maintained by the community to have an easier way to manage external library dependencies.
Expand All @@ -34,6 +36,8 @@ This module should be the highest in loading order. Any other module that requir
This mod is intended to ensure that all mods in a player's modlist are using the latest version of Harmony to minimize conflicts.

## For Modders
**We added a Debug UI! Available via CTRL+ALT+H.**

You still need to reference Harmony as a NuGet package, it is not required to include ``0Harmony.dll`` in the final /bin output of your module.
You do need to add this to your ``SubModule.xml``
```xml
Expand Down
5 changes: 3 additions & 2 deletions build/VersionChecker/VersionChecker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<HarmonyVersion>2.2.1</HarmonyVersion>
<!--BuildResources Version-->
<BuildResourcesVersion>1.0.1.68</BuildResourcesVersion>
<BUTRAnalyzerVersion>1.0.1.9</BUTRAnalyzerVersion>
<BUTRSharedVersion>2.0.0.78</BUTRSharedVersion>
<BUTRModuleManagerVersion>3.0.94</BUTRModuleManagerVersion>
<BUTRAnalyzerVersion>1.0.1.12</BUTRAnalyzerVersion>
<BUTRSharedVersion>2.0.0.82</BUTRSharedVersion>
<BUTRModuleManagerVersion>3.0.97</BUTRModuleManagerVersion>
<!--Current Bannerlord Version-->
<GameVersion>1.1.0</GameVersion>
<!--Bannerlord's Root Folder. Leave empty if you want it to be tried to be autoresolved.-->
Expand Down
40 changes: 20 additions & 20 deletions src/Bannerlord.Harmony.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,28 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VersionChecker", "..\build\
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Beta_Debug|Any CPU = Beta_Debug|Any CPU
Beta_Release|Any CPU = Beta_Release|Any CPU
Stable_Debug|Any CPU = Stable_Debug|Any CPU
Stable_Release|Any CPU = Stable_Release|Any CPU
Beta_Release|x64 = Beta_Release|x64
Stable_Debug|x64 = Stable_Debug|x64
Stable_Release|x64 = Stable_Release|x64
Beta_Debug|x64 = Beta_Debug|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Beta_Debug|Any CPU.ActiveCfg = Beta_Debug|Any CPU
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Beta_Debug|Any CPU.Build.0 = Beta_Debug|Any CPU
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Beta_Release|Any CPU.ActiveCfg = Beta_Release|Any CPU
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Beta_Release|Any CPU.Build.0 = Beta_Release|Any CPU
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Stable_Debug|Any CPU.ActiveCfg = Stable_Debug|Any CPU
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Stable_Debug|Any CPU.Build.0 = Stable_Debug|Any CPU
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Stable_Release|Any CPU.ActiveCfg = Stable_Release|Any CPU
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Stable_Release|Any CPU.Build.0 = Stable_Release|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Beta_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Beta_Debug|Any CPU.Build.0 = Debug|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Beta_Release|Any CPU.ActiveCfg = Release|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Beta_Release|Any CPU.Build.0 = Release|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Stable_Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Stable_Debug|Any CPU.Build.0 = Debug|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Stable_Release|Any CPU.ActiveCfg = Release|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Stable_Release|Any CPU.Build.0 = Release|Any CPU
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Beta_Release|x64.ActiveCfg = Beta_Release|x64
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Beta_Release|x64.Build.0 = Beta_Release|x64
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Stable_Debug|x64.ActiveCfg = Stable_Debug|x64
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Stable_Debug|x64.Build.0 = Stable_Debug|x64
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Stable_Release|x64.ActiveCfg = Stable_Release|x64
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Stable_Release|x64.Build.0 = Stable_Release|x64
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Beta_Debug|x64.ActiveCfg = Beta_Debug|x64
{8F7DF9CA-28B6-43DD-AD0D-12E916E8CEED}.Beta_Debug|x64.Build.0 = Beta_Debug|x64
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Beta_Release|x64.ActiveCfg = Release|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Beta_Release|x64.Build.0 = Release|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Stable_Debug|x64.ActiveCfg = Debug|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Stable_Debug|x64.Build.0 = Debug|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Stable_Release|x64.ActiveCfg = Release|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Stable_Release|x64.Build.0 = Release|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Beta_Debug|x64.ActiveCfg = Debug|Any CPU
{7CD86F86-0C46-4695-953B-5634AF718E5B}.Beta_Debug|x64.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
13 changes: 8 additions & 5 deletions src/Bannerlord.Harmony/Bannerlord.Harmony.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>net472</TargetFramework>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
<Platforms>x64</Platforms>

<Configurations>Stable_Debug;Stable_Release;Beta_Debug;Beta_Release</Configurations>
</PropertyGroup>
Expand All @@ -18,18 +19,20 @@

<!--Windows Forms-->
<ItemGroup>
<_SDKImplicitReference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<!--Windows Forms-->

<ItemGroup>
<PackageReference Include="Bannerlord.BuildResources" Version="$(BuildResourcesVersion)" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive"/>
<PackageReference Include="Bannerlord.BUTR.Analyzers" Version="$(BUTRAnalyzerVersion)" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive"/>
<PackageReference Include="Bannerlord.BUTR.Shared" Version="$(BUTRSharedVersion)" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive"/>
<PackageReference Include="Bannerlord.BuildResources" Version="$(BuildResourcesVersion)" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<PackageReference Include="Bannerlord.BUTR.Analyzers" Version="$(BUTRAnalyzerVersion)" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
<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="Lib.Harmony" Version="$(HarmonyVersion)" />
<PackageReference Include="IsExternalInit" Version="1.0.2" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive"/>
<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" />
</ItemGroup>

<Target Name="SetVersion" BeforeTargets="PrepareForBuild" DependsOnTargets="RunResolvePackageDependencies">
Expand Down
37 changes: 37 additions & 0 deletions src/Bannerlord.Harmony/Helpers/InformationManagerHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using HarmonyLib.BUTR.Extensions;

using System;

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

private static readonly DisplayMessageV1Delegate? DisplayMessageV1;

static InformationManagerHelper()
{
var type = AccessTools2.TypeByName("TaleWorlds.Core.InformationManager") ?? AccessTools2.TypeByName("TaleWorlds.Library.InformationManager");
foreach (var methodInfo in HarmonyLib.AccessTools.GetDeclaredMethods(type))
{
var @params = methodInfo.GetParameters();
if (@params.Length == 1 && @params[0].ParameterType.Name.Equals("InformationMessage", StringComparison.Ordinal))
{
DisplayMessageV1 = AccessTools2.GetDelegate<DisplayMessageV1Delegate>(methodInfo);
}
}
}

public static void DisplayMessage(InformationMessageWrapper? message)
{
if (message is null)
return;

if (DisplayMessageV1 is not null)
{
DisplayMessageV1(message.Object);
}
}
}
}
37 changes: 37 additions & 0 deletions src/Bannerlord.Harmony/Helpers/InformationMessageHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using HarmonyLib;
using HarmonyLib.BUTR.Extensions;

using TaleWorlds.Library;

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

static InformationMessageHelper()
{
var type = AccessTools2.TypeByName("TaleWorlds.Core.InformationMessage") ?? AccessTools2.TypeByName("TaleWorlds.Library.InformationMessage");
foreach (var constructorInfo in AccessTools.GetDeclaredConstructors(type, false))
{
var @params = constructorInfo.GetParameters();
if (@params.Length == 9)
{
V1 = AccessTools2.GetDelegate<V1Delegate>(constructorInfo);
}
}
}

public static InformationMessageWrapper? Create(string information, Color color)
{
if (V1 is not null)
{
var obj = V1(information, color);
return InformationMessageWrapper.Create(obj);
}

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

public object Object { get; }

private InformationMessageWrapper(object @object)
{
Object = @object;
}
}
}
6 changes: 3 additions & 3 deletions src/Bannerlord.Harmony/SubModule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bannerlord.BUTR.Shared.Helpers;
using Bannerlord.Harmony.Helpers;

using HarmonyLib;

Expand All @@ -11,7 +12,6 @@
using System.Threading.Tasks;
using System.Windows.Forms;

using TaleWorlds.Core;
using TaleWorlds.Engine;
using TaleWorlds.InputSystem;
using TaleWorlds.Library;
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)
InformationManager.DisplayMessage(new InformationMessage(TextObjectHelper.Create(SErrorHarmonyNotFound)?.ToString() ?? "ERROR", Color.FromUint(COLOR_RED)));
InformationManagerHelper.DisplayMessage(InformationMessageHelper.Create(TextObjectHelper.Create(SErrorHarmonyNotFound)?.ToString() ?? "ERROR", Color.FromUint(COLOR_RED)));
if (harmonyModuleIndex != 0)
{
var textObject = TextObjectHelper.Create(SErrorHarmonyNotFirst)?.SetTextVariable2("EXPECT_ISSUES_WARNING", GetExpectIssuesWarning());
InformationManager.DisplayMessage(new InformationMessage(textObject?.ToString() ?? "ERROR", Color.FromUint(COLOR_RED)));
InformationManagerHelper.DisplayMessage(InformationMessageHelper.Create(textObject?.ToString() ?? "ERROR", Color.FromUint(COLOR_RED)));
}
}

Expand Down

0 comments on commit b2f8e03

Please sign in to comment.