Skip to content

Commit

Permalink
Fix loading tool in Linux/Mono
Browse files Browse the repository at this point in the history
  • Loading branch information
ItEndsWithTens committed Jul 4, 2024
1 parent 7966f14 commit 41089d1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src/SHME.ExternalTool.Guts/CollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using SHME.ExternalTool.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;

namespace SHME.ExternalTool;

Expand Down Expand Up @@ -47,4 +48,26 @@ public static int IndexFromKey<TKey, TValue>(this SortedDictionary<TKey, TValue>

return -1;
}

// These SelectX methods are just a hack to avoid creating anonymous
// methods in the main tool assembly whose signatures contain types
// defined in an external assembly. PointOfInterest or Trigger, for
// example, are defined in SHME.ExternalTool.Guts. Under Mono in
// Linux, when BizHawk tries to load the main plugin assembly, Mono
// tries to load the types it finds in method signatures, failing on
// the aforementioned examples (among others) because the DLLs found
// in the ExternalTool attribute's LoadAssemblyFiles array haven't
// been loaded yet. This is a bit roundabout, but still effective.
public static IEnumerable<TItem2> SelectItem2<TItem1, TItem2>(this IEnumerable<(TItem1, TItem2)> enumerable)
{
return enumerable.Select((tuple) => tuple.Item2);
}
public static IEnumerable<TItem2> SelectManyItem2<TItem1, TItem2>(this IEnumerable<(TItem1, IList<TItem2>)> enumerable)
{
return enumerable.SelectMany((tuple) => tuple.Item2);
}
public static IEnumerable<(TItem1, TItem2)> SelectTuple<TItem1, TItem2>(this IEnumerable<(TItem1, TItem2)> enumerable)
{
return enumerable.Select((tuple) => tuple);
}
}
7 changes: 3 additions & 4 deletions src/SHME.ExternalTool/UI/CustomMainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,10 @@ private void DrawOverlayCommonPre(ref Matrix4x4 matrix, ref Vector3 position, re
{
Guts.Camera.GetVisibleRenderables(
ref Guts.VisibleRenderables, [
.. Guts.Pois.Values
.Select((tuple) => tuple.Item2),
.. Guts.Pois.Values.SelectItem2(),
.. Guts.CameraPaths.Values
.Select((path) => path)
.SelectMany((tuple) => tuple.Item2),
.SelectTuple()
.SelectManyItem2(),
.. Guts.Gems,
.. Guts.Lines]);
}
Expand Down

0 comments on commit 41089d1

Please sign in to comment.