Skip to content

Commit aa6b670

Browse files
authored
Merge pull request #637 from misternebula/dev
0.30.0
2 parents 10c9121 + b2962e1 commit aa6b670

File tree

351 files changed

+764
-369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

351 files changed

+764
-369
lines changed

APITestMod/APITestMod.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using OWML.Common;
2+
using OWML.ModHelper;
3+
using UnityEngine;
4+
using UnityEngine.SceneManagement;
5+
6+
namespace APITestMod;
7+
8+
public class APITestMod : ModBehaviour
9+
{
10+
public void Start()
11+
{
12+
var qsbAPI = ModHelper.Interaction.TryGetModApi<IQSBAPI>("Raicuparta.QuantumSpaceBuddies");
13+
var menuFrameworkAPI = ModHelper.Interaction.TryGetModApi<IMenuAPI>("_nebula.MenuFramework");
14+
15+
LoadManager.OnCompleteSceneLoad += (oldScene, newScene) =>
16+
{
17+
if (newScene != OWScene.SolarSystem)
18+
{
19+
return;
20+
}
21+
22+
var button = menuFrameworkAPI.PauseMenu_MakeSimpleButton("QSB Api Test");
23+
24+
qsbAPI.OnPlayerJoin().AddListener((uint playerId) => ModHelper.Console.WriteLine($"{playerId} joined the game!", MessageType.Success));
25+
qsbAPI.OnPlayerLeave().AddListener((uint playerId) => ModHelper.Console.WriteLine($"{playerId} left the game!", MessageType.Success));
26+
27+
button.onClick.AddListener(() =>
28+
{
29+
ModHelper.Console.WriteLine("TESTING QSB API!");
30+
31+
ModHelper.Console.WriteLine($"Local Player ID : {qsbAPI.GetLocalPlayerID()}");
32+
33+
ModHelper.Console.WriteLine("Player IDs :");
34+
35+
foreach (var playerID in qsbAPI.GetPlayerIDs())
36+
{
37+
ModHelper.Console.WriteLine($" - id:{playerID} name:{qsbAPI.GetPlayerName(playerID)}");
38+
}
39+
40+
ModHelper.Console.WriteLine("Setting custom data as \"QSB TEST STRING\"");
41+
qsbAPI.SetCustomData(qsbAPI.GetLocalPlayerID(), "APITEST.TESTSTRING", "QSB TEST STRING");
42+
ModHelper.Console.WriteLine($"Retreiving custom data : {qsbAPI.GetCustomData<string>(qsbAPI.GetLocalPlayerID(), "APITEST.TESTSTRING")}");
43+
44+
ModHelper.Console.WriteLine("Sending string message test...");
45+
qsbAPI.RegisterHandler<string>("apitest-string", MessageHandler);
46+
qsbAPI.SendMessage("apitest-string", "STRING MESSAGE", true);
47+
48+
ModHelper.Console.WriteLine("Sending int message test...");
49+
qsbAPI.RegisterHandler<int>("apitest-int", MessageHandler);
50+
qsbAPI.SendMessage("apitest-int", 123, true);
51+
52+
ModHelper.Console.WriteLine("Sending float message test...");
53+
qsbAPI.RegisterHandler<float>("apitest-float", MessageHandler);
54+
qsbAPI.SendMessage("apitest-float", 3.14f, true);
55+
});
56+
};
57+
}
58+
59+
private void MessageHandler<T>(uint from, T data)
60+
=> ModHelper.Console.WriteLine($"Got : {data}");
61+
}

APITestMod/APITestMod.csproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net48</TargetFramework>
5+
<RootNamespace>APITestMod</RootNamespace>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<OutputPath Condition="Exists('$(OwmlDir)')">$(OwmlDir)\Mods\_nebula.QSBAPITest</OutputPath>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="OuterWildsGameLibs" Version="1.1.13.457" IncludeAssets="compile" />
13+
<PackageReference Include="OWML" Version="2.9.5" IncludeAssets="compile" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<None Update="manifest.json">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
22+
</Project>

