Ludeon Forums

RimWorld => Mods => Help => Topic started by: RawCode on November 17, 2015, 05:42:00 AM

Title: (not) Original research: <Module> .cctor as mod entry point for RimWorld
Post by: RawCode on November 17, 2015, 05:42:00 AM
TL:DR - does not work as "entry" point, will be invoked before any other method in module, if no methods are invoked - no luck.

In order to test things, i checked some articles about "Module constructor C#" and found related content: http://einaregilsson.com/module-initializers-in-csharp/

Code below is "copy paste" with few additional lines.
namespace Rimgazer
{
    public static class module
    {
        public static void main()
        {
            Console.WriteLine(Environment.StackTrace);
            Console.WriteLine("LOOKS LIKE MODULE CCTOR");
        }
    }
}


In order to test how things will go, i "wrote" same loading 2 liner:

byte[] rawAssembly = File.ReadAllBytes("Rimgazer.dll");
Assembly asm = AppDomain.CurrentDomain.Load(rawAssembly);

Console.WriteLine (asm);

RuntimeHelpers.RunModuleConstructor (asm.GetModules ()[0].ModuleHandle);
Console.WriteLine ("BREAK");
asm.GetTypes ()[0].GetMethod ("main").Invoke (null, null);


RimWorld invoke no debugging, just "asm.GetTypes ()" and this invocation will not trigger module cctor.