Advertisement
Guest User

example

a guest
Feb 3rd, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <map>
  5. #include <cctype>
  6. #include <functional>
  7. #include <algorithm>
  8. #include "ScoReader.h"
  9. #include "ScoWriter.h"
  10.  
  11. inline std::string trim(const std::string &s)
  12. {
  13.     const auto f = std::find_if_not(s.begin(), s.end(), [](int c) { return std::isspace(c); });
  14.     return std::string(f, std::find_if_not(s.rbegin(), std::string::const_reverse_iterator(f), [](int c) { return std::isspace(c); }).base());
  15. }
  16.  
  17. std::map<std::string, std::string> load_repl_list(const char* filename)
  18. {
  19.     std::ifstream f(filename);
  20.  
  21.     std::map<std::string, std::string> map;
  22.     while (!f.eof())
  23.     {
  24.         std::string s;
  25.         std::getline(f, s);
  26.  
  27.         auto p = s.find('#');
  28.         if (p != std::string::npos) s.erase(p);
  29.  
  30.         p = s.find("->");
  31.  
  32.         if (p == std::string::npos) continue;
  33.  
  34.         const auto a = trim(s.substr(0, p));
  35.         const auto b = trim(s.substr(p + 2));
  36.  
  37.         map[a] = b;
  38.     }
  39.  
  40.     f.close();
  41.  
  42.     return map;
  43. }
  44.  
  45. int main()
  46. {
  47.     auto map = load_repl_list("F:\\repl_list.txt");
  48.  
  49.     sco_file_t scene;
  50.     read_sco_file(fopen("E:\\Mount&Blade Warband\\Modules\\DNO_Historical_Battle_0.96\\SceneObj\\scn_town_nov_center.sco", "rb"), &scene);
  51.  
  52.     for (int i = 0; i < scene.num_mission_objects; i++)
  53.     {
  54.         if (scene.mission_objects[i].meta_type == MT_SCENE_PROP)
  55.         {
  56.             std::string id = scene.mission_objects[i].id;
  57.             id.erase(0, 4);
  58.             //std::cout << "scene prop '" << id << "'" << std::endl;
  59.             if (!map.count(id)) continue;
  60.             std::cout << "replace '" << id << "' with '" << map[id] << "'" << std::endl;
  61.             id = "spr_" + map[id];
  62.             scene.mission_objects[i].id = strdup(id.data());
  63.         }
  64.         else if (scene.mission_objects[i].meta_type == MT_FLORA)
  65.         {
  66.             std::string id = scene.mission_objects[i].id;
  67.             std::cout << "flora '" << id << "'" << std::endl;
  68.             if (!map.count(id)) continue;
  69.             std::cout << "replace '" << id << "' with '" << map[id] << "'" << std::endl;
  70.             id = map[id];
  71.             scene.mission_objects[i].id = strdup(id.data());
  72.         }
  73.     }
  74.  
  75.     write_sco_file(fopen("scn_town_25_center.sco", "wb"), &scene);
  76.  
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement