Switch all patches over to HarmonyLib

This commit is contained in:
Nick 2022-05-05 20:15:18 -04:00
parent c953ee6de0
commit e6ac6c9c8a
19 changed files with 891 additions and 765 deletions

View File

@ -24,8 +24,6 @@ using OWML.Common.Menus;
using UnityEngine;
using UnityEngine.SceneManagement;
using Logger = NewHorizons.Utility.Logger;
using NewHorizons.Builder.Atmosphere;
using PacificEngine.OW_CommonResources.Geometry.Orbits;
using NewHorizons.Utility.CommonResources;
using UnityEngine.Events;
using HarmonyLib;
@ -99,6 +97,9 @@ namespace NewHorizons
public void Start()
{
// Patches
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
OnChangeStarSystem = new StarSystemEvent();
OnStarSystemLoaded = new StarSystemEvent();
@ -113,15 +114,6 @@ namespace NewHorizons
BodyDict["EyeOfTheUniverse"] = new List<NewHorizonsBody>(); // Keep this empty tho fr
SystemDict["SolarSystem"] = new NewHorizonsSystem("SolarSystem", new StarSystemConfig(null), this);
// Patches
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
Tools.Patches.Apply();
Tools.WarpDrivePatches.Apply();
Tools.OWCameraFix.Apply();
Tools.ShipLogPatches.Apply();
Tools.TranslationPatches.Apply();
Logger.Log("Begin load of config files...", Logger.LogType.Log);
try

View File

@ -0,0 +1,134 @@
using HarmonyLib;
using NewHorizons.Builder.Props;
using NewHorizons.Components;
using NewHorizons.External;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class AudioSignalPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.SignalNameToString))]
public static bool AudioSignal_SignalNameToString(SignalName __0, ref string __result)
{
var customSignalName = SignalBuilder.GetCustomSignalName(__0);
if (customSignalName == null) return true;
else
{
__result = TranslationHandler.GetTranslation(customSignalName, TranslationHandler.TextType.UI).ToUpper();
return false;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.FrequencyToIndex))]
public static bool AudioSignal_FrequencyToIndex(SignalFrequency __0, ref int __result)
{
switch (__0)
{
case (SignalFrequency.Default):
__result = 0;
break;
case (SignalFrequency.Traveler):
__result = 1;
break;
case (SignalFrequency.Quantum):
__result = 2;
break;
case (SignalFrequency.EscapePod):
__result = 3;
break;
case (SignalFrequency.WarpCore):
__result = 4;
break;
case (SignalFrequency.HideAndSeek):
__result = 5;
break;
case (SignalFrequency.Radio):
__result = 6;
break;
case (SignalFrequency.Statue):
__result = 7;
break;
default:
// Frequencies are in powers of 2
__result = (int)(Mathf.Log((float)__0) / Mathf.Log(2f));
break;
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.IndexToFrequency))]
public static bool AudioSignal_IndexToFrequency(int __0, ref SignalFrequency __result)
{
switch (__0)
{
case 0:
__result = SignalFrequency.Default;
break;
case 1:
__result = SignalFrequency.Traveler;
break;
case 2:
__result = SignalFrequency.Quantum;
break;
case 3:
__result = SignalFrequency.EscapePod;
break;
case 4:
__result = SignalFrequency.WarpCore;
break;
case 5:
__result = SignalFrequency.HideAndSeek;
break;
case 6:
__result = SignalFrequency.Radio;
break;
case 7:
__result = SignalFrequency.Statue;
break;
default:
__result = (SignalFrequency)(Math.Pow(2, __0));
break;
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.FrequencyToString))]
public static bool AudioSignal_FrequencyToString(SignalFrequency __0, ref string __result)
{
var customName = SignalBuilder.GetCustomFrequencyName(__0);
if (customName != null && customName != "")
{
if (NewHorizonsData.KnowsFrequency(customName)) __result = TranslationHandler.GetTranslation(customName, TranslationHandler.TextType.UI).ToUpper();
else __result = UITextLibrary.GetString(UITextType.SignalFreqUnidentified);
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.UpdateSignalStrength))]
public static bool AudioSignal_UpdateSignalStrength(AudioSignal __instance, Signalscope __0, float __1)
{
// I hate this, just because I can't override the base method in CloakedAudioSignal
if (__instance is CloakedAudioSignal)
{
((CloakedAudioSignal)__instance).UpdateSignalStrength(__0, __1);
return false;
}
return true;
}
}
}

View File

@ -0,0 +1,124 @@
using NewHorizons.Builder.General;
using NewHorizons.Builder.Props;
using NewHorizons.Components;
using NewHorizons.External;
using OWML.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using HarmonyLib;
using NewHorizons.Utility;
using OWML.Utils;
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
using Object = UnityEngine.Object;
using NewHorizons.Handlers;
using NewHorizons.Builder.ShipLog;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class EyeOfTheUniversePatches
{
// Funny eye of the universe stuff
[HarmonyPrefix]
[HarmonyPatch(typeof(DeathManager), nameof(DeathManager.KillPlayer))]
public static bool DeathManager_KillPlayer()
{
return (Main.Instance.CurrentStarSystem != "EyeOfTheUniverse");
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipThrusterController), nameof(ShipThrusterController.ReadTranslationalInput))]
public static bool ShipThrusterController_ReadTranslationalInput(ShipThrusterController __instance, ref Vector3 __result)
{
if (Main.Instance.CurrentStarSystem != "EyeOfTheUniverse") return true;
float value = OWInput.GetValue(InputLibrary.thrustX, InputMode.All);
float value2 = OWInput.GetValue(InputLibrary.thrustZ, InputMode.All);
float value3 = OWInput.GetValue(InputLibrary.thrustUp, InputMode.All);
float value4 = OWInput.GetValue(InputLibrary.thrustDown, InputMode.All);
if (!OWInput.IsInputMode(InputMode.ShipCockpit | InputMode.LandingCam))
{
__result = Vector3.zero;
return false;
}
if (!__instance._shipResources.AreThrustersUsable())
{
__result = Vector3.zero;
return false;
}
if (__instance._autopilot.IsFlyingToDestination())
{
__result = Vector3.zero;
return false;
}
Vector3 vector = new Vector3(value, 0f, value2);
if (vector.sqrMagnitude > 1f)
{
vector.Normalize();
}
vector.y = value3 - value4;
if (__instance._requireIgnition && __instance._landingManager.IsLanded())
{
vector.x = 0f;
vector.z = 0f;
vector.y = Mathf.Clamp01(vector.y);
if (!__instance._isIgniting && __instance._lastTranslationalInput.y <= 0f && vector.y > 0f)
{
__instance._isIgniting = true;
__instance._ignitionTime = Time.time;
GlobalMessenger.FireEvent("StartShipIgnition");
}
if (__instance._isIgniting)
{
if (vector.y <= 0f)
{
__instance._isIgniting = false;
GlobalMessenger.FireEvent("CancelShipIgnition");
}
if (Time.time < __instance._ignitionTime + __instance._ignitionDuration)
{
vector.y = 0f;
}
else
{
__instance._isIgniting = false;
__instance._requireIgnition = false;
GlobalMessenger.FireEvent("CompleteShipIgnition");
RumbleManager.PlayShipIgnition();
}
}
}
float d = __instance._thrusterModel.GetMaxTranslationalThrust() / __instance._thrusterModel.GetMaxTranslationalThrust();
Vector3 vector2 = vector * d;
if (__instance._limitOrbitSpeed && vector2.magnitude > 0f)
{
Vector3 vector3 = __instance._landingRF.GetOWRigidBody().GetWorldCenterOfMass() - __instance._shipBody.GetWorldCenterOfMass();
Vector3 vector4 = __instance._shipBody.GetVelocity() - __instance._landingRF.GetVelocity();
Vector3 vector5 = vector4 - Vector3.Project(vector4, vector3);
Vector3 vector6 = Quaternion.FromToRotation(-__instance._shipBody.transform.up, vector3) * __instance._shipBody.transform.TransformDirection(vector2 * __instance._thrusterModel.GetMaxTranslationalThrust());
Vector3 vector7 = Vector3.Project(vector6, vector3);
Vector3 vector8 = vector6 - vector7;
Vector3 a = vector5 + vector8 * Time.deltaTime;
float magnitude = a.magnitude;
float orbitSpeed = __instance._landingRF.GetOrbitSpeed(vector3.magnitude);
if (magnitude > orbitSpeed)
{
a = a.normalized * orbitSpeed;
vector8 = (a - vector5) / Time.deltaTime;
vector6 = vector7 + vector8;
vector2 = __instance._shipBody.transform.InverseTransformDirection(vector6 / __instance._thrusterModel.GetMaxTranslationalThrust());
}
}
__instance._lastTranslationalInput = vector;
__result = vector2;
return false;
}
}
}

