Skip to content

Commit

Permalink
v4.0.7 (#73)
Browse files Browse the repository at this point in the history
* Update test-and-publish.yml

* Sorted

Fixed

* Fixed MCMv3 and ModLib v1/v13 - Instance in OnSubModuleLoad returned null

Removed MBO project
Made some properties computable
Added DependedModuleMetadata prototype

* Removed the interfaces, the behavior of ModLib and MCMv3 with v4 is too different .

* Using reverse patch instead of replication of WidgetPrefab.LoadFrom

Better reflection overall
Returned Implementation Loader

* Test fix

* Fixed ModLib Compatibility Layer issues

* Internalized types

Sealed types
Removed BaseSettingsProvider.GetSettingsObject
Minor formatting

* Added ButterLib settings

Added loggers in MCM.Implementation
Switched to hardcoded UI and Implementations again

* Split path in ISettingsFormat

Fixed OptionsVMMixin not triggering on Escape
Added PropertyChangedWithValue for Dropdown
Fixed SetSelectedIndexAction
Added json2 format that handles Dropdown as an integer
Fancier reflection
Fixed tests
Updated version

* Test fix 2

* Update README.md

* Update README.md

* Added NoInlining for Harmony related stuff

Fixed missing Option menu
  • Loading branch information
Aragas authored Sep 12, 2020
1 parent 078f0e1 commit 168c5db
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<Version>4.0.6</Version>
<Version>4.0.7</Version>
<GameVersion>1.4.3</GameVersion>
<HarmonyVersion>2.0.2</HarmonyVersion>
<ButterLibVersion>1.0.8</ButterLibVersion>
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: 4.0.7
Game Versions: e1.4.3,e1.5.0,e1.5.1,e1.5.2
* Fixed missing ModOptions menu in Options screen
---------------------------------------------------------------------------------------------------
Version: 4.0.6
Game Versions: e1.4.3,e1.5.0,e1.5.1
* Added ButterLib settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HarmonyLib;

using System.Collections.Generic;
using System.Runtime.CompilerServices;

using TaleWorlds.MountAndBlade;

Expand Down Expand Up @@ -31,6 +32,7 @@ public static void Patch(Harmony harmony)
}

