#How to Create a C# Mod

1 messages · Page 1 of 1 (latest)

wooden plume
#

Since Craig's videos are several years old now, and the setup is slightly different now compared to then, I've written a guide for setting up a basic C# mod for Total Miner. Currently, the guide covers the basic setup and using your custom items in the mod, but I plan to include other specific functionality, such as adding new Lua functions, arcade games, etc.

Note: This is a written guide, not a video.

This guide assumes you have some basic knowledge of C#. If not, you'll need to learn C# first. There are many free resources online to help you get started.

This guide is also going to focus on the C# side of mods. Some basic XML setup will be included, but for the most part this guide assumes you either already know how XML mods work (where it's needed) or aren't planning to use it.

We will be using Visual Studio 2022 in this guide, but the setup for Visual Studio 2026 is mostly the same. If you have a different preferred editor, some parts of this guide may not apply the same way.

Your feedback is greatly appreciated! If you have any questions or something isn't explained clearly, let me know here and I'll try to help. If needed, I can also update the guide to better explain it.

https://github.com/DaveTheMonitor/TMModTutorial/blob/master/README.md

GitHub

Tutorial for creating a basic Total Miner mod. Includes an example mod. - DaveTheMonitor/TMModTutorial

wild heron
#

Could you give some examples as to what modding (currently) can do that you can't do in game if possible?

#

Other than new items which is already really handy and cool

wooden plume
#

The guide repo contains an example mod that'll have all the features covered in the guide. Some examples of things that can be added are:

  • Custom Lua script functions
  • Custom block meshes
  • Custom arcade machine games
  • Custom GUI menus
wooden plume
#

Added new tutorials:

Handling Input

Perform actions when the player presses a key or button.

Saving Data

Save custom data for the world that shouldn't reset when the world is reloaded.

Player Data

Give the player custom data, such as mana for swinging a staff.
Note that this tutorial is more advanced than the others

Also fixed the monogame link and slightly updated the existing guides

sinful crest
#

@wooden plume wasn’t there supposed to be stiff for arcade mods?

#

that or any version where it is ITMPlugin.Initialize(ITMPluginManager mgr, ITMMod path) rather than ITMPlugin.Initialize(ITMPluginManager mgr, string path)

#

@calm spear if you’re able to help

sinful crest
#

or is there no api suipport for arcade games

dusty timber
wooden plume
# dusty timber <@377461942362701825> Jus wanna let you know this link is broken https://docs.m...

If that's the link for downloading the MonoGame templates, here's the new link:
https://docs.monogame.net/articles/getting_started/2_choosing_your_ide_visual_studio.html#install-monogame-extension-for-visual-studio-2022
I'll update it when I can

This section provides a step-by-step guide for setting up your development IDE on Windows for Visual Studio.

dusty timber
#

Ty

wooden plume
sinful crest
wooden plume
sinful crest
#

i did that, but the issue i’m having is that with my mod, when you select the game, your character will continuously swing their arm

#

so i think that there’s something missing

i’m not sure if i’m missing any xml stuff, if there needs to be because if you mess with the xml data for total rush and do something it doesn’t like, the same thing happens

#

but the other games don’t have them, so idk what’s going on
@wooden plume

wooden plume
#

When the player continuously swings that means your mod is throwing an exception. Attaching the debugger usually catches exceptions, if not you have to use breakpoints and monitor fields/locals effectively to find it

sinful crest
#

ok

wooden plume
#

With the hand swing specifically, these are almost always exceptions being thrown on swing events. In the case of an arcade game, most likely something was initialized incorrectly.

sinful crest
#

ok

sinful crest
#

would it be possible to provide a custom texture and then use it for one of the unused 12 arcade textures? @wooden plume

#

does the game support custom texture swapping of existing textures?

wooden plume
#

afaik the game doesn't use those textures at all, so changing them wouldn't do anything
And the game doesn't support dynamic texture changing like that unless you use C#, but that's a complicated mess

sinful crest
#

how does the texture pack api work

does it not allow for texture swapping

wooden plume
#

The current texture pack system is a single atlas image. It wouldn't make sense to use an entire texture pack for one arcade game texture.
If the arcade API is updated (which it might be after the block ID changes), then custom textures will probably be supported then

sinful crest
#

that’s poop

wooden plume
wooden plume
#

I'm in the process of updating the tutorial so the setup is accurate, and making it easier to find working examples for each page. Until then, if your mod doesn't work, then follow these steps:

Your project most likely references the wrong MonoGame version.

A little while ago, MonoGame updated to 3.8.4. The current template is set to reference 3.8.*, which will automatically choose the most recent 3.8 version - currently 3.8.4. When the tutorial was made, the template referenced the exact version that the template was for.

TM uses MonoGame 3.8.1.303, so you need to change the project to reference MonoGame.Framework.DesktopGL 3.8.1.303. Project -> Manage NuGet Packages -> Installed -> MonoGame.Framework.DesktopGL -> Version -> 3.8.1.303 -> Update

wooden plume
#

Updated the tutorial. It is now accurate to the most recent version of the game. The tutorial still uses Visual Studio 2022 for the setup, but the setup for Visual Studio 2026 is mostly the same, so you should still be able to follow along if you'd rather use that.
I've also reorganized the tutorial to make it easier to view the code required for each section by giving each section its own project.
I plan to add more sections in the near future, if there's anything in particular you'd be interested in knowing about, please let me know!

#

Sorry it took so long, it didn't actually take 7 months to update it. I just put it on the backburner while I had other things to do.

wooden plume
#

Added a Lua functions tutorial

wooden plume
#

Should I add a section to the modding guide on using Harmony?
A lot of mods that want to do more advanced stuff will probably want to use it, but it feels like it might be out of the scope of the tutorial (which is showing how to use the game's API)