Posted: Sun Jan 18, 2015 7:16 pm Post subject:
SUN.EXE Source code
The title says it all, the attachment contains a solution file with the source code of SUN.EXE
I'm new to this forum and I'm a big fan of the Westwood games. Since I like coding and I wanted to expand my field of knowledge I started to decompile tiberian sun. I started with the executable SUN.EXE since that's the main entry point of the whole game.
Short summary of executable:
- It reads NameOfExe.lcf, where NameOfExe is SUN
- Tries to apply patches if any by invoking patchget.dat, whilst using information from the file above
- Runs game.exe and waits until that returns
PLEASE NOTE:
All naming in the source code was up to my own interpretations, this also counts for the layout of the source files.
This executable that comes out of the source code when compiled should behave exactly the same as the original SUN.EXE with only one exception:
The original SUN.EXE could be given arguments when ran (for example: trough cmd.exe and adding arguments). Some parsing of these arguments was going on in the original code which I haven't been able to identify yet. Also I was unable to test some methods, I have flagged these with a macro SUN_UNTESTEDA, however it's very unlikely that they will not function, since I'm pretty sure I decompiled them properly and last: when reading launcher.txt when there's a patch applied it shows the patch notes. I couldn't completly test the parsing of this file, however I think the result is still the same.
COPYRIGHT STUFF:
I do not care what you do with this source as long as you don't claim that you are the creator of it. If you modify it in such a way that it's completly different it would be nice if there's a reference to me.
COMPILATION:
I wrote and test compiled this in Visual Studio 2013 Ultimate. I'm unsure what version the original exe is but the last modification date is: 18-05-1999 12:18 and size 80kb
Huh what? You post source code of a worthless launcher exe???
Maybe if you start with game.exe... as that launcher is of no use as its easily disabled from ever being needed by game.exe anyways.
If one is trying to decompile the entirety of Tiberian Sun, he would have to begin from the beginning. Which is SUN.EXE. Also If you have read my post it stated that I'm trying to expand my knowledge and beginning with a simple patcher executable is a whole lot easier than the game itself. QUICK_EDIT
Also Known As: banshee_revora (Steam) Joined: 15 Aug 2002 Location: Brazil
Posted: Sun Jan 18, 2015 11:05 pm Post subject:
Hello Neijwiert and welcome to PPM forums. This place has a legion of people that, likewise you, are trying to learn things by decompiling Tiberian Sun and other games. So, your efforts are appreciated here.
However, what Apollo has been trying to warn you is that you are going to the wrong direction if you think that sun.exe has any use at all. I mean, sun.exe is so useless that you do not need to actually run it to run the game. As you've probably seen, it works to patch the game, specially when you go online for the first time with the unpatched version of the game. The truth is that you can play the game by executing game.exe instead of sun.exe.
So, no, sun.exe is not the beggining, as you said. The whole game logic is in game.exe.
Also, perhaps you might be interested on some initiatives to inject C++ code at the game.exe by using Syringe. While Ares does it with Yuri's Revenge, HyperPatch works with Tiberian Sun's game.exe. They've already mapped most of the important functions of these games and they use these addresses to run their own stuff once the program passes through these memory addresses. QUICK_EDIT
Hello Neijwiert and welcome to PPM forums. This place has a legion of people that, likewise you, are trying to learn things by decompiling Tiberian Sun and other games. So, your efforts are appreciated here.
However, what Apollo has been trying to warn you is that you are going to the wrong direction if you think that sun.exe has any use at all. I mean, sun.exe is so useless that you do not need to actually run it to run the game. As you've probably seen, it works to patch the game, specially when you go online for the first time with the unpatched version of the game. The truth is that you can play the game by executing game.exe instead of sun.exe.
So, no, sun.exe is not the beggining, as you said. The whole game logic is in game.exe.
Also, perhaps you might be interested on some initiatives to inject C++ code at the game.exe by using Syringe. While Ares does it with Yuri's Revenge, HyperPatch works with Tiberian Sun's game.exe. They've already mapped most of the important functions of these games and they use these addresses to run their own stuff once the program passes through these memory addresses.
Thank you. I'm not planning on injecting anything at all, I'm looking for decompilation. I'm aware that SUN.EXE is not required to play Tiberian Sun, but what I meant with 'main entry point' is that if you'd put all the files of tiberian sun in perspective (so not only the actual game code) SUN.EXE would be on top. And again, as I said before, SUN.EXE is a fairly simple (small) executable and good for me to start with. I've already started with Game.exe. The only thing that might be useful to me if those code injections mention the functionality of the addresses they hook, that could save me time on figuring out of what they do. QUICK_EDIT
Its good to see someone interested in fully decompiling the game into a recompileable form, they guys involved in the ares and hyperpatch projects have already done a lot of work in mapping out the exe which should provide a leg up. Just be sure to release your efforts even if they are incomplete if you ever loose interest in the project so others might take up the gauntlet down the road.
I would say though to try and replace any windows API calls with cross platform code wherever possible. I realise that TS makes heavy use of some aspects of the winapi, but anything you cross platform during decompilation will make any porting efforts easier if and when a compileable version is available. QUICK_EDIT
Its good to see someone interested in fully decompiling the game into a recompileable form, they guys involved in the ares and hyperpatch projects have already done a lot of work in mapping out the exe which should provide a leg up. Just be sure to release your efforts even if they are incomplete if you ever loose interest in the project so others might take up the gauntlet down the road.
I would say though to try and replace any windows API calls with cross platform code wherever possible. I realise that TS makes heavy use of some aspects of the winapi, but anything you cross platform during decompilation will make any porting efforts easier if and when a compileable version is available.
I will release all the decompiled code, regardless if I'm going to finish it or not. I will not focus on making it cross platform (yet) first I'm going to focus on the original code. Then I might take a look at that. (Or just use windows lol :p) QUICK_EDIT
I don't get why some people are so butthurt that you decompiled SUN.EXE, the fact this is happening and he already stated he'd be moving on to Tiberian Sun itself is good to hear.
I'm curious though, isn't this process, decompiling GAME.EXE, going to take a very long time?
I'd indeed also focus first on decompiling and understanding everything before moving on to cross platform support.
Nice to see this happening!
I hope I can use some knowledge in the new map editor hehe _________________
Neijwiert: We have been spending a lot time with the games already, you should join our irc channel and hang around there, i have no doubt we can help you out with some things
Also Known As: ZivDero Joined: 23 Jul 2013 Location: Russia
Posted: Mon Jan 19, 2015 9:18 pm Post subject:
Are you gonna move on to Red Alert 2 + YR? It could:
a) Help with the development of Ares
b) Reveal what is really left in the game from TS (repair the old logics with modified TS code?) and use that for A
c) modify and recompile the engine to use the modern technologies for compatibility purposes. Repairing an old game could make it live longer. _________________
DarkVen9109 wrote:
What in the name of insanity is this? I FRICKING LOVE THIS LOGICCCC!!!!!!!!!!!!OOOOOOOOHEEAWWWWWWWWWWWYAAAAAAAAAAAAAAAAAWWWWWW PEW PEW PEW PEW BOOM BOOM BOOM!! Nice I love this!!!! Ferriswheel bomb, Dive bomb. New Logic discovered thanks to Kenosis
He has barely started with TS (which by itself is already a gigantic job to decompile) and you're already asking if he'll move on to RA2/YR? Really, give him some time, he has only decompiled SUN.exe so far and has just started with Game.exe, which is where all the game logic is. _________________ CnCNet Client | CnCNet TS patches | More Quality-of-Life Improvements for RA Remastered
Joined: 22 Nov 2010 Location: Iszkaszentgyorgy, Hungary
Posted: Mon Jan 19, 2015 11:49 pm Post subject:
Ignore Parasite, he has no idea what he's even talking about.
Good luck, Neijwiert. I'd say more but sadly, even I'm not enough qualified to aid you in what you try to achieve. Some of the logics are quite simple tho and the YR class hierarchy is quite done - while hierarchies are quite simple, it could still give you a hint regarding which variable you're looking at. On the other hand since YR and Firestorm are two branches of the same tree, they're not 1:1 copies so I'm not even certain that could help at all. _________________ "If you didn't get angry and mad and frustrated, that means you don't care about the end result, and are doing something wrong." - Greg Kroah-Hartman
=======================
Past C&C projects: Attacque Supérior (2010-2019); Valiant Shades (2019-2021)
=======================
WeiDU mods: Random Graion Tweaks | Graion's Soundsets
Maintainance: Extra Expanded Enhanced Encounters! | BGEESpawn
Contributions: EE Fixpack | Enhanced Edition Trilogy | DSotSC (Trilogy) | UB_IWD | SotSC & a lot more... QUICK_EDIT
I don't get why some people are so butthurt that you decompiled SUN.EXE, the fact this is happening and he already stated he'd be moving on to Tiberian Sun itself is good to hear.
I'm curious though, isn't this process, decompiling GAME.EXE, going to take a very long time?
I'd indeed also focus first on decompiling and understanding everything before moving on to cross platform support.
Nice to see this happening!
I hope I can use some knowledge in the new map editor hehe
It is indeed going to take a very long time. I won't be done in a week like I was with SUN.EXE. In my post below I will post a link to my current progress. I haven't come across any map editor logic yet, or any code related to how the maps work.
FunkyFr3sh wrote:
Neijwiert: We have been spending a lot time with the games already, you should join our irc channel and hang around there, i have no doubt we can help you out with some things
I will definetly be joining that channel if I have questions. I'm a bit rusty with Tiberian Sun myself, so I'm hoping other people can fill in the blanks.
Parasite03 wrote:
Are you gonna move on to Red Alert 2 + YR? It could:
a) Help with the development of Ares
b) Reveal what is really left in the game from TS (repair the old logics with modified TS code?) and use that for A
c) modify and recompile the engine to use the modern technologies for compatibility purposes. Repairing an old game could make it live longer.
a) Don't know what that is, I'm assuming it's a mod?
b) I'm aware that it will reveal it, that's why it's called reversed engineering to 'reveal' the source code. And yes I'm aiming for it to be used in mods. The one thing I'm affraid of is that it will be used to cheat.
c) Also part of my final plan. Will be looking at multi-platform porting and maybe bugfixing and stuff.
Graion Dilach wrote:
Ignore Parasite, he has no idea what he's even talking about.
Good luck, Neijwiert. I'd say more but sadly, even I'm not enough qualified to aid you in what you try to achieve. Some of the logics are quite simple tho and the YR class hierarchy is quite done - while hierarchies are quite simple, it could still give you a hint regarding which variable you're looking at. On the other hand since YR and Firestorm are two branches of the same tree, they're not 1:1 copies so I'm not even certain that could help at all.
I'm not even sure if I'm qualified aswell. So far its been going quiete well, but I might stumble upon code I just cannot decompile. I had this obstruction with SUN.EXE too. The way it stored all the entries in SUN.lcf looked really weird in the dissasembler and took me about 2 days to figure out what data type the first field was in LauncherConfigFile.
I don't really know in what way the expansions are related, but what I do know is that the plane tiberian sun version has some stuff that is about firestorm.
So yeah I've been going about and started working on Game.exe. I have made a solution with (so far) the following projects: Game, Language and SUN. SUN and Language(.dll) are completly decompiled. with language having the exception of 2 resource entries not decompiled. I haven't identified those yet. They have ID 192 and 193. I haven't named all the strings in the strings table yet (macros for their ID), since there are just too many entries. I will go about and name these as I come across them in the code. If anyone feels like naming them already or creating better names for the dialogs, be my guest. Like I said I'm a bit rusty and I might get names wrong.
If you are going to make this public from the get go, you might want to put it in a github repo or something similar rather than just raring it up. That way interested parties can just pull the work in progress and if they have any insight, they can provide patches. QUICK_EDIT
Also Known As: ZivDero Joined: 23 Jul 2013 Location: Russia
Posted: Wed Jan 21, 2015 2:02 pm Post subject:
^Rampastein wrote:
Quote:
Are you gonna move on to Red Alert 2 + YR?
He has barely started with TS (which by itself is already a gigantic job to decompile) and you're already asking if he'll move on to RA2/YR? Really, give him some time, he has only decompiled SUN.exe so far and has just started with Game.exe, which is where all the game logic is.
I did not mean to say something like "Do that because I need it".
I just asked if he had plans to do that in the not near future or if he has not thought about other games yet. _________________
DarkVen9109 wrote:
What in the name of insanity is this? I FRICKING LOVE THIS LOGICCCC!!!!!!!!!!!!OOOOOOOOHEEAWWWWWWWWWWWYAAAAAAAAAAAAAAAAAWWWWWW PEW PEW PEW PEW BOOM BOOM BOOM!! Nice I love this!!!! Ferriswheel bomb, Dive bomb. New Logic discovered thanks to Kenosis
Change of plans; I'm going to assist CCHyper as he is very far in the process of decompiling. The progress will not be open-source because of his terms. QUICK_EDIT
Change of plans; I'm going to assist CCHyper as he is very far in the process of decompiling. The progress will not be open-source because of his terms.
You make it sound like I am a dictator! QUICK_EDIT
Since when are Hypers minions allowed to speak in the public?
@Neijwiert: It's nice to see fresh blood in the modding and hex-editing community. Good luck with your project. I'm looking forward for any progress you can make. _________________ SHP Artist of Twisted Insurrection: Nod buildings
i know, though in this case it's the same to me.
game.exe->assembler->high-level language source code->compiled exe
assembler = knowing which hex addresses do what. then changing them to change the game, which is hex editing
high-level language source code= adding new code->leads to new/different logics, which is modding too _________________ SHP Artist of Twisted Insurrection: Nod buildings
There isn't much point it being open source until its actually compilable into something useful. The game is much larger than SUN.exe with thousands of functions so it might take a little while longer and that assumes that everyone involved keeps up their motivation. With time and a little luck we might end up with something like OpenDune for the older C&C games, but lets not get ahead of ourselves here, this is a lot of code to go through and rewrite to compilable source code. QUICK_EDIT
There isn't much point it being open source until its actually compilable into something useful. The game is much larger than SUN.exe with thousands of functions so it might take a little while longer and that assumes that everyone involved keeps up their motivation. With time and a little luck we might end up with something like OpenDune for the older C&C games, but lets not get ahead of ourselves here, this is a lot of code to go through and rewrite to compilable source code.
There is no need to wait until the whole game was rewritten, you can rewrite just one function and use it right away... Yes, we have a nice patching system if you didn't hear of it yet (even if you are everyday in our IRC channel) QUICK_EDIT
I actually wonder why Hyper doesn't also make use of that patching system. Being able to release one hack (or a few hacks) at a time seems a lot more practical (and faster) that doing everything at once after all. _________________ QUICK_EDIT
I actually wonder why Hyper doesn't also make use of that patching system. Being able to release one hack (or a few hacks) at a time seems a lot more practical (and faster) that doing everything at once after all.
The newer patching system is not different to any other way bar it being quicker. QUICK_EDIT
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum