Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Loader.cpp 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*!
  2. * \file src/loader/Loader.cpp
  3. * \brief Level file loader
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "loader/Loader.h"
  9. #include "loader/LoaderTR1.h"
  10. #include "loader/LoaderTR2.h"
  11. #include "loader/LoaderTR3.h"
  12. Loader::LoaderVersion Loader::checkFile(std::string f) {
  13. BinaryFile file;
  14. if (file.open(f.c_str()) != 0)
  15. return TR_UNKNOWN;
  16. uint32_t start = file.readU32();
  17. switch (start) {
  18. case 0x00000020:
  19. return TR_1;
  20. case 0x0000002D:
  21. return TR_2;
  22. case 0xFF080038:
  23. case 0xFF180038:
  24. return TR_3;
  25. case 0xFFFFFFF0: // bogus
  26. case 0x00345254: // "TR4\0"
  27. return TR_4;
  28. }
  29. return TR_UNKNOWN;
  30. }
  31. std::unique_ptr<Loader> Loader::createLoader(std::string f) {
  32. LoaderVersion v = checkFile(f);
  33. switch (v) {
  34. case TR_1:
  35. return std::unique_ptr<Loader>(new LoaderTR1());
  36. case TR_2:
  37. return std::unique_ptr<Loader>(new LoaderTR2());
  38. case TR_3:
  39. return std::unique_ptr<Loader>(new LoaderTR3());
  40. }
  41. return nullptr;
  42. }
  43. Loader::~Loader() { }