-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from BUTR/dev
Release
- Loading branch information
Showing
11 changed files
with
139 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/Bannerlord.Harmony/Helpers/InformationManagerHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
src/Bannerlord.Harmony/Helpers/InformationMessageHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
src/Bannerlord.Harmony/Helpers/InformationMessageWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters