Project Perfect Mod Forums
:: Home :: Get Hosted :: PPM FAQ :: Forum FAQ :: Privacy Policy :: Search :: Memberlist :: Usergroups :: Register :: Profile :: Log in to check your private messages :: Log in ::


The time now is Tue Apr 16, 2024 3:28 pm
All times are UTC + 0
SUN.EXE Source code
Moderators: Global Moderators, Tiberian Sun Moderators
Post new topic   Reply to topic Page 1 of 1 [31 Posts] Mark the topic unread ::  View previous topic :: View next topic
Author Message
Neijwiert
Civilian


Joined: 18 Jan 2015

PostPosted: Sun Jan 18, 2015 7:16 pm    Post subject:  SUN.EXE Source code Reply with quote  Mark this post and the followings unread

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



Tiberian Sun.rar
 Description:

Download
 Filename:  Tiberian Sun.rar
 Filesize:  63.2 KB
 Downloaded:  65 Time(s)


Back to top
View user's profile Send private message
ApolloTD
Commander


Joined: 19 Nov 2003

PostPosted: Sun Jan 18, 2015 9:54 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.

Back to top
View user's profile Send private message
Neijwiert
Civilian


Joined: 18 Jan 2015

PostPosted: Sun Jan 18, 2015 9:57 pm    Post subject: Reply with quote  Mark this post and the followings unread

ApolloTD wrote:
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.

Back to top
View user's profile Send private message
Banshee
Supreme Banshee


Also Known As: banshee_revora (Steam)
Joined: 15 Aug 2002
Location: Brazil

PostPosted: Sun Jan 18, 2015 11:05 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.

Back to top
View user's profile Send private message Visit poster's website Skype Account
Neijwiert
Civilian


Joined: 18 Jan 2015

PostPosted: Sun Jan 18, 2015 11:11 pm    Post subject: Reply with quote  Mark this post and the followings unread

Banshee wrote:
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.

Back to top
View user's profile Send private message
Blade
Cyborg Commando


Joined: 23 Dec 2003

PostPosted: Mon Jan 19, 2015 9:36 am    Post subject: Reply with quote  Mark this post and the followings unread

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.

Back to top
View user's profile Send private message
Neijwiert
Civilian


Joined: 18 Jan 2015

PostPosted: Mon Jan 19, 2015 6:30 pm    Post subject: Reply with quote  Mark this post and the followings unread

Blade wrote:
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)

Back to top
View user's profile Send private message
RP
Commander


Joined: 12 Jul 2012
Location: Mapping God Heaven

PostPosted: Mon Jan 19, 2015 7:31 pm    Post subject: Reply with quote  Mark this post and the followings unread

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 #Tongue

_________________


Mental Omega 3.0 Mission creator - Creator of FinalOmega: APYR 3.0 Map Editor

/ppm/'s stupidity

Back to top
View user's profile Send private message
FunkyFr3sh
Cyborg Soldier


Joined: 23 Sep 2014

PostPosted: Mon Jan 19, 2015 9:17 pm    Post subject: Reply with quote  Mark this post and the followings unread


Back to top
View user's profile Send private message
Parasite03
Cyborg Artillery


Also Known As: ZivDero
Joined: 23 Jul 2013
Location: Russia

PostPosted: Mon Jan 19, 2015 9:18 pm    Post subject: Reply with quote  Mark this post and the followings unread

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 Very Happy

_________________

Back to top
View user's profile Send private message
^Rampastein
Rampastring


Joined: 11 Oct 2008
Location: Gensokyo

PostPosted: Mon Jan 19, 2015 11:41 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.

_________________
CnCNet Client | CnCNet TS patches | More Quality-of-Life Improvements for RA Remastered


Back to top
View user's profile Send private message ModDB Profile ID Facebook Profile URL
Graion Dilach
Defense Minister


Joined: 22 Nov 2010
Location: Iszkaszentgyorgy, Hungary

PostPosted: Mon Jan 19, 2015 11:49 pm    Post subject: Reply with quote  Mark this post and the followings unread

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...

Back to top
View user's profile Send private message Visit poster's website ModDB Profile ID
Neijwiert
Civilian


Joined: 18 Jan 2015

PostPosted: Tue Jan 20, 2015 11:20 am    Post subject: Reply with quote  Mark this post and the followings unread

RP wrote:
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 #Tongue


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

https://kiwiirc.com/client/irc.freenode.net/cncnet/?nick=Guest|?

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.

LINK:
https://drive.google.com/folderview?id=0B7qBNqPzsL5PWGlSS0hWdm8zbTg&usp=sharing

Back to top
View user's profile Send private message
Blade
Cyborg Commando


Joined: 23 Dec 2003

PostPosted: Tue Jan 20, 2015 1:34 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.

Back to top
View user's profile Send private message
Parasite03
Cyborg Artillery


Also Known As: ZivDero
Joined: 23 Jul 2013
Location: Russia

PostPosted: Wed Jan 21, 2015 2:02 pm    Post subject: Reply with quote  Mark this post and the followings unread

^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 Very Happy

_________________

Back to top
View user's profile Send private message
Orac
President


Joined: 11 Jul 2008
Location: New Zealand

PostPosted: Wed Jan 21, 2015 10:35 pm    Post subject: Reply with quote  Mark this post and the followings unread

This is very cool, Neijwiert.

It's wonderful to see skilled people taking an interest in these elderly games.

