Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
Made Distance.NoServerLimit compliant with the repository coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
REHERC committed Aug 5, 2020
1 parent f88e05b commit 18c9fda
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 99 deletions.
3 changes: 3 additions & 0 deletions Centrifuge.Mods.Distance.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Distance.CustomDeathMessage
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Distance.NoServerLimit", "Distance.NoServerLimit\Distance.NoServerLimit.csproj", "{249F576D-6A84-46D7-BAC7-308810DDDF8B}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Distance.NoServerLimit.Content", "Distance.NoServerLimit.Content\Distance.NoServerLimit.Content.shproj", "{260FE22A-730A-4723-A744-DD06302F92CB}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Distance.TextureModifier.Content\Distance.TextureModifier.Content.projitems*{06a78a9a-7a66-431f-8023-36eaa5d0fbaf}*SharedItemsImports = 4
Distance.TextureModifier.Content\Distance.TextureModifier.Content.projitems*{07d04eb9-6ab9-46cf-a3c3-a2e1d24fbeef}*SharedItemsImports = 13
Distance.NoServerLimit.Content\Distance.NoServerLimit.Content.projitems*{260fe22a-730a-4723-a744-dd06302f92cb}*SharedItemsImports = 13
Distance.CustomDeathMessages.Content\Distance.CustomDeathMessages.Content.projitems*{57657ebc-1f29-4357-b4ef-45b2b22f5a3f}*SharedItemsImports = 13
Distance.TrackMusic.Content\Distance.TrackMusic.Content.projitems*{58bfee58-73a0-4451-9da7-0fb51f1c53ea}*SharedItemsImports = 13
Distance.SceneDumper.Content\Distance.SceneDumper.Content.projitems*{e84718c2-200c-415f-ad1d-0cc133c38e70}*SharedItemsImports = 13
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>260fe22a-730a-4723-a744-dd06302f92cb</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Distance.NoServerLimit.Content</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)Mod\mod.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>260fe22a-730a-4723-a744-dd06302f92cb</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Distance.NoServerLimit.Content.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"FriendlyName": "No Server Limit",
"Author": "Ciastex",
"Contact": "Discord: Ciastex#6170",
"ModuleFileName": "NoServerLimit.dll",
"ModuleFileName": "Distance.NoServerLimit.dll",
"Priority": 10,
"SkipLoad": false,
"Dependencies": [],
Expand Down
52 changes: 52 additions & 0 deletions Distance.NoServerLimit/ConfigurationLogic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Reactor.API.Configuration;
using System;
using UnityEngine;

namespace Distance.NoServerLimit
{
public class ConfigurationLogic : MonoBehaviour
{
#region Properties
public int MaxPlayerCount
{
get => Get<int>("MaxPlayerCount");
set => Set("MaxPlayerCount", value);
}
#endregion

internal Settings Config;

public event Action<ConfigurationLogic> OnChanged;

private void Load()
{
Config = new Settings("Server");
}

public void Awake()
{
Load();

Get("MaxPlayerCount", 32);

Save();
}

public T Get<T>(string key, T @default = default)
{
return Config.GetOrCreate(key, @default);
}

public void Set<T>(string key, T value)
{
Config[key] = value;
Save();
}

public void Save()
{
Config?.Save();
OnChanged?.Invoke(this);
}
}
}
60 changes: 55 additions & 5 deletions Distance.NoServerLimit/Distance.NoServerLimit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,65 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Mod.cs" />
<Compile Include="Patches.cs" />
<Compile Include="ConfigurationLogic.cs" />
<Compile Include="Entry.cs" />
<Compile Include="Harmony\Assembly-CSharp\HostAGame\IncrementMaxPlayers.cs" />
<Compile Include="Harmony\Assembly-CSharp\NetworkingManager\CreateServer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="mod.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>SET MODNAME=Distance No Server Limit
SET INCLUDE=$(SolutionDir)Distance.NoServerLimit.Content

SET BUILD=$(ProjectDir)$(OutDir)
SET PACKAGES=$(SolutionDir)Build\%25MODNAME%25\Centrifuge

SET MOD=%25PACKAGES%25\Mods\%25MODNAME%25

REM ===== COPY MOD FILES =====

CALL :MAKEDIR "%25MOD%25"

CALL :COPYDIR "%25INCLUDE%25\Mod" "%25MOD%25"
CALL :COPY "%25BUILD%25Distance.NoServerLimit.dll" "%25MOD%25"

CALL :INCLUDEGSL Centrifuge.Distance

EXIT 0

REM ===== BUILD SUBROUTINES =====

:MAKEDIR
IF NOT EXIST %251 MKDIR %251
GOTO :EOF

:COPY
ECHO NUL &gt; %252
XCOPY /s /Y /v %251 %252
GOTO :EOF

:COPYDIR
XCOPY /i /s /Y /v %251 %252
GOTO :EOF

:INCLUDEGSL
CALL :MAKEDIR "%25PACKAGES%25\GameSupport"
CALL :COPY "%25BUILD%25%251.dll" "%25PACKAGES%25\GameSupport"
GOTO :EOF

:INCLUDEDEPENDENCY
CALL :MAKEDIR "%25MOD%25\Dependencies"
CALL :COPY "%25BUILD%25%251.dll" "%25MOD%25\Dependencies"
GOTO :EOF

