Jump to content

Tutorials that focus on Harmony


Recommended Posts

TL;DR - I'm Ryan, Can you folks recommend a good guide (video or written) on getting going with Harmony based mods in 7D2D?

 

Hey folks,

 

Super quick intro from me, I'm Ryan, a software developer from Scotland, fellow 7D2D fan and modding enthusiast. I've not got a lot of mods under my belt, just a silly Stones are Buses one (that as the name suggests, turns all the stones in the game into buses), a little Quality of Life piece I maintain for myself, and my 1 "proper" mod that is yet to be released (so is a little secret for the moment).

 

I share this info in the hopes that it gives a least a little bit of credibility to the request I'm about to make! I'm a (semi) active member of a rom hacking community so appreciate how often doe eyed new people join communities / forums with creative brains gushing with ideas and then make innocent but ambitious requests without realising the monolithic task they are really looking at. Please take my word that I won't be doing that! At least not entirely naïvely!

 

I'm looking to step my modding game up, and progress into the "real" stuff, the bits that are beyond what XML modding alone can do.

 

I've cherry picked through all the topics in the Tutorials & Guides - 7 Days to Die section, I've been through xyth's excellent post on A20 - Consolidated Guide to Modding with Unity - Tutorials & Guides - 7 Days to Die and indeed popped all his video's on and watched throughout the day, and I've also watched Max Fox's YouTube series on the topic I'm about to ask about, but I still find myself missing a little bit of info...

 

Can you folks recommend a good guide (video or written) on getting going with Harmony based mods in 7D2D?

 

From what I've found so far, I gather it is making use of Unity, Visual Studio, the Harmony library and dnSpy (for looking at the original files) but it would be GREAT if there was a "Getting started tutorial" somewhere so I can hit the ground running with it and not have to muddle through what I imagine is already well trodden ground.

 

What I have pictured in my head is a: "Install Unity, install VS, install dnSpy, this is how you add Harmony, this is how you use dnSpy to find some code, this is how you edit that code with Harmony, this is how you recompile it and apply it to the game, here's the finished product" styled guide!

 

I know it's going to be a suggestion but I'll point out ahead of time that I really don't want to hit up someone's Discord and just ask questions there. It's awesome that people are out their willing to help noobs like myself, and I don't want to sound like a choosing beggar, but I really want something I can peruse in my own time and my own leisure so I can at least get that fundamental ground knowledge in place before I go bugging all the more experienced folks and pulling them away from their own projects! Discord feels much more like a real time chat system to myself, and I'll of course do it if there are already sources there that fulfil my needs, but I really don't want to be asking all my simple questions to people! I'll save that for the complicated ones!

 

Cheers for reading, please accept this as my introduction thread (so be gentle!) and I'll hopefully see you all round the forums.

Edited by RyanFaeScotland (see edit history)
Link to comment
Share on other sites

  • RyanFaeScotland changed the title to Tutorials that focus on Harmony

I don't know if there is that kind of tutorial available. The ones you linked are the best ones to start with IMHO.

 

Once you've gone through those, then I think the next step is to look through other peoples' code to see what they did. Once you've done that, I think you've gone beyond the tutorial stage and into the stage where you should ask questions.

 

If you want code to look through, my own "Mostly Dead" mod is probably good. I'm hardly an expert so it's good "beginner" code to look at.

https://gitlab.com/karlgiesing/7d2d-a20-modlets/-/tree/main/khzmusik_Mostly_Dead

 

The Harmony stuff is actually pretty easy. First you add some class that is equivalent to this:

https://gitlab.com/karlgiesing/7d2d-a20-modlets/-/blob/main/khzmusik_Mostly_Dead/Harmony/MostlyDead.cs

 

For the details of Harmony patching, it's best to get it from the horse's mouth:

https://harmony.pardeike.net/articles/patching.html

 

If you understand all of that, then you should really get a Discord account and go to Guppycur's Discord. I know you don't want Discord recommendations, but they have a huge amount of knowledge there, and it goes beyond just people asking questions in chat.

 

I hope that helps.

 

Link to comment
Share on other sites

Hey khzmusik, thanks for the detailed response. That's some well documented code, looks like a great resource to get started on, appreciate you sharing.

 

I've joined the Discord, it's huge! I'm not hugely against them, just a bit stuck in my ways I guess! I much prefer things being split out into topics like they are in a forum with individual discussions on each topic. With Discord it feels like you need to wade through so much jumbled discussion to learn anything!

 

However, I'll go check it out, I'm sure there is plenty to learn there.

Link to comment
Share on other sites

  • 3 weeks later...
On 12/17/2022 at 7:22 AM, khzmusik said:

If you want code to look through, my own "Mostly Dead" mod is probably good.

 

One story ends. Another begins....

 

Not that your story has ended at all, but given that is what your mod says when you die in game and spawn afresh it seemed like a fitting way to highlight that, as suggested, I've managed to get your mod working from scratch (i.e. cloning the repo from git into Visual Studio, building and deploying) and that now, thanks to your help, my own journey can begin!

 

Thanks a lot for pointing me on the path, you were right, this is a great way to get started.

 

