Skip to content

Commit

Permalink
Merge pull request #289 from BUTR/dev
Browse files Browse the repository at this point in the history
v2.11.0
  • Loading branch information
Aragas authored Feb 6, 2024
2 parents 202ef6a + 54638a6 commit 11f952f
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
shell: pwsh

- name: ReportGenerator
uses: danielpalme/[email protected].0
uses: danielpalme/[email protected].1
with:
reports: 'coverage_uiextenderex_debug.xml;coverage_uiextenderex_release.xml'
targetdir: 'coveragereport'
Expand All @@ -76,7 +76,7 @@ jobs:
path: coveragereport

- name: Upload ReportGenerator to CodeCov
uses: codecov/codecov-action@v3.1.4
uses: codecov/codecov-action@v4.0.1
with:
token: ${{secrets.CODECOV_TOKEN}}
file: coveragereport/Cobertura.xml
Expand Down
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!--Development Variables-->
<PropertyGroup>
<!--Module Version-->
<Version>2.10.0</Version>
<Version>2.11.0</Version>
<!--Harmony Version-->
<HarmonyVersion>2.2.2</HarmonyVersion>
<HarmonyExtensionsVersion>3.2.0.77</HarmonyExtensionsVersion>
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 2.11.0
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.1.6,v1.2.x
* Disabled the BETA changes due to regression
* Added back the old UIExtender constructor for backwards compatibility
---------------------------------------------------------------------------------------------------
Version: 2.10.0
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.1.6,v1.2.8
* BETA! Might cause issues with the UI in specific cases!
Expand Down
8 changes: 8 additions & 0 deletions src/Bannerlord.UIExtenderEx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "articles", "articles", "{80
..\docs\articles\toc.yml = ..\docs\articles\toc.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "general", "general", "{3FA98C73-903D-406D-A1C4-D22DF4C5C00B}"
ProjectSection(SolutionItems) = preProject
..\docs\articles\general\InteractingWithOtherMods.md = ..\docs\articles\general\InteractingWithOtherMods.md
..\docs\articles\general\Overview.md = ..\docs\articles\general\Overview.md
..\docs\articles\general\toc.yml = ..\docs\articles\general\toc.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Beta_Release|x64 = Beta_Release|x64
Expand Down Expand Up @@ -128,6 +135,7 @@ Global
{8969A5E2-BC12-46F8-BF4A-E8F73771E4E5} = {8034BC17-4282-4A4B-942B-80EEC315C1C2}
{395402D4-28B5-4974-943D-04B7D5F6673D} = {8034BC17-4282-4A4B-942B-80EEC315C1C2}
{B4D6A888-2D8F-49A4-87C5-6CD18D8F818B} = {8034BC17-4282-4A4B-942B-80EEC315C1C2}
{3FA98C73-903D-406D-A1C4-D22DF4C5C00B} = {8034BC17-4282-4A4B-942B-80EEC315C1C2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {31629F18-48B4-4C3E-87C3-BDCB9BBF1BBD}
Expand Down
14 changes: 7 additions & 7 deletions src/Bannerlord.UIExtenderEx/Patches/GauntletMoviePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ internal static class GauntletMoviePatch
private static readonly ConcurrentDictionary<UIExtenderRuntime, List<string>> _widgetNames = new();
private static readonly ConcurrentDictionary<Type, Type[]> _widgetChildCache = new();
private static readonly AccessTools.FieldRef<GeneratedPrefabContext, Dictionary<string, Dictionary<string, CreateGeneratedWidget>>>? _generatedPrefabs =
AccessTools2.FieldRefAccess<GeneratedPrefabContext, Dictionary<string, Dictionary<string, CreateGeneratedWidget>>>("_generatedPrefabs");
AccessTools2.FieldRefAccess<GeneratedPrefabContext, Dictionary<string, Dictionary<string, CreateGeneratedWidget>>>("_generatedPrefabs");

public static void Register(UIExtenderRuntime runtime, string? autoGenWidgetName)
{
if (string.IsNullOrEmpty(autoGenWidgetName))
Expand Down Expand Up @@ -73,7 +73,7 @@ static IEnumerable<Type> GetChildWidgets(Type widgetType)
var autoGenNames = widgetNames.Where(x => x.Contains("__"));
return autoGenNames.Select(x => x.Split(["__"], StringSplitOptions.None)[0]);
}
}
}
/* This implementation actually created the Widget, but it seems that game didn't intend for that
var variantName = datasource == null ? "Default" : datasource.GetType().FullName;
var data = datasource == null ? new Dictionary<string, object>() : new() { {"DataSource", datasource} };
Expand All @@ -88,16 +88,16 @@ static IEnumerable<Type> GetChildWidgets(Type widgetType)
var autoGenNames = widgetNames.Where(x => x.Contains("__")).ToArray();
return autoGenNames.Select(x => x.Split(["__"], StringSplitOptions.None)[0]);
}
*/
*/

