Exemplo n.º 1
0
        public override void Enter(Actor owner, ActorAIController ownerAI)
        {
            base.Enter(owner, ownerAI);

            ownerAI.ChaseTarget   = GameSystem.Instance.ActorManager.GetRandomPlayer();
            this.currentDirection = this.GetTargetDirection(owner, ownerAI);

            this.GetObserver(owner)
            .SubscribeWithState3(this, owner, ownerAI, (_, _this, _owner, _ownerAI) =>
            {
                _owner.StatusController.SetMoveSpeedRate(_this.moveSpeedRate);
                _owner.Broker.Publish(RequestMove.Get(_this.currentDirection.ToVector2()));

                if (_this.IsReverse(_owner, _ownerAI))
                {
                    _this.changeDirectionDuration += Time.deltaTime;
                }
                else
                {
                    _this.changeDirectionDuration = 0.0f;
                }

                if (_this.changeDirectionDuration > _this.changeDirectionDelay)
                {
                    _this.changeDirectionDuration = 0.0f;
                    _this.currentDirection        = _this.GetTargetDirection(_owner, _ownerAI);
                }
            })
            .AddTo(this.events);
        }
Exemplo n.º 2
0
        void IActorReactionOnTriggerEnter2D.Do(Actor actor)
        {
            if (!this.includeTags.Contains(actor.tag))
            {
                return;
            }

            Broker.Global.Receive <EndFadeIn>()
            .Take(1)
            .SubscribeWithState2(this, actor, (_, _this, _actor) =>
            {
                Broker.Global.Publish(RequestChangeStage.Get(_this.prefab));
                _actor.Movement.Warp(_this.actorPosition);
                Broker.Global.Publish(RequestFadeOut.Get(_this.direction.ToReverse().ToFadeType(), _this.fadeTimeSeconds));
                Broker.Global.Publish(EndChangeStage.Get());
            });

            Broker.Global.Publish(BeginChangeStage.Get());
            Broker.Global.Publish(RequestFadeIn.Get(this.direction.ToFadeType(), this.fadeTimeSeconds));

            actor.UpdateAsObservable()
            .TakeUntil(Broker.Global.Receive <EndChangeStage>())
            .SubscribeWithState2(this, actor, (_, _this, _actor) =>
            {
                _actor.Broker.Publish(RequestMove.Get(_this.direction.ToVector2()));
            })
            .AddTo(actor);
        }
Exemplo n.º 3
0
    public RequestMove moving(float posX, float posY, float posZ)
    {
        RequestMove move = new RequestMove();

        move.send(posX, posY, posZ);
        return(move);
    }
Exemplo n.º 4
0
    public void SendMove(int x, int y, string playerID)
    {
        var msg = new RequestMove();

        msg.playerID = playerID;
        msg.x        = x;
        msg.y        = y;

        SendMessage(msg.ToMessage());
    }
Exemplo n.º 5
0
        /// <summary>
        /// Serialize <see cref="RequestMove"/>.
        /// </summary>
        /// <param name="request">Request to serialize</param>
        private void SerializeRequestMove(RequestMove request)
        {
            if (this.versionToUse < SerializationFormatVersions.Version19)
            {
                throw new NotImplementedException(string.Format("The channel is in version {0} which doesn't support Move", this.versionToUse));
            }

            this.binaryWriter.Write((int)request.Version);
            this.binaryWriter.Write((string)request.PathDst);
            this.binaryWriter.Write((ushort)request.MoveMode);
        }
Exemplo n.º 6
0
 public bool SendMoveRequest(int pieceIndex, int x, int y)
 {
     if (cManager && cManager.IsConnected())
     {
         RequestMove request = new RequestMove();
         request.send(pieceIndex, x, y);
         cManager.send(request);
         return(true);
     }
     return(false);
 }
Exemplo n.º 7
0
 public bool SendMoveRequest(float x, float y, float angle)
 {
     if (cManager && cManager.IsConnected())
     {
         RequestMove request = new RequestMove();
         request.send(x, y, angle);
         cManager.send(request);
         return(true);
     }
     return(false);
 }
