Skip to content

Commit 7cbb88a

Browse files
committed
Fixing regressions
1 parent 665d567 commit 7cbb88a

3 files changed

Lines changed: 44 additions & 42 deletions

File tree

src/Atlasd/Battlenet/Protocols/Game/ChatEvent.cs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -180,92 +180,94 @@ public byte[] ToByteArray(ProtocolType.Types protocolType)
180180
Buffer.BlockCopy(Text, 0, product, 0, Math.Min(4, Text.Length));
181181
Array.Reverse(product); // "RATS" becomes "STAR", etc.
182182

183-
using var m = new MemoryStream(); // Expandable buffer
184-
using var w = new BinaryWriter(m);
183+
byte[] username = Encoding.UTF8.GetBytes(Username);
184+
185+
using var m = new MemoryStream(0xFFFF);
186+
using var w = new System.IO.BinaryWriter(m);
185187

186-
w.Write($"{1000 + EventId} ");
188+
w.Write(Encoding.UTF8.GetBytes($"{1000 + EventId} "));
187189

188190
switch (EventId)
189191
{
190192
case EventIds.EID_USERSHOW:
191193
case EventIds.EID_USERJOIN:
192194
case EventIds.EID_USERUPDATE:
193195
{
194-
w.Write(EventId == EventIds.EID_USERJOIN ? "JOIN " : "USER ");
195-
w.Write(Username);
196-
w.Write($" {Flags:X4} [");
196+
w.Write(Encoding.UTF8.GetBytes(EventId == EventIds.EID_USERJOIN ? "JOIN " : "USER "));
197+
w.Write(username);
198+
w.Write(Encoding.UTF8.GetBytes($" {Flags:X4} ["));
197199
w.Write(product);
198-
w.Write(']');
200+
w.Write((byte)']');
199201
break;
200202
}
201203
case EventIds.EID_USERLEAVE:
202204
{
203-
w.Write("LEAVE ");
204-
w.Write(Username);
205-
w.Write($" {Flags:X4}");
205+
w.Write(Encoding.UTF8.GetBytes("LEAVE "));
206+
w.Write(username);
207+
w.Write(Encoding.UTF8.GetBytes($" {Flags:X4}"));
206208
break;
207209
}
208210
case EventIds.EID_WHISPERFROM:
209211
case EventIds.EID_WHISPERTO:
210212
{
211-
w.Write("WHISPER ");
212-
w.Write(Username);
213-
w.Write($" {Flags:X4} \"");
213+
w.Write(Encoding.UTF8.GetBytes("WHISPER "));
214+
w.Write(username);
215+
w.Write(Encoding.UTF8.GetBytes($" {Flags:X4} \""));
214216
w.Write(Text);
215-
w.Write('"');
217+
w.Write((byte)'"');
216218
break;
217219
}
218220
case EventIds.EID_TALK:
219221
case EventIds.EID_EMOTE:
220222
{
221-
w.Write(EventId == EventIds.EID_EMOTE ? "EMOTE " : "TALK ");
222-
w.Write(Username);
223-
w.Write($" {Flags:X4} \"");
223+
w.Write(Encoding.UTF8.GetBytes(EventId == EventIds.EID_EMOTE ? "EMOTE " : "TALK "));
224+
w.Write(username);
225+
w.Write(Encoding.UTF8.GetBytes($" {Flags:X4} \""));
224226
w.Write(Text);
225-
w.Write('"');
227+
w.Write((byte)'"');
226228
break;
227229
}
228230
case EventIds.EID_BROADCAST:
229231
{
230-
w.Write("BROADCAST \"");
232+
w.Write(Encoding.UTF8.GetBytes("BROADCAST \""));
231233
w.Write(Text);
232-
w.Write('"');
234+
w.Write((byte)'"');
233235
break;
234236
}
235237
case EventIds.EID_CHANNELJOIN:
236238
{
237-
w.Write("CHANNEL \"");
239+
w.Write(Encoding.UTF8.GetBytes("CHANNEL \""));
238240
w.Write(Text);
239-
w.Write('"');
241+
w.Write((byte)'"');
240242
break;
241243
}
242244
case EventIds.EID_INFO:
243245
{
244-
w.Write("INFO \"");
246+
w.Write(Encoding.UTF8.GetBytes("INFO \""));
245247
w.Write(Text);
246-
w.Write('"');
248+
w.Write((byte)'"');
247249
break;
248250
}
249251
case EventIds.EID_ERROR:
250252
{
251-
w.Write("ERROR \"");
253+
w.Write(Encoding.UTF8.GetBytes("ERROR \""));
252254
w.Write(Text);
253-
w.Write('"');
255+
w.Write((byte)'"');
254256
break;
255257
}
256258
default:
257259
{
258-
w.Write("UNKNOWN ");
259-
w.Write(Username);
260-
w.Write($" {Flags:X4} \"");
260+
w.Write(Encoding.UTF8.GetBytes("UNKNOWN "));
261+
w.Write(username);
262+
w.Write(Encoding.UTF8.GetBytes($" {Flags:X4} \""));
261263
w.Write(Text);
262-
w.Write('"');
264+
w.Write((byte)'"');
263265
break;
264266
}
265267
}
266268

267-
w.Write(Battlenet.Common.NewLine);
268-
return m.GetBuffer();
269+
w.Write(Encoding.UTF8.GetBytes(Battlenet.Common.NewLine));
270+
return m.GetBuffer()[0..(int)w.BaseStream.Length];
269271
}
270272
default:
271273
throw new ProtocolNotSupportedException(protocolType, null, $"Unsupported protocol type [0x{(byte)protocolType:X2}]");

src/Atlasd/Battlenet/Protocols/Game/Messages/SID_ENTERCHAT.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ public override bool Invoke(MessageContext context)
140140
var username = r.ReadByteString();
141141
var statstring = r.ReadByteString();
142142

143-
using var m = new MemoryStream();
144-
using var w = new BinaryWriter(m);
145-
w.Write($"{2000 + Id} NAME ");
143+
using var m = new MemoryStream(0xFFFF);
144+
using var w = new System.IO.BinaryWriter(m);
145+
w.Write(Encoding.UTF8.GetBytes($"{2000 + Id} NAME "));
146146
w.Write(username);
147-
w.Write(Battlenet.Common.NewLine);
148-
return m.GetBuffer();
147+
w.Write(Encoding.UTF8.GetBytes(Battlenet.Common.NewLine));
148+
return m.GetBuffer()[0..(int)w.BaseStream.Length];
149149
}
150150
else
151151
{

src/Atlasd/Battlenet/Protocols/Game/Messages/SID_MESSAGEBOX.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public override bool Invoke(MessageContext context)
5959
var caption = r.ReadByteString();
6060

6161
using var m = new MemoryStream();
62-
using var w = new BinaryWriter(m);
63-
w.Write($"{2000 + Id} MESSAGEBOX \"");
62+
using var w = new System.IO.BinaryWriter(m);
63+
w.Write(Encoding.UTF8.GetBytes($"{2000 + Id} MESSAGEBOX \""));
6464
w.Write(text);
65-
w.Write('"');
66-
w.Write(Battlenet.Common.NewLine);
67-
return m.GetBuffer();
65+
w.Write((byte)'"');
66+
w.Write(Encoding.UTF8.GetBytes(Battlenet.Common.NewLine));
67+
return m.GetBuffer()[0..(int)w.BaseStream.Length];
6868
}
6969
else
7070
{

0 commit comments

Comments
 (0)