Skip to content

Mod Creation: The Project Environment

TheTimeSweeper edited this page Jul 8, 2023 · 5 revisions

This guide will go over how to start a new mod for Wizard of Legend from scratch:

  • Creating visual studio class library
  • Adding the necessary project references
  • Writing a BepInEx Plugin

Creating Visual Studio Class Library

  1. If you haven't already, download Visual Studio Community.
  2. Start Visual Studio, and create a C# Class Library (.NET Framework)
  3. Choose the Project name you wish, the Location you wish
  4. For Framework, choose .NET Framework 3.5.
  5. You're well on your way! Optionally, if you plan to upload this to a git repo, download a .gitignore for visual studio and place it in your solution folder

Adding the Necessary Project References

0. Skipping this section

You can simply download the lib folder here and use those. All the necessary references should be ready to go. If you do, skip to step 4

If you want (or, for any reason, need) to grab the references yourself:

1. Grabbing the Game Libraries

  1. Create a folder in your project directory called lib.
  2. Assuming you've installed BepInEx and have run the game modded (if not, download BepInEx Here)
    Navigate to the folder BepInEx/core, and copy all the files in there to your lib folder.
  3. Assuming you've run the game with HookGenPatcher (if not, download Here, install, and run the game once)
    Navigate to BepInEx/plugins/MMHOOK folder and copy the MMHOOK_Assembly-CSharp.dll to your lib folder.
  4. Navigate to your game's executable folder. Go to Wizard of Legend\WizardOfLegend_Data\Managed and copy over UnityEngine.dll and UnityEngine.UI.dll to your lib folder.

You only need one more dll to reference, but for that you're going to need to publicize

2. Publicizing Assembly-CSharp.dll

The reason we do this is to access the game code's private fields in our mods. This opens many doors for our mods without the need of something like reflection.

  1. Download NStrip.
  2. Download latest release and unzip.
  3. Open console command in the folder where you unzipped.
  4. Run the command .\NStrip.exe -p -cg -cg-exclude-events -remove-readonly <FULL_PATH_TO_WOL_FOLDER\WizardOfLegend_Data\Managed\Assembly-CSharp.dll>.
  5. This should spit out a new .dll with all the method bodies stripped, and fields publicized.
  6. Finally, add this new .dll to your lib folder.

3. Grab any Mod Dependencies

If you plan on adding relics, robes, and/or arcana you'll be using LegendAPI.
For this, or any other mod you want to use the code of, you need to add those as references as well
(Again, if you're using the template, a LegendAPI.dll should already be there)

  1. Find the mod on wizard-of-legend.thunderstore.io.
  2. Manually download the latest version.
  3. Unzip the downloaded mod, find the .dll file and add it to your lib folder.

4. Adding the References to Your Project

With all the assemblies gathered, you can now add them all to your project's references:

  1. Back in Visual Studio, find the solution explorer on the right. Under your CSharp project, right click References and choose Add Reference...
    image
  2. Navigate to your lib folder, and add all .dll files

In order to use the publicized Assembly-CSharp.dll, you need to have these lines anywhere in your codebase:

using System.Security;
using System.Security.Permissions;

[assembly: SecurityPermission( SecurityAction.RequestMinimum, SkipVerification = true )]

For organization, I usually create a new file called ModAccess.cs with only these lines.

Writing a BepInEx Plugin

This is where basic knowledge of classes, functions, and attributes in C# will come into play. If you do not have that, it should be quite easy to get online.

  • Your CSharp Project in Visual Studio usually starts with a base class called Class1.cs.
  • Rename this class and file to whatever you like, conventionally ending in Plugin (For example MyCoolModPlugin)
  • Make this class inherit from BaseUnityPlugin and add the BepInPlugin attribute like this:
[BepInPlugin("CoolAuthorName.CoolModName", "Cool Mod Name", "0.1.0")]
public class MyCoolModPlugin: BaseUnityPlugin 
{
    void Awake() 
    {

    }
}

This is the basis of every mod. Your mod should now work! It won't do anything, but you can build this project and Bepin should load it.
(if it doesn't, ping thetimesweeper on discord and tell him he FUCKED UP)

And you're done!

Your project environment is set up to start modding.

Continue to the First Mod guide to learn more about the BaseUnityPlugin you've just created, and how to take your mod further.

After you've understood that, if you'd like to create Relics (Items), Robes (Outfits) or Arcana (Skills), refer to the Custom Content pages on this wiki.

Good luck and have fun!