Skip to content
Draft
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
/MinecraftClient.userprefs
/Other/
/.vs/
SessionCache.ini
.*
!/.github
/packages
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
path = ConsoleInteractive
url = https://github.com/breadbyte/ConsoleInteractive
branch = main
[submodule "MinecraftProtocolLibrary"]
path = MinecraftProtocolLibrary
url = https://github.com/BruceChenQAQ/Minecraft-Protocol-Library.git
13 changes: 11 additions & 2 deletions MinecraftClient.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 17.3.32901.215
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinecraftClient", "MinecraftClient\MinecraftClient.csproj", "{1E2FACE4-F5CA-4323-9641-740C6A551770}"
ProjectSection(ProjectDependencies) = postProject
{B6EA6A06-0EF8-4931-93EA-68EB02D69FE9} = {B6EA6A06-0EF8-4931-93EA-68EB02D69FE9}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleInteractive", "ConsoleInteractive\ConsoleInteractive\ConsoleInteractive\ConsoleInteractive.csproj", "{93DA4D71-EFAD-4493-BE21-A105AF663660}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinecraftProtocolLibrary", "MinecraftProtocolLibrary\MinecraftProtocolLibrary\MinecraftProtocolLibrary.csproj", "{B6EA6A06-0EF8-4931-93EA-68EB02D69FE9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,13 +26,17 @@ Global
{93DA4D71-EFAD-4493-BE21-A105AF663660}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93DA4D71-EFAD-4493-BE21-A105AF663660}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93DA4D71-EFAD-4493-BE21-A105AF663660}.Release|Any CPU.Build.0 = Release|Any CPU
{B6EA6A06-0EF8-4931-93EA-68EB02D69FE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6EA6A06-0EF8-4931-93EA-68EB02D69FE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6EA6A06-0EF8-4931-93EA-68EB02D69FE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6EA6A06-0EF8-4931-93EA-68EB02D69FE9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
RESX_ShowErrorsInErrorList = False
SolutionGuid = {6DED60F4-9CF4-4DB3-8966-582B2EBE8487}
RESX_SortFileContentOnSave = False
SolutionGuid = {6DED60F4-9CF4-4DB3-8966-582B2EBE8487}
RESX_ShowErrorsInErrorList = False
EndGlobalSection
EndGlobal
39 changes: 39 additions & 0 deletions MinecraftClient/AsyncTaskHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MinecraftClient.Protocol.ProfileKey;
using MinecraftClient.Protocol.Session;

namespace MinecraftClient
{
internal static class AsyncTaskHandler
{
private static readonly List<Task> Tasks = new();

internal static Task CheckUpdate = Task.CompletedTask;

internal static Task CacheSessionReader = Task.CompletedTask;

internal static Task SaveSessionToDisk = Task.CompletedTask;

internal static Task WritebackSettingFile = Task.CompletedTask;

internal static async void ExitCleanUp()
{
await WritebackSettingFile;

await CacheSessionReader;

await SaveSessionToDisk;

foreach (var task in Tasks)
{
await task;
}

Tasks.Clear();
}
}
}
2 changes: 1 addition & 1 deletion MinecraftClient/ChatBots/AutoAttack.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using MinecraftClient.Mapping;
using MinecraftClient.EntityHandler;
using MinecraftClient.Scripting;
using Tomlet.Attributes;

Expand Down
3 changes: 1 addition & 2 deletions MinecraftClient/ChatBots/AutoDig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,9 @@ public override void OnDeath()
StopDigging();
}

public override bool OnDisconnect(DisconnectReason reason, string message)
public override int OnDisconnect(DisconnectReason reason, string message)
{
StopDigging();

return base.OnDisconnect(reason, message);
}
}
Expand Down
3 changes: 2 additions & 1 deletion MinecraftClient/ChatBots/AutoFishing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Brigadier.NET.Builder;
using MinecraftClient.CommandHandler;
using MinecraftClient.CommandHandler.Patch;
using MinecraftClient.EntityHandler;
using MinecraftClient.Inventory;
using MinecraftClient.Mapping;
using MinecraftClient.Scripting;
Expand Down Expand Up @@ -535,7 +536,7 @@ public override void OnDeath()
StopFishing();
}

public override bool OnDisconnect(DisconnectReason reason, string message)
public override int OnDisconnect(DisconnectReason reason, string message)
{
StopFishing();

Expand Down
86 changes: 60 additions & 26 deletions MinecraftClient/ChatBots/AutoRelog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ private void _Initialize()
}
}

public override bool OnDisconnect(DisconnectReason reason, string message)
public override int OnDisconnect(DisconnectReason reason, string message)
{
bool triggerReco = false;
if (reason == DisconnectReason.UserLogout)
{
LogDebugToConsole(Translations.bot_autoRelog_ignore_user_logout);
Expand All @@ -113,44 +114,77 @@ public override bool OnDisconnect(DisconnectReason reason, string message)
if (Config.Ignore_Kick_Message)
{
Configs._BotRecoAttempts++;
LaunchDelayedReconnection(null);
return true;
LogDebugToConsole(Translations.bot_autoRelog_reconnect_always);
triggerReco = true;
}

foreach (string msg in Config.Kick_Messages)
else
{
if (comp.Contains(msg))
foreach (string msg in Config.Kick_Messages)
{
Configs._BotRecoAttempts++;
LaunchDelayedReconnection(msg);
return true;
if (comp.Contains(msg))
{
Configs._BotRecoAttempts++;
LogDebugToConsole(string.Format(Translations.bot_autoRelog_reconnect, msg));
triggerReco = true;
break;
}
}
}

LogDebugToConsole(Translations.bot_autoRelog_reconnect_ignore);
if (!triggerReco)
LogDebugToConsole(Translations.bot_autoRelog_reconnect_ignore);
}
}

return false;
if (triggerReco)
{
double delay = random.NextDouble() * (Config.Delay.max - Config.Delay.min) + Config.Delay.min;
LogToConsole(string.Format(Translations.bot_autoRelog_wait, delay));
return (int)Math.Floor(delay * 1000);
}
else
{
return -1;
}
}

private void LaunchDelayedReconnection(string? msg)
public static int OnDisconnectStatic(DisconnectReason reason, string message)
{
double delay = random.NextDouble() * (Config.Delay.max - Config.Delay.min) + Config.Delay.min;
LogDebugToConsole(string.Format(string.IsNullOrEmpty(msg) ? Translations.bot_autoRelog_reconnect_always : Translations.bot_autoRelog_reconnect, msg));
LogToConsole(string.Format(Translations.bot_autoRelog_wait, delay));
System.Threading.Thread.Sleep((int)Math.Floor(delay * 1000));
ReconnectToTheServer();
}
bool triggerReco = false;
if (Config.Enabled
&& reason != DisconnectReason.UserLogout
&& (Config.Retries < 0 || Configs._BotRecoAttempts < Config.Retries))
{
message = GetVerbatim(message);
string comp = message.ToLower();

public static bool OnDisconnectStatic(DisconnectReason reason, string message)
{
if (Config.Enabled)
if (Config.Ignore_Kick_Message)
{
Configs._BotRecoAttempts++;
triggerReco = true;
}
else
{
foreach (string msg in Config.Kick_Messages)
{
if (comp.Contains(msg))
{
Configs._BotRecoAttempts++;
triggerReco = true;
break;
}
}
}
}

if (triggerReco)
{
double delay = random.NextDouble() * (Config.Delay.max - Config.Delay.min) + Config.Delay.min;
return (int)Math.Floor(delay * 1000);
}
else
{
AutoRelog bot = new();
bot.Initialize();
return bot.OnDisconnect(reason, message);
return -1;
}
return false;
}
}
}
4 changes: 2 additions & 2 deletions MinecraftClient/ChatBots/Farmer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ public override void AfterGameJoined()
running = false;
}

public override bool OnDisconnect(DisconnectReason reason, string message)
public override int OnDisconnect(DisconnectReason reason, string message)
{
running = false;
return true;
return base.OnDisconnect(reason, message);
}

private void MainPorcess()
Expand Down
1 change: 1 addition & 0 deletions MinecraftClient/ChatBots/FollowPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Brigadier.NET.Builder;
using MinecraftClient.CommandHandler;
using MinecraftClient.CommandHandler.Patch;
using MinecraftClient.EntityHandler;
using MinecraftClient.Mapping;
using MinecraftClient.Scripting;
using Tomlet.Attributes;
Expand Down
78 changes: 48 additions & 30 deletions MinecraftClient/ChatBots/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,52 +356,70 @@ private static void RenderInConsole(McMap map)

