Skip to content
This repository has been archived by the owner on Jul 18, 2020. It is now read-only.

Commit

Permalink
Version 0.4.2, bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zetrith committed Jan 17, 2019
1 parent e545e89 commit 994f60b
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 12 deletions.
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Manifest>

<identifier>Multiplayer</identifier>
<version>0.4.1</version>
<version>0.4.2</version>
<manifestUri>https://raw.githubusercontent.com/Zetrith/Multiplayer/master/About/Manifest.xml</manifestUri>
<downloadUri>https://github.com/Zetrith/Multiplayer/releases/latest</downloadUri>

Expand Down
3 changes: 2 additions & 1 deletion Source/Client/ArbiterPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Multiplayer.Client
{
[HarmonyPatch(typeof(GUI), nameof(GUI.skin), MethodType.Getter)]
[MpPatch(typeof(GUI), "get_" + nameof(GUI.skin))]
static class GUISkinArbiter_Patch
{
static bool Prefix(ref GUISkin __result)
Expand Down Expand Up @@ -53,6 +53,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
[MpPatch(typeof(Section), nameof(Section.RegenerateLayers))]
[MpPatch(typeof(SectionLayer), nameof(SectionLayer.DrawLayer))]
[MpPatch(typeof(Map), nameof(Map.MapUpdate))]
[MpPatch(typeof(GUIStyle), nameof(GUIStyle.CalcSize))]
static class CancelForArbiter
{
static bool Prefix() => !Multiplayer.arbiterInstance;
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/ClientNetworking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public SteamServerConn(CSteamID remoteId) : base(remoteId)

protected override void OnDisconnect()
{
serverPlayer.Server.OnDisconnected(this);
serverPlayer.Server.OnDisconnected(this, MpDisconnectReason.ClientLeft);
}
}

Expand Down
23 changes: 20 additions & 3 deletions Source/Client/Multiplayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ static Multiplayer()
Sync.InitHandlers();

HandleCommandLine();

RuntimeHelpers.RunClassConstructor(typeof(Text).TypeHandle);
}

private static void SetUsername()
Expand All @@ -174,6 +176,11 @@ private static void SetUsername()
Multiplayer.username = "Player" + Rand.Range(0, 9999);
}

private static void DoubleLongEvent(Action action, string textKey)
{
LongEventHandler.QueueLongEvent(() => LongEventHandler.QueueLongEvent(action, textKey, false, null), textKey, false, null);
}

private static void HandleCommandLine()
{
if (GenCommandLine.TryGetCommandLineArg("connect", out string ip))
Expand All @@ -190,7 +197,7 @@ private static void HandleCommandLine()
int.TryParse(split[1], out port);

if (IPAddress.TryParse(ip, out IPAddress addr))
LongEventHandler.QueueLongEvent(() => ClientUtil.TryConnect(addr, port), "Connecting", false, null);
DoubleLongEvent(() => ClientUtil.TryConnect(addr, port), "Connecting");
}

if (GenCommandLine.CommandLineArgPassed("arbiter"))
Expand All @@ -202,7 +209,7 @@ private static void HandleCommandLine()

if (GenCommandLine.TryGetCommandLineArg("replay", out string replay))
{
LongEventHandler.QueueLongEvent(() =>
DoubleLongEvent(() =>
{
Replay.LoadReplay(Replay.ReplayFile(replay), true, () =>
{
Expand All @@ -214,7 +221,7 @@ private static void HandleCommandLine()

Application.Quit();
});
}, "Replay", false, null);
}, "Replay");
}

if (GenCommandLine.CommandLineArgPassed("printsync"))
Expand Down Expand Up @@ -332,6 +339,16 @@ private static void DoPatches()
new HarmonyMethod(typeof(PageModsPatch), nameof(PageModsPatch.Postfix))
);
}

var cancelForArbiter = new HarmonyMethod(typeof(CancelForArbiter), "Prefix");

var prisonLaborBehavior = MpReflection.GetTypeByName("PrisonLabor.Behaviour_MotivationIcon");
if (prisonLaborBehavior != null)
harmony.Patch(prisonLaborBehavior.GetMethod("Update", new Type[0]), cancelForArbiter);

var prisonLaborPawnIcons = MpReflection.GetTypeByName("PrisonLabor.Core.GUI_Components.PawnIcons") ?? MpReflection.GetTypeByName("PrisonLabor.MapComponent_Icons");
if (prisonLaborPawnIcons != null)
harmony.Patch(prisonLaborPawnIcons.GetMethod("MapComponentTick", new Type[0]), cancelForArbiter);
}

