Merge pull request #335 from misternebula/village-satellite-sync

Village satellite sync
This commit is contained in:
_nebula 2021-11-03 16:45:20 +00:00 committed by GitHub
commit 5826404701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 301 additions and 47 deletions

View File

@ -52,8 +52,9 @@
<Reference Include="Unity.Cecil.Pdb">
<HintPath>..\..\..\..\..\..\Program Files\Unity\Hub\Editor\2017.4.33f1\Editor\Data\Managed\Unity.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="Unity.UNetWeaver">
<HintPath>..\..\..\..\..\..\Program Files\Unity\Hub\Editor\2017.4.33f1\Editor\Data\Managed\Unity.UNetWeaver.dll</HintPath>
<Reference Include="Unity.UNetWeaver, Version=1.0.7209.2424, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Unity.UNetWeaver.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@ -68,5 +69,8 @@
<Compile Include="Weaver.cs" />
<Compile Include="WeaverLists.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="lib\Unity.UNetWeaver.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Binary file not shown.

View File

@ -89,5 +89,8 @@
public static string QSBDebugEvent = "QSBDebugEvent";
public static string QSBEnterNomaiHeadZone = "QSBEnterNomaiHeadZone";
public static string QSBExitNomaiHeadZone = "QSBExitNomaiHeadZone";
public static string QSBEnterSatelliteCamera = "QSBEnterSatelliteCamera";
public static string QSBExitSatelliteCamera = "QSBExitSatelliteCamera";
public static string QSBSatelliteSnapshot = "QSBSatelliteSnapshot";
}
}

View File

