Command & Conquer Communications Center

keeping the classics alive!

Author Topic: TiberianSharp (formerly Luftballon) research thread  (Read 5893 times)

Offline CCHyper

  • Minigunner/Rifle Soldier
  • *****
  • Posts: 29
    • View Profile
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #15 on: June 25, 2011, 02:03:34 PM »
WWLib -> Westwood Library. Was Westwoods base code for every game they wrote. It contains file handling, memory management, vector and maths algo's, network code, basic behavior and so on.

There was some Renegade source code released by someone who worked on the Tiberian Technologies project for Renegade. The project was given some source code from the game to help understand how the game worked and in turn, develop new rendering and network code to replace the existing engines.

But we cant really talk about this publicly, as EA got there knickers in a twist when it was leaked out of the project.

Can you read ASM well? Or perhaps understand pseudo enough to rewrite? Aswell as common compiler optimizations, you should be able to recreate such classes without the source, this is what we do with the Ares and Orca projects for Yuris Revenge and Tiberian Sun respectfully.

Offline ShadowDog

  • Grenadier
  • *****
  • Posts: 61
    • View Profile
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #16 on: June 25, 2011, 02:10:25 PM »
Orca? There's an Ares for TS? Cool.

Wait, memory management? TD, RA, SS, TS, RA2, even Renegade were written in C? They never went to C++? Is that why it runs so fast?
Quote from: Nyerguds
Get that Starcrap outta my C&C :P

Offline CCHyper

  • Minigunner/Rifle Soldier
  • *****
  • Posts: 29
    • View Profile
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #17 on: June 25, 2011, 02:24:12 PM »
Orca is what im working on for Tiberian Sun, its my injection project based on the Syringe package

Offline Nyerguds

  • C&C1 H4x0r
  • Global Moderator
  • *
  • Posts: 3207
  • Green Forum Alien
    • View Profile
    • C&C95 Project 1.06
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #18 on: June 25, 2011, 11:05:39 PM »
Well, my thesis/internship project for university college was a C# desktop app that automatically scanned content from Word documents and uploaded it to an online platform. More specifically, it is a tool for teachers to automate the creation of assessments on the school's online platform.

Besides that, I've also completely rewritten CCSetup in C#, and this rewrite includes my very own ini file reading and writing system. I've recently ported that code to Java too. There's quite some pics of the new ccsetup on the ModDB site of the 1.06 patch. I've also made a radar colour editor for TS/RA2 SHP files, and, just for fun, a program to unlock protected mixfiles (but I never released or even announced I made such a thing :P )

At this moment though, I'm working to make a Java program to be the successor of my internship project (they hired me :) ), and at the moment that's mostly made up of GUI and database (SQLite) operations. I've also been working again on a java game which was originally made as big project in my first year at the university college. I made a thread about it here. The topic on cncnz I linked to also has a link to the source of that game, though it's mostly in Dutch :dry:

[edit]

Oh, I also wrote a Dune II game data editor in Pascal. With a text UI :D
« Last Edit: June 25, 2011, 11:55:46 PM by Nyerguds »

Offline ShadowDog

  • Grenadier
  • *****
  • Posts: 61
    • View Profile
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #19 on: June 26, 2011, 01:55:49 AM »
I'm glad that you mentioned Pascal, because the file format guide I'm using refers to a Pascal longint. I know that an x86 int and long are the same size, so I'm wondering if Pascal has self-imposed sizes, or if the person just arbitrarily put longint instead of int. Honestly all this file format reading can be confusing when people say, for example, word instead of 2 bytes.

Hyper, do you have a Bug Tracker? If not, I'll set up Mantis on my site.
Quote from: Nyerguds
Get that Starcrap outta my C&C :P

Offline Nyerguds

  • C&C1 H4x0r
  • Global Moderator
  • *
  • Posts: 3207
  • Green Forum Alien
    • View Profile
    • C&C95 Project 1.06
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #20 on: June 26, 2011, 11:09:16 AM »
Well, basically, in assembler
-byte = 1 byte
-word = 2 bytes
-dword ('double word') = 4 bytes.

As for longint, I think the name comes from the specific 32-bit "longer" int at the moment the standard for int (on 16-bit architecture) was still 16 bit.

