コード例 #1
0
        public static Exception Initialize()
        {
            Exception exception = null;

            var tessApiType = typeof(Tesseract.Page).Assembly.GetType("Tesseract.Interop.TessApi");
            var leptApiType = typeof(Tesseract.Page).Assembly.GetType("Tesseract.Interop.LeptonicaApi");

            var tessApiCustomType = CreateInterfaceType <ITessApiSignatures>("tesseract41", "tesseract", "4");
            var leptApiCustomType = CreateInterfaceType <ILeptonicaApiSignatures>("leptonica-1.80.0", "lept", "5");

            var loader = new NativeLoader();

            loader.WindowsOptions.UseSetDllDirectory = true;

            try
            {
                var tessApiInstance = (ITessApiSignatures)loader.CreateInstance(tessApiCustomType);
                var leptApiInstance = (ILeptonicaApiSignatures)loader.CreateInstance(leptApiCustomType);

                tessApiType.GetField("native", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, tessApiInstance);
                leptApiType.GetField("native", BindingFlags.NonPublic | BindingFlags.Static).SetValue(null, leptApiInstance);
            }
            catch (TargetInvocationException e)
            {
                exception = e.InnerException;
            }
            catch (Exception e)
            {
                exception = e;
            }

            return(exception);
        }
コード例 #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="MultiProcessGameModeClient" /> class.
 /// </summary>
 /// <param name="startBehaviour">The start method.</param>
 /// <param name="gameModeProvider">The game mode provider.</param>
 /// <param name="encoding">The encoding to use when en/decoding text messages sent to/from the server.</param>
 public HostedGameModeClient(GameModeStartBehaviour startBehaviour, IGameModeProvider gameModeProvider, Encoding encoding)
 {
     Encoding          = encoding;
     _startBehaviour   = startBehaviour;
     _gameModeProvider = gameModeProvider ?? throw new ArgumentNullException(nameof(gameModeProvider));
     NativeLoader      = new NativeLoader(this);
 }
コード例 #3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="MultiProcessGameModeClient" /> class.
 /// </summary>
 /// <param name="communicationClient">The communication client to be used by the game mode client.</param>
 /// <param name="startBehaviour">The start method.</param>
 /// <param name="gameModeProvider">The game mode provider.</param>
 /// <param name="encoding">The encoding to use when en/decoding text messages sent to/from the server.</param>
 public MultiProcessGameModeClient(ICommunicationClient communicationClient, GameModeStartBehaviour startBehaviour, IGameModeProvider gameModeProvider, Encoding encoding)
 {
     Encoding            = encoding;
     _startBehaviour     = startBehaviour;
     _gameModeProvider   = gameModeProvider ?? throw new ArgumentNullException(nameof(gameModeProvider));
     CommunicationClient = communicationClient ?? throw new ArgumentNullException(nameof(communicationClient));
     NativeLoader        = new NativeLoader(this);
 }
コード例 #4
0
 public Interpreter()
 {
     debug       = false;
     local_scope = global_scope;
     NativeLoader.load_natives(this);
     this.loader = new Loader(this);
     this.loader.load_builtin_lib();
     ExceptionManager.interpreter = this;
 }
コード例 #5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="MultiProcessGameModeClient" /> class.
        /// </summary>
        /// <param name="gameModeProvider">The game mode provider.</param>
        /// <param name="encoding">The encoding to use when en/decoding text messages sent to/from the server.</param>
        public HostedGameModeClient(IGameModeProvider gameModeProvider, Encoding encoding)
        {
            Encoding          = encoding;
            _gameModeProvider = gameModeProvider ?? throw new ArgumentNullException(nameof(gameModeProvider));
            NativeLoader      = new NativeLoader(this);
            _buffer           = Marshal.AllocHGlobal(_txBufferLength = 1024 * 6);
            _buffer1K         = Marshal.AllocHGlobal(1024);

            ServerPath = AppContext.BaseDirectory;
        }
コード例 #6
0
 static Native()
 {
     if (PlatformHelper.IsWindows)
     {
         _loader = new WinNativeLoader();
     }
     else
     {
         _loader = new UnixNativeLoader();
     }
 }