Back to top
View user's profile Send private message
Neijwiert
Civilian


Joined: 18 Jan 2015

PostPosted: Thu Jan 22, 2015 5:36 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.

Back to top
View user's profile Send private message
CCHyper
Defense Minister


Joined: 07 Apr 2005

PostPosted: Thu Jan 22, 2015 6:08 pm    Post subject: Reply with quote  Mark this post and the followings unread

Neijwiert wrote:
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!

Back to top
View user's profile Send private message
Neijwiert
Civilian


Joined: 18 Jan 2015

PostPosted: Thu Jan 22, 2015 7:37 pm    Post subject: Reply with quote  Mark this post and the followings unread

I'm sorry master CCHyper, I will go back to my 16 hour work shift right now.

Back to top
View user's profile Send private message
Banshee
Supreme Banshee


Also Known As: banshee_revora (Steam)
Joined: 15 Aug 2002
Location: Brazil

PostPosted: Fri Jan 23, 2015 1:55 am    Post subject: Reply with quote  Mark this post and the followings unread

No, Neijwiert, he is not that kind. It's actually a 20 hours work shift, seven days a week. #Tongue

Back to top
View user's profile Send private message Visit poster's website Skype Account
Lin Kuei Ominae
Seth


Joined: 16 Aug 2006
Location: Germany

PostPosted: Fri Jan 23, 2015 8:19 am    Post subject: Reply with quote  Mark this post and the followings unread

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

Public SHPs
X-Mech Calendar (28 Mechs for GDI and Nod)
5 GDI, 5 Nod, 1 Mutant, 1 Scrin unit, 1 GDI building

Tools
Image Shaper______TMP Shop______C&C Executable Modifier

Back to top
View user's profile Send private message
Iran
Pyro Sniper


Joined: 23 Mar 2011

PostPosted: Fri Jan 23, 2015 6:56 pm    Post subject: Reply with quote  Mark this post and the followings unread

He's not hex editing/modding, he's reverse engineering the game.

Back to top
View user's profile Send private message
Lin Kuei Ominae
Seth


Joined: 16 Aug 2006
Location: Germany

PostPosted: Fri Jan 23, 2015 8:53 pm    Post subject: Reply with quote  Mark this post and the followings unread

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

Public SHPs
X-Mech Calendar (28 Mechs for GDI and Nod)
5 GDI, 5 Nod, 1 Mutant, 1 Scrin unit, 1 GDI building

Tools
Image Shaper______TMP Shop______C&C Executable Modifier

Back to top
View user's profile Send private message
OmegaBolt
President


Joined: 21 Mar 2005
Location: York, England

PostPosted: Fri Jan 23, 2015 9:16 pm    Post subject: Reply with quote  Mark this post and the followings unread

Why would that not be made open source? Seems really dumb tbh.

Back to top
View user's profile Send private message Send e-mail
^Rampastein
Rampastring


Joined: 11 Oct 2008
Location: Gensokyo

PostPosted: Fri Jan 23, 2015 9:26 pm    Post subject: Reply with quote  Mark this post and the followings unread

OmegaBolt wrote:
Why would that not be made open source? Seems really dumb tbh.

I think the same. Who really benefits from it being closed source?

_________________
CnCNet Client | CnCNet TS patches | More Quality-of-Life Improvements for RA Remastered


Back to top
View user's profile Send private message ModDB Profile ID Facebook Profile URL
Iran
Pyro Sniper


Joined: 23 Mar 2011

PostPosted: Fri Jan 23, 2015 11:57 pm    Post subject: Reply with quote  Mark this post and the followings unread

It really isn't hex editing at all.

Back to top
View user's profile Send private message
Blade
Cyborg Commando


Joined: 23 Dec 2003

PostPosted: Sat Jan 24, 2015 12:57 am    Post subject: Reply with quote  Mark this post and the followings unread

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.

Back to top
View user's profile Send private message
FunkyFr3sh
Cyborg Soldier


Joined: 23 Sep 2014

PostPosted: Sat Jan 24, 2015 11:59 am    Post subject: Reply with quote  Mark this post and the followings unread

Blade wrote:
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) Very Happy

Back to top
View user's profile Send private message
Bittah Commander
Defense Minister


Joined: 21 May 2003
Location: The Netherlands

PostPosted: Sat Jan 24, 2015 5:06 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.

_________________

Back to top
View user's profile Send private message ModDB Profile ID YouTube User URL Facebook Profile URL
CCHyper
Defense Minister


Joined: 07 Apr 2005

PostPosted: Sun Jan 25, 2015 12:37 pm    Post subject: Reply with quote  Mark this post and the followings unread

Bittah Commander wrote:
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.

Back to top
View user's profile Send private message
Iran
Pyro Sniper


Joined: 23 Mar 2011

PostPosted: Sun Jan 25, 2015 1:00 pm    Post subject: Reply with quote  Mark this post and the followings unread

Plus you can embed C code and link it with ASM code (not inlined but assembled with NASM)

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [31 Posts] Mark the topic unread ::  View previous topic :: View next topic
 
Share on TwitterShare on FacebookShare on Google+Share on DiggShare on RedditShare on PInterestShare on Del.icio.usShare on Stumble Upon
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


Powered by phpBB © phpBB Group

[ Time: 0.2603s ][ Queries: 13 (0.0121s) ][ Debug on ]