-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #678 from qsb-dev/dev
Version 1.1.0
- Loading branch information
Showing
51 changed files
with
477 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using HarmonyLib; | ||
using Mirror; | ||
using NewHorizons; | ||
using QSB; | ||
using QSB.Patches; | ||
using QSB.Player; | ||
using QSB.SaveSync.Messages; | ||
using QSB.Utility; | ||
|
||
namespace QSBNH.Patches; | ||
|
||
|
||
/// <summary> | ||
/// extremely jank way to inject system and NH addons when joining. | ||
/// this should probably be split into its own separate message, but it doesnt really matter :P | ||
/// | ||
/// BUG: completely explodes if one person has NH and the other does not | ||
/// </summary> | ||
internal class GameStateMessagePatches : QSBPatch | ||
{ | ||
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart; | ||
|
||
private static string _initialSystem; | ||
private static int[] _hostAddonHash; | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(GameStateMessage), nameof(GameStateMessage.Serialize))] | ||
public static void GameStateMessage_Serialize(GameStateMessage __instance, NetworkWriter writer) | ||
{ | ||
var currentSystem = QSBNH.Instance.NewHorizonsAPI.GetCurrentStarSystem(); | ||
|
||
writer.Write(currentSystem); | ||
writer.WriteArray(QSBNH.HashAddonsForSystem(currentSystem)); | ||
} | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(GameStateMessage), nameof(GameStateMessage.Deserialize))] | ||
public static void GameStateMessage_Deserialize(GameStateMessage __instance, NetworkReader reader) | ||
{ | ||
_initialSystem = reader.Read<string>(); | ||
_hostAddonHash = reader.ReadArray<int>(); | ||
} | ||
|
||
[HarmonyPostfix] | ||
[HarmonyPatch(typeof(GameStateMessage), nameof(GameStateMessage.OnReceiveRemote))] | ||
public static void GameStateMessage_OnReceiveRemote() | ||
{ | ||
if (QSBCore.IsHost) | ||
{ | ||
DebugLog.DebugWrite($"Why is the host being given the initial state info?"); | ||
} | ||
else | ||
{ | ||
DebugLog.DebugWrite($"Player#{QSBPlayerManager.LocalPlayerId} is being sent to {_initialSystem}"); | ||
|
||
WarpManager.RemoteChangeStarSystem(_initialSystem, false, false, _hostAddonHash); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using HarmonyLib; | ||
using NewHorizons.External; | ||
using QSB; | ||
using QSB.Patches; | ||
using QSB.SaveSync; | ||
using QSB.Utility; | ||
|
||
namespace QSBNH.Patches; | ||
|
||
/// <summary> | ||
/// pretends to be a new profile when in multiplayer so NH saves its data to a new place | ||
/// </summary> | ||
public class NewHorizonsDataPatches : QSBPatch | ||
{ | ||
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart; | ||
|
||
[HarmonyPrefix] | ||
[HarmonyPatch(typeof(NewHorizonsData), nameof(NewHorizonsData.GetProfileName))] | ||
public static bool NewHorizonsData_GetProfileName(out string __result) | ||
{ | ||
if (QSBCore.IsInMultiplayer) | ||
{ | ||
__result = QSBStandaloneProfileManager.SharedInstance?.currentProfile?.profileName + "_mult"; | ||
DebugLog.DebugWrite($"using fake multiplayer profile {__result} for NH"); | ||
} | ||
else | ||
{ | ||
__result = QSBStandaloneProfileManager.SharedInstance?.currentProfile?.profileName; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net48</TargetFramework> | ||
<RootNamespace>QSBNH</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<OutputPath Condition="Exists('$(OwmlDir)')">$(OwmlDir)\Mods\Raicuparta.QuantumSpaceBuddies</OutputPath> | ||
<NoWarn>CS1998;CS0649</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="lib\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\QSB\QSB.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="Mirror"> | ||
<HintPath>..\Lib\Mirror.dll</HintPath> | ||
</Reference> | ||
<Reference Include="NewHorizons"> | ||
<HintPath>lib\NewHorizons.dll</HintPath> | ||
<Private>false</Private> | ||
</Reference> | ||
<Reference Include="UniTask"> | ||
<HintPath>..\Lib\UniTask.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Mirror; | ||
using NewHorizons; | ||
using OWML.Common; | ||
using OWML.ModHelper; | ||
using QSB; | ||
using QSB.Utility; | ||
using UnityEngine; | ||
|
||
namespace QSBNH | ||
{ | ||
public class QSBNH : MonoBehaviour | ||
{ | ||
public static QSBNH Instance; | ||
|
||
public INewHorizons NewHorizonsAPI; | ||
|
||
private void Start() | ||
{ | ||
Instance = this; | ||
DebugLog.DebugWrite($"Start of QSB-NH compatibility code.", MessageType.Success); | ||
NewHorizonsAPI = QSBCore.Helper.Interaction.TryGetModApi<INewHorizons>("xen.NewHorizons"); | ||
} | ||
|
||
public static string HashToMod(int hash) | ||
{ | ||
foreach (var mod in NewHorizons.Main.MountedAddons) | ||
{ | ||
var name = mod.ModHelper.Manifest.UniqueName; | ||
if (name.GetStableHashCode() == hash) | ||
{ | ||
return name; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static int[] HashAddonsForSystem(string system) | ||
{ | ||
if (NewHorizons.Main.BodyDict.TryGetValue(system, out var bodies)) | ||
{ | ||
var addonHashes = bodies | ||
.Where(x => x.Mod.ModHelper.Manifest.UniqueName != "xen.NewHorizons") | ||
.Select(x => x.Mod.ModHelper.Manifest.UniqueName.GetStableHashCode()) | ||
.Distinct(); | ||
|
||
var nhPlanetHashes = bodies | ||
.Where(x => x.Mod.ModHelper.Manifest.UniqueName == "xen.NewHorizons") | ||
.Select(x => x.Config.name.GetStableHashCode()); | ||
|
||
return addonHashes.Concat(nhPlanetHashes).ToArray(); | ||
} | ||
else | ||
{ | ||
return null; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Cysharp.Threading.Tasks; | ||
using QSB.WorldSync; | ||
using QSBNH.QuantumPlanet.WorldObjects; | ||
|
||
namespace QSBNH.QuantumPlanet; | ||
public class QuantumPlanetManager : WorldObjectManager | ||
{ | ||
public override WorldObjectScene WorldObjectScene => WorldObjectScene.Both; | ||
public override bool DlcOnly => false; | ||
|
||
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) => | ||
QSBWorldSync.Init<QSBQuantumPlanet, NewHorizons.Components.Quantum.QuantumPlanet>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using QSB.QuantumSync.WorldObjects; | ||
|
||
namespace QSBNH.QuantumPlanet.WorldObjects; | ||
|
||
public class QSBQuantumPlanet : QSBQuantumObject<NewHorizons.Components.Quantum.QuantumPlanet> | ||
{ | ||
} |
Oops, something went wrong.