Skip to content

Commit

Permalink
Merge pull request #678 from qsb-dev/dev
Browse files Browse the repository at this point in the history
Version 1.1.0
  • Loading branch information
JohnCorby authored Apr 25, 2024
2 parents 5cfaf77 + 40c2c22 commit d37787b
Show file tree
Hide file tree
Showing 51 changed files with 477 additions and 135 deletions.
4 changes: 2 additions & 2 deletions APITestMod/APITestMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OuterWildsGameLibs" Version="1.1.13.457" IncludeAssets="compile" />
<PackageReference Include="OWML" Version="2.9.7" IncludeAssets="compile" />
<PackageReference Include="OuterWildsGameLibs" Version="1.1.14.768" IncludeAssets="compile" />
<PackageReference Include="OWML" Version="2.11.1" IncludeAssets="compile" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion APITestMod/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"name": "QSB API Test Mod",
"uniqueName": "_nebula.QSBAPITest",
"version": "1.0.0",
"owmlVersion": "2.9.7",
"owmlVersion": "2.11.1",
"dependencies": [ "Raicuparta.QuantumSpaceBuddies", "_nebula.MenuFramework" ]
}
16 changes: 11 additions & 5 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
> :warning: Warning! :warning:
Mod development needs a powerful PC!
Unexpected errors and issues may occur when editing networking code.
Running multiple instances of the game can be very taxing on your computer.
We're not responsible if you push your PC too hard.
> [!WARNING]
> Mod development needs a powerful PC!\
> Unexpected errors and issues may occur when editing networking code.\
> Running multiple instances of the game can be very taxing on your computer.\
> We're not responsible if you push your PC too hard.
## Prerequisites
- Visual Studio 2022.
Expand Down Expand Up @@ -48,6 +48,9 @@ Use the API by copying [the API definition](https://github.com/misternebula/quan
## Debugging
### Debug Actions :

> [!NOTE]
> this list is slightly outdated. it will be updated when debug settings are updated
Press Q + Numpad Enter to toggle debug mode in game (corresponds with the debug setting "debugMode" in the section below).

Hold Q and press :
Expand All @@ -65,6 +68,9 @@ Hold Q and press :

### Debug Settings :

> [!NOTE]
> this list is slightly outdated because it will be replaced by mod options at some point
Create a file called `debugsettings.json` in the QSB folder.
The template for this file is this :

Expand Down
2 changes: 1 addition & 1 deletion FizzySteamworks/FizzySteamworks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="OuterWildsGameLibs" Version="1.1.13.457" IncludeAssets="compile" />
<PackageReference Include="OuterWildsGameLibs" Version="1.1.14.768" IncludeAssets="compile" />
<Reference Include="..\Lib\*.dll" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions MirrorWeaver/MirrorWeaver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="OuterWildsGameLibs" Version="1.1.13.457" />
<PackageReference Include="OWML" Version="2.9.7" />
<PackageReference Include="OuterWildsGameLibs" Version="1.1.14.768" />
<PackageReference Include="OWML" Version="2.11.1" />
<Reference Include="..\Lib\*.dll" />
</ItemGroup>
</Project>
64 changes: 64 additions & 0 deletions QSB-NH/Patches/GameStateMessagePatches.cs
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);
}
}
}
33 changes: 33 additions & 0 deletions QSB-NH/Patches/NewHorizonsDataPatches.cs
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;
}
}
32 changes: 32 additions & 0 deletions QSB-NH/QSB-NH.csproj
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>
59 changes: 59 additions & 0 deletions QSB-NH/QSBNH.cs
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;
}
}
}
}
13 changes: 13 additions & 0 deletions QSB-NH/QuantumPlanet/QuantumPlanetManager.cs
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>();
}
7 changes: 7 additions & 0 deletions QSB-NH/QuantumPlanet/WorldObjects/QSBQuantumPlanet.cs
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>
{
}
Loading

0 comments on commit d37787b

Please sign in to comment.