Skip to content

Commit

Permalink
Fix P/Invokes crashing in EverestModule.Load()
Browse files Browse the repository at this point in the history
EverestModuleAssemblyContext.LoadUnmanagedFromThisMod(string) accesses
the module meta's Hash. If a P/Invoke occurs in EverestModule.Load(),
the Hash has not yet been computed, which crashes the game.

This commit fixes that by calculating the Hash if it is null.

Fixes EverestAPI#671.
  • Loading branch information
SnipUndercover committed Apr 27, 2024
1 parent c735065 commit f9f9ad7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion Celeste.Mod.mm/Mod/Module/EverestModuleAssemblyContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,15 @@ private IntPtr LoadUnmanagedFromThisMod(string name) {
// We have to unzip the native libs into the cache
string cachePath = Path.Combine(Everest.Loader.PathCache, "unmanaged-libs", UnmanagedLibraryFolder, ModuleMeta.Name);

string modHash = (ModuleMeta.Hash ?? ModuleMeta.Multimeta.First(meta => meta.Hash != null).Hash).ToHexadecimalString();
string modHash = (
ModuleMeta.Hash
?? ModuleMeta.Multimeta.FirstOrDefault(meta => meta.Hash != null).Hash

// if we're here, this means a P/Invoke occured in Load(); calculate the hash real quick
// https://github.com/EverestAPI/Everest/issues/761
?? (ModuleMeta.Hash = Everest.GetChecksum(ModuleMeta))
).ToHexadecimalString();

if (Directory.Exists(cachePath) && (!File.Exists(cachePath + ".sum") || File.ReadAllText(cachePath + ".sum") != modHash))
Directory.Delete(cachePath, true);

Expand Down
2 changes: 1 addition & 1 deletion Celeste.Mod.mm/Mod/Module/EverestModuleMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void PostParse() {
/// </summary>
internal void RegisterMod() {
Everest.InvalidateInstallationHash();
Hash = Everest.GetChecksum(this);
Hash ??= Everest.GetChecksum(this);

// Audio banks are cached, and as such use the module's hash. We can only ingest those now.
if (patch_Audio.AudioInitialized) {
Expand Down

0 comments on commit f9f9ad7

Please sign in to comment.