Skip to content

Commit

Permalink
support for steam server browser
Browse files Browse the repository at this point in the history
  • Loading branch information
radistmorse committed Jul 13, 2020
1 parent 4cedd9c commit 76acb77
Show file tree
Hide file tree
Showing 88 changed files with 18,129 additions and 43 deletions.
31 changes: 0 additions & 31 deletions GameClientNetwork_Patch.cs

This file was deleted.

2 changes: 1 addition & 1 deletion PEPatch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="GameClientNetwork_Patch.cs" />
<Compile Include="PatchInitializer.cs" />
<Compile Include="PatchUtils.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServerRegisteredLocal.cs" />
<Compile Include="TitleMenuGui_N_Patch.cs" />
<Compile Include="UILobbyMainWndCtrl_Patch.cs" />
<Compile Include="UIMLoginControl_Patch.cs" />
Expand Down
6 changes: 6 additions & 0 deletions PEPatch.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.30225.117
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PEPatch", "PEPatch.csproj", "{4F89695C-7E04-4C94-9B2B-560FC7289904}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PEServerPatch", "PEServerPatch\PEServerPatch.csproj", "{3FC4C6C1-38BC-432A-87B9-1CAA6D213CE8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{4F89695C-7E04-4C94-9B2B-560FC7289904}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F89695C-7E04-4C94-9B2B-560FC7289904}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F89695C-7E04-4C94-9B2B-560FC7289904}.Release|Any CPU.Build.0 = Release|Any CPU
{3FC4C6C1-38BC-432A-87B9-1CAA6D213CE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3FC4C6C1-38BC-432A-87B9-1CAA6D213CE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3FC4C6C1-38BC-432A-87B9-1CAA6D213CE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3FC4C6C1-38BC-432A-87B9-1CAA6D213CE8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Binary file added PEPatch.zip
Binary file not shown.
138 changes: 138 additions & 0 deletions PEServerPatch/PEServerPatch.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3FC4C6C1-38BC-432A-87B9-1CAA6D213CE8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PEServerPatch</RootNamespace>
<AssemblyName>PEServerPatch</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;UNITY_5; UNITY_BUILD; UNITY_STANDALONE_WIN</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Lib.Harmony.2.0.1\lib\net35\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\PELib\PEServerLib\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="uLink">
<HintPath>..\PELib\PEServerLib\uLink.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\PELib\PEServerLib\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="PatchInitializer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SteamManager.cs" />
<Compile Include="Steamworks.NET\autogen\isteamapplist.cs" />
<Compile Include="Steamworks.NET\autogen\isteamapps.cs" />
<Compile Include="Steamworks.NET\autogen\isteamclient.cs" />
<Compile Include="Steamworks.NET\autogen\isteamcontroller.cs" />
<Compile Include="Steamworks.NET\autogen\isteamfriends.cs" />
<Compile Include="Steamworks.NET\autogen\isteamgameserver.cs" />
<Compile Include="Steamworks.NET\autogen\isteamgameserverhttp.cs" />
<Compile Include="Steamworks.NET\autogen\isteamgameserverinventory.cs" />
<Compile Include="Steamworks.NET\autogen\isteamgameservernetworking.cs" />
<Compile Include="Steamworks.NET\autogen\isteamgameserverstats.cs" />
<Compile Include="Steamworks.NET\autogen\isteamgameserverugc.cs" />
<Compile Include="Steamworks.NET\autogen\isteamgameserverutils.cs" />
<Compile Include="Steamworks.NET\autogen\isteamhtmlsurface.cs" />
<Compile Include="Steamworks.NET\autogen\isteamhttp.cs" />
<Compile Include="Steamworks.NET\autogen\isteaminventory.cs" />
<Compile Include="Steamworks.NET\autogen\isteammatchmaking.cs" />
<Compile Include="Steamworks.NET\autogen\isteammusic.cs" />
<Compile Include="Steamworks.NET\autogen\isteammusicremote.cs" />
<Compile Include="Steamworks.NET\autogen\isteamnetworking.cs" />
<Compile Include="Steamworks.NET\autogen\isteamremotestorage.cs" />
<Compile Include="Steamworks.NET\autogen\isteamscreenshots.cs" />
<Compile Include="Steamworks.NET\autogen\isteamugc.cs" />
<Compile Include="Steamworks.NET\autogen\isteamunifiedmessages.cs" />
<Compile Include="Steamworks.NET\autogen\isteamuser.cs" />
<Compile Include="Steamworks.NET\autogen\isteamuserstats.cs" />
<Compile Include="Steamworks.NET\autogen\isteamutils.cs" />
<Compile Include="Steamworks.NET\autogen\isteamvideo.cs" />
<Compile Include="Steamworks.NET\autogen\NativeMethods.cs" />
<Compile Include="Steamworks.NET\autogen\SteamCallbacks.cs" />
<Compile Include="Steamworks.NET\autogen\SteamConstants.cs" />
<Compile Include="Steamworks.NET\autogen\SteamEnums.cs" />
<Compile Include="Steamworks.NET\autogen\SteamStructs.cs" />
<Compile Include="Steamworks.NET\CallbackDispatcher.cs" />
<Compile Include="Steamworks.NET\CallbackIdentity.cs" />
<Compile Include="Steamworks.NET\InteropHelp.cs" />
<Compile Include="Steamworks.NET\ISteamMatchmakingResponses.cs" />
<Compile Include="Steamworks.NET\Packsize.cs" />
<Compile Include="Steamworks.NET\Steam.cs" />
<Compile Include="Steamworks.NET\types\MatchmakingTypes\gameserveritem_t.cs" />
<Compile Include="Steamworks.NET\types\MatchmakingTypes\servernetadr_t.cs" />
<Compile Include="Steamworks.NET\types\SteamClientPublic\CGameID.cs" />
<Compile Include="Steamworks.NET\types\SteamClientPublic\CSteamID.cs" />
<Compile Include="Steamworks.NET\types\SteamClientPublic\HAuthTicket.cs" />
<Compile Include="Steamworks.NET\types\SteamClient\HSteamPipe.cs" />
<Compile Include="Steamworks.NET\types\SteamClient\HSteamUser.cs" />
<Compile Include="Steamworks.NET\types\SteamClient\SteamAPIWarningMessageHook_t.cs" />
<Compile Include="Steamworks.NET\types\SteamClient\SteamAPI_CheckCallbackRegistered_t.cs" />
<Compile Include="Steamworks.NET\types\SteamClient\SteamAPI_PostAPIResultInProcess_t.cs" />
<Compile Include="Steamworks.NET\types\SteamFriends\FriendsGroupID_t.cs" />
<Compile Include="Steamworks.NET\types\SteamHTMLSurface\HHTMLBrowser.cs" />
<Compile Include="Steamworks.NET\types\SteamHTTP\HTTPCookieContainerHandle.cs" />
<Compile Include="Steamworks.NET\types\SteamHTTP\HTTPRequestHandle.cs" />
<Compile Include="Steamworks.NET\types\SteamInventory\SteamInventoryResult_t.cs" />
<Compile Include="Steamworks.NET\types\SteamInventory\SteamItemDef_t.cs" />
<Compile Include="Steamworks.NET\types\SteamInventory\SteamItemInstanceID_t.cs" />
<Compile Include="Steamworks.NET\types\SteamMatchmaking\HServerListRequest.cs" />
<Compile Include="Steamworks.NET\types\SteamMatchmaking\HServerQuery.cs" />
<Compile Include="Steamworks.NET\types\SteamNetworking\SNetListenSocket_t.cs" />
<Compile Include="Steamworks.NET\types\SteamNetworking\SNetSocket_t.cs" />
<Compile Include="Steamworks.NET\types\SteamRemoteStorage\PublishedFileId_t.cs" />
<Compile Include="Steamworks.NET\types\SteamRemoteStorage\PublishedFileUpdateHandle_t.cs" />
<Compile Include="Steamworks.NET\types\SteamRemoteStorage\UGCFileWriteStreamHandle_t.cs" />
<Compile Include="Steamworks.NET\types\SteamRemoteStorage\UGCHandle_t.cs" />
<Compile Include="Steamworks.NET\types\SteamScreenshots\ScreenshotHandle.cs" />
<Compile Include="Steamworks.NET\types\SteamTypes\AccountID_t.cs" />
<Compile Include="Steamworks.NET\types\SteamTypes\AppId_t.cs" />
<Compile Include="Steamworks.NET\types\SteamTypes\DepotId_t.cs" />
<Compile Include="Steamworks.NET\types\SteamTypes\ManifestId_t.cs" />
<Compile Include="Steamworks.NET\types\SteamTypes\SteamAPICall_t.cs" />
<Compile Include="Steamworks.NET\types\SteamUGC\UGCQueryHandle_t.cs" />
<Compile Include="Steamworks.NET\types\SteamUGC\UGCUpdateHandle_t.cs" />
<Compile Include="Steamworks.NET\types\SteamUnifiedMessages\ClientUnifiedMessageHandle.cs" />
<Compile Include="Steamworks.NET\types\SteamUserStats\SteamLeaderboardEntries_t.cs" />
<Compile Include="Steamworks.NET\types\SteamUserStats\SteamLeaderboard_t.cs" />
<Compile Include="uLinkNetwork_Patch.cs" />
<Compile Include="uLobbyNetwork_Patch.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
20 changes: 20 additions & 0 deletions PEServerPatch/PatchInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using HarmonyLib;
using System.Threading;

namespace PEServerPatch
{
public class PatchInitializer
{
public static void Main()
{
new Thread(() =>
{
Thread.Sleep(100);

var harmony = new Harmony("PEServerPatch");

harmony.PatchAll();
}).Start();
}
}
}
36 changes: 36 additions & 0 deletions PEServerPatch/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PEServerPatch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PEServerPatch")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3fc4c6c1-38bc-432a-87b9-1caa6d213ce8")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
112 changes: 112 additions & 0 deletions PEServerPatch/SteamManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using Steamworks;
using UnityEngine;