for (int base_y = 0; base_y < map.Height; base_y += scale)
{
int last_R = -1, last_G = -1, last_B = -1;
string lastFg = string.Empty, lagtBg = string.Empty;
for (int base_x = 0; base_x < map.Width; base_x += scale)
{
int RL = 0, GL = 0, BL = 0, RR = 0, GR = 0, BR = 0;
double mid_dx = (double)(scale - 1) / 2;
int RUL = 0, GUL = 0, BUL = 0, RUR = 0, GUR = 0, BUR = 0;
int RDL = 0, GDL = 0, BDL = 0, RDR = 0, GDR = 0, BDR = 0;
double mid = (double)(scale - 1) / 2;
for (int dy = 0; dy < scale; ++dy)
{
for (int dx = 0; dx < scale; ++dx)
{
int x = Math.Min(base_x + dx, map.Width - 1);
int y = Math.Min(base_y + dy, map.Height - 1);
ColorRGBA color = MapColors.ColorByteToRGBA(map.Colors![x + y * map.Width]);
if (dx <= mid_dx)
if (dx <= mid)
{
RL += color.R; GL += color.G; BL += color.B;
if (dy <= mid)
{
RUL += color.R; GUL += color.G; BUL += color.B;
}
if (dy >= mid)
{
RDL += color.R; GDL += color.G; BDL += color.B;
}
}
if (dx >= mid_dx)
if (dx >= mid)
{
RR += color.R; GR += color.G; BR += color.B;
if (dy <= mid)
{
RUR += color.R; GUR += color.G; BUR += color.B;
}
if (dy >= mid)
{
RDR += color.R; GDR += color.G; BDR += color.B;
}
}
}
}

int pixel_cnt = ((scale + 1) / 2) * scale;
RL = (int)Math.Round((double)RL / pixel_cnt);
GL = (int)Math.Round((double)GL / pixel_cnt);
BL = (int)Math.Round((double)BL / pixel_cnt);
RR = (int)Math.Round((double)RR / pixel_cnt);
GR = (int)Math.Round((double)GR / pixel_cnt);
BR = (int)Math.Round((double)BR / pixel_cnt);

if (RL == last_R && GL == last_G && BL == last_B)
sb.Append(' ');
else
{
sb.Append(ColorHelper.GetColorEscapeCode((byte)RL, (byte)GL, (byte)BL, false)).Append(' ');
last_R = RL; last_G = GL; last_B = BL;
}

if (RR == last_R && GR == last_G && BR == last_B)
sb.Append(' ');
else
{
sb.Append(ColorHelper.GetColorEscapeCode((byte)RR, (byte)GR, (byte)BR, false)).Append(' ');
last_R = RR; last_G = GR; last_B = BR;
}
int pixel_cnt = ((scale + 1) / 2) * ((scale + 1) / 2);
RDL = (int)Math.Round((double)RDL / pixel_cnt);
GDL = (int)Math.Round((double)GDL / pixel_cnt);
BDL = (int)Math.Round((double)BDL / pixel_cnt);
RDR = (int)Math.Round((double)RDR / pixel_cnt);
GDR = (int)Math.Round((double)GDR / pixel_cnt);
BDR = (int)Math.Round((double)BDR / pixel_cnt);

RUL = (int)Math.Round((double)RUL / pixel_cnt);
GUL = (int)Math.Round((double)GUL / pixel_cnt);
BUL = (int)Math.Round((double)BUL / pixel_cnt);
RUR = (int)Math.Round((double)RUR / pixel_cnt);
GUR = (int)Math.Round((double)GUR / pixel_cnt);
BUR = (int)Math.Round((double)BUR / pixel_cnt);

string colorCode = ColorHelper.GetColorEscapeCode((byte)RUL, (byte)GUL, (byte)BUL, true);
if (lastFg != colorCode) { sb.Append(colorCode); lastFg = colorCode; }
colorCode = ColorHelper.GetColorEscapeCode((byte)RDL, (byte)GDL, (byte)BDL, false);
if (lagtBg != colorCode) { sb.Append(colorCode); lagtBg = colorCode; }
sb.Append('▀');

colorCode = ColorHelper.GetColorEscapeCode((byte)RUR, (byte)GUR, (byte)BUR, true);
if (lastFg != colorCode) { sb.Append(colorCode); lastFg = colorCode; }
colorCode = ColorHelper.GetColorEscapeCode((byte)RDR, (byte)GDR, (byte)BDR, false);
if (lagtBg != colorCode) { sb.Append(colorCode); lagtBg = colorCode; }
sb.Append('▀');
}
if (base_y >= map.Height - scale)
sb.Append(ColorHelper.GetResetEscapeCode());
Expand Down
2 changes: 1 addition & 1 deletion MinecraftClient/ChatBots/ReplayCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public override void Update()
}
}

public override bool OnDisconnect(DisconnectReason reason, string message)
public override int OnDisconnect(DisconnectReason reason, string message)
{
replay!.OnShutDown();
return base.OnDisconnect(reason, message);
Expand Down
2 changes: 1 addition & 1 deletion MinecraftClient/ChatBots/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public override void Initialize()
//Load the given file from the startup parameters
if (LookForScript(ref file!))
{
lines = System.IO.File.ReadAllLines(file, Encoding.UTF8);
lines = File.ReadAllLines(file, Encoding.UTF8);
csharp = file.EndsWith(".cs");
thread = null;

Expand Down
4 changes: 2 additions & 2 deletions MinecraftClient/ChatBots/ScriptScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ public override void Update()
}
}

public override bool OnDisconnect(DisconnectReason reason, string message)
public override int OnDisconnect(DisconnectReason reason, string message)
{
serverlogin_done = false;
return false;
return base.OnDisconnect(reason, message);
}

private static string Task2String(TaskConfig task)
Expand Down
Loading