Exemplo n.º 8
0
        internal static unsafe void InitializePlugin(PluginHeader *plugin)
        {
            _onConnected             = OnConnected;
            _onDisconnected          = OnDisconnected;
            _onReceive               = OnPacketReceive;
            _onSend                  = OnPacketSend;
            _onPlayerPositionChanged = OnPlayerPositionChanged;
            _onClientClosing         = OnClientClosing;
            _onHotkeyPressed         = OnHotkeyPressed;
            _onMouse                 = OnMouse;
            _onTick                  = OnTick;
            WindowHandle             = plugin->HWND;

            plugin->OnConnected             = Marshal.GetFunctionPointerForDelegate(_onConnected);
            plugin->OnDisconnected          = Marshal.GetFunctionPointerForDelegate(_onDisconnected);
            plugin->OnRecv                  = Marshal.GetFunctionPointerForDelegate(_onReceive);
            plugin->OnSend                  = Marshal.GetFunctionPointerForDelegate(_onSend);
            plugin->OnPlayerPositionChanged = Marshal.GetFunctionPointerForDelegate(_onPlayerPositionChanged);
            plugin->OnClientClosing         = Marshal.GetFunctionPointerForDelegate(_onClientClosing);
            plugin->OnHotkeyPressed         = Marshal.GetFunctionPointerForDelegate(_onHotkeyPressed);
            plugin->OnMouse                 = Marshal.GetFunctionPointerForDelegate(_onMouse);
            plugin->Tick = Marshal.GetFunctionPointerForDelegate(_onTick);

            _getPacketLength = Marshal.GetDelegateForFunctionPointer <OnGetPacketLength>(plugin->GetPacketLength);
            _getUOFilePath   = Marshal.GetDelegateForFunctionPointer <OnGetUOFilePath>(plugin->GetUOFilePath);
            _sendToClient    = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(plugin->Recv);
            _sendToServer    = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(plugin->Send);
            _requestMove     = Marshal.GetDelegateForFunctionPointer <RequestMove>(plugin->RequestMove);
            _setTitle        = Marshal.GetDelegateForFunctionPointer <OnSetTitle>(plugin->SetTitle);

            ClientPath    = _getUOFilePath();
            ClientVersion = new Version((byte)(plugin->ClientVersion >> 24), (byte)(plugin->ClientVersion >> 16),
                                        (byte)(plugin->ClientVersion >> 8), (byte)plugin->ClientVersion);

            if (!Path.IsPathRooted(ClientPath))
            {
                ClientPath = Path.GetFullPath(ClientPath);
            }

            Art.Initialize(ClientPath);
            Hues.Initialize(ClientPath);
            Cliloc.Initialize(ClientPath);
            Skills.Initialize(ClientPath);
            Speech.Initialize(ClientPath);
            TileData.Initialize(ClientPath);
            Statics.Initialize(ClientPath);
            MapInfo.Initialize(ClientPath);

            ClassicAssembly = AppDomain.CurrentDomain.GetAssemblies()
                              .FirstOrDefault(a => a.FullName.StartsWith("ClassicUO,"));

            InitializeExtensions();
        }
Exemplo n.º 9
0
        public unsafe bool Install(PluginHeader *header)
        {
            _sendToClient =
                (OnPacketSendRecv)Marshal.GetDelegateForFunctionPointer(header->Recv, typeof(OnPacketSendRecv));
            _sendToServer =
                (OnPacketSendRecv)Marshal.GetDelegateForFunctionPointer(header->Send, typeof(OnPacketSendRecv));
            _getPacketLength =
                (OnGetPacketLength)Marshal.GetDelegateForFunctionPointer(header->GetPacketLength,
                                                                         typeof(OnGetPacketLength));
            _getPlayerPosition =
                (OnGetPlayerPosition)Marshal.GetDelegateForFunctionPointer(header->GetPlayerPosition,
                                                                           typeof(OnGetPlayerPosition));
            _castSpell      = (OnCastSpell)Marshal.GetDelegateForFunctionPointer(header->CastSpell, typeof(OnCastSpell));
            _getStaticImage =
                (OnGetStaticImage)Marshal.GetDelegateForFunctionPointer(header->GetStaticImage,
                                                                        typeof(OnGetStaticImage));
            _requestMove =
                (RequestMove)Marshal.GetDelegateForFunctionPointer(header->RequestMove, typeof(RequestMove));
            _setTitle   = (OnSetTitle)Marshal.GetDelegateForFunctionPointer(header->SetTitle, typeof(OnSetTitle));
            _uoFilePath =
                (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;
            m_ClientWindow                  = header->HWND;
            _tick                           = Tick;
            _recv                           = OnRecv;
            _send                           = OnSend;
            _onHotkeyPressed                = OnHotKeyHandler;
            _onMouse                        = OnMouseHandler;
            _onUpdatePlayerPosition         = OnPlayerPositionChanged;
            _onClientClose                  = OnClientClosing;
            _onInitialize                   = OnInitialize;
            _onConnected                    = OnConnected;
            _onDisconnected                 = OnDisconnected;
            _onFocusGained                  = OnFocusGained;
            _onFocusLost                    = OnFocusLost;
            header->Tick                    = Marshal.GetFunctionPointerForDelegate(_tick);
            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);
            header->OnClientClosing         = Marshal.GetFunctionPointerForDelegate(_onClientClose);
            header->OnInitialize            = Marshal.GetFunctionPointerForDelegate(_onInitialize);
            header->OnConnected             = Marshal.GetFunctionPointerForDelegate(_onConnected);
            header->OnDisconnected          = Marshal.GetFunctionPointerForDelegate(_onDisconnected);
            header->OnFocusGained           = Marshal.GetFunctionPointerForDelegate(_onFocusGained);
            header->OnFocusLost             = Marshal.GetFunctionPointerForDelegate(_onFocusLost);

            return(true);
        }
Exemplo n.º 10
0
        public override void Enter(Actor owner, ActorAIController ownerAI)
        {
            base.Enter(owner, ownerAI);

            this.velocity = this.velocities[Random.Range(0, this.velocities.Count)];

            this.GetObserver(owner)
            .SubscribeWithState3(this, owner, ownerAI, (_, _this, _owner, _ownerAI) =>
            {
                _owner.StatusController.SetMoveSpeedRate(_this.moveSpeedRate);
                _owner.Broker.Publish(RequestMove.Get(_this.velocity));
            })
            .AddTo(this.events);
        }