View File

@ -0,0 +1,25 @@
using HarmonyLib;
using NewHorizons.Builder.Props;
using NewHorizons.Components;
using NewHorizons.External;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class LocatorPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(Locator), nameof(Locator.RegisterCloakFieldController))]
public static bool Locator_RegisterCloakFieldController()
{
return Locator._cloakFieldController == null;
}
}
}

View File

@ -0,0 +1,32 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class MapControllerPatches
{
[HarmonyPostfix]
[HarmonyPatch(typeof(MapController), nameof(MapController.Awake))]
public static void MapController_Awake(MapController __instance, ref float ____maxPanDistance, ref float ____maxZoomDistance, ref float ____minPitchAngle, ref float ____zoomSpeed)
{
____maxPanDistance = Main.FurthestOrbit * 1.5f;
____maxZoomDistance *= 6f;
____minPitchAngle = -90f;
____zoomSpeed *= 4f;
__instance._mapCamera.farClipPlane = Main.FurthestOrbit * 10f;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(MapController), nameof(MapController.OnTargetReferenceFrame))]
public static void MapController_OnTargetReferenceFrame(MapController __instance, ReferenceFrame __0)
{
__instance._isLockedOntoMapSatellite = true;
}
}
}

View File

@ -1,20 +1,19 @@
using System;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Tools
namespace NewHorizons.Patches
{
public static class OWCameraFix
[HarmonyPatch]
public static class OWCameraPatch
{
public static void Apply()
{
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<OWCamera>("Awake", typeof(OWCameraFix), nameof(OWCameraFix.OnOWCameraAwake));
}
private static void OnOWCameraAwake(OWCamera __instance)
[HarmonyPostfix]
[HarmonyPatch(typeof(OWCamera), nameof(OWCamera.Awake))]
public static void OnOWCameraAwake(OWCamera __instance)
{
var oldDist = __instance.farClipPlane;
var newDist = __instance.farClipPlane * 10f;

View File

@ -0,0 +1,128 @@
using HarmonyLib;
using NewHorizons.Builder.Props;
using NewHorizons.External;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class PlayerDataPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerData), nameof(PlayerData.KnowsFrequency))]
public static bool OnPlayerDataKnowsFrequency(SignalFrequency __0, ref bool __result)
{
var freqString = SignalBuilder.GetCustomFrequencyName(__0);
if (freqString != null && freqString != "")
{
__result = NewHorizonsData.KnowsFrequency(freqString);
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerData), nameof(PlayerData.LearnFrequency))]
public static bool OnPlayerDataLearnFrequency(SignalFrequency __0)
{
var freqString = SignalBuilder.GetCustomFrequencyName(__0);
if (freqString != null && freqString != "")
{
NewHorizonsData.LearnFrequency(freqString);
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerData), nameof(PlayerData.KnowsSignal))]
public static bool OnPlayerDataKnowsSignal(SignalName __0, ref bool __result)
{
var customSignalName = SignalBuilder.GetCustomSignalName(__0);
if (customSignalName != null)
{
__result = NewHorizonsData.KnowsSignal(customSignalName);
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerData), nameof(PlayerData.LearnSignal))]
public static bool OnPlayerDataLearnSignal(SignalName __0)
{
var customSignalName = SignalBuilder.GetCustomSignalName(__0);
if (customSignalName != null)
{
if (!NewHorizonsData.KnowsSignal(customSignalName)) NewHorizonsData.LearnSignal(customSignalName);
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerData), nameof(PlayerData.KnowsMultipleFrequencies))]
public static bool OnPlayerDataKnowsMultipleFrequencies(ref bool __result)
{
if (NewHorizonsData.KnowsMultipleFrequencies())
{
__result = true;
return false;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerData), nameof(PlayerData.AddNewlyRevealedFactID))]
public static bool OnPlayerDataAddNewlyRevealedFactID(string __0)
{
if (ShipLogHandler.IsModdedFact(__0))
{
NewHorizonsData.AddNewlyRevealedFactID(__0);
return false;
}
else
{
return true;
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerData), nameof(PlayerData.GetNewlyRevealedFactIDs))]
public static bool OnPlayerDataGetNewlyRevealedFactIDs(ref List<string> __result)
{
__result = PlayerData._currentGameSave.newlyRevealedFactIDs.Concat(NewHorizonsData.GetNewlyRevealedFactIDs()).ToList();
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerData), nameof(PlayerData.ClearNewlyRevealedFactIDs))]
public static bool OnPlayerDataClearNewlyRevealedFactIDs()
{
PlayerData._currentGameSave.newlyRevealedFactIDs.Clear();
NewHorizonsData.ClearNewlyRevealedFactIDs();
return false;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerData), nameof(PlayerData.ResetGame))]
public static void OnPlayerDataResetGame()
{
NewHorizonsData.Reset();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerData), nameof(PlayerData.GetNewlyRevealedFactIDs))]
public static void PlayerData_GetNewlyRevealedFactIDs(ref List<string> __result)
{
ShipLogManager manager = Locator.GetShipLogManager();
__result = __result.Where(e => manager.GetFact(e) != null).ToList();
}
}
}

View File

@ -0,0 +1,35 @@
using NewHorizons.Builder.General;
using NewHorizons.Builder.Props;
using NewHorizons.Components;
using NewHorizons.External;
using OWML.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using HarmonyLib;
using NewHorizons.Utility;
using OWML.Utils;
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
using Object = UnityEngine.Object;
using NewHorizons.Handlers;
using NewHorizons.Builder.ShipLog;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class PlayerSpawnerPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerSpawner), nameof(PlayerSpawner.SpawnPlayer))]
public static void PlayerSpawner_SpawnPlayer(PlayerSpawner __instance)
{
Logger.Log("Player spawning");
__instance.SetInitialSpawnPoint(Main.SystemDict[Main.Instance.CurrentStarSystem].SpawnPoint);
}
}
}

View File

@ -0,0 +1,33 @@
using HarmonyLib;
using NewHorizons.Builder.Props;
using NewHorizons.Components;
using NewHorizons.External;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class PlayerStatePatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerState), nameof(PlayerState.CheckShipOutsideSolarSystem))]
public static bool PlayerState_CheckShipOutsideSolarSystem(PlayerState __instance, ref bool __result)
{
if (PlayerState._inBrambleDimension) return false;
// Stop the game from trying to recall your ship when you're visiting far away planets
Transform sunTransform = Locator.GetSunTransform();
OWRigidbody shipBody = Locator.GetShipBody();
var maxDist2 = Mathf.Max(900000000f, Main.FurthestOrbit * Main.FurthestOrbit * 2f);
__result = sunTransform != null && shipBody != null && (sunTransform.position - shipBody.transform.position).sqrMagnitude > maxDist2;
return false;
}
}
}

View File

@ -0,0 +1,25 @@
using HarmonyLib;
using NewHorizons.Builder.Props;
using NewHorizons.Components;
using NewHorizons.External;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class ProbeLauncherPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(ProbeLauncher), nameof(ProbeLauncher.UpdateOrbitalLaunchValues))]
public static bool ProbeLauncher_UpdateOrbitalLaunchValues(ProbeLauncher __instance)
{
return (Locator.GetPlayerRulesetDetector()?.GetPlanetoidRuleset()?.GetGravityVolume() != null);
}
}
}

