xcc_lmd_file_write.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 "xcc_lmd_file_write.h"
  17. #include "cc_structures.h"
  18. #include "xcc_file.h"
  19. void Cxcc_lmd_file_write::add_fname(const string& fname)
  20. {
  21. m_index.push_back(to_lower_copy(fname));
  22. }
  23. Cvirtual_binary Cxcc_lmd_file_write::write(t_game game) const
  24. {
  25. int size = sizeof(t_xcc_header) + sizeof(t_xcc_lmd_header);
  26. for (auto& i : m_index)
  27. size += i.length() + 1;
  28. Cvirtual_binary data;
  29. byte* w = data.write_start(size);
  30. t_xcc_header& header = *reinterpret_cast<t_xcc_header*>(w);
  31. strcpy(header.id, xcc_id);
  32. header.size = size;
  33. header.type = xcc_ft_lmd;
  34. header.version = 0;
  35. w += sizeof(t_xcc_header);
  36. t_xcc_lmd_header& lmd_header = *reinterpret_cast<t_xcc_lmd_header*>(w);
  37. lmd_header.c_fnames = m_index.size();
  38. lmd_header.game = game;
  39. w += sizeof(t_xcc_lmd_header);
  40. for (auto& i : m_index)
  41. {
  42. strcpy(reinterpret_cast<char*>(w), i.c_str());
  43. w += i.length() + 1;
  44. }
  45. return data;
  46. }