<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[xoreos]]></title>
  <link href="https://xoreos.org/atom.xml" rel="self"/>
  <link href="https://xoreos.org/"/>
  <updated>2020-08-03T19:11:04+02:00</updated>
  <id>https://xoreos.org/</id>
  <author>
    <name><![CDATA[xoreos]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[xoreos 0.0.6 "Elanee" Released]]></title>
    <link href="https://xoreos.org/blog/2020/08/03/xoreos-0-dot-0-6-elanee-released/"/>
    <updated>2020-08-03T15:00:00+02:00</updated>
    <id>https://xoreos.org/blog/2020/08/03/xoreos-0-dot-0-6-elanee-released</id>
    <content type="html"><![CDATA[<p>As a belated 10th birthday (yes, xoreos is 10 years old now), here&rsquo;s a new release of xoreos! It&rsquo;s xoreos 0.0.6, nicknamed &ldquo;Elanee&rdquo;, including <a href="https://github.com/xoreos/xoreos/releases/tag/v0.0.6">xoreos</a>, <a href="https://github.com/xoreos/xoreos-tools/releases/tag/v0.0.6">xoreos-tools</a> and <a href="https://github.com/xoreos/phaethon/releases/tag/v0.0.6">Phaethon</a>.</p>

<p>In xoreos proper, the most visible change is in <em>Knights of the Old Republic</em>: <a href="https://github.com/seedhartha">seedhartha</a> has put a lot of work into making the tutorial partially playable! The player character can collect their belongings, put on their gear, let Trask open the first door, open the second door and engage in mock combat.</p>

<p>You can see it in action in this video here:</p>

<p style="text-align:center;"> <iframe width="640" height="360" src="https://www.youtube.com/embed/oxNPYHSE60A" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>

<p>Under the hood, the code for <em>Knights of the Old Republic</em> and <em>Knights of the Old Republic II</em> was fundamentally restructured to build off a common base, so a lot of the underlying concepts in the first game are also available in the second, but are not as visible. You can, however, skip the prologue in <em>Knights of the Old Republic II</em> to watch your player character awaken in the Peragus mining facility and trigger a few early interactions.</p>

<p>Watch it in this video here:</p>

<p style="text-align:center;"> <iframe width="640" height="360" src="https://www.youtube.com/embed/Njjs7ukE1_c" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>

<p>The only other game where something has happened visibly is <em>Jade Empire</em>: you can now run through a preliminary character generation and listen to area background music.</p>

<p>User-invisible changes include:</p>

<ul>
<li>Partial implementations of ActionScript and Scaleform GFx for <em>Dragon Age</em> menus, thanks to <a href="https://github.com/Nostritius">Nostritius</a></li>
<li>Partial implementations of XACT WaveBanks and SoundBanks for <em>Jade Empire</em></li>
<li>Partial implementations of FMOD SampleBanks and Events for <em>Dragon Age: Origins</em>, the latter thanks to <a href="https://github.com/Nostritius">Nostritius</a></li>
<li>Partial implementations of Wwise SoundBanks for <em>Dragon Age II</em></li>
<li>WebM (Matroska + VPx) support for the Enhanced Edition of <em>Neverwinter Nights</em>, thanks to <a href="https://github.com/clone2727">clone2727</a></li>
<li>Support for big-endian GFF4 files found in console ports</li>
<li>Support for resource files found in mobile ports</li>
<li>Support for more <em>Neverwinter Nights 2</em> structures, thanks to <a href="https://github.com/rjshae">rjshae</a></li>
</ul>


<p style="text-align:center;"> <iframe width="640" height="360" src="https://www.youtube.com/embed/9OmHLipK8Sw" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>

<p>xoreos and xoreos-tools now require a C++11-capable compiler, in an attempt to modernize a bit. This should hopefully not be a huge problem. Phaethon already required a C++14-capable compiler the last release; this has not changed.</p>

<p>This leads us to the news in xoreos-tools: the xoreos-tools package has gained nine new tools, most of them thanks to <a href="https://github.com/Nostritius">Nostritius</a>. These tools are: unobb, untws, rim, keybif, tws, fixnwn2xml, xml2gff, fev2xml and ncsdecomp.</p>

<p>The first two new tools, unobb and untws, are new archive unpackers. unobb extracts &ldquo;obb&rdquo; files found in Aspyr&rsquo;s Android and iOS ports of the BioWare games, which can be either plain ZIP files or, more interesting, a virtual filesystem. untws extracts save files from <em>The Witcher</em>.</p>

<p>The next three tools, rim, keybif and tws are archive packers. rim is the counterpart to unrim, creating RIM archives. keybif is the counterpart to unkeybif, creating KEY/BIF archives (and lzma-compressed KEY/BZF archives found in Aspyr&rsquo;s mobile ports). However, V1.1 files for <em>The Witcher</em> are not yet supported. And lastly, tws, is the counterpart to the new untws tool, creating save files for The <em>Witcher</em>.</p>

<p>Next up, fixnwn2xml takes the non-standard XML files in <em>Neverwinter Nights 2</em> and turns them into valid, standards-compliant XML files. This tool is thanks to <a href="https://github.com/rjshae">rjshae</a>, based on <a href="https://github.com/asr1">asr1</a>&rsquo;s work, reworking it to fit better into our stream classes.</p>

<p>xml2gff is the counterpart to gff2xml, taking an XML file and turning it back into a GFF. Only GFF3 (GFF V3.2/V3.3) are supported for now, so neither <em>Sonic Chronicles: The Dark Brotherhood</em> nor the <em>Dragon Age</em> games (which use GFF V4.0/V4.1) are supported at the moment.</p>

<p>Another work-in-progress tool is fev2xml, which reads the FMOD event file format FEV and creates a human-readable XML file. Only the FEV1 version is supported and then only a fraction of its features.</p>

<p>Likewise, ncsdecomp is the start of an NWScript bytecode decompiler, built on the foundations of our NWScript bytecode disassembler. It&rsquo;s highly experimental and we give no guarantees that it works correctly at all.</p>

<p>In addition to these new tools, there are some new minor features and bugfixes:</p>

<ul>
<li>unerf can now extract ERF V2.1</li>
<li>erf can now create ERF V2.0 and V2.2</li>
<li>xoreostex2tga now supports animated TPCs and swizzled Xbox SBMs</li>
<li>gff2xml now supports SAC files and big-endian GFF4s</li>
<li>tlk2xml now supports big-endian GFF4s</li>
<li>The character encoding matrix for <em>Jade Empire</em> is now correct</li>
</ul>


<p>As for Phaethon, the 0.0.6 version of Phaethon is mostly a &ldquo;maintenance release&rdquo;, keeping the foundation in sync with xoreos. There are no major new features. There are, however, a number of smaller bug fixes. Also, Phaethon can now open ERF V2.1 files and display swizzled Xbox SBM images. Additionally, BIF files can be inspected directly, even when no corresponding KEY file can be found (this does mean, though, that the filenames are missing).</p>

<p>To sum it all up: xoreos inched a bit further along, gained more initial implementations useful later on and xoreos-tools hopefully increased its usefulness for modders and spelunkers. Still a lot more to do, a long way to go. But we are, after all, in for the long ride. :)</p>

<p>Sources and binaries for Windows, GNU/Linux and macOS are attached to the GitHub release, <a href="https://github.com/xoreos/xoreos/releases/tag/v0.0.6">here for xoreos</a>, <a href="https://github.com/xoreos/xoreos-tools/releases/tag/v0.0.6">here for xoreos-tools</a> and <a href="https://github.com/xoreos/phaethon/releases/tag/v0.0.6">here for Phaethon</a>.</p>

<p>Additionally, the repository and the source tarballs contain PKGBUILD files in dists/arch/, debian build directories in dists/debian/ and spec files in dists/fedora, which can be used to build Arch Linux, Debian/Ubuntu and Fedora packages, respectively. Alternatively, the PKGBUILD files are also in Arch Linux’s AUR (<a href="https://aur.archlinux.org/packages/xoreos/">here for xoreos</a>, <a href="https://aur.archlinux.org/packages/xoreos-tools/">here for xoreos-tools</a>, <a href="https://aur.archlinux.org/packages/phaethon/">here for Phaethon</a>), and we have a <a href="https://github.com/xoreos/gentoo-overlay">Gentoo overlay</a>.</p>

<p>And as always, we’re looking for more developers to join us in our efforts to reimplement those 3D BioWare RPGs. If <em>you</em> would like to help, please feel free to <a href="https://wiki.xoreos.org/index.php?title=Contact_us">contact us</a>. :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Not-Thanksgiving 2018]]></title>
    <link href="https://xoreos.org/blog/2018/11/26/not-thanksgiving-2018/"/>
    <updated>2018-11-26T22:49:00+01:00</updated>
    <id>https://xoreos.org/blog/2018/11/26/not-thanksgiving-2018</id>
    <content type="html"><![CDATA[<p>Another year nears its end. <a href="https://xoreos.org/blog/2018/07/03/xoreos-0-dot-0-5-dawn-star-released/">After unfortunately skipping last year&rsquo;s Not-Thanksgiving post</a>, we are, back to our regular yearly retrospection. For people new to xoreos: this series is a kind of introspective look into what happened with the xoreos project over the past year. I&rsquo;m not in the USA, so I don&rsquo;t observe Thanksgiving, but nevertheless, I do want to give thanks to all the great people working with me on xoreos, and supporting us in other ways.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20181125_malak.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20181125_malak_t.png' width='256' height='192' title='KotOR main menu with Darth Malak' alt='KotOR main menu with Darth Malak'><span class='caption-text'>KotOR main menu with Darth Malak</span></span></a></p>

<p>I already wrote <a href="https://xoreos.org/blog/2018/07/03/xoreos-0-dot-0-5-dawn-star-released/">a combination introspective and release post back in July</a>, which gave some updates since the previous <a href="https://xoreos.org/blog/2016/11/24/not-thanksgiving-2016/">Not-Thanksgiving post in 2016</a>, so let&rsquo;s see what happened since then:</p>

<ul>
<li>After the release, I took a look at the different kind of &ldquo;wavebanks&rdquo; xoreos-supported games use, and implemented loaders for those. A wavebank is a collection of sound files packed into an archive, indexed by either a numerical or string ID. We have:

<ul>
<li><a href="https://github.com/xoreos/xoreos/blob/master/src/sound/xactwavebank.h">XACT WaveBank</a>, used by Jade Empire. There&rsquo;s two versions, <a href="https://github.com/xoreos/xoreos/blob/master/src/sound/xactwavebank_binary.cpp">a binary one</a> (the original format, I assume) in the Xbox version, and <a href="https://github.com/xoreos/xoreos/blob/master/src/sound/xactwavebank_ascii.cpp">an ASCII one</a> in the Windows version.</li>
<li><a href="https://github.com/xoreos/xoreos/blob/master/src/sound/fmodsamplebank.h">FMOD SampleBank</a>, used in Dragon Age: Origins.</li>
<li><a href="https://github.com/xoreos/xoreos/blob/master/src/sound/wwisesoundbank.h">Wwise SoundBank</a>, used in Dragon Age II.</li>
</ul>
</li>
<li>However, &ldquo;wavebanks&rdquo; are just one part of the coin. They&rsquo;re used together with sound and event definitions, which tell you <em>how</em> to play the waves in the wavebank, including looping, sequencing and filters. These are still mostly missing. <a href="https://github.com/xoreos/xoreos/pull/362">Nostritius has started</a> <a href="https://github.com/xoreos/xoreos/pull/367">looking at FMOD Event files, FEV</a>, though.</li>
<li>Next, I looked at the Android versions of Knights of the Old Republic and Jade Empire. I found that they contain packed data in archives. I added <a href="https://github.com/xoreos/xoreos-tools/blob/master/src/unobb.cpp">a tool to xoreos-tools, unobb</a>, that can extract these. I also added probes for the extracted data files to xoreos.</li>
<li>Nostritius also <a href="https://github.com/xoreos/xoreos/pull/337">added a probe for the Xbox version of Dragon Age: Origins</a>, and we added support for its data file differences.

<ul>
<li>For the Xbox version of Dragon Age II, <a href="https://github.com/xoreos/xoreos/issues/335">we&rsquo;re still missing information on its ERF compression</a>.</li>
</ul>
</li>
<li>seedhartha, in the mean time, <a href="https://github.com/xoreos/xoreos/pull/341">restructured the engine code to store object references in scripts and containers as IDs</a>, instead of plain pointers. This is necessary to correctly implement the DestroyObject script function, for example, without accidentally accessing the objects afterwards.</li>
<li>Nostritius notified me that I had the wrong string encoding table set up for Jade Empire. <a href="https://github.com/xoreos/xoreos/commit/9e991c76d">We fixed that</a>. Now non-English versions of Jade Empire should work correctly.</li>
<li>Nostritius also <a href="https://github.com/xoreos/xoreos/pull/319">made Malak appear in the KotOR menu</a>, and implemented <a href="https://github.com/xoreos/xoreos/pull/312">GUI scaling for KotOR</a> <a href="https://github.com/xoreos/xoreos/pull/374">and KotOR2</a>.</li>
<li>Nostritius wrote several new tools for xoreos-tools: a <a href="https://github.com/xoreos/xoreos-tools/pull/25">packer and unpacker for The Witcher save files</a>, a <a href="https://github.com/xoreos/xoreos-tools/pull/26">KEY/BIF packer</a>, and a <a href="https://github.com/xoreos/xoreos-tools/pull/27">xml2gff tool</a> (which means he had to write a <a href="https://github.com/xoreos/xoreos/pull/300">GFF3 writer</a>, which will be very useful in the future).</li>
<li>I bumped the C++ version for xoreos-tools to C++11. This is kind of a test run for xoreos proper. In the future, I plan to C++11-ify the codebase quite a bit.</li>
<li>rjshae took <a href="https://github.com/xoreos/xoreos-tools/pull/1">asr1 WIP code</a> to fix the non-standard XML files NWN2 uses for its GUI <a href="https://github.com/xoreos/xoreos-tools/pull/24">and brought it up to speed</a>. This means the way to implement the NWN2 GUI is now clear(er).</li>
<li>rjshae also <a href="https://github.com/xoreos/xoreos/pull/372">fixed up our common trap/trigger code</a>, and <a href="https://github.com/xoreos/xoreos/pull/377">partially implemented triggers for NWN2</a>.</li>
<li>Nostritius started implementing support for the <a href="https://github.com/xoreos/xoreos/pull/294">Flash-based</a> <a href="https://github.com/xoreos/xoreos/pull/373">ScaleForm GFx</a>, which the two Dragon Age games use for their GUI.</li>
<li>seedhartha took mirv&rsquo;s WIP shader-based renderer and <a href="https://github.com/xoreos/xoreos/pull/381">turned it into a clean PR</a>, which I then merged. This means, mirv can now continue working on the new renderer in-tree, with hopefully smaller, more easily reviewable PRs to come.</li>
<li>Finally, clone2727 reorganized our <a href="https://github.com/xoreos/xoreos/compare/d9d2c3f87e20cbe95d98fcb33dc7ff31ef79e92d%5E...9bc09deee719121ddd064a6534f0c6018e276416">audio</a> and <a href="https://github.com/xoreos/xoreos/compare/cc67f12b36b6f34445a62e1959c244e9fac77b38%5E...25975d5e44e6445f0146e1f54d38f86f2a1fd620">video decoding code</a>.</li>
</ul>


<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20181125_dao.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20181125_dao_t.png' width='256' height='201' title='WIP Dragon Age: Origins main menu' alt='WIP Dragon Age: Origins main menu'><span class='caption-text'>WIP Dragon Age: Origins main menu</span></span></a></p>

<p>Quite a lot, right? :)</p>

<p>Of course, there&rsquo;s still things in progress, among them:</p>

<ul>
<li>mirv is continuing work on the new renderer.</li>
<li>Supermanu is <a href="https://github.com/xoreos/xoreos/pull/211">working on pathfinding</a>.</li>
<li>Nostritius is furthering our ScaleForm GFx reimplementation.</li>
</ul>


<p>xoreos wouldn&rsquo;t be what it is without the help of a lot of great people, for whom I am thankful.</p>

<ul>
<li><a href="https://github.com/rjshae">rjshae</a>, for taking up work on NWN2 in xoreos.</li>
<li><a href="https://github.com/asr1">asr1</a>, for starting the NWN2 XML fixer, that&rsquo;s now in xoreos-tools.</li>
<li><a href="https://github.com/seedhartha">seedhartha</a>, for working on KotOR and getting the renderer rewrite mergeable.</li>
<li><a href="https://github.com/mirv-sillyfish">mirv</a>, for doing the renderer rewrite in the first place.</li>
<li><a href="https://github.com/Nostritius">Nostritius</a>, for doing a heck of a lot of different things in xoreos.</li>
<li><a href="https://github.com/clone2727">clone2727</a>, for keeping me grounded.</li>
<li><a href="http://aluigi.altervista.org/">Luigi Auiremma</a>, for all his research and tools.</li>
<li><a href="https://github.com/Supermanu">Supermanu</a>, for his pathfinding work.</li>
<li><a href="https://github.com/Farmboy0">Farmboy0</a>, for his help and advice.</li>
<li>The people at <a href="https://www.gamingonlinux.com/">GamingOnLinux</a>, a great community for, well, Gaming on Linux.</li>
<li>Linux porters like <a href="http://flibitijibibo.com/">flibitijibibo</a>, <a href="https://icculus.org/">icculus</a> and <a href="https://cheeseness.itch.io/">Cheeseness</a>, for providing this much-needed service and also being all-around good people.</li>
<li>A myriads of other people I probably forgot, because I&rsquo;m bad at remembering.</li>
</ul>


<p>Hopefully, the future will bring even more movement into this little project. If <em>you</em> would like to help with that, then please, feel free to <a href="https://wiki.xoreos.org/index.php?title=Contact_us">contact us</a>! :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[xoreos 0.0.5 "Dawn Star" Released]]></title>
    <link href="https://xoreos.org/blog/2018/07/03/xoreos-0-dot-0-5-dawn-star-released/"/>
    <updated>2018-07-03T16:50:00+02:00</updated>
    <id>https://xoreos.org/blog/2018/07/03/xoreos-0-dot-0-5-dawn-star-released</id>
    <content type="html"><![CDATA[<p>Fashionably (?) late, but still finally there, a new release of xoreos arrives! xoreos 0.0.5, nicknamed &ldquo;Dawn Star&rdquo;, coming with <a href="https://github.com/xoreos/xoreos/releases/tag/v0.0.5">xoreos</a>, <a href="https://github.com/xoreos/xoreos-tools/releases/tag/v0.0.5">xoreos-tools</a> and for the first time, <a href="https://github.com/xoreos/phaethon/releases/tag/v0.0.5">Phaethon</a>, an in-progress graphical resource explorer.</p>

<p>A lot has happened in the last two years. A busy real life unfortunately made me miss the yearly &ldquo;Not-Thanksgiving&rdquo; progress report last year&hellip;so this here will be a kind of combination release post and progress report. Buckle up, this will be a long one. If you&rsquo;re only interested in the short release notes, move on to the GitHub release pages linked above and again at the bottom of the post. Cool? Cool.</p>

<p>So, continuing from <a href="https://xoreos.org/blog/2016/11/24/not-thanksgiving-2016/">the last progress report in 2016</a>, what exactly has happened?</p>

<p>Back then, I said I was working on unit tests for xoreos, planning to make them public in December. <a href="https://github.com/xoreos/xoreos/pull/133">I did that</a>, and then merged them in February 2017. Since then, several more have been added and bugs were found (and prevented) with them. I consider them a huge success and a boon to the codebase. However, the coverage is nowhere near 100%. <a href="https://github.com/xoreos/xoreos/pulls">Pull requests</a> adding new unit tests to existing code are always welcome ;).</p>

<p>Soon after, I took another stab at one variant of the texture format in <em>Jade Empire</em>, used for lightmaps. I had previously tried to figure it out, but failed. But with the added knowledge of the textures in the Xbox version of <em>Knights of the Old Republic</em>, which are swizzled [*], I realized that the lightmaps in <em>Jade Empire</em> are also swizzled. They&rsquo;re even swizzled in the same way, so I could just reuse the deswizzling code, and voilà, now that texture variant is correctly read.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20180703_texture_swizzled.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20180703_texture_swizzled.png' width='128' height='128' title='Swizzled texture' alt='Swizzled texture'><span class='caption-text'>Swizzled texture</span></span></a> <a href="https://xoreos.org/images/blog/20180703_texture_deswizzled.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20180703_texture_deswizzled.png' width='128' height='128' title='Deswizzled texture' alt='Deswizzled texture'><span class='caption-text'>Deswizzled texture</span></span></a></p>

<p>([*] Swizzling changes how the pixels of the image are stored. Usually, pixels are stored linearly, from left to right, from top to bottom. This is not necessarily ideal for GPUs, though, because GPUs like it when things that are displayed near each other are also stored near each other (<a href="https://en.wikipedia.org/wiki/Locality_of_reference">spacial locality</a>). And while the pixels left and right of a pixel are near each other, the pixels above and below are not. Therefore, swizzled textures store pixels in a sort of zig-zag order. The <a href="https://en.wikipedia.org/wiki/Z-order_curve">Z-order curve</a> is a popular scheme for that.)</p>

<p>Next up, Farmboy0 and Nostritius both worked on the GUI systems in <em>Jade Empire</em> and the two <em>Knights of the Old Republic</em> games. <em>Jade Empire</em> now has a partially working main menu (with dressupgeekout submitting pull requests to <a href="https://github.com/xoreos/xoreos/pull/277">make the &ldquo;Exit&rdquo; button work</a> and <a href="https://github.com/xoreos/xoreos/pull/272">enabling background music</a>), and the <em>Knights of the Old Republic</em> games gained character creators and partial in-game menus.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20180703_jade_menu.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20180703_jade_menu_t.png' width='256' height='192' title='Jade Empire main menu' alt='Jade Empire main menu'><span class='caption-text'>Jade Empire main menu</span></span></a> <a href="https://xoreos.org/images/blog/20180703_kotor_chargen.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20180703_kotor_chargen_t.png' width='256' height='192' title='KotOR character generator' alt='KotOR character generator'><span class='caption-text'>KotOR character generator</span></span></a> <a href="https://xoreos.org/images/blog/20180703_kotor2_chargen.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20180703_kotor2_chargen_t.png' width='256' height='192' title='KotOR2 character generator' alt='KotOR2 character generator'><span class='caption-text'>KotOR2 character generator</span></span></a></p>

<p>Speaking of <em>Knights of the Old Republic</em>, these two games are progressing quite a bit, thanks to seedhartha. They now have a fully working animation system, PC movement (with walkmesh evaluation based on <a href="https://github.com/xoreos/xoreos/pull/211">Supermanu&rsquo;s work</a>) and even initial dialogues. In fact, the first game already shows a semblance of the first few minutes of tutorial on the Endar Spire, with your bunk mate telling you grab your gear from a chest and equip it.</p>

<p style="text-align:center;"> <iframe width="640" height="480" src="https://www.youtube.com/embed/gh7shS90wSw" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>

<p>For the <em>Dragon Age</em> games, Nostritius implemented an <a href="https://en.wikipedia.org/wiki/ActionScript">ActionScript</a> interpreter. Together with a renderer for <a href="https://en.wikipedia.org/wiki/Adobe_Flash">Adobe Flash</a> vector graphics (still work in progress), this will be a reimplementation of <a href="https://en.wikipedia.org/wiki/Scaleform_GFx">Scaleform GFx</a>. Scaleform GFx is used for the user interface, like menus and quickbars, in <em>Dragon Age: Origins</em> and <em>Dragon Age II</em>. Note that the vector renderer is not yet in the public xoreos codebase and that the screenshot below is more of a proof of concept.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20180703_dao_flash.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20180703_dao_flash_t.png' width='256' height='201' title='Dragon Age: Origins main menu (WIP)' alt='Dragon Age: Origins main menu (WIP)'><span class='caption-text'>Dragon Age: Origins main menu (WIP)</span></span></a></p>

<p>On the xoreos-tools side of things, I added two new tools, ssf2xml and xml2ssf. ssf2xml takes a sound set file (SSF), as used by the two <em>Neverwinter Nights</em> and the two <em>Knights of the Old Republic</em> games and converts it into a human-readable XML file. xml2ssf is the counterpart, taking an XML file and converting it back into a game-readable SSF file.</p>

<p>Nostritius then added a third new tools, erf, <a href="https://github.com/xoreos/xoreos-tools/pull/19">an ERF packer</a>. It is the counterpart to the already existing unerf tool. Where unerf extracts files from ERF archives, erf takes files and creates a new ERF archive. Unlike the unerf tool, erf currently only supports version V1.0 of the ERF format, as used by <em>Neverwinter Nights</em>, the two <em>Knights of the Old Republic</em> games. <em>Jade Empire</em> and <em>The Witcher</em>.</p>

<p>Also on xoreos-tools, cosmo-ray <a href="https://github.com/xoreos/xoreos-tools/pull/8">unified the parameter handling</a>. This massively cuts down on code duplication in the tools and removes a potential source of mistakes.</p>

<p>Moving on to the third package, Phaethon. Phaethon is a graphical resource explorer, able to look into the archives found in the BioWare Aurora games and display several different types of resources. Previous xoreos releases didn&rsquo;t mention it, but it has existed for several years already now. Of course, it&rsquo;s still far from finished and could use more contributors.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20180703_phaethon.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20180703_phaethon_t.png' width='256' height='196' title='Phaethon' alt='Phaethon'><span class='caption-text'>Phaethon</span></span></a></p>

<p>In the past, Phaethon used the wxWidgets libraries for the GUI. But I was never really happy with it; I never managed to get widget placement to work consistently across platforms (or even just across different window managers on Linux). I always hoped to rewrite it in Qt some day. Therefore, I was really quite happy that michaelpm54 <a href="https://github.com/xoreos/phaethon/pull/7">did that work for me</a>, rewriting Phaethon to use Qt5.</p>

<p>I&rsquo;m now far more comfortable providing Phaethon release packages along with xoreos and xoreos-tools. However, due to us using <a href="https://woboq.com/blog/verdigris-qt-without-moc.html">Verdigris</a> to compile Qt5 applications without moc, Phaethon now requires a C++14-capable compiler. My local cross-compilers, the ones I use to create the binary release packages for Windows and macOS (and the chroot I use to build the Linux packages), didn&rsquo;t have that.  Consequently, I had to update my cross-compilers and chroot.</p>

<p>I did that, and now I can create working binary packages for Phaethon on these operating systems. And this also opens up a path to let C++11 features into the xoreos codebases in the future, something which I had been thinking about for a while now (currently, apart from Verdigris in Phaethon, all of the xoreos codebases are C++03-compliant).</p>

<p style="text-align:center;"> <iframe width="640" height="360" src="https://www.youtube.com/embed/vInkatsPTB0" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>

<p>On the other hand, also on the packages front, I dropped the openSUSE Build Service (OBS), the service that builds binary packages for a number of Linux distributions. I simply do not have enough time to keep the build specifications there up-to-date. Especially since every time a new distribution release is added, it requires me to invest several days worth of work to get them to build. Anybody willing to take over that task and officially administrate the xoreos OBS specs, please <a href="https://wiki.xoreos.org/index.php?title=Contact_us">contact us</a>.</p>

<p>Last but not least, there were also, of course, a lot of code quality improvements. Many of which were triggered by the introduction of new compiler warnings flags, new compiler instrumentations and static analyzers. I&rsquo;m really grateful for all the options I have for checking the xoreos codebase, grateful for all the amount of work done by the gcc and clang/llvm people, and all the services offering free access to FLOSS projects.</p>

<p>And that&rsquo;s about it for the past two years. Many improvements, but also still many things left to do. There&rsquo;s several things cooking, but I&rsquo;d rather not jinx them ;). In either case, I&rsquo;ll try getting out the next release relatively sooner.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20180703_kotor_bastila.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20180703_kotor_bastila_t.png' width='256' height='192' title='Meeting Bastila in KotOR' alt='Meeting Bastila in KotOR'><span class='caption-text'>Meeting Bastila in KotOR</span></span></a> <a href="https://xoreos.org/images/blog/20180703_kotor2_handmaidens.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20180703_kotor2_handmaidens_t.png' width='256' height='192' title='Meeting the Handmaidens in KotOR2' alt='Meeting the Handmaidens in KotOR2'><span class='caption-text'>Meeting the Handmaidens in KotOR2</span></span></a></p>

