The XL Engine is and will remain free, donations are purely optional but greatly appreciated.

Recent Comments

I’ve been working feverishly on the Beta lately and have decided to take a step back and look and what’s been accomplished. While it’s hard to say, linearly, how far along things are – going through the code just doesn’t work that way – I can show a “map” of the code as seen so far.

For many of the files (21 of them) I know the actual name used, which I will provide. For other files, I don’t know the real name but do know about the functionality provided (to varying levels).

Numerical values shown are the first 3 numbers of the in-memory hex addresses – for example 0x16F4C7 “LoadCell()” would be shown as 16F. This is a high level map, so only file names are shown.

Start Address | Code File or Description
130 | main game loop (3D view) – file name unknown (yet)
132 | archive.c
134 | engsupp.c
13D | maploads.c
144 | career.c
147 | automap.c
155 | fs2df.c
15A | intro.c
15D | init.c
15D | text.c
166 | parse.c
16B | quests.c
16E | LoadCell and support – file name unknown (yet)
178 | char.c
18C | disk.c
192 | weapon.c
19B | loadsave.c
19C | support.c
1A0 | interface.c
1A5 | objlib.c
1A6 | maplogic.c
Files names below this point are unknown but functionality is.
1B0 | c-lib (malloc, free, fopen, fread, fclose, memset, rand,etc.)
1E0 | 3D rendering functionality
240 | mouse and font functionality

This includes sound support but I’ve re-written most of that already to support OpenAL.

I should also mention that most c-lib functions are not being written based off of the Daggerfall code – instead the modern equivalents are used (DOS based file system support, for example, isn’t very useful on Windows).

The major exception to this is rand() – since it must act exactly like vanilla Daggerfall, otherwise dungeon textures will be wrong. Yes, you read that right – here’s why:

word textureTableSrc[5]=	//0x28617C
{ 119, 120, 122, 123, 124 };
word textureTableCur[5];	//0x286186

void InitializeTextureTable()
	int r0 = rand();
	srand( curLocationRec->locationID>>16 );
	byte r = randByte();
	int r2 = _texRandTable[ r ];

	memcpy(textureTableCur, textureTableSrc, 10);
	for (int i=0; i<5; i++)
		byte n = random_range(0, 4);
		if ( n == 2 )
			n += 2;
		n += textureTableSrc[r2];
		textureTableCur[i] = n;



textureTableCur[] now contains texture file indices which are used to texture the various dungeon sections (modulo 5). As you can tell, if the random number generator is even slightly different, the dungeons will be textured completely differently. As it is, it works because the random number seed is based off the location ID – but note that the generator is re-seeded at the end so things like loot, random encounters, etc. are not affected by the locationID as well. :)

15 Responses to “Daggerfall Code Map”

  • Nevereverar:

    Its good to see how these things work. Most people in a similar position to you just gloss over the finer details of stuff like this. It gives a real sense that things are being accomplished.
    Good luck with all this texture business Lucius. You’re truly doing gods work

  • Boff:

    It’s easy to gloss over how things worked, and how you expect them to work.
    A modern day programmer will just giggle at a random number generator that doesn’t work to well.

    I remember programming some “basic” at school some years back and the random number, so so poorly seeded, you got the exact same sequence of numbers time and time again, irrespective of bootups.
    (Looking back I think there was a number of those “numbers from lost” involved)
    Some people might consider this a bug.
    Well looking into how they did stuff “in the old days”, For Elite’s star stystem, they use the same flawed random number technique to “generate” the same starmap time and time again.

    Glad to see you are still putting up the good fight for us all!

    • luciusDXL:

      Thanks. Though a proper psuedo-random number generator will always generate the same sequence from a given seed. The trick is to pick seed values such that you’re sequences are different when you want them to be. Anyway so what Bethesda did is completely sane – except for one thing… using the c-lib rand() function instead of their own – which isn’t guaranteed to perform exactly the same between different compilers. This would have been a major problem if they ever ported Daggerfall to Mac like LucasArts did for Dark Forces for example.

    • Al-Khwarizmi:

      This is totally off-topic, but actually that is not a bug of random number generators, it’s a feature!

      For example, suppose that you have an algorithm that uses random numbers and you want to make a regression test for it (i.e. a test to check that it is still working as intended after changing other parts of the program). To do that, it’s very convenient that rand() always generates the same sequence of numbers, that way you can check that the output of the algorithm is exactly the same after the changes and be sure that it was not affected.

      Another area where this is important is science. It is important that other people are able to reproduce your experiments.

      Of course, in a game (and outside of debugging purposes, or deliberate world sharing as is done in Brogue) it doesn’t make much sense to generate numbers in that way.

  • Thanks Lucius!! Please, keep posting news, as makes more interesting the wait for next Xlengine release (and dont forget to apply Oculus in that next release, im dying to wander on the beautiful dungeons of Dagggerfall in real 3d!!!!)

    • Dagganticipation:

      Oculus support would be amazing, though I’m not sure if this is a serious request or just a joke XD (most likely a joke)

    • luciusDXL:

      Occulus Rift support is planned but not for the next release. Right now the focus is only on getting the Beta done. :)

  • Michel Renier:

    I just wish you good luck, Lucius. It’s great to see the progress made.

    Yes, and a question – may be, i didn’t get it, but still – will every new save provide a new world (in a certain way)?

    • luciusDXL:

      Some things are randomized – such as quest locations (though there are many main quest locations that are fixed), loot, etc. But the actual environment and textures are always the same every time you start again. Loot and non-specific monster spawns are potentially different every time you enter a dungeon. Though some monster spawns will always be the same critter – which is why the humans in Privateer’s Hold can be different but the bats, rats, imps, skeletons,etc. are always the same. Anyway you get the idea. :)

  • daggeruser129:

    This is seriously awesome! I dream of the day I can see the (more-or-less) sourcecode to my favorite game. Does any one know how Lucius obtained the code? Purely reverse engineering from the disassembly of the original executable? Pretty amazing!

    Please consider open-sourcing this at some point, or allowing developers to collaborate you in a semi-open manner, Lucius! I’m a professional software engineer and would love to help, and I’m sure lots of others here would too!

    • luciusDXL:

      This is all from reverse engineering, I’ve never seen the actual source code unfortunately. :) However the code I generate is pretty close to the original (and identical in functionality) since it is derived from the compiled result. Of course variable and function names are different, though file names are accurate – except where I say I don’t know what the correct file name is yet of course. I will be releasing the code in the future.

  • Alex Freeman:

    I’m in awe of your ability to reverse engineer something as complicated as Daggerfall. Any tips on how to become as great at reverse engineering and programming as you?

    • Anon:

      Not luciusDXL but…

      Start small and practice everyday.

    • luciusDXL:

      Anon’s answer is about as good as I can give. :) I learned by a lot of reading and just trying things. My early attempts were terrible but I got better with every one.

    • Damanslaya:

      Also another good way to become a great programmer is to take classes and talk to people that have experience in programming and reverse engineering. “An investment in education pays the best interest” – Benjamin Franklin

Leave a Reply

The XL Engine is and will remain free, donations are purely optional but greatly appreciated.