Just googled it. "LongInt is a Borland Pascal extension. Borland Pascal defines LongInt as a 32-bit signed integer type." However, some more recent compilers like GNU Pascal or Freepascal may use it as 64-bit integer. It's basically a problem with evolution... on 16-bit architectures the standard "int" is 2 bytes, on 32-bit it became 4 bytes, and on 64-bit it'll become 8 bytes. It's simply a matter of how much the standard CPU registers hold. I'm just glad they finally got actual bit-specified types (Int16, Int32, Int64) in modern programming languages.

In old references, the Borland standard holds though, and you can safely assume longint simply means 32-bit.
« Last Edit: June 26, 2011, 11:11:17 AM by Nyerguds »

Offline ShadowDog

  • Grenadier
  • *****
  • Posts: 61
    • View Profile
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #21 on: June 26, 2011, 03:18:29 PM »
Of course, I forgot CnC was 16-bit. IIRC, 8-bits make up one byte, 16-bits would be 2 bytes, and 32 would be 4. Makes sense now. Thank you, Nyer.

Oh, and I just realized that qword = quad-word. Obvious, but not as obvious when you don't know what a dword is. :)

Edit:

Code: [Select]
public class MultiString
{
    public string Eng = ""; //!HACK
    public string Ger = ""; //!HACK
    public string Spa = ""; //!HACK
    public string Fre = ""; //!HACK
    public string String
    {
        get
        {
            string aaa = "";
            BasicClass.Languages.ForEach(delegate(String lang)
            {
                string bbb = GetStringLang(lang);
                if (bbb != "")
                {
                    aaa = bbb;
                }
            });
            if (aaa != "")
            {
                return GetStringLang(aaa);
            }
            if (BasicClass.Production)
            {
                return "";
            }
            else
            {
                return "*INVALID*";
            }
        }
    }
    public string GetStringLang(string lang)
    {
        if (lang == "Eng")
        {
            return Eng;
        }
        else if (lang == "Ger")
        {
            return Ger;
        }
        else if (lang == "Spa")
        {
            return Spa;
        }
        else if (lang == "Fre")
        {
            return Fre;
        }
        if (BasicClass.Production)
        {
            return "";
        }
        else
        {
            return "*INVALID*";
        }
    }
}

That get{} construct (is that the term?) seems really handy, though admittedly I see no point in it as opposed to a procedure. However, what I really want is some way to have a list formatted like this:

"Eng" = "Hi!",
"Ger" = "Guten tag or whatever",
"Fre" = "However the heck those Fremen say hello",
"Spa" = "iHola senior!" //As you can tell, I got a D in Spanish. Mainly because I can't remember where that darn... "marky thing" goes...

And return the later part based off the former. In BYOND, you make the list like this:
var whatever = list("a" = "c","b" = "d")
and access the later part by either going:
whatever[1] //1-indexed, IIRC
or:
whatever["a"]
with it returning null whenever you try to access something that isn't there. Is there anything that easy to use in C#, or am I going to have to have 2 lists, loop through the first list hoping to find string A, and if it's there, return the string at the same position in list B? Because if not, I'll make an API for that (in the last couple of days, I've done lots of stuff under the hood, but it's mainly been stuff like making my APIs easier to use and more child-proof; defensive programming is the way to go, because you never know when you'll be reduced to the intelligence level of a garden hose).

Edit2: Are all the mouse cursors displayed from the center with the exception of the generic mouse, or is there some sort of table I'll need to mimic?

Edit3: This is what I'm getting for conquer.mix
NumFiles: 266
DataSize: 50690

But it should be 2459769 instead of 50690. Can you figure out what's wrong? This is conquer.mix, by the way.

Code: [Select]
int NumFiles  = (mixfile[1] * 256) + mixfile[0];
Console.WriteLine("NumFiles: " + NumFiles);
int DataSize = (mixfile[5] * (256 * 3)) + (mixfile[4] * (256 * 2)) + (mixfile[3] * 256) + mixfile[2];
Console.WriteLine("DataSize: " + DataSize);
« Last Edit: June 26, 2011, 07:21:58 PM by ShadowDog »
Quote from: Nyerguds
Get that Starcrap outta my C&C :P