View File

@ -20,97 +20,97 @@ namespace NewHorizons.Patches
// If it has a river fluid its a normal one and we don't do anything
if (__instance._riverFluid != null) return true;
// Copy paste the original method
if (__instance._raftBody.IsSuspended())
{
return false;
}
bool playerInEffectsRange = __instance._playerInEffectsRange;
__instance._playerInEffectsRange = ((Locator.GetPlayerBody().GetPosition() - __instance._raftBody.GetPosition()).sqrMagnitude < 2500f);
if (playerInEffectsRange && !__instance._playerInEffectsRange)
{
__instance._effectsController.StopAllEffects();
}
if (__instance._dock != null || __instance._movingToTarget)
{
__instance._localAcceleration = Vector3.zero;
if (__instance._playerInEffectsRange)
{
__instance._effectsController.UpdateMovementAudio(false, __instance._lightSensors);
}
if (__instance._movingToTarget)
{
__instance.UpdateMoveToTarget();
}
return false;
}
if (__instance._fluidDetector.InFluidType(FluidVolume.Type.WATER))
{
if (__instance._lightSensors[0].IsIlluminated())
{
__instance._localAcceleration += Vector3.forward * __instance._acceleration;
}
if (__instance._lightSensors[1].IsIlluminated())
{
__instance._localAcceleration += Vector3.right * __instance._acceleration;
}
if (__instance._lightSensors[2].IsIlluminated())
{
__instance._localAcceleration -= Vector3.forward * __instance._acceleration;
}
if (__instance._lightSensors[3].IsIlluminated())
{
__instance._localAcceleration -= Vector3.right * __instance._acceleration;
}
}
if (__instance._localAcceleration.sqrMagnitude > 0.001f)
{
__instance._raftBody.AddLocalAcceleration(__instance._localAcceleration);
}
if (__instance._playerInEffectsRange)
{
// All this to change what fluidVolume we use on this line
float num = __instance._fluidDetector.InFluidType(FluidVolume.Type.WATER) ? __instance._fluidDetector._alignmentFluid.GetFractionSubmerged(__instance._fluidDetector) : 0f;
bool allowMovement = num > 0.25f && num < 1f;
__instance._effectsController.UpdateMovementAudio(allowMovement, __instance._lightSensors);
__instance._effectsController.UpdateGroundedAudio(__instance._fluidDetector);
}
__instance._localAcceleration = Vector3.zero;
// Copy paste the original method
if (__instance._raftBody.IsSuspended())
{
return false;
}
bool playerInEffectsRange = __instance._playerInEffectsRange;
__instance._playerInEffectsRange = ((Locator.GetPlayerBody().GetPosition() - __instance._raftBody.GetPosition()).sqrMagnitude < 2500f);
if (playerInEffectsRange && !__instance._playerInEffectsRange)
{
__instance._effectsController.StopAllEffects();
}
if (__instance._dock != null || __instance._movingToTarget)
{
__instance._localAcceleration = Vector3.zero;
if (__instance._playerInEffectsRange)
{
__instance._effectsController.UpdateMovementAudio(false, __instance._lightSensors);
}
if (__instance._movingToTarget)
{
__instance.UpdateMoveToTarget();
}
return false;
}
if (__instance._fluidDetector.InFluidType(FluidVolume.Type.WATER))
{
if (__instance._lightSensors[0].IsIlluminated())
{
__instance._localAcceleration += Vector3.forward * __instance._acceleration;
}
if (__instance._lightSensors[1].IsIlluminated())
{
__instance._localAcceleration += Vector3.right * __instance._acceleration;
}
if (__instance._lightSensors[2].IsIlluminated())
{
__instance._localAcceleration -= Vector3.forward * __instance._acceleration;
}
if (__instance._lightSensors[3].IsIlluminated())
{
__instance._localAcceleration -= Vector3.right * __instance._acceleration;
}
}
if (__instance._localAcceleration.sqrMagnitude > 0.001f)
{
__instance._raftBody.AddLocalAcceleration(__instance._localAcceleration);
}
if (__instance._playerInEffectsRange)
{
// All this to change what fluidVolume we use on this line
float num = __instance._fluidDetector.InFluidType(FluidVolume.Type.WATER) ? __instance._fluidDetector._alignmentFluid.GetFractionSubmerged(__instance._fluidDetector) : 0f;
bool allowMovement = num > 0.25f && num < 1f;
__instance._effectsController.UpdateMovementAudio(allowMovement, __instance._lightSensors);
__instance._effectsController.UpdateGroundedAudio(__instance._fluidDetector);
}
__instance._localAcceleration = Vector3.zero;
return false;
}
[HarmonyReversePatch]
[HarmonyPatch(typeof(AsymmetricFluidDetector), "ManagedFixedUpdate")]
public static void AsymmetricFluidDetector_ManagedFixedUpdate(AsymmetricFluidDetector __instance)
{
// This is like doing base.FixedUpdate
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AlignToSurfaceFluidDetector), "ManagedFixedUpdate")]
public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance)
[HarmonyReversePatch]
[HarmonyPatch(typeof(AsymmetricFluidDetector), "ManagedFixedUpdate")]
public static void AsymmetricFluidDetector_ManagedFixedUpdate(AsymmetricFluidDetector __instance)
{
if (!__instance._alignmentFluid is NHFluidVolume) return true;
// This is like doing base.FixedUpdate
}
// Mostly copy pasting from the AlignWithDirection class
AsymmetricFluidDetector_ManagedFixedUpdate(__instance);
[HarmonyPrefix]
[HarmonyPatch(typeof(AlignToSurfaceFluidDetector), "ManagedFixedUpdate")]
public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance)
{
if (!__instance._alignmentFluid is NHFluidVolume) return true;
if (__instance._inAlignmentFluid)
{
// Both in world space
var currentDirection = __instance._owRigidbody.transform.up;
var alignmentDirection = (__instance.transform.position - __instance._alignmentFluid.transform.position).normalized;
var degreesToTarget = Vector3.Angle(currentDirection, alignmentDirection);
// Mostly copy pasting from the AlignWithDirection class
AsymmetricFluidDetector_ManagedFixedUpdate(__instance);
var adjustedSlerpRate = Mathf.Clamp01(100f / degreesToTarget * Time.fixedDeltaTime);
if (__instance._inAlignmentFluid)
{
// Both in world space
var currentDirection = __instance._owRigidbody.transform.up;
var alignmentDirection = (__instance.transform.position - __instance._alignmentFluid.transform.position).normalized;
var degreesToTarget = Vector3.Angle(currentDirection, alignmentDirection);
Vector3 a = OWPhysics.FromToAngularVelocity(currentDirection, alignmentDirection);
__instance._owRigidbody.SetAngularVelocity(Vector3.zero);
__instance._owRigidbody.AddAngularVelocityChange(a * adjustedSlerpRate);
}
var adjustedSlerpRate = Mathf.Clamp01(10f / degreesToTarget * Time.fixedDeltaTime);
return false;
}
}
Vector3 a = OWPhysics.FromToAngularVelocity(currentDirection, alignmentDirection);
//__instance._owRigidbody.SetAngularVelocity(Vector3.zero);
__instance._owRigidbody.AddAngularVelocityChange(a * adjustedSlerpRate);
}
return false;
}
}
}

View File

