| 1 | /* |
| 2 | * OpenTyrian: A modern cross-platform port of Tyrian |
| 3 | * Copyright (C) 2007-2009 The OpenTyrian Development Team |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | #include "helptext.h" |
| 20 | |
| 21 | #include "config.h" |
| 22 | #include "episodes.h" |
| 23 | #include "file.h" |
| 24 | #include "fonthand.h" |
| 25 | #include "menus.h" |
| 26 | #include "opentyr.h" |
| 27 | #include "video.h" |
| 28 | |
| 29 | #include <assert.h> |
| 30 | #include <string.h> |
| 31 | |
| 32 | const JE_byte menuHelp[MENU_MAX][11] = /* [1..maxmenu, 1..11] */ |
| 33 | { |
| 34 | { 1, 34, 2, 3, 4, 5, 0, 0, 0, 0, 0 }, |
| 35 | { 6, 7, 8, 9, 10, 11, 11, 12, 0, 0, 0 }, |
| 36 | { 13, 14, 15, 15, 16, 17, 12, 0, 0, 0, 0 }, |
| 37 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 38 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 39 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 40 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 41 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 42 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 43 | { 4, 30, 30, 3, 5, 0, 0, 0, 0, 0, 0 }, |
| 44 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 45 | { 16, 17, 15, 15, 12, 0, 0, 0, 0, 0, 0 }, |
| 46 | { 31, 31, 31, 31, 32, 12, 0, 0, 0, 0, 0 }, |
| 47 | { 4, 34, 3, 5, 0, 0, 0, 0, 0, 0, 0 } |
| 48 | }; |
| 49 | |
| 50 | JE_byte verticalHeight = 7; |
| 51 | JE_byte helpBoxColor = 12; |
| 52 | JE_byte helpBoxBrightness = 1; |
| 53 | JE_byte helpBoxShadeType = FULL_SHADE; |
| 54 | |
| 55 | char helpTxt[39][231]; /* [1..39] of string [230] */ |
| 56 | char pName[21][16]; /* [1..21] of string [15] */ |
| 57 | char miscText[HELPTEXT_MISCTEXT_COUNT][42]; /* [1..68] of string [41] */ |
| 58 | char miscTextB[HELPTEXT_MISCTEXTB_COUNT][HELPTEXT_MISCTEXTB_SIZE]; /* [1..5] of string [10] */ |
| 59 | char keyName[8][18]; /* [1..8] of string [17] */ |
| 60 | char menuText[7][HELPTEXT_MENUTEXT_SIZE]; /* [1..7] of string [20] */ |
| 61 | char outputs[9][31]; /* [1..9] of string [30] */ |
| 62 | char topicName[6][21]; /* [1..6] of string [20] */ |
| 63 | char mainMenuHelp[HELPTEXT_MAINMENUHELP_COUNT][66]; /* [1..34] of string [65] */ |
| 64 | char inGameText[6][21]; /* [1..6] of string [20] */ |
| 65 | char detailLevel[6][13]; /* [1..6] of string [12] */ |
| 66 | char gameSpeedText[5][13]; /* [1..5] of string [12] */ |
| 67 | char inputDevices[3][13]; /* [1..3] of string [12] */ |
| 68 | char networkText[HELPTEXT_NETWORKTEXT_COUNT][HELPTEXT_NETWORKTEXT_SIZE]; /* [1..4] of string [20] */ |
| 69 | char difficultyNameB[11][21]; /* [0..9] of string [20] */ |
| 70 | char joyButtonNames[5][21]; /* [1..5] of string [20] */ |
| 71 | char superShips[HELPTEXT_SUPERSHIPS_COUNT][26]; /* [0..10] of string [25] */ |
| 72 | char specialName[HELPTEXT_SPECIALNAME_COUNT][10]; /* [1..9] of string [9] */ |
| 73 | char destructHelp[25][22]; /* [1..25] of string [21] */ |
| 74 | char weaponNames[17][17]; /* [1..17] of string [16] */ |
| 75 | char destructModeName[DESTRUCT_MODES][13]; /* [1..destructmodes] of string [12] */ |
| 76 | char shipInfo[HELPTEXT_SHIPINFO_COUNT][2][256]; /* [1..13, 1..2] of string */ |
| 77 | char menuInt[MENU_MAX+1][11][18]; /* [0..14, 1..11] of string [17] */ |
| 78 | |
| 79 | static void decrypt_string(char *s, size_t len) |
| 80 | { |
| 81 | static const unsigned char crypt_key[] = { 204, 129, 63, 255, 71, 19, 25, 62, 1, 99 }; |
| 82 | |
| 83 | if (len == 0) |
| 84 | return; |
| 85 | |
| 86 | for (size_t i = len - 1; ; --i) |
| 87 | { |
| 88 | s[i] ^= crypt_key[i % sizeof(crypt_key)]; |
| 89 | if (i == 0) |
| 90 | break; |
| 91 | s[i] ^= s[i - 1]; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | void read_encrypted_pascal_string(char *s, size_t size, FILE *f) |
| 96 | { |
| 97 | Uint8 len; |
| 98 | char buffer[255]; |
| 99 | |
| 100 | fread_u8_die(&len, 1, f); |
| 101 | fread_die(buffer, 1, len, f); |
| 102 | |
| 103 | if (size == 0) |
| 104 | return; |
| 105 | |
| 106 | decrypt_string(buffer, len); |
| 107 | |
| 108 | assert(len < size); |
| 109 | |
| 110 | len = MIN(len, size - 1); |
| 111 | memcpy(s, buffer, len); |
| 112 | s[len] = '\0'; |
| 113 | } |
| 114 | |
| 115 | void skip_pascal_string(FILE *f) |
| 116 | { |
| 117 | Uint8 len; |
| 118 | char buffer[255]; |
| 119 | |
| 120 | fread_u8_die(&len, 1, f); |
| 121 | fread_die(buffer, 1, len, f); |
| 122 | } |
| 123 | |
| 124 | void JE_helpBox(SDL_Surface *screen, int x, int y, const char *message, unsigned int boxwidth) |
| 125 | { |
| 126 | JE_byte startpos, endpos, pos; |
| 127 | JE_boolean endstring; |
| 128 | |
| 129 | char substring[256]; |
| 130 | |
| 131 | if (strlen(message) == 0) |
| 132 | { |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | pos = 1; |
| 137 | endpos = 0; |
| 138 | endstring = false; |
| 139 | |
| 140 | do |
| 141 | { |
| 142 | startpos = endpos + 1; |
| 143 | |
| 144 | do |
| 145 | { |
| 146 | endpos = pos; |
| 147 | do |
| 148 | { |
| 149 | pos++; |
| 150 | if (pos == strlen(message)) |
| 151 | { |
| 152 | endstring = true; |
| 153 | if ((unsigned)(pos - startpos) < boxwidth) |
| 154 | { |
| 155 | endpos = pos + 1; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | } while (!(message[pos-1] == ' ' || endstring)); |
| 160 | |
| 161 | } while (!((unsigned)(pos - startpos) > boxwidth || endstring)); |
| 162 | |
| 163 | SDL_strlcpy(substring, message + startpos - 1, MIN((size_t)(endpos - startpos + 1), sizeof(substring))); |
| 164 | JE_textShade(screen, x, y, substring, helpBoxColor, helpBoxBrightness, helpBoxShadeType); |
| 165 | |
| 166 | y += verticalHeight; |
| 167 | |
| 168 | } while (!endstring); |
| 169 | |
| 170 | if (endpos != pos + 1) |
| 171 | { |
| 172 | JE_textShade(screen, x, y, message + endpos, helpBoxColor, helpBoxBrightness, helpBoxShadeType); |
| 173 | } |
| 174 | |
| 175 | helpBoxColor = 12; |
| 176 | helpBoxShadeType = FULL_SHADE; |
| 177 | } |
| 178 | |
| 179 | void JE_HBox(SDL_Surface *screen, int x, int y, unsigned int messagenum, unsigned int boxwidth) |
| 180 | { |
| 181 | JE_helpBox(screen, x, y, helpTxt[messagenum-1], boxwidth); |
| 182 | } |
| 183 | |
| 184 | void JE_loadHelpText(void) |
| 185 | { |
| 186 | const unsigned int menuInt_entries[MENU_MAX + 1] = { -1, 7, 9, 8, -1, -1, 11, -1, -1, -1, 6, 4, 6, 7, 5 }; |
| 187 | |
| 188 | FILE *f = dir_fopen_die(data_dir(), "tyrian.hdt", "rb"); |
| 189 | fread_s32_die(&episode1DataLoc, 1, f); |
| 190 | |
| 191 | /*Online Help*/ |
| 192 | skip_pascal_string(f); |
| 193 | for (unsigned int i = 0; i < COUNTOF(helpTxt); ++i) |
| 194 | read_encrypted_pascal_string(helpTxt[i], sizeof(helpTxt[i]), f); |
| 195 | skip_pascal_string(f); |
| 196 | |
| 197 | /*Planet names*/ |
| 198 | skip_pascal_string(f); |
| 199 | for (unsigned int i = 0; i < COUNTOF(pName); ++i) |
| 200 | read_encrypted_pascal_string(pName[i], sizeof(pName[i]), f); |
| 201 | skip_pascal_string(f); |
| 202 | |
| 203 | /*Miscellaneous text*/ |
| 204 | skip_pascal_string(f); |
| 205 | for (unsigned int i = 0; i < COUNTOF(miscText); ++i) |
| 206 | read_encrypted_pascal_string(miscText[i], sizeof(miscText[i]), f); |
| 207 | skip_pascal_string(f); |
| 208 | |
| 209 | /*Little Miscellaneous text*/ |
| 210 | skip_pascal_string(f); |
| 211 | for (unsigned int i = 0; i < COUNTOF(miscTextB); ++i) |
| 212 | read_encrypted_pascal_string(miscTextB[i], sizeof(miscTextB[i]), f); |
| 213 | skip_pascal_string(f); |
| 214 | |
| 215 | /*Key names*/ |
| 216 | skip_pascal_string(f); |
| 217 | for (unsigned int i = 0; i < menuInt_entries[6]; ++i) |
| 218 | read_encrypted_pascal_string(menuInt[6][i], sizeof(menuInt[6][i]), f); |
| 219 | skip_pascal_string(f); |
| 220 | |
| 221 | /*Main Menu*/ |
| 222 | skip_pascal_string(f); |
| 223 | for (unsigned int i = 0; i < COUNTOF(menuText); ++i) |
| 224 | read_encrypted_pascal_string(menuText[i], sizeof(menuText[i]), f); |
| 225 | skip_pascal_string(f); |
| 226 | |
| 227 | /*Event text*/ |
| 228 | skip_pascal_string(f); |
| 229 | for (unsigned int i = 0; i < COUNTOF(outputs); ++i) |
| 230 | read_encrypted_pascal_string(outputs[i], sizeof(outputs[i]), f); |
| 231 | skip_pascal_string(f); |
| 232 | |
| 233 | /*Help topics*/ |
| 234 | skip_pascal_string(f); |
| 235 | for (unsigned int i = 0; i < COUNTOF(topicName); ++i) |
| 236 | read_encrypted_pascal_string(topicName[i], sizeof(topicName[i]), f); |
| 237 | skip_pascal_string(f); |
| 238 | |
| 239 | /*Main Menu Help*/ |
| 240 | skip_pascal_string(f); |
| 241 | for (unsigned int i = 0; i < COUNTOF(mainMenuHelp); ++i) |
| 242 | read_encrypted_pascal_string(mainMenuHelp[i], sizeof(mainMenuHelp[i]), f); |
| 243 | skip_pascal_string(f); |
| 244 | |
| 245 | /*Menu 1 - Main*/ |
| 246 | skip_pascal_string(f); |
| 247 | for (unsigned int i = 0; i < menuInt_entries[1]; ++i) |
| 248 | read_encrypted_pascal_string(menuInt[1][i], sizeof(menuInt[1][i]), f); |
| 249 | skip_pascal_string(f); |
| 250 | |
| 251 | /*Menu 2 - Items*/ |
| 252 | skip_pascal_string(f); |
| 253 | for (unsigned int i = 0; i < menuInt_entries[2]; ++i) |
| 254 | read_encrypted_pascal_string(menuInt[2][i], sizeof(menuInt[2][i]), f); |
| 255 | skip_pascal_string(f); |
| 256 | |
| 257 | /*Menu 3 - Options*/ |
| 258 | skip_pascal_string(f); |
| 259 | for (unsigned int i = 0; i < menuInt_entries[3]; ++i) |
| 260 | read_encrypted_pascal_string(menuInt[3][i], sizeof(menuInt[3][i]), f); |
| 261 | skip_pascal_string(f); |
| 262 | |
| 263 | /*InGame Menu*/ |
| 264 | skip_pascal_string(f); |
| 265 | for (unsigned int i = 0; i < COUNTOF(inGameText); ++i) |
| 266 | read_encrypted_pascal_string(inGameText[i], sizeof(inGameText[i]), f); |
| 267 | skip_pascal_string(f); |
| 268 | |
| 269 | /*Detail Level*/ |
| 270 | skip_pascal_string(f); |
| 271 | for (unsigned int i = 0; i < COUNTOF(detailLevel); ++i) |
| 272 | read_encrypted_pascal_string(detailLevel[i], sizeof(detailLevel[i]), f); |
| 273 | skip_pascal_string(f); |
| 274 | |
| 275 | /*Game speed text*/ |
| 276 | skip_pascal_string(f); |
| 277 | for (unsigned int i = 0; i < COUNTOF(gameSpeedText); ++i) |
| 278 | read_encrypted_pascal_string(gameSpeedText[i], sizeof(gameSpeedText[i]), f); |
| 279 | skip_pascal_string(f); |
| 280 | |
| 281 | // episode names |
| 282 | skip_pascal_string(f); |
| 283 | for (unsigned int i = 0; i < COUNTOF(episode_name); ++i) |
| 284 | read_encrypted_pascal_string(episode_name[i], sizeof(episode_name[i]), f); |
| 285 | skip_pascal_string(f); |
| 286 | |
| 287 | // difficulty names |
| 288 | skip_pascal_string(f); |
| 289 | for (unsigned int i = 0; i < COUNTOF(difficulty_name); ++i) |
| 290 | read_encrypted_pascal_string(difficulty_name[i], sizeof(difficulty_name[i]), f); |
| 291 | skip_pascal_string(f); |
| 292 | |
| 293 | // gameplay mode names |
| 294 | skip_pascal_string(f); |
| 295 | for (unsigned int i = 0; i < COUNTOF(gameplay_name); ++i) |
| 296 | read_encrypted_pascal_string(gameplay_name[i], sizeof(gameplay_name[i]), f); |
| 297 | skip_pascal_string(f); |
| 298 | |
| 299 | /*Menu 10 - 2Player Main*/ |
| 300 | skip_pascal_string(f); |
| 301 | for (unsigned int i = 0; i < menuInt_entries[10]; ++i) |
| 302 | read_encrypted_pascal_string(menuInt[10][i], sizeof(menuInt[10][i]), f); |
| 303 | skip_pascal_string(f); |
| 304 | |
| 305 | /*Input Devices*/ |
| 306 | skip_pascal_string(f); |
| 307 | for (unsigned int i = 0; i < COUNTOF(inputDevices); ++i) |
| 308 | read_encrypted_pascal_string(inputDevices[i], sizeof(inputDevices[i]), f); |
| 309 | skip_pascal_string(f); |
| 310 | |
| 311 | /*Network text*/ |
| 312 | skip_pascal_string(f); |
| 313 | for (unsigned int i = 0; i < COUNTOF(networkText); ++i) |
| 314 | read_encrypted_pascal_string(networkText[i], sizeof(networkText[i]), f); |
| 315 | skip_pascal_string(f); |
| 316 | |
| 317 | /*Menu 11 - 2Player Network*/ |
| 318 | skip_pascal_string(f); |
| 319 | for (unsigned int i = 0; i < menuInt_entries[11]; ++i) |
| 320 | read_encrypted_pascal_string(menuInt[11][i], sizeof(menuInt[11][i]), f); |
| 321 | skip_pascal_string(f); |
| 322 | |
| 323 | /*HighScore Difficulty Names*/ |
| 324 | skip_pascal_string(f); |
| 325 | for (unsigned int i = 0; i < COUNTOF(difficultyNameB); ++i) |
| 326 | read_encrypted_pascal_string(difficultyNameB[i], sizeof(difficultyNameB[i]), f); |
| 327 | skip_pascal_string(f); |
| 328 | |
| 329 | /*Menu 12 - Network Options*/ |
| 330 | skip_pascal_string(f); |
| 331 | for (unsigned int i = 0; i < menuInt_entries[12]; ++i) |
| 332 | read_encrypted_pascal_string(menuInt[12][i], sizeof(menuInt[12][i]), f); |
| 333 | skip_pascal_string(f); |
| 334 | |
| 335 | /*Menu 13 - Joystick*/ |
| 336 | skip_pascal_string(f); |
| 337 | for (unsigned int i = 0; i < menuInt_entries[13]; ++i) |
| 338 | read_encrypted_pascal_string(menuInt[13][i], sizeof(menuInt[13][i]), f); |
| 339 | skip_pascal_string(f); |
| 340 | |
| 341 | /*Joystick Button Assignments*/ |
| 342 | skip_pascal_string(f); |
| 343 | for (unsigned int i = 0; i < COUNTOF(joyButtonNames); ++i) |
| 344 | read_encrypted_pascal_string(joyButtonNames[i], sizeof(joyButtonNames[i]), f); |
| 345 | skip_pascal_string(f); |
| 346 | |
| 347 | /*SuperShips - For Super Arcade Mode*/ |
| 348 | skip_pascal_string(f); |
| 349 | for (unsigned int i = 0; i < COUNTOF(superShips); ++i) |
| 350 | read_encrypted_pascal_string(superShips[i], sizeof(superShips[i]), f); |
| 351 | skip_pascal_string(f); |
| 352 | |
| 353 | /*SuperShips - For Super Arcade Mode*/ |
| 354 | skip_pascal_string(f); |
| 355 | for (unsigned int i = 0; i < COUNTOF(specialName); ++i) |
| 356 | read_encrypted_pascal_string(specialName[i], sizeof(specialName[i]), f); |
| 357 | skip_pascal_string(f); |
| 358 | |
| 359 | /*Secret DESTRUCT game*/ |
| 360 | skip_pascal_string(f); |
| 361 | for (unsigned int i = 0; i < COUNTOF(destructHelp); ++i) |
| 362 | read_encrypted_pascal_string(destructHelp[i], sizeof(destructHelp[i]), f); |
| 363 | skip_pascal_string(f); |
| 364 | |
| 365 | /*Secret DESTRUCT weapons*/ |
| 366 | skip_pascal_string(f); |
| 367 | for (unsigned int i = 0; i < COUNTOF(weaponNames); ++i) |
| 368 | read_encrypted_pascal_string(weaponNames[i], sizeof(weaponNames[i]), f); |
| 369 | skip_pascal_string(f); |
| 370 | |
| 371 | /*Secret DESTRUCT modes*/ |
| 372 | skip_pascal_string(f); |
| 373 | for (unsigned int i = 0; i < COUNTOF(destructModeName); ++i) |
| 374 | read_encrypted_pascal_string(destructModeName[i], sizeof(destructModeName[i]), f); |
| 375 | skip_pascal_string(f); |
| 376 | |
| 377 | /*NEW: Ship Info*/ |
| 378 | skip_pascal_string(f); |
| 379 | for (unsigned int i = 0; i < COUNTOF(shipInfo); ++i) |
| 380 | { |
| 381 | read_encrypted_pascal_string(shipInfo[i][0], sizeof(shipInfo[i][0]), f); |
| 382 | read_encrypted_pascal_string(shipInfo[i][1], sizeof(shipInfo[i][1]), f); |
| 383 | } |
| 384 | skip_pascal_string(f); |
| 385 | |
| 386 | /*Menu 12 - Network Options*/ |
| 387 | skip_pascal_string(f); |
| 388 | for (unsigned int i = 0; i < menuInt_entries[14]; ++i) |
| 389 | read_encrypted_pascal_string(menuInt[14][i], sizeof(menuInt[14][i]), f); |
| 390 | |
| 391 | fclose(f); |
| 392 | } |