Ludeon Forums

RimWorld => Mods => Topic started by: ambivalence on October 10, 2017, 12:20:10 PM

Title: C++ and RimWorld mods.
Post by: ambivalence on October 10, 2017, 12:20:10 PM
Is it possible to write mods for the game using C++? I have some skill in it and I know, that Unity engine (just for example) seems to support the ability to use in some way. Not very interested in gamedev though, so I cannot tell it for sure; just like RimCommunity and wanna contribute some.
Title: Re: C++ and RimWorld mods.
Post by: Kiame on October 10, 2017, 12:40:04 PM
Seeing as Visual Studio can compile .Net languages into the same intermediate language it's probably possible. Really though, if you know C++ going to C# is simple. And as someone who did that transition (not for rimworld in my case) I can't even imagine going back to C++. C# is just so much cleaner to work in.
Title: Re: C++ and RimWorld mods.
Post by: Nightinggale on October 23, 2017, 08:12:05 PM
Speaking as a C++ programmer, I say if you know C++, you know C#. All I had to do was to look up yield return and that's about it. The rest is based on just looking at the vanilla source code, which modders will have to look at anyway. I had a bit of a beginenr's problem connecting with the Harmony library, but once that was solved, it look like 2-3 hours and I had a mod, which I have been missing for ages. It's not like C++ and C# are really different.

Oh and do look up methods vs properties. While they are nearly identical, they aren't in all cases.
Title: Re: C++ and RimWorld mods.
Post by: Fluffy (l2032) on October 25, 2017, 07:19:35 AM
QuoteSeeing as Visual Studio can compile .Net
C++ is not a .Net language, is it?

QuoteOh and do look up methods vs properties. While they are nearly identical, they aren't in all cases.
Technically, a property is a combination of two methods, a getter, and a setter. It's just syntactic sugar, really. Ofcourse, there's a bunch more magic going on behind the scenes with magic properties (automatically create a backing field), and getter shorthand. In addition, there's some extra reflection helpers for properties (but you could also just use method reflection on [propertyName]_get to get the getter method directly).

But yeah, C# is a really nice beginner language, and should be easy coming from C++. The language itself is incredibly descriptive, to the point of being overly verbose. Also, it's managed, so it's quite a bit harder to create memory leaks.

As far as I know, the Unity engine itself is written in C++, but applications built on it are generally C# or JavaScript (yuck). Ofcourse, you can create bindings to C++ methods from C#, but that's probably more trouble than it's worth for most projects.
Title: Re: C++ and RimWorld mods.
Post by: Nightinggale on October 25, 2017, 08:49:25 AM
Quote from: Fluffy (l2032) on October 25, 2017, 07:19:35 AMTechnically, a property is a combination of two methods, a getter, and a setter. It's just syntactic sugar, really. Ofcourse, there's a bunch more magic going on behind the scenes with magic properties
Yeah they are nearly the same and usually interchangeable, which is why people do not pay much attention to it when you see what is written online. However reading the Harmony documentation for methods and applying it to a property was part of the reason why it took me a few days to get Harmony to work as intended. Apart from that, issues and progress has been unrelated to C# itself and would have been just the same in C++.