コード例 #7
0
ファイル: Native.cs プロジェクト: zerodowned/ClassicUO
 static Native()
 {
     if (SDL2.SDL.SDL_GetPlatform() != "Windows")
     {
         _loader = new UnixNativeLoader();
     }
     else
     {
         _loader = new WinNativeLoader();
     }
 }
コード例 #8
0
 static Native()
 {
     if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX)
     {
         _loader = new UnixNativeLoader();
     }
     else
     {
         _loader = new WinNativeLoader();
     }
 }
コード例 #9
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="MultiProcessGameModeClient" /> class.
 /// </summary>
 /// <param name="communicationClient">The communication client to be used by the game mode client.</param>
 /// <param name="startBehaviour">The start method.</param>
 /// <param name="gameModeProvider">The game mode provider.</param>
 /// <param name="encoding">The encoding to use when en/decoding text messages sent to/from the server.</param>
 public MultiProcessGameModeClient(ICommunicationClient communicationClient, GameModeStartBehaviour startBehaviour, IGameModeProvider gameModeProvider, Encoding encoding)
 {
     Encoding            = encoding;
     _startBehaviour     = startBehaviour;
     _gameModeProvider   = gameModeProvider ?? throw new ArgumentNullException(nameof(gameModeProvider));
     CommunicationClient = communicationClient ?? throw new ArgumentNullException(nameof(communicationClient));
     NativeLoader        = new NativeLoader(this);
     _console            = new StreamWriter(Console.OpenStandardOutput())
     {
         AutoFlush = true
     };
 }
コード例 #10
0
        public static ToolStripMenuItem GetOpenAppMenuItem()
        {
            var item = new ToolStripMenuItem(Env.OpenAppText);
            var exe  = Reg.GetExePath();

            item.Click += (sender, args) =>
            {
                Cmd.RunAsInvoker(exe, "");
            };
            item.Image = NativeLoader.GetShell32Icon(2);
            return(item);
        }
コード例 #11
0
 private void Awake()
 {
     if (instance != null && instance.plugin.PluginName == plugin.PluginName)
     {
         Destroy(this.gameObject);
         return;
     }
     DontDestroyOnLoad(this.gameObject);
     instance = this;
     LoadPlugin();
     InitPlugin();
     SceneManager.sceneLoaded += OnSceneLoaded;
 }
コード例 #12
0
        public static ToolStripMenuItem GetCreateDirecotyCommandFileMenuItem(string path)
        {
            var item = new ToolStripMenuItem(Env.CreateFolderSpecificFileText);

            item.Click += (sender, args) =>
            {
                var o = new DirectoryCommand[]
                {
                    new DirectoryCommand()
                    {
                        Name = "Custom Command", Command = "cmd"
                    },
                };
                Yaml.SaveYaml(path, o);
                File.SetAttributes(path, FileAttributes.Hidden);
            };
            item.Image = NativeLoader.GetShell32Icon(70);
            return(item);
        }
コード例 #13
0
        public ToolStripItem ToMenuItem(string workingDir)
        {
            if (string.IsNullOrEmpty(Command) && Name == Env.VAR_SEPNAME)
            {
                return(new ToolStripSeparator());
            }

            var display = string.IsNullOrEmpty(Name) ? Command : Name;
            var item    = new ToolStripMenuItem(display)
            {
                Enabled = IsMatch(workingDir),
            };

            item.Click += (sender, args) =>
            {
                Execute(workingDir);
            };
            if (!string.IsNullOrEmpty(Icon))
            {
                var exIcon = ExpandEnvVars(Icon, workingDir);
                item.Image = NativeLoader.LocaImage(exIcon);
            }
            return(item);
        }
コード例 #14
0
 public void Initialize()
 {
     NativeLoader.Setup();
 }
