Blade Posted February 9, 2016 Share Posted February 9, 2016 Okay, so we recently wrote a MapClass implementation as part of our drive to get map drawing done. This handles the cell grid and a bunch of stuff relating to it and with a bit of glue code it might be enough to get a basic map renderer on the go. In the game its one of the lower classes in a hierarchy of inherited classes that control all the aspects of the in game UI, so to get something basic drawing as it does in the game, there is still a bit of work ahead. After that we've taken a change of pace into some code that we previously investigated, but struggled to get a working implementation going. The code in question is the internal "Multi Precision Integer" library that is used to do the RSA part of the mix header encryption. Now we have header decryption working as it is using an embedded library, but if we stay with that library we are bound to its license terms so really we wanted our own version of the games internal "XMP" library. In fact the code everyone and their dog uses to handle the encrypted headers, the XCC decryption code, is pretty much already the code from the game reversed to C. It has problems however, for a start, GCC seems to hate compiling it with optimizations. Secondly, its not big endian friendly which might harm future attempts to port the code to systems other than x86. For all these reasons we started writing our own implementations and its pretty straight forward like doing long addition, subtraction, multiplication and such like you learned at school only with each "place" in the number being a 32bit int rather than 0-9. It all went well until we got to the "modular" operators, specifically modular multiplication. If you've ever looked into the XCC code, this is done by a function called calc_a_bignum there, but its really the Thad Smith Modular Multiplication algorithm as far as we can tell. In fact it looks like the WW coders were heavily influenced in their algorithm choice by the PGP algorithms (presumably as that was one of the few crypto libraries with available source at the time). It does some crazy bit shift magic to speed up calculating this value and even in the PGP code it is hard to follow, much less the XCC code version. So crazy in fact that currently we still can't get a fully 32bit version to work, we've had to resort to a simpler algorithm based on long division to calculate the modulo of the multiplication result. Its not as fast, but it does mean that we finally have a home grown "Multiple Precision" library that can decode mix file headers. Now, back to those scenario hierarchy classes.... Edit: I've managed to implement an alternative to the Thad Smith algorithm that is still fast, so another external library dependency is definitely eliminated. Link to comment Share on other sites More sharing options...
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!Register a new account
Already have an account? Sign in here.Sign In Now