namespace PEServerPatch
{
public class SteamManager : MonoBehaviour
{
private static SteamManager instance;

public static SteamManager Instance {
get {
if (instance == null)
{
instance = new GameObject("SteamManager").AddComponent<SteamManager>();
}

return instance;
}
}

private bool initialized;

private Callback<SteamServersConnected_t> serverConnectedCallback;
private Callback<SteamServerConnectFailure_t> serverNotConnectedCallback;
private Callback<SteamServersDisconnected_t> serverDisconnectedCallback;

public void Awake()
{
DontDestroyOnLoad(gameObject);

ushort port = (ushort)(uLink.Network.listenPort + 20);

if (ServerConfig.PublicServer == false && port <= 9925)
{
port = (ushort)(port + 17095);
}

initialized = Steamworks.GameServer.Init(0u, 0, (ushort)uLink.Network.listenPort, port, EServerMode.eServerModeNoAuthentication, ServerConfig.ServerVersion.Replace("V",""));

if (!initialized)
{
Debug.Log("[Steamworks.NET] GameServer_Init() failed. Verify your installation.");

return;
}

serverConnectedCallback = Callback<SteamServersConnected_t>.CreateGameServer(ServerConnectedCallback);
serverNotConnectedCallback = Callback<SteamServerConnectFailure_t>.CreateGameServer(ServerNotConnectedCallback);
serverDisconnectedCallback = Callback<SteamServersDisconnected_t>.CreateGameServer(ServerDisconnectedCallback);
}

public void Update()
{
if (initialized)
{
Steamworks.GameServer.RunCallbacks();
}
}

public void LogOff()
{
if (initialized && SteamGameServer.BLoggedOn())
{
SteamGameServer.EnableHeartbeats(false);
SteamGameServer.LogOff();
}
}

public void LogOn()
{
SteamGameServer.SetModDir("PlanetExplorers");
SteamGameServer.SetProduct("PlanetExplorers");
SteamGameServer.SetGameDescription("Planet Explorers");
SteamGameServer.LogOnAnonymous();
}

public void SetAdditionalGameInfo()
{
var type = ServerConfig.GameType.ToString();
var mode = ServerConfig.SceneMode.ToString();
var UID = ServerConfig.ServerUID.ToString("X");
var state = (uLinkNetwork.ServerStatus & CustomData.EServerStatus.Gameing) == CustomData.EServerStatus.Gameing ? 4 : 1;
var numPlayers = uLink.Network.connections.Length;
var masterName = ServerConfig.MasterRoleName;
var pub = ServerConfig.PublicServer ? ",public" : "";
SteamGameServer.SetGameTags($"{type},{mode},{UID},{state},{numPlayers},{masterName}{pub}");
}

private void ServerConnectedCallback(SteamServersConnected_t callback)
{
Debug.Log("[Steamworks.NET] GameServer connected successfully");

SteamGameServer.SetServerName(ServerConfig.ServerName);
SteamGameServer.SetPasswordProtected(!string.IsNullOrEmpty(ServerConfig.Password));
SteamGameServer.SetMaxPlayerCount(ServerConfig.TeamNum * ServerConfig.NumPerTeam);
SteamGameServer.SetMapName(ServerConfig.MapName);
SteamGameServer.SetDedicatedServer(true);
SetAdditionalGameInfo();
SteamGameServer.EnableHeartbeats(true);
}

private void ServerNotConnectedCallback(SteamServerConnectFailure_t callback)
{
Debug.Log($"[Steamworks.NET] GameServer connection failed: {callback.m_eResult}");
}

private void ServerDisconnectedCallback(SteamServersDisconnected_t callback)
{
Debug.Log($"[Steamworks.NET] GameServer disconnected: {callback.m_eResult}");
}
}
}
Loading

0 comments on commit 76acb77

Please sign in to comment.