I'll likely write up something proper in the near future, but for now here is the only steps I'd like to highlight to people that might be starting on the same journey:

  • To some it'll seem obvious, but for the avoidance of doubt, it is Visual Studio you open up and work with the Mostly Dead project in. If you have been following along some other tutorials you might think you need Unity for this, you don't. I'm using VS2019 as it is the version I have installed, 2022 and newer probably work.
  • When you open the project you'll have a lot of "Unreferenced assembly" errors for things like AmplifyMotion, Assembly-CSharp, Assembly-CSharp-firstpass and so on. You'll find these in your 7D2D game folder. Right click the MostlyDead project file and go to Properties -> Reference Paths -> Browse and add the folder 7 Days To Die\7DaysToDie_Data\Managed\
  • I removed the 2 EasyCheat references without issue (couldn't find them to add them)
  • I also added HarmonyX as a NuGet package, but I'm not certain if this is required (I'll double check before writing something proper up EDIT - I double checked, it isn't needed, just make sure the reference to the Harmony.dll is in there).
  • Finally, once the project is built, the only required output files and folders are: Config/  Harmony/ Scripts/ UIAtlases/ ModInfo.xml and MostlyDead.dll, the rest are just build artifacts and can be ignored

If you've any comments to add @khzmusik on what I've discovered so far they would of course be welcome. Otherwise thank you once more, and I hope to have something of my own to show very soon.

Edited by RyanFaeScotland (see edit history)
Link to comment
Share on other sites

13 hours ago, RyanFaeScotland said:

 

One story ends. Another begins....

 

Not that your story has ended at all, but given that is what your mod says when you die in game and spawn afresh it seemed like a fitting way to highlight that, as suggested, I've managed to get your mod working from scratch (i.e. cloning the repo from git into Visual Studio, building and deploying) and that now, thanks to your help, my own journey can begin!

 

Thanks a lot for pointing me on the path, you were right, this is a great way to get started.

 

I'll likely write up something proper in the near future, but for now here is the only steps I'd like to highlight to people that might be starting on the same journey:

  • To some it'll seem obvious, but for the avoidance of doubt, it is Visual Studio you open up and work with the Mostly Dead project in. If you have been following along some other tutorials you might think you need Unity for this, you don't. I'm using VS2019 as it is the version I have installed, 2022 and newer probably work.
  • When you open the project you'll have a lot of "Unreferenced assembly" errors for things like AmplifyMotion, Assembly-CSharp, Assembly-CSharp-firstpass and so on. You'll find these in your 7D2D game folder. Right click the MostlyDead project file and go to Properties -> Reference Paths -> Browse and add the folder 7 Days To Die\7DaysToDie_Data\Managed\
  • I removed the 2 EasyCheat references without issue (couldn't find them to add them)
  • I also added HarmonyX as a NuGet package, but I'm not certain if this is required (I'll double check before writing something proper up).
  • Finally, once the project is built, the only required output files and folders are: Config/  Harmony/ Scripts/ UIAtlases/ ModInfo.xml and MostlyDead.dll, the rest are just build artifacts and can be ignored

If you've any comments to add @khzmusik on what I've discovered so far they would of course be welcome. Otherwise thank you once more, and I hope to have something of my own to show very soon.

 

By a strange coincidence, I just did some C# modding yesterday, for the first time in quite a while. I totally forgot about setting up Visual Studio.

 

What you have is mostly what I do. However, I do some things differently, and it might make your life easier.

 

For one thing, I always use the Mod Launcher to develop. If you create a new "MyMods," it will create a new copy of the game, by default in C:\7D2D\Custom\MyMods\[MyMod name]. That way you can refer to that specific copy of the game, so your development doesn't break any games in progress, and updates won't mess with your development. You can get the Mod Launcher here:

http://7d2dmodlauncher.org

 

Second, and I can't believe I forgot to mention this, SphereII has a sample project in his Git repo that is specifically set up as a template for game development. It is here:

https://github.com/SphereII/SphereII.Mods/tree/master/SampleProject

 

Even if you don't use it, the instructions are pretty good. However, it was written a while ago. More modern versions of Visual Studio and the .NET Framework will work perfectly fine (I use .NET Framework 4.8).

 

Also, you don't need to install Harmony as a NuGet package. It comes with the game. Just include a reference to the 0Harmony.dll file. In fact, that file and assembly-csharp.dll are probably all you need for modding the game, though adding everything in the Managed directory doesn't hurt anything. Make sure you set "Copy Local" to false.

 

You can also set up VS to launch and debug the game itself:

  1. Go to Project -> Properties -> Debug tab
  2. In the Configuration drop down, select "All Configurations"
  3. Select "Start External Program" and enter the location of the 7DaysToDie executable, e.g. C:\7D2D\Custom\MyMods\[MyMod name]\7DaysToDie.exe (make sure it's NOT the EAC one)
  4. Under Command Line Arguments, put: -logfile "C:\7D2D\Custom\MyMods\[MyMod name]\7DaysToDie_Data\output_log.txt" "-savegamefolder=C:\7D2D\Saves\MyMods\[MyMod name]" -nogs -noeac
  5. For the Working Directory, put: C:\7D2D\Custom\MyMods\[MyMod name]\

While you're doing that, you should also set up the mod's root directory as the output directory, so you won't have to move your .dll later. That is in the Build tab. Just put .\ in the Output field.

 

Hope that helps!

Link to comment
Share on other sites

You've saved me a write up!

 

I managed to spend some time today on the Discord and sure enough, SphereII was there and handed out some sage advice and pointed me in the direction of his videos too. Between your guidance and his videos (such as this one which pretty much exactly what I had pictured in my head: https://www.youtube.com/watch?v=107sHMcESv0) I think I'm where I need to be in terms of getting started!

 

Away to download dotPeek (an alternative to dnSpy) to try and have a poke about and see if I can make a mod of my own to do some simple things.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...