/// <summary> /// Called when a game level is loaded. If applicable, activates the Snooper mod /// for the loaded level. /// </summary> /// /// <param name="mode">The <see cref="LoadMode"/> a game level is loaded in.</param> public override void OnLevelLoaded(LoadMode mode) { switch (mode) { case LoadMode.LoadGame: case LoadMode.NewGame: case LoadMode.LoadScenario: case LoadMode.NewGameFromScenario: break; default: return; } try { patcher.Apply(); } catch (Exception ex) { Debug.LogError("The 'Snooper' mod failed to perform method redirections: " + ex); SafeRevertPatches(); return; } WorldInfoPanelPatches.CitizenInfoPanel = CustomCitizenInfoPanel.Enable(); WorldInfoPanelPatches.VehicleInfoPanel = CustomVehicleInfoPanel.Enable(); }
/// <summary> /// Called when a game level is loaded. If applicable, activates the Snooper mod /// for the loaded level. /// </summary> /// /// <param name="mode">The <see cref="LoadMode"/> a game level is loaded in.</param> public override void OnLevelLoaded(LoadMode mode) { switch (mode) { case LoadMode.LoadGame: case LoadMode.NewGame: case LoadMode.LoadScenario: case LoadMode.NewGameFromScenario: break; default: return; } IPatch[] patches = { WorldInfoPanelPatches.UpdateBindings, HumanAIPatches.StartMoving1, HumanAIPatches.StartMoving2, CargoTruckAIPatches.SetTarget, }; patcher = new MethodPatcher(HarmonyId, patches); HashSet <IPatch> patchedMethods = patcher.Apply(); if (patchedMethods.Count != patches.Length) { Debug.LogError("The 'Snooper' mod failed to perform method redirections"); patcher.Revert(); return; } WorldInfoPanelPatches.CitizenInfoPanel = CustomCitizenInfoPanel.Enable(); WorldInfoPanelPatches.TouristInfoPanel = CustomTouristInfoPanel.Enable(); WorldInfoPanelPatches.CitizenVehicleInfoPanel = CustomCitizenVehicleInfoPanel.Enable(); WorldInfoPanelPatches.ServiceVehicleInfoPanel = CustomCityServiceVehicleInfoPanel.Enable(); }
/// <summary>Enables the citizen info panel customization. Can return null on failure.</summary> /// <returns>An instance of the <see cref="CustomCitizenInfoPanel"/> class that can be used for disabling /// the customization, or null when the customization fails.</returns> public static CustomCitizenInfoPanel Enable() { var result = new CustomCitizenInfoPanel(GameInfoPanelName); return(result.Initialize() ? result : null); }