Stardew Valley
0 of 0

File information

Last updated

Original upload

Created by

pepoluan

Uploaded by

pepoluan

Virus scan

Safe to use

Tags for this mod

About this mod

A "helper bundle" to assist developing mods that patches the game using Harmony. FOR ADVANCED MODDERS only!

Requirements
Permissions and credits
Changelogs
Donations
This is not a "mod" per se; rather, this is a resource for modders.

First things first: This is a "Helper Bundle", not a "Framework".

What's the difference?

A "framework" provides a complete, often opinionated, full-blown system to hide the underlying mechanism. It is almost invariably complex, and you need to follow its own well-defined procedure to perfrom things. If a feature/facility does not exist, you usually have to either extend the framework using the framework's development guidelines, or submit an Issue report to the maker so they can implement the facility in a way that meshes with the overall concept/design of the "framework".

A clear -- and relevant -- example is the Harmony framework itself. You can actually perform your own patching, but that's a very complex process that will require you to interact with .Net Framework's "IL Interpreter". Harmony hides all that behind its framework, so you don't have to go to the nitty-gritty low level of CIL manipulation.

A "helper bundle" is, on the other hand, just a collection of optional tools to help you use the underlying mechanism. A little veneer might exist to provide some 'convenience methods' in using the underlying mechanism, but overall you're still nearly directly using the underlying mechanism. You still have access to the low(er) level mechanisms themselves.

For example, the InstructionsWalker class provided in this helper bundle. It does not hide how Harmony works; rather, it just provides a convenient way to search an array of instructions, providing convenience methods to (1) search for a pattern of CIL ops, (2) perform replacement of ops with assertations, and many others.

Even the HarmonyPatcherHelper class does not hide the mechanism of Harmony; rather, it simplifies all the boilerplate code such as the try..catch protection, instantiation of MethodInfo and HarmonyMethod objects required by HarmonyInstance.Patch(), and so on.

A benefit of making this a "helper bundle" instead of a "framework", is that this strategy allows simple inclusion in your project(s):
  • Copy the single file PatcherHelper.cs to your project's directory
  • Add that file to the Project you're working on
  • Add the statement using PatcherHelper; to the top of your patcher code
  • Done.


No need to download binaries or install exotic NuGet packages. Just a simple source-code inclusion. And since the source code is MPL-2.0 licensed, you're free to license the rest of your source code the way you want. (MPL-2.0 license applies to just that file only, and it does not preclude any kind of licenses -- including proprietary license -- to be applied to the whole project.)

Most importantly, since this is a source-code bundle, it will NOT cause DLL hell due to different mods requiring different versions of PatcherHelper.


Installation

As aforementioned, the process is simple:
  • Download & extract the .7z file provided
    or alternatively
    Clone the repository to your hard disk
  • Copy the PatcherHelper.cs file to your project, into the directory where your ModEntry.cs resides
  • Add the statement using PatcherHelper; to the top of the .cs file where you want to use the PatcherHelper bundle
  • Done.

Please note that the one uploaded here on Nexus might not be the newest version. The newest version always appear in the repository below first.


Source Code

Is available on SourceForge
, released under the MPL-2.0 license.


Examples

For the latest and greatest examples, please check this source code, especially the following files in there:
  • EBRNG_Patcher.cs -- shows how to use the HarmonyPatcherQueue class
  • EBRNG_Patches.cs and files within Patches/ -- shows how to use (1) the WantOpCache class, and (2) the WantOp factory methods