mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-03-22 10:23:26 +08:00
UXAssist: hide all universe simulators and messages while hide UIs in space
This commit is contained in:
@@ -191,6 +191,78 @@ public class PersistPatch : PatchImpl<PersistPatch>
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
// Disable rendering when hideAllUI0 is true
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(GameLogic), nameof(GameLogic.LateUpdate))]
|
||||
[HarmonyPatch(typeof(GameLogic), nameof(GameLogic.Draw))]
|
||||
[HarmonyPatch(typeof(GameLogic), nameof(GameLogic.DrawPost))]
|
||||
private static IEnumerable<CodeInstruction> GameLogic_LateUpdate_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.Start();
|
||||
matcher.CreateLabel(out var label);
|
||||
matcher.InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Call, AccessTools.PropertyGetter(typeof(UIRoot), nameof(UIRoot.instance))),
|
||||
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(UIRoot), nameof(UIRoot.uiGame))),
|
||||
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(UIGame), nameof(UIGame.hideAllUI0))),
|
||||
new CodeInstruction(OpCodes.Brfalse, label),
|
||||
new CodeInstruction(OpCodes.Ret)
|
||||
);
|
||||
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
static bool _preHideAllUI0 = false;
|
||||
static bool _localPlanetChanged = false;
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(UIGame), nameof(UIGame._OnLateUpdate))]
|
||||
private static void UIGame__OnLateUpdate_Prefix(UIGame __instance)
|
||||
{
|
||||
_preHideAllUI0 = __instance.hideAllUI0;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UIGame), nameof(UIGame._OnLateUpdate))]
|
||||
private static void UIGame__OnLateUpdate_Postfix(UIGame __instance)
|
||||
{
|
||||
var hideAllUI0 = __instance.hideAllUI0;
|
||||
if (_localPlanetChanged)
|
||||
{
|
||||
_localPlanetChanged = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_preHideAllUI0 == hideAllUI0) return;
|
||||
}
|
||||
var show = GameMain.localPlanet != null || !hideAllUI0;
|
||||
GameMain.data?.mainPlayer?.effect.sailEffect.gameObject.SetActive(!hideAllUI0);
|
||||
var universeSimulator = GameMain.universeSimulator;
|
||||
if (universeSimulator == null) return;
|
||||
universeSimulator.gameObject.SetActive(show);
|
||||
var planetSimulators = universeSimulator.planetSimulators;
|
||||
if (planetSimulators == null) return;
|
||||
foreach (var planet in planetSimulators)
|
||||
{
|
||||
if (planet == null) continue;
|
||||
planet.gameObject.SetActive(show);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(UniverseSimulator), nameof(UniverseSimulator.SetPlanetSimulator))]
|
||||
private static void UniverseSimulator_SetPlanetSimulator_Postfix(UniverseSimulator __instance, PlanetSimulator sim)
|
||||
{
|
||||
if (GameMain.localPlanet == null && UIRoot.instance.uiGame.hideAllUI0) sim.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(GameData), nameof(GameData.localPlanet), MethodType.Setter)]
|
||||
private static void GameData_localPlanet_Setter_Prefix(GameData __instance, PlanetData value)
|
||||
{
|
||||
var oldPlanet = __instance.localPlanet;
|
||||
if (oldPlanet == null && value != null || oldPlanet != null && value == null) _localPlanetChanged = true;
|
||||
}
|
||||
|
||||
#region Cluster Upload Result
|
||||
|
||||
[HarmonyPostfix]
|
||||
|
||||
Reference in New Issue
Block a user