id_log.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. XCC Utilities and Library
  3. Copyright (C) 2000 Olaf van der Spek <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #include "stdafx.h"
  16. #include <id_log.h>
  17. #include <fstream>
  18. #include <mix_file.h>
  19. #include <string_conversion.h>
  20. #include <xcc_dirs.h>
  21. struct t_idinfo
  22. {
  23. string name;
  24. string description;
  25. };
  26. using t_id_list = map<int, t_idinfo>;
  27. t_id_list td_list, ra_list, ts_list, dune2_list, ra2_list;
  28. static t_id_list& get_list(t_game game)
  29. {
  30. switch (game)
  31. {
  32. case game_ra:
  33. return ra_list;
  34. case game_ts:
  35. return ts_list;
  36. case game_dune2:
  37. return dune2_list;
  38. case game_ra2:
  39. return ra2_list;
  40. }
  41. return td_list;
  42. }
  43. static void read_list(t_game game, const char*& s)
  44. {
  45. t_id_list& d = get_list(game);
  46. int count = *reinterpret_cast<const int*>(s);
  47. s += 4;
  48. t_idinfo idinfo;
  49. while (count--)
  50. {
  51. idinfo.name = s;
  52. s += idinfo.name.length() + 1;
  53. idinfo.description = s;
  54. s += idinfo.description.length() + 1;
  55. d[Cmix_file::get_id(game, idinfo.name)] = idinfo;
  56. }
  57. }
  58. int mix_database::load()
  59. {
  60. if (!td_list.empty() || !ra_list.empty() || !ts_list.empty())
  61. return 0;
  62. Cvirtual_binary f;
  63. if (f.load(xcc_dirs::get_data_dir() + "global mix database.dat") || f.size() < 16)
  64. return 1;
  65. const char* data = reinterpret_cast<const char*>(f.data());
  66. read_list(game_td, data);
  67. read_list(game_ra, data);
  68. read_list(game_ts, data);
  69. read_list(game_ra2, data);
  70. if (0)
  71. {
  72. ofstream log_f("c:\\log.txt");
  73. for (auto& i : ts_list)
  74. log_f << i.second.name << '\t' << i.second.description << endl;
  75. }
  76. return 0;
  77. char name[12] = "scg00ea.bin";
  78. const char char1[] = "bgjm";
  79. const char char2[] = "ew";
  80. const char char3[] = "abc";
  81. for (int i = 0; i < 2; i++)
  82. {
  83. if (i)
  84. strcpy(name + 8, "ini");
  85. for (int j = 0; j < 4; j++)
  86. {
  87. name[2] = char1[j];
  88. for (int k = 0; k < 100; k++)
  89. {
  90. memcpy(name + 3, nwzl(2, k).c_str(), 2);
  91. for (int l = 0; l < 2; l++)
  92. {
  93. name[5] = char2[l];
  94. for (int m = 0; m < 3; m++)
  95. {
  96. name[6] = char3[m];
  97. mix_database::add_name(game_td, name, "");
  98. mix_database::add_name(game_ra, name, "");
  99. mix_database::add_name(game_ts, name, "");
  100. }
  101. }
  102. }
  103. }
  104. }
  105. return 0;
  106. }
  107. void mix_database::add_name(t_game game, const string& name, const string& description)
  108. {
  109. t_idinfo idinfo;
  110. idinfo.name = name;
  111. idinfo.description = description;
  112. get_list(game)[Cmix_file::get_id(game, name)] = idinfo;
  113. }
  114. string mix_database::get_name(t_game game, int id)
  115. {
  116. auto i = find_ptr(get_list(game), id);
  117. return i ? i->name : "";
  118. }
  119. string mix_database::get_description(t_game game, int id)
  120. {
  121. auto i = find_ptr(get_list(game), id);
  122. return i ? i->description : "";
  123. }