Skip to content

Commit

Permalink
Even more struct edge case fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0ade committed Dec 12, 2021
1 parent 03a9816 commit 1eeb605
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
44 changes: 43 additions & 1 deletion MonoMod.UnitTest/RuntimeDetour/DetourExtTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace MonoMod.UnitTest {
[Collection("RuntimeDetour")]
public class DetourExtTest {
public unsafe class DetourExtTest {
[Fact]
public void TestDetoursExt() {
lock (TestObject.Lock) {
Expand Down Expand Up @@ -327,6 +327,43 @@ public void TestDetoursExt() {
);
#endif

// This is based off of something provided by a Harmony user.
// It should be preferably tested on x86, as it's where the edge case with this certain return size occurred.
#if true
Assert.Equal(
0x11111111,
new TwoInts() {
A = 0x11111111,
B = 0x22222222
}.Magic
);

using (Hook h = new Hook(
typeof(TwoInts).GetMethod("get_Magic", BindingFlags.Public | BindingFlags.Instance),
new Func<Func<IntPtr, int>, IntPtr, int>((orig, self) => {
int rv = orig(self);
rv = rv * 2 + ((TwoInts*) self)->B;
return rv;
})
)) {
Assert.Equal(
0x11111111 * 2 + 0x22222222,
new TwoInts() {
A = 0x11111111,
B = 0x22222222
}.Magic
);
}

Assert.Equal(
0x11111111,
new TwoInts() {
A = 0x11111111,
B = 0x22222222
}.Magic
);
#endif


AppDomain.CurrentDomain.FirstChanceException -= OnFirstChanceException;

Expand Down Expand Up @@ -361,6 +398,11 @@ public static int DummyB(int a, int b) {
public struct TwoInts {
public int A;
public int B;
public int Magic {
get {
return A;
}
}
public override string ToString()
=> $"({A}, {B})";
}
Expand Down

0 comments on commit 1eeb605

Please sign in to comment.