@ -8,32 +8,16 @@ using Logger = NewHorizons.Utility.Logger;
using Object = UnityEngine.Object;
using NewHorizons.Builder.ShipLog;
using NewHorizons.Handlers;
using HarmonyLib;
namespace NewHorizons.Tools
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class ShipLogPatches
{
public static void Apply()
{
var playerDataGetNewlyRevealedFactIDs = typeof(PlayerData).GetMethod("GetNewlyRevealedFactIDs");
Main.Instance.ModHelper.HarmonyHelper.AddPostfix(playerDataGetNewlyRevealedFactIDs, typeof(ShipLogPatches), nameof(ShipLogPatches.OnPlayerDataGetNewlyRevealedFactIDsComplete));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ShipLogManager>("Awake", typeof(ShipLogPatches), nameof(ShipLogPatches.OnShipLogManagerAwake));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ShipLogManager>("Start", typeof(ShipLogPatches), nameof(ShipLogPatches.OnShipLogManagerStart));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ShipLogManager>("IsFactRevealed", typeof(ShipLogPatches), nameof(ShipLogPatches.OnShipLogManagerIsFactRevealed));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ShipLogManager>("CheckForCompletionAchievement", typeof(ShipLogPatches), nameof(ShipLogPatches.OnShipLogManagerCheckForCompletionAchievement));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<UIStyleManager>("GetCuriosityColor", typeof(ShipLogPatches), nameof(ShipLogPatches.OnUIStyleManagerGetCuriosityColor));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ShipLogSandFunnel>("Awake", typeof(ShipLogPatches), nameof(ShipLogPatches.DisableShipLogSandFunnel));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ShipLogSandFunnel>("UpdateState", typeof(ShipLogPatches), nameof(ShipLogPatches.DisableShipLogSandFunnel));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ShipLogAstroObject>("GetName", typeof(ShipLogPatches), nameof(ShipLogPatches.OnShipLogAstroObjectGetName));
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<ShipLogMapMode>("Initialize", typeof(ShipLogPatches), nameof(ShipLogPatches.OnShipLogMapModeInitialize));
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<ShipLogManager>("Awake", typeof(ShipLogPatches), nameof(ShipLogPatches.OnShipLogManagerAwakeComplete));
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<ShipLogAstroObject>("UpdateState", typeof(ShipLogPatches), nameof(ShipLogPatches.OnShipLogAstroObjectUpdateState));
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<ShipLogManager>(nameof(ShipLogManager.RevealFact), typeof(ShipLogPatches), nameof(ShipLogPatches.OnShipLogManagerRevealFact));
}
public static void OnShipLogManagerAwake(ShipLogManager __instance)
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.Awake))]
public static void ShipLogManager_Awake_Prefix(ShipLogManager __instance)
{
RumorModeBuilder.Init();
ShipLogHandler.Init();
@ -64,7 +48,9 @@ namespace NewHorizons.Tools
}
}
public static void OnShipLogManagerAwakeComplete(ShipLogManager __instance)
[HarmonyPostfix]
[HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.Awake))]
public static void ShipLogManager_Awake_Postfix(ShipLogManager __instance)
{
ShipLogHandler.CheckForModdedFacts(__instance);
RumorModeBuilder.GenerateEntryData(__instance);
@ -77,7 +63,9 @@ namespace NewHorizons.Tools
Logger.Log("Ship Log Generation Complete For: " + Main.Instance.CurrentStarSystem, Logger.LogType.Log);
}
public static bool OnShipLogManagerIsFactRevealed(ShipLogManager __instance, ref bool __result, string __0)
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.IsFactRevealed))]
public static bool ShipLogManager_IsFactRevealed(ShipLogManager __instance, ref bool __result, string __0)
{
if (__instance._factDict != null && __instance._factDict.ContainsKey(__0))
{
@ -91,7 +79,9 @@ namespace NewHorizons.Tools
return false;
}
public static bool OnShipLogManagerCheckForCompletionAchievement(ShipLogManager __instance)
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.CheckForCompletionAchievement))]
public static bool ShipLogManager_CheckForCompletionAchievement(ShipLogManager __instance)
{
foreach (KeyValuePair<string, ShipLogFact> keyValuePair in __instance._factDict)
{
@ -104,7 +94,9 @@ namespace NewHorizons.Tools
return false;
}
public static bool OnShipLogManagerStart(ShipLogManager __instance)
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.Start))]
public static bool ShipLogManager_Start(ShipLogManager __instance)
{
foreach (NewHorizonsBody body in Main.BodyDict[Main.Instance.CurrentStarSystem])
{
@ -125,9 +117,11 @@ namespace NewHorizons.Tools
}
}
public static bool OnUIStyleManagerGetCuriosityColor(UIStyleManager __instance, CuriosityName __0, bool __1, ref Color __result)
[HarmonyPrefix]
[HarmonyPatch(typeof(UIStyleManager), nameof(UIStyleManager.GetCuriosityColor))]
public static bool UIStyleManager_GetCuriosityColor(UIStyleManager __instance, CuriosityName __0, bool __1, ref Color __result)
{
if ((int) __0 < 7)
if ((int)__0 < 7)
{
return true;
}
@ -138,7 +132,9 @@ namespace NewHorizons.Tools
}
}
public static void OnShipLogMapModeInitialize(ShipLogMapMode __instance)
[HarmonyPostfix]
[HarmonyPatch(typeof(ShipLogMapMode), nameof(ShipLogMapMode.Initialize))]
public static void ShipLogMapMode_Initialize(ShipLogMapMode __instance)
{
GameObject panRoot = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH);
GameObject sunObject = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/Sun");
@ -168,7 +164,9 @@ namespace NewHorizons.Tools
Logger.Log("Map Mode Construction Complete", Logger.LogType.Log);
}
public static bool OnShipLogAstroObjectGetName(ShipLogAstroObject __instance, ref string __result)
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipLogAstroObject), nameof(ShipLogAstroObject.GetName))]
public static bool ShipLogAstroObject_GetName(ShipLogAstroObject __instance, ref string __result)
{
if (ShipLogHandler.IsVanillaAstroID(__instance.GetID()))
{
@ -181,15 +179,16 @@ namespace NewHorizons.Tools
}
}
public static void OnShipLogAstroObjectUpdateState(ShipLogAstroObject __instance)
[HarmonyPostfix]
[HarmonyPatch(typeof(ShipLogAstroObject), nameof(ShipLogAstroObject.UpdateState))]
public static void ShipLogAstroObject_UpdateState(ShipLogAstroObject __instance)
{
Transform detailsParent = __instance.transform.Find("Details");
if (detailsParent != null)
{
foreach (GameObject child in SearchUtilities.GetAllChildren(detailsParent.gameObject))
{
Component detail;
if (child.TryGetComponent(typeof(ShipLogDetail), out detail))
if (child.TryGetComponent(typeof(ShipLogDetail), out Component detail))
{
(detail as ShipLogDetail)?.UpdateState(__instance._state);
}
@ -204,18 +203,23 @@ namespace NewHorizons.Tools
}
}
public static bool DisableShipLogSandFunnel()
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipLogSandFunnel), nameof(ShipLogSandFunnel.UpdateState))]
public static bool ShipLogSandFunnel_UpdateState()
{
return Main.Instance.CurrentStarSystem == "SolarSystem";
}
public static void OnPlayerDataGetNewlyRevealedFactIDsComplete(ref List<string> __result)
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipLogSandFunnel), nameof(ShipLogSandFunnel.Awake))]
public static bool ShipLogSandFunnel_Awake()
{
ShipLogManager manager = Locator.GetShipLogManager();
__result = __result.Where(e => manager.GetFact(e) != null).ToList();
return Main.Instance.CurrentStarSystem == "SolarSystem";
}
public static void OnShipLogManagerRevealFact(string __0)
[HarmonyPostfix]
[HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.RevealFact))]
public static void ShipLogManager_RevealFact(string __0)
{
StarChartHandler.OnRevealFact(__0);
}

View File

