Skip to content

Commit

Permalink
Merge branch 'dev' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 committed Aug 24, 2024
2 parents 2e41f55 + 10944f7 commit 932a971
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Celeste.Mod.mm/Mod/Everest/Everest.DiscordSDK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private string GetMapIconURL(AreaData areaData) {
return IconBaseURL + "/rich-presence-icons-static/null.png";
}
} else {
byte[] hash = ChecksumHasher.ComputeHash(icon.Data);
byte[] hash = ComputeHash(icon.Data);
string hashString = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
if (RichPresenceIcons.Contains(hashString)) {
return IconBaseURL + "/rich-presence-icons/" + hashString + ".png";
Expand Down
41 changes: 24 additions & 17 deletions Celeste.Mod.mm/Mod/Everest/Everest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Celeste.Mod.Backdrops;
using Celeste.Mod.Core;
using Celeste.Mod.Entities;
using Celeste.Mod.Core;
using Celeste.Mod.Helpers;
using Celeste.Mod.Helpers.LegacyMonoMod;
using Celeste.Mod.UI;
Expand All @@ -14,7 +12,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Net;
Expand Down Expand Up @@ -121,19 +118,29 @@ public static partial class Everest {

internal static bool _ContentLoaded;

/// <summary>
/// The hasher used to determine the mod and installation hashes.
/// </summary>
[Obsolete("Use the ComputeHash methods instead. They will reach stable on Sep 7, and this field will be removed in the following stable on Oct 5.")]
public readonly static HashAlgorithm ChecksumHasher = XXHash64.Create();

public static byte[] ComputeHash(byte[] buffer) {
using (HashAlgorithm checksumHasher = XXHash64.Create()) {
return checksumHasher.ComputeHash(buffer);
}
}

public static byte[] ComputeHash(Stream inputStream) {
using (HashAlgorithm checksumHasher = XXHash64.Create()) {
return checksumHasher.ComputeHash(inputStream);
}
}

/// <summary>
/// Get the checksum for a given file.
/// </summary>
/// <param name="path">The file path.</param>
/// <returns>A checksum.</returns>
public static byte[] GetChecksum(string path) {
using (FileStream fs = File.OpenRead(path))
return ChecksumHasher.ComputeHash(fs);
return ComputeHash(fs);
}

/// <summary>
Expand Down Expand Up @@ -165,7 +172,7 @@ public static byte[] GetChecksum(ref Stream stream) {

long pos = stream.Position;
stream.Seek(0, SeekOrigin.Begin);
byte[] hash = ChecksumHasher.ComputeHash(stream);
byte[] hash = ComputeHash(stream);
stream.Seek(pos, SeekOrigin.Begin);
return hash;
}
Expand All @@ -185,7 +192,7 @@ void AddFile(string path) {
}
*/
void AddStream(Stream stream) {
data.AddRange(ChecksumHasher.ComputeHash(stream));
data.AddRange(ComputeHash(stream));
}

// Add all mod containers (or .DLLs).
Expand All @@ -208,7 +215,7 @@ void AddStream(Stream stream) {
}

// Return the final hash.
return _InstallationHash = ChecksumHasher.ComputeHash(data.ToArray());
return _InstallationHash = ComputeHash(data.ToArray());
}
}
public static string InstallationHashShort {
Expand Down Expand Up @@ -269,7 +276,7 @@ internal static void ParseArgs(string[] args) {

else if (arg == "--debugger")
Debugger.Launch();

else if (arg == "--debugger-attach") {
Logger.Info("Everest", "Waiting for debugger to attach...");
while (!Debugger.IsAttached) { }
Expand Down Expand Up @@ -297,7 +304,7 @@ internal static void ParseArgs(string[] args) {
if (Enum.TryParse(queue.Dequeue(), ignoreCase: true, out LogLevel level))
Logger.SetLogLevelFromSettings("", level);
}

else if (arg == "--use-scancodes") {
Environment.SetEnvironmentVariable("FNA_KEYBOARD_USE_SCANCODES", "1");
}
Expand Down Expand Up @@ -405,7 +412,7 @@ static void UnregisterModDetour(object detour) {
RegisterModDetour(owner, info, info.Undo);
};
DetourManager.ILHookUndone += UnregisterModDetour;

DetourManager.NativeDetourApplied += info => {
if (GetHookOwner(out _) is not Assembly owner)
return;
Expand Down Expand Up @@ -529,7 +536,7 @@ internal static void Shutdown() {

internal static void Dispose(object sender, EventArgs args) {
Audio.Unload(); // This exists but never gets called by the vanilla game.

foreach (ConcurrentDictionary<object, Action> detours in _ModDetours.Values)
foreach (Action detourUndo in detours.Values)
detourUndo();
Expand Down Expand Up @@ -700,7 +707,7 @@ internal static void CheckDependenciesOfDelayedMods() {
// all dependencies are loaded, all optional dependencies are either loaded or won't load => we're good to go!
Logger.Info("core", $"Dependencies of mod {entry.Item1} are now satisfied: loading");
EverestSplashHandler.IncreaseLoadedModCount(entry.Item1.Name); // Notify the splash

if (Everest.Modules.Any(mod => mod.Metadata.Name == entry.Item1.Name)) {
// a duplicate of the mod was loaded while it was sitting in the delayed list.
Logger.Warn("core", $"Mod {entry.Item1.Name} already loaded!");
Expand Down Expand Up @@ -767,7 +774,7 @@ private static bool checkIfOneOfDependenciesIsDelayedAndCanBeLoaded(List<Everest
internal static void Unregister(this EverestModule module) {
module.OnInputDeregister();
module.Unload();

// TODO: Unload from LuaLoader
// TODO: Unload from EntityLoaders
// TODO: Undo event listeners
Expand Down
2 changes: 2 additions & 0 deletions Celeste.Mod.mm/Mod/Helpers/ModUpdateInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ public class ModUpdateInfo {
public virtual int LastUpdate { get; set; }
public virtual string URL { get; set; }
public virtual List<string> xxHash { get; set; }
public virtual string GameBananaType { get; set; }
public virtual int GameBananaId { get; set; }
}
}
34 changes: 26 additions & 8 deletions Celeste.Mod.mm/Patches/Autotiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void ReadInto(patch_TerrainType data, Tileset tileset, XmlElement xml) {
ReadIntoCustomTemplate(data, tileset, xml);
}

if (xml.HasAttr("soundPath") && xml.HasAttr("sound")) { // Could accommodate for no sound attr, but requiring it should improve clarity on user's end
if (xml.HasAttr("soundPath") && xml.HasAttr("sound")) { // Could accommodate for no sound attr, but requiring it should improve clarity on user's end
SurfaceIndex.TileToIndex[xml.AttrChar("id")] = xml.AttrInt("sound");
patch_SurfaceIndex.IndexToCustomPath[xml.AttrInt("sound")] = (xml.Attr("soundPath").StartsWith("event:/") ? "" : "event:/") + xml.Attr("soundPath");
} else if (xml.HasAttr("sound")) {
Expand All @@ -81,6 +81,14 @@ private void ReadInto(patch_TerrainType data, Tileset tileset, XmlElement xml) {

if (xml.HasAttr("debris"))
data.Debris = xml.Attr("debris");

if (xml.HasAttr("ignoreExceptions")) {
string[] array = xml.Attr("ignoreExceptions").Split(',');

foreach (string text in array)
if (text.Length > 0)
data.IgnoreExceptions.Add(text[0]);
}
}

private void ReadIntoCustomTemplate(patch_TerrainType data, Tileset tileset, XmlElement xml) {
Expand Down Expand Up @@ -132,10 +140,10 @@ private void ReadIntoCustomTemplate(patch_TerrainType data, Tileset tileset, Xml
if (char.IsLetter(c))
masked.Mask[i++] = GetByteLookup(c);
break;
/*
* Error handling for characters that don't exist in a defined filter could be added,
* but is slightly more likely to break old custom tilesets if someone has defined a mask that containes nonstandard spacers (usually '-')
*/
/*
* Error handling for characters that don't exist in a defined filter could be added,
* but is slightly more likely to break old custom tilesets if someone has defined a mask that containes nonstandard spacers (usually '-')
*/
}
}
} catch (IndexOutOfRangeException e) {
Expand Down Expand Up @@ -389,6 +397,10 @@ public bool TryGetCustomDebris(out string path, char tiletype) {
// Required because TerrainType is private.
private class patch_TerrainType {
public char ID;

public HashSet<char> Ignores;
public HashSet<char> IgnoreExceptions;

public List<patch_Masked> Masked;
public patch_Tiles Center;
public patch_Tiles Padded;
Expand All @@ -402,18 +414,24 @@ private class patch_TerrainType {
public Dictionary<byte, string> whitelists;
public Dictionary<byte, string> blacklists;

[MonoModIgnore]
public extern bool Ignore(char c);

public extern void orig_ctor(char id);
[MonoModConstructor]
public void ctor(char id) {
orig_ctor(id);

IgnoreExceptions = new HashSet<char>();

whitelists = new Dictionary<byte, string>();
blacklists = new Dictionary<byte, string>();
}

[MonoModReplace]
public bool Ignore(char c) {
if (ID == c || IgnoreExceptions.Contains(c))
return false;

return Ignores.Contains('*') || Ignores.Contains(c);
}
}

// Required because Tiles is private.
Expand Down
18 changes: 17 additions & 1 deletion Celeste.Mod.mm/Patches/Spikes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,27 @@

namespace Celeste {
public class patch_Spikes : Spikes {
public patch_Spikes(Vector2 position, int size, Directions direction, string type)
public patch_Spikes(Vector2 position, int size, Directions direction, string type)
: base(position, size, direction, type) {
// no-op. MonoMod ignores this - we only need this to make the compiler shut up.
}

[MonoModConstructor]
[MonoModIgnore]
public extern void ctor(Vector2 position, int size, Directions direction, string type);

[MonoModIgnore]
private static extern int GetSize(EntityData data, Directions dir);

[MonoModConstructor]
[MonoModReplace]
public void ctor(EntityData data, Vector2 offset, Directions dir) {
ctor(data.Position + offset, GetSize(data, dir), dir, data.Attr("type", "default"));

if (!data.Bool("attachToSolid", defaultValue: true))
Remove(Get<StaticMover>());
}

[MonoModIgnore]
[PatchSpikesDraw]
public override extern void Render();
Expand Down
Loading

0 comments on commit 932a971

Please sign in to comment.