|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using HarmonyLib; |
| 7 | +using Mirror; |
| 8 | +using NewHorizons; |
| 9 | +using QSB; |
| 10 | +using QSB.Patches; |
| 11 | +using QSB.Player; |
| 12 | +using QSB.SaveSync.Messages; |
| 13 | +using QSB.Utility; |
| 14 | + |
| 15 | +namespace QSBNH.Patches; |
| 16 | + |
| 17 | + |
| 18 | +/// <summary> |
| 19 | +/// extremely jank way to inject system and NH addons when joining. |
| 20 | +/// this should probably be split into its own separate message, but it doesnt really matter :P |
| 21 | +/// |
| 22 | +/// BUG: completely explodes if one person has NH and the other does not |
| 23 | +/// </summary> |
| 24 | +internal class GameStateMessagePatches : QSBPatch |
| 25 | +{ |
| 26 | + public override QSBPatchTypes Type => QSBPatchTypes.OnModStart; |
| 27 | + |
| 28 | + private static string _initialSystem; |
| 29 | + private static int[] _hostAddonHash; |
| 30 | + |
| 31 | + [HarmonyPostfix] |
| 32 | + [HarmonyPatch(typeof(GameStateMessage), nameof(GameStateMessage.Serialize))] |
| 33 | + public static void GameStateMessage_Serialize(GameStateMessage __instance, NetworkWriter writer) |
| 34 | + { |
| 35 | + var currentSystem = QSBNH.Instance.NewHorizonsAPI.GetCurrentStarSystem(); |
| 36 | + |
| 37 | + writer.Write(currentSystem); |
| 38 | + writer.WriteArray(QSBNH.HashAddonsForSystem(currentSystem)); |
| 39 | + } |
| 40 | + |
| 41 | + [HarmonyPostfix] |
| 42 | + [HarmonyPatch(typeof(GameStateMessage), nameof(GameStateMessage.Deserialize))] |
| 43 | + public static void GameStateMessage_Deserialize(GameStateMessage __instance, NetworkReader reader) |
| 44 | + { |
| 45 | + _initialSystem = reader.Read<string>(); |
| 46 | + _hostAddonHash = reader.ReadArray<int>(); |
| 47 | + } |
| 48 | + |
| 49 | + [HarmonyPostfix] |
| 50 | + [HarmonyPatch(typeof(GameStateMessage), nameof(GameStateMessage.OnReceiveRemote))] |
| 51 | + public static void GameStateMessage_OnReceiveRemote() |
| 52 | + { |
| 53 | + if (QSBCore.IsHost) |
| 54 | + { |
| 55 | + DebugLog.DebugWrite($"Why is the host being given the initial state info?"); |
| 56 | + } |
| 57 | + else |
| 58 | + { |
| 59 | + DebugLog.DebugWrite($"Player#{QSBPlayerManager.LocalPlayerId} is being sent to {_initialSystem}"); |
| 60 | + |
| 61 | + WarpManager.RemoteChangeStarSystem(_initialSystem, false, false, _hostAddonHash); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments