Compare commits

..

1 Commits
v1 ... master

@ -35,18 +35,15 @@
<Reference Include="LogicWorld.BuildingManagement"> <Reference Include="LogicWorld.BuildingManagement">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.BuildingManagement.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.BuildingManagement.dll</HintPath>
</Reference> </Reference>
<Reference Include="LogicWorld.Players">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Players.dll</HintPath>
</Reference>
<Reference Include="LogicWorld.Physics">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Physics.dll</HintPath>
</Reference>
<Reference Include="LogicWorld.Interfaces"> <Reference Include="LogicWorld.Interfaces">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Interfaces.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Interfaces.dll</HintPath>
</Reference> </Reference>
<Reference Include="LogicWorld.Modding"> <Reference Include="LogicWorld.Modding">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Modding.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.Modding.dll</HintPath>
</Reference> </Reference>
<Reference Include="LogicWorld.GameStates">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.GameStates.dll</HintPath>
</Reference>
<Reference Include="LogicWorld.SharedCode"> <Reference Include="LogicWorld.SharedCode">
<HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.SharedCode.dll</HintPath> <HintPath>$(LogicWorldGameLocation)\Logic_World_Data\Managed\LogicWorld.SharedCode.dll</HintPath>
</Reference> </Reference>

@ -1,6 +1,6 @@
MHG.SettingsMenu.Pages.Controls.Headings.DLatchPoke: "Mod: DLatch Poke" MHG.SettingsMenu.Pages.Controls.Headings.DLatchPoke: "Mod: DLatch Poke"
FancyInput.Trigger.DLatchPoke.Poke: "Poke a DLatch" FancyInput.Trigger.DLatchPoke.Poke: "Toggle DLatch State"
FancyInput.Trigger.DLatchPoke.Poke.Description: """ FancyInput.Trigger.DLatchPoke.Poke.Description: """
Toggles the internal state of the DLatch the player is looking at. Toggles the internal state of the DLatch (or multiple) the player is looking at or has selected.
""" """

@ -1,7 +1,7 @@
ID: D4VID_DLatchPoke ID: D4VID_DLatchPoke
Name: DLatch Poke Name: DLatch Poke
Author: D4VID Author: D4VID
Version: 1.0.2 Version: 2.0.0
Priority: 0 Priority: 0
Dependencies: Dependencies:
- EccsLogicWorldAPI - EccsLogicWorldAPI