@ -0,0 +1,41 @@
using HarmonyLib;
using NewHorizons.Builder.Props;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class SignalScopePatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(Signalscope), nameof(Signalscope.Awake))]
public static bool Signalscope_Awake(Signalscope __instance, ref AudioSignal[] ____strongestSignals)
{
____strongestSignals = new AudioSignal[8];
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Signalscope), nameof(Signalscope.SwitchFrequencyFilter))]
public static bool Signalscope_SwitchFrequencyFilter(Signalscope __instance, int __0)
{
var increment = __0;
var count = SignalBuilder.NumberOfFrequencies;
__instance._frequencyFilterIndex += increment;
__instance._frequencyFilterIndex = ((__instance._frequencyFilterIndex >= count) ? 0 : __instance._frequencyFilterIndex);
__instance._frequencyFilterIndex = ((__instance._frequencyFilterIndex < 0) ? count - 1 : __instance._frequencyFilterIndex);
SignalFrequency signalFrequency = AudioSignal.IndexToFrequency(__instance._frequencyFilterIndex);
if (!PlayerData.KnowsFrequency(signalFrequency) && (!__instance._isUnknownFreqNearby || __instance._unknownFrequency != signalFrequency))
{
__instance.SwitchFrequencyFilter(increment);
}
return false;
}
}
}

View File

@ -0,0 +1,60 @@
using HarmonyLib;
using NewHorizons.Builder.Props;
using NewHorizons.Components;
using NewHorizons.External;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class SingularityPatches
{
// For our custom black holes that don't link to anything
[HarmonyPrefix]
[HarmonyPatch(typeof(BlackHoleVolume), nameof(BlackHoleVolume.Start))]
public static bool BlackHoleVolume_Start(BlackHoleVolume __instance)
{
return __instance._whiteHole == null;
}
// To fix custom white holes
[HarmonyPrefix]
[HarmonyPatch(typeof(WhiteHoleVolume), nameof(WhiteHoleVolume.Awake))]
public static bool WhiteHoleVolume_Awake(WhiteHoleVolume __instance)
{
__instance._growQueue = new List<OWRigidbody>(8);
__instance._growQueueLocationData = new List<RelativeLocationData>(8);
__instance._ejectedBodyList = new List<OWRigidbody>(64);
try
{
__instance._whiteHoleBody = __instance.gameObject.GetAttachedOWRigidbody(false);
__instance._whiteHoleProxyShadowSuperGroup = __instance._whiteHoleBody.GetComponentInChildren<ProxyShadowCasterSuperGroup>();
__instance._fluidVolume = __instance.gameObject.GetRequiredComponent<WhiteHoleFluidVolume>();
}
catch (Exception) { }
return false;
}
// This is to stop the game throwing too many errors if the probe is destroyed by a blackhole
[HarmonyPrefix]
[HarmonyPatch(typeof(SurveyorProbe), nameof(SurveyorProbe.IsLaunched))]
public static bool SurveyorProbe_IsLaunched(SurveyorProbe __instance, ref bool __result)
{
try
{
__result = __instance.gameObject.activeSelf;
}
catch (Exception)
{
__result = true;
}
return false;
}
}
}

View File

@ -0,0 +1,54 @@
using HarmonyLib;
using NewHorizons.Builder.Props;
using NewHorizons.Components;
using NewHorizons.External;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class SunPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(SunLightParamUpdater), nameof(SunLightParamUpdater.LateUpdate))]
public static bool SunLightParamUpdater_LateUpdate(SunLightParamUpdater __instance)
{
if (__instance.sunLight)
{
Vector3 position = __instance.transform.position;
float w = 2000f;
if (__instance._sunController != null)
{
w = (__instance._sunController.HasSupernovaStarted() ? __instance._sunController.GetSupernovaRadius() : __instance._sunController.GetSurfaceRadius());
}
float range = __instance.sunLight.range;
Color color = (__instance._sunLightController != null) ? __instance._sunLightController.sunColor : __instance.sunLight.color;
float w2 = (__instance._sunLightController != null) ? __instance._sunLightController.sunIntensity : __instance.sunLight.intensity;
Shader.SetGlobalVector(__instance._propID_SunPosition, new Vector4(position.x, position.y, position.z, w));
Shader.SetGlobalVector(__instance._propID_OWSunPositionRange, new Vector4(position.x, position.y, position.z, 1f / (range * range)));
Shader.SetGlobalVector(__instance._propID_OWSunColorIntensity, new Vector4(color.r, color.g, color.b, w2));
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(SunSurfaceAudioController), nameof(SunSurfaceAudioController.Update))]
public static bool SunSurfaceAudioController_Update(SunSurfaceAudioController __instance)
{
if (__instance._sunController != null) return true;
var surfaceRadius = __instance.transform.parent.parent.localScale.magnitude;
float value = Mathf.Max(0f, Vector3.Distance(Locator.GetPlayerCamera().transform.position, __instance.transform.position) - surfaceRadius);
float num = Mathf.InverseLerp(1600f, 100f, value);
__instance._audioSource.SetLocalVolume(num * num * __instance._fade);
return false;
}
}
}

View File

@ -0,0 +1,49 @@
using HarmonyLib;
using NewHorizons.Components.Orbital;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class TranslationPatches
{
[HarmonyPrefix]
[HarmonyPatch(typeof(ReferenceFrame), nameof(ReferenceFrame.GetHUDDisplayName))]
public static bool ReferenceFrame_GetHUDDisplayName(ReferenceFrame __instance, ref string __result)
{
var ao = __instance.GetAstroObject();
if (ao == null) return true;
if (ao is NHAstroObject)
{
if ((ao as NHAstroObject).HideDisplayName) __result = "";
else __result = TranslationHandler.GetTranslation(ao.GetCustomName(), TranslationHandler.TextType.UI);
return false;
}
return true;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(CanvasMapMarker), nameof(CanvasMapMarker.Init), new Type[] { typeof(Canvas), typeof(Transform), typeof(string) })]
public static void CanvasMapMarker_Init(CanvasMapMarker __instance)
{
__instance._label = TranslationHandler.GetTranslation(__instance._label, TranslationHandler.TextType.UI);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(CanvasMapMarker), nameof(CanvasMapMarker.SetLabel))]
public static void CanvasMapMarker_SetLabel(CanvasMapMarker __instance)
{
__instance._label = TranslationHandler.GetTranslation(__instance._label, TranslationHandler.TextType.UI);
}
}
}

View File

@ -1,4 +1,5 @@
using NewHorizons.Builder.General;
using HarmonyLib;
using NewHorizons.Builder.General;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
@ -7,18 +8,14 @@ using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Tools
namespace NewHorizons.Patches
{
[HarmonyPatch]
public static class WarpDrivePatches
{
public static void Apply()
{
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ShipCockpitController>("Update", typeof(WarpDrivePatches), nameof(WarpDrivePatches.OnShipCockpitControllerUpdate));
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<ShipLogMapMode>("EnterMode", typeof(WarpDrivePatches), nameof(WarpDrivePatches.OnShipLogMapModeEnterMode));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ShipLogController>("Update", typeof(WarpDrivePatches), nameof(WarpDrivePatches.OnShipLogControllerUpdate));
}
public static void OnShipLogMapModeEnterMode(ShipLogMapMode __instance)
[HarmonyPostfix]
[HarmonyPatch(typeof(ShipLogMapMode), nameof(ShipLogMapMode.EnterMode))]
public static void ShipLogMapMode_EnterMode(ShipLogMapMode __instance)
{
if (!Main.HasWarpDrive) return;
@ -28,7 +25,9 @@ namespace NewHorizons.Tools
text.text = newPrompt;
}
public static bool OnShipCockpitControllerUpdate(ShipCockpitController __instance)
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipCockpitController), nameof(ShipCockpitController.Update))]
public static bool ShipCockpitController_Update(ShipCockpitController __instance)
{
if (!Main.HasWarpDrive) return true;
@ -44,7 +43,9 @@ namespace NewHorizons.Tools
return true;
}
public static bool OnShipLogControllerUpdate(ShipLogController __instance)
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipLogController), nameof(ShipLogController.Update))]
public static bool ShipLogController_Update(ShipLogController __instance)
{
if (!Main.HasWarpDrive) return true;
@ -54,6 +55,7 @@ namespace NewHorizons.Tools
|| StarChartHandler.ShipLogStarChartMode == null)
return true;
// Mostly copied from the base method but we're trying to fit in our new mode
__instance._exitPrompt.SetVisibility(__instance._currentMode.AllowCancelInput());
__instance._currentMode.UpdateMode();
if (__instance._currentMode.AllowModeSwap() && OWInput.IsNewlyPressed(InputLibrary.swapShipLogMode, InputMode.All))

