// Vanilla caches are tied to the original game mode. Release its exact
// components before takeover. Some vanilla destructors unconditionally clear
// their static cache later; resolve those getters from the current takeover
// owner so delayed destruction cannot invalidate the replacement.
modded class SCR_ArsenalManagerComponent
{
 static void ERR_ReleaseTerrainSingleton(SCR_ArsenalManagerComponent expected)
 {
  if (s_Instance == expected) s_Instance = null;
 }
}

modded class SCR_GroupsManagerComponent
{
 static void ERR_ReleaseTerrainSingleton(SCR_GroupsManagerComponent expected)
 {
  if (s_Instance == expected) s_Instance = null;
 }
}

modded class SCR_SupportStationManagerComponent
{
 static void ERR_ReleaseTerrainSingleton(SCR_SupportStationManagerComponent expected)
 {
  if (s_Instance == expected) s_Instance = null;
 }
}

modded class SCR_TaskFinishHistoryManagerComponent
{
 static void ERR_ReleaseTerrainSingleton(SCR_TaskFinishHistoryManagerComponent expected)
 {
  if (s_Instance == expected) s_Instance = null;
 }
 override static SCR_TaskFinishHistoryManagerComponent GetInstance()
 {
  ERR_TerrainTakeoverMode mode;
  if (GetGame()) mode = ERR_TerrainTakeoverMode.Cast(GetGame().GetGameMode());
  if (mode) return SCR_TaskFinishHistoryManagerComponent.Cast(mode.FindComponent(SCR_TaskFinishHistoryManagerComponent));
  return super.GetInstance();
 }
}

modded class SCR_TaskManagerUIComponent
{
 static void ERR_ReleaseTerrainSingleton(SCR_TaskManagerUIComponent expected)
 {
  if (s_Instance == expected) s_Instance = null;
 }
 override static SCR_TaskManagerUIComponent GetInstance()
 {
  ERR_TerrainTakeoverMode mode;
  if (GetGame()) mode = ERR_TerrainTakeoverMode.Cast(GetGame().GetGameMode());
  if (mode) return SCR_TaskManagerUIComponent.Cast(mode.FindComponent(SCR_TaskManagerUIComponent));
  return super.GetInstance();
 }
}

modded class SCR_TextsTaskManagerComponent
{
 static void ERR_ReleaseTerrainSingleton(SCR_TextsTaskManagerComponent expected)
 {
  if (s_Instance == expected) s_Instance = null;
 }
 override static SCR_TextsTaskManagerComponent GetInstance()
 {
  ERR_TerrainTakeoverMode mode;
  if (GetGame()) mode = ERR_TerrainTakeoverMode.Cast(GetGame().GetGameMode());
  if (mode) return SCR_TextsTaskManagerComponent.Cast(mode.FindComponent(SCR_TextsTaskManagerComponent));
  return super.GetInstance();
 }
}

modded class SCR_MapMarkerManagerComponent
{
 override static SCR_MapMarkerManagerComponent GetInstance()
 {
  ERR_TerrainTakeoverMode mode;
  if (GetGame()) mode = ERR_TerrainTakeoverMode.Cast(GetGame().GetGameMode());
  if (mode) return SCR_MapMarkerManagerComponent.Cast(mode.FindComponent(SCR_MapMarkerManagerComponent));
  return super.GetInstance();
 }
}

modded class SCR_RespawnSystemComponent
{
 override static SCR_RespawnSystemComponent GetInstance()
 {
  ERR_TerrainTakeoverMode mode;
  if (GetGame()) mode = ERR_TerrainTakeoverMode.Cast(GetGame().GetGameMode());
  if (mode) return SCR_RespawnSystemComponent.Cast(mode.FindComponent(SCR_RespawnSystemComponent));
  return super.GetInstance();
 }
}