// Prevent any Integrated MCMv3 from loading
[MethodImpl(MethodImplOptions.NoInlining)]
private static bool StopIntegratedLoaderSubModuleCtor(MCMv3IntegratedLoaderSubModule __instance)
{
_loader(__instance) = new EmptyIntegratedLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;

using TaleWorlds.Engine.Screens;
using TaleWorlds.Library;
Expand All @@ -29,6 +30,7 @@ public DefaultGameMenuScreenHandler()
postfix: new HarmonyMethod(AccessTools.Method(typeof(DefaultGameMenuScreenHandler), nameof(Constructor)), 300));
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Constructor(InitialMenuVM __instance, ref MBBindingList<InitialMenuOptionVM> ____menuOptions)
{
_instance.SetTarget(__instance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

using TaleWorlds.Engine.Screens;
using TaleWorlds.Localization;
Expand Down Expand Up @@ -58,6 +59,7 @@ public DefaultIngameMenuScreenHandler()
postfix: new HarmonyMethod(AccessTools.Method(typeof(DefaultIngameMenuScreenHandler), nameof(OnMissionScreenFinalize)), 300));
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void MapScreen_GetEscapeMenuItems(MapScreen __instance, ref List<EscapeMenuItemVM> __result)
{
foreach (var (key, value) in ScreensCache)
Expand All @@ -77,6 +79,7 @@ private static void MapScreen_GetEscapeMenuItems(MapScreen __instance, ref List<
key, false, false));
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void MissionSingleplayerEscapeMenu_GetEscapeMenuItems(GauntletMissionEscapeMenuBase __instance, ref List<EscapeMenuItemVM> __result)
{
foreach (var (key, value) in ScreensCache)
Expand All @@ -96,13 +99,15 @@ private static void MissionSingleplayerEscapeMenu_GetEscapeMenuItems(GauntletMis
key, false, false));
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void OnMissionScreenInitialize(MissionView __instance)
{
if (__instance is GauntletMissionEscapeMenuBase gauntletMissionEscapeMenuBase)
{
_instance.SetTarget(DataSource(gauntletMissionEscapeMenuBase));
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void OnMissionScreenFinalize(MissionView __instance)
{
if (__instance is GauntletMissionEscapeMenuBase)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using MCM.Abstractions.Settings.Base;

namespace MCM.Implementation.Settings.Properties
{
Expand Down
3 changes: 3 additions & 0 deletions src/MCM.Tests/DependencyInjectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;

using TaleWorlds.Engine;
using TaleWorlds.Library;
Expand All @@ -26,12 +27,14 @@ namespace MCM.Tests
{
public class DependencyInjectionTests
{
[MethodImpl(MethodImplOptions.NoInlining)]
private static bool MockedGetConfigsPath(ref string __result)
{
__result = AppDomain.CurrentDomain.BaseDirectory;
return false;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool MockedGetLoadedModules(ref List<ModuleInfo> __result)
{
__result = new List<ModuleInfo>();
Expand Down
1 change: 1 addition & 0 deletions src/MCM.UI/MCM.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<PropertyGroup>
<Authors>Aragas, mipen</Authors>
<AssemblyName>MCMv4.UI.v$(Version)</AssemblyName>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
6 changes: 5 additions & 1 deletion src/MCM.UI/MCMUISubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using SandBox;

using System.ComponentModel;
using System.Runtime.CompilerServices;

using TaleWorlds.Engine.Screens;
using TaleWorlds.Localization;
Expand All @@ -28,6 +29,7 @@ public sealed class MCMUISubModule : MBSubModuleBase
{
private static readonly UIExtender Extender = new UIExtender("MCM.UI");

[MethodImpl(MethodImplOptions.NoInlining)]
protected override void OnSubModuleLoad()
{
base.OnSubModuleLoad();
Expand All @@ -49,10 +51,11 @@ protected override void OnSubModuleLoad()
DelayedSubModuleManager.Subscribe<SandBoxSubModule, MCMUISubModule>(
nameof(OnSubModuleLoad), SubscriptionType.AfterMethod, (s, e) =>
{
Extender.Register();
Extender.Register(typeof(MCMUISubModule).Assembly);
});
}

[MethodImpl(MethodImplOptions.NoInlining)]
protected override void OnBeforeInitialModuleScreenSetAsRoot()
{
base.OnBeforeInitialModuleScreenSetAsRoot();
Expand All @@ -70,6 +73,7 @@ protected override void OnBeforeInitialModuleScreenSetAsRoot()
});
}

[MethodImpl(MethodImplOptions.NoInlining)]
protected override void OnSubModuleUnloaded()
{
base.OnSubModuleUnloaded();
Expand Down
2 changes: 2 additions & 0 deletions src/MCM.UI/Patches/BrushFactoryPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using MCM.UI.Functionality.Injectors;

using System.Collections.Generic;
using System.Runtime.CompilerServices;

using TaleWorlds.GauntletUI;

Expand All @@ -20,6 +21,7 @@ public static void Patch(Harmony harmony)
postfix: new HarmonyMethod(AccessTools.Method(typeof(BrushFactoryPatch), nameof(LoadBrushesHarmony))));
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void LoadBrushesHarmony(BrushFactory __instance)
{
if (Brushes != null)
Expand Down
2 changes: 2 additions & 0 deletions src/MCM.UI/Patches/EditableTextPatch.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using HarmonyLib;

using System;
using System.Runtime.CompilerServices;

using TaleWorlds.TwoDimension;

Expand All @@ -18,6 +19,7 @@ public static void Patch(Harmony harmony)
finalizer: new HarmonyMethod(typeof(EditableTextPatch), nameof(GetCursorPosition)));
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static Exception? GetCursorPosition(Exception? __exception) => null;
}
}
3 changes: 3 additions & 0 deletions src/MCM.UI/Patches/GauntletMoviePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

using MCM.Abstractions.Functionality;

using System.Runtime.CompilerServices;

using TaleWorlds.GauntletUI;
using TaleWorlds.GauntletUI.Data;
using TaleWorlds.GauntletUI.PrefabSystem;
Expand All @@ -24,6 +26,7 @@ public static void Patch(Harmony harmony)
prefix: new HarmonyMethod(AccessTools.Method(typeof(GauntletMoviePatch), nameof(LoadMovieHarmony))));
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool LoadMovieHarmony(GauntletMovie __instance, Widget ____movieRootNode)
{
var movie = BaseResourceHandler.Instance.MovieRequested(__instance.MovieName);
Expand Down
3 changes: 3 additions & 0 deletions src/MCM.UI/Patches/ViewModelPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

using MCM.Abstractions;

using System.Runtime.CompilerServices;

using TaleWorlds.Library;

namespace MCM.UI.Patches
Expand All @@ -19,6 +21,7 @@ public static void Patch(Harmony harmony)
/// Trigger ExecuteCommand in the wrapped VM
/// We can't extend\copy methods like we do with properties
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
private static bool ExecuteCommandPatch(ViewModel __instance, string commandName, object[] parameters)
{
if (__instance is IWrapper wrapper && wrapper.Object is ViewModel viewModel)
Expand Down
3 changes: 3 additions & 0 deletions src/MCM.UI/Patches/WidgetPrefabPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Xml;

using TaleWorlds.GauntletUI.PrefabSystem;
Expand All @@ -19,12 +20,14 @@ public static void Patch(Harmony harmony)
new HarmonyMethod(SymbolExtensions.GetMethodInfo(() => LoadFromDocument(null!, null!, null!, null!)))).Patch();
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static WidgetPrefab LoadFromDocument(
PrefabExtensionContext prefabExtensionContext,
WidgetAttributeContext widgetAttributeContext,
string path,
XmlDocument document)
{
[MethodImpl(MethodImplOptions.NoInlining)]
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase method)
{
var returnNull = new List<CodeInstruction>
Expand Down
4 changes: 2 additions & 2 deletions src/MCM.UI/UIExtenderEx/OptionsPrefabExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace MCM.UI.UIExtenderEx
{
[PrefabExtension("Options", "descendant::OptionsScreenWidget[@Id='Options']/Children/Standard.TopPanel/Children/ListPanel/Children")]
internal sealed class OptionsPrefabExtension1 : PrefabExtensionInsertPatch
public sealed class OptionsPrefabExtension1 : PrefabExtensionInsertPatch
{
public override string Id => "Options1";
public override int Position => 3;
Expand Down Expand Up @@ -36,7 +36,7 @@ public OptionsPrefabExtension2()
}

[PrefabExtension("Options", "descendant::OptionsScreenWidget[@Id='Options']/Children/ListPanel[@Id='MainSectionListPanel']/Children/Widget[@Id='DescriptionsRightPanel']")]
internal sealed class OptionsPrefabExtension3 : PrefabExtensionReplacePatch
public sealed class OptionsPrefabExtension3 : PrefabExtensionReplacePatch
{
public override string Id => "Options3";
private XmlDocument XmlDocument { get; } = new XmlDocument();
Expand Down
14 changes: 13 additions & 1 deletion src/MCM.UI/UIExtenderEx/OptionsVMMixin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.CompilerServices;

using TaleWorlds.Library;
using TaleWorlds.MountAndBlade.ViewModelCollection.GameOptions;
Expand Down Expand Up @@ -60,18 +61,21 @@ static OptionsVMMixin()
postfix: new HarmonyMethod(AccessTools.Method(typeof(OptionsVMMixin), nameof(ExecuteCloseOptionsPostfix)), 300));
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void OptionsPostfix(OptionsVM __instance)
{
__instance.SetPropertyValue(nameof(ModOptionsSelected), false);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void ExecuteCloseOptionsPostfix(OptionsVM __instance)
{
if (__instance.GetPropertyValue("MCMMixin") is WeakReference<OptionsVMMixin> weakReference && weakReference.TryGetTarget(out var mixin))
{
mixin?.ExecuteCloseOptions();
}
}


[MethodImpl(MethodImplOptions.NoInlining)]
private static void OriginalExecuteCloseOptions(OptionsVM instance) => throw new NotImplementedException("It's a stub");

private readonly ModOptionsVM _modOptions = new ModOptionsVM();
Expand All @@ -84,6 +88,7 @@ private static void ExecuteCloseOptionsPostfix(OptionsVM __instance)
[DataSourceProperty]
public ModOptionsVM ModOptions
{
[MethodImpl(MethodImplOptions.NoInlining)]
get
{
ModOptionsSelected = true;
Expand All @@ -94,7 +99,9 @@ public ModOptionsVM ModOptions
[DataSourceProperty]
public int DescriptionWidth
{
[MethodImpl(MethodImplOptions.NoInlining)]
get => _descriptionWidth;
[MethodImpl(MethodImplOptions.NoInlining)]
private set
{
if (_descriptionWidth == value)
Expand All @@ -108,7 +115,9 @@ private set
[DataSourceProperty]
public bool ModOptionsSelected
{
[MethodImpl(MethodImplOptions.NoInlining)]
get => _modOptionsSelected;
[MethodImpl(MethodImplOptions.NoInlining)]
set
{
if (_modOptionsSelected == value)
Expand Down Expand Up @@ -138,6 +147,7 @@ public override void OnFinalize()
}

[DataSourceMethod]
[MethodImpl(MethodImplOptions.NoInlining)]
public void ExecuteCloseOptions()
{
ModOptions.ExecuteCancelInternal(false);
Expand All @@ -147,6 +157,7 @@ public void ExecuteCloseOptions()
}

[DataSourceMethod]
[MethodImpl(MethodImplOptions.NoInlining)]
public void ExecuteDone()
{
ModOptions.ExecuteDoneInternal(false, () =>
Expand All @@ -157,6 +168,7 @@ public void ExecuteDone()
}

[DataSourceMethod]
[MethodImpl(MethodImplOptions.NoInlining)]
public void ExecuteCancel()
{
ModOptions.ExecuteCancelInternal(false, () =>
Expand Down
8 changes: 4 additions & 4 deletions src/MCM.UI/Utils/WrappedMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public WrappedMethodInfo(MethodInfo actualMethodInfo, object instance)
public override CallingConventions CallingConvention => _methodInfoImplementation.CallingConvention;
public override bool ContainsGenericParameters => _methodInfoImplementation.ContainsGenericParameters;
public override IEnumerable<CustomAttributeData> CustomAttributes => _methodInfoImplementation.CustomAttributes;
public override Type DeclaringType => _methodInfoImplementation.DeclaringType;
public override Type? DeclaringType => _methodInfoImplementation.DeclaringType;
public override bool IsGenericMethod => _methodInfoImplementation.IsGenericMethod;
public override bool IsGenericMethodDefinition => _methodInfoImplementation.IsGenericMethodDefinition;
public override bool IsSecurityCritical => _methodInfoImplementation.IsSecurityCritical;
Expand All @@ -32,8 +32,8 @@ public WrappedMethodInfo(MethodInfo actualMethodInfo, object instance)
public override MethodImplAttributes MethodImplementationFlags => _methodInfoImplementation.MethodImplementationFlags;
public override Module Module => _methodInfoImplementation.Module;
public override string Name => _methodInfoImplementation.Name;
public override Type ReflectedType => _methodInfoImplementation.ReflectedType;
public override ParameterInfo ReturnParameter => _methodInfoImplementation.ReturnParameter;
public override Type? ReflectedType => _methodInfoImplementation.ReflectedType;
public override ParameterInfo? ReturnParameter => _methodInfoImplementation.ReturnParameter;
public override Type ReturnType => _methodInfoImplementation.ReturnType;
public override ICustomAttributeProvider ReturnTypeCustomAttributes => _methodInfoImplementation.ReturnTypeCustomAttributes;

Expand All @@ -45,7 +45,7 @@ public WrappedMethodInfo(MethodInfo actualMethodInfo, object instance)
public override IList<CustomAttributeData> GetCustomAttributesData() => _methodInfoImplementation.GetCustomAttributesData();
public override Type[] GetGenericArguments() => _methodInfoImplementation.GetGenericArguments();
public override MethodInfo GetGenericMethodDefinition() => _methodInfoImplementation.GetGenericMethodDefinition();
public override MethodBody GetMethodBody() => _methodInfoImplementation.GetMethodBody();
public override MethodBody? GetMethodBody() => _methodInfoImplementation.GetMethodBody();
public override MethodImplAttributes GetMethodImplementationFlags() => _methodInfoImplementation.GetMethodImplementationFlags();
public override ParameterInfo[] GetParameters() => _methodInfoImplementation.GetParameters();
public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) =>
Expand Down
Loading

0 comments on commit 168c5db

Please sign in to comment.