return Enumerable.Empty<string>();
}

var moviesPatched = new HashSet<string>(UIExtender.GetAllRuntimes().SelectMany(x => x.PrefabComponent.GetMoviesToPatch()));
var moviesInvolved = new HashSet<string>(GetAllInvolvedAutoGenNames(widgetFactory, movieName, datasource));
if (moviesInvolved.Overlaps(moviesPatched))
doNotUseGeneratedPrefabs = true;
doNotUseGeneratedPrefabs = true;

var moviesBlacklisted = _widgetNames.SelectMany(kv => kv.Value);
if (moviesBlacklisted.Contains(movieName))
doNotUseGeneratedPrefabs = true;
Expand Down
17 changes: 17 additions & 0 deletions src/Bannerlord.UIExtenderEx/Patches/UIConfigPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using HarmonyLib;
using HarmonyLib.BUTR.Extensions;

namespace Bannerlord.UIExtenderEx.Patches;

internal static class UIConfigPatch
{
public static void Patch(Harmony harmony)
{
harmony.TryPatch(
AccessTools2.DeclaredPropertySetter("TaleWorlds.Engine.GauntletUI.UIConfig:DoNotUseGeneratedPrefabs"),
prefix: AccessTools2.DeclaredMethod("Bannerlord.UIExtenderEx.Patches.UIConfigPatch:Prefix"));
}

// Disable setting a value to DoNotUseGeneratedPrefabs
private static bool Prefix() => false;
}
19 changes: 19 additions & 0 deletions src/Bannerlord.UIExtenderEx/SubModule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bannerlord.BUTR.Shared.Helpers;

using BUTR.MessageBoxPInvoke.Helpers;

using System;
Expand All @@ -12,6 +13,24 @@ namespace Bannerlord.UIExtenderEx;

public class SubModule : MBSubModuleBase
{
#if !ENABLE_PARTIAL_AUTOGEN
static SubModule()
{
// Disable AutoGens as early as possible
try
{
// Force load TaleWorlds.Engine.GauntletUI as it might not be loaded yet!
System.Reflection.Assembly.Load("TaleWorlds.Engine.GauntletUI");
}
catch (Exception e)
{
Utils.MessageUtils.Fail($"Failed to load 'TaleWorlds.Engine.GauntletUI'! Exception: {e}");
}

TaleWorlds.Engine.GauntletUI.UIConfig.DoNotUseGeneratedPrefabs = true;
}
#endif

// We can't rely on EN since the game assumes that the default locale is always English
private const string SWarningTitle =
@"{=eySpdc25EE}Warning from Bannerlord.UIExtenderEx!";
Expand Down
6 changes: 5 additions & 1 deletion src/Bannerlord.UIExtenderEx/UIExtender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public class UIExtender

static UIExtender()
{
#if ENABLE_PARTIAL_AUTOGEN
GauntletMoviePatch.Patch(Harmony);
#else
UIConfigPatch.Patch(Harmony);
#endif
ViewModelPatch.Patch(Harmony);
WidgetPrefabPatch.Patch(Harmony);
BrushFactoryManager.Patch(Harmony);
Expand Down Expand Up @@ -61,7 +65,7 @@ private UIExtender(string moduleName, bool _)
/// Default constructor. `moduleName` should match module folder because it will be used to look-up resources
/// </summary>
/// <param name="moduleName">Module name, should match module folder</param>
[Obsolete("Use UIExtender.Create(moduleName)", true)]
[Obsolete("Use UIExtender.Create(moduleName) if backwards compatibility is not a concern.", false)]
public UIExtender(string moduleName)
{
_moduleName = moduleName;
Expand Down

0 comments on commit 11f952f

Please sign in to comment.