improve comments/documentation

This commit is contained in:
_nebula 2023-09-18 09:48:25 +01:00
parent 06715cacc1
commit 2d00330d86
3 changed files with 32 additions and 5 deletions

View File

@ -133,7 +133,7 @@ public class QSBCore : ModBehaviour
if (GameVendor != GameVendor.Steam) if (GameVendor != GameVendor.Steam)
{ {
DebugLog.ToConsole($"Not steam, initializing Steamworks..."); DebugLog.DebugWrite($"Not steam, initializing Steamworks...");
if (!Packsize.Test()) if (!Packsize.Test())
{ {
@ -146,6 +146,12 @@ public class QSBCore : ModBehaviour
} }
// from facepunch.steamworks SteamClient.cs // from facepunch.steamworks SteamClient.cs
// Normally, Steam sets these env vars when launching the game through the Steam library.
// These would also be set when running the .exe directly, thanks to Steam's "DRM" in the exe.
// We're setting these manually to 480 - an AppID that every Steam account owns by default.
// This tells Steam and Steamworks that the user is playing a game they own.
// This lets anyone use Steamworks, even if they don't own Outer Wilds.
// We also don't have to worry about Steam achievements or DLC in this case.
Environment.SetEnvironmentVariable("SteamAppId", "480"); Environment.SetEnvironmentVariable("SteamAppId", "480");
Environment.SetEnvironmentVariable("SteamGameId", "480"); Environment.SetEnvironmentVariable("SteamGameId", "480");
@ -161,24 +167,40 @@ public class QSBCore : ModBehaviour
{ {
SteamRerouter.ModSide.Interop.Init(); SteamRerouter.ModSide.Interop.Init();
DebugLog.ToConsole($"Is steam - overriding AppID"); DebugLog.DebugWrite($"Is steam - overriding AppID");
OverrideAppId(); OverrideAppId();
} }
} }
public void OverrideAppId() public void OverrideAppId()
{ {
// Normally, Steam sets env vars when launching the game through the Steam library.
// These would also be set when running the .exe directly, thanks to Steam's "DRM" in the exe.
// However, for Steam players to be able to join non-Steam players, everyone has to be using Steamworks with the same AppID.
// At this point, OW has already initialized Steamworks.
// Since we handle achievements and DLC ownership in the rerouter, we need to re-initialize Steamworks with the new AppID.
// (Also, Mobius forgor to change some default Steamworks code, so sometimes these env vars aren't set at all.
// In this instance the overlay and achievements also don't work, but we can't fix that here.)
// reset steamworks instance
SteamManager.s_EverInitialized = false; SteamManager.s_EverInitialized = false;
var instance = SteamManager.s_instance; var instance = SteamManager.s_instance;
instance.m_bInitialized = false; instance.m_bInitialized = false;
SteamManager.s_instance = null; SteamManager.s_instance = null;
// Releases pointers and frees memory used by Steam to manage the current game.
// Does not unhook the overlay, so we dont have to worry about that :peepoHappy:
SteamAPI.Shutdown(); SteamAPI.Shutdown();
// Set the env vars to an AppID that everyone owns by default.
// from facepunch.steamworks SteamClient.cs
Environment.SetEnvironmentVariable("SteamAppId", "480"); Environment.SetEnvironmentVariable("SteamAppId", "480");
Environment.SetEnvironmentVariable("SteamGameId", "480"); Environment.SetEnvironmentVariable("SteamGameId", "480");
// Re-initialize Steamworks.
instance.InitializeOnAwake(); instance.InitializeOnAwake();
// TODO also reregister hook and gamepad thing or else i think that wont work // TODO also reregister hook and gamepad thing or else i think that wont work
} }

View File

@ -19,8 +19,11 @@ public static class Interop
Log("init"); Log("init");
Harmony.CreateAndPatchAll(typeof(Patches)); Harmony.CreateAndPatchAll(typeof(Patches));
// cache dlc ownership since the patched function gets called often // Cache DLC ownership since the patched function gets called often.
OwnershipStatus = IsDlcOwned() ? EntitlementsManager.AsyncOwnershipStatus.Owned : EntitlementsManager.AsyncOwnershipStatus.NotOwned; // This won't work if the player buys the DLC mid-game, but too bad!
OwnershipStatus = IsDlcOwned()
? EntitlementsManager.AsyncOwnershipStatus.Owned
: EntitlementsManager.AsyncOwnershipStatus.NotOwned;
} }
public static void Log(object msg) => Debug.Log($"[SteamRerouter] {msg}"); public static void Log(object msg) => Debug.Log($"[SteamRerouter] {msg}");
@ -56,6 +59,7 @@ public static class Interop
type.ToString(), type.ToString(),
arg.ToString() arg.ToString()
}; };
Log($"args = {args.Join()}"); Log($"args = {args.Join()}");
var process = Process.Start(new ProcessStartInfo var process = Process.Start(new ProcessStartInfo
{ {
@ -68,6 +72,7 @@ public static class Interop
RedirectStandardOutput = true, RedirectStandardOutput = true,
RedirectStandardError = true RedirectStandardError = true
}); });
if (waitForExit) if (waitForExit)
{ {
process!.WaitForExit(); process!.WaitForExit();
@ -78,6 +83,7 @@ public static class Interop
return process.ExitCode; return process.ExitCode;
} }
return -1; return -1;
} }
} }

View File

@ -30,7 +30,6 @@ public static class Patches
return false; return false;
} }
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(Achievements), nameof(Achievements.Earn))] [HarmonyPatch(typeof(Achievements), nameof(Achievements.Earn))]
private static bool Achievements_Earn(Achievements.Type type) private static bool Achievements_Earn(Achievements.Type type)