Offline Nyerguds

  • C&C1 H4x0r
  • Global Moderator
  • *
  • Posts: 3207
  • Green Forum Alien
    • View Profile
    • C&C95 Project 1.06
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #22 on: June 26, 2011, 07:22:06 PM »
C&C isn't 16 bit. Has never been 16 bit either. But most programs written for it back in those days were.
« Last Edit: June 26, 2011, 08:11:46 PM by Nyerguds »

Offline ShadowDog

  • Grenadier
  • *****
  • Posts: 61
    • View Profile
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #23 on: June 26, 2011, 07:46:14 PM »
Wasn't the DOS version (or was that just the installer)? Or am I confusing what 16-bit actually means?

Edit: I figured out the problem with the MIX headers: I was multiplying 256 by 2, 3, etc, instead of exponential...ing it by that much.

For the record (in case future peoples of the futures want something to reference when they discuss TD's .mix file format, because you know that'll be all the rage in A.D. 2101), TD has it's high bytes last. Which was that, big endian or little endian? I also get those two mixed up, no pun intended.

Edit2:

What are those last 3191 bytes in conquer.mix that supposedly aren't data for? 6 bytes for the header, 2456578 for the data, and the total file size is 2459775 bytes. Odd, isn't it?
« Last Edit: June 26, 2011, 08:04:31 PM by ShadowDog »
Quote from: Nyerguds
Get that Starcrap outta my C&C :P

Offline Nyerguds

  • C&C1 H4x0r
  • Global Moderator
  • *
  • Posts: 3207
  • Green Forum Alien
    • View Profile
    • C&C95 Project 1.06
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #24 on: June 26, 2011, 08:11:50 PM »
As for your data stuff:

-In the language system I built into C&C95 I don't have an internal list of languages. I parse the 3-character language string from the ini straight into the strings "lang_???.mix" and "lang_???.ini" to read a bunch of file REPLACEMENTS. Meaning that if you start in french, the English version of the strings file, sidebar buttons and game icons are simply not read at all. There is no list, and no language detection logic in the game.
Have you looked into the indexing system used in the conquer.eng file? It's pretty straightforward. I think it was four lines of assembler to get the string position if you got the start of the file and the string index.

-I haven't really looked into mix headers, except briefly into the TS ones, and that was only to fix them if they were broken as "mix protection".

-mouse cursors: Not a clue, really. I've never really looked into that. I kinda expect that to all be hardcoded in the cursor code, setting the click point at the moment it loads the cursor.

[edit]

I mess up big and little endian too, but it's actually pretty simple... look at the number "123". The "1" at the front is "100", so it's the largest number. The "3" at the end is the smallest number. So the end (since we read from left to right) is the smallest (least significant) number, which makes it little-endian.

C&C uses big-endian, where a hexadecimal number 12345678 becomes bytes 78 56 34 12
« Last Edit: June 26, 2011, 08:16:11 PM by Nyerguds »

Offline ShadowDog

  • Grenadier
  • *****
  • Posts: 61
    • View Profile
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #25 on: June 27, 2011, 09:04:56 AM »
I know the language thing isn't remotely like what TD uses; my idea is to make it so you can switch languages mid-mission, and also to let a half-implemented language fallback to another language. In my library, the language order is English, Spanish, French (due to being similar to Spanish), and German, though in TibSharp, it's English, German, French, Spanish. I'm planning on implementing the same thing for textures, too. Also, I'm planning on de-hardcoding it so that it uses the 2 list system I outlined previously.

I'm heard that C# doesn't do palettes, only shaders, and that I'd need to either have multiple textures that I manipulate on initialization to replace their colors with whatever they should be, or write a shader that does that, which I hear would be a performance hit. Since I'm going to be creating the Image from scratch anyway, I'll probably just use fastpixel (which I have a program I can reference, thankfully) and create a CNCFakePaletteSHP class that holds all the sides' paletting of a SHP. Considering that even if I could get it to do palettes, it'd still have to be broken into multiple Images, that'll be a PITA.

Unless, of course, fastpixel is faster than the speed of freaking light and I could have it convert hundreds of SHP-data-thingys into an image per-frame. Argh. I'll probably ask godly-cheese to make a giant mission (bigger than SS/RA's maximum map size) with a stupid amount of units to stress test the thing once I've made a map editor.

Edit: Opps, fastpixel isn't a library, it's a random class in ClassicMap, which is a Pokemon map editor. Argh. Anyway, research time, I suppose.

