Ejemplo n.º 1
0
 private void SafeRevertPatches()
 {
     try
     {
         patcher.Revert();
     }
     catch (Exception ex)
     {
         Debug.LogWarning("The 'Snooper' mod failed to revert method redirections: " + ex);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Called when a game level is about to be unloaded. If the Snooper mod was activated
        /// for this level, deactivates the mod for this level.
        /// </summary>
        public override void OnLevelUnloading()
        {
            patcher?.Revert();
            patcher = null;

            WorldInfoPanelPatches.CitizenInfoPanel?.Disable();
            WorldInfoPanelPatches.CitizenInfoPanel = null;

            WorldInfoPanelPatches.TouristInfoPanel?.Disable();
            WorldInfoPanelPatches.TouristInfoPanel = null;

            WorldInfoPanelPatches.CitizenVehicleInfoPanel?.Disable();
            WorldInfoPanelPatches.CitizenVehicleInfoPanel = null;

            WorldInfoPanelPatches.ServiceVehicleInfoPanel?.Disable();
            WorldInfoPanelPatches.ServiceVehicleInfoPanel = null;
        }
Ejemplo n.º 3
0
        /// <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();
        }