APITestMod/IMenuAPI.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using UnityEngine;
2+
using UnityEngine.UI;
3+
4+
namespace APITestMod;
5+
6+
public interface IMenuAPI
7+
{
8+
// Title screen
9+
GameObject TitleScreen_MakeMenuOpenButton(string name, int index, Menu menuToOpen);
10+
GameObject TitleScreen_MakeSceneLoadButton(string name, int index, SubmitActionLoadScene.LoadableScenes sceneToLoad, PopupMenu confirmPopup = null);
11+
Button TitleScreen_MakeSimpleButton(string name, int index);
12+
// Pause menu
13+
GameObject PauseMenu_MakeMenuOpenButton(string name, Menu menuToOpen, Menu customMenu = null);
14+
GameObject PauseMenu_MakeSceneLoadButton(string name, SubmitActionLoadScene.LoadableScenes sceneToLoad, PopupMenu confirmPopup = null, Menu customMenu = null);
15+
Button PauseMenu_MakeSimpleButton(string name, Menu customMenu = null);
16+
Menu PauseMenu_MakePauseListMenu(string title);
17+
// Misc
18+
PopupMenu MakeTwoChoicePopup(string message, string confirmText, string cancelText);
19+
PopupInputMenu MakeInputFieldPopup(string message, string placeholderMessage, string confirmText, string cancelText);
20+
PopupMenu MakeInfoPopup(string message, string continueButtonText);
21+
// Startup Popups
22+
void RegisterStartupPopup(string message);
23+
}

APITestMod/IQSBAPI.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using OWML.Common;
2+
using UnityEngine.Events;
3+
4+
public interface IQSBAPI
5+
{
6+
/// <summary>
7+
/// If called, all players connected to YOUR hosted game must have this mod installed.
8+
/// </summary>
9+
void RegisterRequiredForAllPlayers(IModBehaviour mod);
10+
11+
/// <summary>
12+
/// Returns the player ID of the current player.
13+
/// </summary>
14+
uint GetLocalPlayerID();
15+
16+
/// <summary>
17+
/// Returns the name of a given player.
18+
/// </summary>
19+
/// <param name="playerID">The ID of the player you want the name of.</param>
20+
string GetPlayerName(uint playerID);
21+
22+
/// <summary>
23+
/// Returns the list of IDs of all connected players.
24+
/// </summary>
25+
uint[] GetPlayerIDs();
26+
27+
/// <summary>
28+
/// Invoked when a player joins the game.
29+
/// </summary>
30+
UnityEvent<uint> OnPlayerJoin();
31+
32+
/// <summary>
33+
/// Invoked when a player leaves the game.
34+
/// </summary>
35+
UnityEvent<uint> OnPlayerLeave();
36+
37+
/// <summary>
38+
/// Sets some arbitrary data for a given player.
39+
/// </summary>
40+
/// <typeparam name="T">The type of the data.</typeparam>
41+
/// <param name="playerId">The ID of the player.</param>
42+
/// <param name="key">The unique key to access this data by.</param>
43+
/// <param name="data">The data to set.</param>
44+
void SetCustomData<T>(uint playerId, string key, T data);
45+
46+
/// <summary>
47+
/// Returns some arbitrary data from a given player.
48+
/// </summary>
49+
/// <typeparam name="T">The type of the data.</typeparam>
50+
/// <param name="playerId">The ID of the player.</param>
51+
/// <param name="key">The unique key of the data you want to access.</param>
52+
/// <returns>The data requested. If key is not valid, returns default.</returns>
53+
T GetCustomData<T>(uint playerId, string key);
54+
55+
/// <summary>
56+
/// Sends a message containing arbitrary data to every player.
57+
/// </summary>
58+
/// <typeparam name="T">The type of the data being sent. This type must be serializable.</typeparam>
59+
/// <param name="messageType">The unique key of the message.</param>
60+
/// <param name="data">The data to send.</param>
61+
/// <param name="receiveLocally">If true, the action given to <see cref="RegisterHandler{T}"/> will also be called on the same client that is sending the message.</param>
62+
void SendMessage<T>(string messageType, T data, bool receiveLocally = false);
63+
64+
/// <summary>
65+
/// Registers an action to be called when a message is received.
66+
/// </summary>
67+
/// <typeparam name="T">The type of the data in the message.</typeparam>
68+
/// <param name="messageType">The unique key of the message.</param>
69+
/// <param name="handler">The action to be ran when the message is received. The uint is the player ID that sent the messsage.</param>
70+
void RegisterHandler<T>(string messageType, Action<uint, T> handler);
71+
}

