Ejemplo n.º 1
0
        private static Result ThreeMapVMPatches(CodePatcherComponent comp)
        {
            var callsite = typeof(MapVM).GetConstructor(new Type[]
            {
                typeof(INavigationHandler), typeof(IMapStateHandler), typeof(MapBarShortcuts), typeof(Action)
            });

            if (callsite == null)
            {
                return(Result.Failure);
            }

            var dependentRefreshMethods = new[]
            {
                typeof(MapInfoVM).GetMethod(nameof(MapInfoVM.Refresh)),
                typeof(MapTimeControlVM).GetMethod(nameof(MapTimeControlVM.Refresh)),
                typeof(MapNavigationVM).GetMethod(nameof(MapNavigationVM.Refresh)),
            };

            if (dependentRefreshMethods.Any(e => e == null))
            {
                return(Result.Failure);
            }

            comp.AddViewModelInstantiationPatch(callsite);
            foreach (var method in dependentRefreshMethods)
            {
                comp.AddViewModelRefreshPatch(method);
            }

            return(Result.Success);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="moduleName">Name of the module this runtime is assigned to</param>
        internal UIExtenderRuntime(string moduleName)
        {
            ModuleName = moduleName;

            PrefabComponent    = new PrefabComponent(moduleName);
            ViewModelComponent = new ViewModelComponent(moduleName);
            CodePatcher        = new CodePatcherComponent(this);
        }
Ejemplo n.º 3
0
        internal static bool AddTo(CodePatcherComponent comp)
        {
            var widgetLoadMethod     = typeof(WidgetPrefab).GetMethod(nameof(WidgetPrefab.LoadFrom));
            var executeCommandMethod = typeof(TaleWorlds.Library.ViewModel).GetMethod(nameof(TaleWorlds.Library.ViewModel.ExecuteCommand));

            if (widgetLoadMethod == null || executeCommandMethod == null)
            {
                return(false);
            }

            comp.AddWidgetLoadPatch(widgetLoadMethod);
            comp.AddViewModelExecutePatch(executeCommandMethod);
            return(true);
        }
Ejemplo n.º 4
0
        internal static Result AddTo(CodePatcherComponent comp)
        {
            int value = 0;

            value |= (int)ThreeMapVMPatches(comp);
            value |= (int)PartyVMPatch(comp);
            value |= (int)MissionAgentStatusVMPatch(comp);
            value |= (int)MapVMPatch(comp);
            value |= (int)CharacterVMPatch(comp);

            if (Enum.IsDefined(typeof(Result), value))
            {
                return((Result)value);
            }
            else
            {
                Debug.Fail($"Invalid enum usage!");
                return(Result.Failure);
            }
        }
Ejemplo n.º 5
0
        private static Result CharacterVMPatch(CodePatcherComponent comp)
        {
            var callsite = typeof(CharacterDeveloperVM).GetConstructor(new Type[] { typeof(Action) });

            if (callsite == null)
            {
                return(Result.Failure);
            }

            var refresh = typeof(CharacterVM).GetMethod(nameof(CharacterVM.RefreshValues));

            if (refresh == null)
            {
                return(Result.Failure);
            }

            comp.AddViewModelInstantiationPatch(callsite);
            comp.AddViewModelRefreshPatch(refresh);
            return(Result.Success);
        }
Ejemplo n.º 6
0
        private static Result MapVMPatch(CodePatcherComponent comp)
        {
            var callsite = typeof(GauntlerMapBarGlobalLayer).GetMethod(nameof(GauntlerMapBarGlobalLayer.Initialize));

            if (callsite == null)
            {
                return(Result.Failure);
            }

            var refresh = typeof(MapVM).GetMethod(nameof(MapVM.OnRefresh));

            if (refresh == null)
            {
                return(Result.Failure);
            }

            comp.AddViewModelInstantiationPatch(callsite);
            comp.AddViewModelRefreshPatch(refresh);
            return(Result.Success);
        }
Ejemplo n.º 7
0
        private static Result MissionAgentStatusVMPatch(CodePatcherComponent comp)
        {
            var callsite = typeof(MissionGauntletAgentStatus).GetMethod(nameof(MissionGauntletAgentStatus.EarlyStart));

            if (callsite == null)
            {
                return(Result.Failure);
            }

            var refresh = typeof(MissionAgentStatusVM).GetMethod(nameof(MissionAgentStatusVM.Tick));

            if (refresh == null)
            {
                return(Result.Failure);
            }

            comp.AddViewModelInstantiationPatch(callsite);
            comp.AddViewModelRefreshPatch(refresh);
            return(Result.Success);
        }
Ejemplo n.º 8
0
        private static Result CustomBattleMenuSideVMPatch(CodePatcherComponent comp)
        {
            var callsite = typeof(CustomBattleMenuVM).GetConstructor(new[] { typeof(CustomBattleState) });

            if (callsite == null)
            {
                return(Result.Failure);
            }

            var refresh = typeof(CustomBattleMenuSideVM).GetMethod(nameof(CustomBattleMenuSideVM.RefreshValues));

            if (refresh == null)
            {
                return(Result.Failure);
            }

            comp.AddViewModelInstantiationPatch(callsite);
            comp.AddViewModelRefreshPatch(refresh);
            return(Result.Success);
        }
Ejemplo n.º 9
0
        private static Result CustomBattleVMPatch(CodePatcherComponent comp)
        {
            var callsite = typeof(CustomBattleScreen).GetMethod("OnInitialize", BindingFlags.NonPublic | BindingFlags.Instance);

            if (callsite == null)
            {
                return(Result.Failure);
            }

            var refresh = typeof(CustomBattleMenuVM).GetMethod(nameof(CustomBattleMenuVM.RefreshValues));

            if (refresh == null)
            {
                return(Result.Failure);
            }

            comp.AddViewModelInstantiationPatch(callsite);
            comp.AddViewModelRefreshPatch(refresh);
            return(Result.Success);
        }
Ejemplo n.º 10
0
        private static Result PartyVMPatch(CodePatcherComponent comp)
        {
            Type       type            = typeof(GauntletPartyScreen);
            MethodInfo interfaceMethod = type.GetInterface(nameof(IGameStateListener)).GetMethod("OnActivate");

            if (interfaceMethod == null)
            {
                return(Result.Failure);
            }

            InterfaceMapping map = type.GetInterfaceMap(interfaceMethod.DeclaringType ?? throw new NullReferenceException("Cannot find GauntletPartyScreen IGameStateListener.OnActivate method"));
            var callsite         = map.TargetMethods[Array.IndexOf(map.InterfaceMethods, interfaceMethod)];

            if (callsite == null)
            {
                return(Result.Failure);
            }

            comp.AddViewModelInstantiationPatch(callsite);
            return(Result.Success);
        }