How do Valve create games that run on Linux, Mac and Windows? I imagine they dont really write one version for each platform bec that would just be a nightmare.. or do they? I imagine it is written in a portable C++ code (or C#?) but I wanted to know more details about this. I've developed an app on Adobe AIR and considering on porting it to a diff language as Adobe abandoned linux support.
Every Valve product is developed using their own in-house game engine called Source. The Source Engine is written in C++. The source engine contains both an OpenGL and a DirectX renderer which helps it in being cross platform, but the key is SDL. The open source Simple Direct Media Library is used by a team inside Valve which is tasked almost exclusively with taking Valve's popular products cross-platform. SDL allows Valve to focus less on writing redundant code that will work here, there, and everywhere and instead focus on fixing what needs to be changed to allow for the build to work on platform X, Y, and Z and let SDL take care of the rest.
SDL allows for this by creating a simple interface that works for every platform (well not every platform, but the ones that matter) when it comes to things like window management, context management, event handling, etc. Without SDL you would have to write code that makes a window for Windows, OSX and Linux just to get the basic window management stuff to work cross platform. In SDL, you call three functions and you have a window. See the reason why people use it now? SDL is at the heart of most of Valve's games today because they are beginning to think about cross-platform from the beginning.
I'm not specifically talking about Dota2 but about most of cross-platform games in general.
Usually developers create/use a middle were called GameEngine. It's usually in a form of a large scale library containing tools for all sorts of things such as handling game physics, loading and rendering graphical objects, loading and running scripts, managing network related stuff, and so on...
That GameEngine thing can also provide support for those kind of things across multiple platforms. It provides developers with a unified interface, while having different implementations across different platforms. The same thing happens almost every time you see a cross platform application. Even C# itself that you mentioned is doing the same thing under the hood; it's providing a unified developing experience across all platforms, while handling platform-specific differences under the hood.
In case of valve (Dota2 and their other games) that GameEngine is called "Source Engine". while anything built on top of Source Engine is platform independent, the engine itself have different implementations for different operating systems. Here is an example: the engine might have a function to draw an sphere. In windows this routine is written using DirectX while in linux and mac it's using OpenGL.
It means higher level developers including those who are implementing game logic and pretty much everything in a game, won't even notice platform changes, but in it's base level code Dota2 (and pretty much any other game) is written once per platform.