07-17-2012, 01:13 PM
So in case anyone is curious about how the Marti implemented randomness in lf2, well it's magic :p.
To get the rand() function working in the AI stuff we had to use lf2 seeds rather than our own, so that when replays get loaded our rand functions give the same values as when the game was first played.
Anyway, the random function is located at 00417170. Here it is reversed:
Slightly different than the original, the original accepts 2 parameters instead of one, but doesn't use one because magic.
Anyway, gotta love marti and his crazy implementations. %1234 , %3000 ... Arbitrary numbers ftw!
To get the rand() function working in the AI stuff we had to use lf2 seeds rather than our own, so that when replays get loaded our rand functions give the same values as when the game was first played.
Anyway, the random function is located at 00417170. Here it is reversed:
C-Code:
int random(int max){//random function that works with replays int result; // eax@2 signed int v3; // eax@3 DWORD &dword_450C34 = *((DWORD *)0x450C34); DWORD &dword_450BCC = *((DWORD *)0x450BCC); if ( max > 0 ){ dword_450C34 = (dword_450C34 + 1) % 1234; v3 = dword_450C34 + (unsigned __int8)*(((BYTE *)0x44FF90) + (dword_450BCC + 1) % 3000); dword_450BCC = (dword_450BCC + 1) % 3000; result = v3 % max; }else{ result = 0; } return result; } |
Slightly different than the original, the original accepts 2 parameters instead of one, but doesn't use one because magic.
Anyway, gotta love marti and his crazy implementations. %1234 , %3000 ... Arbitrary numbers ftw!
10 ʏᴇᴀʀs sɪɴᴄᴇ ɪʀᴄ ɢᴏᴏᴅ.ɪ ᴡᴀʟᴋ ᴛʜʀᴏᴜɢʜ ᴛʜᴇ ᴇᴍᴘᴛʏ sᴛʀᴇᴇᴛs ᴛʀʏɪɴɢ ᴛᴏ ᴛʜɪɴᴋ ᴏғ sᴏᴍᴇᴛʜɪɴɢ ᴇʟsᴇ ʙᴜᴛ ᴍʏ ᴘᴀᴛʜ ᴀʟᴡᴀʏs ʟᴇᴀᴅs ᴛᴏ ᴛʜᴇ ɪʀᴄ. ɪ sᴛᴀʀᴇ ᴀᴛ ᴛʜᴇ sᴄʀᴇᴇɴ ғᴏʀ ʜᴏᴜʀs ᴀɴᴅ ᴛʀʏ ᴛᴏ sᴜᴍᴍᴏɴ ᴛʜᴇ ɢᴏᴏᴅ ɪʀᴄ. ɪ ᴡᴀᴛᴄʜ ᴏᴛʜᴇʀ ɪʀᴄ ᴄʜᴀɴɴᴇʟs ʙᴜᴛ ɪᴛ ɪs ɴᴏ ɢᴏᴏᴅ. ɪ ᴘᴇsᴛᴇʀ ᴢᴏʀᴛ ᴀɴᴅ ᴛʀʏ ᴛᴏ ʀᴇsɪsᴛ ʜɪs sᴇxɪɴᴇss ʙᴜᴛ ɪᴛ ɪs ᴀʟʟ ᴍᴇᴀɴɪɴɢʟᴇss. ᴛʜᴇ ᴇɴᴅ ɪs ɴᴇᴀʀ.ɪ ᴛʜᴇɴ ᴜsᴜᴀʟʟʏ ʀᴇᴀᴅ sᴏᴍᴇ ᴏʟᴅ ɪʀᴄ ʟᴏɢs ᴀɴᴅ ᴄʀʏ ᴍʏsᴇʟғ ᴛᴏ sʟᴇᴇᴘ.