Skip to content

Commit

Permalink
- Debug tools now work again
Browse files Browse the repository at this point in the history
- Paint designations synced
- Fix errors when multiple players reinstall a building
- Fix players appearing twice in the player list
- Fix mod file differences being ignored when connecting
- Host window revamp
- Option to auto-pause on certain events
- Game passwords
- Option to save the game after you get disconnected
- Separate "Multiplayer" section in key config
- Refactor window classes
  • Loading branch information
Zetrith committed Oct 31, 2022
1 parent 08b2bf0 commit 9f963d3
Show file tree
Hide file tree
Showing 48 changed files with 1,211 additions and 857 deletions.
21 changes: 19 additions & 2 deletions Defs/KeyBindings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@

<Defs>

<KeyBindingDef ParentName="GameKeyBinding">
<KeyBindingCategoryDef>
<defName>Multiplayer</defName>
<label>multiplayer</label>
<description>Controls used in multiplayer.</description>
<isGameUniversal>true</isGameUniversal>
<checkForConflicts>
<li>Development</li>
<li>Game</li>
<li>SelectionMisc</li>
<li>MainTabs</li>
</checkForConflicts>
</KeyBindingCategoryDef>

<KeyBindingDef Name="MultiplayerKeyBinding" Abstract="true">
<category>Multiplayer</category>
</KeyBindingDef>

<KeyBindingDef ParentName="MultiplayerKeyBinding">
<defName>MpToggleChat</defName>
<label>toggle chat</label>
<defaultKeyCodeA>Equals</defaultKeyCodeA>
</KeyBindingDef>

<KeyBindingDef ParentName="GameKeyBinding">
<KeyBindingDef ParentName="MultiplayerKeyBinding">
<defName>MpPingKey</defName>
<label>ping location</label>
<defaultKeyCodeA>Keypad0</defaultKeyCodeA>
Expand Down
12 changes: 6 additions & 6 deletions Source/Client/AsyncTime/AsyncTimeComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ public void ExecuteCmd(ScheduledCommand cmd)
data.Log.current.text = handler.ToString();
}

// if (cmdType == CommandType.DebugTools)
// {
// MpDebugTools.HandleCmd(data);
// }
if (cmdType == CommandType.DebugTools)
{
MpDebugTools.HandleCmd(data);
}

if (cmdType == CommandType.CreateMapFactionData)
{
Expand Down Expand Up @@ -410,7 +410,7 @@ bool SetState(Designator designator, ByteReader data)
Thing thing = SyncSerialization.ReadSync<Thing>(data);
if (thing == null) return false;

DesignatorInstallPatch.thingToInstall = thing;
DesignatorInstall_SetThingToInstall.thingToInstall = thing;
}

if (designator is Designator_Zone)
Expand All @@ -428,7 +428,7 @@ void RestoreState()
if (prevArea.HasValue)
Designator_AreaAllowed.selectedArea = prevArea.Value.Inner;

DesignatorInstallPatch.thingToInstall = null;
DesignatorInstall_SetThingToInstall.thingToInstall = null;
}

try
Expand Down
31 changes: 31 additions & 0 deletions Source/Client/AsyncTime/AsyncTimePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using Multiplayer.Client.Util;
Expand Down Expand Up @@ -602,4 +603,34 @@ static void Postfix(Map __state)
}
}
}

[HarmonyPatch(typeof(LetterStack), nameof(LetterStack.ReceiveLetter), typeof(Letter), typeof(string))]
static class ReceiveLetterPause
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> insts)
{
foreach (var inst in insts)
{
if (inst.operand == AccessTools.PropertyGetter(typeof(Prefs), nameof(Prefs.AutomaticPauseMode)))
inst.operand = AccessTools.Method(typeof(ReceiveLetterPause), nameof(AutomaticPauseMode));
else if (inst.operand == AccessTools.Method(typeof(TickManager), nameof(TickManager.Pause)))
inst.operand = AccessTools.Method(typeof(ReceiveLetterPause), nameof(PauseOnLetter));

yield return inst;
}
}

static AutomaticPauseMode AutomaticPauseMode()
{
return (AutomaticPauseMode) Multiplayer.GameComp.pauseOnLetter;
}