public static UniqueList<Texture2D> icons = new UniqueList<Texture2D>();
Expand Down
16 changes: 16 additions & 0 deletions Source/Client/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ static class LoadGameMarker
[MpPatch(typeof(SoundStarter), nameof(SoundStarter.PlayOneShot))]
[MpPatch(typeof(Command_SetPlantToGrow), nameof(Command_SetPlantToGrow.WarnAsAppropriate))]
[MpPatch(typeof(TutorUtility), nameof(TutorUtility.DoModalDialogIfNotKnown))]
[MpPatch(typeof(CameraJumper), nameof(CameraJumper.TryHideWorld))]
static class CancelFeedbackNotTargetedAtMe
{
public static bool Cancel =>
Expand All @@ -840,6 +841,18 @@ static class CancelFeedbackNotTargetedAtMe
static bool Prefix() => !Cancel;
}

[HarmonyPatch(typeof(Targeter), nameof(Targeter.BeginTargeting), typeof(TargetingParameters), typeof(Action<LocalTargetInfo>), typeof(Pawn), typeof(Action), typeof(Texture2D))]
static class CancelBeginTargeting
{
static bool Prefix()
{
if (TickPatch.currentExecutingCmdIssuedBySelf && MapAsyncTimeComp.executingCmdMap != null)
MapAsyncTimeComp.keepTheMap = true;

return !CancelFeedbackNotTargetedAtMe.Cancel;
}
}

[MpPatch(typeof(MoteMaker), nameof(MoteMaker.MakeStaticMote), new[] { typeof(IntVec3), typeof(Map), typeof(ThingDef), typeof(float) })]
[MpPatch(typeof(MoteMaker), nameof(MoteMaker.MakeStaticMote), new[] { typeof(Vector3), typeof(Map), typeof(ThingDef), typeof(float) })]
static class CancelMotesNotTargetedAtMe
Expand Down Expand Up @@ -1058,6 +1071,9 @@ public static void SetupMap(Map map)
async.mapTicks = Find.Maps.Where(m => m != map).Select(m => m.AsyncTime()?.mapTicks).Max() ?? Find.TickManager.TicksGame;
async.storyteller = new Storyteller(Find.Storyteller.def, Find.Storyteller.difficulty);
async.storyWatcher = new StoryWatcher();

if (!Multiplayer.WorldComp.asyncTime)
async.TimeSpeed = Find.TickManager.CurTimeSpeed;
}
}

Expand Down
1 change: 1 addition & 0 deletions Source/Client/PlayerCursors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static void Postfix()
{
if (!drawnThisUpdate.Add(sel.Key)) continue;
if (!ThingsById.thingsById.TryGetValue(sel.Key, out Thing thing)) continue;
if (thing.Map != Find.CurrentMap) continue;

selTimes[thing] = sel.Value;
SelectionDrawerUtility.CalculateSelectionBracketPositionsWorld(SelectionDrawer.bracketLocs, thing, thing.DrawPos, thing.RotatedSize.ToVector2(), selTimes, Vector2.one, 1f);
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/ScribeUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void UnregisterAllTemp()

public void UnregisterAllFrom(Map map)
{
foreach (var val in allObjectsByLoadID.Values)
foreach (var val in allObjectsByLoadID.Values.ToArray())
{
if (val is Thing thing && thing.Map == map ||
val is PassingShip ship && ship.Map == map ||
Expand Down
8 changes: 4 additions & 4 deletions Source/Common/MultiplayerServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public ServerPlayer OnConnected(IConnection conn)
return conn.serverPlayer;
}

public void OnDisconnected(IConnection conn)
public void OnDisconnected(IConnection conn, MpDisconnectReason reason)
{
if (conn.State == ConnectionStateEnum.Disconnected) return;

Expand All @@ -243,7 +243,7 @@ public void OnDisconnected(IConnection conn)

conn.State = ConnectionStateEnum.Disconnected;

MpLog.Log($"Disconnected: {conn}");
MpLog.Log($"Disconnected ({reason}): {conn}");
}

public void SendToAll(Packets id)
Expand Down Expand Up @@ -371,7 +371,7 @@ public void OnPeerConnected(NetPeer peer)
public void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo)
{
IConnection conn = peer.GetConnection();
server.OnDisconnected(conn);
server.OnDisconnected(conn, MpDisconnectReason.ClientLeft);
}

public void OnNetworkLatencyUpdate(NetPeer peer, int latency)
Expand Down Expand Up @@ -468,7 +468,7 @@ public void Disconnect(string reasonKey)
public void Disconnect(MpDisconnectReason reason, byte[] data = null)
{
conn.Close(reason, data);
Server.OnDisconnected(conn);
Server.OnDisconnected(conn, reason);
}

public void SendChat(string msg)
Expand Down
1 change: 1 addition & 0 deletions Source/Common/Networking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public enum MpDisconnectReason : byte
ServerClosed,
ServerFull,
Kick,
ClientLeft,
}

public class PacketReadException : Exception
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public static class MpVersion
{
public const string Version = "0.4.1";
public const string Version = "0.4.2";
public const int Protocol = 11;

#if DEBUG
Expand Down

0 comments on commit 994f60b

Please sign in to comment.