C# Modding relevant suggestions in gamecode

Started by MaMilaCan, June 11, 2014, 06:20:59 PM

Previous topic - Next topic

MaMilaCan

Greeting fellow coder  ;D

i just started to mod for Rimworld and really dont like "coding" xml so i started a C# mod.
After reading some old tutorials and quite some try and error (because of the old tutorials ;) i got the mod working.

Yes, i used ILSpy to get an idea how stuff works in Rimworld.

Here are some suggestions for making Coding mods "better".

Problems:
-> Live-Debugging not possible with attached VisualStudio

- when loading the assemblies in the ModAssemblyHandler the Command Assembly.LoadFile(fileInfo.FullName) is used ->  this command does NOT include the maybe existing pdb's wich may exist next to the DLL.
# I would suggest to use code like that:

      byte[] rawAssembly = File.ReadAllBytes("MOD.dll");
      byte[] rawSymbolStore = File.ReadAllBytes("MOD.pdb");
      Assembly assembly = domain.Load(rawAssembly, rawSymbolStore);

-> Creating a mod only in C# not possible

I understand that you at least need the xml About.xml, for the basic ModInfo,
but what i really would love to have is  a  convention like the following:

When the Assembly is loaded, Try to instantiate an object with the Name "InitClass" and immediately Call the void Init().
In there i can create all my defs, publish my classes, reasearch and so on.
So basically add a hook i can use to init my classes on assembly load.


I will keep adding things that jump in my way :D

Have a wonderfull day :)

MaMilaCan


mrofa

Hmm not sure but " Creating a mod only in C# not possible" thing might be used in vanillia+ mod already.

And 100% YES to live debugging if that means i dont need to turn off the game each time i want to change something in .dll :D
All i do is clutter all around.

Tynan

Thanks greatly MaMilaCan. I'm no expert with debugging tech so this is helpful. I'll try to get the pdb files linked as you specify.
Tynan Sylvester - @TynanSylvester - Tynan's Blog

Tynan

All right, I've hooked in the PDB loading; I hope it should work.

About the InitClass.Init method, I don't understand the use case. Can you give me examples of what you'd do in this kind of method?

MaMilaCan - Would you be willing to join the test team to try this out and make sure it works for Alpha5?
Tynan Sylvester - @TynanSylvester - Tynan's Blog

MaMilaCan

Yes i would love to!!!

The use case is as follows:

If you load the assembly and you than call a method i could register and build all the Things and Buildings of my Mod in code, rather than  in xml.

MaMilaCan

That would instantly reduce my debugging time to more than 60%!


Tynan

Quote from: MaMilaCan on June 16, 2014, 04:17:47 PM
That would instantly reduce my debugging time to more than 60%!

Why not just do them in XML like usual? You'd be breaking a number of systems (including translation and live editing) by hack-generating your defs in code.

Also, this init method would have to go at a specific point in the content loading process. Content loading is actually quite complex in this game, with all the cross-referencing, def generation from other defs, live editing support, mod content encapsulation, and def content injecting by the translation system.
Tynan Sylvester - @TynanSylvester - Tynan's Blog

MaMilaCan

Ok here is what i did until now to accomplish it:

i have a very basic xml with almost only the name of the class to create.
Inside that class i create my def in: PostMake

That means if you playce the first object of that type the def is created and kept shared for next objects to use. For performance i would like to do all that init before the game starts, wich is where the init function comes in handy.

Dont get me wrong, the about, my textures and Languages are still in the correct folder, and you can load them like before (btw: i really like how its done).

Hope that clarifies it.

Tynan

What you're doing will break various other game systems. Why don't you just but the def data in the def XML?
Tynan Sylvester - @TynanSylvester - Tynan's Blog

MaMilaCan

#9
I dont like xml-fiddling....
I am working as a programmer, so i want to code with objects.
for me xml is data - no instructions, but of course i see why you made it this way.
Its  a great strategy with the xmls, i was just asking if it is possible ;)

Right now my mod is working as i described it to you with no problem, but i dont get all the aspects for sure ...
Your the boss, if you dont think its a good idea i will find my way with xmls :D

Maybe some things get clearer if i send you my mod? Would you be interested in that?

superpirson

would it be posable to get this to work with the mono .mdb debug files. I have been searching around, and I haven't found an easy answer, but I figure there must be some mono equivalent to  domain.Load that would take a .mdb file. frankly though, I am a quite over my head.
specs: mid2009 MBP OSX 10.9.3 NVIDIA GeForce 9400M 256 MB

MaMilaCan

My reasearch results:
- problem is that unity has its own compiler
- because of that you will not be able to just attach to rimworld
- there is a plugin for VS -> UnityVS that allows debugging in VS BUT only if you are having Unity open and have the game loaded (of course only the author has all the sources so tgis is no way)
- only hope comes from Microsoft: They just bought UnityVS, will make it a free tool and integrate it better in VS, maybe than we have a chance ...

- sadly that will need some time ... if ever possible

Greetings

superpirson

No, what I am asking is if we can use a .mdb file instead of a .pdb file for the symbol data. I am not using vs, I am using Monodevelop. (I'm allergic to windows software)
specs: mid2009 MBP OSX 10.9.3 NVIDIA GeForce 9400M 256 MB