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.

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