Exemplo n.º 11
0
        public void Initialize()
        {
            _startupPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            _getUOFilePath   = GetUOFilePath;
            _getPacketLength = GetPacketLength;
            _sendPacket      = SendPacket;
            _receivePacket   = ReceivePacket;
            _requestMove     = (dir, run) => true;
            _setTitle        = SetTitle;

            _pluginHeader = new PluginHeader
            {
                GetPacketLength = Marshal.GetFunctionPointerForDelegate(_getPacketLength),
                GetUOFilePath   = Marshal.GetFunctionPointerForDelegate(_getUOFilePath),
                Recv            = Marshal.GetFunctionPointerForDelegate(_receivePacket),
                Send            = Marshal.GetFunctionPointerForDelegate(_sendPacket),
                RequestMove     = Marshal.GetFunctionPointerForDelegate(_requestMove),
                SetTitle        = Marshal.GetFunctionPointerForDelegate(_setTitle)
            };

            Engine.StartupPath = _startupPath;

            _packetLengths = new int[byte.MaxValue];

            string json = File.ReadAllText(Path.Combine(_startupPath ?? throw new InvalidOperationException(),
                                                        "packetlengths.json"));

            JObject jsonObj = JObject.Parse(json);

            foreach (JProperty token in jsonObj["PacketLengths"].Children <JProperty>())
            {
                int key = int.Parse(token.Name);
                int val = token.Value.ToObject <int>();

                if (val == 0x8000)
                {
                    val = 0;
                }

                _packetLengths[key] = val;
            }
        }
Exemplo n.º 12
0
        internal static unsafe void InitializePlugin(PluginHeader *plugin)
        {
            _onConnected             = OnConnected;
            _onDisconnected          = OnDisconnected;
            _onReceive               = OnPacketReceive;
            _onSend                  = OnPacketSend;
            _onPlayerPositionChanged = OnPlayerPositionChanged;
            _onClientClosing         = OnClientClosing;
            _onHotkeyPressed         = OnHotkeyPressed;
            _onMouse                 = OnMouse;
            _hWnd = plugin->HWND;

            plugin->OnConnected             = Marshal.GetFunctionPointerForDelegate(_onConnected);
            plugin->OnDisconnected          = Marshal.GetFunctionPointerForDelegate(_onDisconnected);
            plugin->OnRecv                  = Marshal.GetFunctionPointerForDelegate(_onReceive);
            plugin->OnSend                  = Marshal.GetFunctionPointerForDelegate(_onSend);
            plugin->OnPlayerPositionChanged = Marshal.GetFunctionPointerForDelegate(_onPlayerPositionChanged);
            plugin->OnClientClosing         = Marshal.GetFunctionPointerForDelegate(_onClientClosing);
            plugin->OnHotkeyPressed         = Marshal.GetFunctionPointerForDelegate(_onHotkeyPressed);
            plugin->OnMouse                 = Marshal.GetFunctionPointerForDelegate(_onMouse);

            _getPacketLength = Marshal.GetDelegateForFunctionPointer <OnGetPacketLength>(plugin->GetPacketLength);
            _getUOFilePath   = Marshal.GetDelegateForFunctionPointer <OnGetUOFilePath>(plugin->GetUOFilePath);
            _sendToClient    = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(plugin->Recv);
            _sendToServer    = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(plugin->Send);
            _requestMove     = Marshal.GetDelegateForFunctionPointer <RequestMove>(plugin->RequestMove);

            ClientPath = _getUOFilePath();

            if (!Path.IsPathRooted(ClientPath))
            {
                ClientPath = Path.GetFullPath(ClientPath);
            }

            Art.Initialize(ClientPath);
            Hues.Initialize(ClientPath);
            Cliloc.Initialize(ClientPath);
            Skills.Initialize(ClientPath);
            Speech.Initialize(ClientPath);
            TileData.Initialize(ClientPath);
        }
Exemplo n.º 13
0
        public void NewGame(RequestMove input, NotificateGameEvent notificate)
        {
            _input      = input;
            _notificate = notificate;

            bagIndex         = 0;
            timerCounter     = 0;
            tetraminoCounter = 0;

            foreach (Cell c in Matrix)
            {
                c.Status = null;
            }

            _notificate(GameEvent.GameStart);

            if (!_tmr.IsEnabled)
            {
                _tmr.Start();
            }
        }
Exemplo n.º 14
0
        void IControllableUserInput.UpdateInput()
        {
            if (this.actor == null)
            {
                return;
            }

            var velocity = new Vector2(Input.GetAxis("Horizontal"), 0.0f);

            if (velocity.sqrMagnitude > 0.0f)
            {
                this.actor.Broker.Publish(RequestMove.Get(velocity));
            }

            var vertical = Input.GetAxis("Vertical");

            if (vertical < 0.0f)
            {
                this.actor.Broker.Publish(RequestFallOneWayPlatforms.Get());
            }

            if (Input.GetButtonDown("InvokeGameEvent"))
            {
                this.actor.Broker.Publish(RequestInvokeGameEvent.Get());
            }

            if (Input.GetButtonDown("Jump"))
            {
                this.actor.Broker.Publish(RequestJump.Get());
            }

            this.PublishRequestFire(InputName.Fire1, 0);
            this.PublishRequestFire(InputName.Fire2, 1);
            this.PublishRequestFire(InputName.Fire3, 2);

            this.PublishRequestTerminationFire(InputName.Fire1, 0);
            this.PublishRequestTerminationFire(InputName.Fire2, 1);
            this.PublishRequestTerminationFire(InputName.Fire3, 2);
        }
