/// <summary> /// Loads the steam library. /// </summary> /// <returns>A value indicating if the load was successful.</returns> /*public static bool LoadSteam() * { * if (SteamHandle != IntPtr.Zero) * return true; * * string path = SteamProcessInfo.SteamInstallPath; * * if (!string.IsNullOrEmpty(path)) * SysNative.SetDllDirectory(path + ";" + Path.Combine(path, "bin")); * * path = Path.Combine(path, "steam.dll"); * * IntPtr module = SysNative.LoadLibraryEx(path, IntPtr.Zero, SysNative.LOAD_WITH_ALTERED_SEARCH_PATH); * * if (module == IntPtr.Zero) * return false; * * _callCreateSteamInterface = SysNative.GetExportFunction<SteamNative._f>(module, "_f"); * if (_callCreateSteamInterface == null) * return false; * * SteamHandle = module; * * return true; * }*/ /// <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 = SteamProcessInfo.SteamInstallPath; if (!string.IsNullOrEmpty(path)) { SysNative.SetDllDirectory(path + ";" + Path.Combine(path, "bin")); } if (SysNative.Is64Bit()) { path = Path.Combine(path, "steamclient64.dll"); } else { path = Path.Combine(path, "steamclient.dll"); } IntPtr module = SysNative.LoadLibraryEx(path, IntPtr.Zero, SysNative.LOAD_WITH_ALTERED_SEARCH_PATH); if (module == IntPtr.Zero) { return(false); } _callCreateInterface = SysNative.GetExportFunction <SteamNative.CreateInterface>(module, "CreateInterface"); if (_callCreateInterface == null) { return(false); } _callSteamBGetCallback = SysNative.GetExportFunction <SteamNative.SteamBGetCallback>(module, "Steam_BGetCallback"); if (_callSteamBGetCallback == null) { return(false); } _callSteamFreeLastCallback = SysNative.GetExportFunction <SteamNative.SteamFreeLastCallback>(module, "Steam_FreeLastCallback"); if (_callSteamFreeLastCallback == null) { return(false); } CallSteamGetAPICallResult = SysNative.GetExportFunction <SteamNative.SteamGetAPICallResult>(module, "Steam_GetAPICallResult"); if (CallSteamGetAPICallResult == null) { return(false); } SteamClientHandle = module; return(true); }
private bool InitSteam() { if (SteamProcessInfo.SteamProcess == null) { Logger.Error("The Steam process could not be located or started. Aborting Steam initialization."); return(false); } if (IsLoaded(SteamClientDllHandle)) { Logger.Info("Steam is already initialized."); return(true); } Logger.Info("Beginning initialization of Steam..."); SysNative.SetDllDirectory(SteamProcessInfo.SteamInstallPath + ";" + Path.Combine(SteamProcessInfo.SteamInstallPath, "bin")); var clientDllHandle = SysNative.LoadLibraryEx(SteamProcessInfo.SteamClientDllPath, IntPtr.Zero, SysNative.LOAD_WITH_ALTERED_SEARCH_PATH); if (!IsLoaded(clientDllHandle)) { Logger.Error("Failed to load the Steam Client DLL. Aborting initialization.", 1); return(false); } _callCreateInterface = SysNative.GetExportFunction <SteamNative.CreateInterface>(clientDllHandle, "CreateInterface"); if (_callCreateInterface == null) { Logger.Error("Failed to retrieve the 'CreateInterface' export function. Aborting initialization.", 1); return(false); } _callCreateSteamPipe = SysNative.GetExportFunction <SteamNative.CreateSteamPipe>(clientDllHandle, "Steam_CreateSteamPipe"); if (_callCreateSteamPipe == null) { Logger.Error("Failed to retrieve the 'Steam_CreateSteamPipe' export function. Aborting initialization.", 1); return(false); } _callBReleaseSteamPipe = SysNative.GetExportFunction <SteamNative.BReleaseSteamPipe>(clientDllHandle, "Steam_BReleaseSteamPipe"); if (_callBReleaseSteamPipe == null) { Logger.Error("Failed to retrieve the 'Steam_BReleaseSteamPipe' export function. Aborting initialization.", 1); return(false); } _callConnectToGlobalUser = SysNative.GetExportFunction <SteamNative.ConnectToGlobalUser>(clientDllHandle, "Steam_ConnectToGlobalUser"); if (_callConnectToGlobalUser == null) { Logger.Error("Failed to retrieve the 'Steam_ConnectToGlobalUser' export function. Aborting initialization.", 1); return(false); } _callReleaseUser = SysNative.GetExportFunction <SteamNative.ReleaseUser>(clientDllHandle, "Steam_ReleaseUser"); if (_callReleaseUser == null) { Logger.Error("Failed to retrieve the 'Steam_ReleaseUser' export function. Aborting initialization.", 1); return(false); } Pipe = CreateSteamPipe(); if (!IsValidPipe(Pipe)) { Logger.Error("Failed to create a Steam pipe (IPC). Aborting initialization.", 1); return(false); } User = ConnectToGlobalUser(Pipe); if (!IsValidUser(User)) { Logger.Error("Failed to connect to Steam global user (IPC). Aborting initialization.", 1); return(false); } SteamClientDllHandle = clientDllHandle; Logger.Info("Steam initialization succeeded!", 1); return(true); }