ModScriptBasics: Difference between revisions

From The Colonists
Jump to navigation Jump to search
initial placeholder - needs formatting
 
No edit summary
Line 1: Line 1:
Basics-Scripting (C#)
Basics-Scripting (C#)


=Basics
=Basics=


For now follow the Rimworld, setup, but instead of the Rimworld dll use Game.dll from TheColonists folder.
For now follow the Rimworld, setup, but instead of the Rimworld dll use Game.dll from TheColonists folder.
Line 7: Line 7:
[https://rimworldwiki.com/wiki/Modding_Tutorials/Setting_up_a_solution](https://rimworldwiki.com/wiki/Modding_Tutorials/Setting_up_a_solution)
[https://rimworldwiki.com/wiki/Modding_Tutorials/Setting_up_a_solution](https://rimworldwiki.com/wiki/Modding_Tutorials/Setting_up_a_solution)


==Framework Sample
==Framework Sample==


This is a basic class which sets up Harmony, registers a custom tech and contains a Harmony prefix for when a player completes a research.
This is a basic class which sets up Harmony, registers a custom tech and contains a Harmony prefix for when a player completes a research.

Revision as of 15:11, 30 November 2022

Basics-Scripting (C#)

Basics

For now follow the Rimworld, setup, but instead of the Rimworld dll use Game.dll from TheColonists folder.

[1](https://rimworldwiki.com/wiki/Modding_Tutorials/Setting_up_a_solution)

Framework Sample

This is a basic class which sets up Harmony, registers a custom tech and contains a Harmony prefix for when a player completes a research.

===

using HarmonyLib; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine;

namespace TestMod2 {

   public class TestMod2 {
       static public int CUSTOM_TECH_1_ID = 200;
       [StaticConstructorOnStartup]
       public static int Init() {
           Harmony.DEBUG = true;
           var harmony = new Harmony("testmod2");
           FileLog.Log("testing harmony logging");
           harmony.PatchAll();
           SerialiseFactory.AddCustom(typeof(TechInfo), (byte) CUSTOM_TECH_1_ID, typeof(CustomTechInfo));
           Debug.Log("#TestMod2# Init Complete!");
           return 2;
       }
   }
   [HarmonyPatch(typeof(Player), "OnTechResearched")]
   class Patch {
       static void Prefix(TechID techId) {
           Debug.Log("#TestMod2# OnTechResearched:" + techId);

if((int) techId == TechMod2.CUSTOM_TECH_1_ID) { FileLog.Log("custom tech researched - myVar: " + techId.ToInfo<CustomTechInfo>().myVar); }

       }
   }

}

=======