Skip to content

Commit

Permalink
Don't allow loading saves with maps that aren't installed
Browse files Browse the repository at this point in the history
  • Loading branch information
Insprill committed Jun 22, 2023
1 parent 2fb784f commit ff699fc
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions Mapify/Locale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static class Locale
private const string DEFAULT_LANGUAGE = "English";
public const string SESSION__MAP_SELECTOR = "mapify/session/map_selector";
public const string LAUNCHER__SESSION_MAP = "mapify/launcher/session_map";
public const string LAUNCHER__SESSION_MAP_NOT_INSTALLED = "mapify/launcher/session_map_not_installed";
public const string LOADING__PLEASE_WAIT = "mapify/loading/please_wait";
public const string LOADING__LOADING_MAP = "mapify/loading/loading_map";
private static readonly char[] PREFIX_CHARS = PREFIX.ToCharArray();
Expand Down
23 changes: 23 additions & 0 deletions Mapify/Patches/AScenarioProviderPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Linq;
using DV.Common;
using DV.UI;
using HarmonyLib;
using Mapify.Editor;
using Mapify.Map;
using Mapify.Utils;

namespace Mapify.Patches
{
[HarmonyPatch(typeof(AScenarioProvider), nameof(AScenarioProvider.CanStartNewSession))]
public static class AScenarioProvider_CanStartNewSession_Patch
{
private static bool Prefix(IGameSession session, ref (bool canRun, string reasonLocKey) __result)
{
BasicMapInfo basicMapInfo = session.GameData.GetBasicMapInfo();
if (Maps.AllMapNames.Contains(basicMapInfo.mapName))
return true;
__result = (false, Locale.LAUNCHER__SESSION_MAP_NOT_INSTALLED);
return false;
}
}
}
30 changes: 30 additions & 0 deletions Mapify/Patches/LauncherControllerPatch.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using DV.Common;
using DV.UI;
using DV.UI.PresetEditors;
using DV.UIFramework;
using HarmonyLib;
using Mapify.Editor;
using Mapify.Map;
using Mapify.Utils;

namespace Mapify.Patches
Expand Down Expand Up @@ -41,4 +45,30 @@ private static void Postfix(UIStartGameData data, ref string __result)
__result = string.Join("\n", strings);
}
}

[HarmonyPatch(typeof(LauncherController), "OnRunClicked")]
public static class LauncherController_OnRunClicked_Patch
{
private static bool Prefix(LauncherController __instance, ISaveGame ___saveGame)
{
BasicMapInfo basicMapInfo = ___saveGame.Data.GetBasicMapInfo();
if (Maps.AllMapNames.Contains(basicMapInfo.mapName))
return true;

PopupManager popupManager = null;
__instance.FindPopupManager(ref popupManager);

if (!popupManager.CanShowPopup())
{
Mapify.LogError("Cannot show popup!");
return false;
}

Popup okPopupPrefab = __instance.GetComponentInParent<InitialScreenController>().continueLoadNewController.career.okPopupPrefab;

Popup popup = popupManager.ShowPopup(okPopupPrefab);
popup.labelTMPro.text = Locale.Get(Locale.LAUNCHER__SESSION_MAP_NOT_INSTALLED, basicMapInfo.mapName);
return false;
}
}
}
1 change: 1 addition & 0 deletions locale.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ session/map_selector__tooltip,,Select a Map
launcher/map_selector__tooltip_disabled,,
loading/please_wait,,"loading{0}, please wait... {1}%"
loading/loading_map,,Loading map {0}
launcher/session_map_not_installed,,The map {0} isn't installed! Please install it before loading this save.

0 comments on commit ff699fc

Please sign in to comment.