Guides/Modding

*Guide by **Jdewi***

This guide will touch on how to create Roguelands mods.

## Requirements

* Gadget Core from GitHub
* Visual Studio Community with **.NET desktop development** module (2019 or later recommended) from Microsoft

## Template Mod

1. Decide on a place to keep your mods (e.g. *Documents/MODS*).
2. Download Code as ZIP from https://github.com/SuperKael/Gadget-Core.
3. Extract the GadgetCore.xml file inside the Release folder and copy it to the *Roguelands\_Data/Managed* folder in your Roguelands folder.
4. From the same zip, extract the folder named **TemplateGadgetMod** and copy it into your modding folder (e.g. *Documents/MODS/TemplateGadgetMod*)
5. Rename the TemplateGadgetMod folder and the TemplateGadgetMod.cs and TemplateGadgetMod.csproj within, and edit the contents of Manifest.ini to something more appropriate for your mod (e.g. BugFixMod, BugFixMod.cs, BugFixMod.csproj, BugFixMod, BugFixMod.dll).
6. Follow the instruction in the README.txt file inside your mod's folder to set up **GamePaths.xml**. The ManagedFolder field should be **Roguelands\_Data/Managed/**.
7. Open Visual Studio and choose **Create a new project** and select **Blank Solution**.
	1. The Location will be one folder above where you store your mods (e.g. *Documents*).
	2. The Solution Name will be the name for where you store your mods (e.g. *MODS*).
	3. This should have the same spelling and capitalization so your solution file appears inside your modding folder.
	4. Click Create.
8. There should be a panel named **Solution Explorer** on the right side of the window (if not, go to *View -> Solution Explorer*).
	1. Right click on the solution you just made in the Solution Explorer and go to *Add -> Existing Project...*
	2. Direct it to the **.csproj file** in your mod's folder (e.g. *Documents/MODS/BugFixMod/BugFixMod.csproj*).
9. Replace the TemplateGadgetMod name with your mod's name.
	1. Hit Ctrl+F to open the Find and Replace dialogue
	2. Change the tab to *Replace in Files*
	3. Set the *Find text* to **TemplateGadgetMod**
	4. Set *Replace text* to your **mod's name without spaces** (e.g. BugFixMod). Click *Replace All*.
	5. Set the *Find text* to **Template Gadget Mod**
	6. Set the *Replace text* to your **mod's name** (with or without spaces, e.g. BugFixMod or Bug Fix Mod). Click *Replace All*.
10. In the Solution Explorer, expand the Properties folder and double-click AssemblyInfo.cs to edit it. Change all the template stuff.

## Creating the mod

* Now that you have your template mod set up you can modify it to do whatever you want.
* You can include textures in your mod by creating a folder named `Assets` in your mod's folder (e.g. `BugFixMod/Assets`) and dropping .png files in there.
	+ Then selecting them in the *Solution Explorer* in Visual Studio and setting `Copy To Output Directory` to `Copy always` or `Copy if newer`. You can then load these textures with `GadgetCoreAPI.LoadTexture2D("FileName");`

## Initialization

* Most content can be added to the game via GadgetCore without needing to patch, by using GadgetCore's specific methods in your mod's `Initialize` method. See the examples below.

### Items

You can change the `ItemType` to create emblems, usables, armor, etc. `swordUseTex` here is the item texture that shows in your hand when equipped. The image itself is 64x64px but you mostly want to use the top right of the image; the image is centered on the player's hand. `swordInventoryTex` is the item texture in your inventory. The image itself is 32x32px but you should generally only use the middle 14x14 to fit in an inventory slot.

```
protected override void Initialize()
 {
    Texture2D swordUseTex = GadgetCoreAPI.LoadTexture2D("SwordUse.png"); // equipped
    Texture2D swordInventoryTex = GadgetCoreAPI.LoadTexture2D("SwordInventory.png");
    sword = new ItemInfo(ItemType.WEAPON, "Sword", "Scales with STR + FTH/2", swordInventoryTex, 20, new EquipStats(3, 2, 0, 0, 0, 2), HeldTex: swordUseTex);
    sword.SetWeaponInfo(new float[6] { 0, 1, 0, 0, 0, 0.5f }, (AudioClip)Resources.Load("au/i/i300")); // scaling and sound
    sword.Register("Sword");
    sword.OnAttack += sword.SwingSword; // you can replace this with your own attack coroutine
 }
```

### Combat Chips

This code goes in the initialize method like in the previous example.

```
ChipInfo myChip = new ChipInfo(ChipType.ACTIVE, "Example Chip", "Description here", 8, exampleTexture);
myChip.Register("Example Chip");
myChip.OnUse += MyChip_OnUse;

```

## Coding

### RPCs

A remote procedure call (RPC) is when a computer program causes a procedure (subroutine) to execute in a different address space (commonly on another computer on a shared network), which is coded as if it were a normal (local) procedure call, without the programmer explicitly coding the details for the remote interaction.