-
Notifications
You must be signed in to change notification settings - Fork 28
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
Clarify how to integrate D2Moo for modders #20
Comments
Reading the list I'd prefer the "subproject - Import D2MOO .dlls and patch the functions you want" If there was a vote that is what I'd choose |
I'm likely doing it wrong and forcing this project to do something it really isn't geared towards, but I had to end up going with copy-paste. I want to detour calls to functions Foo, Bar, and Baz to my own implementations, but I want these functions to continue using the existing D2 logic for everything else so the mod can coexist with other mods and to use code that is known to be working. Half of this issue is something that will disappear as this codebase grows for instance
Let's say I had a custom My_SKILLS_SrvSt58_FireClaws. I want it to still call SKILLS_GetSkillsTxtRecord from the loaded D2Common library instead of the D2Moo implementation (It's just an example, assume these are both from the same dll and a bit more complex). I do this because I want to call functions that other mods may have injected their own code into and because it's guaranteed to be a correct implementation since it's using the original logic. I started off as "subproject - Configure CMake to use your own patch files and .def" and this was working well until I started hitting issues with other mods and running into not yet complete logic in this codebase. Am I doing something completely wrong, or do I just have a not so great usecase at the moment? |
So there are multiple issues at hand.
There are multiple ways to do this, but essentially if you want to use D2Moo's patching mechanism you'll need to rely on doing 2 things:
The first one is easy to do with pretty much any patching mechanism, including D2Moo's.
If using D2Moo's patching mechanism, if you need to patch ordinal functions(or pointers) this couldn't be easier, just change the patch action as done here for datatables: D2MOO/D2.Detours.patches/1.10f/D2Common.patch.cpp Lines 43 to 44 in dff4668
If you need to patch something that is not an ordinal, you'll need to use the extra patch actions D2MOO/D2.Detours.patches/1.10f/D2Common.patch.cpp Line 1376 in dff4668
If you need to call the original function from your detoured version, you'll also want to use extra patch actions by specifying a pointer that can store the original function address, much like what the debugger does:
In theory, we wouldn't need to patch D2Moo to call the original code if:
One alternative would be to use only D2Moo's headers, write your own patching DLLs and/or mechanism, and only write the functions you want to patch. As soon as would try to call a function that does not exist in your DLL and that is not an imported ordinal, you would end up with a linker error saying it can't find the function. You could then implement it as a simple call to the original function that you loaded with
I hope this can help and answers your question. If I can help making the process easier, don't hesitate to suggest changes to the project. I know one of the current pain points is that currently one .dll can only patch one original .dll. (This was kind of done on purpose to avoid mixing code from multiple .dlls and export ordinals that shouldn't be) |
Right now I did not choose the way we want to support mods for the D2Moo integration.
In the long term, I think the best option is to use a fork of D2Moo, but it's not necessarily simple to migrate from an existing mod (for example using D2Template) as you would have 2 different patching methods.
In my opinion this should be a discussion with other modders / community, so I listed a few ideas, their advantages and drawbacks in the following table.
Please give your opinion!
The text was updated successfully, but these errors were encountered: