Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion HarmonyTests/Patching/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,15 @@ public void Test_ArrayArguments()
var st2 = new ArgumentArrayMethods.SomeStruct() { n = 9 };
var f1 = new float[] { 8f };
var f2 = new float[] { 9f };
var b1 = true;
var b2 = true;

instance.Method(
n1, ref n2, out var n3,
s1, ref s2, out var s3,
st1, ref st2, out var st3,
f1, ref f2, out var f3
f1, ref f2, out var f3,
b1, ref b2, out var b3
);

// prefix input
Expand All @@ -353,6 +356,10 @@ public void Test_ArrayArguments()
Assert.AreEqual(9f, ((float[])r[i])[0], $"prefix[{i++}]");
Assert.AreEqual(null, (float[])r[i], $"prefix[{i++}]");

Assert.AreEqual(true, (bool)r[i], $"prefix[{i++}]");
Assert.AreEqual(true, (bool)r[i], $"prefix[{i++}]");
Assert.AreEqual(false, (bool)r[i], $"prefix[{i++}]");

// postfix input
r = ArgumentArrayPatches.postfixInput;
i = 0;
Expand All @@ -372,6 +379,10 @@ public void Test_ArrayArguments()
Assert.AreEqual(5.6f, ((float[])r[i])[2], $"postfix[{i++}]");
Assert.AreEqual(6.5f, ((float[])r[i])[2], $"postfix[{i++}]");

Assert.AreEqual(true, (bool)r[i], $"postfix[{i++}]");
Assert.AreEqual(false, (bool)r[i], $"postfix[{i++}]");
Assert.AreEqual(true, (bool)r[i], $"postfix[{i++}]");

// method output values
Assert.AreEqual(123, n2, "n2");
Assert.AreEqual(456, n3, "n3");
Expand All @@ -381,6 +392,9 @@ public void Test_ArrayArguments()
Assert.AreEqual(456, st3.n, "st3");
Assert.AreEqual(5.6f, f2[2], "f2");
Assert.AreEqual(6.5f, f3[2], "f3");
Assert.AreEqual(true, b1, $"b1");
Assert.AreEqual(false, b2, $"b2");
Assert.AreEqual(true, b3, $"b3");
}

[Test]
Expand Down
14 changes: 11 additions & 3 deletions HarmonyTests/Patching/Assets/ArgumentCases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public void Method(
int n1, ref int n2, out int n3,
string s1, ref string s2, out string s3,
SomeStruct st1, ref SomeStruct st2, out SomeStruct st3,
float[] f1, ref float[] f2, out float[] f3
float[] f1, ref float[] f2, out float[] f3,
bool b1, ref bool b2, out bool b3
)
{
n2 = 12;
Expand All @@ -190,6 +191,8 @@ public void Method(
st3 = new SomeStruct() { n = 45 };
f2 = [1f, 3f, 5f];
f3 = [2f, 4f, 6f];
b2 = true;
b3 = false;
}
}

Expand All @@ -216,22 +219,27 @@ public static bool Prefix(object[] __args)
__args[10] = new float[] { 1.2f, 3.4f, 5.6f };
__args[11] = new float[] { 2.1f, 4.3f, 6.5f };

__args[13] = false;
__args[14] = true;

return false;
}

public static void Postfix(
int n1, int n2, int n3,
string s1, string s2, string s3,
ArgumentArrayMethods.SomeStruct st1, ArgumentArrayMethods.SomeStruct st2, ArgumentArrayMethods.SomeStruct st3,
float[] f1, float[] f2, float[] f3
float[] f1, float[] f2, float[] f3,
bool b1, bool b2, bool b3
)
{
postfixInput =
[
n1, n2, n3,
s1, s2, s3,
st1, st2, st3,
f1, f2, f3
f1, f2, f3,
b1, b2, b3
];
}
}
Expand Down