Edit2: Changed some hacky stuff into a flexible function, and it hit the fan. I finally tracked it down to an XOR statement. The main problem was what the fuck is an XOR statement and why shouldn't ^ be the exponent symbol. I haven't even gotten to anything involving bit-shifting or whatever yet and I'm already finding it to be a PITA.
« Last Edit: June 27, 2011, 12:43:59 PM by ShadowDog »
Quote from: Nyerguds
Get that Starcrap outta my C&C :P

Offline Nyerguds

  • C&C1 H4x0r
  • Global Moderator
  • *
  • Posts: 3207
  • Green Forum Alien
    • View Profile
    • C&C95 Project 1.06
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #26 on: June 27, 2011, 03:08:43 PM »
and also to let a half-implemented language fallback to another language.
Mine does that... simply by first reading the default language's settings, and then using these values as defaults for reading the actual one. I'm also working on an ini-based strings system to do both partial and complete replacements of the strings files.

I don't really get the storage system associated with your languages code though... but it reminds me of InnoSetup, where you can set custom strings for any number of supported languages, like this: (taken from the C&C95 v1.06 patch installer)

eng.langchoice=Set the game language:
ger.langchoice=Wählen Sie die Sprache für das Spiel:
fre.langchoice=Configurez la langue du jeu:

eng.reschoice=Screen Resolution:
ger.reschoice=Bildschirmauflösung:
fre.reschoice=Résolution graphique:

Though I'm not sure how you'd implement that for the entire game... it uses numerical IDs, not strings.

Offline ShadowDog

  • Grenadier
  • *****
  • Posts: 61
    • View Profile
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #27 on: June 28, 2011, 05:43:59 PM »
I'll parse the conquer.eng/.etc files, making a new MultiString for each that has it's values set accordingly. After that, I'll read whatever files those were that patch the conquer.* files. The MultiStrings are going to be in a list, BTW, so I can just call them up by index.

I'm not going to be handling absolutely everything the way TD does. For example, while TD has it's pre-briefing briefing (the part that shows up after you select a territory, but before you actually load the mission) call up string number x, I'll first check to see if the mission's .ini has anything on it, then check some .ini file for that info. You already wrote down that info, and I made it into an .ini file and shoved it somewhere in Luftballon. Once I finish up .mix loading, find a good way to store the canonical versions of the files in memory, parse the .tmp and .shp files, and figure out how to use palettes in a shader environment, I'll get around to getting the fancier things like actually loading text. For now, I've just finished getting back on a normal sleep schedule, so I'll be around 7PM before I'm ready to screw with TibDawn some more.

P.S. Played some more Black Ops. today. Kicks GoldenEye Wii's butt.
Quote from: Nyerguds
Get that Starcrap outta my C&C :P

Offline Iran

  • Medium Tank
  • *
  • Posts: 809
    • View Profile
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #28 on: June 29, 2011, 01:31:49 AM »
Level editor? Pfff, the Renegade Red Hat 8 FDS contains most of the code from the win32 version of the game, including parts of the singleplayer and it has all the symbols!

CCHyper: APOC gave them parts of the source code and stuff. One guy got close to one of the devs and accidently found that source code on an open directory owned by the dev. He ragequit and leaked it out. He''s been acting like a total retard for years so it's kinda amazing how he got so close to the dev. :/

ShadowDog: Did you take a look at OpenRA, it also implements C&C1/RA1 somewhat with C#. Although you'll probably only want to use small parts of what they have, they use an OpenGL wrapper for C# and they support Mono.

What kind of university allows projects with dutch code comments to pass? lol
« Last Edit: June 29, 2011, 01:46:12 AM by Maikel »

Offline Nyerguds

  • C&C1 H4x0r
  • Global Moderator
  • *
  • Posts: 3207
  • Green Forum Alien
    • View Profile
    • C&C95 Project 1.06
Re: TiberianSharp (formerly Luftballon) research thread
« Reply #29 on: June 29, 2011, 08:09:44 AM »
What kind of university allows projects with dutch code comments to pass? lol
Um, a Dutch-language university, duh. I live in Belgium. IIRC they specifically asked to make the code Dutch... most informatics teachers here are unfortunately people whose only knowledge of English comes from the programming. Their English pronunciation is usually pretty atrocious, too :P
« Last Edit: June 29, 2011, 08:14:41 AM by Nyerguds »