Esempio n. 1
0
        public XayaWrapper(string dataPath, string host_s, string gamehostport_s, ref string result, InitialCallback inCal, ForwardCallback forCal, BackwardCallback backCal)
        {
            if (!NativeMethods.SetDllDirectory(dataPath + "\\..\\XayaStateProcessor\\"))
            {
                result = "Could not set dll directory";
                return;
            }

            string path = dataPath.Replace("/", "\\") + "\\..\\XayaStateProcessor\\libxayawrap.dll";

            pDll = NativeMethods.LoadLibrary(dataPath.Replace("/", "\\") + "\\..\\XayaStateProcessor\\libxayawrap.dll");
            //Console.WriteLine("error: " + Marshal.GetLastWin32Error());

            if (pDll == IntPtr.Zero)
            {
                result = "Could not load " + dataPath.Replace("/", "\\") + "\\..\\XayaStateProcessor\\libxayawrap.dll";
                return;
            }

            IntPtr pSetInitialCallback = NativeMethods.GetProcAddress(pDll, "setInitialCallback");

            if (pSetInitialCallback == IntPtr.Zero)
            {
                result = "Could not load resolve setInitialCallback";
                return;
            }

            IntPtr pSetForwardCallback = NativeMethods.GetProcAddress(pDll, "setForwardCallback");

            if (pSetForwardCallback == IntPtr.Zero)
            {
                result = "Could not load resolve pSetForwardCallback";
                return;
            }

            IntPtr pSetBackwardCallback = NativeMethods.GetProcAddress(pDll, "setBackwardCallback");

            if (pSetBackwardCallback == IntPtr.Zero)
            {
                result = "Could not load resolve pSetBackwardCallback";
                return;
            }

            setInitialCallback  SetInitialCallback  = (setInitialCallback)Marshal.GetDelegateForFunctionPointer(pSetInitialCallback, typeof(setInitialCallback));
            setForwardCallback  SetForwardlCallback = (setForwardCallback)Marshal.GetDelegateForFunctionPointer(pSetForwardCallback, typeof(setForwardCallback));
            setBackwardCallback SetBackwardCallback = (setBackwardCallback)Marshal.GetDelegateForFunctionPointer(pSetBackwardCallback, typeof(setBackwardCallback));

            initialCallback = new InitialCallback(inCal);
            SetInitialCallback(initialCallback);

            forwardCallback = new ForwardCallback(forCal);
            SetForwardlCallback(forwardCallback);

            backwardsCallback = new BackwardCallback(backCal);
            SetBackwardCallback(backwardsCallback);

            xayaGameService = new XAYAService(host_s + ":" + gamehostport_s, "", "", "");
            IsConnected     = true;
            result          = "Wrapper Initialised";
        }
        public XayaWrapper(string dllDirectoryPath, string host_s, string gamehostport_s, ref string result, InitialCallback inCal, ForwardCallback forCal, BackwardCallback backCal)
        {
            if (!NativeMethods.SetDllDirectory(dllDirectoryPath))
            {
                result = "Could not set dll directory";
                return;
            }

            pDll = NativeMethods.LoadLibrary(dllDirectoryPath + "libxayawrap.dll");


            if (pDll == IntPtr.Zero)
            {
                result = "Could not load " + dllDirectoryPath + "libxayawrap.dll";
                return;
            }

            IntPtr pSetInitialCallback = NativeMethods.GetProcAddress(pDll, "setInitialCallback");

            if (pSetInitialCallback == IntPtr.Zero)
            {
                result = "Could not load resolve setInitialCallback";
                return;
            }

            IntPtr pSetForwardCallback = NativeMethods.GetProcAddress(pDll, "setForwardCallback");

            if (pSetForwardCallback == IntPtr.Zero)
            {
                result = "Could not load resolve pSetForwardCallback";
                return;
            }

            IntPtr pSetBackwardCallback = NativeMethods.GetProcAddress(pDll, "setBackwardCallback");

            if (pSetBackwardCallback == IntPtr.Zero)
            {
                result = "Could not load resolve pSetBackwardCallback";
                return;
            }

            setInitialCallback  SetInitialCallback  = (setInitialCallback)Marshal.GetDelegateForFunctionPointer(pSetInitialCallback, typeof(setInitialCallback));
            setForwardCallback  SetForwardlCallback = (setForwardCallback)Marshal.GetDelegateForFunctionPointer(pSetForwardCallback, typeof(setForwardCallback));
            setBackwardCallback SetBackwardCallback = (setBackwardCallback)Marshal.GetDelegateForFunctionPointer(pSetBackwardCallback, typeof(setBackwardCallback));

            initialCallback = new InitialCallback(inCal);
            SetInitialCallback(initialCallback);

            forwardCallback = new ForwardCallback(forCal);
            SetForwardlCallback(forwardCallback);

            backwardsCallback = new BackwardCallback(backCal);
            SetBackwardCallback(backwardsCallback);

            xayaGameService = new XAYAService(host_s + ":" + gamehostport_s, "", "", "");


            result = "Wrapper Initialised";
        }