-
-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86d8a35
commit 6097ec8
Showing
3 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters