Skip to content

Commit

Permalink
PlayFab max characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Grantapher committed Apr 1, 2023
1 parent 86d8a35 commit 6097ec8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
6 changes: 2 additions & 4 deletions ValheimPlus/Configurations/BaseConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public void LoadIniData(KeyDataCollection data, string section)
var thisConfiguration = GetCurrentConfiguration(section);
if (thisConfiguration == null)
{
Debug.Log("Configuration not set.");
thisConfiguration = this as T;
if (thisConfiguration == null) Debug.Log("Error on setting Configuration");
}
Expand Down Expand Up @@ -96,13 +95,12 @@ public void LoadIniData(KeyDataCollection data, string section)
continue;
}

Debug.Log($"{property.Name} [{keyName}] = {currentValue} ({property.PropertyType})");

if (_getValues.ContainsKey(property.PropertyType))
{
var getValue = _getValues[property.PropertyType];
var value = getValue(data, currentValue, keyName);
Debug.Log($"{keyName} = {currentValue} => {value}");
if (!currentValue.Equals(value))
Debug.Log($" Updating {keyName} from {currentValue} to {value}");
property.SetValue(this, value, null);
}
else Debug.LogWarning($" Could not load data of type {property.PropertyType} for key {keyName}");
Expand Down
59 changes: 59 additions & 0 deletions ValheimPlus/GameClasses/ZPlayFabMatchmaking.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using ValheimPlus.Configurations;

namespace ValheimPlus.GameClasses
{
[HarmonyPatch(typeof(ZPlayFabMatchmaking), "CreateLobby")]
public static class ZPlayFabMatchmaking_CreateLobby_Transpiler
{
/// <summary>
/// Alter playfab server player limit
/// Must be between 2 and 32
/// </summary>
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
if (!Configuration.Current.Server.IsEnabled) return instructions;

try
{
var ldc = instructions.Single(inst => inst.LoadsConstant() && inst.OperandIs(10U));
ldc.operand = Helper.Clamp(Configuration.Current.Server.maxPlayers, 2, 32);
}
catch (Exception)
{
ZLog.LogError("Failed to alter lobby player limit (ZPlayFabMatchmaking_CreateLobby_Transpiler)");
}
return instructions;
}
}

[HarmonyPatch(typeof(ZPlayFabMatchmaking), "CreateAndJoinNetwork")]
public static class ZPlayFabMatchmaking_CreateAndJoinNetwork_Transpiler
{
/// <summary>
/// Alter playfab network configuration player limit
/// Must be between 2 and 32
/// </summary>
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
if (!Configuration.Current.Server.IsEnabled) return instructions;

try
{
var ldc = instructions.Single(inst => inst.LoadsConstant() && inst.OperandIs(10U));
ldc.operand = Helper.Clamp(Configuration.Current.Server.maxPlayers, 2, 32);
}
catch (Exception)
{
ZLog.LogError("Failed to alter network player limit (ZPlayFabMatchmaking_CreateAndJoinNetwork_Transpiler)");
}

return instructions;
}
}
}
3 changes: 2 additions & 1 deletion ValheimPlus/ValheimPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="netstandard" />
<Reference Include="netstandard" />
<Reference Include="0Harmony, Version=2.10.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\HarmonyX.2.10.0\lib\net45\0Harmony.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -405,6 +405,7 @@
<Compile Include="GameClasses\Fireplace.cs" />
<Compile Include="GameClasses\GameCamera.cs" />
<Compile Include="GameClasses\Chat.cs" />
<Compile Include="GameClasses\ZPlayFabMatchmaking.cs" />
<Compile Include="RPC\VPlusMapPinSync.cs" />
<Compile Include="UI\HotkeyBar.cs" />
<Compile Include="GameClasses\Hud.cs" />
Expand Down

0 comments on commit 6097ec8

Please sign in to comment.