Browse Source

Added binary file format template for Script

Thomas Buck 9 years ago
parent
commit
af4c9b1ed9
4 changed files with 189 additions and 2 deletions
  1. 5
    0
      ChangeLog.md
  2. 2
    2
      src/RunTime.cpp
  3. 22
    0
      src/Script.cpp
  4. 160
    0
      utils/script.bfft

+ 5
- 0
ChangeLog.md View File

@@ -2,6 +2,11 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20141110 ]
6
+    * Added [Binspector](https://github.com/binspector/binspector) binary file format template
7
+      that can be used to parse and analyze TR2 and TR3 script files.
8
+    * Minor changes suggested by cppcheck
9
+
5 10
     [ 20141031 ]
6 11
     * Added get command
7 12
 

+ 2
- 2
src/RunTime.cpp View File

@@ -9,8 +9,8 @@
9 9
 #include "utils/strings.h"
10 10
 #include "RunTime.h"
11 11
 
12
-RunTime::RunTime() {
13
-    baseDir = expandHomeDirectory("~/.OpenRaider");
12
+RunTime::RunTime()
13
+    : baseDir(expandHomeDirectory("~/.OpenRaider")) {
14 14
     pakDir = baseDir + "/paks";
15 15
     audioDir = baseDir + "/music";
16 16
     dataDir = baseDir + "/data";

+ 22
- 0
src/Script.cpp View File

@@ -9,6 +9,28 @@
9 9
 #include "Script.h"
10 10
 
11 11
 Script::Script() : puzzles(4), pickups(2), keys(4) {
12
+    version = 0;
13
+    firstOption = 0;
14
+    titleReplace = 0;
15
+    onDeathDemoMode = 0;
16
+    onDeathInGame = 0;
17
+    noInputTime = 0;
18
+    onDemoInterrupt = 0;
19
+    onDemoEnd = 0;
20
+    numLevels = 0;
21
+    numPictures = 0;
22
+    numTitles = 0;
23
+    numFMVs = 0;
24
+    numCutscenes = 0;
25
+    numDemos = 0;
26
+    titleTrack = 0;
27
+    singleLevel = 0;
28
+    flags = 0;
29
+    cypherCode = 0;
30
+    language = 0;
31
+    secretTrack = 0;
32
+    numPCStrings = 41;
33
+    numGameStrings = 0;
12 34
 }
13 35
 
14 36
 Script::~Script() {

+ 160
- 0
utils/script.bfft View File

@@ -0,0 +1,160 @@
1
+/*
2
+ * script.bfft - Tomb Raider 1 - 3 Engine Script Format Description
3
+ * 2014, Thomas Buck <xythobuz@xythobuz.de>
4
+ *
5
+ * Based on the TR Rosetta Stone (http://www.tnlc.com/eep/tr/TRosettaStone.html),
6
+ * this document (http://xythobuz.de/tr_docs/TombPC_TR2.pdf),
7
+ * and my own reverse-engineering efforts.
8
+ * Developed for Binspector (https://github.com/binspector/binspector)
9
+ */
10
+
11
+// ########## General data structures ##########
12
+
13
+struct strings_t {
14
+    unsigned 16 little stringOffsets[stringsInPackage];
15
+    unsigned 16 little stringDataSize;
16
+    unsigned 8 little stringData[stringDataSize];
17
+}
18
+
19
+struct script_t {
20
+    unsigned 16 little sciprOffsets[stringsInPackage];
21
+    unsigned 16 little scriptDataSize;
22
+    unsigned 16 little scriptData[scriptDataSize / 2];
23
+}
24
+
25
+struct hack_t {
26
+    signal isTR2 = 0;
27
+    signal isPCVersion = 1;
28
+
29
+    if ((peek() == 0x13) || (peek() == 0x15)) {
30
+        // TR2 for PC and PSX has 6 "filler bytes" hex 13 00 14 00 15 00
31
+        // (for TR3 for PSX, the filler is hex 15 00 16 00 17 00 instead)
32
+        // at the end of the script block. We need to skip these...
33
+        if (peek() == 0x13) {
34
+            signal isTR2 = 1;
35
+        } else {
36
+            signal isTR2 = 0;
37
+            signal isPCVersion = 0;
38
+        }
39
+
40
+        skip hack[6];
41
+    }
42
+    
43
+    if (peek() == 0x01) {
44
+        // TR2 for PSX has 64 bytes with unknown content (not zero!) here,
45
+        // TR3 for PSX has 40 bytes. We try to identify and skip them (both start with 1)...
46
+        // This is also currently used to set the platform specific string count
47
+        if (isTR2 == 1) {
48
+            signal isPCVersion = 0;
49
+            skip hackPSX[64];
50
+        } else {
51
+            skip hackPSX[40];
52
+        }
53
+    }
54
+
55
+    if (isTR2 == 1) {
56
+        if (isPCVersion == 1) {
57
+            notify "TR2 PC Version detected!";
58
+            signal numPCStrings = 41;
59
+        } else {
60
+            notify "TR2 PSX Version detected!";
61
+            signal numPCStrings = 80;
62
+        }
63
+    } else {
64
+        if (isPCVersion == 1) {
65
+            notify "TR3 PC Version detected!";
66
+            signal numPCStrings = 41;
67
+        } else {
68
+            notify "TR3 PSX Version detected!";
69
+            signal numPCStrings = 80;
70
+        }
71
+    }
72
+}
73
+
74
+// ########## Main file layout ##########
75
+
76
+struct main {
77
+    unsigned 32 little version;
78
+
79
+    unsigned 8 little description[256];
80
+
81
+    unsigned 16 little gameflowSize;
82
+    if (gameflowSize != 128)
83
+        die "Invalid gameflow size!";
84
+
85
+    unsigned 32 little firstOption;
86
+    signed 32 little titleReplace;
87
+    unsigned 32 little onDeathDemoMode;
88
+    unsigned 32 little onDeathInGame;
89
+
90
+    // Scaled * 100 in TR3
91
+    unsigned 32 little noInputTime;
92
+
93
+    unsigned 32 little onDemoInterrupt;
94
+    unsigned 32 little onDemoEnd;
95
+
96
+    skip filler1[36];
97
+
98
+    unsigned 16 little numLevels;
99
+    unsigned 16 little numPictures;
100
+    unsigned 16 little numTitles;
101
+    unsigned 16 little numFMVs;
102
+    unsigned 16 little numCutscenes;
103
+    unsigned 16 little numDemos;
104
+    unsigned 16 little titleTrack;
105
+    signed 16 little singleLevel;
106
+
107
+    skip filler2[32];
108
+
109
+    unsigned 16 little flags;
110
+
111
+    skip filler3[6];
112
+
113
+    unsigned 8 little cypherCode;
114
+    unsigned 8 little language;
115
+
116
+    // Zero in TR3, Part of filler or real number?
117
+    unsigned 16 little secretTrack;
118
+
119
+    skip filler4[4];
120
+
121
+    slot stringsInPackage = numLevels;
122
+    strings_t levelDisplayNames;
123
+
124
+    signal stringsInPackage = numPictures;
125
+    strings_t pictures;
126
+
127
+    signal stringsInPackage = numTitles;
128
+    strings_t titleFilenames;
129
+
130
+    signal stringsInPackage = numFMVs;
131
+    strings_t fmvFilenames;
132
+
133
+    signal stringsInPackage = numLevels;
134
+    strings_t levelFilenames;
135
+
136
+    signal stringsInPackage = numCutscenes;
137
+    strings_t cutsceneFilenames;
138
+
139
+    signal stringsInPackage = numLevels + 1;
140
+    script_t script;
141
+
142
+    slot numPCStrings = 41; // PC Version has 41 pcStrings
143
+    slot isPCVersion = 1;
144
+    slot isTR2 = 1;
145
+    hack_t hack;
146
+
147
+    unsigned 16 little numGameStrings;
148
+
149
+    signal stringsInPackage = numGameStrings;
150
+    strings_t gameStrings;
151
+
152
+    signal stringsInPackage = numPCStrings;
153
+    strings_t pcStrings;
154
+
155
+    signal stringsInPackage = numLevels;
156
+    strings_t puzzles[4];
157
+    strings_t pickups[2];
158
+    strings_t keys[4];
159
+}
160
+

Loading…
Cancel
Save