Ejemplo n.º 1
0
        /// <summary>
        /// Gets the Steam process ID from the registry; returns 0 if Steam isn't running or isn't installed.
        /// </summary>
        /// <returns>Steam's process ID if it is running; otherwise, 0.</returns>
        public static int GetSteamPid()
        {
            if (!IsSteamInstalled)
            {
                return(0);
            }

            string pidRegKey;
            string pidRegName;

            if (SysNative.Is64Bit())
            {
                pidRegKey  = @"HKEY_CURRENT_USER\Software\Valve\Steam\ActiveProcess";
                pidRegName = "pid";
            }
            else
            {
                pidRegKey  = @"HKEY_LOCAL_MACHINE\Software\Valve\Steam";
                pidRegName = "SteamPID";
            }

            Logger.Info($"Attempting to retrieve Steam PID from registry value named '{pidRegName}' inside the key '{pidRegKey}'.");
            var pid = (int)Registry.GetValue(pidRegKey, pidRegName, -1);

            if (pid == -1)
            {
                Logger.Warning($"The Steam PID could not be retrieved because the registry value '{pidRegName}' or registry key '{pidRegKey}' was invalid or did not exist.");
                return(0);
            }

            Logger.Info($"The Steam PID value retrieved from the registry is '{pid}'.");
            return(pid);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieves the Steam installation path from the registry or returns null if not found.
        /// </summary>
        /// <returns>A string containing the Steam installation path; if not found, returns null.</returns>
        private static string GetSteamInstallPath()
        {
            string installPath;

            if (SysNative.Is64Bit())
            {
                installPath = (string)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Valve\Steam", "SteamPath", null);
            }
            else
            {
                installPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\Software\Valve\Steam", "InstallPath", null);
            }

            if (installPath == null)
            {
                const string errorMsg = "No valid Steam installation path could be found.";
                Logger.Error(errorMsg);
                throw new InvalidOperationException(errorMsg);
            }

            installPath = installPath.Replace("/", @"\");
            Logger.Info($"Setting Steam installation path to: '{installPath}'");

            return(installPath);
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the path of the Steam Client DLL.
        /// </summary>
        /// <returns>A string containing the Steam Client DLL path; if not found, returns null.</returns>
        private static string GetSteamClientDllPath()
        {
            if (string.IsNullOrWhiteSpace(SteamInstallPath))
            {
                return(null);
            }

            var dllPath = Path.Combine(SteamInstallPath, SysNative.Is64Bit() ? "steamclient64.dll" : "steamclient.dll");

            Logger.Info($"Setting Steam Client DLL path to: '{dllPath}'");

            return(dllPath);
        }
Ejemplo n.º 5
0
        public LaunchViaSteamMenuItem()
        {
            var defaultConfigLoaded = false;

            try
            {
                // Try to load the plugin's configuration file
                Config.Load();
            }
            catch (FileNotFoundException ex)
            {
                // Load default values if no configuration file is found
                Config.Default();
                defaultConfigLoaded = true;
            }

            // Enable debug logging if enabled in the config
            if (Config.Instance.DebugLogEnabled)
            {
                try
                {
                    Logger.EnableDebugLog(Config.LOG_PATH);
                }
                catch (Exception ex)
                {
                    Logger.Error("An error occurred while attempting to enable debug logging to file. " +
                                 $"Debug messages will only be output to console. Exception: {ex.Message}");
                }
            }

            if (defaultConfigLoaded)
            {
                Logger.Warning($"The configuration file '{Config.CONFIG_FILENAME}' could not be found. Loading defaults.");
            }

            Logger.Info($"SteamLauncher plugin loaded ({(SysNative.Is64Bit() ? "64-bit" : "32-bit")} mode).");

            _activeWindow = new ActiveWindow();
        }