Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed May 25, 2023
1 parent 0e8d1c1 commit c5a526d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Harmony/Harmony.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<FileVersion>$(HarmonyVersion)</FileVersion>
<PackageVersion>$(HarmonyVersion)$(HarmonyPrerelease)</PackageVersion>
<InformationalVersion>$(HarmonyVersion)$(HarmonyPrerelease)</InformationalVersion>
<NoWarn>$(NoWarn);NU5131</NoWarn>
</PropertyGroup>

<!-- In .NET 5.0 Binary Formatters are off by default. Support is added for .NET 5.0+ for fallback JSON Serialization -->
Expand All @@ -45,7 +46,7 @@
</PropertyGroup>
</Otherwise>
</Choose>

<Choose>
<!--
Ideally would check for .NET Core and .NET 5.0+ via TargetFrameworkIdentifier being .NETCoreApp, but that property isn't defined at this point,
Expand Down
3 changes: 1 addition & 2 deletions Harmony/Public/Harmony.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using MonoMod.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -148,7 +147,7 @@ public void PatchCategory(string category)
///
public void PatchCategory(Assembly assembly, string category)
{
PatchClassProcessor[] patchClasses = AccessTools.GetTypesFromAssembly(assembly).Select(CreateClassProcessor).ToArray();
var patchClasses = AccessTools.GetTypesFromAssembly(assembly).Select(CreateClassProcessor).ToArray();
patchClasses.DoIf((patchClass => patchClass.Category == category), (patchClass => patchClass.Patch()));
}

Expand Down
5 changes: 4 additions & 1 deletion Harmony/Tools/AccessTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
using System.Threading;

#if NET45_OR_GREATER
using System.Runtime.CompilerServices;
#endif

namespace HarmonyLib
{
/// <summary>A helper class for reflection related functions</summary>
Expand Down
8 changes: 4 additions & 4 deletions Harmony/Tools/CodeMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ internal bool Matches(List<CodeInstruction> codes, CodeInstruction instruction)
/// <returns></returns>
public static CodeMatch LoadsLocal(bool useAddress = false, string name = null)
{
CodeMatch match = new CodeMatch(null, null, name);
var match = new CodeMatch(null, null, name);

if (useAddress)
{
Expand Down Expand Up @@ -172,7 +172,7 @@ public static CodeMatch LoadsLocal(bool useAddress = false, string name = null)
/// <returns></returns>
public static CodeMatch StoresLocal(string name = null)
{
CodeMatch match = new CodeMatch(null, null, name);
var match = new CodeMatch(null, null, name);

match.opcodes.AddRange(new[]
{
Expand All @@ -193,7 +193,7 @@ public static CodeMatch StoresLocal(string name = null)
/// <returns></returns>
public static CodeMatch LoadsArgument(bool useAddress = false, string name = null)
{
CodeMatch match = new CodeMatch(null, null, name);
var match = new CodeMatch(null, null, name);

if (useAddress)
{
Expand Down Expand Up @@ -224,7 +224,7 @@ public static CodeMatch LoadsArgument(bool useAddress = false, string name = nul
/// <returns></returns>
public static CodeMatch StoresArgument(string name = null)
{
CodeMatch match = new CodeMatch(null, null, name);
var match = new CodeMatch(null, null, name);

match.opcodes.AddRange(new[]
{
Expand Down
2 changes: 1 addition & 1 deletion HarmonyTests/IL/DynamicArgumentPatches.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using NUnit.Framework;
using System;
using System.Collections.Generic;
Expand Down
42 changes: 42 additions & 0 deletions HarmonyTests/Tools/TestCodes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using HarmonyLib;
using NUnit.Framework;
using System.Reflection.Emit;
using static HarmonyLib.Code;

namespace HarmonyLibTests.Tools
{
[TestFixture]
public class Test_Codes : TestLogger
{
[Test]
public void Test_Basic_Code_Usage()
{
var code1 = Ldstr["hello"];
Assert.AreEqual(OpCodes.Ldstr, code1.opcode);
Assert.AreEqual("hello", code1.operand);
Assert.AreEqual(0, code1.labels.Count);
Assert.AreEqual(0, code1.blocks.Count);
Assert.AreEqual(0, code1.jumpsFrom.Count);
Assert.AreEqual(0, code1.jumpsTo.Count);
Assert.AreEqual(null, code1.predicate);

var code2 = Ldarg_0;
Assert.AreEqual(OpCodes.Ldarg_0, code2.opcode);
Assert.AreEqual(null, code2.operand);
Assert.AreEqual(0, code2.labels.Count);
Assert.AreEqual(0, code2.blocks.Count);
Assert.AreEqual(0, code2.jumpsFrom.Count);
Assert.AreEqual(0, code2.jumpsTo.Count);
Assert.AreEqual(null, code2.predicate);
}

[Test]
public void Test_CodeMatch_Usage()
{
var code = Ldstr["test", "foo"];
var match = new CodeMatch(OpCodes.Ldstr, "test", "foo");
Assert.AreEqual("[foo: opcodes=ldstr operands=test]", match.ToString());
Assert.AreEqual("[foo: opcodes=ldstr operands=test]", code.ToString());
}
}
}

0 comments on commit c5a526d

Please sign in to comment.