SamSuka
pardeike
pardeike

patreon


Harmony v1.1

So this is cooking. The next version of Harmony is long overdue. It's a delicate piece of software, just like every larger library that has lots of dependencies.

In case of Harmony, the overall problem gets a bit more complicated. In contrast to other libs that are usually included solo in projects, Harmony is more often than not used in "mods" within a hosting application. As a result, it has to deal with multiple versions of itself and the shared state that they have.

This all comes into play when I decided that it is time to support try-catch meta information within the patches. This affects the user visible API like CodeInstruction which is a high level container for the low level IL instructions of C#. Having multiple patches on the same method results in Harmony piping all code instructions through all user patches and here the problem becomes obvious. The new version of Harmony needs an updated API that allows for try-catch information and at the same time, those instructions can possibly be dealt with by an older version patching after the new one. Which means that the public API must stay the same and at the same time, the internal patch functions need to be updated to not loose this information if handled by and old version.

The solution cost me several nights of sleep but is rather simple: Let Harmony patch itself when it detect older versions of it. I made a convenient method annotation for those methods that need to be kept updated and after a bit of reorganisation the process works.

Today, I released one of my popular mods, Achtung! with the new version. It's hard to test Harmony with unit tests. Especially the specific interactions in multiple assemblies. So I asked for testers but after a very low response I decided to jump into the cold water and give it a shot.

Then chaos broke loose.

In the end, the problem was with some mods patching code instructions by copying them. Before, that had no side effects. But with the new Harmony carrying extra try-catch information in the public API, those mods copied extra try-catch information around without knowing. 

The remaining thing to solve is to automatically prevent this by keeping track of new code instructions that are duplicates of existing ones and carry try-catch information. That extra information must be deleted unless the patch comes from a new Harmony.

This was a rather technical blog post but I wanted to show you what keeps me busy and what maintaining a popular open source library means.

Greetings from Stockholm
/Andreas


More Creators