OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
Loader.cpp
Go to the documentation of this file.
1 
8 #include "global.h"
9 #include "loader/Loader.h"
10 #include "loader/LoaderTR1.h"
11 #include "loader/LoaderTR2.h"
12 #include "loader/LoaderTR3.h"
13 
16  if (file.open(f.c_str()) != 0)
17  return TR_UNKNOWN;
18 
19  uint32_t start = file.readU32();
20  switch (start) {
21  case 0x00000020:
22  return TR_1;
23 
24  case 0x0000002D:
25  return TR_2;
26 
27  case 0xFF080038:
28  case 0xFF180038:
29  return TR_3;
30 
31  case 0xFFFFFFF0: // bogus
32  case 0x00345254: // "TR4\0"
33  return TR_4;
34  }
35 
36  return TR_UNKNOWN;
37 }
38 
39 std::unique_ptr<Loader> Loader::createLoader(std::string f) {
40  LoaderVersion v = checkFile(f);
41  switch (v) {
42  case TR_4:
43  case TR_5:
44  case TR_UNKNOWN:
45  return nullptr;
46 
47  case TR_1:
48  return std::unique_ptr<Loader>(new LoaderTR1());
49 
50  case TR_2:
51  return std::unique_ptr<Loader>(new LoaderTR2());
52 
53  case TR_3:
54  return std::unique_ptr<Loader>(new LoaderTR3());
55  }
56 }
57 
static LoaderVersion checkFile(std::string f)
Definition: Loader.cpp:14
BinaryFile file
Definition: Loader.h:34
TR2 level file loader.
Level file loader.
TR1 level file loader.
TR3 level file loader.
Included everywhere.
virtual uint32_t readU32()
Definition: binary.cpp:27
static std::unique_ptr< Loader > createLoader(std::string f)
Definition: Loader.cpp:39
LoaderVersion
Definition: Loader.h:19
int open(std::string f="")
Definition: binary.cpp:112