コード例 #15
0
        private void FakeGmxRotate()
        {
            _callbacks.TryGetValue("OnIncomingConnection", out var onIncomingConnection);
            _callbacks.TryGetValue("OnPlayerConnect", out var onPlayerConnect);
            _callbacks.TryGetValue("OnPlayerRequestClass", out var onPlayerRequestClass);

            var natIsPlayerConnected = NativeLoader.Load("IsPlayerConnected", new[]
            {
                NativeParameterInfo.ForType(typeof(int))
            });
            var natGetPlayerPoolSize   = NativeLoader.Load("GetPlayerPoolSize", new NativeParameterInfo[0]);
            var natForceClassSelection =
                NativeLoader.Load("ForceClassSelection", new[]
            {
                NativeParameterInfo.ForType(typeof(int))
            });
            var natTogglePlayerSpectating = NativeLoader.Load("TogglePlayerSpectating",
                                                              new[]
            {
                NativeParameterInfo.ForType(typeof(int)),
                NativeParameterInfo.ForType(typeof(int))
            });
            var natGetPlayerIp = NativeLoader.Load("GetPlayerIp",
                                                   new[]
            {
                NativeParameterInfo.ForType(typeof(int)),
                new NativeParameterInfo(NativeParameterType.StringReference, 2, true),
                NativeParameterInfo.ForType(typeof(int)),
            });

            var poolSize = natGetPlayerPoolSize.Invoke();

            for (var i = 0; i <= poolSize; i++)
            {
                var isConnected = natIsPlayerConnected.Invoke(i);

                if (isConnected == 0)
                {
                    continue;
                }

                var args = new object[] { i, null, 16 };
                natGetPlayerIp.Invoke(args);

                if (args[1] is string ip)
                {
                    onIncomingConnection?.Invoke(
                        ValueConverter.GetBytes(i)
                        .Concat(ValueConverter.GetBytes(ip, Encoding.ASCII))
                        .Concat(ValueConverter.GetBytes(9999999))
                        .ToArray(), 0);
                }

                onPlayerConnect?.Invoke(ValueConverter.GetBytes(i), 0);

                natForceClassSelection.Invoke(i);
                natTogglePlayerSpectating.Invoke(i, 1);
                natTogglePlayerSpectating.Invoke(i, 0);

                onPlayerRequestClass?.Invoke(
                    ValueConverter.GetBytes(i)
                    .Concat(ValueConverter.GetBytes(0))
                    .ToArray(), 0);
            }
        }
