Browse Source

Validating pak before putting it in menu list

Thomas Buck 10 years ago
parent
commit
d61daf3fcf
4 changed files with 33 additions and 39 deletions
  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 View File

124
      * \param filename file to check
124
      * \param filename file to check
125
      * \returns 0 if it is a TombRaider pak
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
      * \brief Loads TombRaider 1-5 pak into memory
130
      * \brief Loads TombRaider 1-5 pak into memory
669
      */
669
      */
670
     int loadTR5(FILE *f, void (*percent)(int, void *), void *obj);
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
     void printDebug(const char *methodName, const char *s, ...) __attribute__((format(printf, 3, 4)));
674
     void printDebug(const char *methodName, const char *s, ...) __attribute__((format(printf, 3, 4)));
675
 
675
 

+ 15
- 15
include/TombRaiderData.h View File

19
 #pragma pack(push, tr2_h, 1)
19
 #pragma pack(push, tr2_h, 1)
20
 #endif
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
 typedef enum {
37
 typedef enum {
23
     TR_VERSION_UNKNOWN,
38
     TR_VERSION_UNKNOWN,
24
     TR_VERSION_1,
39
     TR_VERSION_1,
58
     tombraiderFace_PartialAlpha = (1 << 2)
73
     tombraiderFace_PartialAlpha = (1 << 2)
59
 } tombraiderFace_Flags;
74
 } tombraiderFace_Flags;
60
 
75
 
61
-#define TR_SOUND_FOOTSTEP0    1
62
-#define TR_SOUND_F_PISTOL    12
63
-
64
 enum TR4_Objects {
76
 enum TR4_Objects {
65
     TR4_LARA = 0,
77
     TR4_LARA = 0,
66
     TR4_PISTOLS_ANIM = 1,
78
     TR4_PISTOLS_ANIM = 1,
85
     TR4_LARA_SPEECH_HEAD4 = 20
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
  * \brief Basic 24-bit colour structure.
101
  * \brief Basic 24-bit colour structure.
102
  *
102
  *

+ 9
- 8
src/OpenRaider.cpp View File

17
 #include "Game.h"
17
 #include "Game.h"
18
 #include "Menu.h"
18
 #include "Menu.h"
19
 #include "Sound.h"
19
 #include "Sound.h"
20
+#include "TombRaider.h"
20
 #include "Window.h"
21
 #include "Window.h"
21
 #include "utils/strings.h"
22
 #include "utils/strings.h"
22
 #include "utils/time.h"
23
 #include "utils/time.h"
176
     } else if (strcmp(command, "load") == 0) {
177
     } else if (strcmp(command, "load") == 0) {
177
         if (mGame)
178
         if (mGame)
178
             delete mGame;
179
             delete mGame;
179
-        char *tmp = bufferString("%s%s", mPakDir, args->at(0));
180
+        char *tmp = bufferString("%s/%s", mPakDir, args->at(0));
180
         try {
181
         try {
181
             mGame = new Game(tmp);
182
             mGame = new Game(tmp);
182
             delete [] tmp;
183
             delete [] tmp;
553
                      || stringEndsWith(lowerPath, ".tr2")
554
                      || stringEndsWith(lowerPath, ".tr2")
554
                      || stringEndsWith(lowerPath, ".tr4")
555
                      || stringEndsWith(lowerPath, ".tr4")
555
                      || stringEndsWith(lowerPath, ".trc")) {
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
                         // Just load relative filename
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
                 delete [] lowerPath;
567
                 delete [] lowerPath;

+ 7
- 14
src/TombRaider.cpp View File

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

Loading…
Cancel
Save