View File

@ -1,559 +0,0 @@
using NewHorizons.Builder.General;
using NewHorizons.Builder.Props;
using NewHorizons.Components;
using NewHorizons.External;
using OWML.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using HarmonyLib;
using NewHorizons.Utility;
using OWML.Utils;
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
using Object = UnityEngine.Object;
using NewHorizons.Handlers;
using NewHorizons.Builder.ShipLog;
namespace NewHorizons.Tools
{
public class Patches
{
public static void Apply()
{
// Prefixes
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<PlayerState>("CheckShipOutsideSolarSystem", typeof(Patches), nameof(Patches.CheckShipOutersideSolarSystem));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<SunLightParamUpdater>("LateUpdate", typeof(Patches), nameof(Patches.OnSunLightParamUpdaterLateUpdate));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<SunSurfaceAudioController>("Update", typeof(Patches), nameof(Patches.OnSunSurfaceAudioControllerUpdate));
var locatorRegisterCloakFieldController = typeof(Locator).GetMethod(nameof(Locator.RegisterCloakFieldController));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(locatorRegisterCloakFieldController, typeof(Patches), nameof(Patches.OnLocatorRegisterCloakFieldController));
// Lot of audio signal stuff
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<AudioSignal>("SignalNameToString", typeof(Patches), nameof(Patches.OnAudioSignalSignalNameToString));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<AudioSignal>("IndexToFrequency", typeof(Patches), nameof(Patches.OnAudioSignalIndexToFrequency));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<AudioSignal>("FrequencyToIndex", typeof(Patches), nameof(Patches.OnAudioSignalFrequencyToIndex));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<AudioSignal>("FrequencyToString", typeof(Patches), nameof(Patches.OnAudioSignalFrequencyToString));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<Signalscope>("Awake", typeof(Patches), nameof(Patches.OnSignalscopeAwake));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<Signalscope>("SwitchFrequencyFilter", typeof(Patches), nameof(Patches.OnSignalscopeSwitchFrequencyFilter));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<AudioSignal>("UpdateSignalStrength", typeof(Patches), nameof(Patches.OnAudioSignalUpdateSignalStrength));
var playerDataKnowsSignal = typeof(PlayerData).GetMethod("KnowsSignal");
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataKnowsSignal, typeof(Patches), nameof(Patches.OnPlayerDataKnowsSignal));
var playerDataLearnSignal = typeof(PlayerData).GetMethod("LearnSignal");
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataLearnSignal, typeof(Patches), nameof(Patches.OnPlayerDataLearnSignal));
var playerDataKnowsFrequency = typeof(PlayerData).GetMethod("KnowsFrequency");
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataKnowsFrequency, typeof(Patches), nameof(Patches.OnPlayerDataKnowsFrequency));
var playerDataLearnFrequency = typeof(PlayerData).GetMethod("LearnFrequency");
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataLearnFrequency, typeof(Patches), nameof(Patches.OnPlayerDataLearnFrequency));
var playerDataKnowsMultipleFrequencies = typeof(PlayerData).GetMethod("KnowsMultipleFrequencies");
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataKnowsMultipleFrequencies, typeof(Patches), nameof(Patches.OnPlayerDataKnowsMultipleFrequencies));
var playerDataResetGame = typeof(PlayerData).GetMethod("ResetGame");
Main.Instance.ModHelper.HarmonyHelper.AddPostfix(playerDataResetGame, typeof(Patches), nameof(Patches.OnPlayerDataResetGame));
var playerDataAddNewlyRevealedFactID = typeof(PlayerData).GetMethod("AddNewlyRevealedFactID");
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataAddNewlyRevealedFactID, typeof(Patches), nameof(Patches.OnPlayerDataAddNewlyRevealedFactID));
var playerDataGetNewlyRevealedFactIDs = typeof(PlayerData).GetMethod("GetNewlyRevealedFactIDs");
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataGetNewlyRevealedFactIDs, typeof(Patches), nameof(Patches.OnPlayerDataGetNewlyRevealedFactIDs));
var playerDataClearNewlyRevealedFactIDs = typeof(PlayerData).GetMethod("ClearNewlyRevealedFactIDs");
Main.Instance.ModHelper.HarmonyHelper.AddPrefix(playerDataClearNewlyRevealedFactIDs, typeof(Patches), nameof(Patches.OnPlayerDataClearNewlyRevealedFactIDs));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<BlackHoleVolume>("Start", typeof(Patches), nameof(Patches.OnBlackHoleVolumeStart));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<WhiteHoleVolume>("Awake", typeof(Patches), nameof(Patches.OnWhiteHoleVolumeAwake));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ProbeLauncher>("UpdateOrbitalLaunchValues", typeof(Patches), nameof(Patches.OnProbeLauncherUpdateOrbitalLaunchValues));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<SurveyorProbe>("IsLaunched", typeof(Patches), nameof(Patches.OnSurveyorProbeIsLaunched));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<PlayerSpawner>("SpawnPlayer", typeof(Patches), nameof(Patches.OnPlayerSpawnerSpawnPlayerPreFix));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<DeathManager>("KillPlayer", typeof(Patches), nameof(Patches.OnDeathManagerKillPlayer));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ShipThrusterController>("ReadTranslationalInput", typeof(Patches), nameof(Patches.OnShipThrusterControllerReadTranslationalInput));
// Postfixes
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<MapController>("Awake", typeof(Patches), nameof(Patches.OnMapControllerAwake));
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<MapController>("OnTargetReferenceFrame", typeof(Patches), nameof(Patches.OnMapControllerOnTargetReferenceFrame));
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ScrollItem>("Awake", typeof(Patches), nameof(Patches.OnScrollItemAwake));
}
public static bool CheckShipOutersideSolarSystem(PlayerState __instance, ref bool __result)
{
if (PlayerState._inBrambleDimension) return false;
Transform sunTransform = Locator.GetSunTransform();
OWRigidbody shipBody = Locator.GetShipBody();
var maxDist2 = Mathf.Max(900000000f, Main.FurthestOrbit * Main.FurthestOrbit * 2f);
__result = sunTransform != null && shipBody != null && (sunTransform.position - shipBody.transform.position).sqrMagnitude > maxDist2;
return false;
}
public static void OnMapControllerAwake(MapController __instance, ref float ____maxPanDistance, ref float ____maxZoomDistance, ref float ____minPitchAngle, ref float ____zoomSpeed)
{
____maxPanDistance = Main.FurthestOrbit * 1.5f;
____maxZoomDistance *= 6f;
____minPitchAngle = -90f;
____zoomSpeed *= 4f;
__instance._mapCamera.farClipPlane = Main.FurthestOrbit * 10f;
}
public static bool OnSunLightParamUpdaterLateUpdate(SunLightParamUpdater __instance)
{
if (__instance.sunLight)
{
Vector3 position = __instance.transform.position;
float w = 2000f;
if (__instance._sunController != null)
{
w = (__instance._sunController.HasSupernovaStarted() ? __instance._sunController.GetSupernovaRadius() : __instance._sunController.GetSurfaceRadius());
}
float range = __instance.sunLight.range;
Color color = (__instance._sunLightController != null) ? __instance._sunLightController.sunColor : __instance.sunLight.color;
float w2 = (__instance._sunLightController != null) ? __instance._sunLightController.sunIntensity : __instance.sunLight.intensity;
Shader.SetGlobalVector(__instance._propID_SunPosition, new Vector4(position.x, position.y, position.z, w));
Shader.SetGlobalVector(__instance._propID_OWSunPositionRange, new Vector4(position.x, position.y, position.z, 1f / (range * range)));
Shader.SetGlobalVector(__instance._propID_OWSunColorIntensity, new Vector4(color.r, color.g, color.b, w2));
}
return false;
}
public static bool OnSunSurfaceAudioControllerUpdate(SunSurfaceAudioController __instance)
{
if (__instance._sunController != null) return true;
var surfaceRadius = __instance.transform.parent.parent.localScale.magnitude;
float value = Mathf.Max(0f, Vector3.Distance(Locator.GetPlayerCamera().transform.position, __instance.transform.position) - surfaceRadius);
float num = Mathf.InverseLerp(1600f, 100f, value);
__instance._audioSource.SetLocalVolume(num * num * __instance._fade);
return false;
}
#region AudioSignal
public static bool OnAudioSignalSignalNameToString(SignalName __0, ref string __result)
{
var customSignalName = SignalBuilder.GetCustomSignalName(__0);
if (customSignalName == null) return true;
else
{
__result = TranslationHandler.GetTranslation(customSignalName, TranslationHandler.TextType.UI).ToUpper();
return false;
}
}
public static bool OnAudioSignalFrequencyToIndex(SignalFrequency __0, ref int __result)
{
switch(__0)
{
case (SignalFrequency.Default):
__result = 0;
break;
case (SignalFrequency.Traveler):
__result = 1;
break;
case (SignalFrequency.Quantum):
__result = 2;
break;
case (SignalFrequency.EscapePod):
__result = 3;
break;
case (SignalFrequency.WarpCore):
__result = 4;
break;
case (SignalFrequency.HideAndSeek):
__result = 5;
break;
case (SignalFrequency.Radio):
__result = 6;
break;
case (SignalFrequency.Statue):
__result = 7;
break;
default:
// Frequencies are in powers of 2
__result = (int)(Mathf.Log((float)__0) / Mathf.Log(2f));
break;
}
return false;
}
public static bool OnAudioSignalIndexToFrequency(int __0, ref SignalFrequency __result) {
switch (__0)
{
case 0:
__result = SignalFrequency.Default;
break;
case 1:
__result = SignalFrequency.Traveler;
break;
case 2:
__result = SignalFrequency.Quantum;
break;
case 3:
__result = SignalFrequency.EscapePod;
break;
case 4:
__result = SignalFrequency.WarpCore;
break;
case 5:
__result = SignalFrequency.HideAndSeek;
break;
case 6:
__result = SignalFrequency.Radio;
break;
case 7:
__result = SignalFrequency.Statue;
break;
default:
__result = (SignalFrequency)(Math.Pow(2, __0));
break;
}
return false;
}
public static bool OnAudioSignalFrequencyToString(SignalFrequency __0, ref string __result)
{
var customName = SignalBuilder.GetCustomFrequencyName(__0);
if (customName != null && customName != "")
{
if (NewHorizonsData.KnowsFrequency(customName)) __result = TranslationHandler.GetTranslation(customName, TranslationHandler.TextType.UI).ToUpper();
else __result = UITextLibrary.GetString(UITextType.SignalFreqUnidentified);
return false;
}
return true;
}
public static bool OnAudioSignalUpdateSignalStrength(AudioSignal __instance, Signalscope __0, float __1)
{
// I hate this
if(__instance is CloakedAudioSignal)
{
((CloakedAudioSignal)__instance).UpdateSignalStrength(__0, __1);
return false;
}
return true;
}
#endregion
#region Signalscope
public static bool OnSignalscopeAwake(Signalscope __instance, ref AudioSignal[] ____strongestSignals)
{
____strongestSignals = new AudioSignal[8];
return true;
}
public static bool OnSignalscopeSwitchFrequencyFilter(Signalscope __instance, int __0)
{
var increment = __0;
var count = SignalBuilder.NumberOfFrequencies;
__instance._frequencyFilterIndex += increment;
__instance._frequencyFilterIndex = ((__instance._frequencyFilterIndex >= count) ? 0 : __instance._frequencyFilterIndex);
__instance._frequencyFilterIndex = ((__instance._frequencyFilterIndex < 0) ? count - 1 : __instance._frequencyFilterIndex);
SignalFrequency signalFrequency = AudioSignal.IndexToFrequency(__instance._frequencyFilterIndex);
if (!PlayerData.KnowsFrequency(signalFrequency) && (!__instance._isUnknownFreqNearby || __instance._unknownFrequency != signalFrequency))
{
__instance.SwitchFrequencyFilter(increment);
}
return false;
}
#endregion f
#region PlayerData
public static bool OnPlayerDataKnowsFrequency(SignalFrequency __0, ref bool __result)
{
var freqString = SignalBuilder.GetCustomFrequencyName(__0);
if (freqString != null && freqString != "")
{
__result = NewHorizonsData.KnowsFrequency(freqString);
return false;
}
return true;
}
public static bool OnPlayerDataLearnFrequency(SignalFrequency __0)
{
var freqString = SignalBuilder.GetCustomFrequencyName(__0);
if (freqString != null && freqString != "")
{
NewHorizonsData.LearnFrequency(freqString);
return false;
}
return true;
}
public static bool OnPlayerDataKnowsSignal(SignalName __0, ref bool __result)
{
var customSignalName = SignalBuilder.GetCustomSignalName(__0);
if (customSignalName != null)
{
__result = NewHorizonsData.KnowsSignal(customSignalName);
return false;
}
return true;
}
public static bool OnPlayerDataLearnSignal(SignalName __0)
{
var customSignalName = SignalBuilder.GetCustomSignalName(__0);
if (customSignalName != null)
{
if (!NewHorizonsData.KnowsSignal(customSignalName)) NewHorizonsData.LearnSignal(customSignalName);
return false;
}
return true;
}
public static bool OnPlayerDataKnowsMultipleFrequencies(ref bool __result)
{
if (NewHorizonsData.KnowsMultipleFrequencies())
{
__result = true;
return false;
}
return true;
}
public static bool OnPlayerDataAddNewlyRevealedFactID(string __0)
{
if (ShipLogHandler.IsModdedFact(__0))
{
NewHorizonsData.AddNewlyRevealedFactID(__0);
return false;
}
else
{
return true;
}
}
public static bool OnPlayerDataGetNewlyRevealedFactIDs(ref List<string> __result)
{
__result = PlayerData._currentGameSave.newlyRevealedFactIDs.Concat(NewHorizonsData.GetNewlyRevealedFactIDs()).ToList();
return false;
}
public static bool OnPlayerDataClearNewlyRevealedFactIDs()
{
PlayerData._currentGameSave.newlyRevealedFactIDs.Clear();
NewHorizonsData.ClearNewlyRevealedFactIDs();
return false;
}
public static void OnPlayerDataResetGame()
{
NewHorizonsData.Reset();
}
#endregion
public static bool OnBlackHoleVolumeStart(BlackHoleVolume __instance)
{
return __instance._whiteHole == null;
}
public static bool OnWhiteHoleVolumeAwake(WhiteHoleVolume __instance)
{
__instance._growQueue = new List<OWRigidbody>(8);
__instance._growQueueLocationData = new List<RelativeLocationData>(8);
__instance._ejectedBodyList = new List<OWRigidbody>(64);
try
{
__instance._whiteHoleBody = __instance.gameObject.GetAttachedOWRigidbody(false);
__instance._whiteHoleProxyShadowSuperGroup = __instance._whiteHoleBody.GetComponentInChildren<ProxyShadowCasterSuperGroup>();
__instance._fluidVolume = __instance.gameObject.GetRequiredComponent<WhiteHoleFluidVolume>();
}
catch (Exception) { }
return false;
}
public static bool OnProbeLauncherUpdateOrbitalLaunchValues(ProbeLauncher __instance)
{
return (Locator.GetPlayerRulesetDetector()?.GetPlanetoidRuleset()?.GetGravityVolume() != null);
}
public static bool OnSurveyorProbeIsLaunched(SurveyorProbe __instance, ref bool __result)
{
try
{
__result = __instance.gameObject.activeSelf;
}
catch(Exception)
{
__result = true;
}
return false;
}
public static void OnMapControllerOnTargetReferenceFrame(MapController __instance, ReferenceFrame __0)
{
__instance._isLockedOntoMapSatellite = true;
}
public static void OnPlayerSpawnerSpawnPlayerPreFix(PlayerSpawner __instance)
{
Logger.Log("Player spawning");
__instance.SetInitialSpawnPoint(Main.SystemDict[Main.Instance.CurrentStarSystem].SpawnPoint);
}
public static bool OnDeathManagerKillPlayer()
{
return (Main.Instance.CurrentStarSystem != "EyeOfTheUniverse");
}
public static bool OnShipThrusterControllerReadTranslationalInput(ShipThrusterController __instance, ref Vector3 __result)
{
if (Main.Instance.CurrentStarSystem != "EyeOfTheUniverse") return true;
float value = OWInput.GetValue(InputLibrary.thrustX, InputMode.All);
float value2 = OWInput.GetValue(InputLibrary.thrustZ, InputMode.All);
float value3 = OWInput.GetValue(InputLibrary.thrustUp, InputMode.All);
float value4 = OWInput.GetValue(InputLibrary.thrustDown, InputMode.All);
if (!OWInput.IsInputMode(InputMode.ShipCockpit | InputMode.LandingCam))
{
__result = Vector3.zero;
return false;
}
if (!__instance._shipResources.AreThrustersUsable())
{
__result = Vector3.zero;
return false;
}
if (__instance._autopilot.IsFlyingToDestination())
{
__result = Vector3.zero;
return false;
}
Vector3 vector = new Vector3(value, 0f, value2);
if (vector.sqrMagnitude > 1f)
{
vector.Normalize();
}
vector.y = value3 - value4;
if (__instance._requireIgnition && __instance._landingManager.IsLanded())
{
vector.x = 0f;
vector.z = 0f;
vector.y = Mathf.Clamp01(vector.y);
if (!__instance._isIgniting && __instance._lastTranslationalInput.y <= 0f && vector.y > 0f)
{
__instance._isIgniting = true;
__instance._ignitionTime = Time.time;
GlobalMessenger.FireEvent("StartShipIgnition");
}
if (__instance._isIgniting)
{
if (vector.y <= 0f)
{
__instance._isIgniting = false;
GlobalMessenger.FireEvent("CancelShipIgnition");
}
if (Time.time < __instance._ignitionTime + __instance._ignitionDuration)
{
vector.y = 0f;
}
else
{
__instance._isIgniting = false;
__instance._requireIgnition = false;
GlobalMessenger.FireEvent("CompleteShipIgnition");
RumbleManager.PlayShipIgnition();
}
}
}
float d = __instance._thrusterModel.GetMaxTranslationalThrust() / __instance._thrusterModel.GetMaxTranslationalThrust();
Vector3 vector2 = vector * d;
if (__instance._limitOrbitSpeed && vector2.magnitude > 0f)
{
Vector3 vector3 = __instance._landingRF.GetOWRigidBody().GetWorldCenterOfMass() - __instance._shipBody.GetWorldCenterOfMass();
Vector3 vector4 = __instance._shipBody.GetVelocity() - __instance._landingRF.GetVelocity();
Vector3 vector5 = vector4 - Vector3.Project(vector4, vector3);
Vector3 vector6 = Quaternion.FromToRotation(-__instance._shipBody.transform.up, vector3) * __instance._shipBody.transform.TransformDirection(vector2 * __instance._thrusterModel.GetMaxTranslationalThrust());
Vector3 vector7 = Vector3.Project(vector6, vector3);
Vector3 vector8 = vector6 - vector7;
Vector3 a = vector5 + vector8 * Time.deltaTime;
float magnitude = a.magnitude;
float orbitSpeed = __instance._landingRF.GetOrbitSpeed(vector3.magnitude);
if (magnitude > orbitSpeed)
{
a = a.normalized * orbitSpeed;
vector8 = (a - vector5) / Time.deltaTime;
vector6 = vector7 + vector8;
vector2 = __instance._shipBody.transform.InverseTransformDirection(vector6 / __instance._thrusterModel.GetMaxTranslationalThrust());
}
}
__instance._lastTranslationalInput = vector;
__result = vector2;
return false;
}
public static bool OnLocatorRegisterCloakFieldController()
{
return Locator._cloakFieldController == null;
}
public static bool OnScrollItemAwake(ScrollItem __instance)
{
try
{
__instance._type = ItemType.Scroll;
__instance._nomaiWallText = __instance.GetComponentInChildren<NomaiWallText>();
if (__instance._nomaiWallText == null)
{
Logger.LogError("No NomaiWallText found!");
return false;
}
__instance._nomaiWallText.InitializeAsWhiteboardText();
// base.awake
//base.awake
if (__instance._sector == null)
{
__instance._sector = __instance.GetComponentInParent<Sector>();
}
if (__instance._sector != null)
{
__instance._sector.OnOccupantEnterSector += __instance.OnSectorOccupantAdded;
__instance._sector.OnOccupantExitSector += __instance.OnSectorOccupantRemoved;
__instance._sector.OnSectorOccupantsUpdated += __instance.OnSectorOccupantsUpdated;
}
// back
if (!__instance._prebuilt)
{
__instance.FindComponentsInHierarchy();
}
__instance._parentFragment = __instance.GetComponentInParent<DetachableFragment>();
if (__instance._parentFragment != null)
{
__instance._parentFragment.OnChangeSector += __instance.OnParentFragmentChangeSector;
}
GlobalMessenger.AddListener("EnterMapView", new Callback(__instance.OnEnterMapView));
GlobalMessenger.AddListener("ExitMapView", new Callback(__instance.OnExitMapView));
// Back to normal stuff
for (int i = 0; i < __instance._colliders.Length; i++)
{
if (__instance._colliders[i].GetComponent<NomaiWallText>() != null)
{
__instance._colliders[i] = null;
}
}
return false;
}
catch(Exception e)
{
Logger.LogError($"{e.Message}, {e.StackTrace}");
}
return false;
}
}
}