APITestMod/manifest.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"filename": "APITestMod.dll",
3+
"author": "_nebula",
4+
"name": "QSB API Test Mod",
5+
"uniqueName": "_nebula.QSBAPITest",
6+
"version": "1.0.0",
7+
"owmlVersion": "2.9.5",
8+
"dependencies": [ "Raicuparta.QuantumSpaceBuddies", "_nebula.MenuFramework" ]
9+
}

EpicRerouter/EpicRerouter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
</ItemGroup>
1616
<ItemGroup>
1717
<PackageReference Include="OuterWildsGameLibs" Version="1.1.13.457" IncludeAssets="compile" />
18-
<PackageReference Include="OWML" Version="2.9.3" IncludeAssets="compile" />
18+
<PackageReference Include="OWML" Version="2.9.5" IncludeAssets="compile" />
1919
</ItemGroup>
2020
</Project>

MirrorWeaver/MirrorWeaver.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</PropertyGroup>
1010
<ItemGroup>
1111
<PackageReference Include="OuterWildsGameLibs" Version="1.1.13.457" />
12-
<PackageReference Include="OWML" Version="2.9.3" />
12+
<PackageReference Include="OWML" Version="2.9.5" />
1313
<Reference Include="../Mirror/*.dll" />
1414
</ItemGroup>
1515
<ItemGroup>

