Skip to content

Commit 947f25a

Browse files
committed
VisualResponseManager (heavy WIP)
1 parent a2c0023 commit 947f25a

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

src/Dust765/Dust765/VisualResponseManager.cs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
using ClassicUO.Game.GameObjects;
3232
using ClassicUO.Game.Managers;
3333
using ClassicUO.Renderer;
34+
using ClassicUO.IO;
3435
using ClassicUO.IO.Resources;
36+
using ClassicUO.Utility;
3537
using ClassicUO.Utility.Collections;
3638

3739
using Microsoft.Xna.Framework;
@@ -239,5 +241,128 @@ public void OnCliloc(uint cliloc)
239241
502637, //You feel yourself resisting magical energy.
240242
502638 //You feel yourself resisting magical energy.
241243
};
244+
//ON PLUGIN SEND
245+
public void OnPluginSendLog(Span<byte> buffer, int length)
246+
{
247+
if (!IsEnabled)
248+
{
249+
return;
250+
}
251+
252+
//NETCLIENT LOGPACKET
253+
Span<char> span = stackalloc char[256];
254+
ValueStringBuilder output = new ValueStringBuilder(span);
255+
{
256+
int off = sizeof(ulong) + 2;
257+
258+
output.Append(' ', off);
259+
output.Append(string.Format("Ticks: {0} | {1} | ID: {2:X2} Length: {3}\n", Time.Ticks, ("Assistant -> Server"), buffer[0], length));
260+
261+
output.Append(' ', off);
262+
output.Append("0 1 2 3 4 5 6 7 8 9 A B C D E F\n");
263+
264+
output.Append(' ', off);
265+
output.Append("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --\n");
266+
267+
ulong address = 0;
268+
269+
for (int i = 0; i < length; i += 16, address += 16)
270+
{
271+
output.Append($"{address:X8}");
272+
273+
for (int j = 0; j < 16; ++j)
274+
{
275+
if ((j % 8) == 0)
276+
{
277+
output.Append(" ");
278+
}
279+
280+
if (i + j < length)
281+
{
282+
output.Append($" {buffer[i + j]:X2}");
283+
}
284+
else
285+
{
286+
output.Append(" ");
287+
}
288+
}
289+
290+
output.Append(" ");
291+
292+
for (int j = 0; j < 16 && i + j < length; ++j)
293+
{
294+
byte c = buffer[i + j];
295+
296+
if (c >= 0x20 && c < 0x80)
297+
{
298+
output.Append((char) c);
299+
}
300+
else
301+
{
302+
output.Append('.');
303+
}
304+
}
305+
306+
output.Append('\n');
307+
}
308+
output.Append('\n');
309+
output.Append('\n');
310+
311+
Console.WriteLine(output.ToString());
312+
313+
output.Dispose();
314+
}
315+
}
316+
public void OnPluginSend(byte[] data, int length)
317+
{
318+
if (!IsEnabled)
319+
{
320+
return;
321+
}
322+
323+
switch (data[0])
324+
{
325+
case 0x06:
326+
327+
StackDataReader buffer = new StackDataReader(data.AsSpan(0, length));
328+
329+
//skip first
330+
//byte type = buffer.ReadUInt8();
331+
int offset = 1;
332+
buffer.Seek(offset);
333+
334+
//read serial
335+
uint serial = buffer.ReadUInt32BE();
336+
//Console.WriteLine("serial: " + serial.ToHex());
337+
338+
if (SerialHelper.IsItem(serial))
339+
{
340+
Item item = World.Items.Get(serial);
341+
342+
//failsafe
343+
if (item == null)
344+
{
345+
break;
346+
}
347+
348+
//Console.WriteLine("item.Graphic" + item.Graphic);
349+
//Console.WriteLine("item.Name" + item.Name);
350+
351+
//curepot = 0x0F07
352+
//healpot = 0x0F0C
353+
//refreshpot = 0xF0B
354+
//str = 0xF09
355+
//agi = 0xF08
356+
357+
if (item.Graphic == 0x0F07 || item.Graphic == 0x0F0C || item.Graphic == 0xF0B || item.Graphic == 0xF09 || item.Graphic == 0xF08)
358+
{
359+
TriggerByPotMacro(item.Graphic);
360+
}
361+
}
362+
363+
break;
364+
}
365+
}
366+
242367
}
243368
}

src/Network/Plugin.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ private static bool OnPluginSend(ref byte[] data, ref int length)
653653
if (NetClient.LoginSocket.IsDisposed && NetClient.Socket.IsConnected)
654654
{
655655
NetClient.Socket.Send(data, length, true);
656+
657+
// ## BEGIN - END ## // VISUALRESPONSEMANAGER
658+
World.VisualResponseManager.OnPluginSendLog(data, length);
659+
World.VisualResponseManager.OnPluginSend(data, length);
660+
// ## BEGIN - END ## // VISUALRESPONSEMANAGER
656661
}
657662
else if (NetClient.Socket.IsDisposed && NetClient.LoginSocket.IsConnected)
658663
{

0 commit comments

Comments
 (0)