cfg.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include "common/common_types.h"
  7. union ResultCode;
  8. namespace Service {
  9. class Interface;
  10. namespace CFG {
  11. enum SystemModel {
  12. NINTENDO_3DS = 0,
  13. NINTENDO_3DS_XL = 1,
  14. NEW_NINTENDO_3DS = 2,
  15. NINTENDO_2DS = 3,
  16. NEW_NINTENDO_3DS_XL = 4
  17. };
  18. enum SystemLanguage {
  19. LANGUAGE_JP = 0,
  20. LANGUAGE_EN = 1,
  21. LANGUAGE_FR = 2,
  22. LANGUAGE_DE = 3,
  23. LANGUAGE_IT = 4,
  24. LANGUAGE_ES = 5,
  25. LANGUAGE_ZH = 6,
  26. LANGUAGE_KO = 7,
  27. LANGUAGE_NL = 8,
  28. LANGUAGE_PT = 9,
  29. LANGUAGE_RU = 10
  30. };
  31. /// Block header in the config savedata file
  32. struct SaveConfigBlockEntry {
  33. u32 block_id; ///< The id of the current block
  34. u32 offset_or_data; ///< This is the absolute offset to the block data if the size is greater than 4 bytes, otherwise it contains the data itself
  35. u16 size; ///< The size of the block
  36. u16 flags; ///< The flags of the block, possibly used for access control
  37. };
  38. static constexpr u16 C(const char code[2]) {
  39. return code[0] | (code[1] << 8);
  40. }
  41. static const std::array<u16, 187> country_codes = {{
  42. 0, C("JP"), 0, 0, 0, 0, 0, 0, // 0-7
  43. C("AI"), C("AG"), C("AR"), C("AW"), C("BS"), C("BB"), C("BZ"), C("BO"), // 8-15
  44. C("BR"), C("VG"), C("CA"), C("KY"), C("CL"), C("CO"), C("CR"), C("DM"), // 16-23
  45. C("DO"), C("EC"), C("SV"), C("GF"), C("GD"), C("GP"), C("GT"), C("GY"), // 24-31
  46. C("HT"), C("HN"), C("JM"), C("MQ"), C("MX"), C("MS"), C("AN"), C("NI"), // 32-39
  47. C("PA"), C("PY"), C("PE"), C("KN"), C("LC"), C("VC"), C("SR"), C("TT"), // 40-47
  48. C("TC"), C("US"), C("UY"), C("VI"), C("VE"), 0, 0, 0, // 48-55
  49. 0, 0, 0, 0, 0, 0, 0, 0, // 56-63
  50. C("AL"), C("AU"), C("AT"), C("BE"), C("BA"), C("BW"), C("BG"), C("HR"), // 64-71
  51. C("CY"), C("CZ"), C("DK"), C("EE"), C("FI"), C("FR"), C("DE"), C("GR"), // 72-79
  52. C("HU"), C("IS"), C("IE"), C("IT"), C("LV"), C("LS"), C("LI"), C("LT"), // 80-87
  53. C("LU"), C("MK"), C("MT"), C("ME"), C("MZ"), C("NA"), C("NL"), C("NZ"), // 88-95
  54. C("NO"), C("PL"), C("PT"), C("RO"), C("RU"), C("RS"), C("SK"), C("SI"), // 96-103
  55. C("ZA"), C("ES"), C("SZ"), C("SE"), C("CH"), C("TR"), C("GB"), C("ZM"), // 104-111
  56. C("ZW"), C("AZ"), C("MR"), C("ML"), C("NE"), C("TD"), C("SD"), C("ER"), // 112-119
  57. C("DJ"), C("SO"), C("AD"), C("GI"), C("GG"), C("IM"), C("JE"), C("MC"), // 120-127
  58. C("TW"), 0, 0, 0, 0, 0, 0, 0, // 128-135
  59. C("KR"), 0, 0, 0, 0, 0, 0, 0, // 136-143
  60. C("HK"), C("MO"), 0, 0, 0, 0, 0, 0, // 144-151
  61. C("ID"), C("SG"), C("TH"), C("PH"), C("MY"), 0, 0, 0, // 152-159
  62. C("CN"), 0, 0, 0, 0, 0, 0, 0, // 160-167
  63. C("AE"), C("IN"), C("EG"), C("OM"), C("QA"), C("KW"), C("SA"), C("SY"), // 168-175
  64. C("BH"), C("JO"), 0, 0, 0, 0, 0, 0, // 176-183
  65. C("SM"), C("VA"), C("BM") // 184-186
  66. }};
  67. /**
  68. * CFG::GetCountryCodeString service function
  69. * Inputs:
  70. * 1 : Country Code ID
  71. * Outputs:
  72. * 1 : Result of function, 0 on success, otherwise error code
  73. * 2 : Country's 2-char string
  74. */
  75. void GetCountryCodeString(Service::Interface* self);
  76. /**
  77. * CFG::GetCountryCodeID service function
  78. * Inputs:
  79. * 1 : Country Code 2-char string
  80. * Outputs:
  81. * 1 : Result of function, 0 on success, otherwise error code
  82. * 2 : Country Code ID
  83. */
  84. void GetCountryCodeID(Service::Interface* self);
  85. /**
  86. * CFG::GetConfigInfoBlk2 service function
  87. * Inputs:
  88. * 0 : 0x00010082
  89. * 1 : Size
  90. * 2 : Block ID
  91. * 3 : Descriptor for the output buffer
  92. * 4 : Output buffer pointer
  93. * Outputs:
  94. * 1 : Result of function, 0 on success, otherwise error code
  95. */
  96. void GetConfigInfoBlk2(Service::Interface* self);
  97. /**
  98. * CFG::SecureInfoGetRegion service function
  99. * Inputs:
  100. * 1 : None
  101. * Outputs:
  102. * 0 : Result Header code
  103. * 1 : Result of function, 0 on success, otherwise error code
  104. * 2 : Region value loaded from SecureInfo offset 0x100
  105. */
  106. void SecureInfoGetRegion(Service::Interface* self);
  107. /**
  108. * CFG::GenHashConsoleUnique service function
  109. * Inputs:
  110. * 1 : 20 bit application ID salt
  111. * Outputs:
  112. * 0 : Result Header code
  113. * 1 : Result of function, 0 on success, otherwise error code
  114. * 2 : Hash/"ID" lower word
  115. * 3 : Hash/"ID" upper word
  116. */
  117. void GenHashConsoleUnique(Service::Interface* self);
  118. /**
  119. * CFG::GetRegionCanadaUSA service function
  120. * Inputs:
  121. * 1 : None
  122. * Outputs:
  123. * 0 : Result Header code
  124. * 1 : Result of function, 0 on success, otherwise error code
  125. * 2 : 1 if the system is a Canada or USA model, 0 otherwise
  126. */
  127. void GetRegionCanadaUSA(Service::Interface* self);
  128. /**
  129. * CFG::GetSystemModel service function
  130. * Inputs:
  131. * 0 : 0x00050000
  132. * Outputs:
  133. * 1 : Result of function, 0 on success, otherwise error code
  134. * 2 : Model of the console
  135. */
  136. void GetSystemModel(Service::Interface* self);
  137. /**
  138. * CFG::GetModelNintendo2DS service function
  139. * Inputs:
  140. * 0 : 0x00060000
  141. * Outputs:
  142. * 1 : Result of function, 0 on success, otherwise error code
  143. * 2 : 0 if the system is a Nintendo 2DS, 1 otherwise
  144. */
  145. void GetModelNintendo2DS(Service::Interface* self);
  146. /**
  147. * CFG::GetConfigInfoBlk2 service function
  148. * Inputs:
  149. * 0 : 0x00010082
  150. * 1 : Size
  151. * 2 : Block ID
  152. * 3 : Descriptor for the output buffer
  153. * 4 : Output buffer pointer
  154. * Outputs:
  155. * 1 : Result of function, 0 on success, otherwise error code
  156. */
  157. void GetConfigInfoBlk2(Service::Interface* self);
  158. /**
  159. * CFG::GetConfigInfoBlk8 service function
  160. * Inputs:
  161. * 0 : 0x04010082 / 0x08010082
  162. * 1 : Size
  163. * 2 : Block ID
  164. * 3 : Descriptor for the output buffer
  165. * 4 : Output buffer pointer
  166. * Outputs:
  167. * 1 : Result of function, 0 on success, otherwise error code
  168. */
  169. void GetConfigInfoBlk8(Service::Interface* self);
  170. /**
  171. * CFG::UpdateConfigNANDSavegame service function
  172. * Inputs:
  173. * 0 : 0x04030000 / 0x08030000
  174. * Outputs:
  175. * 1 : Result of function, 0 on success, otherwise error code
  176. */
  177. void UpdateConfigNANDSavegame(Service::Interface* self);
  178. /**
  179. * CFG::FormatConfig service function
  180. * Inputs:
  181. * 0 : 0x08060000
  182. * Outputs:
  183. * 1 : Result of function, 0 on success, otherwise error code
  184. */
  185. void FormatConfig(Service::Interface* self);
  186. /**
  187. * Reads a block with the specified id and flag from the Config savegame buffer
  188. * and writes the output to output.
  189. * The input size must match exactly the size of the requested block
  190. * @param block_id The id of the block we want to read
  191. * @param size The size of the block we want to read
  192. * @param flag The requested block must have this flag set
  193. * @param output A pointer where we will write the read data
  194. * @returns ResultCode indicating the result of the operation, 0 on success
  195. */
  196. ResultCode GetConfigInfoBlock(u32 block_id, u32 size, u32 flag, u8* output);
  197. /**
  198. * Creates a block with the specified id and writes the input data to the cfg savegame buffer in memory.
  199. * The config savegame file in the filesystem is not updated.
  200. * @param block_id The id of the block we want to create
  201. * @param size The size of the block we want to create
  202. * @param flags The flags of the new block
  203. * @param data A pointer containing the data we will write to the new block
  204. * @returns ResultCode indicating the result of the operation, 0 on success
  205. */
  206. ResultCode CreateConfigInfoBlk(u32 block_id, u16 size, u16 flags, const void* data);
  207. /**
  208. * Deletes the config savegame file from the filesystem, the buffer in memory is not affected
  209. * @returns ResultCode indicating the result of the operation, 0 on success
  210. */
  211. ResultCode DeleteConfigNANDSaveFile();
  212. /**
  213. * Writes the config savegame memory buffer to the config savegame file in the filesystem
  214. * @returns ResultCode indicating the result of the operation, 0 on success
  215. */
  216. ResultCode UpdateConfigNANDSavegame();
  217. /**
  218. * Re-creates the config savegame file in memory and the filesystem with the default blocks
  219. * @returns ResultCode indicating the result of the operation, 0 on success
  220. */
  221. ResultCode FormatConfig();
  222. /// Initialize the config service
  223. void Init();
  224. /// Shutdown the config service
  225. void Shutdown();
  226. } // namespace CFG
  227. } // namespace Service