From 162c6b751302cd0a9c8187c686501bbf225ed60d Mon Sep 17 00:00:00 2001 From: Andrea Angelini Date: Fri, 11 Dec 2020 08:52:53 +0100 Subject: [PATCH 01/10] + alignment with latest plugin header --- Razor.sln | 5 +- Razor/Client/ClassicUO.cs | 210 ++++++++++++++++++++++++++------------ 2 files changed, 150 insertions(+), 65 deletions(-) diff --git a/Razor.sln b/Razor.sln index 7058756d..2bc50467 100644 --- a/Razor.sln +++ b/Razor.sln @@ -36,9 +36,10 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B24E4FB1-4936-4544-9E88-F3FF9B04FDBA}.Debug|Any CPU.ActiveCfg = Debug|x86 - {B24E4FB1-4936-4544-9E88-F3FF9B04FDBA}.Debug|Any CPU.Build.0 = Debug|x86 + {B24E4FB1-4936-4544-9E88-F3FF9B04FDBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B24E4FB1-4936-4544-9E88-F3FF9B04FDBA}.Debug|Any CPU.Build.0 = Debug|Any CPU {B24E4FB1-4936-4544-9E88-F3FF9B04FDBA}.Debug|x64.ActiveCfg = Debug|x86 + {B24E4FB1-4936-4544-9E88-F3FF9B04FDBA}.Debug|x64.Build.0 = Debug|x86 {B24E4FB1-4936-4544-9E88-F3FF9B04FDBA}.Debug|x86.ActiveCfg = Debug|x86 {B24E4FB1-4936-4544-9E88-F3FF9B04FDBA}.Debug|x86.Build.0 = Debug|x86 {B24E4FB1-4936-4544-9E88-F3FF9B04FDBA}.Release|Any CPU.ActiveCfg = Release|x86 diff --git a/Razor/Client/ClassicUO.cs b/Razor/Client/ClassicUO.cs index 98f577f8..4ad726c8 100644 --- a/Razor/Client/ClassicUO.cs +++ b/Razor/Client/ClassicUO.cs @@ -19,7 +19,6 @@ #endregion using Assistant.UI; -using CUO_API; using System; using System.Diagnostics; using System.IO; @@ -32,11 +31,59 @@ using Assistant.Core; using Assistant.Scripts; +namespace CUO_API +{ + [return: MarshalAs(UnmanagedType.I1)] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate bool OnPacketSendRecv_new_intptr_r(IntPtr data, ref int length); + + [return: MarshalAs(UnmanagedType.I1)] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate bool OnPacketSendRecv_new(byte[] data, ref int length); + + + public ref struct PluginHeader_R + { + public int ClientVersion; + public IntPtr HWND; + public IntPtr OnRecv; + public IntPtr OnSend; + public IntPtr OnHotkeyPressed; + public IntPtr OnMouse; + public IntPtr OnPlayerPositionChanged; + public IntPtr OnClientClosing; + public IntPtr OnInitialize; + public IntPtr OnConnected; + public IntPtr OnDisconnected; + public IntPtr OnFocusGained; + public IntPtr OnFocusLost; + public IntPtr GetUOFilePath; + public IntPtr Recv; + public IntPtr Send; + public IntPtr GetPacketLength; + public IntPtr GetPlayerPosition; + public IntPtr CastSpell; + public IntPtr GetStaticImage; + public IntPtr Tick; + public IntPtr RequestMove; + public IntPtr SetTitle; + + public IntPtr OnRecv_new, OnSend_new, Recv_new, Send_new; + + public IntPtr OnDrawCmdList; + public IntPtr SDL_Window; + public IntPtr OnWndProc; + public IntPtr GetStaticData; + public IntPtr GetTileData; + public IntPtr GetCliloc; + } +} + namespace Assistant { public partial class Engine { - public static unsafe void Install(PluginHeader* plugin) + public static unsafe void Install(void* ptr) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); @@ -64,7 +111,7 @@ public static unsafe void Install(PluginHeader* plugin) Client.Init(false); - if (!(Client.Instance as ClassicUOClient).Install(plugin)) + if (!(Client.Instance as ClassicUOClient).Install(ptr)) { Process.GetCurrentProcess().Kill(); return; @@ -72,7 +119,7 @@ public static unsafe void Install(PluginHeader* plugin) // load ultimasdk before or the Language.Load will throw the cliloc not found warning every time you run cuo string clientPath = - ((OnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(plugin->GetUOFilePath, typeof(OnGetUOFilePath)) + ((CUO_API.OnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(((CUO_API.PluginHeader_R*) ptr)->GetUOFilePath, typeof(CUO_API.OnGetUOFilePath)) )(); // just replicating the static .ctor @@ -136,26 +183,27 @@ public class ClassicUOClient : Client private bool m_ClientRunning = false; private string m_ClientVersion; - private static OnPacketSendRecv _sendToClient, _sendToServer, _recv, _send; - private static OnGetPacketLength _getPacketLength; - private static OnGetPlayerPosition _getPlayerPosition; - private static OnCastSpell _castSpell; - private static OnGetStaticImage _getStaticImage; - private static OnTick _tick; - private static RequestMove _requestMove; - private static OnSetTitle _setTitle; - private static OnGetUOFilePath _uoFilePath; - - - private static OnHotkey _onHotkeyPressed; - private static OnMouse _onMouse; - private static OnUpdatePlayerPosition _onUpdatePlayerPosition; - private static OnClientClose _onClientClose; - private static OnInitialize _onInitialize; - private static OnConnected _onConnected; - private static OnDisconnected _onDisconnected; - private static OnFocusGained _onFocusGained; - private static OnFocusLost _onFocusLost; + private static CUO_API.OnPacketSendRecv_new_intptr_r _sendToClient, _sendToServer; + private static CUO_API.OnPacketSendRecv_new _recv, _send; + private static CUO_API.OnGetPacketLength _getPacketLength; + private static CUO_API.OnGetPlayerPosition _getPlayerPosition; + private static CUO_API.OnCastSpell _castSpell; + private static CUO_API.OnGetStaticImage _getStaticImage; + private static CUO_API.OnTick _tick; + private static CUO_API.RequestMove _requestMove; + private static CUO_API.OnSetTitle _setTitle; + private static CUO_API.OnGetUOFilePath _uoFilePath; + + + private static CUO_API.OnHotkey _onHotkeyPressed; + private static CUO_API.OnMouse _onMouse; + private static CUO_API.OnUpdatePlayerPosition _onUpdatePlayerPosition; + private static CUO_API.OnClientClose _onClientClose; + private static CUO_API.OnInitialize _onInitialize; + private static CUO_API.OnConnected _onConnected; + private static CUO_API.OnDisconnected _onDisconnected; + private static CUO_API.OnFocusGained _onFocusGained; + private static CUO_API.OnFocusLost _onFocusLost; private IntPtr m_ClientWindow; public override void SetMapWndHandle(Form mapWnd) @@ -187,27 +235,29 @@ public override Loader_Error LaunchClient(string client) public override bool ServerEncrypted { get; set; } - public unsafe bool Install(PluginHeader* header) + public unsafe bool Install(void* ptr) { + CUO_API.PluginHeader_R* header = (CUO_API.PluginHeader_R*) ptr; + _sendToClient = - (OnPacketSendRecv) Marshal.GetDelegateForFunctionPointer(header->Recv, typeof(OnPacketSendRecv)); + (CUO_API.OnPacketSendRecv_new_intptr_r) Marshal.GetDelegateForFunctionPointer(header->Recv_new, typeof(CUO_API.OnPacketSendRecv_new_intptr_r)); _sendToServer = - (OnPacketSendRecv) Marshal.GetDelegateForFunctionPointer(header->Send, typeof(OnPacketSendRecv)); + (CUO_API.OnPacketSendRecv_new_intptr_r) Marshal.GetDelegateForFunctionPointer(header->Send_new, typeof(CUO_API.OnPacketSendRecv_new_intptr_r)); _getPacketLength = - (OnGetPacketLength) Marshal.GetDelegateForFunctionPointer(header->GetPacketLength, - typeof(OnGetPacketLength)); + (CUO_API.OnGetPacketLength) Marshal.GetDelegateForFunctionPointer(header->GetPacketLength, + typeof(CUO_API.OnGetPacketLength)); _getPlayerPosition = - (OnGetPlayerPosition) Marshal.GetDelegateForFunctionPointer(header->GetPlayerPosition, - typeof(OnGetPlayerPosition)); - _castSpell = (OnCastSpell) Marshal.GetDelegateForFunctionPointer(header->CastSpell, typeof(OnCastSpell)); + (CUO_API.OnGetPlayerPosition) Marshal.GetDelegateForFunctionPointer(header->GetPlayerPosition, + typeof(CUO_API.OnGetPlayerPosition)); + _castSpell = (CUO_API.OnCastSpell) Marshal.GetDelegateForFunctionPointer(header->CastSpell, typeof(CUO_API.OnCastSpell)); _getStaticImage = - (OnGetStaticImage) Marshal.GetDelegateForFunctionPointer(header->GetStaticImage, - typeof(OnGetStaticImage)); + (CUO_API.OnGetStaticImage) Marshal.GetDelegateForFunctionPointer(header->GetStaticImage, + typeof(CUO_API.OnGetStaticImage)); _requestMove = - (RequestMove) Marshal.GetDelegateForFunctionPointer(header->RequestMove, typeof(RequestMove)); - _setTitle = (OnSetTitle) Marshal.GetDelegateForFunctionPointer(header->SetTitle, typeof(OnSetTitle)); + (CUO_API.RequestMove) Marshal.GetDelegateForFunctionPointer(header->RequestMove, typeof(CUO_API.RequestMove)); + _setTitle = (CUO_API.OnSetTitle) Marshal.GetDelegateForFunctionPointer(header->SetTitle, typeof(CUO_API.OnSetTitle)); _uoFilePath = - (OnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(header->GetUOFilePath, typeof(OnGetUOFilePath)); + (CUO_API.OnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(header->GetUOFilePath, typeof(CUO_API.OnGetUOFilePath)); m_ClientVersion = new Version((byte) (header->ClientVersion >> 24), (byte) (header->ClientVersion >> 16), (byte) (header->ClientVersion >> 8), (byte) header->ClientVersion).ToString(); m_ClientRunning = true; @@ -225,8 +275,8 @@ public unsafe bool Install(PluginHeader* header) _onFocusGained = OnFocusGained; _onFocusLost = OnFocusLost; header->Tick = Marshal.GetFunctionPointerForDelegate(_tick); - header->OnRecv = Marshal.GetFunctionPointerForDelegate(_recv); - header->OnSend = Marshal.GetFunctionPointerForDelegate(_send); + header->OnRecv_new = Marshal.GetFunctionPointerForDelegate(_recv); + header->OnSend_new = Marshal.GetFunctionPointerForDelegate(_send); header->OnHotkeyPressed = Marshal.GetFunctionPointerForDelegate(_onHotkeyPressed); header->OnMouse = Marshal.GetFunctionPointerForDelegate(_onMouse); header->OnPlayerPositionChanged = Marshal.GetFunctionPointerForDelegate(_onUpdatePlayerPosition); @@ -256,13 +306,13 @@ private void OnPlayerPositionChanged(int x, int y, int z) World.Player.Position = new Point3D(x, y, z); } - private unsafe bool OnRecv(ref byte[] data, ref int length) + private unsafe bool OnRecv(byte[] buffer, ref int length) { m_In += (uint) length; - fixed (byte* ptr = data) + fixed (byte* ptr = buffer) { bool result = true; - byte id = data[0]; + byte id = ptr[0]; PacketReader reader = null; Packet packet = null; @@ -277,29 +327,41 @@ private unsafe bool OnRecv(ref byte[] data, ref int length) if (isFilter) { + byte[] data = new byte[length]; + + for (int i = 0; i < length; ++i) + { + data[i] = ptr[i]; + } + packet = new Packet(data, length, PacketsTable.IsDynLength(id)); - result = !PacketHandler.OnServerPacket(id, reader, packet); + result = !PacketHandler.OnClientPacket(id, reader, packet); data = packet.Compile(); - length = (int) packet.Length; + length = (int)packet.Length; + + for (int i = 0; i < length; ++i) + { + data[i] = ptr[i]; + } } if (Packet.Logging) { - Packet.Log(PacketPath.ServerToClient, ptr, data.Length, !result); + Packet.Log(PacketPath.ServerToClient, ptr, length, !result); } return result; } } - private unsafe bool OnSend(ref byte[] data, ref int length) + private unsafe bool OnSend(byte[] buffer, ref int length) { m_Out += (uint) length; - fixed (byte* ptr = data) + fixed (byte * ptr = buffer) { bool result = true; - byte id = data[0]; + byte id = ptr[0]; PacketReader reader = null; Packet packet = null; @@ -313,16 +375,28 @@ private unsafe bool OnSend(ref byte[] data, ref int length) } else if (isFilter) { + byte[] data = new byte[length]; + + for (int i = 0; i < length; ++i) + { + data[i] = ptr[i]; + } + packet = new Packet(data, length, PacketsTable.IsDynLength(id)); result = !PacketHandler.OnClientPacket(id, reader, packet); data = packet.Compile(); length = (int) packet.Length; + + for (int i = 0; i < length; ++i) + { + data[i] = ptr[i]; + } } if (Packet.Logging) { - Packet.Log(PacketPath.ClientToServer, ptr, data.Length, !result); + Packet.Log(PacketPath.ClientToServer, ptr, length, !result); } return result; @@ -518,11 +592,15 @@ public override bool OnCopyData(IntPtr wparam, IntPtr lparam) return false; } - public override void SendToServer(Packet p) + public override unsafe void SendToServer(Packet p) { byte[] data = p.Compile(); int length = (int) p.Length; - _sendToServer(ref data, ref length); + + fixed (byte* ptr = data) + { + _sendToServer((IntPtr) ptr, ref length); + } } public override void SendToServer(PacketReader pr) @@ -530,17 +608,23 @@ public override void SendToServer(PacketReader pr) SendToServer(MakePacketFrom(pr)); } - public override void SendToClient(Packet p) + public override unsafe void SendToClient(Packet p) { byte[] data = p.Compile(); int length = (int) p.Length; - _sendToClient(ref data, ref length); + fixed (byte* ptr = data) + { + _sendToClient((IntPtr)ptr, ref length); + } } - public override void SendPacketToClient(byte[] packet, int length) + public override unsafe void SendPacketToClient(byte[] packet, int length) { - _sendToClient(ref packet, ref length); + fixed (byte* ptr = packet) + { + _sendToClient((IntPtr) ptr, ref length); + } } public override unsafe void ForceSendToClient(Packet p) @@ -548,11 +632,11 @@ public override unsafe void ForceSendToClient(Packet p) byte[] data = p.Compile(); int length = (int) p.Length; - _sendToClient(ref data, ref length); - - if (Packet.Logging) + fixed (byte* ptr = data) { - fixed (byte* ptr = data) + _sendToClient((IntPtr) ptr, ref length); + + if (Packet.Logging) { Packet.Log(PacketPath.RazorToClient, ptr, data.Length); } @@ -564,11 +648,11 @@ public override unsafe void ForceSendToServer(Packet p) byte[] data = p.Compile(); int length = (int) p.Length; - _sendToServer(ref data, ref length); - - if (Packet.Logging) + fixed (byte* ptr = data) { - fixed (byte* ptr = data) + _sendToServer((IntPtr) ptr, ref length); + + if (Packet.Logging) { Packet.Log(PacketPath.RazorToServer, ptr, data.Length); } From ce8bdaa6adeff4649881da97ed19663cd87df1e2 Mon Sep 17 00:00:00 2001 From: Andrea Angelini Date: Fri, 11 Dec 2020 22:30:40 +0100 Subject: [PATCH 02/10] + revert back some things --- Razor/Client/ClassicUO.cs | 90 ++++++++------------------------------- 1 file changed, 17 insertions(+), 73 deletions(-) diff --git a/Razor/Client/ClassicUO.cs b/Razor/Client/ClassicUO.cs index 4ad726c8..492ed205 100644 --- a/Razor/Client/ClassicUO.cs +++ b/Razor/Client/ClassicUO.cs @@ -30,54 +30,7 @@ using System.Windows.Forms; using Assistant.Core; using Assistant.Scripts; - -namespace CUO_API -{ - [return: MarshalAs(UnmanagedType.I1)] - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool OnPacketSendRecv_new_intptr_r(IntPtr data, ref int length); - - [return: MarshalAs(UnmanagedType.I1)] - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool OnPacketSendRecv_new(byte[] data, ref int length); - - - public ref struct PluginHeader_R - { - public int ClientVersion; - public IntPtr HWND; - public IntPtr OnRecv; - public IntPtr OnSend; - public IntPtr OnHotkeyPressed; - public IntPtr OnMouse; - public IntPtr OnPlayerPositionChanged; - public IntPtr OnClientClosing; - public IntPtr OnInitialize; - public IntPtr OnConnected; - public IntPtr OnDisconnected; - public IntPtr OnFocusGained; - public IntPtr OnFocusLost; - public IntPtr GetUOFilePath; - public IntPtr Recv; - public IntPtr Send; - public IntPtr GetPacketLength; - public IntPtr GetPlayerPosition; - public IntPtr CastSpell; - public IntPtr GetStaticImage; - public IntPtr Tick; - public IntPtr RequestMove; - public IntPtr SetTitle; - - public IntPtr OnRecv_new, OnSend_new, Recv_new, Send_new; - - public IntPtr OnDrawCmdList; - public IntPtr SDL_Window; - public IntPtr OnWndProc; - public IntPtr GetStaticData; - public IntPtr GetTileData; - public IntPtr GetCliloc; - } -} +using CUO_API; namespace Assistant { @@ -119,7 +72,7 @@ public static unsafe void Install(void* ptr) // load ultimasdk before or the Language.Load will throw the cliloc not found warning every time you run cuo string clientPath = - ((CUO_API.OnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(((CUO_API.PluginHeader_R*) ptr)->GetUOFilePath, typeof(CUO_API.OnGetUOFilePath)) + ((CUO_API.OnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(((PluginHeader*) ptr)->GetUOFilePath, typeof(OnGetUOFilePath)) )(); // just replicating the static .ctor @@ -183,8 +136,8 @@ public class ClassicUOClient : Client private bool m_ClientRunning = false; private string m_ClientVersion; - private static CUO_API.OnPacketSendRecv_new_intptr_r _sendToClient, _sendToServer; - private static CUO_API.OnPacketSendRecv_new _recv, _send; + private static CUO_API.OnPacketSendRecv _sendToClient, _sendToServer; + private static CUO_API.OnPacketSendRecv _recv, _send; private static CUO_API.OnGetPacketLength _getPacketLength; private static CUO_API.OnGetPlayerPosition _getPlayerPosition; private static CUO_API.OnCastSpell _castSpell; @@ -237,12 +190,12 @@ public override Loader_Error LaunchClient(string client) public unsafe bool Install(void* ptr) { - CUO_API.PluginHeader_R* header = (CUO_API.PluginHeader_R*) ptr; + CUO_API.PluginHeader* header = (CUO_API.PluginHeader*) ptr; _sendToClient = - (CUO_API.OnPacketSendRecv_new_intptr_r) Marshal.GetDelegateForFunctionPointer(header->Recv_new, typeof(CUO_API.OnPacketSendRecv_new_intptr_r)); + (CUO_API.OnPacketSendRecv) Marshal.GetDelegateForFunctionPointer(header->Recv, typeof(CUO_API.OnPacketSendRecv)); _sendToServer = - (CUO_API.OnPacketSendRecv_new_intptr_r) Marshal.GetDelegateForFunctionPointer(header->Send_new, typeof(CUO_API.OnPacketSendRecv_new_intptr_r)); + (CUO_API.OnPacketSendRecv) Marshal.GetDelegateForFunctionPointer(header->Send, typeof(CUO_API.OnPacketSendRecv)); _getPacketLength = (CUO_API.OnGetPacketLength) Marshal.GetDelegateForFunctionPointer(header->GetPacketLength, typeof(CUO_API.OnGetPacketLength)); @@ -275,8 +228,8 @@ public unsafe bool Install(void* ptr) _onFocusGained = OnFocusGained; _onFocusLost = OnFocusLost; header->Tick = Marshal.GetFunctionPointerForDelegate(_tick); - header->OnRecv_new = Marshal.GetFunctionPointerForDelegate(_recv); - header->OnSend_new = Marshal.GetFunctionPointerForDelegate(_send); + header->OnRecv = Marshal.GetFunctionPointerForDelegate(_recv); + header->OnSend = Marshal.GetFunctionPointerForDelegate(_send); header->OnHotkeyPressed = Marshal.GetFunctionPointerForDelegate(_onHotkeyPressed); header->OnMouse = Marshal.GetFunctionPointerForDelegate(_onMouse); header->OnPlayerPositionChanged = Marshal.GetFunctionPointerForDelegate(_onUpdatePlayerPosition); @@ -306,7 +259,7 @@ private void OnPlayerPositionChanged(int x, int y, int z) World.Player.Position = new Point3D(x, y, z); } - private unsafe bool OnRecv(byte[] buffer, ref int length) + private unsafe bool OnRecv(ref byte[] buffer, ref int length) { m_In += (uint) length; fixed (byte* ptr = buffer) @@ -355,7 +308,7 @@ private unsafe bool OnRecv(byte[] buffer, ref int length) } } - private unsafe bool OnSend(byte[] buffer, ref int length) + private unsafe bool OnSend(ref byte[] buffer, ref int length) { m_Out += (uint) length; fixed (byte * ptr = buffer) @@ -597,10 +550,7 @@ public override unsafe void SendToServer(Packet p) byte[] data = p.Compile(); int length = (int) p.Length; - fixed (byte* ptr = data) - { - _sendToServer((IntPtr) ptr, ref length); - } + _sendToServer(ref data, ref length); } public override void SendToServer(PacketReader pr) @@ -613,18 +563,12 @@ public override unsafe void SendToClient(Packet p) byte[] data = p.Compile(); int length = (int) p.Length; - fixed (byte* ptr = data) - { - _sendToClient((IntPtr)ptr, ref length); - } + _sendToClient(ref data, ref length); } - public override unsafe void SendPacketToClient(byte[] packet, int length) + public override void SendPacketToClient(byte[] packet, int length) { - fixed (byte* ptr = packet) - { - _sendToClient((IntPtr) ptr, ref length); - } + _sendToClient(ref packet, ref length); } public override unsafe void ForceSendToClient(Packet p) @@ -634,7 +578,7 @@ public override unsafe void ForceSendToClient(Packet p) fixed (byte* ptr = data) { - _sendToClient((IntPtr) ptr, ref length); + _sendToClient(ref data, ref length); if (Packet.Logging) { @@ -650,7 +594,7 @@ public override unsafe void ForceSendToServer(Packet p) fixed (byte* ptr = data) { - _sendToServer((IntPtr) ptr, ref length); + _sendToServer(ref data, ref length); if (Packet.Logging) { From d061a2293deadc967d8f6f221ae33db22a82be4a Mon Sep 17 00:00:00 2001 From: Andrea Angelini Date: Mon, 24 May 2021 23:56:01 +0200 Subject: [PATCH 03/10] Update ClassicUO.cs --- Razor/Client/ClassicUO.cs | 315 +++++++++++++++++++++++++++----------- 1 file changed, 224 insertions(+), 91 deletions(-) diff --git a/Razor/Client/ClassicUO.cs b/Razor/Client/ClassicUO.cs index c789cc3b..909502f0 100644 --- a/Razor/Client/ClassicUO.cs +++ b/Razor/Client/ClassicUO.cs @@ -1,4 +1,4 @@ -#region license +#region license // Razor: An Ultima Online Assistant // Copyright (C) 2021 Razor Development Community on GitHub @@ -30,17 +30,150 @@ using System.Windows.Forms; using Assistant.Core; using Assistant.Scripts; -using CUO_API; namespace Assistant { + public struct PluginHeader + { + public int ClientVersion; + public IntPtr HWND; + public IntPtr OnRecv; + public IntPtr OnSend; + public IntPtr OnHotkeyPressed; + public IntPtr OnMouse; + public IntPtr OnPlayerPositionChanged; + public IntPtr OnClientClosing; + public IntPtr OnInitialize; + public IntPtr OnConnected; + public IntPtr OnDisconnected; + public IntPtr OnFocusGained; + public IntPtr OnFocusLost; + public IntPtr GetUOFilePath; + public IntPtr Recv; + public IntPtr Send; + public IntPtr GetPacketLength; + public IntPtr GetPlayerPosition; + public IntPtr CastSpell; + public IntPtr GetStaticImage; + public IntPtr Tick; + public IntPtr RequestMove; + public IntPtr SetTitle; + + public IntPtr OnRecv_new, OnSend_new, Recv_new, Send_new; + + public IntPtr OnDrawCmdList; + public IntPtr SDL_Window; + public IntPtr OnWndProc; + public IntPtr GetStaticData; + public IntPtr GetTileData; + public IntPtr GetCliloc; + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + unsafe delegate void OnInstall(void* header); + + [return: MarshalAs(UnmanagedType.I1)] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate bool OnPacketSendRecv_new(byte[] data, ref int length); + + [return: MarshalAs(UnmanagedType.I1)] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate bool OnPacketSendRecv_new_intptr(IntPtr data, ref int length); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate int OnDrawCmdList([Out] out IntPtr cmdlist, ref int size); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + unsafe delegate int OnWndProc(void* ev); + + [return: MarshalAs(UnmanagedType.I1)] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate bool OnGetStaticData + ( + int index, + ref ulong flags, + ref byte weight, + ref byte layer, + ref int count, + ref ushort animid, + ref ushort lightidx, + ref byte height, + ref string name + ); + + [return: MarshalAs(UnmanagedType.I1)] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate bool OnGetTileData(int index, ref ulong flags, ref ushort textid, ref string name); + + [return: MarshalAs(UnmanagedType.I1)] + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate bool OnGetCliloc(int cliloc, [MarshalAs(UnmanagedType.LPStr)] string args, bool capitalize, [Out][MarshalAs(UnmanagedType.LPStr)] out string buffer); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate string OnGetUOFilePath(); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate short OnGetPacketLength(int id); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate bool OnGetPlayerPosition(out int x, out int y, out int z); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void OnCastSpell(int idx); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void OnGetStaticImage(ushort g, ref ArtInfo art); + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct ArtInfo + { + public long Address; + public long Size; + public long CompressedSize; + } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void OnTick(); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate bool RequestMove(int dir, bool run); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void OnSetTitle(string title); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate bool OnHotkey(int key, int mod, bool pressed); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void OnMouse(int button, int wheel); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void OnUpdatePlayerPosition(int x, int y, int z); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void OnClientClose(); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void OnInitialize(); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void OnConnected(); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void OnDisconnected(); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void OnFocusGained(); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void OnFocusLost(); + + public partial class Engine { - public static unsafe void Install(void* ptr) + [DllExport] + public static unsafe void Install(PluginHeader* plugin) { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => { string[] fields = e.Name.Split(','); @@ -56,15 +189,22 @@ public static unsafe void Install(void* ptr) bool isdll = File.Exists(Path.Combine(RootPath, askedassembly.Name + ".dll")); - return Assembly.LoadFile(Path.Combine(RootPath, askedassembly.Name + (isdll ? ".dll" : ".exe"))); + string p = Path.Combine(RootPath, askedassembly.Name + (isdll ? ".dll" : ".exe")); + + Console.WriteLine("[RAZOR]: lib loading -> {0}", p); + + return Assembly.LoadFile(p); }; + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + SplashScreen.Start(); m_ActiveWnd = SplashScreen.Instance; Client.Init(false); - if (!(Client.Instance as ClassicUOClient).Install(ptr)) + if (!(Client.Instance as ClassicUOClient).Install(plugin)) { Process.GetCurrentProcess().Kill(); return; @@ -72,7 +212,7 @@ public static unsafe void Install(void* ptr) // load ultimasdk before or the Language.Load will throw the cliloc not found warning every time you run cuo string clientPath = - ((CUO_API.OnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(((PluginHeader*) ptr)->GetUOFilePath, typeof(OnGetUOFilePath)) + ((OnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(plugin->GetUOFilePath, typeof(OnGetUOFilePath)) )(); // just replicating the static .ctor @@ -136,27 +276,27 @@ public class ClassicUOClient : Client private bool m_ClientRunning = false; private string m_ClientVersion; - private static CUO_API.OnPacketSendRecv _sendToClient, _sendToServer; - private static CUO_API.OnPacketSendRecv _recv, _send; - private static CUO_API.OnGetPacketLength _getPacketLength; - private static CUO_API.OnGetPlayerPosition _getPlayerPosition; - private static CUO_API.OnCastSpell _castSpell; - private static CUO_API.OnGetStaticImage _getStaticImage; - private static CUO_API.OnTick _tick; - private static CUO_API.RequestMove _requestMove; - private static CUO_API.OnSetTitle _setTitle; - private static CUO_API.OnGetUOFilePath _uoFilePath; - - - private static CUO_API.OnHotkey _onHotkeyPressed; - private static CUO_API.OnMouse _onMouse; - private static CUO_API.OnUpdatePlayerPosition _onUpdatePlayerPosition; - private static CUO_API.OnClientClose _onClientClose; - private static CUO_API.OnInitialize _onInitialize; - private static CUO_API.OnConnected _onConnected; - private static CUO_API.OnDisconnected _onDisconnected; - private static CUO_API.OnFocusGained _onFocusGained; - private static CUO_API.OnFocusLost _onFocusLost; + private static OnPacketSendRecv_new_intptr _sendToClient, _sendToServer; + private static OnPacketSendRecv_new_intptr _recv, _send; + private static OnGetPacketLength _getPacketLength; + private static OnGetPlayerPosition _getPlayerPosition; + private static OnCastSpell _castSpell; + private static OnGetStaticImage _getStaticImage; + private static OnTick _tick; + private static RequestMove _requestMove; + private static OnSetTitle _setTitle; + private static OnGetUOFilePath _uoFilePath; + + + private static OnHotkey _onHotkeyPressed; + private static OnMouse _onMouse; + private static OnUpdatePlayerPosition _onUpdatePlayerPosition; + private static OnClientClose _onClientClose; + private static OnInitialize _onInitialize; + private static OnConnected _onConnected; + private static OnDisconnected _onDisconnected; + private static OnFocusGained _onFocusGained; + private static OnFocusLost _onFocusLost; private IntPtr m_ClientWindow; public override void SetMapWndHandle(Form mapWnd) @@ -188,29 +328,27 @@ public override Loader_Error LaunchClient(string client) public override bool ServerEncrypted { get; set; } - public unsafe bool Install(void* ptr) + public unsafe bool Install(PluginHeader* header) { - CUO_API.PluginHeader* header = (CUO_API.PluginHeader*) ptr; - _sendToClient = - (CUO_API.OnPacketSendRecv) Marshal.GetDelegateForFunctionPointer(header->Recv, typeof(CUO_API.OnPacketSendRecv)); + (OnPacketSendRecv_new_intptr) Marshal.GetDelegateForFunctionPointer(header->Recv_new, typeof(OnPacketSendRecv_new_intptr)); _sendToServer = - (CUO_API.OnPacketSendRecv) Marshal.GetDelegateForFunctionPointer(header->Send, typeof(CUO_API.OnPacketSendRecv)); + (OnPacketSendRecv_new_intptr) Marshal.GetDelegateForFunctionPointer(header->Send_new, typeof(OnPacketSendRecv_new_intptr)); _getPacketLength = - (CUO_API.OnGetPacketLength) Marshal.GetDelegateForFunctionPointer(header->GetPacketLength, - typeof(CUO_API.OnGetPacketLength)); + (OnGetPacketLength) Marshal.GetDelegateForFunctionPointer(header->GetPacketLength, + typeof(OnGetPacketLength)); _getPlayerPosition = - (CUO_API.OnGetPlayerPosition) Marshal.GetDelegateForFunctionPointer(header->GetPlayerPosition, - typeof(CUO_API.OnGetPlayerPosition)); - _castSpell = (CUO_API.OnCastSpell) Marshal.GetDelegateForFunctionPointer(header->CastSpell, typeof(CUO_API.OnCastSpell)); + (OnGetPlayerPosition) Marshal.GetDelegateForFunctionPointer(header->GetPlayerPosition, + typeof(OnGetPlayerPosition)); + _castSpell = (OnCastSpell) Marshal.GetDelegateForFunctionPointer(header->CastSpell, typeof(OnCastSpell)); _getStaticImage = - (CUO_API.OnGetStaticImage) Marshal.GetDelegateForFunctionPointer(header->GetStaticImage, - typeof(CUO_API.OnGetStaticImage)); + (OnGetStaticImage) Marshal.GetDelegateForFunctionPointer(header->GetStaticImage, + typeof(OnGetStaticImage)); _requestMove = - (CUO_API.RequestMove) Marshal.GetDelegateForFunctionPointer(header->RequestMove, typeof(CUO_API.RequestMove)); - _setTitle = (CUO_API.OnSetTitle) Marshal.GetDelegateForFunctionPointer(header->SetTitle, typeof(CUO_API.OnSetTitle)); + (RequestMove) Marshal.GetDelegateForFunctionPointer(header->RequestMove, typeof(RequestMove)); + _setTitle = (OnSetTitle) Marshal.GetDelegateForFunctionPointer(header->SetTitle, typeof(OnSetTitle)); _uoFilePath = - (CUO_API.OnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(header->GetUOFilePath, typeof(CUO_API.OnGetUOFilePath)); + (OnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(header->GetUOFilePath, typeof(OnGetUOFilePath)); m_ClientVersion = new Version((byte) (header->ClientVersion >> 24), (byte) (header->ClientVersion >> 16), (byte) (header->ClientVersion >> 8), (byte) header->ClientVersion).ToString(); m_ClientRunning = true; @@ -228,8 +366,8 @@ public unsafe bool Install(void* ptr) _onFocusGained = OnFocusGained; _onFocusLost = OnFocusLost; header->Tick = Marshal.GetFunctionPointerForDelegate(_tick); - header->OnRecv = Marshal.GetFunctionPointerForDelegate(_recv); - header->OnSend = Marshal.GetFunctionPointerForDelegate(_send); + header->OnRecv_new = Marshal.GetFunctionPointerForDelegate(_recv); + header->OnSend_new = Marshal.GetFunctionPointerForDelegate(_send); header->OnHotkeyPressed = Marshal.GetFunctionPointerForDelegate(_onHotkeyPressed); header->OnMouse = Marshal.GetFunctionPointerForDelegate(_onMouse); header->OnPlayerPositionChanged = Marshal.GetFunctionPointerForDelegate(_onUpdatePlayerPosition); @@ -259,13 +397,16 @@ private void OnPlayerPositionChanged(int x, int y, int z) World.Player.Position = new Point3D(x, y, z); } - private unsafe bool OnRecv(ref byte[] buffer, ref int length) + private unsafe bool OnRecv(IntPtr data, ref int length) { + byte[] buffer = new byte[length]; + Marshal.Copy(data, buffer, 0, length); + m_In += (uint) length; - fixed (byte* ptr = buffer) + //fixed (byte* ptr = data) { bool result = true; - byte id = ptr[0]; + byte id = buffer[0]; PacketReader reader = null; Packet packet = null; @@ -274,47 +415,40 @@ private unsafe bool OnRecv(ref byte[] buffer, ref int length) if (isView) { - reader = new PacketReader(ptr, length, PacketsTable.IsDynLength(id)); + reader = new PacketReader((byte*) data, length, PacketsTable.IsDynLength(id)); result = !PacketHandler.OnServerPacket(id, reader, packet); } if (isFilter) { - byte[] data = new byte[length]; - - for (int i = 0; i < length; ++i) - { - data[i] = ptr[i]; - } - - packet = new Packet(data, length, PacketsTable.IsDynLength(id)); - result = !PacketHandler.OnClientPacket(id, reader, packet); + packet = new Packet(buffer, length, PacketsTable.IsDynLength(id)); + result = !PacketHandler.OnServerPacket(id, reader, packet); - data = packet.Compile(); + var compiled = packet.Compile(); length = (int)packet.Length; - for (int i = 0; i < length; ++i) - { - data[i] = ptr[i]; - } + Marshal.Copy(compiled, 0, data, length); } if (Packet.Logging) { - Packet.Log(PacketPath.ServerToClient, ptr, length, !result); + Packet.Log(PacketPath.ServerToClient, (byte*)data, length, !result); } return result; } } - private unsafe bool OnSend(ref byte[] buffer, ref int length) + private unsafe bool OnSend(IntPtr data, ref int length) { + byte[] buffer = new byte[length]; + Marshal.Copy(data, buffer, 0, length); + m_Out += (uint) length; - fixed (byte * ptr = buffer) + //fixed (byte* ptr = data) { bool result = true; - byte id = ptr[0]; + byte id = buffer[0]; PacketReader reader = null; Packet packet = null; @@ -323,33 +457,23 @@ private unsafe bool OnSend(ref byte[] buffer, ref int length) if (isView) { - reader = new PacketReader(ptr, length, PacketsTable.IsDynLength(id)); + reader = new PacketReader((byte*) data, length, PacketsTable.IsDynLength(id)); result = !PacketHandler.OnClientPacket(id, reader, packet); } else if (isFilter) { - byte[] data = new byte[length]; - - for (int i = 0; i < length; ++i) - { - data[i] = ptr[i]; - } - - packet = new Packet(data, length, PacketsTable.IsDynLength(id)); + packet = new Packet(buffer, length, PacketsTable.IsDynLength(id)); result = !PacketHandler.OnClientPacket(id, reader, packet); - data = packet.Compile(); + var compiled = packet.Compile(); length = (int) packet.Length; - for (int i = 0; i < length; ++i) - { - data[i] = ptr[i]; - } + Marshal.Copy(compiled, 0, data, length); } if (Packet.Logging) { - Packet.Log(PacketPath.ClientToServer, ptr, length, !result); + Packet.Log(PacketPath.ClientToServer, (byte*)data, length, !result); } return result; @@ -550,7 +674,10 @@ public override unsafe void SendToServer(Packet p) byte[] data = p.Compile(); int length = (int) p.Length; - _sendToServer(ref data, ref length); + fixed (byte* ptr = data) + { + _sendToServer((IntPtr)ptr, ref length); + } } public override void SendToServer(PacketReader pr) @@ -563,12 +690,18 @@ public override unsafe void SendToClient(Packet p) byte[] data = p.Compile(); int length = (int) p.Length; - _sendToClient(ref data, ref length); + fixed (byte* ptr = data) + { + _sendToClient((IntPtr)ptr, ref length); + } } - public override void SendPacketToClient(byte[] packet, int length) + public override unsafe void SendPacketToClient(byte[] packet, int length) { - _sendToClient(ref packet, ref length); + fixed (byte* ptr = packet) + { + _sendToClient((IntPtr) ptr, ref length); + } } public override unsafe void ForceSendToClient(Packet p) @@ -578,7 +711,7 @@ public override unsafe void ForceSendToClient(Packet p) fixed (byte* ptr = data) { - _sendToClient(ref data, ref length); + _sendToClient((IntPtr) ptr, ref length); if (Packet.Logging) { @@ -594,7 +727,7 @@ public override unsafe void ForceSendToServer(Packet p) fixed (byte* ptr = data) { - _sendToServer(ref data, ref length); + _sendToServer((IntPtr) ptr, ref length); if (Packet.Logging) { @@ -702,4 +835,4 @@ public void OnFocusLost() } } } -} \ No newline at end of file +} From a59d8a21c0b9e33de28665e606f3c8298e3d5f32 Mon Sep 17 00:00:00 2001 From: Andrea Angelini Date: Mon, 24 May 2021 23:56:42 +0200 Subject: [PATCH 04/10] Update ClassicUO.cs --- Razor/Client/ClassicUO.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Razor/Client/ClassicUO.cs b/Razor/Client/ClassicUO.cs index 909502f0..2165ba37 100644 --- a/Razor/Client/ClassicUO.cs +++ b/Razor/Client/ClassicUO.cs @@ -171,7 +171,6 @@ public struct ArtInfo public partial class Engine { - [DllExport] public static unsafe void Install(PluginHeader* plugin) { AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => From c38e3b1b47d1b79e21353a3f094bba66f4dfda5b Mon Sep 17 00:00:00 2001 From: Andrea Angelini Date: Mon, 24 May 2021 23:57:19 +0200 Subject: [PATCH 05/10] Update Razor.csproj --- Razor/Razor.csproj | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Razor/Razor.csproj b/Razor/Razor.csproj index a90c3870..7f88b9fb 100644 --- a/Razor/Razor.csproj +++ b/Razor/Razor.csproj @@ -122,10 +122,6 @@ false - - False - .\cuoapi.dll - System @@ -605,4 +601,4 @@ xcopy /S /Q /Y "$(SolutionDir)etc\*" "$(SolutionDir)bin\Win32\$(Configuration)\" - \ No newline at end of file + From 9f5f92db406351d84ac8a90513984136793acd90 Mon Sep 17 00:00:00 2001 From: Andrea Angelini Date: Mon, 24 May 2021 23:58:49 +0200 Subject: [PATCH 06/10] Update ScriptManager.cs --- Razor/Scripts/ScriptManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Razor/Scripts/ScriptManager.cs b/Razor/Scripts/ScriptManager.cs index 9bd84030..bec7287d 100644 --- a/Razor/Scripts/ScriptManager.cs +++ b/Razor/Scripts/ScriptManager.cs @@ -430,7 +430,7 @@ public static void OnLogout() StopScript(); Timer.Stop(); Assistant.Engine.MainWindow.LockScriptUI(false); - Assistant.Engine.RazorScriptEditorWindow.LockScriptUI(false); + Assistant.Engine.RazorScriptEditorWindow?.LockScriptUI(false); } public static void StartEngine() @@ -1168,4 +1168,4 @@ private static void OnGetItemInfoTarget(bool ground, Serial serial, Point3D pt, } } } -} \ No newline at end of file +} From 1631013a6148541eaeb52bf9f533b28b01f49edf Mon Sep 17 00:00:00 2001 From: Andrea Angelini Date: Wed, 26 May 2021 10:40:44 +0200 Subject: [PATCH 07/10] mark as 'obsolete' some plugin fields --- Razor/Client/ClassicUO.cs | 130 +++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 64 deletions(-) diff --git a/Razor/Client/ClassicUO.cs b/Razor/Client/ClassicUO.cs index 2165ba37..0ef87c89 100644 --- a/Razor/Client/ClassicUO.cs +++ b/Razor/Client/ClassicUO.cs @@ -37,8 +37,8 @@ public struct PluginHeader { public int ClientVersion; public IntPtr HWND; - public IntPtr OnRecv; - public IntPtr OnSend; + [Obsolete] public IntPtr OnRecv_OBSOLETE_DO_NOT_USE; + [Obsolete] public IntPtr OnSend_OBSOLETE_DO_NOT_USE; public IntPtr OnHotkeyPressed; public IntPtr OnMouse; public IntPtr OnPlayerPositionChanged; @@ -49,8 +49,8 @@ public struct PluginHeader public IntPtr OnFocusGained; public IntPtr OnFocusLost; public IntPtr GetUOFilePath; - public IntPtr Recv; - public IntPtr Send; + [Obsolete] public IntPtr Recv_OBSOLETE_DO_NOT_USE; + [Obsolete] public IntPtr Send_OBSOLETE_DO_NOT_USE; public IntPtr GetPacketLength; public IntPtr GetPlayerPosition; public IntPtr CastSpell; @@ -70,25 +70,25 @@ public struct PluginHeader } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - unsafe delegate void OnInstall(void* header); + public unsafe delegate void dOnInstall(void* header); [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate bool OnPacketSendRecv_new(byte[] data, ref int length); + public delegate bool dOnPacketSendRecv_new(byte[] data, ref int length); [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate bool OnPacketSendRecv_new_intptr(IntPtr data, ref int length); + public delegate bool dOnPacketSendRecv_new_intptr(IntPtr data, ref int length); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate int OnDrawCmdList([Out] out IntPtr cmdlist, ref int size); + public delegate int dOnDrawCmdList([Out] out IntPtr cmdlist, ref int size); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - unsafe delegate int OnWndProc(void* ev); + public unsafe delegate int dOnWndProc(void* ev); [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate bool OnGetStaticData + public delegate bool dOnGetStaticData ( int index, ref ulong flags, @@ -103,26 +103,27 @@ ref string name [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate bool OnGetTileData(int index, ref ulong flags, ref ushort textid, ref string name); + public delegate bool dOnGetTileData(int index, ref ulong flags, ref ushort textid, ref string name); [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - delegate bool OnGetCliloc(int cliloc, [MarshalAs(UnmanagedType.LPStr)] string args, bool capitalize, [Out][MarshalAs(UnmanagedType.LPStr)] out string buffer); + public delegate bool dOnGetCliloc(int cliloc, [MarshalAs(UnmanagedType.LPStr)] string args, bool capitalize, [Out][MarshalAs(UnmanagedType.LPStr)] out string buffer); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate string OnGetUOFilePath(); + public delegate string dOnGetUOFilePath(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate short OnGetPacketLength(int id); + public delegate short dOnGetPacketLength(int id); + [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool OnGetPlayerPosition(out int x, out int y, out int z); - + public delegate bool dOnGetPlayerPosition(out int x, out int y, out int z); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnCastSpell(int idx); + public delegate void dOnCastSpell(int idx); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnGetStaticImage(ushort g, ref ArtInfo art); + public delegate void dOnGetStaticImage(ushort g, ref ArtInfo art); [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct ArtInfo @@ -133,44 +134,47 @@ public struct ArtInfo } [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnTick(); + public delegate void dOnTick(); + [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool RequestMove(int dir, bool run); + public delegate bool dRequestMove(int dir, bool run); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnSetTitle(string title); + public delegate void dOnSetTitle(string title); + [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool OnHotkey(int key, int mod, bool pressed); + public delegate bool dOnHotkey(int key, int mod, bool pressed); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnMouse(int button, int wheel); + public delegate void dOnMouse(int button, int wheel); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnUpdatePlayerPosition(int x, int y, int z); + public delegate void dOnUpdatePlayerPosition(int x, int y, int z); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnClientClose(); + public delegate void dOnClientClose(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnInitialize(); + public delegate void dOnInitialize(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnConnected(); + public delegate void dOnConnected(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnDisconnected(); + public delegate void dOnDisconnected(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnFocusGained(); + public delegate void dOnFocusGained(); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void OnFocusLost(); + public delegate void dOnFocusLost(); public partial class Engine { + [DllExport] public static unsafe void Install(PluginHeader* plugin) { AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => @@ -211,7 +215,7 @@ public static unsafe void Install(PluginHeader* plugin) // load ultimasdk before or the Language.Load will throw the cliloc not found warning every time you run cuo string clientPath = - ((OnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(plugin->GetUOFilePath, typeof(OnGetUOFilePath)) + ((dOnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(plugin->GetUOFilePath, typeof(dOnGetUOFilePath)) )(); // just replicating the static .ctor @@ -275,27 +279,25 @@ public class ClassicUOClient : Client private bool m_ClientRunning = false; private string m_ClientVersion; - private static OnPacketSendRecv_new_intptr _sendToClient, _sendToServer; - private static OnPacketSendRecv_new_intptr _recv, _send; - private static OnGetPacketLength _getPacketLength; - private static OnGetPlayerPosition _getPlayerPosition; - private static OnCastSpell _castSpell; - private static OnGetStaticImage _getStaticImage; - private static OnTick _tick; - private static RequestMove _requestMove; - private static OnSetTitle _setTitle; - private static OnGetUOFilePath _uoFilePath; - - - private static OnHotkey _onHotkeyPressed; - private static OnMouse _onMouse; - private static OnUpdatePlayerPosition _onUpdatePlayerPosition; - private static OnClientClose _onClientClose; - private static OnInitialize _onInitialize; - private static OnConnected _onConnected; - private static OnDisconnected _onDisconnected; - private static OnFocusGained _onFocusGained; - private static OnFocusLost _onFocusLost; + private static dOnPacketSendRecv_new_intptr _sendToClient, _sendToServer; + private static dOnPacketSendRecv_new_intptr _recv, _send; + private static dOnGetPacketLength _getPacketLength; + private static dOnGetPlayerPosition _getPlayerPosition; + private static dOnCastSpell _castSpell; + private static dOnGetStaticImage _getStaticImage; + private static dOnTick _tick; + private static dRequestMove _requestMove; + private static dOnSetTitle _setTitle; + private static dOnGetUOFilePath _uoFilePath; + private static dOnHotkey _onHotkeyPressed; + private static dOnMouse _onMouse; + private static dOnUpdatePlayerPosition _onUpdatePlayerPosition; + private static dOnClientClose _onClientClose; + private static dOnInitialize _onInitialize; + private static dOnConnected _onConnected; + private static dOnDisconnected _onDisconnected; + private static dOnFocusGained _onFocusGained; + private static dOnFocusLost _onFocusLost; private IntPtr m_ClientWindow; public override void SetMapWndHandle(Form mapWnd) @@ -330,24 +332,24 @@ public override Loader_Error LaunchClient(string client) public unsafe bool Install(PluginHeader* header) { _sendToClient = - (OnPacketSendRecv_new_intptr) Marshal.GetDelegateForFunctionPointer(header->Recv_new, typeof(OnPacketSendRecv_new_intptr)); + (dOnPacketSendRecv_new_intptr) Marshal.GetDelegateForFunctionPointer(header->Recv_new, typeof(dOnPacketSendRecv_new_intptr)); _sendToServer = - (OnPacketSendRecv_new_intptr) Marshal.GetDelegateForFunctionPointer(header->Send_new, typeof(OnPacketSendRecv_new_intptr)); + (dOnPacketSendRecv_new_intptr) Marshal.GetDelegateForFunctionPointer(header->Send_new, typeof(dOnPacketSendRecv_new_intptr)); _getPacketLength = - (OnGetPacketLength) Marshal.GetDelegateForFunctionPointer(header->GetPacketLength, - typeof(OnGetPacketLength)); + (dOnGetPacketLength) Marshal.GetDelegateForFunctionPointer(header->GetPacketLength, + typeof(dOnGetPacketLength)); _getPlayerPosition = - (OnGetPlayerPosition) Marshal.GetDelegateForFunctionPointer(header->GetPlayerPosition, - typeof(OnGetPlayerPosition)); - _castSpell = (OnCastSpell) Marshal.GetDelegateForFunctionPointer(header->CastSpell, typeof(OnCastSpell)); + (dOnGetPlayerPosition) Marshal.GetDelegateForFunctionPointer(header->GetPlayerPosition, + typeof(dOnGetPlayerPosition)); + _castSpell = (dOnCastSpell) Marshal.GetDelegateForFunctionPointer(header->CastSpell, typeof(dOnCastSpell)); _getStaticImage = - (OnGetStaticImage) Marshal.GetDelegateForFunctionPointer(header->GetStaticImage, - typeof(OnGetStaticImage)); + (dOnGetStaticImage) Marshal.GetDelegateForFunctionPointer(header->GetStaticImage, + typeof(dOnGetStaticImage)); _requestMove = - (RequestMove) Marshal.GetDelegateForFunctionPointer(header->RequestMove, typeof(RequestMove)); - _setTitle = (OnSetTitle) Marshal.GetDelegateForFunctionPointer(header->SetTitle, typeof(OnSetTitle)); + (dRequestMove) Marshal.GetDelegateForFunctionPointer(header->RequestMove, typeof(dRequestMove)); + _setTitle = (dOnSetTitle) Marshal.GetDelegateForFunctionPointer(header->SetTitle, typeof(dOnSetTitle)); _uoFilePath = - (OnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(header->GetUOFilePath, typeof(OnGetUOFilePath)); + (dOnGetUOFilePath) Marshal.GetDelegateForFunctionPointer(header->GetUOFilePath, typeof(dOnGetUOFilePath)); m_ClientVersion = new Version((byte) (header->ClientVersion >> 24), (byte) (header->ClientVersion >> 16), (byte) (header->ClientVersion >> 8), (byte) header->ClientVersion).ToString(); m_ClientRunning = true; From 03f40870ee59b81cb2e93240b32323b81c654485 Mon Sep 17 00:00:00 2001 From: Andrea Angelini Date: Wed, 26 May 2021 11:44:10 +0200 Subject: [PATCH 08/10] experimental thing --- Razor/Client/ClassicUO.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Razor/Client/ClassicUO.cs b/Razor/Client/ClassicUO.cs index 0ef87c89..c447134d 100644 --- a/Razor/Client/ClassicUO.cs +++ b/Razor/Client/ClassicUO.cs @@ -174,7 +174,7 @@ public struct ArtInfo public partial class Engine { - [DllExport] + //[DllExport] experimental public static unsafe void Install(PluginHeader* plugin) { AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => From c1ac6c8e58df6da22c8ac6f26715a06b04946ddc Mon Sep 17 00:00:00 2001 From: Andrea Angelini Date: Wed, 26 May 2021 11:55:24 +0200 Subject: [PATCH 09/10] removed old dOnPacketSendRecv_new --- Razor/Client/ClassicUO.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Razor/Client/ClassicUO.cs b/Razor/Client/ClassicUO.cs index c447134d..21c0dca8 100644 --- a/Razor/Client/ClassicUO.cs +++ b/Razor/Client/ClassicUO.cs @@ -74,11 +74,7 @@ public struct PluginHeader [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool dOnPacketSendRecv_new(byte[] data, ref int length); - - [return: MarshalAs(UnmanagedType.I1)] - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate bool dOnPacketSendRecv_new_intptr(IntPtr data, ref int length); + public delegate bool dOnPacketSendRecv(IntPtr data, ref int length); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate int dOnDrawCmdList([Out] out IntPtr cmdlist, ref int size); @@ -279,8 +275,7 @@ public class ClassicUOClient : Client private bool m_ClientRunning = false; private string m_ClientVersion; - private static dOnPacketSendRecv_new_intptr _sendToClient, _sendToServer; - private static dOnPacketSendRecv_new_intptr _recv, _send; + private static dOnPacketSendRecv _sendToClient, _sendToServer, _recv, _send;; private static dOnGetPacketLength _getPacketLength; private static dOnGetPlayerPosition _getPlayerPosition; private static dOnCastSpell _castSpell; @@ -332,9 +327,9 @@ public override Loader_Error LaunchClient(string client) public unsafe bool Install(PluginHeader* header) { _sendToClient = - (dOnPacketSendRecv_new_intptr) Marshal.GetDelegateForFunctionPointer(header->Recv_new, typeof(dOnPacketSendRecv_new_intptr)); + (dOnPacketSendRecv) Marshal.GetDelegateForFunctionPointer(header->Recv_new, typeof(dOnPacketSendRecv)); _sendToServer = - (dOnPacketSendRecv_new_intptr) Marshal.GetDelegateForFunctionPointer(header->Send_new, typeof(dOnPacketSendRecv_new_intptr)); + (dOnPacketSendRecv) Marshal.GetDelegateForFunctionPointer(header->Send_new, typeof(dOnPacketSendRecv)); _getPacketLength = (dOnGetPacketLength) Marshal.GetDelegateForFunctionPointer(header->GetPacketLength, typeof(dOnGetPacketLength)); From 10c7ca91cd8ab12b059f10e942ee4e9f6836212e Mon Sep 17 00:00:00 2001 From: Andrea Angelini Date: Fri, 11 Jun 2021 13:01:15 +0200 Subject: [PATCH 10/10] minor --- Razor/Client/ClassicUO.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Razor/Client/ClassicUO.cs b/Razor/Client/ClassicUO.cs index 21c0dca8..e1707f48 100644 --- a/Razor/Client/ClassicUO.cs +++ b/Razor/Client/ClassicUO.cs @@ -275,7 +275,7 @@ public class ClassicUOClient : Client private bool m_ClientRunning = false; private string m_ClientVersion; - private static dOnPacketSendRecv _sendToClient, _sendToServer, _recv, _send;; + private static dOnPacketSendRecv _sendToClient, _sendToServer, _recv, _send; private static dOnGetPacketLength _getPacketLength; private static dOnGetPlayerPosition _getPlayerPosition; private static dOnCastSpell _castSpell;