示例#1
0
        internal static TClass CreateInterface <TClass>(string module, int offset = 0)
            where TClass : InteropHelp.INativeWrapper, new()
        {
            try
            {
                ProcessModule procModule = null;

                foreach (ProcessModule m in Process.GetCurrentProcess().Modules)
                {
                    if (m.ModuleName == module)
                    {
                        procModule = m;
                    }
                }

                if (procModule == null)
                {
                    throw new DotaException($"Can't find Module '{module}'");
                }

                IntPtr addrModule = WinImports.LoadLibraryEx(procModule.FileName, IntPtr.Zero,
                                                             WinImports.LoadLibraryFlags.LoadWithAlteredSearchPath);

                if (addrModule == IntPtr.Zero)
                {
                    throw new DotaException($"Can't load Module '{module}'");
                }

                m_callCreateInterface = Native.GetExportFunction <Native.CreateInterface>(addrModule, "CreateInterface");

                if (m_callCreateInterface == null)
                {
                    throw new DotaException($"Interface wasn't created - Module '{module}'");
                }

                IntPtr address = m_callCreateInterface(InterfaceVersions.GetInterfaceIdentifier(typeof(TClass)),
                                                       IntPtr.Zero);

                if (address == IntPtr.Zero)
                {
                    throw new DotaException($"Interface Identifier failed - Module '{module}'");
                }

                if (offset > 0)
                {
                    address = address + offset;
                }


                TClass result = new TClass();
                result.SetupFunctions(address);

                return(result);
            }
            catch (DotaException)
            {
                return(default(TClass));
            }
        }
示例#2
0
        /// <summary>
        /// Loads the steamclient library.
        /// </summary>
        /// <returns>A value indicating if the load was successful.</returns>
        public static bool LoadSteamClient()
        {
            if (SteamClientHandle != IntPtr.Zero)
            {
                return(true);
            }

            string path = GetInstallPath();

            if (!string.IsNullOrEmpty(path))
            {
                Native.SetDllDirectory(path + ";" + Path.Combine(path, "bin"));
            }

            if (Is64Bit())
            {
                path = Path.Combine(path, "steamclient64.dll");
            }
            else
            {
                path = Path.Combine(path, "steamclient.dll");
            }

            IntPtr module = Native.LoadLibraryEx(path, IntPtr.Zero, Native.LOAD_WITH_ALTERED_SEARCH_PATH);

            if (module == IntPtr.Zero)
            {
                return(false);
            }

            CallCreateInterface = Native.GetExportFunction <Native.CreateInterface>(module, "CreateInterface");
            if (CallCreateInterface == null)
            {
                return(false);
            }

            CallSteamBGetCallback = Native.GetExportFunction <Native.SteamBGetCallback>(module, "Steam_BGetCallback");
            if (CallSteamBGetCallback == null)
            {
                return(false);
            }

            CallSteamFreeLastCallback = Native.GetExportFunction <Native.SteamFreeLastCallback>(module, "Steam_FreeLastCallback");
            if (CallSteamFreeLastCallback == null)
            {
                return(false);
            }

            CallSteamGetAPICallResult = Native.GetExportFunction <Native.SteamGetAPICallResult>(module, "Steam_GetAPICallResult");
            if (CallSteamGetAPICallResult == null)
            {
                return(false);
            }

            SteamClientHandle = module;

            return(true);
        }