Sfoglia il codice sorgente

Validating pak before putting it in menu list

Thomas Buck 10 anni fa
parent
commit
d61daf3fcf
4 ha cambiato i file con 33 aggiunte e 39 eliminazioni
  1. 2
    2
      include/TombRaider.h
  2. 15
    15
      include/TombRaiderData.h
  3. 9
    8
      src/OpenRaider.cpp
  4. 7
    14
      src/TombRaider.cpp

+ 2
- 2
include/TombRaider.h Vedi File

@@ -124,7 +124,7 @@ public:
124 124
      * \param filename file to check
125 125
      * \returns 0 if it is a TombRaider pak
126 126
      */
127
-    int checkMime(char *filename);
127
+    static int checkMime(char *filename);
128 128
 
129 129
     /*!
130 130
      * \brief Loads TombRaider 1-5 pak into memory
@@ -669,7 +669,7 @@ private:
669 669
      */
670 670
     int loadTR5(FILE *f, void (*percent)(int, void *), void *obj);
671 671
 
672
-    void print(const char *methodName, const char *s, ...) __attribute__((format(printf, 3, 4)));
672
+    static void print(const char *methodName, const char *s, ...) __attribute__((format(printf, 2, 3)));
673 673
 
674 674
     void printDebug(const char *methodName, const char *s, ...) __attribute__((format(printf, 3, 4)));
675 675
 

+ 15
- 15
include/TombRaiderData.h Vedi File

@@ -19,6 +19,21 @@
19 19
 #pragma pack(push, tr2_h, 1)
20 20
 #endif
21 21
 