static void PauseOnLetter(TickManager manager)
{
if (Multiplayer.GameComp.asyncTime)
((ITickable) Multiplayer.MapContext.AsyncTime() ?? Multiplayer.WorldComp).TimeSpeed = TimeSpeed.Paused;
else
Multiplayer.WorldComp.SetTimeEverywhere(TimeSpeed.Paused);
}
}
}
2 changes: 1 addition & 1 deletion Source/Client/AsyncTime/ITickable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface ITickable

float RealTimeToTickThrough { get; set; }

TimeSpeed TimeSpeed { get; }
TimeSpeed TimeSpeed { get; set; }

Queue<ScheduledCommand> Cmds { get; }

Expand Down
2 changes: 2 additions & 0 deletions Source/Client/Comp/MultiplayerGameComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class MultiplayerGameComp : IExposable, IHasSemiPersistentData
public bool asyncTime;
public bool debugMode;
public bool logDesyncTraces;
public PauseOnLetter pauseOnLetter;
public Dictionary<int, PlayerData> playerData = new(); // player id to player data

public IdBlock globalIdBlock = new(int.MaxValue / 2, 1_000_000_000);
Expand All @@ -24,6 +25,7 @@ public void ExposeData()
Scribe_Values.Look(ref asyncTime, "asyncTime", true, true);
Scribe_Values.Look(ref debugMode, "debugMode");
Scribe_Values.Look(ref logDesyncTraces, "logDesyncTraces");
Scribe_Values.Look(ref pauseOnLetter, "pauseOnLetter");

Scribe_Custom.LookIdBlock(ref globalIdBlock, "globalIdBlock");

Expand Down
27 changes: 21 additions & 6 deletions Source/Client/Comp/MultiplayerWorldComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ public void SetFaction(Faction faction)
SyncResearch.researchSpeed = data.researchSpeed;
}

public void SetTimeEverywhere(TimeSpeed speed)
{
TimeSpeed = speed;
foreach (var map in Find.Maps)
map.AsyncTime().TimeSpeed = speed;
}

public static float lastSpeedChange;

public void ExecuteCmd(ScheduledCommand cmd)
Expand Down Expand Up @@ -260,10 +267,10 @@ public void ExecuteCmd(ScheduledCommand cmd)
data.Log.current.text = handler.ToString();
}

// if (cmdType == CommandType.DebugTools)
// {
// MpDebugTools.HandleCmd(data);
// }
if (cmdType == CommandType.DebugTools)
{
MpDebugTools.HandleCmd(data);
}

if (cmdType == CommandType.WorldTimeSpeed)
{
Expand All @@ -273,14 +280,20 @@ public void ExecuteCmd(ScheduledCommand cmd)

if (!Multiplayer.GameComp.asyncTime)
{
foreach (var map in Find.Maps)
map.AsyncTime().TimeSpeed = speed;
SetTimeEverywhere(speed);

if (!cmd.issuedBySelf)
lastSpeedChange = Time.realtimeSinceStartup;
}

#if DEBUG
MpLog.Log($"Set world speed {speed} {TickPatch.Timer} {Find.TickManager.TicksGame}");
#endif
}

if (cmdType == CommandType.PauseAll)
{
SetTimeEverywhere(TimeSpeed.Paused);
}

if (cmdType == CommandType.SetupFaction)
Expand Down Expand Up @@ -327,8 +340,10 @@ public void ExecuteCmd(ScheduledCommand cmd)
DebugSettings.godMode = prevGodMode;
Prefs.data.devMode = prevDevMode;

#if DEBUG
Log.Message($"rand calls {DeferredStackTracing.randCalls - randCalls1}");
Log.Message("rand state " + Rand.StateCompressed);
#endif

Extensions.PopFaction();
PostContext();
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Debug/DebugActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace Multiplayer.Client
{
[HotSwappable]
static class MPDebugActions
static class MpDebugActions
{
const string MultiplayerCategory = "Multiplayer";

Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Debug/DebugPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static class GrammarRandomStringPatch
static void Postfix(ref string __result)
{
if (SetupQuickTestPatch.marker)
__result = "multiplayer1";
__result = "multiplayer";
}
}

Expand Down
Loading

0 comments on commit 9f963d3

Please sign in to comment.