Skip to content

Commit

Permalink
Merge branch 'feature-harmony'
Browse files Browse the repository at this point in the history
  • Loading branch information
dymanoid committed Aug 5, 2018
2 parents 0128753 + 8582d2b commit 7f6b1fc
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 20 deletions.
30 changes: 27 additions & 3 deletions src/RealTime/Core/Compatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ internal static class Compatibility
/// <summary>Checks for any enabled incompatible mods and notifies the player when any found.</summary>
/// <param name="modName">The name of the current mod.</param>
/// <param name="localizationProvider">The localization provider to use for translation.</param>
/// <param name="additionalInfo">Additional information to be added to the pop up or message box.</param>
/// <returns><c>true</c> if the check was successful and no messages were shown; otherwise, <c>false</c>.</returns>
/// <exception cref="ArgumentException">Thrown when <paramref name="modName"/> is null or an empty string.</exception>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="localizationProvider"/> is null.</exception>
public static void CheckAndNotify(string modName, ILocalizationProvider localizationProvider)
public static bool CheckAndNotify(string modName, ILocalizationProvider localizationProvider, string additionalInfo = null)
{
if (string.IsNullOrEmpty(modName))
{
Expand All @@ -51,14 +53,36 @@ public static void CheckAndNotify(string modName, ILocalizationProvider localiza
List<string> incompatibleMods = GetIncompatibleModNames();
if (incompatibleMods.Count == 0)
{
return;
return true;
}

string separator = Environment.NewLine + " - ";
string caption = modName + " - " + localizationProvider.Translate(TranslationKeys.Warning);
string text = localizationProvider.Translate(TranslationKeys.IncompatibleModsFoundMessage)
+ Environment.NewLine + separator
+ string.Join(separator, incompatibleMods.ToArray());
+ string.Join(separator, incompatibleMods.ToArray())
+ Environment.NewLine + Environment.NewLine
+ additionalInfo;

Notify(caption, text);
return false;
}

/// <summary>Notifies the user either with a pop up or with a message box.</summary>
/// <param name="caption">The caption of the pop up or message box.</param>
/// <param name="text">The notification text.</param>
/// <exception cref="ArgumentException">Thrown when any argument is null or an empty string.</exception>
public static void Notify(string caption, string text)
{
if (string.IsNullOrEmpty(caption))
{
throw new ArgumentException("The caption cannot be null or an empty string", nameof(caption));
}

if (string.IsNullOrEmpty(text))
{
throw new ArgumentException("The text cannot be null or an empty string.", nameof(text));
}

if (!NotifyWithPopup(caption, text))
{
Expand Down
51 changes: 38 additions & 13 deletions src/RealTime/Core/RealTimeCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace RealTime.Core
{
using System;
using System.Collections.Generic;
using System.Linq;
using RealTime.Config;
using RealTime.CustomAI;
using RealTime.Events;
Expand Down Expand Up @@ -53,6 +54,9 @@ private RealTimeCore(
isEnabled = true;
}

/// <summary>Gets a value indicating whether the mod is running in a restricted mode due to method patch failures.</summary>
public bool IsRestrictedMode { get; private set; }

/// <summary>
/// Runs the mod by activating its parts.
/// </summary>
Expand Down Expand Up @@ -83,16 +87,13 @@ public static RealTimeCore Run(ConfigurationProvider<RealTimeConfig> configProvi
throw new ArgumentNullException(nameof(localizationProvider));
}

IEnumerable<IPatch> patches = GetMethodPatches();
List<IPatch> patches = GetMethodPatches();
var patcher = new MethodPatcher(HarmonyId, patches);

try
{
patcher.Apply();
}
catch (Exception ex)
HashSet<IPatch> appliedPatches = patcher.Apply();
if (!CheckRequiredMethodPatches(appliedPatches))
{
Log.Error("The 'Real Time' mod failed to perform method redirections: " + ex);
Log.Error("The 'Real Time' mod failed to perform method redirections for required methods");
patcher.Revert();
return null;
}
Expand Down Expand Up @@ -165,11 +166,19 @@ public static RealTimeCore Run(ConfigurationProvider<RealTimeConfig> configProvi
SimulationHandler.WeatherInfo = weatherInfo;
SimulationHandler.Buildings = BuildingAIPatches.RealTimeAI;
SimulationHandler.Buildings.UpdateFrameDuration();
SimulationHandler.Buildings.InitializeLightState();

if (appliedPatches.Contains(BuildingAIPatches.PrivateShowConsumption))
{
SimulationHandler.Buildings.InitializeLightState();
}

SimulationHandler.Statistics = statistics;

WorldInfoPanelPatches.CitizenInfoPanel = CustomCitizenInfoPanel.Enable(ResidentAIPatch.RealTimeAI, localizationProvider);
WorldInfoPanelPatches.VehicleInfoPanel = CustomVehicleInfoPanel.Enable(ResidentAIPatch.RealTimeAI, localizationProvider);
if (appliedPatches.Contains(WorldInfoPanelPatches.UpdateBindings))
{
WorldInfoPanelPatches.CitizenInfoPanel = CustomCitizenInfoPanel.Enable(ResidentAIPatch.RealTimeAI, localizationProvider);
WorldInfoPanelPatches.VehicleInfoPanel = CustomVehicleInfoPanel.Enable(ResidentAIPatch.RealTimeAI, localizationProvider);
}

AwakeSleepSimulation.Install(configProvider.Configuration);

Expand All @@ -182,8 +191,8 @@ public static RealTimeCore Run(ConfigurationProvider<RealTimeConfig> configProvi
}

result.storageData.Add(configProvider);

result.Translate(localizationProvider);
result.IsRestrictedMode = appliedPatches.Count != patches.Count;

return result;
}
Expand Down Expand Up @@ -256,7 +265,7 @@ public void Translate(ILocalizationProvider localizationProvider)
UIGraphPatches.Translate(localizationProvider.CurrentCulture);
}

private static IEnumerable<IPatch> GetMethodPatches()
private static List<IPatch> GetMethodPatches()
{
var patches = new List<IPatch>
{
Expand All @@ -272,7 +281,8 @@ private static IEnumerable<IPatch> GetMethodPatches()
WorldInfoPanelPatches.UpdateBindings,
UIGraphPatches.MinDataPoints,
UIGraphPatches.VisibleEndTime,
UIGraphPatches.BuildLabels
UIGraphPatches.BuildLabels,
WeatherManagerPatch.SimulationStepImpl
};

if (Compatibility.IsModActive(Compatibility.CitizenLifecycleRebalanceId))
Expand All @@ -287,6 +297,21 @@ private static IEnumerable<IPatch> GetMethodPatches()
return patches;
}

private static bool CheckRequiredMethodPatches(HashSet<IPatch> appliedPatches)
{
IPatch[] requiredPatches =
{
BuildingAIPatches.HandleWorkers,
BuildingAIPatches.CommercialSimulation,
ResidentAIPatch.Location,
ResidentAIPatch.ArriveAtTarget,
TouristAIPatch.Location,
TransferManagerPatch.AddOutgoingOffer
};

return requiredPatches.All(appliedPatches.Contains);
}

private static bool SetupCustomAI(
TimeInfo timeInfo,
RealTimeConfig config,
Expand Down
19 changes: 16 additions & 3 deletions src/RealTime/Core/RealTimeMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,22 @@ public override void OnLevelLoaded(LoadMode mode)
localizationProvider.Translate(TranslationKeys.Warning),
localizationProvider.Translate(TranslationKeys.ModNotWorkingMessage));
}
else if (configProvider.Configuration.ShowIncompatibilityNotifications)
{
Compatibility.CheckAndNotify(Name, localizationProvider);
else
{
string restricted = core.IsRestrictedMode
? localizationProvider.Translate(TranslationKeys.RestrictedMode)
: null;

bool showMessage = core.IsRestrictedMode;
if (configProvider.Configuration.ShowIncompatibilityNotifications)
{
showMessage = Compatibility.CheckAndNotify(Name, localizationProvider, restricted);
}

if (showMessage)
{
Compatibility.Notify(Name + " - " + localizationProvider.Translate(TranslationKeys.Warning), restricted);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/RealTime/Localization/TranslationKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ internal static class TranslationKeys
/// <summary>The warning key.</summary>
public const string Warning = "Warning";

/// <summary>The key for the 'restricted mode' notification.</summary>
public const string RestrictedMode = "RestrictedModeMessage";

/// <summary>The key for a 'mod not working' message.</summary>
public const string ModNotWorkingMessage = "ModNotWorkingMessage";

Expand Down
1 change: 1 addition & 0 deletions src/RealTime/Localization/Translations/de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<language id="de" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<translation id="Warning" value="Warnung" />
<translation id="RestrictedModeMessage" value="Real Time funktioniert im eingeschränkten Modus. Einige Funktionen sind nicht verfügbar. Die Ursache liegt entweder an einem technischen Problem einer third-party Bibliothek oder an einer Mod-Inkompatibilität. Für Unterstützung zeigen Sie dem Entwickler das Log-File von Cities:Skylines." />
<translation id="ModNotWorkingMessage" value="Oh je! Etwas ist schief gelaufen - die Mod 'Real Time' kann nicht aktiviert werden. Bitte zeigen Sie das Log-File von Cities:Skylines dem Entwickler." />
<translation id="IncompatibleModsFoundMessage" value="Real Time etdeckte zumindest eine inkompatible Mod (oder teilweise inkompatible). Es wird empfohlen, davon abzumelden. Weiterspielen ist auf eigenes Risiko möglich, etwas könnte dabei aber nicht funktionieren oder das Spiel könnte abstürzen." />
<translation id="Minutes" value="Min." />
Expand Down
1 change: 1 addition & 0 deletions src/RealTime/Localization/Translations/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<language id="en" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<translation id="Warning" value="Warning" />
<translation id="RestrictedModeMessage" value="Real Time works in restricted mode. Some functionality is disabled. This is because of a technical issue with a third-party library or a mod incompatibility. If you want assistance, please share your game log file with the mod's developer." />
<translation id="ModNotWorkingMessage" value="Oops! Something went wrong - the 'Real Time' mod could not be activated. Please share your game log file with the mod's developer." />
<translation id="IncompatibleModsFoundMessage" value="Real Time detected at least one incompatible mod (or at least partly incompatible). It is recommended to unsubscribe from them. You might continue on your own risk if you know what you are doing, but in this case something might not work properly or even crash the game." />
<translation id="Minutes" value="min." />
Expand Down
1 change: 1 addition & 0 deletions src/RealTime/Localization/Translations/es.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<language id="es" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<translation id="Warning" value="Atención" />
<translation id="RestrictedModeMessage" value="Real Time works in restricted mode. Some functionality is disabled. This is because of a technical issue with a third-party library or a mod incompatibility. If you want assistance, please share your game log file with the mod's developer." />
<translation id="ModNotWorkingMessage" value="¡Oops! Algo ha ido mal - el mod 'Real Time' no se ha podido activar. Por favor, comparte el archivo log con el desarrollador del mod." />
<translation id="IncompatibleModsFoundMessage" value="Real Time detected at least one incompatible mod (or at least partly incompatible). It is recommended to unsubscribe from them. You might continue on your own risk if you know what you are doing, but in this case something might not work properly or even crash the game." />
<translation id="Minutes" value="min." />
Expand Down
1 change: 1 addition & 0 deletions src/RealTime/Localization/Translations/fr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<language id="fr" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<translation id="Warning" value="Attention" />
<translation id="RestrictedModeMessage" value="Real Time works in restricted mode. Some functionality is disabled. This is because of a technical issue with a third-party library or a mod incompatibility. If you want assistance, please share your game log file with the mod's developer." />
<translation id="ModNotWorkingMessage" value="Oops! Quelque chose s'est mal passé - le mod 'Temps réel' n'a pas pu être activé. Veuillez partager le journal du fichier du jeu avec le développeur du mod." />
<translation id="IncompatibleModsFoundMessage" value="Real Time detected at least one incompatible mod (or at least partly incompatible). It is recommended to unsubscribe from them. You might continue on your own risk if you know what you are doing, but in this case something might not work properly or even crash the game." />
<translation id="Minutes" value="min." />
Expand Down
1 change: 1 addition & 0 deletions src/RealTime/Localization/Translations/ko.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<language id="ko" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<translation id="Warning" value="경고" />
<translation id="RestrictedModeMessage" value="Real Time works in restricted mode. Some functionality is disabled. This is because of a technical issue with a third-party library or a mod incompatibility. If you want assistance, please share your game log file with the mod's developer." />
<translation id="ModNotWorkingMessage" value="어이쿠! 무엇인가 잘못되었습니다 - 모드가 정상 동작하지 않습니다! 모드 제작자에게 로그 파일을 보내주세요." />
<translation id="IncompatibleModsFoundMessage" value="Real Time 모드가 최소 한개 이상의 호환되지 않는(혹은 부분적으로 호환되지 않는) 모드를 발견했습니다. 해당 모드를 구독해제 하시는 것을 추천드립니다. 여러분이 원하신다면 놔두셔도 상관없지만, 게임이 정상적으로 흐르지 않거나 튕길 가능성이 있습니다." />
<translation id="Minutes" value="" />
Expand Down
1 change: 1 addition & 0 deletions src/RealTime/Localization/Translations/pl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<language id="pl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<translation id="Warning" value="Warning" />
<translation id="RestrictedModeMessage" value="Real Time works in restricted mode. Some functionality is disabled. This is because of a technical issue with a third-party library or a mod incompatibility. If you want assistance, please share your game log file with the mod's developer." />
<translation id="ModNotWorkingMessage" value="Oops! Something went wrong - the 'Real Time' mod could not be activated. Please share your game log file with the mod's developer." />
<translation id="IncompatibleModsFoundMessage" value="Real Time detected at least one incompatible mod (or at least partly incompatible). It is recommended to unsubscribe from them. You might continue on your own risk if you know what you are doing, but in this case something might not work properly or even crash the game." />
<translation id="Minutes" value="min." />
Expand Down
1 change: 1 addition & 0 deletions src/RealTime/Localization/Translations/pt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<language id="pt" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<translation id="Warning" value="Aviso" />
<translation id="RestrictedModeMessage" value="Real Time works in restricted mode. Some functionality is disabled. This is because of a technical issue with a third-party library or a mod incompatibility. If you want assistance, please share your game log file with the mod's developer." />
<translation id="ModNotWorkingMessage" value="Oops! Algo deu errado - o mod 'Real Time' não pode ser ativado. Por favor envie o log do seu jogo para o desenvolvedor do mod." />
<translation id="IncompatibleModsFoundMessage" value="Real Time detected at least one incompatible mod (or at least partly incompatible). It is recommended to unsubscribe from them. You might continue on your own risk if you know what you are doing, but in this case something might not work properly or even crash the game." />
<translation id="Minutes" value="min." />
Expand Down
1 change: 1 addition & 0 deletions src/RealTime/Localization/Translations/ru.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<language id="ru" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<translation id="Warning" value="Предупреждение" />
<translation id="RestrictedModeMessage" value="Real Time работает в ограниченном режиме. Некоторые функции недоступны. Причина этого может быть в технических проблемах сторонней библиотеки или несовместимости с другими модами. Если требуется помощь, покажите лог-файл игры разработчику мода." />
<translation id="ModNotWorkingMessage" value="Упс! Что-то пошло не так - мод 'Real Time' не может быть активирован. Пожалуйста, покажите лог-файл игры разработчику мода." />
<translation id="IncompatibleModsFoundMessage" value="Real Time обнаружил как минимум один несовместимый мод (или частично несовместимый). Рекомендуется отписаться от всех несовместимых модов. Можно продолжить играть на свой собственный риск, но что-то может не работать или игра может вылетать." />
<translation id="Minutes" value="мин." />
Expand Down
1 change: 1 addition & 0 deletions src/RealTime/Localization/Translations/zh.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<language id="zh" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<translation id="Warning" value="警告" />
<translation id="RestrictedModeMessage" value="Real Time works in restricted mode. Some functionality is disabled. This is because of a technical issue with a third-party library or a mod incompatibility. If you want assistance, please share your game log file with the mod's developer." />
<translation id="ModNotWorkingMessage" value="啊! 出问题了 - Real Time模组无法启用. 请把你的log记录文件分享给该模组的开发者." />
<translation id="IncompatibleModsFoundMessage" value="Real Time detected at least one incompatible mod (or at least partly incompatible). It is recommended to unsubscribe from them. You might continue on your own risk if you know what you are doing, but in this case something might not work properly or even crash the game." />
<translation id="Minutes" value="min." />
Expand Down
2 changes: 1 addition & 1 deletion src/SkyTools

0 comments on commit 7f6b1fc

Please sign in to comment.