Add support for creating replay mod capture files (#1246)

* Add test replay handler
* Fix incorrect built raw packet
* Fix incorrect built raw packet
* Add filter
* Add not working zip lib
* Add dotNetZip lib and complete basic function
* Update ReplayHandler.cs
* Complete Replay handler
Without client player handling
* Complete replay mod
- New ChatBot OnNetworkPacket event
* Add auto-backup and command for Replay Mod
* Add ReplayMod description to readme
* Small naming changes, fix compile error on .NET4.0
* ReplayHandler slight optimizations
Use Path.Combine to automatically use Windows '\' or Linux '/'
Move re-usable common parts outside the Replay handler
Small optimizations in building JSON strings
Co-authored-by: ORelio <oreliogitantispam.l0gin@spamgourmet.com>
This commit is contained in:
ReinforceZwei 2020-09-07 03:51:42 +08:00 committed by GitHub
parent cd1badb9d6
commit 7e20e409a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 32732 additions and 21 deletions

View file

@ -84,6 +84,9 @@ namespace MinecraftClient
// players latency
private Dictionary<string, int> playersLatency = new Dictionary<string, int>();
// ChatBot OnNetworkPacket event
private bool networkPacketCaptureEnabled = false;
public int GetServerPort() { return port; }
public string GetServerHost() { return host; }
public string GetUsername() { return username; }
@ -98,6 +101,8 @@ namespace MinecraftClient
public int GetTotalExperience() { return playerTotalExperience; }
public byte GetCurrentSlot() { return CurrentSlot; }
public int GetGamemode() { return gamemode; }
public bool GetNetworkPacketCaptureEnabled() { return networkPacketCaptureEnabled; }
public int GetProtocolVersion() { return handler.GetProtocolVersion(); }
// get bots list for unloading them by commands
public List<ChatBot> GetLoadedChatBots()
@ -185,6 +190,7 @@ namespace MinecraftClient
if (Settings.Mailer_Enabled) { BotLoad(new ChatBots.Mailer()); }
if (Settings.AutoCraft_Enabled) { BotLoad(new AutoCraft(Settings.AutoCraft_configFile)); }
if (Settings.AutoDrop_Enabled) { BotLoad(new AutoDrop(Settings.AutoDrop_Mode, Settings.AutoDrop_items)); }
if (Settings.ReplayMod_Enabled) { BotLoad(new ReplayCapture(Settings.ReplayMod_BackupInterval)); }
//Add your ChatBot here by uncommenting and adapting
//BotLoad(new ChatBots.YourBot());
@ -757,6 +763,18 @@ namespace MinecraftClient
}
}
/// <summary>
/// Enable or disable network packet event calling.
/// </summary>
/// <remarks>
/// Enable this may increase memory usage.
/// </remarks>
/// <param name="enabled"></param>
public void SetNetworkPacketCaptureEnabled(bool enabled)
{
networkPacketCaptureEnabled = enabled;
}
#endregion
#region Getters: Retrieve data for use in other methods or ChatBots
@ -1492,6 +1510,21 @@ namespace MinecraftClient
}
}
/// <summary>
/// Called when a network packet received or sent
/// </summary>
/// <remarks>
/// Only called if <see cref="networkPacketEventEnabled"/> is set to True
/// </remarks>
/// <param name="packetID">Packet ID</param>
/// <param name="packetData">A copy of Packet Data</param>
/// <param name="isLogin">The packet is login phase or playing phase</param>
/// <param name="isInbound">The packet is received from server or sent by client</param>
public void OnNetworkPacket(int packetID, List<byte> packetData, bool isLogin, bool isInbound)
{
DispatchBotEvent(bot => bot.OnNetworkPacket(packetID, packetData, isLogin, isInbound));
}
/// <summary>
/// Called when a server was successfully joined
/// </summary>