mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-12-11 20:15:10 +01:00
make UseKcpTransport a config option
This commit is contained in:
parent
dfc664be25
commit
033615bfdc
@ -121,7 +121,7 @@ internal class MenuManager : MonoBehaviour, IAddComponentOnStart
|
||||
|
||||
HostButton.transform.GetChild(0).GetChild(1).GetComponent<Text>().text = QSBLocalization.Current.MainMenuHost;
|
||||
ConnectButton.transform.GetChild(0).GetChild(1).GetComponent<Text>().text = QSBLocalization.Current.MainMenuConnect;
|
||||
var text = QSBCore.DebugSettings.UseKcpTransport ? QSBLocalization.Current.PublicIPAddress : QSBLocalization.Current.ProductUserID;
|
||||
var text = QSBCore.UseKcpTransport ? QSBLocalization.Current.PublicIPAddress : QSBLocalization.Current.ProductUserID;
|
||||
ConnectPopup.SetUpPopup(text, InputLibrary.menuConfirm, InputLibrary.cancel, new ScreenPrompt(QSBLocalization.Current.Connect), new ScreenPrompt(QSBLocalization.Current.Cancel), false);
|
||||
ConnectPopup.SetInputFieldPlaceholderText(text);
|
||||
ExistingNewCopyPopup.SetUpPopup(QSBLocalization.Current.HostExistingOrNewOrCopy,
|
||||
@ -337,7 +337,7 @@ internal class MenuManager : MonoBehaviour, IAddComponentOnStart
|
||||
|
||||
private void CreateCommonPopups()
|
||||
{
|
||||
var text = QSBCore.DebugSettings.UseKcpTransport ? QSBLocalization.Current.PublicIPAddress : QSBLocalization.Current.ProductUserID;
|
||||
var text = QSBCore.UseKcpTransport ? QSBLocalization.Current.PublicIPAddress : QSBLocalization.Current.ProductUserID;
|
||||
ConnectPopup = QSBCore.MenuApi.MakeInputFieldPopup(text, text, QSBLocalization.Current.Connect, QSBLocalization.Current.Cancel);
|
||||
ConnectPopup.CloseMenuOnOk(false);
|
||||
ConnectPopup.OnPopupConfirm += () =>
|
||||
@ -628,7 +628,7 @@ internal class MenuManager : MonoBehaviour, IAddComponentOnStart
|
||||
SetButtonActive(NewGameButton, false);
|
||||
_loadingText = HostButton.transform.GetChild(0).GetChild(1).GetComponent<Text>();
|
||||
|
||||
if (!QSBCore.DebugSettings.UseKcpTransport)
|
||||
if (!QSBCore.UseKcpTransport)
|
||||
{
|
||||
var productUserId = EOSSDKComponent.LocalUserProductIdString;
|
||||
|
||||
|
||||
@ -58,10 +58,11 @@ public class QSBCore : ModBehaviour
|
||||
// ignore the last patch numbers like the title screen does
|
||||
Application.version.Split('.').Take(3).Join(delimiter: ".");
|
||||
public static bool DLCInstalled => EntitlementsManager.IsDlcOwned() == EntitlementsManager.AsyncOwnershipStatus.Owned;
|
||||
public static bool UseKcpTransport { get; private set; }
|
||||
public static bool IncompatibleModsAllowed { get; private set; }
|
||||
public static bool ShowPlayerNames { get; private set; }
|
||||
public static bool ShipDamage { get; private set; }
|
||||
public static bool ShowExtraHUDElements { get ; private set; }
|
||||
public static bool ShowExtraHUDElements { get; private set; }
|
||||
public static GameVendor GameVendor { get; private set; } = GameVendor.None;
|
||||
public static bool IsStandalone => GameVendor is GameVendor.Epic or GameVendor.Steam;
|
||||
public static IProfileManager ProfileManager => IsStandalone
|
||||
@ -155,7 +156,9 @@ public class QSBCore : ModBehaviour
|
||||
|
||||
if (DebugSettings.AutoStart)
|
||||
{
|
||||
DebugSettings.UseKcpTransport = true;
|
||||
UseKcpTransport = true;
|
||||
Helper.Config.SetSettingsValue("UseKcpTransport", UseKcpTransport);
|
||||
Helper.Storage.Save(Helper.Config, Constants.ModConfigFileName);
|
||||
DebugSettings.DebugMode = true;
|
||||
}
|
||||
|
||||
@ -254,6 +257,9 @@ public class QSBCore : ModBehaviour
|
||||
|
||||
public override void Configure(IModConfig config)
|
||||
{
|
||||
UseKcpTransport = config.GetSettingsValue<bool>("useKcpTransport") || DebugSettings.AutoStart;
|
||||
QSBNetworkManager.UpdateTransport();
|
||||
|
||||
DefaultServerIP = config.GetSettingsValue<string>("defaultServerIP");
|
||||
IncompatibleModsAllowed = config.GetSettingsValue<bool>("incompatibleModsAllowed");
|
||||
ShowPlayerNames = config.GetSettingsValue<bool>("showPlayerNames");
|
||||
|
||||
@ -71,17 +71,17 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
|
||||
"Failed to resolve host: .*"
|
||||
};
|
||||
|
||||
private static kcp2k.KcpTransport _kcpTransport;
|
||||
private static EosTransport _eosTransport;
|
||||
|
||||
public override void Awake()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
|
||||
if (QSBCore.DebugSettings.UseKcpTransport)
|
||||
{
|
||||
var kcpTransport = gameObject.AddComponent<kcp2k.KcpTransport>();
|
||||
kcpTransport.Timeout = int.MaxValue; // effectively disables kcp ping and timeout (good for testing)
|
||||
transport = kcpTransport;
|
||||
_kcpTransport = gameObject.AddComponent<kcp2k.KcpTransport>();
|
||||
_kcpTransport.Timeout = int.MaxValue; // effectively disables kcp ping and timeout (good for testing)
|
||||
}
|
||||
else
|
||||
{
|
||||
// https://dev.epicgames.com/portal/en-US/qsb/sdk/credentials/qsb
|
||||
var eosApiKey = ScriptableObject.CreateInstance<EosApiKey>();
|
||||
@ -97,10 +97,10 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
|
||||
eosSdkComponent.apiKeys = eosApiKey;
|
||||
eosSdkComponent.epicLoggerLevel = LogLevel.VeryVerbose;
|
||||
|
||||
var eosTransport = gameObject.AddComponent<EosTransport>();
|
||||
eosTransport.SetTransportError = error => _lastTransportError = error;
|
||||
transport = eosTransport;
|
||||
_eosTransport = gameObject.AddComponent<EosTransport>();
|
||||
_eosTransport.SetTransportError = error => _lastTransportError = error;
|
||||
}
|
||||
UpdateTransport();
|
||||
|
||||
gameObject.SetActive(true);
|
||||
|
||||
@ -163,6 +163,14 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
|
||||
ConfigureNetworkManager();
|
||||
}
|
||||
|
||||
public static void UpdateTransport()
|
||||
{
|
||||
if (!QSBCore.IsInMultiplayer)
|
||||
{
|
||||
singleton.transport = QSBCore.UseKcpTransport ? _kcpTransport : _eosTransport;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitPlayerName() =>
|
||||
Delay.RunWhen(PlayerData.IsLoaded, () =>
|
||||
{
|
||||
@ -192,7 +200,6 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
|
||||
PlayerName = "Player";
|
||||
}
|
||||
|
||||
if (!QSBCore.DebugSettings.UseKcpTransport)
|
||||
{
|
||||
EOSSDKComponent.DisplayName = PlayerName;
|
||||
}
|
||||
@ -225,7 +232,6 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
|
||||
{
|
||||
networkAddress = QSBCore.DefaultServerIP;
|
||||
|
||||
if (QSBCore.DebugSettings.UseKcpTransport)
|
||||
{
|
||||
kcp2k.Log.Info = s =>
|
||||
{
|
||||
|
||||
@ -5,9 +5,6 @@ namespace QSB.Utility;
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class DebugSettings
|
||||
{
|
||||
[JsonProperty("useKcpTransport")]
|
||||
public bool UseKcpTransport;
|
||||
|
||||
[JsonProperty("dumpWorldObjects")]
|
||||
public bool DumpWorldObjects;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user