Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/Client/AsyncTime/AsyncTimeComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ public void ExecuteCmd(ScheduledCommand cmd)

executingCmdMap = map;
TickPatch.currentExecutingCmdIssuedBySelf = cmd.issuedBySelf && !TickPatch.Simulating;
TickPatch.currentExecutingCmdType = cmdType;

PreContext();
map.PushFaction(cmd.GetFaction());
Expand Down Expand Up @@ -326,6 +327,7 @@ public void ExecuteCmd(ScheduledCommand cmd)
PostContext();

TickPatch.currentExecutingCmdIssuedBySelf = false;
TickPatch.currentExecutingCmdType = null;
executingCmdMap = null;

if (!keepTheMap)
Expand Down
5 changes: 2 additions & 3 deletions Source/Client/AsyncTime/AsyncWorldTimeComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace Multiplayer.Client.AsyncTime;
public class AsyncWorldTimeComp : IExposable, ITickable
{
public static bool tickingWorld;
public static bool executingCmdWorld;
private TimeSpeed timeSpeedInt;

public float TimeToTickThrough { get; set; }
Expand Down Expand Up @@ -172,8 +171,8 @@ public void ExecuteCmd(ScheduledCommand cmd)
LoggingByteReader data = new LoggingByteReader(cmd.data);
data.Log.Node($"{cmdType} Global");

executingCmdWorld = true;
TickPatch.currentExecutingCmdIssuedBySelf = cmd.issuedBySelf && !TickPatch.Simulating;
TickPatch.currentExecutingCmdType = cmdType;

PreContext();
FactionExtensions.PushFaction(null, cmd.GetFaction());
Expand Down Expand Up @@ -252,7 +251,7 @@ public void ExecuteCmd(ScheduledCommand cmd)
FactionExtensions.PopFaction();
PostContext();
TickPatch.currentExecutingCmdIssuedBySelf = false;
executingCmdWorld = false;
TickPatch.currentExecutingCmdType = null;

Multiplayer.game.sync.TryAddCommandRandomState(randState);

Expand Down
60 changes: 54 additions & 6 deletions Source/Client/Debug/DebugSync.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using System;
using System.Collections.Generic;
using HarmonyLib;
using LudeonTK;
using Multiplayer.Client.Util;
using Multiplayer.Common;

using RimWorld;
using RimWorld.Planet;
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using Verse;
using static HarmonyLib.AccessTools;

namespace Multiplayer.Client
{
Expand Down Expand Up @@ -92,6 +91,13 @@ public static void HandleCmd(ByteReader data)
{
(state.currentData as List<FloatMenuOption>)?.FirstOrDefault(o => o.Hash() == currentHash)?.action();
}
else if (source == DebugSource.Targeter)
{
var targetCell = new IntVec3(cursorX, 0, cursorZ);
var handleTargetSelected = (state.currentData as Action<LocalTargetInfo>);

handleTargetSelected?.Invoke(new LocalTargetInfo(targetCell));
}
}
finally
{
Expand All @@ -117,13 +123,18 @@ public static void HandleCmd(ByteReader data)
}
}

public static void SendCmd(DebugSource source, int hash, string path, Map map)
public static void SendCmd(DebugSource source, int hash, string path, Map map, IntVec3? forcedCell = null)
{
var writer = new LoggingByteWriter();
writer.Log.Node($"Debug tool {source}, map {map.ToStringSafe()}");
int cursorX = 0, cursorZ = 0;

if (map != null)
if (forcedCell.HasValue)
{
cursorX = forcedCell.Value.x;
cursorZ = forcedCell.Value.z;
}
else if (map != null)
{
cursorX = UI.MouseCell().x;
cursorZ = UI.MouseCell().z;
Expand Down Expand Up @@ -216,6 +227,43 @@ public enum DebugSource
Lister,
Tool,
FloatMenu,
Targeter
}

[HarmonyPatch]
static class DebugExecuteDropPodRaidAtLocation
{
static MethodBase TargetMethod()
{
return AccessTools.Method(
typeof(Targeter),
nameof(Targeter.BeginTargeting),
[
typeof(TargetingParameters), typeof(Action<LocalTargetInfo>),
typeof(Pawn), typeof(Action), typeof(Texture2D), typeof(bool)
]);
}

[HarmonyPrefix, HarmonyPriority(Priority.First)]
static bool Prefix(ref Action<LocalTargetInfo> action)
{
if (Multiplayer.Client == null) return true;
if (!Multiplayer.GameComp.debugMode) return true;
if (!Multiplayer.ExecutingCmdDebugTool) return true;
if (!DebugSync.ShouldHandle()) return true;

DebugSync.CurrentPlayerState.currentData = action;

if (Multiplayer.ExecutingCmds && !TickPatch.currentExecutingCmdIssuedBySelf)
return false;

action = targetInfo =>
{
DebugSync.SendCmd(DebugSource.Targeter, 0, null, null, targetInfo.Cell);
};

return true;
}
}

[HarmonyPatch(typeof(DebugActionNode), nameof(DebugActionNode.Enter))]
Expand Down
3 changes: 2 additions & 1 deletion Source/Client/Multiplayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public static class Multiplayer

public static Faction RealPlayerFaction => Client != null ? game.RealPlayerFaction : Faction.OfPlayer;

public static bool ExecutingCmds => AsyncWorldTimeComp.executingCmdWorld || AsyncTimeComp.executingCmdMap != null;
public static bool ExecutingCmds => TickPatch.currentExecutingCmdType != null;
public static bool ExecutingCmdDebugTool => TickPatch.currentExecutingCmdType == CommandType.DebugTools;
public static bool Ticking => AsyncWorldTimeComp.tickingWorld || AsyncTimeComp.tickingMap != null || ConstantTicker.ticking;
public static Map MapContext => AsyncTimeComp.tickingMap ?? AsyncTimeComp.executingCmdMap;

Expand Down
1 change: 1 addition & 0 deletions Source/Client/Patches/TickPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static class TickPatch
public static int tickUntil; // Ticks < tickUntil can be simulated
public static int workTicks;
public static bool currentExecutingCmdIssuedBySelf;
public static CommandType? currentExecutingCmdType;
public static bool serverFrozen;
public static int frozenAt;

Expand Down
Loading