<p>Sources and binaries for Windows, GNU/Linux and macOS are attached to the GitHub release, <a href="https://github.com/xoreos/xoreos/releases/tag/v0.0.5">here for xoreos</a>, <a href="https://github.com/xoreos/xoreos-tools/releases/tag/v0.0.5">here for xoreos-tools</a> and <a href="https://github.com/xoreos/phaethon/releases/tag/v0.0.5">here for Phaethon</a>.</p>

<p>Additionally, the repository and the source tarballs contain PKGBUILD files in dists/arch/, debian build directories in dists/debian/ and spec files in dists/fedora, which can be used to build Arch Linux, Debian/Ubuntu  and Fedora packages, respectively. Alternatively, the PKGBUILD files are also in Arch Linux&rsquo;s AUR (<a href="https://aur.archlinux.org/packages/xoreos/">here for xoreos</a>, <a href="https://aur.archlinux.org/packages/xoreos-tools/">here for xoreos-tools</a>, <a href="https://aur.archlinux.org/packages/phaethon/">here for Phaethon</a>, and we have a <a href="https://github.com/xoreos/gentoo-overlay">Gentoo overlay</a>.</p>

<p>And as always, we&rsquo;re looking for more developers to join us in our efforts to reimplement those 3D BioWare RPGs. If <em>you</em> would like to help, please feel free to <a href="https://wiki.xoreos.org/index.php?title=Contact_us">contact us</a>. :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Not-Thanksgiving 2016]]></title>
    <link href="https://xoreos.org/blog/2016/11/24/not-thanksgiving-2016/"/>
    <updated>2016-11-24T17:30:00+01:00</updated>
    <id>https://xoreos.org/blog/2016/11/24/not-thanksgiving-2016</id>
    <content type="html"><![CDATA[<p>And again a year is nearing its end. Like <a href="https://xoreos.org/blog/2015/11/27/not-thanksgiving-2015/">last year</a> and <a href="https://xoreos.org/blog/2014/11/29/not-thanksgiving/">the year before</a>, I&rsquo;d like to turn my gaze inwards.</p>

<p>A lot of things happened with xoreos this past year, albeit most of them hidden and &ldquo;under the hood&rdquo;:</p>

<ul>
<li>I wrote about <a href="https://xoreos.org/blog/2016/01/12/disassembling-nwscript-bytecode/">disassembling NWScript bytecode</a>. The tasks I mentioned there are still open, too. If anybody wants to take them up, I&rsquo;d be happy to explain them in more detail :).</li>
<li>We <a href="https://xoreos.org/blog/2016/02/01/xoreos-0-dot-0-4-chodo-released/">released xoreos 0.0.4, nicknamed &ldquo;Chodo&rdquo;</a>. That was the only release of xoreos in 2016. xoreos 0.0.4 included some minor fixes and features for <em>Neverwinter Nights</em>, and the xoreos-tools package included the new NWScript disassembler.</li>
<li>In April, I reached a streak of a full year of daily xoreos commits. Due to some real life things, I had to take a break there, though. I&rsquo;m now again at three months of daily commits, but there is a three-month &ldquo;hole&rdquo; between April and August.</li>
</ul>


<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20161124_github1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20161124_github1.png' width='730' height='280' title='GitHub contribution graph in April' alt='GitHub contribution graph in April'><span class='caption-text'>GitHub contribution graph in April</span></span></a></p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20161124_github2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20161124_github2.png' width='730' height='192' title='GitHub contribution graph in November' alt='GitHub contribution graph in November'><span class='caption-text'>GitHub contribution graph in November</span></span></a></p>

<ul>
<li>Farmboy0 fleshed out the <em>Jade Empire</em> engine a bit, mostly in the scripts department.</li>
<li><a href="https://github.com/xoreos/xoreos/commits?author=Supermanu">Supermanu implemented a huge chunk of the character generator</a> for <em>Neverwinter Nights</em>.</li>
<li><a href="https://github.com/xoreos/xoreos/pull/125">Farmboy0 fixed a glitch in the <em>Neverwinter Nights</em> animation system</a> that has plagued xoreos for quite some time: the animation scaling in various creature models was off. This lead to, for example, the head and arms of elves detaching from the body during the yawn animation.</li>
<li>I then implemented a few more animation script functions, too, which is especially noticeable in the intro animation for Hordes of the Underdark. I also fixed a mistake in the keyframe interpolation. This takes care of another glitch in <em>Neverwinter Nights</em>: model nodes rotating the wrong way around.</li>
<li><a href="https://github.com/xoreos/xoreos/pull/127">smbas added support for Lua scripts in <em>The Witcher</em></a>. A lot of the initialization code that sets up the classes and functions <em>The Witcher</em> expects to find is still missing, so nothing obvious is visible as of yet.</li>
<li><a href="https://github.com/xoreos/xoreos/pull/121">Farmboy0 moved the window handling from the GraphicsManager into a new WindowManager class</a>, making the code more readable.</li>
<li><a href="https://github.com/xoreos/xoreos/pull/128">I fundamentally restructured our build system</a>, or at least the autotools part of it (xoreos can be built using either autotools or CMake). Previously, we used a recursive autotools setup, where make recurses into each subdirectory. This is, unfortunately, pretty slow, among other drawbacks. I changed it to be non-recursive now, with the top-level Makefile instead being created using (recursive) includes.</li>
<li>I then introduced various smart pointer templates into the codebase, making it easier to read and easier to keep track of memory allocations.</li>
<li><a href="https://github.com/xoreos/xoreos/pull/129">berenm added AppVeyor integration</a>. Like <a href="https://travis-ci.org/">Travis CI</a> (which we already use as well), <a href="https://www.appveyor.com/">AppVeyor</a> is a <a href="https://en.wikipedia.org/wiki/Continuous_integration">continuous integration</a> service. This means that every single commit to the public xoreos repository will now be built on Microsoft Windows, using Microsoft Visual Studio 2015, in addition to gcc and clang on GNU/Linux (via Travis CI). This ensures that any compilation breakage on these systems is immediately visible and can be fixed at once.</li>
<li><a href="https://github.com/blog/2256-a-whole-new-github-universe-announcing-new-tools-forums-and-features">GitHub added a new feature, &ldquo;Projects&rdquo;</a>, that provide Kanban-like boards of tasks. I took the time to fill the <a href="https://github.com/orgs/xoreos/projects">xoreos Projects page</a> with boards for tasks from our TODO list.</li>
<li>There were of course also various clean-ups, minor fixes and expanded code documentation.</li>
</ul>


<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20161124_nwn1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20161124_nwn1_t.png' width='256' height='170' title='Animation with glitch' alt='Animation with glitch'><span class='caption-text'>Animation with glitch</span></span></a> <a href="https://xoreos.org/images/blog/20161124_nwn2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20161124_nwn2_t.png' width='256' height='170' title='Animation without glitch' alt='Animation without glitch'><span class='caption-text'>Animation without glitch</span></span></a> <a href="https://xoreos.org/images/blog/20161124_nwn3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20161124_nwn3_t.png' width='256' height='170' title='Animations in the HotU intro' alt='Animations in the HotU intro'><span class='caption-text'>Animations in the HotU intro</span></span></a></p>

<p>Additionally, there are several tasks currently being worked on, among them:</p>

<ul>
<li><a href="https://twitter.com/mtondeur42/status/793465750589759492">Supermanu is looking into pathfinding</a>.</li>
<li>mirv is still working on rewriting the OpenGL renderer.</li>
<li>I am currently writing unit tests for the xoreos codebase, using <a href="https://github.com/google/googletest">Google Test</a>. I already found multiple issues, bugs, and corner cases while adding them.</li>
</ul>


<p>From my side of things, my current plan is to make my unit tests branch public some time in December. I&rsquo;ll write a small announcement here about it then. A new release of xoreos, 0.0.5, should follow early next year.</p>

<p>As always, this all wouldn&rsquo;t have been possible without a lot of people. For them I am thankful.</p>

<ul>
<li><a href="https://github.com/farmboy0">Farmboy0</a>, for various fixes, implementations and file format spelunking.</li>
<li><a href="https://github.com/Supermanu">Supermanu</a>, for his character generator work and pathfinding research.</li>
<li><a href="https://github.com/mirv-sillyfish">mirv</a>, for continuing to work on the OpenGL rewrite.</li>
<li><a href="https://github.com/smbas">smbas</a>, for his work on Lua and <em>The Witcher</em>.</li>
<li><a href="https://github.com/berenm">berenm</a>, for the AppVeyor integration and CMake knowledge.</li>
<li><a href="https://github.com/TC01">TC01</a>, for writing a Fedora specfile for the xoreos projects.</li>
<li><a href="https://github.com/CromFr">CromFr</a>, for taking a stab at the <a href="https://gist.github.com/CromFr/104bac52dc9191099d9d9e3dbd2c4975">walkmesh structure in NWN2&rsquo;s TRN files</a>.</li>
<li><a href="https://github.com/clone2727">clone2727</a>, for invaluable ideas and corrections.</li>
<li>The folks at <a href="https://www.gamingonlinux.com/">GamingOnLinux</a>, who continue to be a great resource for all things related to Games on Linux.</li>
</ul>


<p>I am also thankful for all the people who take the time to explain things to others, people who write interesting, useful or needed articles, and people who provide mentoring and help. Relatedly: a week ago, Stephanie Hurlburt published <a href="http://stephaniehurlburt.com/blog/2016/11/14/list-of-engineers-willing-to-mentor-you">an article with engineers who are willing to mentor or answer programming/engineering questions</a>. I for one think that&rsquo;s a really great idea. Please take a look at that article.</p>

<p>And now, let&rsquo;s see what the next year has in store for us. If <em>you</em>, however, found all this terribly interesting and would like to help with our little project, then please, feel free to <a href="https://wiki.xoreos.org/index.php?title=Contact_us">contact us</a>! :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[xoreos 0.0.4 "Chodo" Released]]></title>
    <link href="https://xoreos.org/blog/2016/02/01/xoreos-0-dot-0-4-chodo-released/"/>
    <updated>2016-02-01T00:00:00+01:00</updated>
    <id>https://xoreos.org/blog/2016/02/01/xoreos-0-dot-0-4-chodo-released</id>
    <content type="html"><![CDATA[<p>A new year, a new release: we are proud to announce the release of version 0.0.4, nicknamed &ldquo;Chodo&rdquo;, of <a href="https://github.com/xoreos/xoreos/releases/tag/v0.0.4">xoreos</a> and <a href="https://github.com/xoreos/xoreos-tools/releases/tag/v0.0.4">xoreos-tools</a>.</p>

<p>In this release, Neverwinter Nights now shows speech bubbles for conversation one-liners, as used for cutscenes, bark strings and short NPC dialogues. Additionally, the premium modules BioWare sold for Neverwinter Nights, including the three that come with the Diamond Edition, can now be properly loaded and started.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20160201_bubbles.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20160201_bubbles_t.png' width='256' height='170' title='Speech bubbles' alt='Speech bubbles'><span class='caption-text'>Speech bubbles</span></span></a></p>

<p>An oversight in the handling of the texture fonts used in Neverwinter Nights and the two Knights of the Old Republic games has been fixed. This oversight broke rendering of certain characters, most prominently of those used in eastern European languages and the &ldquo;smart&rdquo; single quotation mark that&rsquo;s used instead of an apostrophe in some strings found in the French versions.</p>

<p>For xoreos-tools, there&rsquo;s two new tools: fixpremiumgff and ncsdis.</p>

<p>The first tool, fixpremiumgff, can restore the deliberately broken GFF files found in the BioWare premium modules for Neverwinter Nights. The resulting GFF files can then be edited as normal.</p>

<p>The second tool, ncsdis, is <a href="https://xoreos.org/blog/2016/01/12/disassembling-nwscript-bytecode/">a disassembler for the stack-based bytecode of BioWare&rsquo;s NWScript scripting language</a>. It supports the scripts of all games targeted by xoreos and can disassemble them into a full assembly listing.  It can also produce a control flow graph in the DOT description language, which can then be plotted into an image by using the dot tools from the <a href="http://graphviz.org/">GraphViz suite</a>.</p>

<p>Moreover, this release includes a lot of user-invisible code documentation and quality fixes, in both xoreos and xoreos-tools.</p>

<p>Binaries for Windows, GNU/Linux and Mac OS X are attached to the GitHub release, <a href="https://github.com/xoreos/xoreos/releases/tag/v0.0.4">here for xoreos</a> and <a href="https://github.com/xoreos/xoreos-tools/releases/tag/v0.0.4">here for xoreos-tools</a>. Additionally, packages for various GNU/Linux distributions can be found on the OpenSuSE Build Service (<a href="https://software.opensuse.org/download.html?project=home%3ADrMcCoy%3Axoreos&amp;package=xoreos">here for xoreos</a>, <a href="https://software.opensuse.org/download.html?project=home%3ADrMcCoy%3Axoreos&amp;package=xoreos-tools">here for xoreos-tools</a>) and in Arch Linux&rsquo;s AUR (<a href="https://aur.archlinux.org/packages/xoreos/">here for xoreos</a>, <a href="https://aur.archlinux.org/packages/xoreos-tools/">here for xoreos-tools</a>).</p>

<p>Alternatively, the repository and the source tarballs contain PKGBUILD files in dists/arch/ and a debian build directory in dists/debian/, which can be used to build Arch Linux and Debian/Ubuntu packages, respectively.</p>

<p>And as always, we&rsquo;re looking for more developers to join us in our efforts to reimplement those 3D BioWare RPGs. If <em>you</em> would like to help, please feel free to <a href="https://wiki.xoreos.org/index.php?title=Contact_us">contact us</a>. :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Disassembling NWScript Bytecode]]></title>
    <link href="https://xoreos.org/blog/2016/01/12/disassembling-nwscript-bytecode/"/>
    <updated>2016-01-12T14:00:00+01:00</updated>
    <id>https://xoreos.org/blog/2016/01/12/disassembling-nwscript-bytecode</id>
    <content type="html"><![CDATA[<p>As I already said in last year&rsquo;s <a href="https://xoreos.org/blog/2015/11/27/not-thanksgiving-2015/">retrospective</a>, I want to write a bit about NWScript and its bytecode.</p>

<p>First of all, what is NWScript? NWScript is the scripting language and system BioWare introduced with <em>Neverwinter Nights</em> and used, with improvements and changes, throughout the Aurora-based games. Specifically, you can find NWScript driving the high-level game logic of <em>Neverwinter Nights</em>, <em>Neverwinter Nights 2</em>, <em>Knights of the Old Republic</em>, <em>Knights of the Old Republic II</em>, <em>Jade Empire</em>, <em>The Witcher</em> (in combination with <a href="http://www.lua.org/">Lua</a>), <em>Dragon Age: Origins</em> and <em>Dragon Age II</em>. This is nearly every single game xoreos targets. The only exception is the Nintendo DS game, <em>Sonic Chronicles: The Dark Brotherhood</em>, which doesn&rsquo;t seem to use any scripts at all.</p>

<p>NWScript is written in a <a href="https://en.wikipedia.org/wiki/C_%28programming_language%29">C</a>-like language and saved with the .nss extension. A <a href="https://en.wikipedia.org/wiki/Compiler">compiler</a> then translates it into a <a href="https://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29">stack</a>-based <a href="https://en.wikipedia.org/wiki/Bytecode">bytecode</a> with the .ncs extension, which is what the game executes. That is similar to how ActionScript in Flash videos works, and how Java, Lua and other scripting languages can operate.</p>

<p>Like C, NWScript is a strongly typed language: each variable has one definite type. Among the available types are &ldquo;int&rdquo; (32-bit signed integer), &ldquo;float&rdquo; (32-bit IEEE floating point), &ldquo;string&rdquo; (a textual ASCII string) and &ldquo;object&rdquo; (an object in the game world, like an NPC or a chest). Moreover, there are several engine types, like &ldquo;event&rdquo; and &ldquo;effect&rdquo;, though which of these are available depends on the game. There are also <a href="https://en.wikipedia.org/wiki/Record_%28computer_science%29">structs</a>, but in the compiled bytecode, they vanish and are replaced by a collection of loose variables. Likewise, the &ldquo;vector&rdquo; type is treated as three single float variables. A special type is the &ldquo;action&rdquo; type, a script state (or <a href="https://en.wikipedia.org/wiki/Functor">functor</a>) that&rsquo;s stored separately.</p>

<p>Additionally, <em>Dragon Age: Origins</em> adds a &ldquo;resource&rdquo; type (which, in the bytecode, can be used interchangeably with the &ldquo;string&rdquo; type) and dynamic arrays. <em>Dragon Age II</em> in turn adds the concept of a reference to a variable to help performance in several use-cases. For these new features, these two games each add two new bytecode opcodes, something not done for any of the other post-<em>Neverwinter Nights</em> games.</p>

<p>To get and modify the state of the game world, like searching for objects and moving them, and for complex mathematical operations like trigonometry functions, the NWScript bytecode can call so-called engine functions. These are functions that are provided by the game itself; about 850 per game, with some overlap. They&rsquo;re declared in the nwscript.nss file (nwscriptdefn.nss for <em>The Witcher</em> and script.ldf for the <em>Dragon Age</em> games) of each game.</p>

<p>The original <em>Neverwinter Nights</em> toolset came with a compiler, but a part of the modding community, the OpenKnights Consortium, created their own, free software compiler, nwnnsscomp. Unfortunately, it has a few disadvantages. For example, it always needs the nwscript.nss file and it also only handles Neverwinter Nights. And while there has been several variations that have been extended to handle newer games, many of these are only available as Windows binaries. As far as I&rsquo;m aware, there never has been a variation that handles <em>Dragon Age: Origins</em> or <em>Dragon Age II</em>. Also, since the code hasn&rsquo;t been touched for 10 years, it&rsquo;s difficult to compile now, and it doesn&rsquo;t work when compiled for 64-bit. For what it&rsquo;s worth, I mirrored the old OpenKnights NWNTools, with a few changes, to <a href="https://github.com/DrMcCoy/NWNTools">GitHub here</a>.</p>

<p>This nwnnsscomp also has a disassembly mode, which can convert the compiled bytecode into somewhat human-readable assembly. This is pretty useful! I wanted my own disassembler in <a href="https://github.com/xoreos/xoreos-tools">xoreos-tools</a>.</p>

<p>The steps to disassemble NWScript bytecode are the following:</p>

<p><strong>1) Read instructions</strong></p>

<p>Read the .ncs file, instruction for instruction. An instruction consists of an opcode (like <code>ADD</code> for addition), the argument types (which are taken from or pushed onto the stack) and any direct arguments. For example, an addition that operates on two integers would be known as <code>ADDII</code>. The instructions are stored in a list, one after the other.</p>

<p><strong>2) Link instructions</strong></p>