Exemplo n.º 15
0
        internal static bool InstallHooks(PluginHeader *header)
        {
            _sendToClient      = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(header->Recv);
            _sendToServer      = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(header->Send);
            _getPacketLength   = Marshal.GetDelegateForFunctionPointer <OnGetPacketLength>(header->GetPacketLength);
            _getPlayerPosition = Marshal.GetDelegateForFunctionPointer <OnGetPlayerPosition>(header->GetPlayerPosition);
            _castSpell         = Marshal.GetDelegateForFunctionPointer <OnCastSpell>(header->CastSpell);
            _getStaticImage    = Marshal.GetDelegateForFunctionPointer <OnGetStaticImage>(header->GetStaticImage);
            _requestMove       = Marshal.GetDelegateForFunctionPointer <RequestMove>(header->RequestMove);
            ClientWindow       = header->HWND;
            _onTick            = Tick;
            _recv                   = OnRecv;
            _send                   = OnSend;
            _onHotkeyPressed        = OnHotKeyHandler;
            _onMouse                = OnMouseHandler;
            _onUpdatePlayerPosition = OnPlayerPositionChanged;
            _onClientClose          = OnClientClosing;
            _onInitialize           = OnInitialize;
            _onConnected            = OnConnected;
            _onDisconnected         = OnDisconnected;
            // _onFocusGained = OnFocusGained;
            // _onFocusLost = OnFocusLost;

            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);
            header->OnClientClosing         = Marshal.GetFunctionPointerForDelegate(_onClientClose);
            header->OnInitialize            = Marshal.GetFunctionPointerForDelegate(_onInitialize);
            header->OnConnected             = Marshal.GetFunctionPointerForDelegate(_onConnected);
            header->OnDisconnected          = Marshal.GetFunctionPointerForDelegate(_onDisconnected);
            // header->OnFocusGained = Marshal.GetFunctionPointerForDelegate( _onFocusGained );
            // header->OnFocusLost = Marshal.GetFunctionPointerForDelegate( _onFocusLost );
            header->Tick = Marshal.GetFunctionPointerForDelegate(_onTick);

            return(true);
        }
Exemplo n.º 16
0
        public void Load()
        {
            _recv              = OnPluginRecv;
            _send              = OnPluginSend;
            _recv_new          = OnPluginRecv_new;
            _send_new          = OnPluginSend_new;
            _getPacketLength   = PacketsTable.GetPacketLength;
            _getPlayerPosition = GetPlayerPosition;
            _castSpell         = GameActions.CastSpell;
            _getStaticImage    = GetStaticImage;
            _getUoFilePath     = GetUOFilePath;
            _requestMove       = RequestMove;
            _setTitle          = SetWindowTitle;

            SDL.SDL_SysWMinfo info = new SDL.SDL_SysWMinfo();
            SDL.SDL_VERSION(out info.version);
            SDL.SDL_GetWindowWMInfo(SDL.SDL_GL_GetCurrentWindow(), ref info);

            IntPtr hwnd = IntPtr.Zero;

            if (info.subsystem == SDL.SDL_SYSWM_TYPE.SDL_SYSWM_WINDOWS)
            {
                hwnd = info.info.win.window;
            }

            PluginHeader header = new PluginHeader
            {
                ClientVersion     = (int)Client.Version,
                Recv              = Marshal.GetFunctionPointerForDelegate(_recv),
                Send              = Marshal.GetFunctionPointerForDelegate(_send),
                GetPacketLength   = Marshal.GetFunctionPointerForDelegate(_getPacketLength),
                GetPlayerPosition = Marshal.GetFunctionPointerForDelegate(_getPlayerPosition),
                CastSpell         = Marshal.GetFunctionPointerForDelegate(_castSpell),
                GetStaticImage    = Marshal.GetFunctionPointerForDelegate(_getStaticImage),
                HWND              = hwnd,
                GetUOFilePath     = Marshal.GetFunctionPointerForDelegate(_getUoFilePath),
                RequestMove       = Marshal.GetFunctionPointerForDelegate(_requestMove),
                SetTitle          = Marshal.GetFunctionPointerForDelegate(_setTitle),
                Recv_new          = Marshal.GetFunctionPointerForDelegate(_recv_new),
                Send_new          = Marshal.GetFunctionPointerForDelegate(_send_new),

                SDL_Window = Client.Game.Window.Handle
            };

            void *func = &header;

            if (Environment.OSVersion.Platform != PlatformID.Unix && Environment.OSVersion.Platform != PlatformID.MacOSX)
            {
                UnblockPath(Path.GetDirectoryName(_path));
            }

            try
            {
                IntPtr assptr = Native.LoadLibrary(_path);

                Log.Trace($"assembly: {assptr}");

                if (assptr == IntPtr.Zero)
                {
                    throw new Exception("Invalid Assembly, Attempting managed load.");
                }

                Log.Trace($"Searching for 'Install' entry point  -  {assptr}");

                IntPtr installPtr = Native.GetProcessAddress(assptr, "Install");

                Log.Trace($"Entry point: {installPtr}");

                if (installPtr == IntPtr.Zero)
                {
                    throw new Exception("Invalid Entry Point, Attempting managed load.");
                }

                Marshal.GetDelegateForFunctionPointer <OnInstall>(installPtr)(func);

                Console.WriteLine(">>> ADDRESS {0}", header.OnInitialize);
            }
            catch
            {
                try
                {
                    var asm  = Assembly.LoadFile(_path);
                    var type = asm.GetType("Assistant.Engine");

                    if (type == null)
                    {
                        Log.Error(
                            "Unable to find Plugin Type, API requires the public class Engine in namespace Assistant.");

                        return;
                    }

                    var meth = type.GetMethod("Install", BindingFlags.Public | BindingFlags.Static);

                    if (meth == null)
                    {
                        Log.Error("Engine class missing public static Install method Needs 'public static unsafe void Install(PluginHeader *plugin)' ");

                        return;
                    }

                    meth.Invoke(null, new object[] { (IntPtr)func });
                }
                catch (Exception err)
                {
                    Log.Error(
                        $"Plugin threw an error during Initialization. {err.Message} {err.StackTrace} {err.InnerException?.Message} {err.InnerException?.StackTrace}");

                    return;
                }
            }


            if (header.OnRecv != IntPtr.Zero)
            {
                _onRecv = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(header.OnRecv);
            }

            if (header.OnSend != IntPtr.Zero)
            {
                _onSend = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(header.OnSend);
            }

            if (header.OnHotkeyPressed != IntPtr.Zero)
            {
                _onHotkeyPressed = Marshal.GetDelegateForFunctionPointer <OnHotkey>(header.OnHotkeyPressed);
            }

            if (header.OnMouse != IntPtr.Zero)
            {
                _onMouse = Marshal.GetDelegateForFunctionPointer <OnMouse>(header.OnMouse);
            }

            if (header.OnPlayerPositionChanged != IntPtr.Zero)
            {
                _onUpdatePlayerPosition = Marshal.GetDelegateForFunctionPointer <OnUpdatePlayerPosition>(header.OnPlayerPositionChanged);
            }

            if (header.OnClientClosing != IntPtr.Zero)
            {
                _onClientClose = Marshal.GetDelegateForFunctionPointer <OnClientClose>(header.OnClientClosing);
            }

            if (header.OnInitialize != IntPtr.Zero)
            {
                _onInitialize = Marshal.GetDelegateForFunctionPointer <OnInitialize>(header.OnInitialize);
            }

            if (header.OnConnected != IntPtr.Zero)
            {
                _onConnected = Marshal.GetDelegateForFunctionPointer <OnConnected>(header.OnConnected);
            }

            if (header.OnDisconnected != IntPtr.Zero)
            {
                _onDisconnected = Marshal.GetDelegateForFunctionPointer <OnDisconnected>(header.OnDisconnected);
            }

            if (header.OnFocusGained != IntPtr.Zero)
            {
                _onFocusGained = Marshal.GetDelegateForFunctionPointer <OnFocusGained>(header.OnFocusGained);
            }

            if (header.OnFocusLost != IntPtr.Zero)
            {
                _onFocusLost = Marshal.GetDelegateForFunctionPointer <OnFocusLost>(header.OnFocusLost);
            }

            if (header.Tick != IntPtr.Zero)
            {
                _tick = Marshal.GetDelegateForFunctionPointer <OnTick>(header.Tick);
            }


            if (header.OnRecv_new != IntPtr.Zero)
            {
                _onRecv_new = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv_new>(header.OnRecv_new);
            }
            if (header.OnSend_new != IntPtr.Zero)
            {
                _onSend_new = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv_new>(header.OnSend_new);
            }

            if (header.OnDrawCmdList != IntPtr.Zero)
            {
                _draw_cmd_list = Marshal.GetDelegateForFunctionPointer <OnDrawCmdList>(header.OnDrawCmdList);
            }
            if (header.OnWndProc != IntPtr.Zero)
            {
                _on_wnd_proc = Marshal.GetDelegateForFunctionPointer <OnWndProc>(header.OnWndProc);
            }


            IsValid = true;

            _onInitialize?.Invoke();
        }
