Skip to content

Instantly share code, notes, and snippets.

@XtraCube
Last active January 29, 2025 20:17
Show Gist options
  • Select an option

  • Save XtraCube/a644ef40c3feb1026bce2c44210ff64c to your computer and use it in GitHub Desktop.

Select an option

Save XtraCube/a644ef40c3feb1026bce2c44210ff64c to your computer and use it in GitHub Desktop.
AmongUsLocator Utility Class to find Among Us automatically.
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Microsoft.Win32;
public enum AmongUsPlatform
{
Steam,
Itch,
Epic
}
public static class AmongUsLocator
{
private const string EosDllRelativePath = "Among Us_Data/Plugins/x86/GfxPluginEGS.dll";
public static string FileToHash(string path)
{
if (!File.Exists(path)) return "";
var array = SHA256.HashData(File.ReadAllBytes(path));
return string.Concat(array.Select(x => x.ToString("x2")));
}
public static AmongUsPlatform? GetPlatform(string path, string steamHash)
{
if (!VerifyAmongUsDirectory(path))
{
return null;
}
if (File.Exists(Path.GetFullPath(EosDllRelativePath, path)))
{
return AmongUsPlatform.Epic;
}
var globalGameFile = new FileInfo(Path.Combine(path, "Among Us_Data", "globalgamemanagers"));
if (!globalGameFile.Exists)
{
return null;
}
var hash = Utilities.FileToHash(globalGameFile.FullName);
return hash == steamHash ? AmongUsPlatform.Steam : AmongUsPlatform.Itch;
}
// return among us path by checking processes first, then registry
public static string? FindAmongUs()
{
var processes = Process.GetProcessesByName("Among Us");
if (processes.Length <= 0)
{
if (UpdatePathFromRegistry() is { } pathFromRegistry)
{
return VerifyAmongUsDirectory(pathFromRegistry) ? pathFromRegistry : null;
}
return null;
}
var path = Path.GetDirectoryName(processes.First().GetMainModuleFileName());
return VerifyAmongUsDirectory(path) ? path : null;
}
// Finds among us from registry location
private static string? UpdatePathFromRegistry()
{
if (!OperatingSystem.IsWindows())
{
return null;
}
var registryEntry = Registry.GetValue(@"HKEY_CLASSES_ROOT\amongus\DefaultIcon", "", null);
if (registryEntry is not string path)
{
return null;
}
var indexOfExe = path.LastIndexOf("Among Us.exe", StringComparison.OrdinalIgnoreCase);
return path.Substring(1,Math.Max(indexOfExe - 1,0));
}
public static bool VerifyAmongUsDirectory(string? path)
{
return path is not null && Directory.Exists(path) && File.Exists(Path.Combine(path, "Among Us.exe"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment