Results 1 to 6 of 6
  1. #1
    Sqeegie's Avatar
    Join Date
    Jul 2014
    Gender
    male
    Location
    Mountains.
    Posts
    94
    Reputation
    10
    Thanks
    817
    My Mood
    Busy

    A Better Way of Creating Mods

    Greetings fellow MPGH stalkers,

    When I first started modding 7DTD almost a decade ago, the tools and resources we had were very primitive compared to what is available now. The learning curve was high, and the guides were scarce. More importantly, the native support 7DTD gave to modders was non-existent. Modders had to build from scratch and often had to create "core mods" by directly patching game assemblies. This caused mods to break every update and often created conflicts when using more than one mod at a time. However, things have greatly changed since those times. 7DTD has dramatically changed the native support for mods, and the general modding community has matured. 7DTD now natively supports loading mod assemblies and supplies Harmony with the game, making it far easier to create advanced mods for 7DTD without having to patch the Assembly-CSharp.dll directly. On top of being easier to learn and implement than traditional patches, if done correctly, the mod does not have to be updated every time 7DTD does.

    I was personally quite slow at adopting this new "orthodox" modding system, but the learning curve is well worth it. I highly recommend everyone on MPGH change to this method rather than continuing to patch the Assembly-CSharp.dll directly. I won’t be putting a full tutorial here. MPGH is very restricted for posting external resources, but I do want to go over the basics and point everyone in the right direction.

    ------------------------------------


    7DTD now provides a ModAPI that can load custom C# assemblies into the game when launched. This allows us modders to write custom C# code to change how the game functions instead of patching existing assemblies.

    The basics steps for creating a mod are:
    1. Install and set up Visual Studio with .NET Framework support.
    2. Create a new .NET Framework class library (.dll) project.
    3. Add assembly references to 7DTD’s Assembly-CSharp.dll and any other library you need.
    4. Create a new class extending 7DTD’s IModApi class and implement the core InitMod method.
    5. Add any custom code.

    To get started with these steps, I recommend checking out SphereII’s "Creating A New Visual Studio Project for A20 and above" tutorial on YouTube:
     



    Here is an example C# class that implements everything needed. It (should) enable creative/debug menus, increase build distance/interval + item pickup range, as well as showing all players on the map:
     

    Code:
    /* .NET Framework 4.5 Class Library
     * 
     * References:
     *  - Assembly-CSharp.dll
     */
    
    public class MPGH : IModApi
    {
        public void InitMod(Mod _modInstance)
        {
            ModEvents.GameStartDone.RegisterHandler(GameStartDone);
        }
    
        private static void GameStartDone()
        {
            GamePrefs.Set(EnumGamePrefs.CreativeMenuEnabled, true);
            GamePrefs.Set(EnumGamePrefs.DebugMenuEnabled, true);
            GamePrefs.Instance.Save();
    
            Constants.cDigAndBuildDistance = 50f;
            Constants.cBuildIntervall = 0.2f;
            Constants.cCollectItemDistance = 50f;
    
            GameStats.Set(EnumGameStats.ShowAllPlayersOnMap, true);
        }
    }

    Once finished writing a mod, build it in release mode to create a custom .dll assembly.

    Like shown in SphereII's video, to add mods to 7DTD, create a Mods folder under the main 7 Days to Die root directory (if it doesn't already exist), and create another subdirectory for your new mod. In this directory, copy any mod .dll assemblies to it, as well as create a new file named "ModInfo.xml" and add my example content below (adjusting it to your needs):
     

    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <xml>
    	<Name value="mpgh" />
    	<DisplayName value="MPGH" />
    	<Version value="1.0" />
    	<Description value="Custom MPGH mod that enables CM/DM menus and other custom edits." />
    	<Author value="Sqeegie" />
    	<Website value="" />
    </xml>

    Once done, the folder structure should look something like this:
    Code:
    7 Days to Die
    \_ Mods
      \_ MPGH
        \_ ModInfo.xml
        \_ MPGH.dll
    On the 7DTD's ModAPI, to quote one of my comments on the forum:
    There is no documentation for ModAPI except for the stuff fellow modders have gathered and posted around. The official ModAPI is very barebones, and there isn't a huge list of premade methods and capabilities built-in. It only provides a few ModEvents and a way to initialize custom code. The rest is left up to the modder to implement. There are several primary methods we use to add our custom functionality using the ModAPI, all through the provided InitMod entrypoint:
    1. Register a handler for one of the built-in ModEvents.
    2. Patch/hook a game method via the Harmony library.
    3. Run custom code directly and/or add a new Unity GameObject to capitalize on its events.

    Using a tool like dnSpy, we can decompile and read the game's code to determine how it works, and based on that, we can figure out how we need to adjust it in order to add our desired functionality.
    In my MPGH code example, I am using the #1 capability of the ModAPI and registering a handler for 7DTD's built-in ModEvent, GameStartDone, which executes after the initial world loading is done. As mentioned, there are other ways of using the ModAPI, but the core methodology lies in using a tool like dnSpy to figure out how the game works (and what needs to be modified) and create a mod to adjust the game's functionality accordingly. For other learning resources on 7DTD modding, I recommend checking out 7DTD's modding section on their official forums.

    ------------------------------------


    I've attached an example Visual Studio project of my MPGH mod, as well as the compiled version that can be used directly in the game.

    VirusScans:

    MPGH
    https://virusscan.jotti.org/en-US/fi...job/4ggvfmtoa3
    https://www.virustotal.com/gui/file/...50616892a82b28

    MPGH_Project
    https://virusscan.jotti.org/en-US/fi...job/mdui2c7lee
    https://www.virustotal.com/gui/file/...35e39017cb1eae

    ==== Please wait until the attachments are approved before trying to download ====

    If you get the following error: "Invalid Attachment specified. If you followed a valid link, please notify the administrator." You need to wait longer.

    <b>Downloadable Files</b> Downloadable Files

  2. The Following 11 Users Say Thank You to Sqeegie For This Useful Post:

    dulp2019 (4 Weeks Ago),H34db4nger (11-29-2023),Hillow123 (1 Week Ago),jim2029 (10-13-2023),lark0715 (08-11-2023),lgw1990 (08-13-2023),Nabtastic (11-11-2023),neon485 (08-03-2023),qinghuanb111 (07-31-2023),qmmt0001 (03-15-2024),Zax8000 (08-06-2023)

  3. #2
    qinghuanb111's Avatar
    Join Date
    Nov 2018
    Gender
    male
    Posts
    1
    Reputation
    10
    Thanks
    0

    good

    right ,MPGH can userd dll to inject 7DTD

  4. #3
    jim2029's Avatar
    Join Date
    Jan 2012
    Gender
    male
    Posts
    45
    Reputation
    10
    Thanks
    3
    So to use this method of making "Mods" will still require EAC to be set to off, correct?

  5. #4
    jim2029's Avatar
    Join Date
    Jan 2012
    Gender
    male
    Posts
    45
    Reputation
    10
    Thanks
    3
    FYI, for me at least, the build/collect/dig distance is not changed from stock and you can't see anyone else on the map. Only thing that is edited is the ability to have cm/dm.

    Its been quite a few alpha's since I've even gotten the View Everyone on Map to work as well as the build/collect distance also.

  6. #5
    H34db4nger's Avatar
    Join Date
    Feb 2016
    Gender
    male
    Posts
    25
    Reputation
    10
    Thanks
    41
    My Mood
    Breezy
    First of all thanks for that very needed post of yours.
    Secondly i always felt it strange to do it like this. But had not enough time and motivation to do so.
    Apperently it seems that has changed now. In case this´ll lead to future "Mods" from my side i´ll tag
    you as instructor and recommend your Topic.
    Cheers for this quality information.

    Quote Originally Posted by qinghuanb111 View Post
    right ,MPGH can userd dll to inject 7DTD
    There will be no injection required since it gets loaded as a mod.


    Quote Originally Posted by jim2029 View Post
    FYI, for me at least, the build/collect/dig distance is not changed from stock and you can't see anyone else on the map. Only thing that is edited is the ability to have cm/dm.
    Apparently thats because constants are not accepted to be changed during the GameStarting phase.
    They´d have rather being changed after that. Haven´t found out which Event should be best for it but im on it right now.
    Changing them while being ingame works flawlessly.

    Take a look yourself:
    https://ibb.co/JyrDf9q


    A small added hack menu which sets a collection of constants does the job well.
    Last edited by H34db4nger; 12-01-2023 at 02:55 AM.

  7. #6
    jim2029's Avatar
    Join Date
    Jan 2012
    Gender
    male
    Posts
    45
    Reputation
    10
    Thanks
    3
    How do you change them in game? I don't have a menu on the left like you show unless I'm missing a hot key somewhere.

Similar Threads

  1. [Tutorial] How to use as many mods as wanted(better way)
    By Aborted in forum Combat Arms Mod Tutorials
    Replies: 14
    Last Post: 08-23-2011, 02:32 PM
  2. Better way then System()
    By That0n3Guy in forum C++/C Programming
    Replies: 5
    Last Post: 11-19-2009, 09:29 PM
  3. [Release]Better way to get allways HS
    By Houston in forum Combat Arms Europe Hacks
    Replies: 7
    Last Post: 07-28-2009, 10:37 AM
  4. easy way to create wr test accounts
    By c_norris in forum WarRock - International Hacks
    Replies: 16
    Last Post: 09-05-2007, 04:03 PM
  5. [tut] better way to make a kssn
    By damanis1 in forum WarRock Korea Hacks
    Replies: 6
    Last Post: 05-20-2007, 11:41 AM