22
+#define TR_SOUND_FOOTSTEP0 1
23
+#define TR_SOUND_F_PISTOL  12
24
+
25
+#define TR_ANIAMTION_RUN            0
26
+#define TR_ANIAMTION_STAND          11
27
+#define TR_ANIAMTION_TURN_L         12
28
+#define TR_ANIAMTION_TURN_R         13
29
+#define TR_ANIAMTION_HIT_WALL_FRONT 53
30
+#define TR_ANIAMTION_SWIM_IDLE      87
31
+#define TR_ANIAMTION_SWIM           86
32
+#define TR_ANIAMTION_SWIM_L         143
33
+#define TR_ANIAMTION_SWIM_R         144
34
+#define TR_ANIAMTION_GRAB_LEDGE     96
35
+#define TR_ANIAMTION_PULLING_UP     97
36
+
22 37
 typedef enum {
23 38
     TR_VERSION_UNKNOWN,
24 39
     TR_VERSION_1,
@@ -58,9 +73,6 @@ typedef enum {
58 73
     tombraiderFace_PartialAlpha = (1 << 2)
59 74
 } tombraiderFace_Flags;
60 75
 
61
-#define TR_SOUND_FOOTSTEP0    1
62
-#define TR_SOUND_F_PISTOL    12
63
-
64 76
 enum TR4_Objects {
65 77
     TR4_LARA = 0,
66 78
     TR4_PISTOLS_ANIM = 1,
@@ -85,18 +97,6 @@ enum TR4_Objects {
85 97
     TR4_LARA_SPEECH_HEAD4 = 20
86 98
 };
87 99
 
88
-#define TR_ANIAMTION_RUN               0
89
-#define TR_ANIAMTION_STAND            11
90
-#define TR_ANIAMTION_TURN_L           12
91
-#define TR_ANIAMTION_TURN_R           13
92
-#define TR_ANIAMTION_HIT_WALL_FRONT   53
93
-#define TR_ANIAMTION_SWIM_IDLE        87
94
-#define TR_ANIAMTION_SWIM             86
95
-#define TR_ANIAMTION_SWIM_L          143
96
-#define TR_ANIAMTION_SWIM_R          144
97
-#define TR_ANIAMTION_GRAB_LEDGE       96
98
-#define TR_ANIAMTION_PULLING_UP       97
99
-
100 100
 /*!
101 101
  * \brief Basic 24-bit colour structure.
102 102
  *

+ 9
- 8
src/OpenRaider.cpp Vedi File

@@ -17,6 +17,7 @@
17 17
 #include "Game.h"
18 18
 #include "Menu.h"
19 19
 #include "Sound.h"
20
+#include "TombRaider.h"
20 21
 #include "Window.h"
21 22
 #include "utils/strings.h"
22 23
 #include "utils/time.h"
@@ -176,7 +177,7 @@ int OpenRaider::command(const char *command, std::vector<char *> *args) {
176 177
     } else if (strcmp(command, "load") == 0) {
177 178
         if (mGame)
178 179
             delete mGame;
179
-        char *tmp = bufferString("%s%s", mPakDir, args->at(0));
180
+        char *tmp = bufferString("%s/%s", mPakDir, args->at(0));
180 181
         try {
181 182
             mGame = new Game(tmp);
182 183
             delete [] tmp;
@@ -553,14 +554,14 @@ void OpenRaider::loadPakFolderRecursive(const char *dir) {
553 554
                      || stringEndsWith(lowerPath, ".tr2")
554 555
                      || stringEndsWith(lowerPath, ".tr4")
555 556
                      || stringEndsWith(lowerPath, ".trc")) {
556
-                    //if (m_tombraider.checkMime(fullPathMap) == 0) {
557
-                        // mConsole->print("Validated pak: '%s'", fullPathMap);
558
-
557
+                    int error = TombRaider::checkMime(fullPathMap);
558
+                    if (error == 0) {
559 559
                         // Just load relative filename
560
-                        mMapList.push_back(bufferString("%s", (fullPathMap + strlen(mPakDir))));
561
-                    //} else {
562
-                    //    mConsole->print("ERROR: pak file '%s' not found or invalid", fullPathMap);
563
-                    //}
560
+                        mMapList.push_back(bufferString("%s", (fullPathMap + strlen(mPakDir) + 1)));
561
+                    } else {
562
+                        mConsole->print("Error: pak file '%s' %s",
563
+                                fullPathMap, (error == -1) ? "not found" : "invalid");
564
+                    }
564 565
                 }
565 566
 
566 567
                 delete [] lowerPath;

+ 7
- 14
src/TombRaider.cpp Vedi File

@@ -359,22 +359,18 @@ unsigned char *TombRaider::Palette8()
359 359
 }
360 360
 
361 361
 
362
-int TombRaider::checkMime(char *filename)
363
-{
362
+int TombRaider::checkMime(char *filename) {
364 363
     FILE *f;
365 364
     unsigned int version;
366 365
 
367
-
368
-    if (!filename || !filename[0])
369
-    {
366
+    if (!filename || !filename[0]) {
370 367
         print("checkFile", "Given filename was empty string or NULL");
371 368
         return -1;
372 369
     }
373 370
 
374 371
     f = fopen(filename, "rb");
375 372
 
376
-    if (!f)
377
-    {
373
+    if (!f) {
378 374
         perror(filename);
379 375
         return -1;
380 376
     }
@@ -383,20 +379,17 @@ int TombRaider::checkMime(char *filename)
383 379
     fread(&version, sizeof(version), 1, f);
384 380
     fclose(f);
385 381
 
386
-    switch (version)
387
-    {
382
+    switch (version) {
388 383
         case 0x00000020:
389 384
         case 0x0000002d:
390 385
         case 0xff080038:
391 386
         case 0xff180038:
392
-        case 0xfffffff0:           // bogus
393
-        case 0x00345254:           // "TR4\0"
387
+        case 0xfffffff0: // bogus
388
+        case 0x00345254: // "TR4\0"
394 389
             return 0;
395 390
         default:
396
-            ;
391
+            return 1;
397 392
     }
398
-
399
-    return 1;
400 393
 }
401 394
 
402 395
 

Loading…
Annulla
Salva