GEN
From OHRRPGCE-Wiki
The lump with the extension .GEN is a critical one. It contains miscelaneous information about a wide varitey of unrelated things, especially max number of records for other files, password information, and other stuff that I felt like sticking in there too-- some of which really don't belong.
This lump is stored in BSAVE format. It has a 7 byte header which indicates the size of the remaining data (and other things). See BSAVE Header for more information.
The following is the meaning of each element.
| Grey fields are obsolete or unused. |
| Pink fields are runtime-only fields used by GAME that do not really belong GEN in the first place, but are there anyway to make including them in SAV files more convenient |
| Blue fields are editor-only fields used by CUSTOM (although some of them, like 39 genMaxTextbox may be used by GAME for error-checking) |
| Green records are preserved in SAV files. |
| Element | Data | Constant | Meaning |
|---|---|---|---|
| 0 | INT | genMaxMap | max maps |
| 1 | INT | genTitle | title screen backdrop index in MXS |
| 2 | INT | genTitleMus | title music |
| 3 | INT | genVictMus | victory music + 1 (0 for none) |
| 4 | INT | genBatMus | default battle music |
| 5 | INT | genPassVersion | passcode format number |
| 6 | INT | genPassRot | new(third-style) passcode rotator |
| 7-15 | BYTE*17 +1 | new(third-style) obfuscated passcode + 1 unused byte | |
| 16-25 | INT*10 | old-old(first-style) obsolete password data | |
| 26 | INT | genMaxHeroPic | max hero graphics in PT0 |
| 27 | INT | genMaxEnemy1Pic | max small enemy graphics in PT1 |
| 28 | INT | genMaxEnemy2Pic | max med enemy graphics in PT2 |
| 29 | INT | genMaxEnemy3Pic | max large graphics in PT3 |
| 30 | INT | genMaxNPCPic | max npc graphics in PT4 |
| 31 | INT | genMaxWeaponPic | max weapon graphics in PT5 |
| 32 | INT | genMaxAttackPic | max attack graphics in PT6 |
| 33 | INT | genMaxTile | max tilesets in TIL |
| 34 | INT | genMaxAttack | max attack definitions in DT6 |
| 35 | INT | genMaxHero | max hero definitions in DT0 |
| 36 | INT | genMaxEnemy | max enemy definitions in DT1 |
| 37 | INT | genMaxFormation | max formations in FOR |
| 38 | INT | genMaxPal | max palettes in PAL |
| 39 | INT | genMaxTextbox | max text boxes in SAY |
| 40 | INT | genMaxPlotscript | total available plotscripts (number of records in PLOTSCR.LST) |
| 41 | INT | genNewgameScript | ID of new-game plotscript |
| 42 | INT | genGameoverScript | ID of game-over plotscript |
| 43 | INT | genMaxRegularScript | ID of highest manually numbered old-style plotscript |
| 44 | INT | genSuspendBits | suspendstuff bits |
| 45 | INT | genCamera | camera mode |
| 46 | INT | genCamArg1 | cameraarg1 |
| 47 | INT | genCamArg2 | cameraarg2 |
| 48 | INT | genCamArg3 | cameraarg3 |
| 49 | INT | genCamArg4 | cameraarg4 |
| 50 | INT | genScrBackdrop | currently displaying script backdrop index in MXS |
| 51 | INT | genDays | days of play |
| 52 | INT | genHours | hours of play |
| 53 | INT | genMinutes | minutes of play |
| 54 | INT | genSeconds | seconds of play |
| 55 | INT | genMaxVehicle | max vehicle types in VEH |
| 56 | INT | genMaxTagname | Last named tag |
| 57 | INT | genLoadgameScript | load-game plotscript |
| 58 | INT | genTextboxBackdrop | currently displaying text box backdrop in MXS |
| 59 | INT | genEnemyDissolve | Default enemy dissolve type. 0=Default (old style dissolve) 1=Crossfade 2=Diagonal vanish 3=Sink into ground |
| 60 | INT | genJoy | Enable/disable joystick |
| 61 | INT | genPoison | Posion status indicator char |
| 62 | INT | genStun | Stun status indicator char |
| 63 | INT | genDamageCap | Damage cap (0 if there is none) |
| 64 | INT | genMute | Mute status indicator char |
| 65-76 | INT*12 | genStatCap | Stat caps for each stat, in this order: HP MP Atk Aim Def Dog Mag Wil Spd Ctr Focus Extra Hits |
| 77 | INT | genMaxSFX | Number of sound effects |
| 78 | INT | genMasterPal | Master palette number in PALETTES.BIN |
| 79 | INT | genMaxMasterPal | Max master palette number in PALETTES.BIN and number of UI color sets in UICOLORS.BIN |
| 80 | INT | genMaxMenu | Max menu in MENUS.BIN |
| 81 | INT | genMaxMenuItem | Max menu item in MENUITEM.BIN |
| 82 | INT | genMaxItem | Max item number in ITM |
| 83-92 | INT*13 | reserved for future ill-conceived additions. Ugh. | |
| 93 | INT | genPW2Offset | old(second-style) passcode offset |
| 94 | INT | genPW2Length | old(second-style) passcode length (-1 if there is no password) |
| 95 | INT | genVersion | RPG file format version ID (6 is the latest) |
| 96 | INT | genStartMoney | starting money |
| 97 | INT | genMaxShop | last shop in SHO |
| 98 | INT | genPW1Offset | old-old(first-style) passcode offset |
| 99 | INT | genPW1Length | old-old(first-style) passcode length |
| 100 | INT | genMaxBackdrop | number of screens in MXS |
| 101 | INT | genBits | general bitsets: 0 - Pause on Battle Menus 1 - Enable Caterpillar party 2 - don't restore HP on level-up 3 - don't restore MP on level-up 4 - Inns don't revive dead heros 5 - Hero swapping always available 6 - Hide ready meter in battle 7 - Hide health bar in battle 8 - disable debugging keys 9 - Simulate old level-up bug 10 - Permit double-triggering of scripts 11 - Skip title screen 12 - Skip load screen 13 - Pause on All Battle Menus 14 - Disable Hero's Battle Cursor 15 - Default passability disabled by default |
| 102 | INT | genStartX | starting X |
| 103 | INT | genStartY | starting Y |
| 104 | INT | genStartMap | starting Map |
| 105 | INT | genOneTimeNPC | one-time-NPC indexer |
| 106-170 | INT*65 | one-time-NPC placeholder bits | |
| 171 | INT | genDefaultDeathSfx | Default enemy death sound effect ID + 1 (0 for none) |
| 172 | INT | genMaxSong | last song number (SNG and BAM) |
| 173 | INT | genAcceptSfx | Sound effect to use for "accept" (in menus) ID + 1 (0 for none) |
| 174 | INT | genCancelSfx | Sound effect to use for "cancel" (in menus) ID + 1 (0 for none) |
| 175 | INT | genChooseSfx | Sound effect to use for moving the cursor (in menus) ID + 1 (0 for none) |
| 176 | INT | gentextboxLetter | Sound effect to use for displaying text box lines ID + 1 (0 for none) |
| 177 | INT | genBits2 | Additional general bitsets 0 - Simulate pushable NPC collision bug |
| 178-198 | INT*23 | wasted space | |
| 199 | INT | old(second-style) password scattertable head | |
| 200-359 | INT*160 | old(second-style) password scattertable |
Maximums : "max XYZ" means 'the highest numbered XYZ'. If you have 80 enemies defined, then "max enemy" == 79, because the numbering starts from 0.
[edit] Passwords
[edit] New Passwords
The password protection in the RPG format is embarasingly weak. The password itself is obscured with weak, but space-wasting encription, and the length of the password is totally unprotected. RPG password protection works entirely on the honor system. Its kinda like that faded sign hanging on the gates of Anhk-Morpork that says "Thank you for not invading our city"
Here is how to read the password. Please-please-pretty-please dont just ignore it. It is flimsy pathetic laughable protection, but its all we have! Dont take away our wire umbrella in the lightening storm!
The password is stored in the GEN lump (see GEN lump details above)
GEN(5) is the password version number. 256 is the current version number, any number lower than 256 indicates that the password is stored in one of the two obsolete password formats. The best thing to do when decoding an RPG file that still has its password in the old format is to print a warning message telling the user to upgrade their RPG file with CUSTOM.EXE
GEN(6) is the password rotator. It will always be a random number from 1 to 254 that will be used to ascii-rotate/obfuscate the password.
GEN(7-15) is the password text. There are 17 bytes of data here (so the high byte of GEN(15) is unused). Read this string of 17 bytes. ascii-rotate each character by subtracting GEN(6), and then discard all characters with ascii values less than 32 (space). The resulting string will be your password. If the string is empty (all 17 chars were under 32) then the RPG file does not have a password.
[edit] Old Passwords
This information describes the old obsolete password storage format. it is only here as a curiousity... and a monument of shame to security-through-obscurity The first element of the password mess GEN(200) is the bit-offset of the first bit in the password, relative to the beginning of the scattertable head (199). The next element (201) is the bit-offset of the next bit in the password, and so on. So GEN(200) thru GEN(207) will give you the bits that make up the first ascii char of the password. GEN(208)-GEN(215) gives you the next char, and so on up to GEN(94)+1 bytes. After you have read all the chars from the scattertable, rotate them down by the value of GEN(93) (that is to say, subtract GEN(93) from the ascii value of each char, and if the result is less than 0, add 256).
Clear as mud, right? Here is an example. Lets suppose that the data in the GEN lump looks like this
GEN(93)=172 the ascii-rotate offset
GEN(94)=23 the number of bits -1.
23+1 = 24, thats the total number of bits in the password
There are 8 bits in each char of the password, so 24
divided by 8 is 3. That means this password will end up being 3 chars long.
BIT OFFSETS/SCATTERTABLE
GEN(199)=8 [0001 0000 0000 0000] dummy number. Never 0 or 255
GEN(200)=4 [0010 0000 0000 0000] Start here. bit 4 in the table is a 0
GEN(201)=3 [1100 0000 0000 0000] bit 3 in the table is a 1, now we have 01
GEN(202)=18[0100 1000 0000 0000] bit 18 is 1: 011
GEN(203)=18[0100 1000 0000 0000] bit 18 is 1: 0111
GEN(204)=54[0110 1100 0000 0000] bit 58 is 0: 01110
GEN(205)=33[1000 0010 0000 0000] bit 33 is 1: 011101
GEN(206)=85[1010 1010 0000 0000] bit 85 is 1: 0111011
GEN(207)=82[0100 1010 0000 0000] bit 82 is 1: 01110111
So we end up with 01110111 which is char 238, (a wierd ascii math symbol) Now we subtract the value of GEN(93) and we get 66, which is the ascii code for upper case B, so we know the first letter of the password is B.
Ah, what fun. what a mess. what a waste. *sigh*
ARCHINYM.LMP . BROWSE.TXT . ATTACK.BIN . BINSIZE.BIN . DEFPAL#.BIN . DEFPASS.BIN . FIXBITS.BIN . LOOKUP.BIN . MENUS.BIN . MENUITEM.BIN . PALETTES.BIN . PLOTSCR.LST . SFXDATA.BIN . SONGDATA.BIN . UICOLORS.BIN . GEN . BAM . Map Format . T . P . E . D . L . N . DOR . DOX . DT0 . DT1 . DT6 . EFS . FOR . FNT . HSP . HSZ . ITM . MAP . MAS . MN . MXS . PAL . PT0 . PT1 . PT2 . PT3 . PT4 . PT5 . PT6 . SAY . SHO . SNG . STF . STT . TAP . TIL . TMN . VEH