:INCLUDEDEPENDENCYRENAME
CALL :MAKEDIR "%25MOD%25\Dependencies"
CALL :COPY "%25BUILD%25%251.dll" "%25MOD%25\Dependencies\%252.dll"
GOTO :EOF</PostBuildEvent>
</PropertyGroup>
</Project>
52 changes: 24 additions & 28 deletions Distance.NoServerLimit/Mod.cs → Distance.NoServerLimit/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,56 @@
using Centrifuge.Distance.GUI.Controls;
using Centrifuge.Distance.GUI.Data;
using Reactor.API.Attributes;
using Reactor.API.Configuration;
using Reactor.API.Interfaces.Systems;
using Reactor.API.Logging;
using Reactor.API.Runtime.Patching;
using System;
using UnityEngine;

namespace ExampleNamespace
namespace Distance.NoServerLimit
{
[ModEntryPoint(ModID)]
public class Mod
[ModEntryPoint("eu.vddcore/NoServerLimit")]
public class Mod : MonoBehaviour
{
public const string ModID = "eu.vddcore/NoServerLimit";
public static Mod Instance;

internal static Log Log = LogManager.GetForCurrentAssembly();
internal static Settings Settings { get; private set; }
public IManager Manager { get; set; }

public Log Logger { get; set; }

public ConfigurationLogic Config { get; private set; }

public void Initialize(IManager manager)
{
Settings = new Settings("server");
ValidateSettings();
CreateSettingsMenu();
Instance = this;
Manager = manager;

RuntimePatcher.AutoPatch();
Logger = LogManager.GetForCurrentAssembly();
Config = gameObject.AddComponent<ConfigurationLogic>();

Log.Info("No Server Limit: Hello, world!");
}
CreateSettingsMenu();

private void ValidateSettings()
{
if (!Settings.ContainsKey("MaxPlayerCount"))
{
Settings["MaxPlayerCount"] = 32;
}
RuntimePatcher.AutoPatch();

Settings.Save();
Logger.Info("No Server Limit: Hello, world!");
}

private void CreateSettingsMenu()
{
MenuTree settingsMenu = new MenuTree("menu.mod.noserverlimit", "No Server Limit Settings")
{
new InputPrompt(MenuDisplayMode.MainMenu, "setting:set_server_limit", "SET MAXIMUM SERVER SLOT COUNT")
.WithDefaultValue(() => Settings.GetItem<int>("MaxPlayerCount").ToString())
.WithDefaultValue(() => Config.MaxPlayerCount.ToString())
.WithSubmitAction((x) => {
try
if (int.TryParse(x, out int result))
{
Settings["MaxPlayerCount"] = int.Parse(x);
Config.MaxPlayerCount = result;
}
catch
else
{
Log.Warning("Failed to parse user input. Setting defaults.");
Settings["MaxPlayerCount"] = 32;
Logger.Warning("Failed to parse user input. Setting defaults.");
Config.MaxPlayerCount = 32;
}
Settings.Save();
})
.WithTitle("ENTER SLOT COUNT")
.WithDescription("Set the maximum supported server slot count.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Harmony;

namespace Distance.NoServerLimit.Harmony
{
[HarmonyPatch(typeof(HostAGame), "IncrementMaxPlayers")]
internal class HostAGame__IncrementMaxPlayers
{
internal static bool Prefix(HostAGame __instance, int direction)
{
__instance.internalMaxPlayerCalc_ = GUtils.mod(__instance.internalMaxPlayerCalc_ + direction, Mod.Instance.Config.MaxPlayerCount);
__instance.maxPlayersLabel_.text = __instance.MaxPlayers_.ToString();

if (direction != 0 && AudioManager.Valid())
{
G.Sys.AudioManager_.PlaySound("ButtonSelect", "Menus", 1f);
}

return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Harmony;
using System;
using UnityEngine;

namespace Distance.NoServerLimit.Harmony
{
[HarmonyPatch(typeof(NetworkingManager), "CreateServer")]
internal class NetworkingManager__CreateServer
{
internal static bool Prefix(NetworkingManager __instance, string serverTitle, string password, int maxPlayerCount)
{
Network.InitializeSecurity();

try
{
__instance.password_ = password;
__instance.serverTitle_ = serverTitle;

G.Sys.GameData_.SetString("ServerTitleDefault", __instance.serverTitle_);

__instance.maxPlayerCount_ = Mathf.Clamp(maxPlayerCount, 1, Mod.Instance.Config.MaxPlayerCount);

G.Sys.GameData_.SetInt("MaxPlayersDefault", __instance.maxPlayerCount_);

int num = 1;
int connections = __instance.maxPlayerCount_ - num;

NetworkConnectionError networkConnectionError = Network.InitializeServer(connections, 32323, true);

if (networkConnectionError != NetworkConnectionError.NoError)
{
G.Sys.MenuPanelManager_.ShowError("Failed to create game lobby. Error code: " + networkConnectionError.ToString(), "Network Error", null, UIWidget.Pivot.Center);
}
}
catch (Exception ex)
{
Debug.LogError(ex.Message);
Mod.Instance.Logger.Exception(ex);
}

return false;
}
}
}
59 changes: 0 additions & 59 deletions Distance.NoServerLimit/Patches.cs

This file was deleted.

Loading

0 comments on commit 18c9fda

Please sign in to comment.