static void Postfix(Dialog_DebugOptionLister __instance, string label, Action toolAction, Container <DebugTool>?__state) { // New tool chosen if (__state != null && DebugTools.curTool != __state?.Inner) { var originalAction = (toolAction.Target as DebugListerContext)?.originalAction ?? toolAction; int hash = Gen.HashCombineInt(GenText.StableStringHash(originalAction.Method.MethodDesc()), GenText.StableStringHash(label)); if (__instance is Dialog_DebugActionsMenu) { var source = MpDebugTools.ListingSource(); if (source == DebugSource.None) { return; } Map map = source == DebugSource.ListingMap ? Find.CurrentMap : null; MpDebugTools.SendCmd(source, hash, map); DebugTools.curTool = null; } if (__instance is Dialog_DebugOptionListLister lister) { var context = (DebugListerContext)toolAction.Target; MpDebugTools.SendCmd(DebugSource.Lister, hash, context.map); DebugTools.curTool = null; } } }
static void Postfix(Dialog_DebugOptionLister __instance, string label, Action toolAction, Container <DebugTool>?__state) { // New tool chosen if (!__state.HasValue || DebugTools.curTool == __state?.Inner) { return; } int hash = Gen.HashCombineInt(GenText.StableStringHash(toolAction.Method.MethodDesc()), GenText.StableStringHash(label)); if (__instance is Dialog_DebugActionsMenu) { var source = MpDebugTools.ListingSource(); if (source == DebugSource.None) { return; } Map map = source == DebugSource.ListingMap ? Find.CurrentMap : null; MpDebugTools.SendCmd(source, hash, map); DebugTools.curTool = null; } else if (__instance is Dialog_DebugOptionListLister lister) { Map map = MpDebugTools.CurrentPlayerState.Map; if (ListingMapMarker.drawing) { map = Find.CurrentMap; } MpDebugTools.SendCmd(DebugSource.Lister, hash, map); DebugTools.curTool = null; } }
private void OnDesynced(SyncInfo one, SyncInfo two, string error) { if (TickPatch.Skipping) { return; } Multiplayer.Client.Send(Packets.Client_Desynced); var local = one.local ? one : two; var remote = !one.local ? one : two; if (local.traces.Any()) { PrintTrace(local, remote); } try { var desyncFile = PrepareNextDesyncFile(); var replay = Replay.ForSaving(Replay.ReplayFile(desyncFile, Multiplayer.DesyncsDir)); replay.WriteCurrentData(); var savedGame = ScribeUtil.WriteExposable(Verse.Current.Game, "game", true, ScribeMetaHeaderUtility.WriteMetaHeader); using (var zip = replay.ZipFile) { zip.AddEntry("sync_local", local.Serialize()); zip.AddEntry("sync_remote", remote.Serialize()); zip.AddEntry("game_snapshot", savedGame); zip.AddEntry("static_fields", MpDebugTools.StaticFieldsToString()); var desyncInfo = new ByteWriter(); desyncInfo.WriteBool(Multiplayer.session.ArbiterPlaying); desyncInfo.WriteInt32(lastValidTick); desyncInfo.WriteBool(lastValidArbiter); desyncInfo.WriteString(MpVersion.Version); desyncInfo.WriteBool(MpVersion.IsDebug); desyncInfo.WriteBool(Prefs.DevMode); desyncInfo.WriteInt32(Multiplayer.session.players.Count); desyncInfo.WriteBool(Multiplayer.WorldComp.debugMode); zip.AddEntry("desync_info", desyncInfo.ToArray()); zip.Save(); } } catch (Exception e) { Log.Error($"Exception writing desync info: {e}"); } Find.WindowStack.windows.Clear(); Find.WindowStack.Add(new DesyncedWindow(error)); }
static bool Prefix(Dialog_DebugOptionLister __instance, string label, ref Action action) { if (Multiplayer.Client == null) { return(true); } if (Current.ProgramState == ProgramState.Playing && !Multiplayer.WorldComp.debugMode) { return(true); } var originalAction = (action.Target as DebugListerContext)?.originalAction ?? action; int hash = Gen.HashCombineInt( GenText.StableStringHash(originalAction.Method.MethodDesc()), GenText.StableStringHash(label) ); if (Multiplayer.ExecutingCmds) { if (hash == MpDebugTools.currentHash) { action(); } return(false); } if (__instance is Dialog_DebugActionsMenu) { var source = MpDebugTools.ListingSource(); if (source == DebugSource.None) { return(true); } Map map = source == DebugSource.ListingMap ? Find.CurrentMap : null; if (ListingIncidentMarker.target != null) { map = ListingIncidentMarker.target as Map; } action = () => MpDebugTools.SendCmd(source, hash, map); } if (__instance is Dialog_DebugOptionListLister) { var context = (DebugListerContext)action.Target; action = () => MpDebugTools.SendCmd(DebugSource.Lister, hash, context.map); } return(true); }
static bool Prefix(Window window) { if (Multiplayer.Client == null) { return(true); } if (!Multiplayer.ExecutingCmds) { return(true); } if (!Multiplayer.GameComp.debugMode) { return(true); } bool keepOpen = TickPatch.currentExecutingCmdIssuedBySelf; var map = Multiplayer.MapContext; if (window is Dialog_DebugOptionListLister lister) { MpDebugTools.CurrentPlayerState.window = lister.options; MpDebugTools.CurrentPlayerState.mapId = map?.uniqueID ?? -1; return(keepOpen); } if (window is FloatMenu menu) { var options = menu.options; if (keepOpen) { menu.options = new List <FloatMenuOption>(); foreach (var option in options) { var copy = new FloatMenuOption(option.labelInt, option.action); int hash = copy.Hash(); copy.action = () => MpDebugTools.SendCmd(DebugSource.FloatMenu, hash, map); menu.options.Add(copy); } } MpDebugTools.CurrentPlayerState.window = options; return(keepOpen); } return(true); }
static bool Prefix(Window window) { if (Multiplayer.Client == null) { return(true); } if (!Multiplayer.ExecutingCmds) { return(true); } if (!Multiplayer.WorldComp.debugMode) { return(true); } bool keepOpen = TickPatch.currentExecutingCmdIssuedBySelf; var map = Multiplayer.MapContext; if (window is Dialog_DebugOptionListLister lister) { var options = lister.options; if (keepOpen) { lister.options = new List <DebugMenuOption>(); foreach (var option in options) { var copy = option; copy.method = new DebugListerContext() { map = map, originalAction = copy.method }.Do; lister.options.Add(copy); } } Multiplayer.game.playerDebugState.GetOrAddNew(MpDebugTools.currentPlayer).window = options; return(keepOpen); } if (window is FloatMenu menu) { var options = menu.options; if (keepOpen) { menu.options = new List <FloatMenuOption>(); foreach (var option in options) { var copy = new FloatMenuOption(option.labelInt, option.action); int hash = copy.Hash(); copy.action = () => MpDebugTools.SendCmd(DebugSource.FloatMenu, hash, map); menu.options.Add(copy); } } Multiplayer.game.playerDebugState.GetOrAddNew(MpDebugTools.currentPlayer).window = options; return(keepOpen); } return(true); }