<p>Each instruction may have a follower, the instruction that follows naturally. For most instructions, this is the instruction next in the list. But certain branching instruction, jumps and subroutine calls, also have jump destinations that may be taken.</p>

<p><strong>3) Create blocks</strong></p>

<p>Group the instructions into <a href="https://en.wikipedia.org/wiki/Basic_block">blocks</a>. A block is a sequence of instructions that follow each other, with two constraints: a jump into a block can only land at the beginning of a block and a jump out of a block can only happen at the end of the block.</p>

<p><strong>4) Create subroutines</strong></p>

<p>Group the blocks into <a href="https://en.wikipedia.org/wiki/Subroutine">subroutines</a>. A subroutine is a sequence of blocks that gets jumped to by a special opcode, <code>JSR</code>, and returns to the place from where it has been called with <code>RETN</code>. (In many programming languages, for example C, these are also called functions, but we&rsquo;re calling them subroutines so that they&rsquo;re not being confused with engine functions. Subroutine is also often the usual term in assembly dialects.)</p>

<p><strong>5) Link subroutines</strong></p>

<p>Record where a subroutine calls another and link the caller and callee, so that a call graph could be created easily. Likewise, the instructions that start and end the subroutine are also separately recorded.</p>

<p><strong>6) Identify &ldquo;special&rdquo; subroutines</strong></p>

<p>There are three special subroutines that we can identify:</p>

<ul>
<li>_start(), the very first subroutine that starts execution of the script. It&rsquo;s the subroutine that contains the very first instruction in the .ncs file.</li>
<li>_global(), which, if it exists, sets up the global variables. This is the subroutine that contains an instruction with a <code>SAVEBP</code> opcode.</li>
<li>main(), which is the <code>main</code> or <code>StartingConditional</code> function visible in the script source. If a _global() subroutine exists, this is the last subroutine called by _global(). Otherwise, it&rsquo;s the last (and only) subroutine called by _start().</li>
</ul>


<p><strong>7) Analyze the stack</strong></p>

<p>This step goes through the whole script and evaluates each instruction for how it manipulates the stack. Since stack elements are explicitly typed, and instructions that create new stack elements know which type they create (either explicitly, or implicitly by copying an already typed element), both the size of the stack and the type of all elements can be figured out. At the end, each instruction will know how the stack looks before its execution. And for each subroutine, we then know its signature: how many parameters it takes, what their types are and what the subroutine returns.</p>

<p>However, this step only works if we know which game this script is from, because we need to know the signatures of the engine functions. And, unfortunately, this step fails when the script subroutines call each other recursively. The stack of a recursing script can&rsquo;t be analyzed like this.</p>

<p><strong>8) Analyze the control flow</strong></p>

<p>So far, the script disassembly consists of blocks that jump to each other, with no further meaning attached. To extract this deeper meaning, we analyze the control flow for higher-level control structures: <a href="https://en.wikipedia.org/wiki/Do_while_loop">do-while loops</a>, <a href="https://en.wikipedia.org/wiki/While_loop">while loops</a>, <a href="https://en.wikipedia.org/wiki/Conditional_%28computer_programming%29">if and if-else blocks</a>, together with <a href="https://en.wikipedia.org/wiki/Control_flow#Early_exit_from_loops">break</a> and <a href="https://en.wikipedia.org/wiki/Control_flow#Continuation_with_next_iteration">continue</a> statements and early subroutine returns. Each block gets a list of designators that show if and how it contributes to such a control structure.</p>

<p><strong>9) Create output</strong></p>

<p>Finally, we create an output. This can be one of three:</p>

<ul>
<li>A full listing, including offset, raw bytes and disassembly. This is similar to the output created by the disassembly mode of the OpenKnights nwnnsscomp.</li>
<li>Only the disassembly. This output might be used to reassemble the script some time later, should someone want to write an assembler.</li>
<li>A <a href="https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29">DOT</a> file. A DOT file is a textual description of a graph, which can be plotted into a graph with the <a href="http://www.graphviz.org/">Graphviz</a> tool. The result is a clear representation of the control flow in graph form.</li>
</ul>


<p>As an example, here&rsquo;s a script from <em>Neverwinter Nights 2</em>: <a href="https://xoreos.org/text/2443_tr_portal_cl.nss.txt">this is the original source</a>, and <a href="https://xoreos.org/text/2443_tr_portal_cl.lst.txt">this is the full listing output</a>, <a href="https://xoreos.org/text/2443_tr_portal_cl.asm.txt">the assembly-only output</a> and <a href="https://xoreos.org/images/blog/20151127_2443_tr_portal_cl.png">the control flow graph</a>.</p>

<p>During this work, I have found a few interesting little bugs in the original BioWare NWScript compiler. For example, this little script, hf_c_skill_value.nss in <em>Neverwinter Nights 2</em> and its disassembly:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>int StartingConditional(int nSkill, int nValue)
</span><span class='line'>{
</span><span class='line'>  object oPC = GetPCSpeaker();
</span><span class='line'>  int nSkill = GetSkillRank(nSkill, oPC);
</span><span class='line'>  return (nSkill &gt;= nValue);
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>


<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>  00000017 02 06                      RSADDO
</span><span class='line'>  00000019 05 00 00EE 00              ACTION GetPCSpeaker 0
</span><span class='line'>  0000001E 01 01 FFFFFFF8 0004        CPDOWNSP -8 4
</span><span class='line'>  00000026 1B 00 FFFFFFFC             MOVSP -4
</span><span class='line'>  0000002C 02 03                      RSADDI
</span><span class='line'>  0000002E 04 03 00000000             CONSTI 0
</span><span class='line'>  00000034 03 01 FFFFFFF4 0004        CPTOPSP -12 4
</span><span class='line'>  0000003C 03 01 FFFFFFF4 0004        CPTOPSP -12 4
</span><span class='line'>  00000044 05 00 013B 03              ACTION GetSkillRank 3</span></code></pre></td></tr></table></div></figure>


<p>Specifically, the <code>int nSkill = GetSkillRank(nSkill, oPC);</code> line is compiled wrong. First, an instruction with the opcode <code>RSADDI</code> is generated, which creates a new integer variable on the stack, for <code>nSkill</code>. Then, the arguments for <code>GetSkillRank</code> are pushed onto the stack, and <code>GetSkillRank</code> is called using the ACTION instruction.</p>

<p>Unfortunately, as soon as the compiler creates the stack space for the local variable <code>nSkill</code>, it associates <code>nSkill</code> with this local variable. So when it&rsquo;s time to push the parameter <code>nSkill</code> for <code>GetSkillRank</code> on the stack, the parameter to the outer <code>StartingConditional</code> subroutine has already been overruled, and the <code>CPTOPSP</code> points to the new local variable.</p>

<p>This renders the <code>nSkill</code> parameter unused and useless, and <code>GetSkillRank</code> is potentially called with an uninitialized value.</p>

<p>For another example, have a look at this script from <em>Neverwinter Nights</em>:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>int StartingConditional()
</span><span class='line'>{
</span><span class='line'>  int iResult;
</span><span class='line'>  object oPC = GetPCSpeaker();
</span><span class='line'>
</span><span class='line'>  iResult = GetClassByPosition(1,oPC) == CLASS_TYPE_DRUID ||
</span><span class='line'>            GetClassByPosition(2,oPC) == CLASS_TYPE_DRUID ||
</span><span class='line'>            GetClassByPosition(3,oPC) == CLASS_TYPE_DRUID;
</span><span class='line'>  return iResult;
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>


<p>It&rsquo;s meant to check whether the player character is a druid. Since you can multi-class in <em>Neverwinter Nights</em>, it checks whether the character is a druid for the first class, for the second class and then the third class. If any of these return true, <code>iResult</code> will be set to true. To achieve this, a <a href="https://en.wikipedia.org/wiki/Boolean_algebra#Operations">boolean disjunction (&ldquo;or&rdquo; operation)</a> is used. As is customary in C-like languages, the boolean disjunction in NWScript is supposed to support short-circuiting: if the first part is already true, the second (and third) checks aren&rsquo;t even called.</p>

<p>Let&rsquo;s see how the disassembly graph looks like:</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20160112_orbioware.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20160112_orbioware.png' width='491' height='816' title='BioWare Disassembly' alt='BioWare Disassembly'><span class='caption-text'>BioWare Disassembly</span></span></a></p>

<p>The first <code>EQII</code> is the first comparison, and then the block in loc_00000057 is supposed to do the short-circuiting. It duplicates the top-most stack element with a <code>CPTOPSP -4 4</code> before bypassing the second comparison and jumping to the <code>LOGORII</code> that does the boolean disjunction. Unfortunately, instead of directly jumping to loc_00000080 with a <code>JMP</code>, a <code>JZ</code> was generated instead. And since the top-most stack element was already duplicated and checked with the previous <code>JZ</code>, we know that the true-edge is never taken. It is a dead edge.</p>

<p>This has an interesting consequence. The short-circuiting for the boolean disjunction is broken: all parts are always evaluated before the results are or&#8217;ed together. In practice, this doesn&rsquo;t matter much. It makes the code a bit slower, and any side effects will always happen.</p>

<p>Additionally, if the true edge were ever taken, the stack would be in a broken state. Unlike <code>JMP</code>, <code>JZ</code> consumes a stack element, and so the <code>LOGORII</code> would be missing one of its arguments. Because this is not possible, it doesn&rsquo;t matter for execution, but my stack analysis dies there. To combat this problem, I added an extra disassembly step after the block generation, the detection of these dead edges. To keep it simple, I only do some simple pattern matching, which is enough for most scripts. There are a few cases where it fails, though.</p>

<p>This bug is present in the original scripts coming with <em>Neverwinter Nights</em>, <em>Knights of the Old Republic</em> and <em>Knights of the Old Republic II</em>, but has already been fixed by the release of <em>Neverwinter Nights 2</em>.</p>

<p>This bug is also not present in the OpenKnights compiler:</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20160112_oropenknights.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20160112_oropenknights.png' width='596' height='699' title='OpenKnights Disassembly' alt='OpenKnights Disassembly'><span class='caption-text'>OpenKnights Disassembly</span></span></a></p>

<p>As you can see, the branch instruction in loc_00000057 is a <code>JMP</code>, as it should be.</p>

<p>So, to recap, xoreos-tools now has a tool that can disassemble NWScript bytecode, similar to the disassemble mode of the OpenKnights nwnnsscomp, with these added features:</p>

<ul>
<li>Easier to compile.</li>
<li>Works compiled as 64-bit.</li>
<li>Out-of-the-box support for the NWScript found in all Aurora-based games.</li>
<li>No need for a separate nwscript.nss.</li>
<li>Support for new array and reference opcodes.</li>
<li>Deeper analysis of the stack, to figure out the subroutine signatures.</li>
<li>Deeper analysis of the control flow, to detect higher-level control structures.</li>
<li>Can create control flow graphs in DOT format.</li>
</ul>


<p>If you&rsquo;re interested, the source is available <a href="https://github.com/xoreos/xoreos-tools/tree/master/src/nwscript">here</a>. Binaries will come with the next release of xoreos and xoreos-tools.</p>

<p>There is, however, still a lot left to do there:</p>

<ul>
<li>Create a decompiler: use the detected control structures as a base to generate C-like NWScript source code.</li>
<li>Detect chained instructions: something like &ldquo;int a = b * c&rdquo; compiles to a lot of instructions that create temporary stack variables.</li>
<li>Detect structs and vectors.</li>
</ul>


<p>Unlike nwnnsscomp, xoreos-tools is still missing a compiler as well. This is something that would be very nice to have indeed. An assembler, which can take the disassembly output and create a working .ncs file out of it would probably be a useful first step in that direction.</p>

<p>If <em>you</em> would like to help and take up any of these tasks, or any other task from our <a href="https://wiki.xoreos.org/index.php?title=TODO">TODO list</a>, please <a href="https://wiki.xoreos.org/index.php?title=Contact_us">contact us</a>! :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Not-Thanksgiving 2015]]></title>
    <link href="https://xoreos.org/blog/2015/11/27/not-thanksgiving-2015/"/>
    <updated>2015-11-27T00:06:00+01:00</updated>
    <id>https://xoreos.org/blog/2015/11/27/not-thanksgiving-2015</id>
    <content type="html"><![CDATA[<p>The end of the year is approaching fast, and just like <a href="https://xoreos.org/blog/2014/11/29/not-thanksgiving/">last year</a>, I want to use this time for some retrospection.</p>

<p>First of all, what happened in the last year?</p>

<ul>
<li><a href="https://github.com/berenm">berenm</a> <a href="https://github.com/xoreos/xoreos/pull/57">added support for building xoreos with CMake</a>, by the way of parsing the automake files used for the autotools build system. This way, xoreos can now be built with either CMake or autotools. I was skeptical at first, especially since I harbour no love for CMake, but it is working reasonably well and I am quite happy with it. In hindsight, I was wrong to reject this pull request for so long.</li>
<li>I focused on supporting all the different model formats used in the Aurora games, and then I made all the games display their in-game areas with objects.</li>
<li>xoreos adopted the <a href="https://github.com/xoreos/xoreos/blob/master/CODE_OF_CONDUCT.md">Contributor Covenant</a> as its Code of Conduct, in the hopes that it helps foster a friendly and welcoming community.</li>
<li>The big one: our first official release, <a href="https://xoreos.org/blog/2015/07/27/xoreos-0-dot-0-2-aribeth-released/">xoreos 0.0.2</a>, nicknamed &ldquo;Aribeth&rdquo;.</li>
<li>I overhauled the script system, making it more generic. This way, I was able to apply it to all targeted games, except <em>Sonic Chronicles: The Dark Brotherhood</em> (which doesn&rsquo;t seem to use any scripts at all). This included figuring out and implementing four new script bytecode opcodes: two for array access in <em>Dragon Age: Origins</em>, and two for reference creation in <em>Dragon Age II</em>.</li>
<li>I implemented reflective environment mapping for <em>Neverwinter Nights</em> and the two <em>Knights of the Old Republic</em> games.</li>
<li>I added a new tool to the <a href="https://github.com/xoreos/xoreos-tools">xoreos-tools</a> package: xml2tlk, which can recreate TLK talk table files out of XML files created by tlk2xml.</li>
<li>With these changes, I decided to push out <a href="https://xoreos.org/blog/2015/09/30/xoreos-0-dot-0-3-bastila-released/">xoreos 0.0.3</a>, nicknamed &ldquo;Bastila&rdquo;.</li>
</ul>


<p>This is all old news, more or less already discussed in previous blog posts. However, since then, I added yet another new tool to the xoreos-tools package: ncsdis. It&rsquo;s a disassembler for NCS files, the stack-based compiled bytecode of the C-like NWScript, BioWare&rsquo;s scripting language used throughout their Aurora-based games.</p>

<p>It basically replaces the disassembler within the old <a href="https://github.com/DrMcCoy/NWNTools">OpenKnightsN WScript compiler</a>, with various added benefits. I&rsquo;ll write a bit more about this tool in the near future, so for now I&rsquo;ll just leave you with an example <a href="https://gist.github.com/DrMcCoy/a07ccb04fe3f232896e6">assembly listing</a> it can produce, as well as a <a href="https://xoreos.org/images/blog/20151127_2443_tr_portal_cl.png">control flow graph</a> it can create (with the help of <a href="https://en.wikipedia.org/wiki/Graphviz">Graphviz</a>). As you can see, it already groups the instruction by blocks and subroutines. It performs a static analysis of the stack (to figure out subroutine parameters and return types) and it also analyzes the control flow to detect assorted control structures (loops, if/else). I plan to grow it into a full-fledged NWScript decompiler.</p>

<p>Additionally, I also added support for BioWare&rsquo;s <em>Neverwinter Nights</em> premium modules, like <a href="https://en.wikipedia.org/wiki/Neverwinter_Nights:_Kingmaker">Kingmaker</a>, to xoreos.</p>

<p>On the documentation side of things,</p>

<ul>
<li>I added comments and documentation to various files in the xoreos sources, hopefully making them more understandable and useful for potential new contributors and otherwise interested people. Considering how awful my memory is at, this is also a kind of future-proofing.</li>
<li><a href="https://github.com/farmboy0">Farmboy0</a> added &ldquo;research&rdquo; subpages for various games on our wiki, filling them with information about their workings.</li>
<li>I extended our <a href="https://wiki.xoreos.org/index.php?title=TODO">TODO list</a> considerably.</li>
<li>I added an <a href="https://github.com/xoreos/xoreos/blob/master/doc/xoreos.conf.example">example configuration file</a>, and extended the documentation on the wiki on how to <a href="https://wiki.xoreos.org/index.php?title=Compiling_xoreos">compile</a> and <a href="https://wiki.xoreos.org/index.php?title=Running_xoreos">run</a> xoreos.</li>
<li>I wrote <a href="https://github.com/xoreos/xoreos-tools/tree/master/man">man pages for each tool in xoreos</a> and <a href="https://github.com/xoreos/xoreos/tree/master/man">for xoreos itself</a>. I also added the former <a href="https://wiki.xoreos.org/index.php?title=Running_xoreos-tools">to the wiki</a>.</li>
</ul>


<p>Phew! This is again a bigger list than I had anticipated. This wouldn&rsquo;t have been possible without these people, for whom I am thankful:</p>

<ul>
<li>I am thankful to <a href="https://github.com/berenm">berenm</a> for providing the CMake bindings, despite my grumbling about it.</li>
<li>I am thankful to <a href="https://github.com/Supermanu">Supermanu</a>, for continuing on chipping away on the <em>Neverwinter Nights</em> character generator.</li>
<li>I am thankful to <a href="https://github.com/Farmboy0">Farmboy0</a>, for working on xoreos&#8217; Jade Empire engine and researching game internals.</li>
<li>I am thankful to <a href="https://github.com/mirv-sillyfish">mirv</a>, for continuing with the huge task of rewriting my naive OpenGL code.</li>
<li>I am thankful to <a href="https://github.com/CoralineAda/">Coraline Ada Ehmke</a> for creating the Contributor Covenant.</li>
<li>I am thankful to all the people in the different BioWare modding communities, for having figured out many different things already. <a href="https://github.com/SkywingvL/">Skywing</a> for example, who had emailed me a few years ago about certain NWScript issues, issues I recently stumbled over again.</li>
<li>I am thankful to <a href="https://github.com/fuzzie">fuzzie</a>, for giving me pointers on the NCS disassembler/decompiler.</li>
<li>I am thankful to the <a href="http://www.gamingonlinux.com/">GamingOnLinux</a> people, who do a lot of work reporting on all sorts of Linux-related gaming news, and who so graciously mirror my xoreos blog posts.</li>
<li>I am thankful to <a href="https://github.com/kevL">kevL</a>, for notifying me of issues with xoreos&#8217; build system on configurations I hadn&rsquo;t thought about.</li>
<li>I am thankful to <a href="http://clone2727.blogspot.com/">clone2727</a>, for putting up with rants and ravings.</li>
<li>I am thankful to all the people who told me when I was wrong, for example when <a href="https://github.com/xoreos/xoreos/commit/bfe06f4c357df2ddaf0ff6ee0b44ef9ff654873c#commitcomment-14211110">I wrongheadedly silenced clang static analyzer warnings</a>, without understanding what I was doing.</li>
<li>I am thankful to everybody else who gave me hints and tips, taught me tricks and procedure, showed me new things, old things, forgotten things, broken things.</li>
<li>I am thankful to all the people who are not angry with me for forgetting them, because they are aware that this is not meant as a personal slight ;).</li>
</ul>


<p>Now that I have these mushy feelings out of my system, here&rsquo;s hoping for another great year! :)</p>

