Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mod confict report when both TMPE and other mods use harmony to patch the same method #747

Closed
pcfantasy opened this issue Feb 27, 2020 · 21 comments
Labels
discussion Contains debate on certain topics EXTERNAL Mod conflict or other external factor technical Tasks that need to be performed in order to improve quality and maintainability

Comments

@pcfantasy
Copy link
Contributor

TMPE.log
output_log(6).txt

@krzychu124 @aubergine10

I update CSUR toolbox, some users sometime will report mod conflict.

Both CSUR toolbox and TMPE use harmony to patch RoadBaseAI.UpdateLanes now. This confict should not happen, I do not know why.

https://github.com/citiesskylines-csur/CSURToolBox/blob/master/Patch/RoadBaseAIUpdateLanesPatch.cs

#611

@pcfantasy pcfantasy added BUG Defect detected triage Awaiting issue categorisation labels Feb 27, 2020
@originalfoo
Copy link
Member

originalfoo commented Feb 27, 2020

Info 805.2317943: ThreadingExtension.OnBeforeSimulationFrame: First frame detected. Detours checked. Result: 1 missing detours
- Error 805.2326772: Traffic Manager: President Edition detected an incompatibility with another mod! You can continue playing but it's NOT recommended. Traffic Manager will not work as expected. See TMPE.log for technical details.
   at CSUtil.Commons.Log.LogToFile(System.String log, LogLevel level)
   at CSUtil.Commons.Log.Error(System.String s)
   at TrafficManager.ThreadingExtension.OnBeforeSimulationFrame()
   at ThreadingWrapper.OnBeforeSimulationFrame()
   at SimulationManager.SimulationStep()
   at SimulationManager.SimulationThread()

Info 805.2739730: The following methods were overriden by another mod:
- 	<Harmony> RoadBaseAI.UpdateLanes with 3 parameters (RoadBaseAI, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)

Note to TMPE team: Doesn't Harmony provide a namespace key for it's patches? If so, could we display the conflicting namespace which would help track down conflicts when the other mod is using Harmony?

@krzychu124 krzychu124 added investigating Issue currently under investigation and removed triage Awaiting issue categorisation labels Mar 1, 2020
@krzychu124
Copy link
Member

OK, I think I figured out what is wrong.
Indeed you are patching the same method as we do but using completely different (probably custom) Harmony build. It looks like preview release of Harmony 2.0 but versioned 1.9.9.9.

To make patching compatible @CitiesSkylinesMods/tmpe would have to migrate to Harmony 2.0.0.X.

I think there are no other options from your side, because you are patching methods of struct instances. That feature is not supported by Harmony 1.2.0.1 so downgrade is not really possible. We don't have data which mods are using TM:PE.

Another issue is that Harmony v2.0 wasn't released yet and selecting intermediate (beta) version might cause even more problems.
Latest info and full story from the author of Harmony lib can be found here

@krzychu124 krzychu124 added discussion Contains debate on certain topics EXTERNAL Mod conflict or other external factor technical Tasks that need to be performed in order to improve quality and maintainability and removed BUG Defect detected investigating Issue currently under investigation labels Mar 2, 2020
@pcfantasy
Copy link
Contributor Author

pcfantasy commented Mar 3, 2020

@krzychu124

harmony2.0 is not compatiable with harmony1.2, so if TMPE is using Harmony 2.0.0.X, I do not think TMPE can compatiable with other mod which is using harmony1.2

In fact, In order to compatiable with mod which is using harmony1.2, I modified Harmony 2.0.0.X, remove some new features and rename it as harmony 1.9.9.9

Please see this issue:
pardeike/Harmony#250

@pcfantasy
Copy link
Contributor Author

@krzychu124

Let`s make this clear. Do you mean to make TMPE and CSUR toolbox compatiable, we should both use harmony2.0.0.X or both use harmony1.2.0.1 ?

@krzychu124
Copy link
Member

krzychu124 commented Mar 3, 2020

Let`s make this clear. Do you mean to make TMPE and CSUR toolbox compatible, we should both use harmony2.0.0.X or both use harmony1.2.0.1 ?

@pcfantasy Exactly, we currently use Harmony 1.2.0.1 and as I said earlier, your CSUR Toolbox can't use harmony 1.2.0.1 because some of your patches will fail to apply. I pulled your repo to test if backward migration is possible and nope, I couldn't patch some of methods you use.
Anyways, we are considering migration to latest harmony release in near future(along with next DLC??).
Latest version 2.0.0.8 was released on nuget 3 days ago and according to Harmony author reddit post linked above is considered as stable.

@pcfantasy
Copy link
Contributor Author

@krzychu124

Thanks, I understand this now. I have a workaround to patch another place until TMPE move to new harmony.

BTW, it is not easy to move TMPE to harmony.

As I said, I tried before. But harmony2.0 do not compatiable with harmony1.2. So if some mods still use harmony1.2, there will be a conflict.

So what do you think about this, or if TMPE want to update to harmony2.0, please notify all other modders.

@krzychu124
Copy link
Member

