fix: Adds back razor/assistuo negotiations (#1089)

* [X] Adds Razor negotiations
* [X] Adds AssistUO "handshake" 🙄
This commit is contained in:
Kamron Batman 2022-06-25 01:47:45 -07:00 • committed by GitHub
parent bc2ed44440
commit 4f28e1e3c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 655 additions and 212 deletions

View file

@ -16,6 +16,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using Server.Assistants;
using CV = Server.ClientVersion;
namespace Server.Network;
@ -69,9 +70,32 @@ public static class IncomingAccountPackets
var flags = reader.ReadInt32();
reader.Seek(8, SeekOrigin.Current);
int prof = reader.ReadByte();
reader.Seek(15, SeekOrigin.Current);
int genderRace = reader.ReadByte();
int genderRace;
if (AssistantConfiguration.Enabled && AssistantConfiguration.Settings.DisallowedFeatures != AssistantFeatures.None)
{
var razorFeatures = (AssistantFeatures)reader.ReadUInt64();
var key = reader.ReadUInt64();
var authOk = razorFeatures == AssistantConfiguration.Settings.DisallowedFeatures &&
// Highly recommend a shard changes these here, in razor and redistribute the assistant.
(key & 0xFFFFFFFFFFFFFF00ul) == 0x0911832B04178300ul;
EventSink.InvokeAssistantAuth(new AssistantAuthEventArgs(state, state.Account, authOk));
if (!state.Running)
{
return;
}
genderRace = (int)(key & 0xFF);
}
else
{
reader.Seek(15, SeekOrigin.Current);
genderRace = reader.ReadByte();
}
var stats = new StatNameValue[]
{
@ -124,7 +148,7 @@ public static class IncomingAccountPackets
var info = state.CityInfo;
var a = state.Account;
if (info == null || a == null || cityIndex < 0 || cityIndex >= info.Length)
if (info == null || a == null || cityIndex >= info.Length)
{
state.Disconnect("Invalid city selected during character creation.");
return;
@ -230,7 +254,32 @@ public static class IncomingAccountPackets
var flags = reader.ReadInt32();
reader.Seek(24, SeekOrigin.Current);
if (AssistantConfiguration.Enabled && AssistantConfiguration.Settings.DisallowedFeatures != AssistantFeatures.None)
{
var razorFeatures = (AssistantFeatures)reader.ReadUInt64();
var key1 = reader.ReadUInt64();
var key2 = reader.ReadUInt64();
var authOk = razorFeatures == AssistantConfiguration.Settings.DisallowedFeatures &&
// Highly recommend a shard changes these here, in razor and redistribute the assistant.
key1 == 0x0911832B04178305ul && key2 == 0x2485071787061988ul;
EventSink.InvokeAssistantAuth(new AssistantAuthEventArgs(state, state.Account, authOk));
}
else
{
reader.Seek(22, SeekOrigin.Current);
if (reader.ReadUInt16() == 0xDEAD)
{
EventSink.InvokeAssistantAuth(new AssistantAuthEventArgs(state, state.Account, false));
}
}
if (!state.Running)
{
return;
}
var charSlot = reader.ReadInt32();
reader.Seek(4, SeekOrigin.Current); // var clientIP = reader.ReadInt32();

View file

@ -17,7 +17,9 @@ using System;
using System.IO;
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using Server.Accounting;
using Server.Assistants;
namespace Server.Network;
@ -54,12 +56,12 @@ public enum DeleteResultType
public static class OutgoingAccountPackets
{
/**
* Packet: 0x81
* Length: Up to 425 bytes
*
* Displays the list of characters during the login process.
* Note: Currently Unused
*/
* Packet: 0x81
* Length: Up to 425 bytes
*
* Displays the list of characters during the login process.
* Note: Currently Unused
*/
public static void SendChangeCharacter(this NetState ns, IAccount a)
{
if (ns == null || a == null)
@ -103,40 +105,40 @@ public static class OutgoingAccountPackets
}
/**
* Packet: 0xBD
* Length: 3 bytes
*
* Sends a requests for the client version
*/
* Packet: 0xBD
* Length: 3 bytes
*
* Sends a requests for the client version
*/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SendClientVersionRequest(this NetState ns) => ns?.Send(stackalloc byte[] { 0xBD, 0x00, 0x03 });
/**
* Packet: 0x85
* Length: 2 bytes
*
* Sends the result of a deletion request
*/
* Packet: 0x85
* Length: 2 bytes
*
* Sends the result of a deletion request
*/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SendCharacterDeleteResult(this NetState ns, DeleteResultType res) =>
ns?.Send(stackalloc byte[] { 0x85, (byte)res });
/**
* Packet: 0x53
* Length: 2 bytes
*
* Sends a PopupMessage with a predetermined message
*/
* Packet: 0x53
* Length: 2 bytes
*
* Sends a PopupMessage with a predetermined message
*/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SendPopupMessage(this NetState ns, PMMessage msg) =>
ns?.Send(stackalloc byte[] { 0x53, (byte)msg });
/**
* Packet: 0xB9
* Length: 3 or 5 bytes
*
* Sends support features based on the client version
*/
* Packet: 0xB9
* Length: 3 or 5 bytes
*
* Sends support features based on the client version
*/
public static void SendSupportedFeature(this NetState ns)
{
if (ns.CannotSendPackets())
@ -182,11 +184,11 @@ public static class OutgoingAccountPackets
}
/**
* Packet: 0x1B
* Length: 37 bytes
*
* Sends login confirmation
*/
* Packet: 0x1B
* Length: 37 bytes
*
* Sends login confirmation
*/
public static void SendLoginConfirmation(this NetState ns, Mobile m)
{
if (ns.CannotSendPackets())
@ -223,22 +225,22 @@ public static class OutgoingAccountPackets
}
/**
* Packet: 0x55
* Length: 1 byte
*
* Sends login completion
*/
* Packet: 0x55
* Length: 1 byte
*
* Sends login completion
*/
public static void SendLoginComplete(this NetState ns)
{
ns?.Send(stackalloc byte[] { 0x55 });
}
/**
* Packet: 0x86
* Length: Up to 424 bytes
*
* Sends updated character list
*/
* Packet: 0x86
* Length: Up to 424 bytes
*
* Sends updated character list
*/
public static void SendCharacterListUpdate(this NetState ns, IAccount a)
{
if (ns == null || a == null)
@ -284,12 +286,14 @@ public static class OutgoingAccountPackets
ns.Send(writer.Span);
}
private static MD5 _md5Provider;
/**
* Packet: 0xA9
* Length: 1410 or more bytes
*
* Sends list of characters and starting cities.
*/
* Packet: 0xA9
* Length: 1410 or more bytes
*
* Sends list of characters and starting cities.
*/
public static void SendCharacterList(this NetState ns)
{
var acct = ns?.Account;
@ -315,14 +319,25 @@ public static class OutgoingAccountPackets
}
}
var count = Math.Max(Math.Max(highSlot + 1, acct.Limit), 5);
// Supported values are 1, 5, 6, or 7
var count = Math.Max(highSlot + 1, acct.Limit);
if (count is not 1 and < 5)
{
count = 5;
}
var length = (client70130 ?
11 + (textLength * 2 + 25) * cityInfo.Length :
9 + (textLength * 2 + 1) * cityInfo.Length) + count * 60;
var writer = new SpanWriter(stackalloc byte[length]);
writer.Write((byte)0xA9); // Packet ID
writer.Write((ushort)length);
writer.Write((byte)count);
writer.Write((byte)count); // TODO: It is probably more proper to use count.
var enforceRazor = AssistantConfiguration.Enabled &&
AssistantConfiguration.Settings.DisallowedFeatures != AssistantFeatures.None;
Span<byte> hashBuffer = enforceRazor ? stackalloc byte[16] : null;
for (int i = 0; i < count; i++)
{
@ -330,12 +345,41 @@ public static class OutgoingAccountPackets
if (m == null)
{
writer.Clear(60);
writer.Clear(30);
}
else
{
var name = (m.RawName?.Trim()).DefaultIfNullOrEmpty("-no name-");
writer.WriteAscii(name, 30);
}
if (enforceRazor)
{
writer.Write((byte)0);
var pos = writer.Position;
if (i == 0)
{
writer.Write((ulong)AssistantConfiguration.Settings.DisallowedFeatures);
}
if (count > 1 && i == 2 || count == 1 && i == 0)
{
_md5Provider ??= MD5.Create();
if (_md5Provider.TryComputeHash(writer.Span, hashBuffer, out var bytesWritten) && bytesWritten == 16)
{
writer.Write(hashBuffer);
}
}
var remaining = 28 - pos;
Utility.RandomBytes(writer.RawBuffer.Slice(writer.Position, remaining));
writer.Seek(remaining, SeekOrigin.Current);
writer.Write((byte)0);
}
else
{
writer.Clear(30); // password
}
}
@ -387,21 +431,21 @@ public static class OutgoingAccountPackets
}
/**
* Packet: 0x82
* Length: 2 bytes
*
* Sends a reason for rejecting the login
*/
* Packet: 0x82
* Length: 2 bytes
*
* Sends a reason for rejecting the login
*/
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void SendAccountLoginRejected(this NetState ns, ALRReason reason) =>
ns?.Send(stackalloc byte[] { 0x82, (byte)reason });
/**
* Packet: 0xA8
* Length: 6 + 40 bytes per server listing
*
* Sends login acknowledge with server listing
*/
* Packet: 0xA8
* Length: 6 + 40 bytes per server listing
*
* Sends login acknowledge with server listing
*/
public static void SendAccountLoginAck(this NetState ns)
{
if (ns.CannotSendPackets())
@ -433,11 +477,11 @@ public static class OutgoingAccountPackets
}
/**
* Packet: 0x8C
* Length: 11 bytes
*
* Sends acknowledge play server
*/
* Packet: 0x8C
* Length: 11 bytes
*
* Sends acknowledge play server
*/
public static void SendPlayServerAck(this NetState ns, ServerInfo si, int authId)
{
if (ns.CannotSendPackets())