<p>And like always, if you want to join our effort, please don&rsquo;t hesitate to <a href="https://wiki.xoreos.org/index.php?title=Contact_us">contact us</a>!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[xoreos 0.0.3 "Bastila" Released]]></title>
    <link href="https://xoreos.org/blog/2015/09/30/xoreos-0-dot-0-3-bastila-released/"/>
    <updated>2015-09-30T15:30:00+02:00</updated>
    <id>https://xoreos.org/blog/2015/09/30/xoreos-0-dot-0-3-bastila-released</id>
    <content type="html"><![CDATA[<p>To keep things moving following the <a href="https://xoreos.org/blog/2015/07/27/xoreos-0-dot-0-2-aribeth-released/">previous 0.0.2 release</a>, we&rsquo;re proud to announce the release of version 0.0.3, nicknamed &ldquo;Bastila&rdquo;, of <a href="https://github.com/xoreos/xoreos/releases/tag/v0.0.3">xoreos</a> and <a href="https://github.com/xoreos/xoreos-tools/releases/tag/v0.0.3">xoreos-tools</a>.</p>

<p>This release features a working script system for all targeted games, with game scripts being fired for the start of a campaign or module, when entering and leaving areas, and when clicking on in-game object. The singular exception is the Nintendo DS game <em>Sonic Chronicles: The Dark Brotherhood</em>, which doesn&rsquo;t seem to feature any scripts at all.</p>

<p>The vast majority of engine functions, the functions that are called by the scripts and that do the actual work of tracking and changing the game state, are still missing, though. Per game there are about 850 functions (with some overlap) that need to be implemented. We currently have about 90, per game, of these written and working within xoreos. Moreover, many of the functions still missing depend on features not yet implemented.</p>

<p>Apart from the script system changes, 0.0.3 also comes with support for reflective environment mapping in <em>Neverwinter Nights</em> and the two <em>Knights of the Old Republic</em> games. The &ldquo;metallic&rdquo; armor and area parts that were rendered transparent in xoreos are now properly reflective. This can be seen, for example, in the Sith troopers in <em>Knights of the Old Republic</em>, in various plate armor worn by NPC in <em>Neverwinter Nights</em>, as well as the metallic floors on the planet of Taris and the icy wastes of Cania. For <em>Neverwinter Nights</em>, xoreos now also correctly smoothes the vertex normals of (binary) models, so that the metallic effect is not broken by sharp polygon edges.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150930_kotor1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150930_kotor1_t.png' width='256' height='170' title='Semi-transparent mask' alt='Semi-transparent mask'><span class='caption-text'>Semi-transparent mask</span></span></a> <a href="https://xoreos.org/images/blog/20150930_kotor2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150930_kotor2_t.png' width='256' height='170' title='Plus reflectivity' alt='Plus reflectivity'><span class='caption-text'>Plus reflectivity</span></span></a> <a href="https://xoreos.org/images/blog/20150930_kotor3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150930_kotor3_t.png' width='256' height='170' title='Correctly rendered Sith trooper' alt='Correctly rendered Sith trooper'><span class='caption-text'>Correctly rendered Sith trooper</span></span></a></p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150930_nwn1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150930_nwn1_t.png' width='256' height='170' title='Without environment map' alt='Without environment map'><span class='caption-text'>Without environment map</span></span></a> <a href="https://xoreos.org/images/blog/20150930_nwn2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150930_nwn2_t.png' width='256' height='170' title='Without normal smoothing' alt='Without normal smoothing'><span class='caption-text'>Without normal smoothing</span></span></a> <a href="https://xoreos.org/images/blog/20150930_nwn3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150930_nwn3_t.png' width='256' height='170' title='Correctly rendered plate armor' alt='Correctly rendered plate armor'><span class='caption-text'>Correctly rendered plate armor</span></span></a></p>

<p>On the xoreos-tools side of things, there&rsquo;s now a new xml2tlk tool that can convert XML files created by the tlk2xml tool back into a talk table TLK file. Please note that, at the moment, only non-GFF&rsquo;d TLK files can be written, as used by the two <em>Neverwinter Nights</em> games, the two <em>Knights of the Old Republic</em> games, <em>Jade Empire</em> and <em>The Witcher</em>. TLK files as used by <em>Sonic Chronicles: The Dark Brotherhood</em> and the two <em>Dragon Age</em> games can not be written (they can, however, be read with the tlk2xml tool).</p>

<p>Additionally, the convert2da tool gained the ability to write binary 2DA files, as used by the two <em>Knights of the Old Republic</em> games; and xoreostex2tga can now correctly read TPC cube maps.</p>

<p>Binaries for Windows, GNU/Linux and Mac OS X are attached to the GitHub release, <a href="https://github.com/xoreos/xoreos/releases/tag/v0.0.3">here for xoreos</a> and <a href="https://github.com/xoreos/xoreos-tools/releases/tag/v0.0.3">here for xoreos-tools</a>. Additionally, packages for various GNU/Linux distributions can be found on the OpenSuSE Build Service (<a href="https://software.opensuse.org/download.html?project=home%3ADrMcCoy%3Axoreos&amp;package=xoreos">here for xoreos</a>, <a href="https://software.opensuse.org/download.html?project=home%3ADrMcCoy%3Axoreos&amp;package=xoreos-tools">here for xoreos-tools</a>) and in Arch Linux&rsquo;s AUR (<a href="https://aur.archlinux.org/packages/xoreos/">here for xoreos</a>, <a href="https://aur.archlinux.org/packages/xoreos-tools/">here for xoreos-tools</a>).</p>

<p>Alternatively, the repository and the source tarballs contain PKGBUILD files in dists/arch/ and a debian build directory in dists/debian/, which can be used to build Arch Linux and Debian/Ubuntu packages, respectively.</p>

<p>And as always, we&rsquo;re looking for more developers to join us in our efforts to reimplement those 3D BioWare RPGs. If <em>you</em> would like to help, please feel free to <a href="https://wiki.xoreos.org/index.php?title=Contact_us">contact us</a>. :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[xoreos 0.0.2 "Aribeth" Released]]></title>
    <link href="https://xoreos.org/blog/2015/07/27/xoreos-0-dot-0-2-aribeth-released/"/>
    <updated>2015-07-27T17:00:08+02:00</updated>
    <id>https://xoreos.org/blog/2015/07/27/xoreos-0-dot-0-2-aribeth-released</id>
    <content type="html"><![CDATA[<p>We are proud to announce our very first release of <a href="https://github.com/xoreos/xoreos/releases/tag/v0.0.2">xoreos</a> and <a href="https://github.com/xoreos/xoreos-tools/releases/tag/v0.0.2">xoreos-tools</a>, version 0.0.2, nicknamed &ldquo;Aribeth&rdquo;.</p>

<p>While xoreos is still far from being useful to end-users, all targeted games work insofar as that they at least show basic in-game areas. You can start the game, xoreos loads the game resources, loads a campaign or module, and then shows an area of the game. This accurately demonstrates what the xoreos project wants to accomplish.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/screenshots/nwn/ingame06.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/screenshots/nwn/ingame06_t.png' width='256' height='192' title='Neverwinter Nights' alt='Neverwinter Nights'><span class='caption-text'>Neverwinter Nights</span></span></a> <a href="https://xoreos.org/screenshots/kotor/menu01.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/screenshots/kotor/menu01_t.png' width='256' height='192' title='Knights of the Old Republic' alt='Knights of the Old Republic'><span class='caption-text'>Knights of the Old Republic</span></span></a> <a href="https://xoreos.org/screenshots/dao/ingame01.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/screenshots/dao/ingame01_t.png' width='256' height='192' title='Dragon Age: Origins' alt='Dragon Age: Origins'><span class='caption-text'>Dragon Age: Origins</span></span></a></p>

<p>Within the in-game area, you can fly around in a &ldquo;spectator&rdquo; mode, using the common first-person WASD control scheme. Moving the mouse while holding down the middle mouse button rotates the camera. With Ctrl+D, a debug console drops down, allowing for general resource dumping and the loading of different areas, modules and/or campaigns.</p>

<p>A few games, specifically <em>Neverwinter Nights</em> and <em>Knights of the Old Republic</em>, also show a main menu, although the latter&rsquo;s is not as extensive yet. The former also shows a few in-game menu elements.</p>

<p>Additionally, <em>Neverwinter Nights</em> also has a script system hooked up, and preliminary dialogue support. This means that clicking on an NPC opens up its conversation dialog, and some of the script commands will be executed. For example, the door in the first area of the original campaign&rsquo;s prelude opens after speaking to Bim and telling him that no tutorial is necessary. However, triggering the tutorial leads to the scripts looping endlessly, because the necessary game functions are not implemented yet.</p>

<p>Further gameplay is still missing. At the moment, none of the other games have a script system.</p>

<p>The current graphics are very basic: only flat-shaded, textured meshes are shown. No lighting, shadows or shaders of any kind are currently available.</p>

<p>Please note that xoreos is still missing a GUI and needs to be started from the command line.</p>

<p>The accompanying xoreos-tools package includes command line tools that can be used to inspect the games&#8217; resource files and, as such, are meant primarily for developers.</p>

<p>Binaries for Windows, GNU/Linux and Mac OS X are attached to the GitHub release, <a href="https://github.com/xoreos/xoreos/releases/tag/v0.0.2">here for xoreos</a> and <a href="https://github.com/xoreos/xoreos-tools/releases/tag/v0.0.2">here for xoreos-tools</a>. Additionally, packages for various GNU/Linux distributions can be found on the OpenSuSE Build Service (<a href="https://software.opensuse.org/download.html?project=home%3ADrMcCoy%3Axoreos&amp;package=xoreos">here for xoreos</a>, <a href="https://software.opensuse.org/download.html?project=home%3ADrMcCoy%3Axoreos&amp;package=xoreos-tools">here for xoreos-tools</a>) and in Arch Linux&rsquo;s AUR (<a href="https://aur.archlinux.org/packages/xoreos/">here for xoreos</a>, <a href="https://aur.archlinux.org/packages/xoreos-tools/">here for xoreos-tools</a>).</p>

<p>Alternatively, the repository and the source tarballs contain PKGBUILD files in dists/arch/ and a debian build directory in dists/debian/, which can be used to build Arch Linux and Debian/Ubuntu packages, respectively.</p>

<p>And as always, we&rsquo;re looking for more developers to join us in our efforts to reimplement those 3D BioWare RPGs. If <em>you</em> would like to help, please feel free to <a href="https://wiki.xoreos.org/index.php?title=Contact_us">contact us</a>. :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Dragon Age Models and Areas]]></title>
    <link href="https://xoreos.org/blog/2015/07/10/dragon-age-models-and-areas/"/>
    <updated>2015-07-10T04:04:09+02:00</updated>
    <id>https://xoreos.org/blog/2015/07/10/dragon-age-models-and-areas</id>
    <content type="html"><![CDATA[<p>Yet further down the path of getting all targeted games to show areas, it seems like I reached the end with <em>Dragon Age: Origins</em> and <em>Dragon Age II</em>. Similar to my posts about my progress with <em>Sonic Chronicles: The Dark Brotherhood</em> (<a href="https://xoreos.org/blog/2015/06/05/the-odd-one-out-sonic-chronicles-1-slash-3/">Part 1</a>, <a href="https://xoreos.org/blog/2015/06/06/the-odd-one-out-sonic-chronicles-2-slash-3/">Part 2</a>, <a href="https://xoreos.org/blog/2015/06/07/the-odd-one-out-sonic-chronicles-3-slash-3/">Part 3</a>), <a href="https://xoreos.org/blog/2015/04/12/the-witcher-models-and-areas/"><em>The Witcher</em></a>, <a href="https://xoreos.org/blog/2015/02/15/jade-empire-models-and-areas/"><em>Jade Empire</em></a> and <a href="https://xoreos.org/blog/2015/02/01/neverwinter-nights-2-areas/"><em>Neverwinter Nights 2</em></a>, this will be a short description of what I did. This time: <em>Dragon Age: Origins</em> and <em>Dragon Age II</em>.</p>

<h3>Models</h3>

<p>Lucky for me, the <em>Dragon Age</em> model format is reasonably well documented in the <a href="http://social.bioware.com/wiki/datoolset/index.php/Model"><em>Dragon Age</em> toolset wiki</a>. tazpn even created standalone model viewers for <a href="http://social.bioware.com/project/218/"><em>Dragon Age: Origins</em></a> and <a href="http://social.bioware.com/project/4253/"><em>Dragon Age II</em></a>, and released them with sources under the terms of the 3-clause BSD license. :)</p>

<p>And since the model format is based on GFF4, missing pieces of information are relatively easy to decipher too. So I quickly had a loader capable of reading the skeleton whipped up for both <em>Dragon Age: Origins</em> and <em>Dragon Age II</em> (since they are nearly identical in format).</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150710_skeletonragedemon.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_skeletonragedemon_t.png' width='256' height='170' title='Rage demon skeleton' alt='Rage demon skeleton'><span class='caption-text'>Rage demon skeleton</span></span></a> <a href="https://xoreos.org/images/blog/20150710_skeletondragon.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_skeletondragon_t.png' width='256' height='170' title='Dragon skeleton' alt='Dragon skeleton'><span class='caption-text'>Dragon skeleton</span></span></a></p>

<p>With a bit of fiddling, the meshes were there too. There&rsquo;s two types of meshes within the models: static meshes, directly hanging at one specific bone, and dynamic meshes that include weights for several bones for each vertex. Similar to <a href="https://xoreos.org/blog/2015/06/06/the-odd-one-out-sonic-chronicles-2-slash-3/">models in <em>Sonic Chronicles</em></a>, this would deform the mesh according to those weights when the bones are animated. Unlike <em>Sonic Chronicles</em>, the default vertex positions of those meshes create a valid, unanimated pose. This means I could just completely ignore the bone weights for now, and load the meshes as if they were static. In the future, a vertex shader would combine those weights with the bone position to create the fully animatable model meshes.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150710_meshragedemon.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_meshragedemon_t.png' width='256' height='170' title='Rage demon mesh' alt='Rage demon mesh'><span class='caption-text'>Rage demon mesh</span></span></a> <a href="https://xoreos.org/images/blog/20150710_meshdragon.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_meshdragon_t.png' width='256' height='170' title='Dragon mesh' alt='Dragon mesh'><span class='caption-text'>Dragon mesh</span></span></a> <a href="https://xoreos.org/images/blog/20150710_meshstatue.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_meshstatue_t.png' width='256' height='170' title='Statue mesh' alt='Statue mesh'><span class='caption-text'>Statue mesh</span></span></a></p>

<p>Only thing missing now were the textures. For that, I needed to read the MAO (material object) files, which contains the material file (MAT), various textures (diffuse, lightmap, etc.) and a number of optional parameters. The material file in turn contains several different &ldquo;semantics&rdquo;, which is basically the name of a shader and how to map the MAO values onto the shader input. The original game takes all these, looks for the most fitting semantic in the material file (depending on number of parameters, graphics card capability and user settings), and then tells the graphics card which shader to use to render the mesh.</p>

<p>Now, since we don&rsquo;t actually support any shaders yet (and we can&rsquo;t use the game&rsquo;s Direct3D shaders directly anyway), we simple read the MAO (which can be either in GFF4 or XML format), take the diffuse texture, and apply it to the mesh directly.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150710_textureragedemon.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_textureragedemon_t.png' width='256' height='170' title='Textured rage demon' alt='Textured rage demon'><span class='caption-text'>Textured rage demon</span></span></a> <a href="https://xoreos.org/images/blog/20150710_texturedragon.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_texturedragon_t.png' width='256' height='170' title='Textured dragon' alt='Textured dragon'><span class='caption-text'>Textured dragon</span></span></a> <a href="https://xoreos.org/images/blog/20150710_texturestatue.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_texturestatue_t.png' width='256' height='170' title='Textured statue' alt='Textured statue'><span class='caption-text'>Textured statue</span></span></a></p>

<h3>Campaigns</h3>

<p>With the models done, I turned to reading the <em>Dragon Age: Origins</em> campaign files. A campaign, that is either the default single player campaign (which is defined in a CIF file), or a DLC package (with both a CIF file and a manifest.xml) that doesn&rsquo;t extend another campaign (those would be add-ons).</p>

<p>There&rsquo;s several caveats involved here:</p>

<p>First of all, most of the DLC packages are encrypted. The original game queries a BioWare server for the decryption key, asking whether its a legitimate copy. While the encryption method is known (Blowfish in ECB mode), xoreos does not include any of the keys. So the only campaigns apart from the main one loadable right now are the unencrypted ones, namely <em>Dragon Age: Awakening</em>, and any custom ones you might have downloaded (including the PC Gamer promo DLC <a href="http://dragonage.wikia.com/wiki/A_Tale_of_Orzammar">A Tale of Orzammar</a>).</p>

<p>Then, we don&rsquo;t load any add-ons. So no Shale or Feastday Gifts, even if they weren&rsquo;t encrypted (which they are). It&rsquo;s not like xoreos could do anything with them yet anyway.</p>

<p>Finally, we have no way to install .dazip packages yet, so those need to be installed using the original game for now, or manually extracted and put in the right places. In the future, something that install them would be nice. Or maybe we could support loading of packed .dazip files, but that could be slow.</p>

<p>In either case, I implemented the loading of standalone campaign files.</p>

<h3>Areas and rooms</h3>

<p>Next up were areas (ARE) and environment layouts (ARL) with room definitions (RML). The ARE contains dynamic room information, like what music to play, and the placeables and creatures (more of those later). The ARL defines what rooms are in the area (as well as pathing information, weather, fog, etc.), each of them being a RML file with models. They are all, again, GFF4 files, making them nice and easy to understand.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150710_arena.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_arena_t.png' width='256' height='170' title='Arena' alt='Arena'><span class='caption-text'>Arena</span></span></a> <a href="https://xoreos.org/images/blog/20150710_castle.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_castle_t.png' width='256' height='170' title='Castle' alt='Castle'><span class='caption-text'>Castle</span></span></a> <a href="https://xoreos.org/images/blog/20150710_ostagar1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_ostagar1_t.png' width='256' height='170' title='Ostagar' alt='Ostagar'><span class='caption-text'>Ostagar</span></span></a></p>

<p>There was one problem, though. The orientations of the models were given in <a href="https://en.wikipedia.org/wiki/Quaternion">quaternions</a>, and as I said in the <a href="https://xoreos.org/blog/2015/04/12/the-witcher-models-and-areas/">blog post about my <em>The Witcher</em> progress</a>, a combination the automatic world rotation xoreos does, and our Model class wanting <a href="https://en.wikipedia.org/wiki/Euler_angles">Euler angles</a> instead leads to them not being correctly evaluated for whole models.</p>

<p>I was getting sick of that not being correct. I bit the bullet and removed the world rotation (which meant I had to rejigger the placement code in all engines, as well as the camera system, which was especially painful in <em>Sonic Chronicles</em>). And then I changed the Model class to take <a href="https://en.wikipedia.org/wiki/Axis%E2%80%93angle_representation">axis-angle</a> rotations instead; those can be more easily calculated from quaternions, and can still be directly fed into OpenGL.</p>

<p>As a result, the area room models in <em>Dragon Age: Origins</em> were correctly oriented. And the placeable models in <em>The Witcher</em> as well.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150710_elvenalienage.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_elvenalienage_t.png' width='256' height='170' title='Elven alienage' alt='Elven alienage'><span class='caption-text'>Elven alienage</span></span></a> <a href="https://xoreos.org/images/blog/20150710_ostagar2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_ostagar2_t.png' width='256' height='170' title='Ostagar' alt='Ostagar'><span class='caption-text'>Ostagar</span></span></a></p>

<p>You might notice that the ground mesh in outdoor areas looks very blurry and low-res. That&rsquo;s because the original game doesn&rsquo;t specify a single texture for those, but instead combines several textures together in a shader. We don&rsquo;t support that yet, so instead we apply the replacement texture of the lowest LOD which is normally used for meshes that are far away.</p>

<h3>Placeables</h3>

<p>On to the placeables, the objects within areas. They are defined within a list in the ARE file (giving position, orientation, name, etc.), each with a template. The template is a UTP file, a GFF3, that contains common properties for all instances of this placeable. This includes an appearance, which is an index into a GDA (a GFF&rsquo;d 2DA, a two-dimensional table), which specifies, among other things, the model to use.</p>

<p>So far, so usual for BioWare games.</p>

<p>One difference, though. In the <em>Dragon Age</em> games, the GDA files do not stand alone. Instead, each is a combination of potentially several GDA files with the same prefix (defined in m2da.gda). This is used for DLCs, which then can simply add rows to a GDA, instead of overwriting the whole file. Consequentially, the appearance index is not a direct row number, but corresponds to a value in the &ldquo;ID&rdquo; column.</p>

<p>A bit fiddly, but still relatively easy to implement.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150710_placeable1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_placeable1_t.png' width='256' height='170' title='Placeable' alt='Placeable'><span class='caption-text'>Placeable</span></span></a> <a href="https://xoreos.org/images/blog/20150710_placeable2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_placeable2_t.png' width='256' height='170' title='Placeable' alt='Placeable'><span class='caption-text'>Placeable</span></span></a></p>

<h3>Creatures</h3>

<p>The creatures were more difficult. There&rsquo;s several types of creatures: type S (simple) are just a single model; type H (head) are split into a body model and several models for the head (base, eyes, hair, beard); type W (welded) are similar to H, but already include weapons in the body model; and &ldquo;P&rdquo; (player-type) creatures are segmented into head (with base, eyes, hair, beard), chest, hands (gloves) and feet (boots).</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150710_creatureh1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_creatureh1_t.png' width='256' height='170' title='Hurlock' alt='Hurlock'><span class='caption-text'>Hurlock</span></span></a> <a href="https://xoreos.org/images/blog/20150710_creatureh2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_creatureh2_t.png' width='256' height='170' title='Headless Duncan' alt='Headless Duncan'><span class='caption-text'>Headless Duncan</span></span></a> <a href="https://xoreos.org/images/blog/20150710_creatureh3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_creatureh3_t.png' width='256' height='170' title='Headless kitchen boy' alt='Headless kitchen boy'><span class='caption-text'>Headless kitchen boy</span></span></a></p>

<p>Moreover, creatures of type P also switch model parts depending on the equipped items. So armor changes the chest model, gloves and boots change the hands/feet models and a helmet replaces the hair. Which models to use depends on several factors, and includes look-ups in several different GDA files, as well as UTC (creature template) and UTI (items) files.</p>

<p>Another problem is the tinting. The original game uses a shader to tint hair, skin and armor parts custom, user-selectable colors. To do that, their textures just contain intensity values in two color channels, while the two other channels are used as a bump map and something else (which I&rsquo;m not sure yet). If we just apply the texture to those body parts, they are suddenly mostly transparent. To work around that for now, we manually modify each of those textures to remove the transparency. That leaves the weird coloring, but you can at least see all the body parts then.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150710_creatureh4.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_creatureh4_t.png' width='256' height='170' title='Duncan without hair' alt='Duncan without hair'><span class='caption-text'>Duncan without hair</span></span></a> <a href="https://xoreos.org/images/blog/20150710_creatureh5.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_creatureh5_t.png' width='256' height='170' title='Kitchen boy' alt='Kitchen boy'><span class='caption-text'>Kitchen boy</span></span></a> <a href="https://xoreos.org/images/blog/20150710_creatureh6.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_creatureh6_t.png' width='256' height='170' title='Cook' alt='Cook'><span class='caption-text'>Cook</span></span></a></p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150710_meetingofheads.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_meetingofheads_t.png' width='256' height='170' title='Meeting of the heads' alt='Meeting of the heads'><span class='caption-text'>Meeting of the heads</span></span></a> <a href="https://xoreos.org/images/blog/20150710_bodiedheads.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_bodiedheads_t.png' width='256' height='170' title='Bodies' alt='Bodies'><span class='caption-text'>Bodies</span></span></a> <a href="https://xoreos.org/images/blog/20150710_helmets.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_helmets_t.png' width='256' height='170' title='Helmets' alt='Helmets'><span class='caption-text'>Helmets</span></span></a></p>

<h3>Dragon Age II</h3>

<p>I then applied all this to Dragon Age II. Just a few minor changes to the resource loading was necessary, and nearly everything worked out of the box.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150710_hawkeestate.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_hawkeestate_t.png' width='256' height='170' title='Hawke Estate' alt='Hawke Estate'><span class='caption-text'>Hawke Estate</span></span></a> <a href="https://xoreos.org/images/blog/20150710_viscountskeep.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_viscountskeep_t.png' width='256' height='170' title='Viscount's Keep' alt='Viscount's Keep'><span class='caption-text'>Viscount&rsquo;s Keep</span></span></a></p>

<p>Only the P-type creatures needed a bit more work, since how the body part models are constructed changed.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150710_aveline.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150710_aveline_t.png' width='256' height='170' title='Companions' alt='Companions'><span class='caption-text'>Companions</span></span></a></p>

<p>Similar to <em>Sonic Chronicles</em>, <em>Dragon Age II</em> is also missing many of the GDA headers; they&rsquo;re only stored as CRC hashes. With a dictionary attack, I did manage to crack about half of them, but that still leaves about 450 unknown. Something to watch out for in the future.</p>

<h3>Music</h3>

<p>I also investigated how music works in the two games. <em>Dragon Age: Origins</em> uses <a href="https://en.wikipedia.org/wiki/FMOD">FMOD</a>, and <em>Dragon Age II</em> uses <a href="https://en.wikipedia.org/wiki/Audiokinetic_Wwise">Wwise</a>. Both work similarily: the area specifies an event group, and the scripts then tell the library to play a specific event list from that group at certain times. The library does the rest, evaluating the events in the event list (which range from &ldquo;play sound X&rdquo;, over &ldquo;set volume to Y&rdquo;, to &ldquo;add Z% reverb&rdquo;). And while I do have adequately licensed code to read the sounds from both libraries&#8217; soundbanks, figuring out the events is a massive undertaking. And we don&rsquo;t have a script system for the <em>Dragon Age</em> games in place anyway, so this is nothing that can be done right now.</p>

<h3>What&rsquo;s next</h3>

<p>So&hellip; All games xoreos cares about now show areas. What&rsquo;s next, then?</p>

<p>Well, first of all, I&rsquo;d like to do some cleanup of the engines code. Sync them up, make them more similar to each other. Right now, many things are done slightly different in each engine, because the games changes something around and the old concept suddenly didn&rsquo;t fit anymore. If possible, I&rsquo;d like to unify the concepts again.</p>

<p>There&rsquo;s also a few potential portability issues I want to investigate. For example, I read that using fopen() on Windows with filenames containing non-ASCII characters won&rsquo;t work at all. Instead, I&rsquo;ll probably have to change xoreos&#8217; File stream class to use Boost&rsquo;s fstreams, and convert our UTF-8 strings to UTF-16 on file open. I hope that&rsquo;s something I can test with Wine, otherwise I&rsquo;ll have to bug somebody with access to a real Windows.</p>

<p>After those things have been cleared, I&rsquo;d like to prepare for our very first release. I plan to include both xoreos and xoreos-tools, with sources (of course) and pre-compiled binaries for GNU/Linux, Mac OS X (>= 10.5) and Windows, each for both x86 and x86_64. I have cross-compilers for those, and they all <em>should</em> work. Yes, xoreos is still not really useful for end-users, but a release can&rsquo;t hurt, and might give us some publicity and/or get people interested. Who knows.</p>

<p>I could use some testers for those binaries, though, to make sure I get the library dependencies correctly. And that the GNU/Linux binaries work on other systems than just mine.</p>

<p>I&rsquo;m also open for other platforms. Would it make sense to have xoreos pre-compiled for Free/Net/OpenBSD? Other architectures than just x86/x86_64? Anybody with insights there, and capable of compiling those binaries (or pointers to cross-compilers), please, <a href="https://wiki.xoreos.org/index.php?title=Contact_us">contact us</a>. :)</p>

<p>As for how to continue the actual xoreos development, I think it would be useful to transfer the script system that&rsquo;s currently hooked up to <em>Neverwinter Nights</em> onto the other engines. It would need to be rewritten, though. When I first wrote it, I wanted to have engine functions with signatures that mirrored the signatures of what the scripts call. I couldn&rsquo;t get it to work, though, and settled on a context that contained an array of parameters. For some reason, I still used boost::bind for all the functions, which, at that point, was not necessary. boost::bind compiles really, really slow, and so now the files containing the <em>Neverwinter Nights</em> engines functions take ages to compile. This needs to go.</p>

<p>There, that&rsquo;s the current short-term roadmap for me: cleanup, release, script system.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Odd One Out: Sonic Chronicles (3/3)]]></title>
    <link href="https://xoreos.org/blog/2015/06/07/the-odd-one-out-sonic-chronicles-3-slash-3/"/>
    <updated>2015-06-07T02:24:12+02:00</updated>
    <id>https://xoreos.org/blog/2015/06/07/the-odd-one-out-sonic-chronicles-3-slash-3</id>
    <content type="html"><![CDATA[<p>(This is part 3 of 3 of my report about the progress on <em>Sonic Chronicles</em>. If you haven&rsquo;t already, please also read <a href="https://xoreos.org/blog/2015/06/05/the-odd-one-out-sonic-chronicles-1-slash-3/">part 1</a> and <a href="https://xoreos.org/blog/2015/06/06/the-odd-one-out-sonic-chronicles-2-slash-3/">part 2</a>.)</p>

<p>Now that I had (nearly) everything graphical together, it was time to weave it all together into something approaching fake <em>Sonic Chronicles</em> gameplay.</p>

<h3>Windows size</h3>

<p>Being a Nintendo DS game, <em>Sonic Chronicles</em> run on two screens of 256x192 each, arranged on top of each other. To make this easy on me, I decided to, for now, force xoreos&#8217; window size to a static 256x384, and draw into it as if it was the two Nintendo DS screen. For the future, we&rsquo;ll have to think about how to handle scaling.</p>

<p>There&rsquo;s at least two ways to handle this:</p>

<ul>
<li>Render into two textures, one for the each screen, then scale these</li>
<li>Scale and position the pieces separately</li>
</ul>


<p>The former is the easy way out, but the latter might provide higher quality. There might be a third, a middle way: draw all 2D elements combined with scaling, and render the 3D objects in higher resolution.</p>

<h3>Intro panels</h3>

<p>To make the game feel a bit more real, I rigged up few static panels showing the various splash screens, and the &ldquo;Start your adventure&rdquo; GUI. Note that the button isn&rsquo;t actually working: it&rsquo;s really just an image that waits for a mouse click.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150607_intro1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150607_intro1.png' width='256' height='384' title='Touch to Start' alt='Touch to Start'><span class='caption-text'>Touch to Start</span></span></a> <a href="https://xoreos.org/images/blog/20150607_intro2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150607_intro2.png' width='256' height='384' title='Start your Adventure' alt='Start your Adventure'><span class='caption-text'>Start your Adventure</span></span></a> <a href="https://xoreos.org/images/blog/20150607_intro3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150607_intro3.png' width='256' height='384' title='Chapter 1' alt='Chapter 1'><span class='caption-text'>Chapter 1</span></span></a></p>

<h3>Area background</h3>

<p>After the intro panels, <em>Sonic Chronicles</em> in xoreos then dumps you right into the first area. Using a static panel again, it displays the mini map on the top screen, and the area background on the bottom screen. With the arrow keys, you can move the camera along the X and Y axes, and the area background panel follows the camera to draw the section.</p>

<h3>Area placeables</h3>

<p>That was easy enough. I then wasted the better part of a day trying to trace and guess at how the game loads the &ldquo;placeable&rdquo; objects, the usable 3D objects in the area. The area description within the ARE file lists all placeables, each with an integer with the &ldquo;name&rdquo; of 40023 that seems to be a running ID and an integer called 40018 that&rsquo;s unique for each type. I.e. collectable rings have a 40018 value of 0, the item chest 6, and the pile of wood in the first area has a value of 15. The model names are listed in appearances.gda. So far, so familiar. However, the model for the wood pile is on row 101, and I failed to find a consistent way to connect those two numbers, 15 and 101, either mathematical or with the help of other data files, that would have worked for other placeables as well.</p>

<p>With nowhere else to turn, I looked at the disassembly. And I wept. There <em>is</em> no clean way to connect those numbers, because the placeable instantiation is hardcoded: there&rsquo;s a big old switch with all possible values (43 of them, 0-42) for the integer 40018, with object instantiation for each of them.</p>

<p>To keep it simple for now, I added a little array mapping that type ID onto a row in the appearances.gda. Not all cells are filled yet, but enough that the first area makes sense.</p>

<p>But, to get the models to display correctly, there was still something missing. You see, xoreos sets up a proper <a href="https://en.wikipedia.org/wiki/3D_projection#Perspective_projection">perspective projection</a> matrix, where objects in the distance are smaller and all this jazz. <em>Sonic Chronicles</em>, however, uses an <a href="https://en.wikipedia.org/wiki/Orthographic_projection">orthogonal projection</a> at an angle of 45°. So, I added a method in our GraphicsManager to let the game code select an orthogonal projection instead.</p>

<p>And after some other minor fixes related to this, like scaling the rate of camera movement to fit the 45° angle (so that 3D objects stay at the same point on the background image when you move), and adding the changed orthogonal viewport to our unproject() function (so that detecting that you&rsquo;ve moused over an object works correctly), the placeables now display and behave correctly within the areas.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150607_area1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150607_area1.png' width='256' height='384' title='Green Hill Zone' alt='Green Hill Zone'><span class='caption-text'>Green Hill Zone</span></span></a> <a href="https://xoreos.org/images/blog/20150607_area2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150607_area2.png' width='256' height='384' title='Blue Ridge Zone' alt='Blue Ridge Zone'><span class='caption-text'>Blue Ridge Zone</span></span></a> <a href="https://xoreos.org/images/blog/20150607_area3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150607_area3.png' width='256' height='384' title='Voxai Beta Interior' alt='Voxai Beta Interior'><span class='caption-text'>Voxai Beta Interior</span></span></a></p>

<h3>That all?</h3>

<p>So, what&rsquo;s missing? Quite a lot, actually:</p>

<p>Model animations. Those can be both geometry- and texture-based. In geometry-based animations, the bones move around and rotate, leading to different vertex positions. With texture-based animations, the textures move, rotate or scale, or even get replaced by different textures.</p>

<p>Most of the placeable types aren&rsquo;t yet recognized. Nor do the placeables do anything yet. Nor do we create creatures, triggers and squads. Nor do we have a player character that can move around.</p>

<p>There are also no conversations of any kind implemented yet, and there&rsquo;s no proper GUI and menu support.</p>

<p>We&rsquo;re also lacking sound and music. There&rsquo;s partial documentation for them, though, so it should be relatively easy to manage. Videos, which we still miss too, will be more difficult: we need to reverse-engineer the ActImagine VX video codec, since no one has done that yet.</p>

<p>This all is stuff for the TODO pile, though. Nothing I want to work on at the moment. Of course, we would welcome <em>your</em> contribution, so please, don&rsquo;t hesitate to <a href="https://wiki.xoreos.org/index.php?title=Contact_us">contact us</a> if you want to tackle any of these features, or anything else for that matter!</p>

<h3>What&rsquo;s next, then?</h3>

<p>If I want to continue on the path of getting all games to show areas, <em>Dragon Age: Origins</em> would be next. We&rsquo;ll see how well I&rsquo;ll do there, I guess! :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Odd One Out: Sonic Chronicles (2/3)]]></title>
    <link href="https://xoreos.org/blog/2015/06/06/the-odd-one-out-sonic-chronicles-2-slash-3/"/>
    <updated>2015-06-06T01:42:26+02:00</updated>
    <id>https://xoreos.org/blog/2015/06/06/the-odd-one-out-sonic-chronicles-2-slash-3</id>
    <content type="html"><![CDATA[<p>(This is part 2 of 3 of my report about the progress on <em>Sonic Chronicles</em>. <a href="https://xoreos.org/blog/2015/06/05/the-odd-one-out-sonic-chronicles-1-slash-3/">Part 1 can be found here.</a> <a href="https://xoreos.org/blog/2015/06/07/the-odd-one-out-sonic-chronicles-3-slash-3/">Part 3 can be found here.</a>)</p>

<p>After having implemented readers for the common BioWare formats, I turned to the graphics formats. They&rsquo;re, for the most part, stock Nintendo DS formats, which means I could build upon detective work from the Nintendo modding scene. I have to thank three people in particular: <a href="http://problemkaputt.de/">Martin Korth</a>, of <a href="http://problemkaputt.de/gba.htm">NO$GBA</a> fame, whose <a href="http://problemkaputt.de/gbatek.htm">GBATEK documentation</a> is invaluable, <a href="http://llref.emutalk.net/">lowlines</a> who figured out much of the <a href="http://llref.emutalk.net/docs/">gory details of Nintendo&rsquo;s formats</a> and pleoNeX, whose GPLv3-licensed tool <a href="https://github.com/pleonex/tinke">Tinke</a> provided the base on which I implemented my code.</p>

<h3>SMALL</h3>

<p>When I looked over the files inside the <em>Sonic Chronicles</em> archives, I noticed a peculiar thing. There&rsquo;s a lot of files with names ending in &ldquo;.small&rdquo;. I suspected a compression scheme, especially after examining the files in a hexeditor. And sure enough, there are several compression algorithms provided by the Nintendo DS firmware. The one used by <em>Sonic Chronicles</em> is an LZSS variant, which can be decompressed using <a href="https://code.google.com/p/dsdecmp/">barubary&rsquo;s MIT-licensed dsdecmp tool</a> (<a href="https://github.com/gravgun/dsdecmp">GitHub mirror</a>). I pulled the decompressor into xoreos.</p>

<h3>NSBTX</h3>

<p>The first graphics format in <em>Sonic Chronicles</em> I inspected was <a href="http://llref.emutalk.net/docs/?file=xml/btx0.xml#xml-doc">NSBTX</a>. NSBTX files are texture; or rather: archives of several textures used by a single model each. Implementing the reading of these was simple enough, and I added a small program to <a href="https://github.com/xoreos/xoreos-tools">our tools collection</a> that can &ldquo;extract&rdquo; them into TGAs.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150606_nsbtx1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nsbtx1.png' width='128' height='64' title='Hill' alt='Hill'><span class='caption-text'>Hill</span></span></a> <a href="https://xoreos.org/images/blog/20150606_nsbtx2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nsbtx2.png' width='64' height='64' title='Boar' alt='Boar'><span class='caption-text'>Boar</span></span></a> <a href="https://xoreos.org/images/blog/20150606_nsbtx3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nsbtx3.png' width='64' height='64' title='Tails' alt='Tails'><span class='caption-text'>Tails</span></span></a></p>

<h3>NFTR</h3>

<p>Next up, I wanted to see the fonts, <a href="http://romxhack.esforos.com/fuentes-nftr-de-nds-t67">NFTR</a>, used in the game. They&rsquo;re bitmap fonts, with each glyph an image. The image can be 1-bit black and white, or it can be greyscale for anti-aliasing, shadowing or outlining purposes. Additionally, there&rsquo;s mapping tables to translate a code point in a certain encoding (<a href="https://en.wikipedia.org/wiki/UTF-16">UTF-16</a>, <a href="https://en.wikipedia.org/wiki/UTF-32">UTF-32</a>, <a href="https://en.wikipedia.org/wiki/Windows-1252">CP1252</a> or <a href="https://en.wikipedia.org/wiki/Shift_JIS">Shift-JIS</a>) into the index of the glyph it represents.</p>

<p>There was a bit of trial and error involved, as the documentation and existing FLOSS projects to display the fonts weren&rsquo;t quite correct in certain details (which might not even be their fault; Nintendo likes to subtly change formats between firmware versions). But, before long, I could print arbitrary strings in these fonts in xoreos.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150606_nftr.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nftr_t.png' width='256' height='299' title='Font drawing test' alt='Font drawing test'><span class='caption-text'>Font drawing test</span></span></a></p>

<h3>NBFS/NBFP</h3>

<p><em>Sonic Chronicles</em> comes with a few NBFS files, which is a dead-simple raw format: 8-bit paletted image data, with the palette (in <a href="https://en.wikipedia.org/wiki/High_color">16-bit RGB555</a> values) in an NBFP file of the same name. They&rsquo;re mostly used for images spanning a whole Nintendo DS screen.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150606_nbfs1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nbfs1.png' width='256' height='192' title='Mini map' alt='Mini map'><span class='caption-text'>Mini map</span></span></a> <a href="https://xoreos.org/images/blog/20150606_nbfs2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nbfs2.png' width='256' height='192' title='Conversation card' alt='Conversation card'><span class='caption-text'>Conversation card</span></span></a></p>

<h3>NCGR/NCLR</h3>

<p>The main image format used in <em>Sonic Chronicles</em>, however, was still missing: <a href="http://llref.emutalk.net/docs/?file=xml/ncgr.xml#xml-doc">NCGR</a>. As I went along implementing a reader, I learned these ugly facts:</p>

<ul>
<li>The palettes are in separate <a href="http://llref.emutalk.net/docs/?file=xml/nclr.xml#xml-doc">NCLR</a> files that are shared among NCGR</li>
<li>Most of the images are made up of several NCGR files, arranged on a grid</li>
<li>The NCGR image data itself is made up of 8x8 pixel tiles</li>
</ul>


<p>Essentially, this image of Sonic is divided into these parts:</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150606_ncgr1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_ncgr1.png' width='128' height='192' title='Sonic' alt='Sonic'><span class='caption-text'>Sonic</span></span></a> <a href="https://xoreos.org/images/blog/20150606_ncgr2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_ncgr2.png' width='132' height='196' title='NCGR cells' alt='NCGR cells'><span class='caption-text'>NCGR cells</span></span></a> <a href="https://xoreos.org/images/blog/20150606_ncgr3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_ncgr3.png' width='145' height='217' title='NCGR tiles' alt='NCGR tiles'><span class='caption-text'>NCGR tiles</span></span></a></p>

<p>This all makes assembling the final image a bit&hellip;ugly. But hey, I made it work in the end.</p>

<p>&hellip;except for one thing: a few of the NCGR files don&rsquo;t specify their width and height. By fiddling with the values a bit, I managed to find these values manually, but the resulting image looks off: it&rsquo;s as if the image is supposed to be rearranged afterwards, different pieces drawn at different places. Each of those file also has an <a href="http://llref.emutalk.net/docs/?file=xml/ncer.xml#xml-doc">NCER</a> file with the same name. I assume that means information on how to draw these NCGR are within the NCER. A thing for the TODO pile.</p>

<h3>NSBMD</h3>

<p>I then went for the big one: the 3D model format <a href="http://llref.emutalk.net/docs/?file=xml/bmd0.xml#xml-doc">NSBMD</a>. This involved a lot of fiddling, guessing and trial-and-error, as the documentation of these formats is sparse, and oftentimes wrong.</p>

<p>Conceptually, an NSBMD file consists of these parts:</p>

<ul>
<li>Bones</li>
<li>Bone commands</li>
<li>Materials</li>
<li>Polygons</li>
<li>Polygon commands</li>
</ul>


<p>A bone consists of a name and a transformation that displaces it from its (at that point unknown) parent bone. They are stored as a flat list. The bone commands then specify how the bones connect together. And they give each bone a location in the Nintendo DS&rsquo;s matrix stack (a list of <a href="https://en.wikipedia.org/wiki/Transformation_matrix">transformation matrices</a> containing the absolute transformation of each bone at the time of rendering).</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150606_nsbmd_bones1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nsbmd_bones1_t.png' width='256' height='170' title='Broken boar skeleton' alt='Broken boar skeleton'><span class='caption-text'>Broken boar skeleton</span></span></a> <a href="https://xoreos.org/images/blog/20150606_nsbmd_bones2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nsbmd_bones2_t.png' width='256' height='170' title='Getting there...' alt='Getting there...'><span class='caption-text'>Getting there&hellip;</span></span></a> <a href="https://xoreos.org/images/blog/20150606_nsbmd_bones3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nsbmd_bones3_t.png' width='256' height='170' title='Correct boar skeleton' alt='Correct boar skeleton'><span class='caption-text'>Correct boar skeleton</span></span></a></p>

<p>The material contains the texture name (which reference textures inside the NSBTX with the same name as the NSBMD), and a few properties.</p>

<p>Each polygon can use a single material, and contains a list of polygon commands. These polygon commands produce the actual geometry. They set color, normal and texture coordinates, and generate vertices. They also manipulate the matrix stack, specifically replacing the working matrix with the matrix from the stack position of certain bones. In essence, this bases the vertices on the position of the bone.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150606_nsbmd_polygons1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nsbmd_polygons1_t.png' width='256' height='170' title='No.' alt='No.'><span class='caption-text'>No.</span></span></a> <a href="https://xoreos.org/images/blog/20150606_nsbmd_polygons2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nsbmd_polygons2_t.png' width='256' height='170' title='Boar with holes' alt='Boar with holes'><span class='caption-text'>Boar with holes</span></span></a> <a href="https://xoreos.org/images/blog/20150606_nsbmd_polygons3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nsbmd_polygons3_t.png' width='256' height='170' title='Correct boar' alt='Correct boar'><span class='caption-text'>Correct boar</span></span></a></p>

<p>While the Nintendo DS interprets the polygon commands on-the-fly while rendering, and while they can be nearly directly converted to OpenGL-1.2-era glBegin()/glEnd() blocks, this is not really want we want to do. So instead, we, while loading, interpret the polygon commands into an intermediate structure.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150606_nsbmd1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nsbmd1_t.png' width='256' height='170' title='Sonic' alt='Sonic'><span class='caption-text'>Sonic</span></span></a> <a href="https://xoreos.org/images/blog/20150606_nsbmd2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nsbmd2_t.png' width='256' height='170' title='Amy' alt='Amy'><span class='caption-text'>Amy</span></span></a> <a href="https://xoreos.org/images/blog/20150606_nsbmd3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_nsbmd3_t.png' width='256' height='170' title='Tails' alt='Tails'><span class='caption-text'>Tails</span></span></a></p>

<p>The result is a relatively massive loader for these files, and that doesn&rsquo;t yet include support for animations.</p>

<p>One interesting anecdote: the Nintendo DS doesn&rsquo;t use <a href="https://en.wikipedia.org/wiki/Floating_point">floating-point numbers</a> to represent real numbers, but various formats of <a href="https://en.wikipedia.org/wiki/Fixed-point_arithmetic">fixed-point numbers</a>. Those are found extensively in the NSBMD files. But when I implemented the GFF4 format earlier (see <a href="https://xoreos.org/blog/2015/06/05/the-odd-one-out-sonic-chronicles-1-slash-3/">part 1 of my <em>Sonic Chronicles</em> progress report</a>), I found, in the GFF4 files used by <em>Sonic Chronicles</em>, a field type not described in the <em>Dragon Age</em> toolset wiki. Turns out, those are Nintendo DS fixed-point numbers!</p>

<h3>CBGT/PAL and CDPTH</h3>

<p>With those pesky models out of the way, I was ready to show the areas, right? Wrong. There&rsquo;s yet another graphics format in <em>Sonic Chronicles</em>: CBGT, used for the area background images.</p>

<p>However, CBGT isn&rsquo;t a Nintendo format. No, it&rsquo;s one of BioWare&rsquo;s creation. It does, though, take inspiration from the Nintendo DS formats. It consists of blocks of 64x64 pixels, each compressed using the LZSS algorithm found in SMALL files, and each block divided into 8x8 pixel tiles. PAL files of the same name carry palettes, with each CBGT able to use a different palette within the PAL.</p>

<p>Since I already knew how to puzzle together those cells and tiles from the NCGR format, getting the image itself was not a problem. But I was at a loss where to get the dimensions of the image from, and how to distribute the palettes onto the cells. I figured out an algorithm for the latter, that worked for <em>nearly</em> all images, but the outliers still annoyed me. Then it hit me: for each CBGT/PAL pair, there&rsquo;s a third file: a 2DA. And that one contains the information which cell uses which palette, neatly organized in a 2D table exactly how the cells are arranged in the final image. This, of course, is enough to calculate the final image dimensions as well.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150606_cbgt1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_cbgt1_t.png' width='255' height='188' title='Wrong palette distribution' alt='Wrong palette distribution'><span class='caption-text'>Wrong palette distribution</span></span></a> <a href="https://xoreos.org/images/blog/20150606_cbgt2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_cbgt2_t.png' width='255' height='188' title='Correct palette distribution' alt='Correct palette distribution'><span class='caption-text'>Correct palette distribution</span></span></a></p>

<p>I also found a fourth file for nearly each CBGT/PAL/2DA tuple: a CDPTH. Arranged in a similar fashion to the CBGT, it contains 16-bit depth information for each area background. This is used to let certain background pieces draw over the 3D models in the game, when they should appear behind something.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150606_cdpth.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150606_cdpth_t.png' width='255' height='188' title='Depth values' alt='Depth values'><span class='caption-text'>Depth values</span></span></a></p>

<p><em>Now</em> I was ready to implement actual <em>Sonic Chronicles</em> stuff. <a href="https://xoreos.org/blog/2015/06/07/the-odd-one-out-sonic-chronicles-3-slash-3/">I&rsquo;ll describe that in part 3</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Odd One Out: Sonic Chronicles (1/3)]]></title>
    <link href="https://xoreos.org/blog/2015/06/05/the-odd-one-out-sonic-chronicles-1-slash-3/"/>
    <updated>2015-06-05T02:11:18+02:00</updated>
    <id>https://xoreos.org/blog/2015/06/05/the-odd-one-out-sonic-chronicles-1-slash-3</id>
    <content type="html"><![CDATA[<p>And further down the path of getting all targetted games to show areas I go. Previously, I wrote about my progress with <a href="https://xoreos.org/blog/2015/04/12/the-witcher-models-and-areas/"><em>The Witcher</em></a>, <a href="https://xoreos.org/blog/2015/02/15/jade-empire-models-and-areas/"><em>Jade Empire</em></a> and <a href="https://xoreos.org/blog/2015/02/01/neverwinter-nights-2-areas/"><em>Neverwinter Nights 2</em></a>. For the next two months, I took a look at the odd one out: the Nintendo DS game <a href="https://en.wikipedia.org/wiki/Sonic_Chronicles:_The_Dark_Brotherhood"><em>Sonic Chronicles: The Dark Brotherhood</em></a>.</p>

<p>Yes, a Nintendo DS game. I wasn&rsquo;t so sure myself that game is actually a &ldquo;proper&rdquo; target for xoreos. I&rsquo;m still not 100% sure, but I know now that it at least does use several BioWare file formats, as well as Nintendo DS formats. I also saw that some of those BioWare formats are used in <em>Dragon Age: Origins</em> as well, so <em>Sonic Chronicles</em> actually did provide a natural station on my path.</p>

<p>I&rsquo;ll divide my report in three parts. In this post, I&rsquo;ll go a bit into the details of those common BioWare file formats. <a href="https://xoreos.org/blog/2015/06/06/the-odd-one-out-sonic-chronicles-2-slash-3/">In the next post</a>, I cover the graphics (that are mostly Nintendo formats). <a href="https://xoreos.org/blog/2015/06/07/the-odd-one-out-sonic-chronicles-3-slash-3/">And the third post</a> will show how I tied it all together in xoreos.</p>

<p>So, onwards to the BioWare formats.</p>

<h3>GFF4</h3>

<p>GFF is BioWare&rsquo;s &ldquo;General File Format&rdquo;, which is used as the basis for many things in BioWare games. It&rsquo;s an old format, already found in the Infinity Engine, but not quite as complex yet. (<strong>Correction:</strong> It seems I misremembered there; GFF is not used in the Infinity Engine. I apologize for this mistake.) Conceptually, it is comparable to <a href="https://en.wikipedia.org/wiki/XML">XML</a><sup><a href="#footnote_205150605_1_1">1</a></sup>: hierarchical data, organized in a tree-like fashion, able to hold basically everything. As such, it&rsquo;s used to describe areas, characters, items, dialogues, &hellip; Unlike XML, however, GFF is a binary format, not directly human-readable.</p>

<p>Since GFF is such an important format, xoreos already implemented a reader (thanks to <a href="https://github.com/xoreos/xoreos-docs/tree/master/specs/bioware">BioWare releasing specifications for the Neverwinter Nights toolset</a>. And we provide <a href="https://github.com/xoreos/xoreos-tools">a tool to convert them into XML</a> for easier readability, too. It was only, however, for versions 3.2 (used by <em>Neverwinter Nights</em>, <em>Neverwinter Nights 2</em>, <em>Knights of the Old Republic</em>, <em>Knights of the Old Republic 2</em> and <em>Jade Empire</em>) and 3.3 (used by <em>The Witcher</em>). But <em>Sonic Chronicles</em>, <em>Dragon Age: Origins</em> and <em>Dragon Age 2</em> needed a reader for versions 4.0 and 4.1 &ndash; and boy did they change the format.</p>

<p>You see, after converting the GFF3 to XML, the whole thing is really quite readable and understandable. Every tag has a full string as a name, making the uses and intentions clear. But from the game&rsquo;s perspective, this has a huge drawback: it&rsquo;s slow. Strings are unwieldy, slow to read and compare, and variable length items are generally a pain when you want to quickly jump to a specific field. To curb that, GFF4 removes those pesky strings. Instead, fields use a single 32-bit integer as their &ldquo;name&rdquo;, making comparisons easy as pie.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150605_gff3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150605_gff3_t.png' width='256' height='173' title='GFF3 as XML' alt='GFF3 as XML'><span class='caption-text'>GFF3 as XML</span></span></a> <a href="https://xoreos.org/images/blog/20150605_gff4.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150605_gff4_t.png' width='256' height='173' title='GFF4 as XML' alt='GFF4 as XML'><span class='caption-text'>GFF4 as XML</span></span></a></p>

<p>Lucky for me, the new GFF4 format is already documented <a href="http://social.bioware.com/wiki/datoolset/index.php/GFF">on the Dragon Age Toolset Wiki</a>. The huge amount of example files provided by the two <em>Dragon Age</em> games and <em>Sonic Chronicles</em> gave me ample opportunities to test out corner cases as well. Easy. The gff2xml tool mentioned above now supports GFF4 as well.</p>

<p><a name="footnote_205150605_1_1">[1]</a> In fact, BioWare generates their GFF4 files out of XML, as can be seen from the <em>Dragon Age: Origins</em> toolset.</p>

<h3>TLK</h3>

<p>Next up, I saw a new TLK format used in Sonic. TLK is a &ldquo;talktable&rdquo;, a list of strings indexed by a numerical ID. The idea is that you have all text used in the game in one place, easy to use and easy to translate. Already used in Neverwinter Nights, xoreos has a reader for it already. It&rsquo;s relatively simple, too.</p>

<p>However, the new format is quite different. In fact, it&rsquo;s a GFF4! I did say that you can basically stick everything in a GFF, right? That&rsquo;s what they did for <em>Sonic Chronicles</em> (and the two <em>Dragon Age</em> games). With the new GFF4 reader, adding GFF4&rsquo;d TLK support was quick and painless.</p>

<h3>GDA</h3>

<p>Just like the GFF4&rsquo;d TLK, GDA is an old friend in GFF4 suit. This time, it&rsquo;s 2DA: a 2 dimensional array, a table if you will. If you&rsquo;re still lost, think Excel spreadsheet, a simple collection of data organized on a grid.</p>

<p>2DAs are used to, for example, specify the models of different objects. The GIT file describing objects in an area would say &ldquo;Here&rsquo;s an object, we call it Chair, it has Appearance 179&rdquo;. The game then looks into appearances.2da, at row 179 and column &ldquo;ModelName&rdquo;, grab that filename there and load it as the object&rsquo;s model.</p>

<p>GDA is, essentially, just the same thing as GFF4. A list of columns giving their name and type, and a list of rows with the data for each column. <strong>However</strong>&hellip; While real 2DA have an actual column name (the &ldquo;ModelName&rdquo;, for example), making guessing the meaning easy, GDA don&rsquo;t actually store a name. They store a <a href="https://en.wikipedia.org/wiki/Hash_function">hash</a> of the name (specifically, the CRC32 of the UTF-16LE encoded string in all lowercase), a number that&rsquo;s meaningless in and of itself.</p>

<p>There&rsquo;s 845 unique hashes in the GDA files found in Sonic. There&rsquo;s no real way to turn them back into readable strings, but there&rsquo;s a certain trick I could apply: a <a href="https://en.wikipedia.org/wiki/Dictionary_attack">dictionary attack</a>. I got myself a huge list of words found in a dictionary, hashed them, and compared the hashes. Then I extracted all strings I could find in the game (from the GFFs, mostly), and did the same. Then I combined the words of these lists. Then I combined matches. Each time, I manually went through the list to kick out the many, many false positives: strings that hashed to a valid number, but that don&rsquo;t make sense in the context of the game (&ldquo;necklessnoflyzone&rdquo;, &ldquo;rareuniquemummifications&rdquo;, &ldquo;properlyunsmoked&rdquo;).</p>

<p>Phew, that was a lot of tedious work. Still, I managed to find the source strings for 534 of those 845 hashes, 63%. Sure, there&rsquo;s still 311 missing, but that&rsquo;ll have to wait for later.</p>

<p>And that&rsquo;s it for the common BioWare file formats. <a href="https://xoreos.org/blog/2015/06/06/the-odd-one-out-sonic-chronicles-2-slash-3/">Tune in next time when I go over the graphical formats.</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Witcher Models and Areas]]></title>
    <link href="https://xoreos.org/blog/2015/04/12/the-witcher-models-and-areas/"/>
    <updated>2015-04-12T17:32:18+02:00</updated>
    <id>https://xoreos.org/blog/2015/04/12/the-witcher-models-and-areas</id>
    <content type="html"><![CDATA[<p>Further continuing on the path to make all the engines display areas (see my posts on <a href="https://xoreos.org/blog/2015/02/15/jade-empire-models-and-areas/"><em>Jade Empire</em></a> and <a href="https://xoreos.org/blog/2015/02/01/neverwinter-nights-2-areas/"><em>Neverwinter Nights 2</em></a>), I looked at <em>The Witcher</em> next.</p>

<p>As some people might know, CD Projekt RED licensed BioWares Aurora engine for the first <em>The Witcher</em> game (and only the first; the later parts use their own REDengine). And in many aspects, it&rsquo;s very obvious that they spawn off directly from the <em>Neverwinter Nights</em> codebase, not from later BioWare titles. There have been quite some changes, though, to accommodate for <em>The Witcher</em>&rsquo;s requirements.</p>

<h3>Models</h3>

<p>Due to their similarity to <em>Neverwinter Nights</em>&lsquo; MDL model files (and with light help from <a href="http://www.tbotr.net/modules.php?mod=Downloads&amp;op=download&amp;sid=3&amp;ssid=3&amp;dlid=19">Michael_DarkAngel&rsquo;s twMax code</a>), I had already a partially working loader for <em>The Witcher</em>&rsquo;s MDB files. Or so I thought. Turns out, my quick &amp; dirty hack was just about enough to get simple object and character models to show, but it totally failed on area geometry models. Those turned up completely invisible.</p>

<h3>Textures and lightmaps</h3>

<p>Closely looking at what my code does made me realize that the geometry itself loaded, but the textures failed to load. In fact, the textures it tried to load didn&rsquo;t exist. However, there were similarly named ones in the resources. In fact, for the requested texture &ldquo;foo&rdquo;, there were texture resources &ldquo;foo!d&rdquo;, &ldquo;foo!n&rdquo; and several others.</p>

<p>Well, these are, it seems, lightmaps, and several different ones depending on the time of day (named after their Polish words). There&rsquo;s:</p>

<ul>
<li>!d, for dzień (day)</li>
<li>!r, for rano (morning)</li>
<li>!p, for południe (noon)</li>
<li>!w, for wieczór (evening)</li>
<li>!n, for noc (night)</li>
</ul>


<p>Since not all of them might exist for a given texture, I settled on just loading the first one available. And yes, that gave me textured area geometry. With just the lightmap applied, it still looked a bit low-res, however. No wonder, there needs to be a base texture as well. Unlike <em>Neverwinter Nights</em>, which just straight up names the textures and has simple TXI files for some texture properties, <em>The Witcher</em> has full-fledged material definitions integrated into the model. And they&rsquo;re shader-based. For the object models, it was enough to just take the texture names and run with it, but for the area geometry models, I had to extend this a bit. Granted, this is still a hack (we <em>still</em> don&rsquo;t support shaders), and fails occasionally, only less so than before.</p>

<p>The result was this:</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150412_WitcherArea1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150412_WitcherArea1_t.png' width='256' height='160' title='Kaer Morhen exterior' alt='Kaer Morhen exterior'><span class='caption-text'>Kaer Morhen exterior</span></span></a> <a href="https://xoreos.org/images/blog/20150412_WitcherArea2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150412_WitcherArea2_t.png' width='256' height='160' title='Kaer Morhen exterior' alt='Kaer Morhen exterior'><span class='caption-text'>Kaer Morhen exterior</span></span></a> <a href="https://xoreos.org/images/blog/20150412_WitcherArea3.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150412_WitcherArea3_t.png' width='256' height='160' title='Kaer Morhen interior' alt='Kaer Morhen interior'><span class='caption-text'>Kaer Morhen interior</span></span></a></p>

<p>There&rsquo;s bits missing, I hear you say? Correct. Unfortunately.</p>

<h3>TexturePaint nodes</h3>

<p>More debug printouts on the model loader clued me in: there&rsquo;s a new kind model node! The twMax author also noticed this; he calls them &ldquo;TexturePaint&rdquo;. No support for them in twMax, though. My Google-fu didn&rsquo;t uncover anything else helpful either.</p>

<p>With no existing tools to help me, I had to do the dirty work myself. I pulled out my trusty friend the disassembler. Luckily, CD Projekt RED kept the tradition of supporting ASCII representation of model files, and so I was able to map out the loader code relatively quickly, for the most part.</p>

<p>First, I filled out my loader to stub and comment more MDB fields I previously just ignored. Then, I started implementing the TexturePaint nodes. Thanks to a brief email conversation with someone who&rsquo;s also playing around with <em>The Witcher</em> models, I already knew what these nodes probably represented: geometry textured by blending several distinct textures together, to create more realistic terrain. I.e. similar to what I found <em>Neverwinter Nights 2</em> does for its terrain geometry.</p>

<p>This turned out to be exactly the case, only with in-node weightmaps instead of the color channel approach in <em>Neverwinter Nights 2</em>. Additionally, these nodes too have a lightmap applied. Without shaders, this mixing is awfully slow and memory-consuming to do, therefore I instead just apply the lightmap for now. The result looks like this:</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150412_WitcherArea4.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150412_WitcherArea4_t.png' width='256' height='160' title='TexturePaint node with lightmap' alt='TexturePaint node with lightmap'><span class='caption-text'>TexturePaint node with lightmap</span></span></a></p>

<p>It&rsquo;s not exactly pretty, but it at least shows something.</p>

<h3>Level of Detail (LOD)</h3>

<p>After having implemented the TexturePaint nodes, I found a curious issue: certain nodes appeared twice, overlapping each other:</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150412_WitcherArea5.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150412_WitcherArea5_t.png' width='256' height='160' title='Overlapping model nodes' alt='Overlapping model nodes'><span class='caption-text'>Overlapping model nodes</span></span></a></p>

<p>This is the result of the LOD information in the node headers. Some nodes are supposed to be displayed when you&rsquo;re near, some when you&rsquo;re far. Simpler textured geometry nodes are displayed instead of the more complex TexturePaint nodes when far enough away to not notice the texture blending anyway. As a workaround, I rigged it to only display the highest LOD for now.</p>

<h3>Areas</h3>

<p>With the area models correctly loading, I went on to actually load the area. Owing to its origin, it&rsquo;s again very similar to <em>Neverwinter Nights</em>, with one difference: no tiles and tilesets. Instead, the &ldquo;tileset&rdquo; value specifies the singular area geometry model to display.</p>

<p>I quickly implemented loading said area geometry model and simple area objects. And was baffled. The area geometry&rsquo;s position didn&rsquo;t match up with the objects&#8217; positions. The area was so far in the distance, you couldn&rsquo;t even see it. I looked and searched for a &ldquo;tile&rdquo; position in the area description files&hellip;nothing. As an experiments, I bound moving the area model to keyboard keys, and played around with it until it fit. The correct position, for some reason, is {1500.0, 1500.0, 0.0}. Don&rsquo;t ask me <em>why</em>, but this works for all areas in the game. ¯\_(ツ)_/¯</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150412_WitcherArea6.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150412_WitcherArea6_t.png' width='256' height='160' title='Kaer Morhen exterior' alt='Kaer Morhen exterior'><span class='caption-text'>Kaer Morhen exterior</span></span></a> <a href="https://xoreos.org/images/blog/20150412_WitcherArea7.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150412_WitcherArea7_t.png' width='256' height='160' title='Outskirts of Vizima' alt='Outskirts of Vizima'><span class='caption-text'>Outskirts of Vizima</span></span></a> <a href="https://xoreos.org/images/blog/20150412_WitcherArea8.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150412_WitcherArea8_t.png' width='256' height='160' title='Country Inn' alt='Country Inn'><span class='caption-text'>Country Inn</span></span></a></p>

<h3>Object orientation</h3>

<p>There was another thing I noticed, though: the orientation of the area objects is wrong. Unlike <em>Neverwinter Nights</em>, which only specifies one angle, the &ldquo;bearing&rdquo;, for each object, <em>The Witcher</em> lets you rotate all objects in all three axes. The orientation is described as a <a href="https://en.wikipedia.org/wiki/Quaternion">quaternion</a>. Now, <em>Neverwinter Nights 2</em> does the same and because we need the object orientation in <a href="https://en.wikipedia.org/wiki/Euler_angles">Euler angles</a> instead, we convert them. Unfortunately, that code doesn&rsquo;t seem to work correctly in <em>The Witcher</em>. I assume it&rsquo;s connected to the fact that <em>The Witcher</em> actually fully rotates the objects (while <em>Neverwinter Nights 2</em> only, in effect, rotates around two axes), combined with how xoreos changes the axes around for world objects and additionally needs to translate the coordinate system from Direct3D orientation to OpenGL&rsquo;s.</p>

<p>Try as I might, I couldn&rsquo;t get the correct orientation. After way too much banging my head against the wall, I caved and put that onto the TODO pile. That&rsquo;s something I have to revisit another day.</p>

<h3>Creatures</h3>

<p>&ldquo;Only objects? Where are the creatures, the NPCs, the people?&rdquo;, I hear you ask, imaginary reader. Well, <em>The Witcher</em> doesn&rsquo;t directly describe creatures in the area files. Instead, there are spawn points, and I think the rest is handled by the game scripts. Not something I can do now. No NPCs for now, I&rsquo;m afraid.</p>

<h3>Miscellaneous</h3>

<p>A few bits and pieces I found out or did during this endeavour:</p>

<ul>
<li>I renamed the engine and namespace in xoreos from &ldquo;thewitcher&rdquo;/&ldquo;TheWitcher&rdquo; to &ldquo;witcher&rdquo;/&ldquo;Witcher&rdquo;</li>
<li>I noticed that <em>The Witcher</em>, unlike other Aurora games, encodes all strings in UTF-8. The language IDs are also wildly different. To get these together under one big tent, I changed how xoreos handles languages and encodings</li>
<li><em>The Witcher</em> uses Lua scripts. I already knew that previously. But what I didn&rsquo;t know: it also, additionally, uses the traditional NWScript. That&rsquo;ll be a lot of &ldquo;fun&rdquo; to reimplement&hellip;</li>
<li>I found references to the <a href="http://luaforge.net/projects/luacom/">LuaCOM library</a> in the <em>The Witcher</em> disassembly, which provides Lua bindings for ActiveX components. I <em>really</em>, <em>really</em>, <em>really</em> hope that&rsquo;s unused</li>
</ul>


<p>In conclusion, area loading in <em>The Witcher</em> is now in a similar state to area loading in <em>Neverwinter Nights</em>, <em>Neverwinter Nights 2</em>, <em>Knights of the Old Republic</em>, <em>Knights of the Old Republic II</em> and <em>Jade Empire</em>. It&rsquo;s not flawless, and there&rsquo;s still a lot of things missing, but it&rsquo;s a start. :)</p>

<p>What&rsquo;s next? There&rsquo;s three games left without area support: <em>Dragon Age: Origins</em>, <em>Dragon Age 2</em> and <em>Sonic Chronicles: The Dark Brotherhood</em>. The latter is a Nintendo DS game, and is missing basic support for a lot of DS-specific file formats. In fact, I&rsquo;m still not 100% sure this game even belongs in xoreos&hellip; The two <em>Dragon Age</em> games are somewhat further along: resource loading works and the texture format is known. They are, however, completely missing model support, as well as support for the new GFF version. Since that is at least something to go by, it&rsquo;s possible I&rsquo;ll tackle <em>Dragon Age: Origins</em> next. It could take a while until I have something worthwhile to report, though.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Jade Empire Models and Areas]]></title>
    <link href="https://xoreos.org/blog/2015/02/15/jade-empire-models-and-areas/"/>
    <updated>2015-02-15T16:25:51+01:00</updated>
    <id>https://xoreos.org/blog/2015/02/15/jade-empire-models-and-areas</id>
    <content type="html"><![CDATA[<p>Continuing with my quest to make the engines display areas (as I did <a href="https://xoreos.org/blog/2015/02/01/neverwinter-nights-2-areas/">with <em>Neverwinter Nights 2</em></a>), I turned to <em>Jade Empire</em> the last two weeks. There was just one tiny issue: xoreos didn&rsquo;t yet support the model format. While I could make use of other&rsquo;s people reverse-engineering work for the model formats of other engines (<a href="https://cdn.rawgit.com/xoreos/xoreos-docs/master/specs/torlack/binmdl.html"><em>Neverwinter Nights</em> (Torlack)</a>, <a href="http://nwn2.wikia.com/wiki/MDB_Format"><em>Neverwinter Nights 2</em> (Tazpn)</a> and <a href="https://home.comcast.net/~cchargin/kotor/mdl_info.html"><em>Knights of the Old Republic</em> (cchargin)</a>), apparently barely anybody bothered to look into <em>Jade Empire</em>. <a href="http://www.lucasforums.com/showpost.php?p=2318655&amp;postcount=51">A person called Maian tried to figure out a few thing with just a hexeditor</a>, and while that was a great start (and confirmed my suspicions that the format is similar to <em>Knights of the Old Republic</em>&rsquo;s), it wasn&rsquo;t enough for full support in xoreos.</p>

<p>So, with no other place to look, I buckled down and opened the <em>Jade Empire</em> binary in a disassembler.</p>

<h3>Models</h3>

<p>The loader function was quickly found, and in combination with Maian&rsquo;s findings, the header was a cakewalk. The model nodes, the structures containing the mesh data, however, proved to be more tricky: the engine simply read the whole shebang into memory, to be used later.</p>

<p>Trying to find a shortcut, I remembered that <em>Neverwinter Nights</em> was able to load ASCII representations of its models. I searched for some common keywords like &ldquo;verts&rdquo; and &ldquo;faces&rdquo;. I had luck: there still is a ASCII model loader in <em>Jade Empire</em>, and not just a remnant of older code; it was updated to load ASCII representations of <em>Jade Empire</em> models. Moreover, for the most part, it actually parsed the model values into the same struct it reads the binary data into. Meaning: I could directly map data from the model file to their ASCII name, getting their meaning handed on a platter.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150215_ModelParseHeader.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_ModelParseHeader_t.png' width='256' height='205' title='Parsing the Binary Model Header' alt='Parsing the Binary Model Header'><span class='caption-text'>Parsing the Binary Model Header</span></span></a> <a href="https://xoreos.org/images/blog/20150215_ModelParseNodeType.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_ModelParseNodeType_t.png' width='256' height='205' title='Parsing the Node Type' alt='Parsing the Node Type'><span class='caption-text'>Parsing the Node Type</span></span></a> <a href="https://xoreos.org/images/blog/20150215_ModelParseTriMesh.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_ModelParseTriMesh_t.png' width='256' height='205' title='Parsing an ASCII TriMesh Node' alt='Parsing an ASCII TriMesh Node'><span class='caption-text'>Parsing an ASCII TriMesh Node</span></span></a></p>

<h3>Untextured Geometry</h3>

<p>This basically gave me the entirety of the general node header, and a good part of the TriMesh node (that contain model geometry in form of a triangle mesh) header. What it did not help with was the format of the vertex data and face indices; those were parsed into a different structure.</p>

<p>Chasing down the place where the binary data was put into that structure wasn&rsquo;t too difficult, and soon I had enough information to render basic, untextured geometry:</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150215_Untextured.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_Untextured_t.png' width='256' height='192' title='Untextured Geometry' alt='Untextured Geometry'><span class='caption-text'>Untextured Geometry</span></span></a></p>

<h3>Materials and Textures</h3>

<p>While there was a texture field in the TriMesh node, I found it was more often then not empty. Instead, there was a numerical material field, and a matching .mab file in the resource. A material definition in binary format. I also found several .mat files in the resources, ASCII material definitions. Trying my luck again for finding a loader of these in the binary, I searched for the string in the disassembly, and yes: there is a loader for the ASCII material files, parsing them into exactly the layout of the binary .mab files.</p>

<p>With that, and some fiddling with the offset into the vertex structure for the texture coordinates, I managed to render textured geometry:</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150215_Textured.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_Textured_t.png' width='256' height='192' title='Textured Geometry' alt='Textured Geometry'><span class='caption-text'>Textured Geometry</span></span></a></p>

<h3>Triangle lists, strips and fans, oh my!</h3>

<p>People familiar with <em>Jade Empire</em> might recognize that model: that&rsquo;s <a href="http://jadeempire.wikia.com/wiki/Silk_Fox">Silk Fox</a> (SPOILER WARNING on that link!). And for some reason, she usually wears a veil in front of face. So, where&rsquo;s that veil?</p>

<p>Turns out, while meshes in <em>Knights of the Old Republic</em>&rsquo;s models are always triangle lists (simple, unconnected triangles), <em>Jade Empire</em> models also contain other mesh types: <a href="https://en.wikipedia.org/wiki/Triangle_strip">triangle strips</a> and <a href="https://en.wikipedia.org/wiki/Triangle_fan">triangle fans</a>. For the sake of simplicity, I decided to unroll them into triangle lists for now, and that made the veil visible:</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150215_Veil.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_Veil_t.png' width='256' height='192' title='Veil'd' alt='Veil'd'><span class='caption-text'>Veil&rsquo;d</span></span></a></p>

<h3>Now, about that vertex structure&hellip;</h3>

<p>I said above that I fiddled a bit to find the texture coordinates inside the vertex structure. Well, in fact, what I did was a big, fat hack: I hard-coded the offset based on the size of the structure. Obviously, that&rsquo;s wrong. And it did fail for a lot of models, most prominently the models used for the area geometry.</p>

<p>Wasting quite some time trying to find how the vertex structure is interpreted in the disassembly (and even trying to trace it with <a href="https://www.winehq.org/site/docs/winedev-guide/dbg-commands">WineDbg</a>), I eventually found the answer where I should have looked way earlier: in the <em>Knights of the Old Republic</em> model loader. Since the two model formats are similar, I could just apply what the one did to find the offset in the other. With that, the area geometry renders more correctly:</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150215_AreaModel.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_AreaModel_t.png' width='256' height='192' title='Area Model' alt='Area Model'><span class='caption-text'>Area Model</span></span></a></p>

<p>Please note a few things. Yes, not all fields in the material definition are used yet (in fact, only the 4 base textures are used). As such, the rendering looks a bit off, especially where environment mapping should happen. That&rsquo;s why the roof is semi-transparent, for example.</p>

<p>Also, while I did find the offsets for the textures, I&rsquo;m not yet sure about the other pieces of data. Specifically, the normals and data found after the texture offsets. For example, take a look at this hexdump of the vertex array for Silk Fox&rsquo;s head (click for a bigger view):</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150215_VertexData.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_VertexData_t.png' width='256' height='192' title='Vertex Data for Silk Fox's Head' alt='Vertex Data for Silk Fox's Head'><span class='caption-text'>Vertex Data for Silk Fox&rsquo;s Head</span></span></a></p>

<p>Each colored section is a new vertex. The red box, i.e. the first twelve bytes of each vertex, is the vertex position, stored as 3 <a href="https://en.wikipedia.org/wiki/IEEE_floating_point">IEEE floats</a> in <a href="https://en.wikipedia.org/wiki/Endianness">little endian</a> byte order. The green box, i.e. 8 bytes at offset 0x14 within each vertex, is the first set of texture coordinates, stored as 2 IEEE floats.</p>

<p>Now, the field that in <em>Knights of the Old Republic</em> models denote the offset to the normals, points to 0xC. Unfortunately, there&rsquo;s only space for 2 floats here, while the normal usually needs 3 floats. I have frankly no idea what&rsquo;s going in there. In the case of the first vertex, the data could intentionally overlap, since the 0.0f would fit, but that breaks down not much later.</p>

<p>The data after the texture coordinates looks pretty un-floaty, more like several uint16 values. Again, no idea what that could be yet.</p>

<p>I am, of course, always open to suggestions if <em>you</em> should know what this could mean. :)</p>

<p>In either case, this brings <em>Jade Empire</em> model support close to the other model formats. I found that enough for now; I did spent about 50 hours staring at disassembly to get this far, after all.</p>

<h3>Areas</h3>

<p>Like a lot of things, areas in <em>Jade Empire</em> are structurally similar to areas in <em>Knights of the Old Republic</em>. A .lyt file specifies the layout: the positions of several models (called &ldquo;rooms&rdquo;) that make up the area geometry. And a .vis file specifies which rooms is visible from where, so that, in-game, rooms that are not visible from the current location can be culled from the render queue.</p>

<p>Unlike <em>Knights of the Old Republic</em> (and also unlike <em>Neverwinter Nights</em>), the <em>Jade Empire</em> areas don&rsquo;t have .are and .git files to describe static and dynamic elements of the area, like the name, the music playing in the background, and objects and creatures found within. Instead, there&rsquo;s another array in the .lyt file for simple, state-machine driven objects like doors, and an .art file gives some general information for each room (mostly wind, fog, camera perspective). Everything else seems to be placed or started by the game scripts.</p>

<p>A script system is not something I want to bind to the <em>Jade Empire</em> engine just yet, but loading the layout file and placing the room models, that I can do:</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150215_TwoRivers.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_TwoRivers_t.png' width='256' height='160' title='Two Rivers School' alt='Two Rivers School'><span class='caption-text'>Two Rivers School</span></span></a> <a href="https://xoreos.org/images/blog/20150215_TeaHouse.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_TeaHouse_t.png' width='256' height='160' title='Tien's Landing Tea House' alt='Tien's Landing Tea House'><span class='caption-text'>Tien&rsquo;s Landing Tea House</span></span></a></p>

<p>Again, the same caveats as above apply: no proper material support yet. And due to these issues of missing environment mapping and wrong blending, those two screenshots are actually less ugly than others. See for yourselves:</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150215_TiensLanding.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_TiensLanding_t.png' width='256' height='160' title='Broken Transparency Masking' alt='Broken Transparency Masking'><span class='caption-text'>Broken Transparency Masking</span></span></a> <a href="https://xoreos.org/images/blog/20150215_Heaven.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_Heaven_t.png' width='256' height='160' title='Drawing Order vs Translucent Mesh' alt='Drawing Order vs Translucent Mesh'><span class='caption-text'>Drawing Order vs Translucent Mesh</span></span></a> <a href="https://xoreos.org/images/blog/20150215_Mind.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150215_Mind_t.png' width='256' height='160' title='Bug in a Texture Loader?' alt='Bug in a Texture Loader?'><span class='caption-text'>Bug in a Texture Loader?</span></span></a></p>

<p>Still, apart from the missing NPCs and objects, <em>Jade Empire</em> areas are now in a similar state to areas in <em>Knights of the Old Republic</em>. That counts for something, no? :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Neverwinter Nights 2 Areas]]></title>
    <link href="https://xoreos.org/blog/2015/02/01/neverwinter-nights-2-areas/"/>
    <updated>2015-02-01T16:10:00+01:00</updated>
    <id>https://xoreos.org/blog/2015/02/01/neverwinter-nights-2-areas</id>
    <content type="html"><![CDATA[<p>During the last 2 weeks, I implemented basic support for <em>Neverwinter Nights 2</em> areas and campaigns/modules. In particular:</p>

<ul>
<li>Reading the list of modules and the starting module in a campaign</li>
<li>Reading module areas and starting conditions</li>
<li>Loading general area information like music</li>
<li>Loading area geometry and objects

<ul>
<li>Tiles</li>
<li>Terrain</li>
<li>Doors</li>
<li>Placeables</li>
<li>Environmental objects</li>
<li>Creatures</li>
</ul>
</li>
<li>Flying through the areas in a &ldquo;spectator mode&rdquo;</li>
<li>Highlighting potentially useable objects</li>
<li>Hooking up a debug console

<ul>
<li>listcampaign/loadcampaign commands</li>
<li>listmodules/loadmodule commands</li>
<li>listareas/gotoarea commands</li>
</ul>
</li>
</ul>


<p>As a result, areas in <em>Neverwinter Nights 2</em> are now in a similarly supported state as areas in the two <em>Knights of the Old Republic</em> games.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150201_IndoorOverview.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150201_IndoorOverview_t.png' width='256' height='160' title='Indoor Area' alt='Indoor Area'><span class='caption-text'>Indoor Area</span></span></a> <a href="https://xoreos.org/images/blog/20150201_OutdoorOverview.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150201_OutdoorOverview_t.png' width='256' height='160' title='Outdoor Area' alt='Outdoor Area'><span class='caption-text'>Outdoor Area</span></span></a></p>

<p>So, here&rsquo;s a few interesting things and/or issues with them.</p>

<h3>Tiles and Metatiles</h3>

<p>Like the first <em>Neverwinter Nights game</em>, areas in <em>Neverwinter Nights 2</em> are (or can be, more about that later) made up of tiles. Meaning, a grid of models define the general structure: piece of indoors floor with walls, corners, windows and/or doors. Unlike the first game, though, there&rsquo;s also metatitles, which are bigger models spanning the space of several regular tiles. This is used, for example, for the piece of the cave where you wake up in the <em>Mask of the Betrayer</em> expansion.</p>

<p>xoreos correctly loads and displays both tiles and metatiles.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150201_MetaTiles.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150201_MetaTiles_t.png' width='256' height='160' title='Metatile in MotB' alt='Metatile in MotB'><span class='caption-text'>Metatile in MotB</span></span></a></p>

<h3>Terrain</h3>

<p>Also unlike the first game, areas in the second game can also use terrain instead (or maybe even additionally to) tiles. The terrain is floor geometry unique to the area, and consists of patches of land and water, together with walk mesh definitions. Terrain is used very often in outdoor areas, to give those areas a more unique and less flat feeling.</p>

<p>xoreos correctly loads and displays the land and water patches, in a very rudimentary and stubby way.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150201_Terrain.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150201_Terrain_t.png' width='256' height='160' title='Terrain Geometry' alt='Terrain Geometry'><span class='caption-text'>Terrain Geometry</span></span></a></p>

<h3>Environmental Object</h3>

<p><em>Neverwinter Nights 2</em> adds a new area object type: environmental objects. These seem to be quite similar to regular placeables, only that they are static and can&rsquo;t ever be moved. Apparently, their geometry is also baked into the area walk meshes.</p>

<p>As an extra weird bit, environmental objects store their position and orientation differently than all the other objects.</p>

<p>xoreos correctly loads and displays environmental objects in areas.</p>

<h3>Trees</h3>

<p><em>Neverwinter Nights 2</em> also adds new, non-static trees, courtesy of the <a href="https://en.wikipedia.org/wiki/SpeedTree">SpeedTree middleware</a>. Tree definitions seem to consist of just a few parameters and a random seed, the rest is done by the SpeedTree library.</p>

<p>xoreos does <strong>not</strong> load or display those trees yet. In fact, that will be a major task in the future. Luckily, trees aren&rsquo;t essential; them missing is not a showstopper.</p>

<h3>Creature Models and Animations</h3>

<p>xoreos also partially loads and displays the various creatures (animals, NPCs, monsters, &hellip;) defined in the area files. There&rsquo;s one caveat, though: the different model parts (head, hair, gloves, boots) aren&rsquo;t actually attached to the body yet. They&rsquo;re loaded as separate models and those are already placed correctly for default character dimensions. Of course, this would fail with scaled models (which we do not yet support).</p>

<p>The underlying problem is this: where the character models in <em>Neverwinter Nights</em> and <em>Knights of the Old Republic</em> contain special nodes telling the engine where to place the different body parts, <em>Neverwinter Nights 2</em> has no such thing. Instead, each skin geometry vertex has a &ldquo;bone index&rdquo; attribute that, I assume, are indices into the <a href="https://en.wikipedia.org/wiki/RAD_Game_Tools">Granny 3D</a> animation files.</p>

<p>Which means: to properly attach the body parts, and to animate the models, we first need to figure those files out.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150201_CreatureModels.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150201_CreatureModels_t.png' width='256' height='160' title='Bounding Boxes of the Model Parts' alt='Bounding Boxes of the Model Parts'><span class='caption-text'>Bounding Boxes of the Model Parts</span></span></a></p>

<h3>Tile and Object Tinting</h3>

<p>A lot of objects in <em>Neverwinter Nights 2</em> areas use <a href="http://www.rwscreations.com/RWSForum/viewtopic.php?f=18&amp;t=727">tint maps</a>. These are special textures with intensity values in their color channels. When an object is loaded from the area definition, those also contain 3 color values, and those color values are combined with the intensity values in the tint map to create a unique tinting of the object. This gives you the ability to create blue-ish caskets with yellow-ish metal rings, purple carpets, green vases and the like, without having to manually create textures for each color combination.</p>

<p>Moreover, tiles also use this tinting.</p>

<p>Currently, xoreos can evaluate and use those tinting, but entirely in software. For each object, an uncompressed RGBA texture is created, and the color values are mixed on loading. Of course, this has certain drawbacks:</p>

<p>First of all, it&rsquo;s slow. But more damning, it takes up a lot of extra memory, both on the GPU and in the system&rsquo;s RAM. As a ballpark, a common large-ish area creates 1GB of extra textures; even more when there&rsquo;s a lot of objects around.</p>

<p>This is, of course, unacceptable. In the future, this tinting should most probably be done with shaders on the GPU.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150201_TintWithout1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150201_TintWithout1_t.png' width='256' height='160' title='Without Tinting' alt='Without Tinting'><span class='caption-text'>Without Tinting</span></span></a> <a href="https://xoreos.org/images/blog/20150201_TintWith1.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150201_TintWith1_t.png' width='256' height='160' title='With Tinting' alt='With Tinting'><span class='caption-text'>With Tinting</span></span></a></p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150201_TintWithout2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150201_TintWithout2_t.png' width='256' height='160' title='Without Tinting' alt='Without Tinting'><span class='caption-text'>Without Tinting</span></span></a> <a href="https://xoreos.org/images/blog/20150201_TintWith2.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150201_TintWith2_t.png' width='256' height='160' title='With Tinting' alt='With Tinting'><span class='caption-text'>With Tinting</span></span></a></p>

<h3>Terrain Tinting</h3>

<p>There is another tinting mechanism: terrain geometry uses a similar approach, only more extended. Instead of just 3 mix channels, there&rsquo;s 6 (using 2 mixing textures) and instead of just mixing colors, textures are mixing. I.e.: a terrain patch can specify up to 6 texture that will be mixed according to the color values in 2 mix textures. The result is a layered texture that removes all visible texture tiling effects.</p>

<p>Additionally, each patch also has a color value to modify the texture, increasing the flexibility again.</p>

<p>At the moment, xoreos does none of this, for obvious reasons. Instead, the singular color value is applied to each patch, creating a more flat look.</p>

<h3>Doors and Chests</h3>

<p>Currently, xoreos does not display most doors and chests entirely correctly: doors are missing their, well, door part (only the door frame and knob are visible) and chests are missing their lid. I have no idea if that&rsquo;s connected to the animation system, tinting, or what.</p>

<p style="text-align:center;"> <a href="https://xoreos.org/images/blog/20150201_DoorsChests.png"><span class='caption-wrapper'><img class='caption' src='https://xoreos.org/images/blog/20150201_DoorsChests_t.png' width='256' height='160' title='Broken Door and Chest' alt='Broken Door and Chest'><span class='caption-text'>Broken Door and Chest</span></span></a></p>

<p>All in all, I&rsquo;m pretty happy with the progress so far. :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Farewell to the Neverwinter Nights Podcast]]></title>
    <link href="https://xoreos.org/blog/2014/12/02/a-farewell-to-the-neverwinter-nights-podcast/"/>
    <updated>2014-12-02T08:31:00+01:00</updated>
    <id>https://xoreos.org/blog/2014/12/02/a-farewell-to-the-neverwinter-nights-podcast</id>
    <content type="html"><![CDATA[<p>Unbeknownst to me, the <a href="http://www.nwnpodcast.com/">Neverwinter Nights Podcast</a>, the podcast where I had <a href="https://xoreos.org/blog/2014/04/23/interview-for-the-neverwinter-nights-podcast/">my first and so far only interview</a>, recorded its last episode in August. While I was not a frequent listener, I am still sad to see it go. So with some melancholy in my heart, I thank Brian S. Bloom, Ben H., Mark Shook and the rest of the crew for their work (and their continued shout-outs to the xoreos project) and wish them the best of luck in their future.</p>

<p>If a story-driven Neverwinter Nights 2 persistent world is your thing, please have a look at their&rsquo;s, <a href="http://www.realmsoftrinity.com/">Realms of Trinity</a>, and consider <a href="http://www.realmsoftrinity.com/Donations.aspx">supporting them</a>. Thanks.</p>

<p>The Neverwinter Nights Podcast website might go offline in May 2015, so I took the liberty of mirroring <a href="https://xoreos.org/audio/NWNP-00192.mp3">the episode with my interview here</a>. You can find the original text accompanying the interview below.</p>

<hr />

<p><img src="https://xoreos.org/images/nwn-episode192_feature.jpg" alt="Neverwinter Nights Podcast Episode 192 - Project Xoreos" /></p>

<p>Please join Mark AKA Madmage999 and Brian AKA Sir Brian, from <a href="http://www.realmsoftrinity.com/">NWN2 Realms of Trinity</a>, as they interview the lead developer of the <a href="https://xoreos.org/">Xoreos</a> project, Sven AKA Dr. McCoy.</p>

<p><a href="https://xoreos.org/audio/NWNP-00192.mp3">Neverwinter Nights Podcast Episode 192</a></p>

<p><strong>xoreos</strong> is an ongoing FLOSS project to reimplement BioWare (and derivatives) as used in their 3D games, beginning with Neverwinter Nights. The goal is to have a portable program to play those games even on operating systems those games were never meant to be played on, such as GNU/Linux and Mac OS X.</p>

<h4>How is it licensed?</h4>

<p>xoreos is free software and licensed under the terms of the GNU General Public License version 3 or later (GPLv3+).</p>

<h4>A note about piracy</h4>

<p>To use xoreos to run the games, you have own the original game media. We do not endorse piracy in any way, shape or form.</p>

<h4>What does currently work?</h4>

<p>In its current state, xoreos is still far away from its goal. At the moment, we are able to load resource archives and read basic file formats. Video and sound playing works, models are partially supported, and for earlier games, areas are shown and even some very basic gameplay exists.</p>

<h4>What is left to do?</h4>

<p>A lot of work is still left to do. We are actively looking for developers interested in joining our efforts in taking apart BioWare games and reimplementing them. If that sounds something you would find exciting and feel capable of, please contact us. We are always happy to see new faces. :)</p>

<p>The most pressing matter, however, is finding a person with knowledge of OpenGL: The current graphics subsystem is barebones and was quickly hacked together without much deeper understanding. If works for what is shown right now, but is far from being anywhere near adequate. There are a lot of features missing, and the performance is nothing to be proud of. Again, we would be very glad to welcome you in our still small team!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Not-Thanksgiving]]></title>
    <link href="https://xoreos.org/blog/2014/11/29/not-thanksgiving/"/>
    <updated>2014-11-29T12:58:00+01:00</updated>
    <id>https://xoreos.org/blog/2014/11/29/not-thanksgiving</id>
    <content type="html"><![CDATA[<p>I am not an US-citizen, but nevertheless, I think the time is right for an introspective blog post about the progress and general state of the xoreos project and what I am thankful for. Oh, and no worries, I&rsquo;m not throwing the towel here. :)</p>

<p>So, let&rsquo;s start with what has happened: there has been quite some work and changes and fixes under the hood. Not as much as I&rsquo;d like, and no hugely visible new features yet, but still.</p>

<p>On the code side, we have:</p>

<ul>
<li>BZF:
Added support for BZF archives, used in the <a href="https://itunes.apple.com/en/app/star-wars-knights-old-republic/id611436052">iOS version of Knights of the Old Republic</a>. Basically, these are your standard <a href="https://github.com/xoreos/xoreos-docs/raw/master/specs/bioware/KeyBIF_Format.pdf">BIF archives</a>, but the data inside is compressed using <a href="https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Markov_chain_algorithm">LZMA</a>.</li>
<li>WMA:
Fixed a crash in the WMA decoder occurring in some audio files found in the Xbox version Knights of the Old Republic.</li>
<li>FilePath and FileList cleanup:
Lots of cleanup and restructuring in these utility classes handling paths, file names and lists of these.</li>
<li>Rewrote absolutize(), relativize(), normalize(), canonicalize():
These functions operate on path. They create absolute paths from relative paths and vice versa, normalized (resolving ambiguities like &ldquo;/./&rdquo;) or canonicalized (stronger disambiguities including symbolic links) versions. As a result, paths in the config file now properly resolve ~/ to the user&rsquo;s home directory.</li>
<li>ConfigDir and UserDir:
Changed the location of the config file on GNU/Linux to $XDG_CONFIG_HOME/xoreos/xoreos.conf (i.e. following the <a href="http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html">XDG Base Directory Specification</a>) and on Mac OS X to ~/Library/Preferences/xoreos/xoreos.conf. Likewise, the default log path is now $XDG_DATA_HOME/xoreos/xoreos.log on GNU/Linux and ~/Library/Application Support/xoreos/xoreos.log on Mac OS OX. On Windows, they are still in $APPDATA/xoreos/.</li>
<li>UNUSED:
Added an UNUSED macro to mark deliberately unused function parameters and enabled the compiler flag to warn about unused function parameters without this macro. This helps find places where the lack of usage was in error.</li>
<li>Icon:
Embedded the <a href="https://github.com/xoreos/xoreos-media/blob/master/icons/svg/icon-grey.svg">xoreos icon</a> into the executable to be displayed in the standard application icon of the operating system.</li>
<li>Loading progress:
Added a progress bar <a href="https://xoreos.org/images/xoreos_progressbar.png">visualizing</a> the game loading stages at startup.</li>
<li>Split docs / tools repo:
I split the xoreos-docs repository from the xoreos-tools repository. Both are now clean standalone repositories.</li>
</ul>


<p>Additionally, I started working on another little tool: <a href="https://github.com/xoreos/phaethon">Phaethon</a>. Phaethon is a graphical resource explorer (using <a href="https://www.wxwidgets.org/">wxWidgets</a>) for BioWare Aurora engine games, able to look into the archives, extract files, display images and play audio files. It&rsquo;s not yet finished, and there&rsquo;s several things left to implement, including displaying <a href="https://github.com/xoreos/xoreos-docs/blob/master/specs/bioware/GFF_Format.pdf">GFF files</a>. The goal is to have a more user-friendly, GUI companion to the existing <a href="https://github.com/xoreos/xoreos-tools">CLI xoreos tools</a>.</p>

<p>There has also been several improvements on the documentation side of things:</p>

<ul>
<li>Clarified the license on our <a href="https://github.com/xoreos/xoreos/tree/master/m4">custom m4 macros</a>:
They&rsquo;re all released under the terms of the CC0 license now.</li>
<li>Fixed the wrong-headed BioWare &ldquo;copyright&rdquo; notices:
Instead, we now properly <a href="https://github.com/xoreos/xoreos/blob/master/AUTHORS#L36">identify trademarks</a> registered and/or used by BioWare and others.</li>
<li>CONTRIBUTING:
Added a proper <a href="https://github.com/xoreos/xoreos/blob/master/CONTRIBUTING.md">CONSTRIBUTING.md</a> file explaining how to contribute to the project.</li>
<li>Wiki:
Added articles in <a href="https://wiki.xoreos.org/">our wiki</a> explaining <a href="https://wiki.xoreos.org/index.php?title=Compiling_xoreos">how to compile xoreos</a> and <a href="https://wiki.xoreos.org/index.php?title=Running_xoreos">how to run and configure xoreos</a>. Also added a collection of links hopefully providing some <a href="https://wiki.xoreos.org/index.php?title=Developer_Central#Reverse_engineering_help">introduction to reverse engineering</a>.</li>
</ul>


<p>As you can see, this is quite a list. And that&rsquo;s only half of the story. Leading to what (or, more precisely, <em>who</em>) I am thankful for, there&rsquo;s been contributions by several incredible people:</p>

<ul>
<li>I am thankful to <a href="https://github.com/ImperatorPrime">ImperatorPrime</a>, for wrangling the <a href="https://travis-ci.org/xoreos/xoreos">Travis CI</a> integration. This also helped me in setting up a more comfortable, semi-automatic <a href="https://scan.coverity.com/projects/544">Coverity Scan</a> integration.</li>
<li>I am thankful to <a href="https://github.com/Supermanu">Supermanu</a>, for improving on the Neverwinter Nights GUI code and for continuing to implement the Neverwinter Nights character generator.</li>
<li>I am thankful to <a href="https://github.com/mirv-sillyfish">mirv</a>, for starting to tackle the monumental task of rewriting the graphics subsystem. I&rsquo;m looking forward to seeing this evolve, so that we can finally put my naive OpenGL code out of its misery.</li>
<li>I am thankful to <a href="http://clone2727.blogspot.com/">clone2727</a>, for all his insights and advice over the years, for always having an open ear for my complaints and rants.</li>
<li>I am thankful to all the other people providing me with help, with tips, bug reports, bug fixes, file format information, existing modding tools, Aurora engine knowledge, complaints, offers to contribute, etc., etc., etc.</li>
</ul>


<p>There, this is what&rsquo;s happened in the last 7 month since the last blog post; this is the current state of the project. Looking forward, here&rsquo;s hoping that we all continue to find time to work on xoreos, that maybe more people will join us and that together, we can make this project bloom into something wonderful.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Interview for the Neverwinter Nights Podcast]]></title>
    <link href="https://xoreos.org/blog/2014/04/23/interview-for-the-neverwinter-nights-podcast/"/>
    <updated>2014-04-23T09:53:00+02:00</updated>
    <id>https://xoreos.org/blog/2014/04/23/interview-for-the-neverwinter-nights-podcast</id>
    <content type="html"><![CDATA[<p>This past Saturday, I was being <a href="http://www.nwnpodcast.com/nwnp/2014/04/22/nwnp-podcast-episode-192-xoreos-an-open-source-reimplementation-of-the-bioware-aurora-engine/">interviewed for the Neverwinter Nights Podcast about the xoreos project</a>. I talked a bit how this project got started, what I&rsquo;m focusing on and about the current situation.</p>

<p>Not being used to being interviewed, or speaking English for that matter, my nervousness is quite audible. But I hope I still got my points across. :)</p>

<p>So, if you&rsquo;re interested, <a href="http://www.nwnpodcast.com/nwnp/2014/04/22/nwnp-podcast-episode-192-xoreos-an-open-source-reimplementation-of-the-bioware-aurora-engine/">give it a listen</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[New Wiki]]></title>
    <link href="https://xoreos.org/blog/2013/08/05/new-wiki/"/>
    <updated>2013-08-05T10:11:00+02:00</updated>
    <id>https://xoreos.org/blog/2013/08/05/new-wiki</id>
    <content type="html"><![CDATA[<p>At the suggestion of <a href="https://github.com/ImperatorPrime">ImperatorPrime</a> I should set up a MediaWiki: <a href="https://wiki.xoreos.org/">https://wiki.xoreos.org/</a>. The sidebar link has also been updated to reflect the change.</p>

<p>This will hopefully be more flexible than the GitHub wiki, and will allow easy contributions by people outside of GitHub. The idea is that this will become a knowledge hub into the internals of BioWare&rsquo;s Aurora engine. Any interesting things anyone has found out, we&rsquo;ll be glad to have documented here. So please, if you feel the need to crawl deep into the bowls of the Aurora engine, or have already done so, add your newly-found understanding to our wiki. :)</p>

<p>We will be migrating the GitHub wiki pages to our wiki, and see about adding some new information as well, in the following days.</p>
]]></content>
  </entry>
  
</feed>