Exemplo n.º 17
0
        public void Load()
        {
            _recv              = OnPluginRecv;
            _send              = OnPluginSend;
            _getPacketLength   = PacketsTable.GetPacketLength;
            _getPlayerPosition = GetPlayerPosition;
            _castSpell         = GameActions.CastSpell;
            _getStaticImage    = GetStaticImage;
            _getUoFilePath     = GetUOFilePath;
            _requestMove       = RequestMove;
            _setTitle          = SetWindowTitle;

            //IntPtr headerPtr = Marshal.AllocHGlobal(4 + 8 * 18); // 256 ?
            //Marshal.WriteInt32(headerPtr, (int)FileManager.ClientVersion);
            //Marshal.WriteIntPtr(headerPtr, Marshal.GetFunctionPointerForDelegate(_recv));
            //Marshal.WriteIntPtr(headerPtr, Marshal.GetFunctionPointerForDelegate(_send));
            //Marshal.WriteIntPtr(headerPtr, Marshal.GetFunctionPointerForDelegate(_getPacketLength));
            //Marshal.WriteIntPtr(headerPtr, Marshal.GetFunctionPointerForDelegate(_getPlayerPosition));
            //Marshal.WriteIntPtr(headerPtr, Marshal.GetFunctionPointerForDelegate(_castSpell));
            //Marshal.WriteIntPtr(headerPtr, Marshal.GetFunctionPointerForDelegate(_getStaticImage));
            //Marshal.WriteIntPtr(headerPtr, SDL.SDL_GL_GetCurrentWindow());
            //Marshal.WriteIntPtr(headerPtr, Marshal.GetFunctionPointerForDelegate(_getUoFilePath));

            SDL.SDL_SysWMinfo info = new SDL.SDL_SysWMinfo();
            SDL.SDL_VERSION(out info.version);
            SDL.SDL_GetWindowWMInfo(SDL.SDL_GL_GetCurrentWindow(), ref info);

            IntPtr hwnd = IntPtr.Zero;

            if (info.subsystem == SDL.SDL_SYSWM_TYPE.SDL_SYSWM_WINDOWS)
            {
                hwnd = info.info.win.window;
            }

            PluginHeader header = new PluginHeader
            {
                ClientVersion     = (int)FileManager.ClientVersion,
                Recv              = Marshal.GetFunctionPointerForDelegate(_recv),
                Send              = Marshal.GetFunctionPointerForDelegate(_send),
                GetPacketLength   = Marshal.GetFunctionPointerForDelegate(_getPacketLength),
                GetPlayerPosition = Marshal.GetFunctionPointerForDelegate(_getPlayerPosition),
                CastSpell         = Marshal.GetFunctionPointerForDelegate(_castSpell),
                GetStaticImage    = Marshal.GetFunctionPointerForDelegate(_getStaticImage),
                HWND              = hwnd,
                GetUOFilePath     = Marshal.GetFunctionPointerForDelegate(_getUoFilePath),
                RequestMove       = Marshal.GetFunctionPointerForDelegate(_requestMove),
                SetTitle          = Marshal.GetFunctionPointerForDelegate(_setTitle)
            };

            void *func = &header;

            try
            {
                IntPtr assptr = SDL2EX.SDL_LoadObject(_path);

                Log.Message(LogTypes.Trace, $"assembly: {assptr}");

                if (assptr == IntPtr.Zero)
                {
                    throw new Exception("Invalid Assembly, Attempting managed load.");
                }

                Log.Message(LogTypes.Trace, $"Searching for 'Install' entry point  -  {assptr}");

                IntPtr installPtr = SDL2EX.SDL_LoadFunction(assptr, "Install");

                Log.Message(LogTypes.Trace, $"Entry point: {installPtr}");

                if (installPtr == IntPtr.Zero)
                {
                    throw new Exception("Invalid Entry Point, Attempting managed load.");
                }
                Marshal.GetDelegateForFunctionPointer <OnInstall>(installPtr)(ref func);
            }
            catch
            {
                try
                {
                    var asm  = Assembly.LoadFile(_path);
                    var type = asm.GetType("Assistant.Engine");

                    if (type == null)
                    {
                        Log.Message(LogTypes.Error,
                                    $"Unable to find Plugin Type, API requires the public class Engine in namespace Assistant.");
                        return;
                    }

                    var meth = type.GetMethod("Install", BindingFlags.Public | BindingFlags.Static);
                    if (meth == null)
                    {
                        Log.Message(LogTypes.Error, $"Engine class missing public static Install method Needs 'public static unsafe void Install(PluginHeader *plugin)' ");
                        return;
                    }

                    meth.Invoke(null, new object[] { (IntPtr)func });
                }
                catch (Exception err)
                {
                    Log.Message(LogTypes.Error,
                                $"Invalid plugin specified. {err} {err.StackTrace}");
                    return;
                }
            }


            if (header.OnRecv != IntPtr.Zero)
            {
                _onRecv = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(header.OnRecv);
            }
            if (header.OnSend != IntPtr.Zero)
            {
                _onSend = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(header.OnSend);
            }
            if (header.OnHotkeyPressed != IntPtr.Zero)
            {
                _onHotkeyPressed = Marshal.GetDelegateForFunctionPointer <OnHotkey>(header.OnHotkeyPressed);
            }
            if (header.OnMouse != IntPtr.Zero)
            {
                _onMouse = Marshal.GetDelegateForFunctionPointer <OnMouse>(header.OnMouse);
            }
            if (header.OnPlayerPositionChanged != IntPtr.Zero)
            {
                _onUpdatePlayerPosition = Marshal.GetDelegateForFunctionPointer <OnUpdatePlayerPosition>(header.OnPlayerPositionChanged);
            }
            if (header.OnClientClosing != IntPtr.Zero)
            {
                _onClientClose = Marshal.GetDelegateForFunctionPointer <OnClientClose>(header.OnClientClosing);
            }
            if (header.OnInitialize != IntPtr.Zero)
            {
                _onInitialize = Marshal.GetDelegateForFunctionPointer <OnInitialize>(header.OnInitialize);
            }
            if (header.OnConnected != IntPtr.Zero)
            {
                _onConnected = Marshal.GetDelegateForFunctionPointer <OnConnected>(header.OnConnected);
            }
            if (header.OnDisconnected != IntPtr.Zero)
            {
                _onDisconnected = Marshal.GetDelegateForFunctionPointer <OnDisconnected>(header.OnDisconnected);
            }
            if (header.OnFocusGained != IntPtr.Zero)
            {
                _onFocusGained = Marshal.GetDelegateForFunctionPointer <OnFocusGained>(header.OnFocusGained);
            }
            if (header.OnFocusLost != IntPtr.Zero)
            {
                _onFocusLost = Marshal.GetDelegateForFunctionPointer <OnFocusLost>(header.OnFocusLost);
            }
            if (header.Tick != IntPtr.Zero)
            {
                _tick = Marshal.GetDelegateForFunctionPointer <OnTick>(header.Tick);
            }
            IsValid = true;

            //Marshal.FreeHGlobal(headerPtr);

            _onInitialize?.Invoke();
        }
        private void CacheInvalidate(IRingMasterClientCache cache, IRingMasterRequest req)
        {
            if (cache == null || req == null)
            {
                return;
            }

            switch (req.RequestType)
            {
            case RingMasterRequestType.GetData:
            case RingMasterRequestType.GetChildren:
            case RingMasterRequestType.GetAcl:
            case RingMasterRequestType.Exists:
                return;

            case RingMasterRequestType.Create:
            {
                cache.Invalidate(this.cachePrefix, req.Path);
                cache.Invalidate(this.cachePrefix, PrefixedClientCache.GetParent(req.Path));
                break;
            }

            case RingMasterRequestType.Delete:
            {
                RequestDelete delete = req as RequestDelete;

                if (delete.IsCascade)
                {
                    cache.Wipe(this.cachePrefix);
                }
                else
                {
                    cache.Invalidate(this.cachePrefix, req.Path);
                    cache.Invalidate(this.cachePrefix, PrefixedClientCache.GetParent(req.Path));
                }

                break;
            }

            case RingMasterRequestType.Move:
            {
                RequestMove move = req as RequestMove;

                cache.Invalidate(this.cachePrefix, move.Path);
                cache.Invalidate(this.cachePrefix, PrefixedClientCache.GetParent(move.Path));
                cache.Invalidate(this.cachePrefix, PrefixedClientCache.GetParent(move.PathDst));
                break;
            }

            default:
            {
                cache.Invalidate(this.cachePrefix, req.Path);

                AbstractRingMasterCompoundRequest list = req as AbstractRingMasterCompoundRequest;

                if (list != null && list.Requests != null)
                {
                    foreach (IRingMasterRequest child in list.Requests)
                    {
                        this.CacheInvalidate(cache, child);
                    }
                }

                break;
            }
            }
        }