コード例 #16
0
        private void ProcessCommand(ServerCommandData data)
        {
            switch (data.Command)
            {
            case ServerCommand.Tick:
                if (!_canTick)
                {
                    break;
                }

                _gameModeProvider.Tick();

                // The server expects at least a message every 5 seconds or else the debug pause
                // detector kicks in. Send one at least every 3 to be safe.
                if (DateTime.UtcNow - _lastSend > TimeSpan.FromSeconds(3))
                {
                    Send(ServerCommand.Alive, null);
                }

                break;

            case ServerCommand.Pong:
                if (_pongs.Count == 0)
                {
                    CoreLog.Log(CoreLogLevel.Error, "Received a random pong");
                    CoreLog.Log(CoreLogLevel.Debug, Environment.StackTrace);
                }
                else
                {
                    _pongs.Dequeue().Pong();
                }
                break;

            case ServerCommand.Announce:
                CoreLog.Log(CoreLogLevel.Error, "Received a random server announcement");
                CoreLog.Log(CoreLogLevel.Debug, Environment.StackTrace);
                break;

            case ServerCommand.PublicCall:
                var name   = ValueConverter.ToString(data.Data, 0, Encoding);
                var isInit = name == "OnGameModeInit";

                if (CoreLog.DoesLog(CoreLogLevel.Verbose))
                {
                    CoreLog.LogVerbose("Incoming public call: {0}", name);
                }

                if ((_startBehaviour == GameModeStartBehaviour.Gmx || _startBehaviour == GameModeStartBehaviour.FakeGmx) && !_initReceived &&
                    !isInit)
                {
                    CoreLog.Log(CoreLogLevel.Debug, $"Skipping callback {name} because OnGameModeInit has not yet been called");
                    Send(ServerCommand.Response, AZero);
                    break;
                }

                var isFirstInit = isInit && !_initReceived;
                if (isFirstInit)
                {
                    _initReceived = true;
                }

                if (_callbacks.TryGetValue(name, out var callback))
                {
                    int?result = null;
                    try
                    {
                        result = callback.Invoke(data.Data, name.Length + 1);

                        CoreLog.LogVerbose("Public call response for {0}: {1}", name, result);
                    }
                    catch (Exception e)
                    {
                        OnUnhandledException(new UnhandledExceptionEventArgs(e));
                    }

                    Send(ServerCommand.Response,
                         result != null
                                ? AOne.Concat(ValueConverter.GetBytes(result.Value))
                                : AZero);
                }
                else
                {
                    CoreLog.Log(CoreLogLevel.Error, "Received unknown callback " + name);
                    CoreLog.Log(CoreLogLevel.Debug, Environment.StackTrace);
                }

                if (isFirstInit)
                {
                    if (_startBehaviour == GameModeStartBehaviour.FakeGmx)
                    {
                        _callbacks.TryGetValue("OnIncomingConnection", out var onIncomingConnection);
                        _callbacks.TryGetValue("OnPlayerConnect", out var onPlayerConnect);
                        _callbacks.TryGetValue("OnPlayerRequestClass", out var onPlayerRequestClass);

                        var natIsPlayerConnected = NativeLoader.Load("IsPlayerConnected", new[]
                        {
                            NativeParameterInfo.ForType(typeof(int))
                        });
                        var natGetPlayerPoolSize   = NativeLoader.Load("GetPlayerPoolSize", new NativeParameterInfo[0]);
                        var natForceClassSelection =
                            NativeLoader.Load("ForceClassSelection", new[]
                        {
                            NativeParameterInfo.ForType(typeof(int))
                        });
                        var natTogglePlayerSpectating = NativeLoader.Load("TogglePlayerSpectating",
                                                                          new[]
                        {
                            NativeParameterInfo.ForType(typeof(int)),
                            NativeParameterInfo.ForType(typeof(int))
                        });
                        var natGetPlayerIp = NativeLoader.Load("GetPlayerIp",
                                                               new[]
                        {
                            NativeParameterInfo.ForType(typeof(int)),
                            new NativeParameterInfo(NativeParameterType.StringReference, 2),
                            NativeParameterInfo.ForType(typeof(int)),
                        });

                        var poolSize = natGetPlayerPoolSize.Invoke();
                        for (var i = 0; i <= poolSize; i++)
                        {
                            var isConnected = natIsPlayerConnected.Invoke(i);

                            if (isConnected == 0)
                            {
                                continue;
                            }

                            var args = new object[] { i, null, 16 };
                            natGetPlayerIp.Invoke(args);

                            if (args[1] is string ip)
                            {
                                onIncomingConnection?.Invoke(
                                    ValueConverter.GetBytes(i)
                                    .Concat(ValueConverter.GetBytes(ip, Encoding.ASCII))
                                    .Concat(ValueConverter.GetBytes(9999999))
                                    .ToArray(), 0);
                            }

                            onPlayerConnect?.Invoke(ValueConverter.GetBytes(i), 0);

                            natForceClassSelection.Invoke(i);
                            natTogglePlayerSpectating.Invoke(i, 1);
                            natTogglePlayerSpectating.Invoke(i, 0);

                            onPlayerRequestClass?.Invoke(
                                ValueConverter.GetBytes(i)
                                .Concat(ValueConverter.GetBytes(0))
                                .ToArray(), 0);
                        }
                    }

                    _canTick = true;
                }
                else if (_initReceived && name == "OnGameModeExit")
                {
                    CoreLog.Log(CoreLogLevel.Info, "OnGameModeExit received, sending reconnect signal...");
                    Send(ServerCommand.Reconnect, null);

                    // Give the server time to receive the reconnect signal.
                    // TODO: This is an ugly freeze/comms-deadlock fix.
                    Thread.Sleep(100);

                    CleanUp();
                }
                break;

            default:
                CoreLog.Log(CoreLogLevel.Error, $"Unknown command {data.Command} recieved with {data.Data?.Length.ToString() ?? "NULL"} data");
                CoreLog.Log(CoreLogLevel.Debug, Environment.StackTrace);
                break;
            }
        }
コード例 #17
0
ファイル: ClientTests.cs プロジェクト: zYg-sys/scaliendb
 public ClientTests()
 {
     NativeLoader.Load();
 }