Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Contributing Patches

Tyler Young edited this page Apr 6, 2020 · 3 revisions

First Steps

If you intend to contribute a patch to the CommunityPatch project, here's how you should stat.

First, fork the project on GitHub.

Use one of the patches in the /src/Patches/ directory as a template.

If you need to use Harmony, you may use ItemComparisonColorPatch.cs as a template.

What Should Be Patched

Is if you think something is broken intended behavior, it needs a patch.

You can detail why the patch is necessary in a draft PR before you've even written anything but a stub for the patch.

The PR will be given opinions and reviewed, and will be subject of early approval and rejection.

Create the PR as early as possible to reduce the amount of work you need to do by getting reviews as often as possible.

Using Harmony

If you are patching a method with harmony, you should have the patch determine it's applicability.

Check if the target method is already patched, and if so, the patch should not be applicable.

If the target method is different from what you expect (here demonstrated by a SHA256 hash check) then the patch should not be applicable.


    public bool IsApplicable(Game game) {
      var patchInfo = Harmony.GetPatchInfo(TargetMethodInfo);
      if (patchInfo != null && patchInfo.Owners.Any())
        return false;

      var bytes = TargetMethodInfo.GetMethodBody()?.GetILAsByteArray();
      if (bytes == null) return false;

      using var hasher = SHA256.Create();
      var hash = hasher.ComputeHash(bytes);
      return hash.SequenceEqual(new byte[] {
        0x4C, 0x29, 0xDC, 0x2D, 0x78, 0x89, 0xA7, 0xA8,
        0xC6, 0xDA, 0x84, 0xDB, 0x07, 0x2E, 0x7D, 0xB4,
        0x99, 0xED, 0xB2, 0xB9, 0xC4, 0xBB, 0xAD, 0xE4,
        0xC9, 0xD1, 0xC8, 0x0F, 0xD7, 0x8C, 0x25, 0x15
      });
    }

You may use any method of validating the method IL that you deem appropriate, subject to a simple code review.

Getting / Hashing IL Bytes

Clone this wiki locally