17 #define printStrings(cnt, acc, name) { \
18 std::cout << name << " (" << cnt << ")" << std::endl; \
19 for (unsigned int i = 0; i < cnt; i++) { \
20 std::cout << " " << acc(i) << std::endl; \
22 std::cout << std::endl; \
25 #define printStrings2D(c, cnt, acc, name) { \
26 std::cout << name << " (" << c << "*" << cnt << ")" << std::endl; \
27 for (unsigned int a = 0; a < cnt; a++) { \
29 for (unsigned int i = 0; i < c; i++) { \
30 std::cout << acc(i, a); \
34 std::cout << std::endl; \
36 std::cout << std::endl; \
39 #define registerLambda(x, y) { \
40 s.registerScriptHandler(x, [](bool hasOperand, uint16_t operand) { \
41 std::cout << "\t" << y; \
43 std::cout << " (" << operand << ")"; \
44 std::cout << std::endl; \
88 for (
unsigned int i = 0; i < (s.
levelCount() + 1); i++) {
90 std::cout <<
"Script for Title:" << std::endl;
92 std::cout <<
"Script for \"" << s.
getLevelName(i - 1) <<
"\" (" << i - 1 <<
"):" << std::endl;
95 std::cout <<
"Returned " << error <<
"..." << std::endl;
98 std::cout << std::endl;
105 static int test(
const char* file,
unsigned int n) {
110 if (s.
load(file) != 0) {
111 std::cout <<
"Could not open file " << file << std::endl;
122 std::cout <<
"Platform String Count " << s.
pcStringCount() <<
" != " <<
127 std::cout <<
"Success!" << std::endl << std::endl;
131 static int readPayloadChunk(
const unsigned char* data,
unsigned int size,
const char* file) {
132 static const unsigned int bufferSize = 16384;
133 unsigned char buffer[bufferSize];
137 stream.zalloc = Z_NULL;
138 stream.zfree = Z_NULL;
139 stream.opaque = Z_NULL;
140 int error = inflateInit(&stream);
142 std::cout <<
"inflateInit() Error " << error << std::endl;
147 stream.avail_in = size;
148 stream.next_in =
const_cast<unsigned char*
>(data);
149 stream.avail_out = bufferSize;
150 stream.next_out = buffer;
151 error = inflate(&stream, Z_FINISH);
152 if (error != Z_STREAM_END) {
153 std::cout <<
"inflate() Error " << error << std::endl;
159 std::ofstream s(file, std::ios_base::out | std::ios_base::binary);
160 s.write(reinterpret_cast<const char*>(buffer), bufferSize - stream.avail_out);
168 char tmpFile[] =
"/tmp/openraider_unit_test_0";
170 while ((f = fopen(tmpFile,
"r")) != NULL) {
175 std::cout <<
"Temporary test file: " << tmpFile << std::endl;
181 error = s.
load(tmpFile);
185 std::cout <<
"Error loading script!" << std::endl;
187 error =
test(tmpFile, n);
195 int main(
int argc,
char* argv[]) {
196 bool printHelp =
false;
198 bool printData =
true;
202 if ((strcmp(argv[1],
"--printData") == 0)
203 || (strcmp(argv[1],
"--printScript") == 0)) {
205 if (strcmp(argv[1],
"--printScript") == 0) {
209 if ((argv[2][0] >=
'0')
211 whichFile = argv[2][0] -
'0';
216 }
else if (argc != 1) {
221 std::cout <<
"Usage:" << std::endl;
222 std::cout <<
"\t" << argv[0] <<
" [--printData | --printScript] [N | /path]" << std::endl;
228 if (whichFile == -1) {
235 return runForPayload(static_cast<unsigned int>(whichFile),
true, printData);
int runScript(unsigned int level)
unsigned int titleCount()
static int printDataScript(Script &s, bool strings)
Start level without weapons.
std::string getTitleFilename(unsigned int i)
Unknown, nothing changes in TR2.
Unknown, nothing changes in TR2. Start in Motorboat?
static const unsigned int testSizes[testPayloadCount]
std::string getLevelFilename(unsigned int i)
std::string getLevelName(unsigned int i)
Lara dies when her feet reach given depth.
#define registerLambda(x, y)
static const unsigned int testExpectedPlatformStringCount[testPayloadCount]
Play soundtrack (precedes level opcode)
static void error(char *msg)
#define printStrings2D(c, cnt, acc, name)
unsigned int gameStringCount()
unsigned int pictureCount()
Tomb Raider 2/3 Script Loader.
Display level-completion stats.
std::string getPickupString(unsigned int i, unsigned int j)
Match N-S orientation of Room and animated characters.
static const char * testDescription[testPayloadCount]
std::string getPuzzleString(unsigned int i, unsigned int j)
unsigned int videoCount()
Kill all enemies to finish the level.
#define assertEqual(x, y)
int load(std::string file)
static int runForPayload(unsigned int n, bool print, bool printData)
std::string getKeyString(unsigned int i, unsigned int j)
std::string getGameString(unsigned int i)
unsigned int pcStringCount()
Tomb Raider Script Loader Unit Test Header.
Unused in TR2. Or PSX? Used in TR3.
If zero, level does not account for secrets.
unsigned int cutsceneCount()
std::string getPictureFilename(unsigned int i)
static int readPayloadChunk(const unsigned char *data, unsigned int size, const char *file)
unsigned int levelCount()
static const unsigned int testExpectedGameStringCount[testPayloadCount]
Lara starts level without ammo or medi packs.
Does not compile. PSX? Used in TR3.
std::string getCutsceneFilename(unsigned int i)
static const unsigned char * testPayloads[testPayloadCount]
Special animation of Lara when level starts.
End of game. Show stats, start credits sequence, music ID 52 in TR2.
static const unsigned int testPayloadCount
std::string getPCString(unsigned int i)
static int test(const char *file, unsigned int n)
#define printStrings(cnt, acc, name)
std::string getVideoFilename(unsigned int i)
Items given to Lara at level start (+1000), or at all secrets found (+0)
int main(int argc, char *argv[])