@ -6,6 +6,8 @@
* MISC.
*/
DebugEvent,
SatelliteProjector,
SatelliteProjectorSnapshot,
/*
* SERVER EVENTS

View File

@ -15,6 +15,7 @@ using QSB.Player.Events;
using QSB.ProbeSync.Events;
using QSB.QuantumSync.Events;
using QSB.RoastingSync.Events;
using QSB.SatelliteSync.Events;
using QSB.ShipSync.Events;
using QSB.ShipSync.Events.Component;
using QSB.ShipSync.Events.Hull;
@ -69,6 +70,8 @@ namespace QSB.Events
new ServerStateEvent(),
new ClientStateEvent(),
new DebugEvent(),
new SatelliteProjectorEvent(),
new SatelliteProjectorSnapshotEvent(),
// World Objects
new ElevatorEvent(),
new GeyserEvent(),

View File

@ -16,6 +16,7 @@ using QSB.Player.Patches;
using QSB.PoolSync.Patches;
using QSB.QuantumSync.Patches;
using QSB.RoastingSync.Patches;
using QSB.SatelliteSync.Patches;
using QSB.ShipSync.Patches;
using QSB.StatueSync.Patches;
using QSB.TimeSync.Patches;
@ -67,7 +68,8 @@ namespace QSB.Patches
new MapPatches(),
new RespawnPatches(),
new LauncherPatches(),
new SolanumPatches()
new SolanumPatches(),
new SatelliteProjectorPatches()
};
TypeToInstance = new Dictionary<QSBPatchTypes, Harmony>

View File

@ -200,6 +200,10 @@
<Compile Include="QuantumSync\QuantumManager.cs" />
<Compile Include="QuantumSync\Patches\QuantumVisibilityPatches.cs" />
<Compile Include="QuantumSync\Patches\ServerQuantumPatches.cs" />
<Compile Include="SatelliteSync\Events\SatelliteProjectorEvent.cs" />
<Compile Include="SatelliteSync\Events\SatelliteProjectorSnapshotEvent.cs" />
<Compile Include="SatelliteSync\Patches\SatelliteProjectorPatches.cs" />
<Compile Include="SatelliteSync\SatelliteProjectorManager.cs" />
<Compile Include="SectorSync\TargetType.cs" />
<Compile Include="ClientServerStateSync\Events\ServerStateEvent.cs" />
<Compile Include="ClientServerStateSync\ServerState.cs" />

View File

@ -16,6 +16,7 @@ using QSB.Player;
using QSB.Player.TransformSync;
using QSB.PoolSync;
using QSB.QuantumSync;
using QSB.SatelliteSync;
using QSB.SectorSync;
using QSB.ShipSync;
using QSB.StatueSync;
@ -102,6 +103,7 @@ namespace QSB
gameObject.AddComponent<DebugGUI>();
gameObject.AddComponent<MenuManager>();
gameObject.AddComponent<RespawnManager>();
gameObject.AddComponent<SatelliteProjectorManager>();
// WorldObject managers
gameObject.AddComponent<QuantumManager>();

View File

@ -0,0 +1,42 @@
using QSB.Events;
using QSB.Messaging;
namespace QSB.SatelliteSync.Events
{
class SatelliteProjectorEvent : QSBEvent<BoolMessage>
{
public override EventType Type => EventType.SatelliteProjector;
public override void SetupListener()
{
GlobalMessenger.AddListener(EventNames.QSBEnterSatelliteCamera, () => Handler(true));
GlobalMessenger.AddListener(EventNames.QSBExitSatelliteCamera, () => Handler(false));
}
public override void CloseListener()
{
GlobalMessenger.RemoveListener(EventNames.QSBEnterSatelliteCamera, () => Handler(true));
GlobalMessenger.RemoveListener(EventNames.QSBExitSatelliteCamera, () => Handler(false));
}
private void Handler(bool usingProjector) => SendEvent(CreateMessage(usingProjector));
private BoolMessage CreateMessage(bool usingProjector) => new BoolMessage
{
AboutId = LocalPlayerId,
Value = usingProjector
};
public override void OnReceiveRemote(bool isHost, BoolMessage message)
{
if (message.Value)
{
SatelliteProjectorManager.Instance.RemoteEnter();
}
else
{
SatelliteProjectorManager.Instance.RemoteExit();
}
}
}
}

View File

@ -0,0 +1,34 @@
using QSB.Events;
using QSB.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace QSB.SatelliteSync.Events
{
class SatelliteProjectorSnapshotEvent : QSBEvent<BoolMessage>
{
public override EventType Type => EventType.SatelliteProjectorSnapshot;
public override void SetupListener()
{
GlobalMessenger<bool>.AddListener(EventNames.QSBSatelliteSnapshot, (bool forward) => Handler(forward));
}
public override void CloseListener()
{
GlobalMessenger<bool>.RemoveListener(EventNames.QSBSatelliteSnapshot, (bool forward) => Handler(forward));
}
private void Handler(bool forward) => SendEvent(CreateMessage(forward));
private BoolMessage CreateMessage(bool forward) => new BoolMessage
{
AboutId = LocalPlayerId,
Value = forward
};
public override void OnReceiveRemote(bool isHost, BoolMessage message) => SatelliteProjectorManager.Instance.RemoteTakeSnapshot(message.Value);
}
}

View File

@ -0,0 +1,62 @@
using HarmonyLib;
using QSB.Events;
using QSB.Patches;
using UnityEngine;
namespace QSB.SatelliteSync.Patches
{
[HarmonyPatch]
class SatelliteProjectorPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPrefix]
[HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.OnPressInteract))]
public static bool UseProjector()
{
QSBEventManager.FireEvent(EventNames.QSBEnterSatelliteCamera);
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.TurnOffProjector))]
public static bool LeaveProjector()
{
QSBEventManager.FireEvent(EventNames.QSBExitSatelliteCamera);
return true;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(SatelliteSnapshotController), nameof(SatelliteSnapshotController.Update))]
public static bool UpdateReplacement(SatelliteSnapshotController __instance)
{
if (!OWInput.IsInputMode(InputMode.SatelliteCam))
{
return false;
}
if (OWInput.IsNewlyPressed(InputLibrary.toolActionPrimary, InputMode.All))
{
QSBEventManager.FireEvent(EventNames.QSBSatelliteSnapshot, true);
__instance._satelliteCamera.transform.localEulerAngles = __instance._initCamLocalRot;
__instance.RenderSnapshot();
return false;
}
if (__instance._allowRearview && OWInput.IsNewlyPressed(InputLibrary.toolActionSecondary, InputMode.All))
{
QSBEventManager.FireEvent(EventNames.QSBSatelliteSnapshot, false);
__instance._satelliteCamera.transform.localEulerAngles = __instance._initCamLocalRot + new Vector3(0f, 180f, 0f);
__instance.RenderSnapshot();
return false;
}
if (OWInput.IsNewlyPressed(InputLibrary.cancel, InputMode.All))
{
__instance.TurnOffProjector();
}
return false;
}
}
}

View File

@ -0,0 +1,86 @@
using QSB.Utility;
using System.Linq;
using UnityEngine;
namespace QSB.SatelliteSync
{
class SatelliteProjectorManager : MonoBehaviour
{
public static SatelliteProjectorManager Instance { get; private set; }
public SatelliteSnapshotController Projector { get; private set; }
public void Start()
{
Instance = this;
QSBSceneManager.OnUniverseSceneLoaded += OnSceneLoaded;
}
public void OnDestroy()
{
QSBSceneManager.OnUniverseSceneLoaded -= OnSceneLoaded;
}
private void OnSceneLoaded(OWScene oldScene, OWScene newScene)
{
if (newScene == OWScene.SolarSystem)
{
Projector = Resources.FindObjectsOfTypeAll<SatelliteSnapshotController>().First();
Projector._loopingSource.spatialBlend = 1f;
Projector._oneShotSource.spatialBlend = 1f;
}
}
public void RemoteEnter()
{
Projector.enabled = true;
Projector._interactVolume.DisableInteraction();
if (Projector._showSplashTexture)
{
Projector._splashObject.SetActive(false);
Projector._diagramObject.SetActive(true);
Projector._projectionScreen.gameObject.SetActive(false);
}
if (Projector._fadeLight != null)
{
Projector._fadeLight.StartFade(0f, 2f, 0f);
}
var audioClip = Projector._oneShotSource.PlayOneShot(AudioType.TH_ProjectorActivate, 1f);
Projector._loopingSource.FadeIn(audioClip.length, false, false, 1f);
}
public void RemoteExit()
{
Projector.enabled = false;
Projector._interactVolume.EnableInteraction();
Projector._interactVolume.ResetInteraction();
if (Projector._showSplashTexture)
{
Projector._splashObject.SetActive(true);
Projector._diagramObject.SetActive(false);
Projector._projectionScreen.gameObject.SetActive(false);
}
if (Projector._fadeLight != null)
{
Projector._fadeLight.StartFade(Projector._initLightIntensity, 2f, 0f);
}
var audioClip = Projector._oneShotSource.PlayOneShot(AudioType.TH_ProjectorStop, 1f);
Projector._loopingSource.FadeOut(audioClip.length, OWAudioSource.FadeOutCompleteAction.STOP, 0f);
}
public void RemoteTakeSnapshot(bool forward)
{
Projector._satelliteCamera.transform.localEulerAngles = forward
? Projector._initCamLocalRot
: Projector._initCamLocalRot + new Vector3(0f, 180f, 0f);
Projector.RenderSnapshot();
}
}
}

View File

@ -71,12 +71,20 @@ namespace QSB.Tools.ProbeLauncherTool.Patches
// TODO : ehhhh idk about this. maybe copy each sound source so we have a 2d version (for local) and a 3d version (for remote)?
// this would probably be a whole qsb version on it's own
[HarmonyPostfix]
[HarmonyPrefix]
[HarmonyPatch(typeof(ProbeLauncherEffects), nameof(ProbeLauncherEffects.PlayRetrievalClip))]
public static void ProbeLauncherEffects_PlayRetrievalClip(OWAudioSource ____owAudioSource) => ____owAudioSource.GetAudioSource().spatialBlend = 1f;
public static bool ProbeLauncherEffects_PlayRetrievalClip(OWAudioSource ____owAudioSource)
{
____owAudioSource.GetAudioSource().spatialBlend = 1f;
return true;
}
[HarmonyPostfix]
[HarmonyPrefix]
[HarmonyPatch(typeof(ProbeLauncherEffects), nameof(ProbeLauncherEffects.PlayLaunchClip))]
public static void ProbeLauncherEffects_PlayLaunchClip(OWAudioSource ____owAudioSource) => ____owAudioSource.GetAudioSource().spatialBlend = 1f;
public static bool ProbeLauncherEffects_PlayLaunchClip(OWAudioSource ____owAudioSource)
{
____owAudioSource.GetAudioSource().spatialBlend = 1f;
return true;
}
}
}

View File

@ -3,7 +3,7 @@
"settings": {
"defaultServerIP": "localhost",
"port": 7777,
"debugMode": false,
"debugMode": true,
"showLinesInDebug": false
}
}

View File

@ -1,36 +1,41 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QSB.Patches;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace QSBTests
{
[TestClass]
public class PatchTests
{
//[TestMethod]
//public void CheckUnreferencedPatches()
//{
// var qsbAssembly = Assembly.Load("QSB");
// var allPatchTypes = qsbAssembly
// .GetTypes()
// .Where(x => typeof(QSBPatch).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract);
[TestMethod]
public void CheckUnreferencedPatches()
{
var qsbAssembly = Assembly.Load("QSB");
var allPatchTypes = qsbAssembly
.GetTypes()
.Where(x => typeof(QSBPatch).IsAssignableFrom(x) && !x.IsInterface && !x.IsAbstract);
// QSBPatchManager.Init();
// var patchInstances = (List<QSBPatch>)typeof(QSBPatchManager)
// .GetField("_patchList", BindingFlags.NonPublic | BindingFlags.Static)
// .GetValue(typeof(QSBPatchManager));
QSBPatchManager.Init();
var patchInstances = (List<QSBPatch>)typeof(QSBPatchManager)
.GetField("_patchList", BindingFlags.NonPublic | BindingFlags.Static)
.GetValue(typeof(QSBPatchManager));
// var failedTypes = new List<Type>();
// foreach (var type in allPatchTypes)
// {
// if (!patchInstances.Any(x => x.GetType() == type))
// {
// failedTypes.Add(type);
// }
// }
var failedTypes = new List<Type>();
foreach (var type in allPatchTypes)
{
if (!patchInstances.Any(x => x.GetType() == type))
{
failedTypes.Add(type);
}
}
// if (failedTypes.Count > 0)
// {
// Assert.Fail(string.Join(", ", failedTypes.Select(x => x.Name)));
// }
//}
if (failedTypes.Count > 0)
{
Assert.Fail(string.Join(", ", failedTypes.Select(x => x.Name)));
}
}
}
}

View File

@ -52,8 +52,9 @@
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>$(GameDir)\OuterWilds_Data\Managed\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.Networking">
<HintPath>$(GameDir)\OuterWilds_Data\Managed\UnityEngine.Networking.dll</HintPath>
<Reference Include="UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\QSB\lib\UnityEngine.Networking.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>

View File

@ -91,10 +91,10 @@ QSB relies on exact orders of objects found using Resources.FindObjectsOfTypeAll
| Quantum objects | Yes |
| Repairing ship parts | Yes |
| Repairing "satellite" parts | No |
| Ship | Kinda of |
| Ship | Yes |
| Ship log | Yes |
| Solanum | No |
| Timber Hearth satellite | No |
| Solanum | Yes |
| Timber Hearth satellite | Yes |
| Tornadoes | No |
QSB also changes some mechanics of the base game, to better fit a multiplayer experience. These include :
@ -137,19 +137,15 @@ Note - _nebula has no idea how Hamachi works and has never used it, so don't ask
## Playing as a client
- Run the game.
- You'll see some new buttons on the top left.
- Replace `localhost` with the server's public IP address.
- Press "Connect". You can join servers in the menu or in-game, but it is recommended to join in the main menu.
- If you see "Stop", you are connected.
- If it stops at "Connecting to..." then you or the host has issues with their firewall/router/other.
- On the title/pause menu, select "MULTIPLAYER (CONNECT)".
- Enter the public IP address of the host.
- Hit connect, and pray.
## Playing as a host
- Open port `7777` on your router.
- Run the game.
- You'll see some new buttons on the top left.
- Press "Host". This can be done in-game or in the menu, but it is recommened to start servers in the menu.
- If you now see the "Stop" button, you are hosting.
- On the title/pause menu, select "MULTIPLAYER (HOST)".
- Give your external IPv4 address to your clients ([like what you see here](http://whatismyip.host/)).
## Development Setup
@ -160,10 +156,10 @@ Note - _nebula has no idea how Hamachi works and has never used it, so don't ask
- Open the file `QSB/QSB.csproj.user` in your favorite text editor
- Edit the entry `<GameDir>` to point to the directory where Outer Wilds is installed
- Edit the entry `<OwmlDir>` to point to your OWML directory (it is installed inside the Mod Manager directory)
- Do the same for QuantumUNET/QuantumUNET.csproj.user
- Do the same for `QuantumUNET/QuantumUNET.csproj.user` and `QSBTests/QSBTests.csproj.user`
- Open the project solution file `QSB.sln` in Visual Studio
- If needed, right click `References` in the Solution Explorer > Manage NuGet Packages > Update OWML to fix missing references
- Run this to stop tracking QSB.csproj.user: ```git update-index --skip-worktree QSB/QSB.csproj.user```
- Run this to stop tracking QSB.csproj.user: ```git update-index --skip-worktree QSB/QSB.csproj.user``` (and do the same for the other .user files)
To fix the references, right click "References" in the Solution Explorer > "Add Reference", and add all the missing DLLs (references with yellow warning icon). You can find these DLLs in the game's directory (`OuterWilds\OuterWilds_Data\Managed`);

Binary file not shown.