Exemplo n.º 19
0
        public void Load()
        {
            _recv              = OnPluginRecv;
            _send              = OnPluginSend;
            _recv_new          = OnPluginRecv_new;
            _send_new          = OnPluginSend_new;
            _getPacketLength   = PacketsTable.GetPacketLength;
            _getPlayerPosition = GetPlayerPosition;
            _castSpell         = GameActions.CastSpell;
            _getStaticImage    = GetStaticImage;
            _getUoFilePath     = GetUOFilePath;
            _requestMove       = RequestMove;
            _setTitle          = SetWindowTitle;
            _get_static_data   = GetStaticData;
            _get_tile_data     = GetTileData;

            /*
             * SDL.SDL_SysWMinfo info = new SDL.SDL_SysWMinfo();
             * SDL.SDL_VERSION(out info.version);
             * SDL.SDL_GetWindowWMInfo(SDL.SDL_GL_GetCurrentWindow(), ref info);
             *
             * IntPtr hwnd = IntPtr.Zero;
             *
             * if (info.subsystem == SDL.SDL_SYSWM_TYPE.SDL_SYSWM_WINDOWS)
             *  hwnd = info.info.win.window;
             *
             * PluginHeader header = new PluginHeader
             * {
             *  ClientVersion = (int) Client.Version,
             *  Recv = Marshal.GetFunctionPointerForDelegate(_recv),
             *  Send = Marshal.GetFunctionPointerForDelegate(_send),
             *  GetPacketLength = Marshal.GetFunctionPointerForDelegate(_getPacketLength),
             *  GetPlayerPosition = Marshal.GetFunctionPointerForDelegate(_getPlayerPosition),
             *  CastSpell = Marshal.GetFunctionPointerForDelegate(_castSpell),
             *  GetStaticImage = Marshal.GetFunctionPointerForDelegate(_getStaticImage),
             *  HWND = hwnd,
             *  GetUOFilePath = Marshal.GetFunctionPointerForDelegate(_getUoFilePath),
             *  RequestMove = Marshal.GetFunctionPointerForDelegate(_requestMove),
             *  SetTitle = Marshal.GetFunctionPointerForDelegate(_setTitle),
             *  Recv_new = Marshal.GetFunctionPointerForDelegate(_recv_new),
             *  Send_new = Marshal.GetFunctionPointerForDelegate(_send_new),
             *
             *  SDL_Window = Client.Game.Window.Handle,
             *  GetStaticData = Marshal.GetFunctionPointerForDelegate(_get_static_data),
             *  GetTileData =  Marshal.GetFunctionPointerForDelegate(_get_tile_data),
             *
             * };
             *
             * void* func = &header;
             *
             * if(Environment.OSVersion.Platform != PlatformID.Unix && Environment.OSVersion.Platform != PlatformID.MacOSX)
             *  UnblockPath(Path.GetDirectoryName(_path));
             *
             * try
             * {
             *  IntPtr assptr = Native.LoadLibrary(_path);
             *
             *  Log.Trace($"assembly: {assptr}");
             *
             *  if (assptr == IntPtr.Zero)
             *      throw new Exception("Invalid Assembly, Attempting managed load.");
             *
             *  Log.Trace($"Searching for 'Install' entry point  -  {assptr}");
             *
             *  IntPtr installPtr = Native.GetProcessAddress(assptr, "Install");
             *
             *  Log.Trace($"Entry point: {installPtr}");
             *
             *  if (installPtr == IntPtr.Zero)
             *      throw new Exception("Invalid Entry Point, Attempting managed load.");
             *
             *  Marshal.GetDelegateForFunctionPointer<OnInstall>(installPtr)(func);
             *
             *  Console.WriteLine(">>> ADDRESS {0}", header.OnInitialize);
             * }
             * catch
             * {
             *  try
             *  {
             *      var asm = Assembly.LoadFile(_path);
             *      var type = asm.GetType("Assistant.Engine");
             *
             *      if (type == null)
             *      {
             *          Log.Error(
             *                      "Unable to find Plugin Type, API requires the public class Engine in namespace Assistant.");
             *
             *          return;
             *      }
             *
             *      var meth = type.GetMethod("Install", BindingFlags.Public | BindingFlags.Static);
             *
             *      if (meth == null)
             *      {
             *          Log.Error("Engine class missing public static Install method Needs 'public static unsafe void Install(PluginHeader *plugin)' ");
             *
             *          return;
             *      }
             *
             *      meth.Invoke(null, new object[] { (IntPtr) func });
             *  }
             *  catch (Exception err)
             *  {
             *      Log.Error(
             *                  $"Plugin threw an error during Initialization. {err.Message} {err.StackTrace} {err.InnerException?.Message} {err.InnerException?.StackTrace}");
             *
             *      return;
             *  }
             * }
             *
             *
             * if (header.OnRecv != IntPtr.Zero)
             *  _onRecv = Marshal.GetDelegateForFunctionPointer<OnPacketSendRecv>(header.OnRecv);
             *
             * if (header.OnSend != IntPtr.Zero)
             *  _onSend = Marshal.GetDelegateForFunctionPointer<OnPacketSendRecv>(header.OnSend);
             *
             * if (header.OnHotkeyPressed != IntPtr.Zero)
             *  _onHotkeyPressed = Marshal.GetDelegateForFunctionPointer<OnHotkey>(header.OnHotkeyPressed);
             *
             * if (header.OnMouse != IntPtr.Zero)
             *  _onMouse = Marshal.GetDelegateForFunctionPointer<OnMouse>(header.OnMouse);
             *
             * if (header.OnPlayerPositionChanged != IntPtr.Zero)
             *  _onUpdatePlayerPosition = Marshal.GetDelegateForFunctionPointer<OnUpdatePlayerPosition>(header.OnPlayerPositionChanged);
             *
             * if (header.OnClientClosing != IntPtr.Zero)
             *  _onClientClose = Marshal.GetDelegateForFunctionPointer<OnClientClose>(header.OnClientClosing);
             *
             * if (header.OnInitialize != IntPtr.Zero)
             *  _onInitialize = Marshal.GetDelegateForFunctionPointer<OnInitialize>(header.OnInitialize);
             *
             * if (header.OnConnected != IntPtr.Zero)
             *  _onConnected = Marshal.GetDelegateForFunctionPointer<OnConnected>(header.OnConnected);
             *
             * if (header.OnDisconnected != IntPtr.Zero)
             *  _onDisconnected = Marshal.GetDelegateForFunctionPointer<OnDisconnected>(header.OnDisconnected);
             *
             * if (header.OnFocusGained != IntPtr.Zero)
             *  _onFocusGained = Marshal.GetDelegateForFunctionPointer<OnFocusGained>(header.OnFocusGained);
             *
             * if (header.OnFocusLost != IntPtr.Zero)
             *  _onFocusLost = Marshal.GetDelegateForFunctionPointer<OnFocusLost>(header.OnFocusLost);
             *
             * if (header.Tick != IntPtr.Zero)
             *  _tick = Marshal.GetDelegateForFunctionPointer<OnTick>(header.Tick);
             *
             *
             * if (header.OnRecv_new != IntPtr.Zero)
             *  _onRecv_new = Marshal.GetDelegateForFunctionPointer<OnPacketSendRecv_new>(header.OnRecv_new);
             * if (header.OnSend_new != IntPtr.Zero)
             *  _onSend_new = Marshal.GetDelegateForFunctionPointer<OnPacketSendRecv_new>(header.OnSend_new);
             *
             * if (header.OnDrawCmdList != IntPtr.Zero)
             *  _draw_cmd_list = Marshal.GetDelegateForFunctionPointer<OnDrawCmdList>(header.OnDrawCmdList);
             * if (header.OnWndProc != IntPtr.Zero)
             *  _on_wnd_proc = Marshal.GetDelegateForFunctionPointer<OnWndProc>(header.OnWndProc);
             */

#if ENABLE_INTERNAL_ASSISTANT
            if (_path == hardcodedInternalAssistantPath)
            {
                try
                {
                    Assistant.Engine.Install(null);

                    Assistant.Engine.UOSteamClient._sendToClient      = OnPluginRecv;
                    Assistant.Engine.UOSteamClient._sendToServer      = OnPluginSend;
                    Assistant.Engine.UOSteamClient._getPacketLength   = PacketsTable.GetPacketLength;
                    Assistant.Engine.UOSteamClient._getPlayerPosition = GetPlayerPosition;
                    Assistant.Engine.UOSteamClient._castSpell         = GameActions.CastSpell;
                    Assistant.Engine.UOSteamClient._getStaticImage    = GetStaticImage;
                    Assistant.Engine.UOSteamClient._requestMove       = RequestMove;
                    Assistant.Engine.UOSteamClient._setTitle          = SetWindowTitle;
                    Assistant.Engine.UOSteamClient._uoFilePath        = GetUOFilePath;

                    _onRecv                 = Assistant.Engine.UOSteamClient._recv;
                    _onSend                 = Assistant.Engine.UOSteamClient._send;
                    _onHotkeyPressed        = Assistant.Engine.UOSteamClient._onHotkeyPressed;
                    _onMouse                = Assistant.Engine.UOSteamClient._onMouse;
                    _onUpdatePlayerPosition = Assistant.Engine.UOSteamClient._onUpdatePlayerPosition;
                    _onClientClose          = Assistant.Engine.UOSteamClient._onClientClose;
                    _onInitialize           = Assistant.Engine.UOSteamClient._onInitialize;
                    _onConnected            = Assistant.Engine.UOSteamClient._onConnected;
                    _onDisconnected         = Assistant.Engine.UOSteamClient._onDisconnected;
                    _onFocusGained          = Assistant.Engine.UOSteamClient._onFocusGained;
                    _onFocusLost            = Assistant.Engine.UOSteamClient._onFocusLost;
                    _tick = Assistant.Engine.UOSteamClient._tick;
                }
                catch (Exception err)
                {
                    Log.Error(
                        $"Plugin threw an error during Initialization. {err.Message} {err.StackTrace} {err.InnerException?.Message} {err.InnerException?.StackTrace}");

                    return;
                }
            }
#endif

            IsValid = true;

            _onInitialize?.Invoke();
        }