QSB.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EpicOnlineTransport", "Epic
2020
EndProject
2121
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EpicRerouter", "EpicRerouter\EpicRerouter.csproj", "{639EFAEE-C4A1-4DA2-8457-D0472A9F6343}"
2222
EndProject
23+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "APITestMod", "APITestMod\APITestMod.csproj", "{0A10143E-6C00-409B-B3A5-C54C1B01599D}"
24+
EndProject
2325
Global
2426
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2527
Debug|Any CPU = Debug|Any CPU
@@ -42,6 +44,10 @@ Global
4244
{639EFAEE-C4A1-4DA2-8457-D0472A9F6343}.Debug|Any CPU.Build.0 = Debug|Any CPU
4345
{639EFAEE-C4A1-4DA2-8457-D0472A9F6343}.Release|Any CPU.ActiveCfg = Release|Any CPU
4446
{639EFAEE-C4A1-4DA2-8457-D0472A9F6343}.Release|Any CPU.Build.0 = Release|Any CPU
47+
{0A10143E-6C00-409B-B3A5-C54C1B01599D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
48+
{0A10143E-6C00-409B-B3A5-C54C1B01599D}.Debug|Any CPU.Build.0 = Debug|Any CPU
49+
{0A10143E-6C00-409B-B3A5-C54C1B01599D}.Release|Any CPU.ActiveCfg = Release|Any CPU
50+
{0A10143E-6C00-409B-B3A5-C54C1B01599D}.Release|Any CPU.Build.0 = Release|Any CPU
4551
EndGlobalSection
4652
GlobalSection(SolutionProperties) = preSolution
4753
HideSolutionNode = FALSE

QSB/API/AddonDataManager.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using QSB.Utility;
4+
5+
namespace QSB.API;
6+
7+
public static class AddonDataManager
8+
{
9+
private static readonly Dictionary<string, Action<uint, object>> _handlers = new();
10+
11+
public static void OnReceiveDataMessage(string messageType, object data, uint from)
12+
{
13+
DebugLog.DebugWrite($"Received data message of message type \"{messageType}\" from {from}!");
14+
if (!_handlers.TryGetValue(messageType, out var handler))
15+
{
16+
return;
17+
}
18+
19+
handler(from, data);
20+
}
21+
22+
public static void RegisterHandler<T>(string messageType, Action<uint, T> handler)
23+
{
24+
DebugLog.DebugWrite($"Registering handler for \"{messageType}\" with type of {typeof(T).Name}");
25+
_handlers.Add(messageType, (from, data) => handler(from, (T)data));
26+
}
27+
}

QSB/API/IQSBAPI.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using OWML.Common;
3+
using UnityEngine.Events;
4+
5+
public interface IQSBAPI
6+
{
7+
/// <summary>
8+
/// If called, all players connected to YOUR hosted game must have this mod installed.
9+
/// </summary>
10+
void RegisterRequiredForAllPlayers(IModBehaviour mod);
11+
12+
/// <summary>
13+
/// Returns the player ID of the current player.
14+
/// </summary>
15+
uint GetLocalPlayerID();
16+
17+
/// <summary>
18+
/// Returns the name of a given player.
19+
/// </summary>
20+
/// <param name="playerID">The ID of the player you want the name of.</param>
21+
string GetPlayerName(uint playerID);
22+
23+
/// <summary>
24+
/// Returns the list of IDs of all connected players.
25+
/// </summary>
26+
uint[] GetPlayerIDs();
27+
28+
/// <summary>
29+
/// Invoked when a player joins the game.
30+
/// </summary>
31+
UnityEvent<uint> OnPlayerJoin();
32+
33+
/// <summary>
34+
/// Invoked when a player leaves the game.
35+
/// </summary>
36+
UnityEvent<uint> OnPlayerLeave();
37+
38+
/// <summary>
39+
/// Sets some arbitrary data for a given player.
40+
/// </summary>
41+
/// <typeparam name="T">The type of the data.</typeparam>
42+
/// <param name="playerId">The ID of the player.</param>
43+
/// <param name="key">The unique key to access this data by.</param>
44+
/// <param name="data">The data to set.</param>
45+
void SetCustomData<T>(uint playerId, string key, T data);
46+
47+
/// <summary>
48+
/// Returns some arbitrary data from a given player.
49+
/// </summary>
50+
/// <typeparam name="T">The type of the data.</typeparam>
51+
/// <param name="playerId">The ID of the player.</param>
52+
/// <param name="key">The unique key of the data you want to access.</param>
53+
/// <returns>The data requested. If key is not valid, returns default.</returns>
54+
T GetCustomData<T>(uint playerId, string key);
55+
56+
/// <summary>
57+
/// Sends a message containing arbitrary data to every player.
58+
/// </summary>
59+
/// <typeparam name="T">The type of the data being sent. This type must be serializable.</typeparam>
60+
/// <param name="messageType">The unique key of the message.</param>
61+
/// <param name="data">The data to send.</param>
62+
/// <param name="receiveLocally">If true, the action given to <see cref="RegisterHandler{T}"/> will also be called on the same client that is sending the message.</param>
63+
void SendMessage<T>(string messageType, T data, bool receiveLocally = false);
64+
65+
/// <summary>
66+
/// Registers an action to be called when a message is received.
67+
/// </summary>
68+
/// <typeparam name="T">The type of the data in the message.</typeparam>
69+
/// <param name="messageType">The unique key of the message.</param>
70+
/// <param name="handler">The action to be ran when the message is received. The uint is the player ID that sent the messsage.</param>
71+
void RegisterHandler<T>(string messageType, Action<uint, T> handler);
72+
}

0 commit comments

Comments
 (0)