View File

@ -1,52 +0,0 @@
using NewHorizons.Components.Orbital;
using NewHorizons.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Tools
{
public static class TranslationPatches
{
public static void Apply()
{
Main.Instance.ModHelper.HarmonyHelper.AddPrefix<ReferenceFrame>(nameof(ReferenceFrame.GetHUDDisplayName), typeof(TranslationPatches), nameof(TranslationPatches.GetHUDDisplayName));
var canvasMapMarkerInit = typeof(CanvasMapMarker).GetMethod(nameof(CanvasMapMarker.Init), new Type[] { typeof(Canvas), typeof(Transform), typeof(string) });
Main.Instance.ModHelper.HarmonyHelper.AddPostfix(canvasMapMarkerInit, typeof(TranslationPatches), nameof(TranslationPatches.OnCanvasMapMarkerInit));
Main.Instance.ModHelper.HarmonyHelper.AddPostfix<CanvasMapMarker>(nameof(CanvasMapMarker.SetLabel), typeof(TranslationPatches), nameof(TranslationPatches.OnCanvasMapMarkerSetLabel));
}
public static bool GetHUDDisplayName(ReferenceFrame __instance, ref string __result)
{
var ao = __instance.GetAstroObject();
if (ao == null) return true;
if(ao is NHAstroObject)
{
if((ao as NHAstroObject).HideDisplayName) __result = "";
else __result = TranslationHandler.GetTranslation(ao.GetCustomName(), TranslationHandler.TextType.UI);
return false;
}
return true;
}
public static void OnCanvasMapMarkerInit(CanvasMapMarker __instance)
{
__instance._label = TranslationHandler.GetTranslation(__instance._label, TranslationHandler.TextType.UI);
}
public static void OnCanvasMapMarkerSetLabel(CanvasMapMarker __instance)
{
__instance._label = TranslationHandler.GetTranslation(__instance._label, TranslationHandler.TextType.UI);
}
}
}