Alpha Centauri 2

Sid Meier's Alpha Centauri & Alien Crossfire => Modding => Bug/Patch Discussion => Topic started by: ete on December 07, 2014, 07:58:05 PM

Title: Decompilation coordination thread
Post by: ete on December 07, 2014, 07:58:05 PM
As i said in the other thread:
I would *really* like to get the active decompilers sharing data with each other, since otherwise there's just massive duplication of effort which could instead be directed towards more improvements to AC. The initial work of merging discovered functions would be significant, but I suspect would be quickly payed back by having three times as many people working on the project.

I want to see this happen because I like it when things get fixed and improved and think this would be a major step forward. I don't know exactly what I can do to help as a non-programmer, but if there's anything I can do to make it more likely I'm in (e.g. teaching people github, talking to people, organizing things).


PlotinuxRedux and Dio have both offered to share their research with the community, scient definitely interested in sharing with at least the other disassemblers, and kyrub has previously given indication (http://alphacentauri2.info/index.php?topic=2892.msg18326#msg18326) he would share his SMAC AI disassembly at some point after he finished work (I'll contact him when the rest of this is set up). Yitzi, I have a half memory of talking to you about this sometime long ago, but am not certain what you said. Would you like to participate?

If everyone with information they're happy sharing with the community could post it in this thread that would be awesome. I also expect you guys will have things to talk about related to the specifics of your work, seeing what's been duplicated, figuring out how to merge, and deciding on a versioning system for easy syncing. I'll be hanging around trying to be useful, would be happy to set up a github organization or something like that if you guys want it.

Several of you have independently come to the conclusion that decompiling large chunks of the game is the only way to make the improvements you want to see in the game. If we can link those chunks up we'll have an opensource clone on our hands, and the possibilities from there are endless.
Title: Re: Decompilation coordination thread
Post by: Yitzi on December 07, 2014, 11:51:13 PM
I don't have decompilation in the normal sense; what I do have is notes on what various functions and variables do, and a step-by-step walkthrough of some functions.

However, I'm pretty sure that source code coming from decompiling the actual program would not be open source in the usual sense, but would be subject to all the copyright rules of the .exe.  So we could mod it more easily, but that's about it.
Title: Re: Decompilation coordination thread
Post by: ete on December 08, 2014, 12:41:52 AM
I don't have decompilation in the normal sense; what I do have is notes on what various functions and variables do, and a step-by-step walkthrough of some functions.

Okay, I'm sure that would be of interest to the others. Would you be willing to share?

However, I'm pretty sure that source code coming from decompiling the actual program would not be open source in the usual sense, but would be subject to all the copyright rules of the .exe.  So we could mod it more easily, but that's about it.

It would not be free software (http://en.wikipedia.org/wiki/Free_software), but it would in a literal sense be open source, and increasing ease of modifications is a very major benefit.
Title: Re: Decompilation coordination thread
Post by: Yitzi on December 08, 2014, 12:52:56 AM
I don't have decompilation in the normal sense; what I do have is notes on what various functions and variables do, and a step-by-step walkthrough of some functions.
Okay, I'm sure that would be of interest to the others. Would you be willing to share?

Sure.  I'm attaching the most important stuff to this post.
Title: Re: Decompilation coordination thread
Post by: scient on December 08, 2014, 01:01:41 AM
Thank you for sharing Yitzi, that has some very useful information I don't have documented.

I could easily integrate this information into my IDA database with additional enums and structures. I have started to do a similar thing as I've gone along. It really enhances the readability of the asm.

Example:
(https://i.imgur.com/fWpWBAF.png)
Title: Re: Decompilation coordination thread
Post by: Yitzi on December 08, 2014, 01:04:36 AM
If you could send me whatever information of that sort you've got (especially anything on AI), that would also be great.
Title: Re: Decompilation coordination thread
Post by: scient on December 08, 2014, 01:12:19 AM
I don't have anything on AI specifically however there are some flags I've found that identify AI vs human units and then toggle AI specific code accordingly.

For example, here:
(https://i.imgur.com/7T9QeRq.png)

Everything I've done is bundled in my IDA database. I will see about cleaning it up and making it available to you and whoever else who would like it in a couple weeks. I have spent a lot of time into making this database very comprehensive.
Title: Re: Decompilation coordination thread
Post by: Buster's Uncle on December 08, 2014, 01:43:20 AM
I wouldn't be surprised if Impaler and Mart, old-timers who have made much study of AI and manipulating it from the .txt end, couldn't be of use, here.
Title: Re: Decompilation coordination thread
Post by: Dio on December 08, 2014, 01:45:27 AM
I posted my labels file in the wrong topic ;goofy;...

Here is my for the most part complete list of all the labels present in the assembly code and their addresses. I could also create a list that shows where individual facilities and their associated effects are located.

Plus a list of bugs that I know exist:

1. This bug occurs when you put SOCIAL, TALENT as a Social Model Effect and look in the datalinks under Society Model Effects. The TALENT bonus or penalty will appear linked to the Society Effects section of the datalinks. If you click on the link, then you can only navigate by pressing “Back.” You can locate the sections in the code for this bug by clicking search for all referenced text strings and then “HELPSOC” and “HELPEFFECT”.
2. This bug occurs after you select a faction with Shift + F9 option in the scenario editor. Once you do that, the diplomacy windows shrink until the text and Faction leader potrait run over the sides. The potential starting points to look for the bug in the code are 004DB9AE, 004DBB12, and 004DB080.
3. This bug is in the world mini map right click menu. The menu has an option called “Recenter this window here” that does not function properly or function at all. The code controlling this label is located at address 004C3C66.
4. This bug occurs when you try to give two or more free starting technologies to a faction. One of the faction’s technologies must grant a free upgrade of the faction’s initial scout unit (i.e. Doctrine: Mobility) and the other technology a free prototyping of a unit design (i.e. Applied Physics). This bug will cause the faction to not get the free scout unit upgrade and only occurs if the technology granting the free prototype is above the technology in the alpha(x) file tech list that gives the free scout unit upgrade. An applicable example of this is giving a faction Doctrine: Mobility and Applied Physics as free starting techs.
Title: Re: Decompilation coordination thread
Post by: Buster's Uncle on December 08, 2014, 01:48:20 AM
No harm - go ahead and repost here.
Title: Re: Decompilation coordination thread
Post by: scient on December 08, 2014, 01:54:47 AM
For labels, I have the logic down pretty nicely. Although, I haven't gone through my IDA db and made a comment which offset is which. However, based on structure it is easy to identify what goes where like so.

(http://i.imgur.com/QpwiRl4.png)

Then if we go to a random offset like so:

(http://i.imgur.com/v5C9Vql.png)

And follow the guidelines, you get with line 420 which is "then". This matches up with your list.

004B48A8   mov eax, dword ptr ds:[edx+664]           then (0x664 == 1636)

It would be helpful to integrate all of them into the the database however to save having to look them up. I have been doing this on my own as I go, so a full list is useful. As for facilities, I have created an enum for them and identified instances like so.

(https://i.imgur.com/ZV3RZ86.png)
Title: Re: Decompilation coordination thread
Post by: Dio on December 08, 2014, 01:58:33 AM
In addition, if it might help, I can make a list of the procedures and memory addresses for the .cvr files in the code that control the display and assembly of chassises, weapons, armor, and special abilities.
Title: Re: Decompilation coordination thread
Post by: scient on December 08, 2014, 02:07:56 AM
I can sync any specific info about caviar data into what I have already. While I have identified most of the functions with my analysis, I haven't gone any further.

For example, I have functions but I don't have any of global data as to what is being added.

(http://i.imgur.com/DXGzfjP.png)

(http://i.imgur.com/R16NyR8.png)

(http://i.imgur.com/ACPLUcI.png)
Title: Re: Decompilation coordination thread
Post by: Yitzi on December 08, 2014, 02:22:14 AM
Everything I've done is bundled in my IDA database. I will see about cleaning it up and making it available to you and whoever else who would like it in a couple weeks. I have spent a lot of time into making this database very comprehensive.

That would be great, thanks.
Title: Re: Decompilation coordination thread
Post by: PlotinusRedux on December 08, 2014, 03:09:30 AM
Scient,

I understand you wanting to clean up your IDA DB before making it available--I'm the same way, generally--but would it be possible to get a .map in the meantime?  That will just list the function names and addresses--I didn't know about the MAC executable having the function names, and just that would be a huge help to me.

You can export a .map file from IDA (File\Produce File\Map File)--either post it here or email it.

I'll be glad to share anything anyone is interested in, but everything I have so far is SMAC, I'm just starting on SMAX tonight.  I have IDA, which can spit out .map and similar files for those that don't have (actually it can even split out the entire disassembly with the comments and all to an html file), and the structures from that in a C header file along with the changes I've made in cpp files.

I've mostly been working on the GUI classes--I've got the base image and surface classes, window/control base class, menu class, and a few other things mapped out with enough data known to use them.
Title: Re: Decompilation coordination thread
Post by: ete on December 08, 2014, 06:22:23 PM
The OpenSMACX repository (https://github.com/OpenSMACX/OpenSMACX) is ready for use! I'm still fiddling with the bug tracker and a few other things, but if everyone interested could register on github (https://github.com/) and set up github for windows (https://windows.github.com/) (or other OS equivalent) that would be great. Post here with your username and I'll add you as a contributor to the repository.

I'm guessing we're probably better off with the shared repository model (https://help.github.com/articles/using-pull-requests/) rather than fork and pull, but am open to switching.

Also I'll be hanging out on #smac (http://alphacentauri2.info/index.php?spage=Chat) a lot over the next few days if anyone feels like chatting about plans or wants some help getting used to github. Just say my name in the channel and my client will alert me, otherwise I may not see you've arrived for an hour or two.
Title: Re: Decompilation coordination thread
Post by: ete on December 08, 2014, 10:04:04 PM
The bug tracker now has a bunch of bugs in: https://github.com/OpenSMACX/OpenSMACX/issues

Ones labeled possible-bug need some discussion.
Title: Re: Decompilation coordination thread
Post by: scient on December 08, 2014, 10:15:17 PM
I think shared model is good for now. Once we reach alpha or beta stage, maybe switching it over. But that won't be for some time.

I just set up github id:  b-casey

Also, I wonder if I should keep a document of any bugs that I've already fixed in my source. There are about 3-4 that come to mind as part of engine code.
Title: Re: Decompilation coordination thread
Post by: ete on December 08, 2014, 10:25:36 PM
Okay, invited you to the organization.

That's probably a good idea. Maybe best to collect up everyone's individual changelogs in a text file in the repository, so we've got one unified changelist?
Title: Re: Decompilation coordination thread
Post by: scient on December 08, 2014, 10:53:42 PM
Well, I don't really have a change log myself. I have made some comments at the top of my header files where I've been keeping comments.

One thing we'll need to worry about at some point is having a unified code format.

For example:

Quote
/*
 * heap.h
 * SMAC/X Project
 * Brendan Casey
 *
 *  v1.0 (6/30/14)
 *
 * Class to handle the low level heap operations to manage or allocate memory
 * Removed an unused error flag (+0) and an unused parameter from squeeze()
 */
Title: Re: Decompilation coordination thread
Post by: ete on December 08, 2014, 11:01:53 PM
Well, I don't really have a change log myself. I have made some comments at the top of my header files where I've been keeping comments.

One thing we'll need to worry about at some point is having a unified code format.

For example:

Quote
/*
 * heap.h
 * SMAC/X Project
 * Brendan Casey
 *
 *  v1.0 (6/30/14)
 *
 * Class to handle the low level heap operations to manage or allocate memory
 * Removed an unused error flag (+0) and an unused parameter from squeeze()
 */
Right, hm. It probably would be worth collecting information on that kind of change up somewhere.

And what do you mean exactly by unified code format? If everyone's stable changes get merged into the shared repository, does that achieve that?
Title: Re: Decompilation coordination thread
Post by: scient on December 08, 2014, 11:06:32 PM
I mean, for the final product I think all the source files should follow certain guidelines of how the code looks. For example, I've been storing all the function comments in header file except for a few runtime bits in the cpp file. Having some unified header format and such. For now, I think just getting it all up onto github is first priority and then sorting it out as we go along.

Example of my heap class decompiled from game.

Quote
/*
 * heap.h
 * SMAC/X Project
 * Brendan Casey
 *
 *  v1.0 (6/30/14)
 *
 * Class to handle the low level heap operations to manage or allocate memory
 * Removed an unused error flag (+0) and an unused parameter from squeeze()
 */

#pragma once
#include "stdafx.h"
#include "general.h" // mem_get()

class Heap
{
   private:
      LPVOID basePtr;    // (+4) -> pointer to base memory address
      LPVOID currentPtr; // (+8) -> current memory address position
      size_t baseSize;   // (+12) -> size of total memory
      size_t freeSize;   // (+16) -> size of free available memory

   public:
      // Constructor and Destructor
      Heap(): basePtr(0), currentPtr(0), baseSize(0), freeSize(0) { }
      ~Heap() { shutdown(); }

      // Get base total memory size
      size_t getBaseSize() { return baseSize; }
      // Get base memory address pointer
      LPVOID getBasePtr() { return basePtr; }

      // Destroy current heap and zero out all class variables
      // LOCATION: 005D4580
      void shutdown();

      // Deflate heap of any free memory
      // LOCATION: 005D45E0
      void squeeze();

      // Allocate memory based on requested size from parameter
      // Return TRUE if memory allocation failed, otherwise FALSE
      // LOCATION: 005D4620
      BOOL init(size_t reqSize);

      // Check if there is currently enough free memory for requested size from parameter
      // If not, allocate more memory to heap in blocks of 1024 bytes until there is enough
      // Return a memory pointer with address to requested size free
      // LOCATION: 005D4680
      LPVOID get(size_t reqSize);
};

Quote
/*
 * heap.cpp
 * SMAC/X Project
 * Brendan Casey
 *
 *  v1.0 (6/30/14)
 *
 * Class to handle the low level heap operations to manage or allocate memory
 */

#include "heap.h"

void Heap::shutdown()
{
   if(basePtr){
      free(basePtr);
   }
   basePtr = currentPtr = 0;
   baseSize = freeSize = 0;
}

void Heap::squeeze()
{
   size_t usedSize = baseSize - freeSize;
   LPVOID newAddr = realloc(basePtr, usedSize);
   if(newAddr){
      basePtr = newAddr;
      baseSize = usedSize;
      freeSize = 0;
   }
}

BOOL Heap::init(size_t reqSize)
{
   if(basePtr){
      shutdown();
   }
   basePtr = mem_get(reqSize);
   if(basePtr){
      currentPtr = basePtr;
      baseSize = freeSize = reqSize;
      return FALSE;
   }
   return TRUE; // failed to allocate memory
}

LPVOID Heap::get(size_t reqSize)
{
   while(freeSize < reqSize){
      LPVOID newAddr = realloc(basePtr, baseSize + 1024);
      if(!newAddr){
         CHAR szError[150]; // max size of string + three int(s) + extra
         wsprintf(szError, "Aborting due to a heap shortage!\nBase size: %d\nFree size: %d\nRequested size: %d",
            baseSize, freeSize, reqSize);
         MessageBox(NULL, szError, "Heap Notice!!", MB_OK);
         exit(3);
      }
      basePtr = newAddr;
      currentPtr = LPVOID(size_t(basePtr) + baseSize - freeSize); // fix in case realloc shifts memory
      baseSize += 1024;
      freeSize += 1024;
   }
   LPVOID freeMemAddr = currentPtr;
   freeSize -= reqSize;
   currentPtr = LPVOID(size_t(currentPtr) + reqSize);
   return freeMemAddr;
}
Title: Re: Decompilation coordination thread
Post by: ete on December 08, 2014, 11:18:19 PM
Right, coding conventions? And yes, I agree that getting your (and Plotinus's) current work up and shared is the next step, can decide on exactly how to organize things and which conventions to follow after. When everyone's work is public I'll contact kyrub.

Edit: Contacted Guv'ner.
Title: Re: Decompilation coordination thread
Post by: Yitzi on December 09, 2014, 12:44:43 AM
By the way, because of how I did my major changes they may not be so easy to decompile normally; in such case, feel free to decompile Kyrub's version or earlier and then ask me to edit the result to fit my changes.
Title: Re: Decompilation coordination thread
Post by: scient on December 09, 2014, 01:13:51 AM
I think the easiest thing is to decompile the original code and then apply any updates or changes from there. If it's minor bug fix, then it would be simple to apply it as you go along. For more intensive patches, it would probably be best to apply after. Smaller room for error. Granted, I've mainly been focusing on engine code and little on game logic where most of my own patches reside.
Title: Re: Decompilation coordination thread
Post by: scient on December 09, 2014, 04:22:08 AM
@Yitiz:
Taking a break from work, I started to look over your notes to see if there is any info to add into my IDA database. So far, there has been a few things. Although, I noticed a mistake and wanted to let you know.

Inside base structure:
"Turns left to revolt: +7"

This is actually the number of turns left until assimilation of the base is complete. Once it goes down to zero, the former faction is set to current faction and the base no longer looks like the previous owners bases.

The info about base flags is useful, I only had rioting and golden age. :)
Title: Re: Decompilation coordination thread
Post by: Yitzi on December 09, 2014, 12:42:46 PM
Inside base structure:
"Turns left to revolt: +7"

This is actually the number of turns left until assimilation of the base is complete. Once it goes down to zero, the former faction is set to current faction and the base no longer looks like the previous owners bases.

The info about base flags is useful, I only had rioting and golden age. :)

Yeah, I just mis-typed what I meant.
Title: Re: Decompilation coordination thread
Post by: ete on December 11, 2014, 01:07:20 AM
There are now 29 issues in the tracker (https://github.com/OpenSMACX/OpenSMACX/issues). I'd like some feedback on tagging from anyone who's interested at some point. There are also a bunch of possible bugs (https://github.com/OpenSMACX/OpenSMACX/labels/possible-bug) that need discussion.

Yitzi, would you be okay with me tracking feature requests from your thread on this?

Also, progress update on text files. Mostly done, but conceptsx has massively changed and specifically reordered which makes comparing diffs much slower. There's a whole lot of good changes, but there's also a few formatting errors and other things to fix so I need to check over it properly.
Title: Re: Decompilation coordination thread
Post by: Yitzi on December 11, 2014, 01:18:14 AM
There are now 29 issues in the tracker (https://github.com/OpenSMACX/OpenSMACX/issues). I'd like some feedback on tagging from anyone who's interested at some point. There are also a bunch of possible bugs (https://github.com/OpenSMACX/OpenSMACX/labels/possible-bug) that need discussion.

Yitzi, would you be okay with me tracking feature requests from your thread on this?

Go ahead.
Title: Re: Decompilation coordination thread
Post by: scient on December 11, 2014, 10:14:16 PM
Yitzi, could you clarify these from variables.txt?

Quote
Factions: Size 20CC.  Faction 0 would have:
  Nessus at 96D1EC
  AI value for SUPPORT x at 96D080+4*x.


virtual mineral count: 946138+4Xfac#

Otherwise, I merged in any missing details from all your text files into my IDA database. Most of it I already had, but every bit helps! At the moment, I have most of all the internal structures from text files mapped out. Also, unit and base are almost entirely complete except for a few members.  These make a big difference in poking around functions. I have portions of the large faction struct (includes diplomacy related info) but that will take some time. The same goes for world map. Granted, having all the game logic functions identified with original names will make this analysis go a lot faster.

By the end of the year, I should have my database all nice and tidy to share. Of course going through each function and marking it up with the enums and structures will be required as well as local variables. The same goes for analysis on the remaining structures. However, the more complete the database is the easier it is start decompilation of game logic code. :)
Title: Re: Decompilation coordination thread
Post by: Yitzi on December 12, 2014, 01:48:31 AM
By the way, note that the alphax variables are their values in my patch, which differ from those in the original, so you'd have to use the right choice for whichever .exe you're analyzing.
Title: Re: Decompilation coordination thread
Post by: scient on December 12, 2014, 02:02:29 AM
Ahhhh, ok that makes sense why some things differed. I already have all alphax variables labeled in my database.

I was curious what you meant by Nessus inside faction struct and instead I found an array with pointers to addresses inside the string table. It doesn't really look like these are used and redundant since most everywhere else just references labels.txt offset.

I was confused by you listing them in faction struct.

I also figured out what you mean by SUPPORT and marked that up.

I'm still not sure what virtual mineral count is tho.
Title: Re: Decompilation coordination thread
Post by: Yitzi on December 12, 2014, 02:36:50 PM
Ahhhh, ok that makes sense why some things differed. I already have all alphax variables labeled in my database.

I was curious what you meant by Nessus inside faction struct and instead I found an array with pointers to addresses inside the string table.

Not sure why; that value should be where the number of Nessus mining stations for that faction are located.  (Unless I mistyped the address; I found it from its reference in the minerals ecodamage formula, so you can always look up there.)  The other satellites are nearby as well IIRC.

Actually, there seem to be a few faction structures, which is part of why enabling more than 7 factions would be such a huge job, though decompilation would make it feasible.

Quote
I'm still not sure what virtual mineral count is tho.

Originally, that location recorded the number of times the faction had used tectonic missiles (which count like PBs for ecodamage purposes, but not faction reputation/sanctions.)  When I redid ecodamage, I used it for the bonus minerals' worth of ecodamage from all history-based sources: Tectonic missiles, PBs (depending on setting; the default counts nerve staples after IIRC the 15th because they're major atrocities, but not PBs used with no UN charter, I provided the option to change that, and PBs only count toward this value if it's set to work by PBs instead of major atrociites), and pops.  (In version 1.x it included ecological facilities built, but now it's based on ecological facilities owned instead.)
Title: Re: Decompilation coordination thread
Post by: PlotinusRedux on December 13, 2014, 04:44:56 PM
Scient:

Do your decompiled classes follow the same prototypes as the original classes?

I'm thinking--once you get your IDA db ready to share, I can pull in the function prototypes from the Mac/Carbon version (I've been playing around with the Python scripting in IDA enough to do that), and do a dump to a .asm file.  Then, running parsers on the .asm file, I can convert it to a compile-able C++ application initially with all the functions naked inline assembly.

In theory, that gives us C source code that can be compiled into a new .exe, which would already make things like assembly level patching by Yitzi easier--he could add as much code as he wanted anywhere he wanted to with all the pointers automatically fixed up, since they will be symbolic names ("loc_XXXXXXXX", "sub_XXXXXXXX", etc.) rather than absolute addresses and offsets.

Then, if your new classes followed the prototypes of the existing classes, we could literally just plug them in in place of the existing assembly versions and recompile.
Title: Re: Decompilation coordination thread
Post by: scient on December 13, 2014, 05:42:31 PM
Yes and no. In some places I have, others not.  I was planning on going through and fixing them up after my initial pass through. I haven't created structure placeholders for some of classes that are used as parameters.

That sounds good. It is at least worth a shot to see if it works. The method you are currently using with DLL injecting is another possibility to start replacing existing game logic functions to fix bugs.
Title: Re: Decompilation coordination thread
Post by: PlotinusRedux on December 14, 2014, 04:32:11 AM
I'd like to try to pull all the assembly into compile-able C source, with my DLL injection as a backup.  The advantage over my DLL injection is the latter requires defines for the address of every function overridden, and if you want to override an existing function and still call the existing function from within the override, you need defines for every place that calls the function so you can change the address they call--putting a jmp instruction at the top of the existing function destroys it.

Currently the dump to .asm is spitting out over 4 million lines, so manually massaging them is out of the question, but I think I can write automated routines to turn that into compile-able C.

Are you using MSVC or GNU, or something else?  I'm using VS 2013 Express, which unfortunately doesn't allow naked functions as class members (not even static ones), so I'd need to define all the functions as straight C __thiscall functions, and have the class members just be stubs that called them.  I haven't looked to see if GNU has that limitation--if it doesn't, that would almost be reason enough for me to switch to GNU.  If you're using MSVC, though, I'll keep it all MSVC compatible.
Title: Re: Decompilation coordination thread
Post by: scient on December 14, 2014, 10:06:06 AM
Ahhh ok I see. That does make sense.

I was originally using MSVC 2012 and just recently updated to MSVC 2015.

Title: Re: Decompilation coordination thread
Post by: DrazharLn on December 14, 2014, 02:13:59 PM
Plotinux, are none of the available asm -> C converters suitable for your purposes?

Here are a couple:
http://decompiler.fit.vutbr.cz/decompilation/ (http://decompiler.fit.vutbr.cz/decompilation/)
http://www2.onlinedisassembler.com/odaweb/ (http://www2.onlinedisassembler.com/odaweb/)

There's also Hex-Rays and Hopper, but they cost money.
Title: Re: Decompilation coordination thread
Post by: scient on December 14, 2014, 03:14:27 PM
Hex-Ray's is by far the best out there, however for more complex software this is not feasible. There will be too many errors and it would be time consuming to go through and fix them up. It is better to decompile each function and go from there. While this is also time consuming, you end up with a better product than a mangle of code. The decompilation routine is useful as a first pass in some cases to then go through and rework the function manually.

I have used Hopper as well, but consider it more of an "IDA" light than a real competitor. In some cases it is useful to have, however it is no where near as polished and robust as IDA.
Title: Re: Decompilation coordination thread
Post by: PlotinusRedux on December 16, 2014, 08:00:20 AM
As Scient says.  Hex-rays is particularly bad with BP-based frames combined with __thiscall functions, from what I've seen.

If we can get a working build in C with C prototypes around naked assembly to start with, that will be no small feat.
Title: Re: Decompilation coordination thread
Post by: PlotinusRedux on December 16, 2014, 08:02:12 AM
On a different note, Scient and/or Yitzi--have either of you found a simple method of determining the topmost window in the game?  The method I'm using in my patch is only working some of the time.

What I'm using now to decide if the map is topmost (i.e., mouse should scroll the map, etc.) is what I took from the scroll check timer:

bool IsCityShowing(void)
{
   bool fRet =
      m_fGlobalTimersEnabled &&
      !*m_pAC->pfGameNotStarted &&
      m_pAC->pfncWinIsVisible(m_pAC->pCityWindow);

   return fRet;
}


bool IsMapShowing(void)
{
   bool fRet =
      m_fGlobalTimersEnabled &&
      !*m_pAC->pfGameNotStarted &&
      !IsCityShowing() &&
      !m_pAC->pfncWinIsVisible(m_pAC->pAnotherWindow) &&
      !m_pAC->pfncWinIsVisible(m_pAC->pAnotherWindow2);

   return fRet;
}

Where pAnotherWindow & pAnotherWindow2 where globals the timer was checking before scrolling.
Title: Re: Decompilation coordination thread
Post by: scient on December 16, 2014, 08:46:18 AM
I will have to look tomorrow, but there is a main "Win" class that handles all the window functionality of other classes. There is one function about whether something is visible but I'm not sure about top most.
Title: Re: Decompilation coordination thread
Post by: PlotinusRedux on December 16, 2014, 10:07:57 AM
Yeah, the base Win class all the others inherit from has an IsVisible member, but I haven't identified all the global instances of Win classes to call IsVisible for all of them.  I did notice 4 globals for unparented windows, but saw at least one case where the map was the topmost window and more than one of those globals was != NULL.  I would have thought the code in the scroll timer call back should be pretty foolproof--I'll look at it again to see if I missed something in translating its checks.

Back to the original topic--once we get the whole thing compile-able, I've got a DX9 control library I wrote for a game I never finished I could adapt to replace the rendering parts of all the UI windows.  The terrain itself screams for DX/OpenGL rendering.  From there, converting the Cavier files to a standard mesh format is all that would stand in the way of a full DX/OpenGL conversion.
Title: Re: Decompilation coordination thread
Post by: PlotinusRedux on December 19, 2014, 02:17:32 AM
Scient, have you done anything with the vtables?  From the .map file, it looks like most of what you have defined is missing the virtual functions.  I was working on a vtable struct for all the Win descendents, but have been holding off until I see what your final IDB has.  If it's missing them too, I should be able to add a lot of function defs in pretty short order.
Title: Re: Decompilation coordination thread
Post by: scient on December 19, 2014, 02:14:17 PM
The one I sent you hasn't had a lot of work on Win class. I have since worked on it a lot more going through and defining virtual functions for each set of classes.

This next week I will have a lot more free time to try and finish it all up. If you want to wait until then, you can see what I've done.
Title: Re: Decompilation coordination thread
Post by: scient on December 19, 2014, 03:17:33 PM
I just thought, I could send you a new map file if that would be helpful. I have the Win class mapped out best I can.
Title: Re: Decompilation coordination thread
Post by: ete on December 19, 2014, 03:47:56 PM
Would it be practical to include your working map file in the repository? You could use .gitignore to keep the things you'd like to clean up first out until you're ready, and that way Plotinus would know exactly what's been done/what he can work on without duplicating effort at all times (so long as you push regularly).
Title: Re: Decompilation coordination thread
Post by: scient on December 19, 2014, 04:25:05 PM
Well, I should be done with mapping out pretty much the rest of main classes by end of next week. I was going to share my IDA database with whoever wants it.

However, putting up a map file on github is a good idea for future. One thing that needs to be done is fixing up all the prototype information regarding variables and data types. So far, I have only done that for functions I've worked on. The pretty much complete analysis of all the functions will greatly aid in any future work on SMAC/X.
Title: Re: Decompilation coordination thread
Post by: ete on December 19, 2014, 04:52:35 PM
Okay, sounds good. I'd also like to see the IDA db on github when you're ready to release, opens up much more streamlined collaboration.
Title: Re: Decompilation coordination thread
Post by: Dio on December 21, 2014, 06:51:15 PM
I am currently working on identifying the various constants and memory addresses that control AI behavior. So far I have identified the memory addresses that control an AI faction's interest in Explore, Discover, Build, Conquer, and Fight (Willingness to use Force). I have also identified at least three different memory addresses that control various aspects of AI behavior and diplomacy. These memory addresses are then compared to various constants and constant combinations to generally determine AI behavior. Finally, I am making a text file with all of my findings as I go along.
Title: Re: Decompilation coordination thread
Post by: ete on December 21, 2014, 09:42:12 PM
Cool stuff. I encourage you to set up github for windows and keep your text file updated here https://github.com/OpenSMACX/OpenSMACX/tree/master/Information/Dio
Title: Re: Decompilation coordination thread
Post by: Dio on December 22, 2014, 01:40:12 AM
Cool stuff. I encourage you to set up github for windows and keep your text file updated here https://github.com/OpenSMACX/OpenSMACX/tree/master/Information/Dio
I will post my text file once I have gathered as much information as I can in various areas :).
Title: Re: Decompilation coordination thread
Post by: Dio on December 22, 2014, 05:56:58 AM
I can not add my text file on github because I lack adminstrative access. I will post it here for now. I will also probably add additional information to the file later this week .
Title: Re: Decompilation coordination thread
Post by: ete on December 22, 2014, 02:31:16 PM
Your account is on the contributors team, which is set to "This team grants Write access: members can read from and push to the team's repositories." so you should be able to edit repository contents.. could you describe to me exactly what stops you so I can try and figure out what's going on?
Title: Re: Decompilation coordination thread
Post by: Dio on December 22, 2014, 04:06:58 PM
Quote
You're creating a file in a project you don't have write access to. We've created a fork of this project for you to commit your proposed changes to. Submitting a change will create the file in a new branch in your fork, so you can send a pull request.

This is the message I get whenever I try to add a file. Basically it makes a copy, or branch, of the original project with my proposed changes. The proposed changes then need to be approved by one of the adminstrators of the repository.
Title: Re: Decompilation coordination thread
Post by: ete on December 22, 2014, 04:36:35 PM
Does that happen when you click Clone in Desktop? Or this (http://github-windows://openRepo/https://github.com/OpenSMACX/OpenSMACX)? You don't need a separate branch, just a clone.
Title: Re: Decompilation coordination thread
Post by: Dio on December 22, 2014, 05:05:01 PM
Clicking on Clone from the github desktop downloads the contents of the repository onto your computer. Clicking the link leads me to an error loading page message.
Title: Re: Decompilation coordination thread
Post by: ete on December 22, 2014, 06:03:40 PM
Clicking on Clone from the github desktop downloads the contents of the repository onto your computer. Clicking the link leads me to an error loading page message.
Okay, do you have a clone on your computer and github for windows? https://windows.github.com/ if yes to both, try moving the text file into the github folder on your computer and making a commit via github for windows? If it gives an error, please tell me exactly what causes it/what the error message is.

And right, that link must only work on github.com. You should be able to clone from there still.
Title: Re: Decompilation coordination thread
Post by: kyrub on December 25, 2014, 11:28:39 PM
Hi guys,
it's nice there seems to be a major cooperation, at last.

I have moved on in my life and I won't be cooperating directly on anything relating gaming. But I am willing to give you all my gathered info on SMAC AI. The tricky part is that I am not a programmer (so my notes don't follow typical structure yours probably do) and I never intended to share my notes with anybody and my notes have been incredibly confusing since my grammar school. So I guess it's down to you to understand... still it is possible to get some good information from the most important parts.

I'll make a search on my old laptop to find out the IDA dbase.
k
Title: Re: Decompilation coordination thread
Post by: kyrub on December 25, 2014, 11:59:02 PM
This is my IDC database for SMAC exe. Concentrate on fontions starting with "AI" prefix, especially AI_build and AI_mvt_ut. There is a lot of info in there. Beware not all my "bugs" ended being one... Double slashes indicate places that I changed in my patch... sadly, not all changes are indicated by "//", as I chose later to abandon the habit. Confusing, I know.
https://www.mediafire.com/?oa2q9932yzsawpk (https://www.mediafire.com/?oa2q9932yzsawpk)


As far as data addresses go, I guess the others have a lot more insight than me.
There are internal flags however:
"continental_flags"
01 - no place to expand on conti
02 - 1 colony pod on conti
04
08 - > 1 colony pod
10
20 - other player present
40 - other player at war present
80
100
200
400 - conti with base taken by human player
800
1000
2000
4000 - invasion by other palyer (I forgot the internal weighs... sorry)

There are other important Ai related flags for baseData 0x30
200 - srapped facility
8000 - ocean base
1000 - IS energy needed +1 > MineralNeeded?
2000 - IS mineralNeeded +1 > EnergyNeeded?
100000 - attacked by plane
200000 - attacked by artillery
80000 -bring terraformed
400 - arifact connected
2000000 - just built colonyx pod
1000000 - just built colony pod nr.2

x34
4000 - nutrients needed

I guess that is my input done.
Good luck there, scient & co.!

Title: Re: Decompilation coordination thread
Post by: PlotinusRedux on December 26, 2014, 08:22:21 AM
Kyrub--thanks for sharing your IDA DB.  I don't know how much Scient may have identified in the AI routines, but I know I haven't identified any of them myself, as I've focused on the UI, so this will all be information I didn't have before.

I just downloaded your IDA db to look at tomorrow, but just to be clear on one thing--your DB is called terran.idc and your post references the SMAC exe.  My own IDA work started with SMAC and only after that did I look to find the equivalent addresses in SMAX, but everyone else's work here seems to have been solely on SMAX.  Is your DB really for terran.exe, the original Alpha Centauri, as it would seem from the name, or did it just get renamed and is really for Alien XFire?  If the former, did you ever identify in the same routines in Alien Xfire?  (It's OK if you didn't, I've already done some work mapping routines between the two that would help me in making a SMAX translation of your SMAC db.)
Title: Re: Decompilation coordination thread
Post by: PlotinusRedux on December 26, 2014, 10:57:43 AM
Scient--

I'm getting more and more optimistic about our ability to release a compileable, drastically improved version of SMAX in a matter of months rather than years.

A large part of the class structure is devoted to UI controls.  Just combining what I had worked out with your .map file and the function prototypes in the MAC version you shared already lays out 60% of the class prototypes for the UI.  That's past the tipping point where finishing the prototypes becomes easy if tedious.

I already have a DirectX 9 control library I wrote that implements 80% of what I've seen in the UI, and the other 20% would be trivial to add.  Once we have the UI prototypes worked out, we're talking weeks for me to completely replace the entire UI code with my own DX9 control code implementing the same interfaces.

The next thing I'd attack is the map and unit rendering code.  The hardest part there will be converting the cavier files to a standard mesh format, though the terrain rending code will also take me some time.  I'm guessing 3-4 months to accomplish a complete conversion of that code to DX9, which combined with the control library will replace all the UI and graphics code and allow textures and meshes of any resolution and color depth.  From there the only limit to how good the game looks is what mesh and graphical artists we can round up.  And some of the non-technical people here who want to contribute could probably download Blender, a free mesh creating program, and produce meshes much better than the current ones--anyone who can draw a decent stick figure could improve them.  I just happen to be in the lowest 1% who can't even draw decent stick figures.

That basically takes care of the entire Jackal engine code, making it easier to identify the rules engine, game logic, AI, etc., code.  I'd assume you and Yitzi et al would have continued to work on that while I was working on replacing the Jackal code.  At that point I could join ya'll in working on that part. 

I really think by a conservative estimate within a year would could have a complete C++ de-compilation/rewrite completed using DX9 for the UI and mesh rendering on the graphics side and a fully customizable game engine on the other side.
Title: Re: Decompilation coordination thread
Post by: ete on December 26, 2014, 02:11:45 PM
Thank you very much kyrub!

@Plotinus: kyrub's work was indeed based on SMAC not SMAX. A few of his changes were transferred to SMAX, as listed here: http://alphacentauri2.info/index.php?action=downloads;sa=view;down=108 (http://alphacentauri2.info/index.php?action=downloads;sa=view;down=108) but the vast majority of improvements and work was SMAC only. We had plans to create a mod for which would clone SMAC within SMAX, at which point he would consider switching over, but it was never finished.

That is amazing news about having the game possibly fully decompiled and significantly improvable within months :D. Especially excited about what can be done with the AI, modability, and full color depth.
Title: Re: Decompilation coordination thread
Post by: Dio on December 27, 2014, 05:41:36 PM
Thank you Kyrub for releasing your IDA database :).
Title: Re: Decompilation coordination thread
Post by: PlotinusRedux on December 28, 2014, 05:47:48 AM
Dio--Any information on any routines or data will be useful.  I think between what I have and what Scient has we're going to have 99% of the UI identified, but I've done nothing on the game logic, ai, etc., myself, and the Mac executable Scient found seems to mainly identify the UI classes rather than the game logic and AI routines that were probably straight C.

So really, I think any areas you want to focus on other than UI will be helpful.

Scient and any other C++ coders--so the main part that is going to suck is MSVC only allows the "naked" specification, which suppresses generation of function prologues and epilogues, outside of classes--you can't even use the specification for static members of a class.  I looked to see if GNU C was any better, and it doesn't even allow the "naked" specification for 80x86 processors at all.  I've always preferred Borland, which gives much more control over--well, everything--but that's a dead end long term since they basically went out of business nearly a decade ago, so I'm forcing myself to not use them.

The only solution I can think of is to wrap the .exe assembly in straight C __thiscall specifications and have a script add thunks for every non-virtual class method to the classes themselves.  It's not a problem for virtual functions since those can be pointed directly at naked __thiscall's that aren't defined as class members, even though we know they really are class members.
Title: Re: Decompilation coordination thread
Post by: Dio on December 28, 2014, 05:46:42 PM
Dio--Any information on any routines or data will be useful.  I think between what I have and what Scient has we're going to have 99% of the UI identified, but I've done nothing on the game logic, ai, etc., myself, and the Mac executable Scient found seems to mainly identify the UI classes rather than the game logic and AI routines that were probably straight C.

So really, I think any areas you want to focus on other than UI will be helpful.

Scient and any other C++ coders--so the main part that is going to suck is MSVC only allows the "naked" specification, which suppresses generation of function prologues and epilogues, outside of classes--you can't even use the specification for static members of a class.  I looked to see if GNU C was any better, and it doesn't even allow the "naked" specification for 80x86 processors at all.  I've always preferred Borland, which gives much more control over--well, everything--but that's a dead end long term since they basically went out of business nearly a decade ago, so I'm forcing myself to not use them.

The only solution I can think of is to wrap the .exe assembly in straight C __thiscall specifications and have a script add thunks for every non-virtual class method to the classes themselves.  It's not a problem for virtual functions since those can be pointed directly at naked __thiscall's that aren't defined as class members, even though we know they really are class members.
Good to hear that my work will not go to waste. I have discovered a few things worth mentioning in the UI interface code but alot of what I found so far is related to script controls and AI behavior in regards to those scripts.

The number of different memory addresses and there associated flags that control AI behavior keeps increasing. I now know that their is at least 4 different memory addresses along with various constant flags they are compared to control various aspects of AI behavior in scenarios and during regular gameplay. The long version will be in the text file I am going to update.
Title: Re: Decompilation coordination thread
Post by: Lord Avalon on December 28, 2014, 11:02:36 PM
...I've always preferred Borland, which gives much more control over--well, everything--but that's a dead end long term since they basically went out of business nearly a decade ago, so I'm forcing myself to not use them. ...


It looks like Turbo C++ is now C++Builder XE7 from Embarcadero Techonologies (http://http://www.embarcadero.com/products/cbuilder?cid=701G0000000tKTx), which acquired CodeGear from Borland in 2008. I am not a coder, so I have no idea if it's any good, but there's a 30-day free trial.
Title: Re: Decompilation coordination thread
Post by: Dio on December 29, 2014, 02:59:43 AM
Attached below is most of my work so far plus a slightly revised and updated version of my Labels in the assembly code file.

Edit: Nobody is interested ???.
Title: Re: Decompilation coordination thread
Post by: Dio on December 31, 2014, 05:32:19 AM
I am currently going through the AI controls for the Diplomacy scripts. Their are alot of immediate constants involved in the running of this game. In addition, I now have a somewhat clear idea of how portions of the faction specific AIs for  ;miriam;, ;morgan;, ;yang;, ;roze;, ;domai;, and ;lal; work :). If people have more memory addresses/data segements identified and are willing to share that is always helpful. I will continue  :read: this code.
Title: Re: Decompilation coordination thread
Post by: PlotinusRedux on December 31, 2014, 07:49:57 AM
Attached below is most of my work so far plus a slightly revised and updated version of my Labels in the assembly code file.

Edit: Nobody is interested ???.

I'm interested, Dio, I've just suspended all work until Scient's release of his IDA database to avoid duplication of effort.  Once he releases that and I spend some time turning it into compilable C, I'll want to incorporate all the information every one has into a GIT C++ project.

Be assured, no one's research they're willing to share will go to waste--I'm just not ready for it yet.

The addresses/routines I have identified are mainly related to the UI and/or are for  terran.exe rather than terranx.exe, so I don't think they'd be of much help to you with the AI.
Title: Re: Decompilation coordination thread
Post by: Yitzi on January 08, 2015, 12:38:56 AM
By the way, I found the landmark creation procedures:
  5C5EF0: jungle
  5C5C70: crater
  5C6DB0: volcano
  5C7F40: mesa
  5C8150: ridge
  5C69E0: uranium
  5C64A0: ruins
  5C7750: unity
  5C7A80: fossil
  5C7540: nexus
  5C7020: borehole
  5C6200: sargasso
  5C6740: dunes
  5C6C40: fresh
  5C83B0: geothermal
In all cases, arg1 and arg2 are position, with -1,-1 for random.  Volcano has arg3 to determine if it comes from a special
event as opposed to map creation or scenario editor
Title: Re: Decompilation coordination thread
Post by: Dio on January 08, 2015, 04:41:03 PM
The procedure at 005002F0 moves arg 1 and 2 into the EAX and EDX registers respectively. Arg 3 takes a push value and moves it into the ECX register. The memory address of the diplomatic relationship with faction x is moved into the register EAX for these operations. Then it performs an AND command with the  memory address for faction diplomatic relationships against the value in ECX. The final result for the AND command on the Diplomatic relationship address is then returned and often has a TEST command performed against itself with a conditional jump following.

This is just one of the many procedures that control AI diplomatic behavior but appears in many of the procedures for AI diplomatic behavior.
Title: Re: Decompilation coordination thread
Post by: Dio on January 08, 2015, 05:15:46 PM
Most of the call commands in the sections around the Script Names for AI Diplomatic interactions simply control either the appearance of words from the playerfiles in strings like FACTIONNAME0, FACTIONADJ2, NUM0 or the diplomatic conditions neccesary for these scripts to occur. What I have not figured out yet is the meaning or use of some of the memory addresses that appear frequently in the script sections for AI diplomatic interactions. Because I have very little reference to their meaning, it is difficult to ascertain their function in the procedure. I know some of the addresses store values with unknown meaning. A few examples of these addresses include 93F800, 93FAA8, 93F80C, 0093F7CC, and so on. Identifying the function of these addresses would greatly ease my reading the procedures.

Lastly, the procedure I described in the previous post opens a whole slew of new diplomatic relationships values that I have not figured out yet.



Title: Re: Decompilation coordination thread
Post by: PlotinusRedux on January 09, 2015, 04:26:50 AM
For anyone interested, while I wait for Scient's IDA release, I've been working with Ford_Prefect to identify the parts of the .cvr files he hadn't already identified.  I think we've got the entire file format pretty much worked out now, including newly identified 8 and 16 bit shader tables, the normal information in the voxel data itself, and all the tags used in the files--enough to easily rebuilt the entire rendering engine in full 32-bit color and create a full model/animation editor.

No formal write up yet, it's still a WIP, and I only just now figured out what the "material" tag was for--it's really a 16-bit shading table, not "material" in any normal 3d graphics sense--but all the information is spread across the thread starting around http://alphacentauri2.info/index.php?topic=6909.45. (http://alphacentauri2.info/index.php?topic=6909.45.)  I'm sure Ford or I will write it up in the not too distant future once we verify my hypothesis about the normals really is correct by encoding it in a rendering engine and seeing it looks right.

My hope is the same engine is being used for the terrain with the models being built in memory by combining a voxel map of the terrain with the terrain textures in the .pcx files instead of being read from a file--if so, I'm a lot closer to my 32-bit conversion than I thought I would be.  The Caviar engine itself can already handle 16-bit color, which would itself be a massive improvement over 8-bit paletted, so it's just the graphics primitives--including the render target of the engine--that are hard-coded to 8-bit, and they will be fairly easy to replace.

Title: Re: Decompilation coordination thread
Post by: Yitzi on January 09, 2015, 12:28:51 PM
The procedure at 005002F0 moves arg 1 and 2 into the EAX and EDX registers respectively. Arg 3 takes a push value and moves it into the ECX register. The memory address of the diplomatic relationship with faction x is moved into the register EAX for these operations. Then it performs an AND command with the  memory address for faction diplomatic relationships against the value in ECX. The final result for the AND command on the Diplomatic relationship address is then returned and often has a TEST command performed against itself with a conditional jump following.

This is just one of the many procedures that control AI diplomatic behavior but appears in many of the procedures for AI diplomatic behavior.

I think it's usually more useful to give it as a more succinct result; we don't need to know what registers are used.  For instance, here 005002F0 simply returns the relationship between faction arg1 and faction arg2, masked by arg3 (i.e. only showing bits present in arg3).
Title: Re: Decompilation coordination thread
Post by: DrazharLn on January 14, 2015, 11:56:03 AM
@PlotinusRedux, Ford_Prefect,

Congratulations!
Title: Re: Decompilation coordination thread
Post by: mmmniple on October 27, 2016, 02:30:12 PM
Hello,i asked a friend to decompile caviar player and caviar web pluggin using hexray for trying to understand this format.

Here goes the results.

http://pastebin.com/LcCxDNhP (http://pastebin.com/LcCxDNhP)

and the export files :

http://www.mediafire.com/file/ozt59x16hu69oj1/pluggin.rar (http://www.mediafire.com/file/ozt59x16hu69oj1/pluggin.rar)

http://www.mediafire.com/file/maiu0tz6qw3ppxv/caviar.rar (http://www.mediafire.com/file/maiu0tz6qw3ppxv/caviar.rar)

I hope this could be usefull.

The original files (i posted on other thread of this forum) :

http://www.mediafire.com/file/1539krs92y9hzj9/CVRPlay.rar (http://www.mediafire.com/file/1539krs92y9hzj9/CVRPlay.rar)

(it included the pdf patent with some info about this technology

and a mini-Faq i have created explaining this files

http://www.mediafire.com/file/td5n52vvdhz99h2/FAQ.txt (http://www.mediafire.com/file/td5n52vvdhz99h2/FAQ.txt)




Title: Re: Decompilation coordination thread
Post by: scient on October 28, 2016, 05:22:44 AM
It looks like that was decompiled with an older version of x86 plugin. Here is one decompiled with latest version. Might have some improved parsing.

npvox.dll
http://pastebin.com/gYML7K2p (http://pastebin.com/gYML7K2p)

If there is anything else you'd like me to run through latest decompiler (x86/x64/ppc) just let me know.
Title: Re: Decompilation coordination thread
Post by: mmmniple on October 28, 2016, 03:36:24 PM
A lot of thanks!
It is increíble the diference between them:
your code seem almost real c (they init the variables,recover more names,..).
Thanks

I have looking on the code and i have extracted some info,maybe nothing important or they had no included on the past of cvr which is already known .
After some search (i have never created a Netscape pluggin ),and read again the patent,i am understanding better.
I dont know if this is the place to post it,if no please tell me where is it.
With help i think the full format can be understanded.

(I think than The middle part of cvr files ,which is no understanded,is the lookup table,where are saved the vector of increments which are already precomputed .
Title: Re: Decompilation coordination thread
Post by: scient on October 29, 2016, 08:49:04 AM
Glad it helped. Let me know if you find anything else you would like decompiled and I'll give it a go.  :)
Title: Re: Decompilation coordination thread
Post by: mmmniple on November 02, 2016, 08:30:37 PM
Glad it helped. Let me know if you find anything else you would like decompiled and I'll give it a go.  :)


Hello,i have just uploaded more documentation about caviar technology and a diferent tech which i thought was the same until today i found on a magazine which i also have uploaded.

Could you decompile the latest caviar player (v1.6)

http://www.mediafire.com/file/c12do2thm29xdmv/CvrPlay.exe (http://www.mediafire.com/file/c12do2thm29xdmv/CvrPlay.exe)

and the file on the rar http://www.mediafire.com/file/4y12nfoju0zbprt/vssevalw.rar (http://www.mediafire.com/file/4y12nfoju0zbprt/vssevalw.rar) ?

(This latest is no related to caviar,but it seem have a similar tech.Maybe it could give some help.one never knows..)

thanks for all

I hope could advance something with the decompiled files to understand the animation part
Title: Re: Decompilation coordination thread
Post by: scient on November 03, 2016, 02:07:03 AM
Of course! I've attached both decompiled files. Let me know if you come across anything else that would be helpful to decompile.  :)
Title: Re: Decompilation coordination thread
Post by: mmmniple on November 03, 2016, 10:19:10 AM
Of course! I've attached both decompiled files. Let me know if you come across anything else that would be helpful to decompile.  :)

Thanks.
The second file was wrong : you have to extract the exe from the rar and dissasm "voxel.exe".i have tried to see it with "PE Explorer",and the functions are 32 bits.
Title: Re: Decompilation coordination thread
Post by: scient on November 03, 2016, 04:31:14 PM
Here you go!
Title: Re: Decompilation coordination thread
Post by: mmmniple on November 03, 2016, 07:40:41 PM
Here you go!

A lot of thanks!
Title: Freeciv engine?
Post by: mmmniple on November 16, 2016, 04:02:28 PM
Hello again.I would love propouse something :
as the engine is the same as civilization 2 + voxel render,why doesnt use as base the
freeciv engine for the reimplementation you are doing based on your dissasmbly code.

i know you had decided use directx9 as base,but i think it could help both comunities (being more easy the proyect could be finished plenty ).Also it would be hightly portable.

if the code for use the same asset is implement there were no need to transformation it,and in the case it doesnt ,they have the tools for creating modpacks.

http://tecfa.unige.ch/guides/games/freeciv/manual/game-21.html (http://tecfa.unige.ch/guides/games/freeciv/manual/game-21.html)


Title: Re: Freeciv engine?
Post by: Yitzi on November 18, 2016, 07:08:10 PM
Hello again.I would love propouse something :
as the engine is the same as civilization 2 + voxel render,why doesnt use as base the
freeciv engine for the reimplementation you are doing based on your dissasmbly code.

I would be wary of that.  From a legal and ethical perspective, what we do with disassembling SMAC/X is ok based on ideas of fair use...and if we start using it significantly for something like freeciv (which is competing with the original in a way that probably precludes fair use), it seems to me that that could be an issue.
Title: Re: Freeciv engine?
Post by: mmmniple on November 18, 2016, 09:33:56 PM
Hello again.I would love propouse something :
as the engine is the same as civilization 2 + voxel render,why doesnt use as base the
freeciv engine for the reimplementation you are doing based on your dissasmbly code.

I would be wary of that.  From a legal and ethical perspective, what we do with disassembling SMAC/X is ok based on ideas of fair use...and if we start using it significantly for something like freeciv (which is competing with the original in a way that probably precludes fair use), it seems to me that that could be an issue.

Hello Yitzi.There are several ways of see this.I would try explain my view,but of course it is only my way of see the matter .

As far i know there are no legal issues if you dont use the assembly code as if ;
it means if you create your code ,based on what you are learning there are no problem.
You can add the use of this assets on something as freeciv without any problem BUT you would never share the assets with it : the person who wanna play it need have the oficial game which can bought on gog,...(GOG version doesnt create new code,they use often fans code-patch and/or dosbox emulators for let user play on new machines)

About competing i think there are no problem for lots of reasons,is more i think it is the opposite :
you are helping to spread the game ,letting new users discover this great game (many of this recreation late are ported as homebrew on videoconsoles as Psp,nds..)
which could help to the company to see there are interest on its game and create a remake or secuel with today technology ( the original 3d version proposed at the begining is what could be a problem)

They are plenty examples of that from another world , ScummVM
 ( Monkey Island Special Edition Collection,Day of Tentacle,Grim Fandando,Full Throttle..) to X-COM 1 and 2.

Some of them make use of the fan remade's open source code for his own use : lots of times the code was lost or maybe need more efford to create something which work on actual machines (when most part is asm code) and they use when wanna let the user play the classic version with the remake ,as happen on Monkey Island where you have the "new game" or press a key and play the classic version.

Here are a list with lots of examples of this kind of proyects

https://en.wikipedia.org/wiki/Game_engine_recreation

https://en.wikipedia.org/wiki/List_of_game_engine_recreations



Title: Re: Freeciv engine?
Post by: Yitzi on November 19, 2016, 11:28:18 PM
Hello again.I would love propouse something :
as the engine is the same as civilization 2 + voxel render,why doesnt use as base the
freeciv engine for the reimplementation you are doing based on your dissasmbly code.

I would be wary of that.  From a legal and ethical perspective, what we do with disassembling SMAC/X is ok based on ideas of fair use...and if we start using it significantly for something like freeciv (which is competing with the original in a way that probably precludes fair use), it seems to me that that could be an issue.

Hello Yitzi.There are several ways of see this.I would try explain my view,but of course it is only my way of see the matter .

As far i know there are no legal issues if you dont use the assembly code as if ;

Ok, that makes sense.
Title: Re: Decompilation coordination thread
Post by: mmmniple on November 27, 2016, 06:58:48 PM
hi,i have seen there was a first try for something similar (a fork from freeciv):

http://freecivac.sourceforge.net/ (http://freecivac.sourceforge.net/)

Title: Re: Decompilation coordination thread
Post by: mmmniple on January 23, 2017, 04:25:04 PM
Hello,i asked a friend to decompile caviar player and caviar web pluggin using hexray for trying to understand this format.

Here goes the results.

http://pastebin.com/LcCxDNhP (http://pastebin.com/LcCxDNhP)

and the export files :

http://www.mediafire.com/file/ozt59x16hu69oj1/pluggin.rar (http://www.mediafire.com/file/ozt59x16hu69oj1/pluggin.rar)

http://www.mediafire.com/file/maiu0tz6qw3ppxv/caviar.rar (http://www.mediafire.com/file/maiu0tz6qw3ppxv/caviar.rar)

I hope this could be usefull.

The original files (i posted on other thread of this forum) :

http://www.mediafire.com/file/1539krs92y9hzj9/CVRPlay.rar (http://www.mediafire.com/file/1539krs92y9hzj9/CVRPlay.rar)

(it included the pdf patent with some info about this technology

and a mini-Faq i have created explaining this files

http://www.mediafire.com/file/td5n52vvdhz99h2/FAQ.txt (http://www.mediafire.com/file/td5n52vvdhz99h2/FAQ.txt)


Hi to all and excuse me for no news in this time : i was too busy .i had some advances with the pluggin RE (i know the format has been reverse enginered and posted the info on the wiki and a new java viewer : "cvr2",but i wanna tried to finish what i have begun (it is my first RE).
Anyway i would comment i found on an older magazind Cd a Netscape versión which work on latest windows (i am sure on windows XP,and win7) and see the older pluggin in action!
(I used the demo they had which change a little the html Source (now you only need change the file name you wanna see on the HTML Source and let this file on the same directory).
If someone is interesting i can upload the netscape and the HTML

Yours
Title: Re: Decompilation coordination thread
Post by: DrazharLn on January 25, 2017, 02:52:09 PM
Please upload the netscape plugin and HTML. If you don't nobody is going to find them again and they might be useful :)
Title: Netscape exe and caviar voxel viewer pluggin working
Post by: mmmniple on January 26, 2017, 01:52:57 PM
Here goes!
I had added a "Minifaq" explaining how to use it .

Also a 16bit version of Netscape which came on the same demo disk i found it with the 32 version .

I dont know if it works : i can no test it.Maybe with windows 3.1 ,but no sure if the pluggin would work with it.if it does great : it could work on any mobile device with dosbox :p
excuse me ,it gave me error for the upload size limit.Later i will upload on other place  and post.sorry
Title: Re: Decompilation coordination thread
Post by: DrazharLn on January 26, 2017, 04:56:53 PM
How big is it?
Title: Re: Decompilation coordination thread
Post by: mmmniple on January 28, 2017, 10:38:59 PM
Hello ,excuse me for the delay : i have too busy until now.
Here goes a mediafire link:

http://www.mediafire.com/file/d5arv0k49y49vfd/Netscape.rar (http://www.mediafire.com/file/d5arv0k49y49vfd/Netscape.rar)

its size is 15,4 Mb
Title: Re: Decompilation coordination thread
Post by: DrazharLn on January 29, 2017, 02:31:24 AM
I've recompressed it as a zip for greater accessibility and hosted it here under Downloads/Utilities: http://alphacentauri2.info/index.php?action=downloads;sa=view;down=351 (http://alphacentauri2.info/index.php?action=downloads;sa=view;down=351)

Thanks again.
Title: Re: Decompilation coordination thread
Post by: Induktio on August 12, 2017, 12:49:43 PM
By the way, I found the landmark creation procedures:
  5C5EF0: jungle
  5C5C70: crater
  5C6DB0: volcano
  5C7F40: mesa
  5C8150: ridge
  5C69E0: uranium
  5C64A0: ruins
  5C7750: unity
  5C7A80: fossil
  5C7540: nexus
  5C7020: borehole
  5C6200: sargasso
  5C6740: dunes
  5C6C40: fresh
  5C83B0: geothermal
In all cases, arg1 and arg2 are position, with -1,-1 for random.  Volcano has arg3 to determine if it comes from a special
event as opposed to map creation or scenario editor

These values are for terranx.exe obviously. When generating a new map, these are called from function 5C86E0.

One feature I've been looking for a long time is the ability to control what landmarks are placed in a random map. It would be simple to remove the relevant function calls, but it would be better to have a config file or an UI option to choose what landmarks are placed. Does anyone have ideas how to accomplish that?

It might also be useful to have more control on the faction starting point placement on random maps. Specifically, I'm wondering if it's possible to normalize the distance to nearest rivals so everybody doesn't start in one crowded island etc. Any idea where the random starting locations are determined?
Title: Re: Decompilation coordination thread
Post by: DrazharLn on August 12, 2017, 06:16:05 PM
Have you had a look at Scient's IDA database? It's very comprehensive with many functions named, structs deciphered and so on.

You'll need IDA >=6 to open it.

http://alphacentauri2.info/index.php?action=downloads;sa=view;down=341 (http://alphacentauri2.info/index.php?action=downloads;sa=view;down=341)
Title: Re: Decompilation coordination thread
Post by: Induktio on August 12, 2017, 08:21:24 PM
I haven't checked that database yet. Alas, not even all 6.x versions are able to open that file. IDA file formats are very version specific. Anyone know the exact version required?

Maybe it is possible to dump the database and typeinfo to a plaintext IDC file? Just open it in IDA, and select "Produce File > Dump ...".
Title: Re: Decompilation coordination thread
Post by: DrazharLn on August 12, 2017, 09:30:58 PM
IDA Pro 6.8.150423 with hexrays works. I think other 6.8 versions will work too.

idc files attached (database and separate typeinfo).

They're from my own database and have a handful more annotations than scient's database.
Title: Re: Decompilation coordination thread
Post by: Induktio on August 14, 2017, 09:50:57 PM
Yeah, that should offer some useful information on the game internals. I'll keep looking on how the map generator could be improved.
Title: Re: Decompilation coordination thread
Post by: Buster's Uncle on August 15, 2017, 01:43:51 AM
 ;b;
Title: Re: Decompilation coordination thread
Post by: Induktio on August 15, 2017, 10:37:47 PM
If anyone else wonders, landmark generation can already be customized with Yitzi's latest patch. There's a new config file option in alphax.txt for that.

The documentation is just buried in a relatively obscure page, near the end here: http://alphacentauri2.info/wiki/New_alphax_variables_in_Yitzi%27s_patch (http://alphacentauri2.info/wiki/New_alphax_variables_in_Yitzi%27s_patch)
Title: Re: Decompilation coordination thread
Post by: DrazharLn on August 15, 2017, 11:11:44 PM
Heh. I completely forgot that Yitzi had already done that.
Title: Re: Decompilation coordination thread
Post by: Induktio on August 16, 2017, 11:12:18 AM
Speaking of the patch documentation, the other thing that left me wondering was the "SELECT PLANETARY ORBIT" "80..100 million miles" option when generating a new map. It's the first thing the map generator asks yet I can't see if it affects anything? Another thread suggested it affects eco damage but not sure how to verify it. At least it should be explained in the readme or worded differently. The map in this game doesn't represent temperature per se, there's only humidity which already has its own setting.
Title: Re: Decompilation coordination thread
Post by: scient on September 24, 2017, 07:01:22 AM
Speaking of the patch documentation, the other thing that left me wondering was the "SELECT PLANETARY ORBIT" "80..100 million miles" option when generating a new map. It's the first thing the map generator asks yet I can't see if it affects anything? Another thread suggested it affects eco damage but not sure how to verify it. At least it should be explained in the readme or worded differently. The map in this game doesn't represent temperature per se, there's only humidity which already has its own setting.

I thought I'd have a quick look at this. So it looks like this was enabled by Yitzi's patch, not by default. By default, the global variable that handles this is set to 1: "90 million miles (average planet)".

SMACX global variable offset: 0x94A2B0
valid values: 0,1,2

The only function that references this global, outside of map configuration, is world_temperature(). This in turn is called by world_build() or world_climate(). The key one is world_climate() that gets called during terraforming, random events, planet busting, ecology functions and many others. It seems to get called on average between 10-20 turns.

Inside world_temperature() the global 0x94A2B0 is used as an upper bound value in the random generation of a local variable as well as some conditional checks. In the end, a value between 0 and 2 is passed as a parameter to the function temp_set(x,y,VALUE). The function looks like it loops through the tiles setting this value. Tiles temperature will change over the course of the game. It seems near the poles, it is always 0. This is likely part of the logic checks on the x/y bounds. It looks like the temp of a square will affect whether it is arid, moist or rainy.

Hopefully this adds some clarity to what this setting is doing. If there is interest, I will decompile the entire world_temperature function.
Title: Re: Decompilation coordination thread
Post by: Induktio on November 09, 2017, 11:27:55 PM
SMACX global variable offset: 0x94A2B0
valid values: 0,1,2

The only function that references this global, outside of map configuration, is world_temperature(). This in turn is called by world_build() or world_climate(). The key one is world_climate() that gets called during terraforming, random events, planet busting, ecology functions and many others. It seems to get called on average between 10-20 turns.

Interesting information right there. I suppose this setting then influences global warming. From the player's perspective it might be most important to see whether this setting will lessen or increase the effects of global warming. I don't know enough to judge whether those other effects have noticeable changes with the temperature option.
Title: Re: Decompilation coordination thread
Post by: Induktio on July 03, 2018, 08:26:39 PM
IDA Pro 6.8.150423 with hexrays works. I think other 6.8 versions will work too.

idc files attached (database and separate typeinfo).

They're from my own database and have a handful more annotations than scient's database.
Decided to take a look at this again. If anyone has problems opening Scient's database, it is also pretty easy to import the annotations from these idc files. One should copy the lines containing MakeName or MakeComm and paste them into IDA's script input box. Then you should have most of the important functions with plain text names, no matter which version of IDA is in use.

There's many things we could improve with the current AI though. Some important ones:
1. How many colony pods to build
2. Where does the AI build colonies
3. How many formers to build
4. How is the terraforming action selected for a given former

If anyone has function locations for these actions already figured out, you could post them here. I'd suspect many of them have something to do with function 0X56B5B0, "enemy_move" but it is the most complicated function in the whole binary.
Title: Re: Decompilation coordination thread
Post by: Induktio on July 04, 2018, 09:28:16 PM
Also a question for scient et al. Does this IDA database incorporate any of the information kyrub used when he made his AI patch?

Edit: ahh, of course kyrub already posted his idc file much earlier here: http://alphacentauri2.info/index.php?topic=14229.msg65853#msg65853 (http://alphacentauri2.info/index.php?topic=14229.msg65853#msg65853)

There seems to be some similarities but I'm not sure yet if kyrub's database has any information that scient's analysis doesn't. It's a different binary but Firaxis probably shared a lot of the codebase.
Title: Re: Decompilation coordination thread
Post by: Induktio on July 11, 2018, 03:51:54 PM
Here's a small mod for terranx.exe that enables some debugging output. It is probably only useful for mod developers. The game by default creates a file called logfile.txt but all of the debug output was disabled when the game binary was built. This patch was built on the default GOG binary, no other changes have been made. To enable the debug patch, edit Alpha Centauri.Ini and make sure it includes these lines:

Code: [Select]
[Alpha Centauri]
Multi Debug=1

Any other value will disable the debug mode. Then just start the game from terranx_debug.exe and you can read the output from logfile.txt. 
Title: Re: Decompilation coordination thread
Post by: bvanevery on July 13, 2018, 08:14:34 PM
If only we knew the secret as to why the AI builds units until it runs out of support.  If we could stop that behavior, it would be the single biggest possible improvement to the competence of the game.
Title: Re: Decompilation coordination thread
Post by: scient on July 24, 2018, 10:50:56 PM
Here is the most recent export from my database. It includes a lot of additional work and clean up over the past year or so. Especially around the internal structures. I had meant to post this closer to the the beginning of the year but I've been super busy with work and certifications. There are still a few things I'd like to do before "officially" sharing this. However, I figured this might be of some use if you are poking around.
Title: Re: Decompilation coordination thread
Post by: Induktio on July 27, 2018, 09:09:29 PM
Yeah, I've been reversing some additional stuff as I've been developing my new mod. Anyway, looks like this file has not been posted here yet:
https://web.archive.org/web/20080827173127/http://meepo.dnsalias.org/misc/SMAC-MP.txt (https://web.archive.org/web/20080827173127/http://meepo.dnsalias.org/misc/SMAC-MP.txt)

It's an old but really accurate description of the map tile data structure. It is dynamically allocated so the pointer to the table is found from 0x94A30C.

Here's some additional observations:
Bytes  3- 4  Bitfield, some unknown flags
Byte   5  Faction bitfield, probably zone of control or tile visibility
Byte  15  Not constant, might relate to visibility
Title: Re: Decompilation coordination thread
Post by: scient on July 28, 2018, 08:23:31 AM
Yeah, I have same document from another board many years ago. Pretty sure I tried to incorporate some of that info into my IDA DB analysis. I think it's still on the todo list to flesh it out more. I did add one bit of info to my version of the document related to internal structure and coordinates. This way you can locate a particular tile's data.

How to get to map struct in memory:
[94A30C] + 0x2C * ((x_coord >> 1) + y_coord * [68FAF0])
Title: Re: Decompilation coordination thread
Post by: Induktio on July 29, 2018, 04:41:26 PM
Here's the header files I've been preparing for release:
https://github.com/induktio/smacheaders

I've omitted any structures related to the graphics rendering because my mod doesn't interact with those issues. But for anything else, people can always send a patch.

So for example, if we wanted to access the map array with this "api", we could write:
Code: [Select]
MAP* mapsq(int x, int y) {
    int i = x/2 + (*tx_map_half_x) * y;
    if (i >= 0 && i < *tx_map_half_x * *tx_map_axis_y)
        return &((*tx_map_ptr)[i]);
    else
        return NULL;
}
Templates: 1: Printpage (default).
Sub templates: 4: init, print_above, main, print_below.
Language files: 4: index+Modifications.english (default), TopicRating/.english (default), PortaMx/PortaMx.english (default), OharaYTEmbed.english (default).
Style sheets: 0: .
Files included: 33 - 892KB. (show)
Queries used: 20.

[Show Queries]