Fix 1.19.3 key exchange in offline mode

This commit is contained in:
BruceChen 2023-01-17 20:16:35 +08:00
parent 92a911ce99
commit 1f54a7c247
5 changed files with 12 additions and 6 deletions

View file

@ -100,7 +100,7 @@ namespace MinecraftClient.ChatBots
private Double attackSpeed = 4; private Double attackSpeed = 4;
private Double attackCooldownSeconds; private Double attackCooldownSeconds;
private readonly bool overrideAttackSpeed = false; private readonly bool overrideAttackSpeed = false;
private readonly int attackRange = 4; private readonly double attackRange = 4.0;
private Double serverTPS; private Double serverTPS;
private float health = 100; private float health = 100;
private readonly bool attackHostile = true; private readonly bool attackHostile = true;

View file

@ -2415,7 +2415,7 @@ namespace MinecraftClient
/// <summary> /// <summary>
/// Called when a server was successfully joined /// Called when a server was successfully joined
/// </summary> /// </summary>
public void OnGameJoined() public void OnGameJoined(bool isOnlineMode)
{ {
string? bandString = Config.Main.Advanced.BrandInfo.ToBrandString(); string? bandString = Config.Main.Advanced.BrandInfo.ToBrandString();
if (!String.IsNullOrWhiteSpace(bandString)) if (!String.IsNullOrWhiteSpace(bandString))
@ -2432,7 +2432,7 @@ namespace MinecraftClient
(byte)Config.MCSettings.MainHand); (byte)Config.MCSettings.MainHand);
if (protocolversion >= Protocol18Handler.MC_1_19_3_Version if (protocolversion >= Protocol18Handler.MC_1_19_3_Version
&& playerKeyPair != null) && playerKeyPair != null && isOnlineMode)
handler.SendPlayerSession(playerKeyPair); handler.SendPlayerSession(playerKeyPair);
if (protocolversion < Protocol18Handler.MC_1_19_3_Version) if (protocolversion < Protocol18Handler.MC_1_19_3_Version)

View file

@ -367,7 +367,7 @@ namespace MinecraftClient.Protocol.Handlers
SendPacket(PacketTypesOut.Pong, packetData); SendPacket(PacketTypesOut.Pong, packetData);
break; break;
case PacketTypesIn.JoinGame: case PacketTypesIn.JoinGame:
handler.OnGameJoined(); handler.OnGameJoined(isOnlineMode);
int playerEntityID = dataTypes.ReadNextInt(packetData); int playerEntityID = dataTypes.ReadNextInt(packetData);
handler.OnReceivePlayerEntityID(playerEntityID); handler.OnReceivePlayerEntityID(playerEntityID);
@ -3383,7 +3383,7 @@ namespace MinecraftClient.Protocol.Handlers
public bool SendPlayerSession(PlayerKeyPair? playerKeyPair) public bool SendPlayerSession(PlayerKeyPair? playerKeyPair)
{ {
if (playerKeyPair == null) if (playerKeyPair == null || !isOnlineMode)
return false; return false;
if (protocolVersion >= MC_1_19_3_Version) if (protocolVersion >= MC_1_19_3_Version)

View file

@ -80,7 +80,7 @@ namespace MinecraftClient.Protocol
/// <summary> /// <summary>
/// Called when a server was successfully joined /// Called when a server was successfully joined
/// </summary> /// </summary>
void OnGameJoined(); void OnGameJoined(bool isOnlineMode);
/// <summary> /// <summary>
/// Received chat/system message from the server /// Received chat/system message from the server

View file

@ -24,6 +24,12 @@ namespace MinecraftClient.Protocol.ProfileKey
if (!string.IsNullOrEmpty(sigV2)) if (!string.IsNullOrEmpty(sigV2))
SignatureV2 = Convert.FromBase64String(sigV2!); SignatureV2 = Convert.FromBase64String(sigV2!);
if (SignatureV2 == null || SignatureV2.Length == 0)
SignatureV2 = Signature;
if (Signature == null || Signature.Length == 0)
Signature = SignatureV2;
} }
public PublicKey(byte[] key, byte[] signature) public PublicKey(byte[] key, byte[] signature)