Yes, we are aware that both versions are incompatible. The easiest way for us would be to update both v11 versions at a time. We will try to notify other modders before we release updated version.

@originalfoo
Copy link
Member

The move to Harmony 2 is going to happen sooner or later anyway, as we already see with CSUR Toolbox, Network Skins 2, etc.... there is a need for the features of Harmony 2. If necessary we could work with other modders to help them migrate to Harmony 2.

A lot of the much older mods are still using the old detours library by cope. Maybe there is some way we could determine which mods are using Harmony, and if so which version of Harmony they are using? Possibly a small mod that could be subscribed which would log details to game log?

@pcfantasy
Copy link
Contributor Author

@krzychu124 @aubergine10

Agree, notify me if any plan about harmony2.0, thanks.

@pcfantasy
Copy link
Contributor Author

pcfantasy commented Mar 4, 2020

@krzychu124

Sorry to ask one more technical detail. This conflict(two harmony version patch one place) do not affect function, I mean both postfix will still work, right?

Some of my mods use different harmony to patch the same method, use prefix, which seems work fine.

But in this case, some users report that my postfix is not work after TMPE show mod conflict warning.

Do you have any idea about this?

Updated:

Uses reported that actually both functions are working normally.

@originalfoo
Copy link
Member

FYI: Seems there are lots of versions of Harmony floating around - I've got about 120 mods active, and these are the versions of Harmony assemblies in the app domain:

image

@dymanoid
Copy link
Contributor

dymanoid commented Mar 4, 2020

Note: although all the assemblies are loaded into the app domain, only one of them will be used by all mods only one of the assemblies of same version will be used by the mods that request this assembly. But which one - that's impossible to predict. It depends on the assembly loading order which is mainly affected by the mod loading order which is, in turn, non-deterministic in Cities: Skylines.

@pcfantasy
Copy link
Contributor Author

@dymanoid

Do you mean if one mod A use harmony1.2, another mod B use harmony1.3(local build and hacked for some new functions). But in fact, both mods may all use harmony1.2 to patch method.

So in the case, B mod want to use local hacked harmony1.3 for new functions but the new functions may not work as experted, because in fact B mod is still using harmony1.2.

Is my understanding right?

@originalfoo
Copy link
Member

originalfoo commented Mar 5, 2020

There is no way for a mod to say which version of harmony it wants; if there are multiple harmony assemblies loaded (different versions) only one of those harmony assembly versions will be used by all mods.

It's exact same problem that RimWorld modders had; whichever version of harmony loads first is used by all other mods, regardless of what versions of harmony those other mods bundled.

@pcfantasy
Copy link
Contributor Author

pcfantasy commented Mar 5, 2020

@aubergine10

Not exactly? You see that NS2 and CSUR toolbox all want new harmony function to patch struct instance. The two mod use local builded harmony version.

Until now, both mod works fine in steam, if NS2 and CSUR toolbox patch is forced by other mod`s harmony1.2. Their patches should not apply to struct instance, and will cause function issue.

@originalfoo
Copy link
Member

Maybe @pardeike could confirm one way or the other?

@pardeike
Copy link

pardeike commented Mar 5, 2020

Maybe a bit long but it sums up what RimWorld went through:
https://www.reddit.com/r/RimWorld/comments/fbnm45/harmony_the_full_story/?utm_source=share&utm_medium=ios_app&utm_name=iossmf

Later in the comments to that story there is a technical post where I explain the details.

@dymanoid
Copy link
Contributor

dymanoid commented Mar 5, 2020

@pcfantasy
Two questions.

Are you sure the mods are working as expected? Maybe they are just lacking some internal functionality due to missing patches but the players just never notice that. If the mod doesn't crash and the main functionality is okay, no player will dig into the details. There are indeed some players having the custom built Harmony instance as the "main" one, and the other mods happen to not use incompatible API, so it just works for those players.

How can you guarantee that your build of Harmony is used when multiple Harmony-using mods are loaded? Did you try to compare the Module GUID of the loaded Harmony assembly with the one of your custom build?

I turns out that I was not quite correct. The game is capable to provide the requested version of the assembly. But if there are multiple instances with same version loaded, there is no guarantee which instance of them will be used.

@pardeike
Copy link

pardeike commented Mar 5, 2020

There is a method that returns the harmony version: https://harmony.pardeike.net/api/HarmonyLib.Harmony.html#HarmonyLib_Harmony_VersionInfo_System_Version__

@pcfantasy
Copy link
Contributor Author

@dymanoid

Thanks for your information.

@originalfoo
Copy link
Member

originalfoo commented Mar 6, 2020

v1.2.0 of Duplicate Assembly Scanner is now in PR review - useful tool if you want to get an idea of which C:SL mods are using Harmony and which of the assemblies are loaded in to app domain, etc: CitiesSkylinesMods/DuplicateAssemblyScanner#16

Note that a mod doesn't even need to be enabled for it's 0Harmony.dll to get loaded by C:SL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Contains debate on certain topics EXTERNAL Mod conflict or other external factor technical Tasks that need to be performed in order to improve quality and maintainability
Projects
None yet
Development

No branches or pull requests

5 participants