-
-
Notifications
You must be signed in to change notification settings - Fork 12
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 #226 from Aragas/dev
v4.7.2
- Loading branch information
Showing
13 changed files
with
127 additions
and
72 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
39 changes: 39 additions & 0 deletions
39
src/MCM.Adapter.ModLibV1.Substitute/Utils/InformationManagerUtils.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,39 @@ | ||
using HarmonyLib.BUTR.Extensions; | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace ModLib.Utils | ||
{ | ||
internal static class InformationManagerUtils | ||
{ | ||
private delegate void DisplayMessageV1Delegate(object data); | ||
private static readonly DisplayMessageV1Delegate? DisplayMessageV1; | ||
|
||
static InformationManagerUtils() | ||
{ | ||
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)) | ||
{ | ||
DisplayMessageV1 = AccessTools2.GetDelegate<DisplayMessageV1Delegate>(methodInfo); | ||
} | ||
} | ||
} | ||
|
||
public static void DisplayMessage(InformationMessageWrapper? message) | ||
{ | ||
if (message is null) | ||
return; | ||
|
||
if (DisplayMessageV1 is not null) | ||
{ | ||
DisplayMessageV1(message.Object); | ||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/MCM.Adapter.ModLibV1.Substitute/Utils/InformationMessageUtils.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,41 @@ | ||
using HarmonyLib; | ||
using HarmonyLib.BUTR.Extensions; | ||
|
||
using System.Linq; | ||
using System.Reflection; | ||
|
||
using TaleWorlds.Library; | ||
|
||
namespace ModLib.Utils | ||
{ | ||
internal static class InformationMessageUtils | ||
{ | ||
private delegate object CtorV1Delegate(string information, Color color); | ||
private static readonly CtorV1Delegate? V1; | ||
|
||
static InformationMessageUtils() | ||
{ | ||
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 == 2 && @params[0].ParameterType == typeof(string) && @params[1].ParameterType == typeof(Color)) | ||
{ | ||
V1 = AccessTools2.GetDelegate<CtorV1Delegate>(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; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/MCM.Adapter.ModLibV1.Substitute/Utils/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,7 @@ | ||
namespace ModLib.Utils | ||
{ | ||
internal sealed record InformationMessageWrapper(object Object) | ||
{ | ||
public static InformationMessageWrapper Create(object @object) => new(@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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,7 @@ | ||
namespace MCM.Utils | ||
{ | ||
public sealed class InformationMessageWrapper | ||
public sealed record InformationMessageWrapper(object Object) | ||
{ | ||
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