@ -1,18 +1,14 @@
using DLatchPoke.Client.Keybindings; using DLatchPoke.Client.Keybindings;
using DLatchPoke.Shared.Packets.C2S; using DLatchPoke.Client.Network;
using EccsLogicWorldAPI.Client.PacketIndexOrdering; using EccsLogicWorldAPI.Client.Injectors;
using FancyInput; using FancyInput;
using LogicAPI.Client; using LogicAPI.Client;
using LogicAPI.Data;
using LogicLog; using LogicLog;
using LogicWorld;
using LogicWorld.Interfaces;
using LogicWorld.Physics;
using LogicWorld.Players;
namespace DLatchPoke.Client { namespace DLatchPoke.Client {
public class DLatchPokeClient : ClientMod { public class DLatchPokeClient : ClientMod {
public new static ILogicLogger Logger; public new static ILogicLogger Logger;
public static bool ServerSupportsMod = false;
protected override void Initialize() { protected override void Initialize() {
Logger = base.Logger; Logger = base.Logger;
@ -21,42 +17,10 @@ namespace DLatchPoke.Client {
// Register keybindings in the settings menu // Register keybindings in the settings menu
CustomInput.Register<DLatchPokeContext, DLatchPokeTrigger>("DLatchPoke"); CustomInput.Register<DLatchPokeContext, DLatchPokeTrigger>("DLatchPoke");
// Register the keybinding to enter the path analyzer game state // Inject packet handlers
FirstPersonInteraction.RegisterBuildingKeybinding(DLatchPokeTrigger.Poke, () => { RawPacketHandlerInjector.addPacketHandler(new AnnounceModPacketHandler(Manifest.Version));
if (!PacketIndexOrdering.doesServerSupportPacket(typeof(DLatchPokeRequest))) {
Logger.Error("Server does not support this mod");
return false;
}
return PokeDLatch();
}
);
// Mark it as optional so that the game works even if the mod is not present on one end
PacketIndexOrdering.markModAsOptional(GetType().Assembly);
Logger.Info("DLatchPoke mod loaded"); Logger.Info("DLatchPoke mod loaded");
} }
private bool PokeDLatch() {
HitInfo hitInfo = PlayerCaster.CameraCast(Masks.Environment | Masks.Structure | Masks.Peg);
if (!hitInfo.HitSomething) {
return false;
}
ComponentAddress componentAddress;
if (hitInfo.HitComponent) {
componentAddress = hitInfo.cAddress;
} else if (hitInfo.HitPeg) {
componentAddress = hitInfo.pAddress.ComponentAddress;
} else {
return false;
}
Instances.SendData.Send(new DLatchPokeRequest() {
ComponentAddress = componentAddress,
});
return true;
}
} }
} }

@ -0,0 +1,36 @@
using DLatchPoke.Client.Keybindings;
using DLatchPoke.Shared.Packets.C2S;
using FancyInput;
using LogicAPI.Data;
using LogicWorld.Building.Overhaul;
using LogicWorld.GameStates;
using LogicWorld.Interfaces;
namespace DLatchPoke.Client {
public class DLatchPokeOperation : BuildingOperation {
public override string IconHexCode => "f363";
public override bool CanOperateOn(ComponentSelection selection) {
if (!DLatchPokeClient.ServerSupportsMod) {
DLatchPokeClient.Logger.Error("Server does not support this mod");
return false;
}
ComponentType dLatchType = Instances.MainWorld.ComponentTypes.GetComponentType("MHG.DLatch");
foreach (ComponentAddress componentAddress in selection) {
if (Instances.MainWorld.Data.Lookup(componentAddress).Data.Type != dLatchType) {
return false;
}
}
return true;
}
public override void BeginOperationOn(ComponentSelection selection) {
Instances.SendData.Send(new DLatchPokeRequest() {
ComponentAddresses = selection.ComponentsInSelection,
});
GameStateManager.TransitionBackToBuildingState();
}
public override InputTrigger OperationStarter => DLatchPokeTrigger.Poke;
}
}

@ -1,6 +1,6 @@
namespace DLatchPoke.Client.Keybindings { namespace DLatchPoke.Client.Keybindings {
public enum DLatchPokeContext { public enum DLatchPokeContext {
None, None = 0,
DLatchPoke, DLatchPoke,
} }
} }

@ -1,7 +1,7 @@
namespace DLatchPoke.Client.Keybindings { namespace DLatchPoke.Client.Keybindings {
// Define all available keybindings of the mod // Define all available keybindings of the mod
public enum DLatchPokeTrigger { public enum DLatchPokeTrigger {
None, None = 0,
Poke, Poke,
} }
} }

@ -0,0 +1,22 @@
using System;
using DLatchPoke.Shared.Packets.S2C;
using LogicWorld.SharedCode.Networking;
namespace DLatchPoke.Client.Network {
public class AnnounceModPacketHandler : PacketHandler<AnnounceModPresence> {
private readonly Version _version;
public AnnounceModPacketHandler(Version version) {
_version = version;
}
public override void Handle(AnnounceModPresence packet, HandlerContext context) {
if (packet.Version == _version) {
DLatchPokeClient.Logger.Info($"Mod is supported on the server: version={packet.Version}");
DLatchPokeClient.ServerSupportsMod = true;
} else {
DLatchPokeClient.Logger.Error($"Mod version mismatch: client={_version}, server={packet.Version}");
}
}
}
}

@ -1,34 +1,68 @@
using System.Collections.Generic;
using System.Linq;
using DLatchPoke.Server.Network; using DLatchPoke.Server.Network;
using DLatchPoke.Shared.Packets.S2C;
using EccsLogicWorldAPI.Server; using EccsLogicWorldAPI.Server;
using EccsLogicWorldAPI.Server.Injectors; using EccsLogicWorldAPI.Server.Injectors;
using EccsLogicWorldAPI.Server.PacketIndexOrdering; using EccsLogicWorldAPI.Shared.PacketWrapper;
using LogicAPI.Data; using LogicAPI.Data;
using LogicAPI.Networking.Packets.Initialization;
using LogicAPI.Server; using LogicAPI.Server;
using LogicAPI.Server.Components; using LogicAPI.Server.Components;
using LogicAPI.Server.Networking;
using LogicAPI.Server.Networking.ClientVerification;
using LogicLog; using LogicLog;
using LogicWorld.LogicCode; using LogicWorld.LogicCode;
using LogicWorld.Server.Circuitry; using LogicWorld.Server.Circuitry;
using LogicWorld.SharedCode.Networking;
namespace DLatchPoke.Server { namespace DLatchPoke.Server {
// ReSharper disable once ClassNeverInstantiated.Global // ReSharper disable once ClassNeverInstantiated.Global
public class DLatchPokeServer : ServerMod { public class DLatchPokeServer : ServerMod, IClientVerifier {
public new static ILogicLogger Logger; public new static ILogicLogger Logger;
private NetworkServer _networkServer;
private readonly Dictionary<string, bool> _playerHasMod = new Dictionary<string, bool>();
private static ICircuitryManager _circuits; private static ICircuitryManager _circuits;
protected override void Initialize() { protected override void Initialize() {
Logger = base.Logger; Logger = base.Logger;
Logger.Info("DLatchPoke server mod loading"); Logger.Info("DLatchPoke server mod loading");
// Register handler for client request packet _networkServer = ServiceGetter.getService<NetworkServer>();
RawPacketHandlerInjector.addPacketHandler(new DLatchPokeRequestHandler(this));
// Mark it as optional so that the game works even if the mod is not present on one end // Inject client verifier:
PacketIndexOrdering.markModAsOptional(GetType().Assembly); RawJoinVerifierInjector.addVerifier(this);
PacketHandlerManager.getCustomPacketHandler<ClientLoadedWorldPacket>()
.addHandlerToEnd(new ClientJoinedPacketHandler(this));
RawPacketHandlerInjector.addPacketHandler(new DLatchPokeRequestHandler(this));
_circuits = ServiceGetter.getService<ICircuitryManager>(); _circuits = ServiceGetter.getService<ICircuitryManager>();
Logger.Info("DLatchPoke server mod loaded"); Logger.Info("DLatchPoke server mod loaded");
} }
/// <summary>
/// Gets called before a player (client) joins the server.
/// Used to check if the player has this mod installed
/// </summary>
public void Verify(VerificationContext ctx) {
bool hasMod = ctx.ApprovalPacket.ClientMods.Contains(Manifest.ID);
string playerName = ctx.PlayerID.Name;
_playerHasMod[playerName] = hasMod;
}
/// <summary>
/// Gets called after verifying a connecting player.
/// If the player has this mod installed, send a packet informing about the mod's presence on the server.
/// </summary>
public void PlayerJoined(PlayerData playerData, HandlerContext context) {
_playerHasMod.TryGetValue(playerData.Name, out bool hasWireTracer);
if (hasWireTracer) {
_networkServer.Send(context.Sender, new AnnounceModPresence() {
Version = Manifest.Version
});
}
}
/// <summary> /// <summary>
/// Gets called from the DLatchPokeRequestHandler. /// Gets called from the DLatchPokeRequestHandler.
/// Toggle the internal state of the DLatch /// Toggle the internal state of the DLatch

@ -0,0 +1,16 @@
using EccsLogicWorldAPI.Shared.PacketWrapper;
using LogicAPI.Networking.Packets.Initialization;
using LogicWorld.SharedCode.Networking;
namespace DLatchPoke.Server.Network {
public class ClientJoinedPacketHandler : CustomPacketHandler<ClientLoadedWorldPacket> {
private readonly DLatchPokeServer _dLatchPokeServer;
public ClientJoinedPacketHandler(DLatchPokeServer dLatchPokeServer) {
_dLatchPokeServer = dLatchPokeServer;
}
public override void handle(ref bool isCancelled, ref ClientLoadedWorldPacket packet, HandlerContext context) {
_dLatchPokeServer.PlayerJoined(packet.PlayerData, context);
}
}
}

@ -1,15 +1,19 @@
using DLatchPoke.Shared.Packets.C2S; using DLatchPoke.Shared.Packets.C2S;
using LogicAPI.Data;
using LogicWorld.SharedCode.Networking; using LogicWorld.SharedCode.Networking;
namespace DLatchPoke.Server.Network { namespace DLatchPoke.Server.Network {
public class DLatchPokeRequestHandler : PacketHandler<DLatchPokeRequest> { public class DLatchPokeRequestHandler : PacketHandler<DLatchPokeRequest> {
private readonly DLatchPokeServer _dLatchPokeServer; private readonly DLatchPokeServer _dLatchPokeServer;
public DLatchPokeRequestHandler(DLatchPokeServer dLatchPokeServer) { public DLatchPokeRequestHandler(DLatchPokeServer dLatchPokeServer) {
_dLatchPokeServer = dLatchPokeServer; _dLatchPokeServer = dLatchPokeServer;
} }
public override void Handle(DLatchPokeRequest packet, HandlerContext context) { public override void Handle(DLatchPokeRequest packet, HandlerContext context) {
_dLatchPokeServer.PokeDLatch(packet.ComponentAddress); foreach (ComponentAddress componentAddress in packet.ComponentAddresses) {
_dLatchPokeServer.PokeDLatch(componentAddress);
}
} }
} }
} }

@ -1,3 +1,4 @@
using System.Collections.Generic;
using LogicAPI.Data; using LogicAPI.Data;
using LogicAPI.Networking.Packets; using LogicAPI.Networking.Packets;
using MessagePack; using MessagePack;
@ -5,6 +6,6 @@ using MessagePack;
namespace DLatchPoke.Shared.Packets.C2S { namespace DLatchPoke.Shared.Packets.C2S {
[MessagePackObject] [MessagePackObject]
public class DLatchPokeRequest : Packet { public class DLatchPokeRequest : Packet {
[Key(0)] public ComponentAddress ComponentAddress; [Key(0)] public IEnumerable<ComponentAddress> ComponentAddresses;
} }
} }

@ -0,0 +1,10 @@
using System;
using LogicAPI.Networking.Packets;
using MessagePack;
namespace DLatchPoke.Shared.Packets.S2C {
[MessagePackObject]
public class AnnounceModPresence : Packet {
[Key(0)] public Version Version;
}
}
Loading…
Cancel
Save