Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import Command
  3. import recalboxFiles
  4. import os.path
  5. from generators.Generator import Generator
  6. import dolphinControllers
  7. from settings.iniSettings import IniSettings
  8. from settings.keyValueSettings import keyValueSettings
  9.  
  10. class DolphinGenerator(Generator):
  11.  
  12. # Game Ratio
  13. GAME_RATIO = \
  14. {
  15. "auto": 0,
  16. "16/9": 1,
  17. "4/3": 2,
  18. "squarepixel": 3,
  19. }
  20.  
  21. # Gamecube languages
  22. GAMECUBE_LANGUAGES = \
  23. {
  24. "en": 0,
  25. "de": 1,
  26. "fr": 2,
  27. "es": 3,
  28. "it": 4,
  29. "du": 5,
  30. }
  31.  
  32. # Wii languages
  33. WII_LANGUAGES = \
  34. {
  35. "jp": 0,
  36. "en": 1,
  37. "de": 2,
  38. "fr": 3,
  39. "es": 4,
  40. "it": 5,
  41. "du": 6,
  42. "zh": 7, # traditional chinese 8, ignored
  43. "kr": 9,
  44. }
  45.  
  46. # Neplay servers
  47. NETPLAY_SERVERS = \
  48. {
  49. # Chine
  50. "CN": "CH",
  51. "TW": "CH",
  52. # Est Asia
  53. "KR": "EA",
  54. "RU": "EA",
  55. "JP": "EA",
  56. # Europe
  57. "GB": "EU",
  58. "DE": "EU",
  59. "FR": "EU",
  60. "ES": "EU",
  61. "IT": "EU",
  62. "PT": "EU",
  63. "TR": "EU",
  64. "SU": "EU",
  65. "NO": "EU",
  66. "NL": "EU",
  67. "PL": "EU",
  68. "HU": "EU",
  69. "CZ": "EU",
  70. "GR": "EU",
  71. "LU": "EU",
  72. "LV": "EU",
  73. "SE": "EU",
  74. # South America
  75. "BR": "SA",
  76. # North America
  77. "US": "NA",
  78. }
  79. ## Setting on dolphin.ini
  80. SECTION_ANALYTICS = "Analytics"
  81. SECTION_BTPASSTHROUGH = "BluetoothPassthrough"
  82. SECTION_CONTROLS = "Controls"
  83. SECTION_CORE = "Core"
  84. SECTION_GAMELIST = "GameList"
  85. SECTION_GENERAL = "General"
  86. SECTION_INTERFACE = "Interface"
  87. SECTION_NETPLAY = "NetPlay"
  88. ## Setting on GFX.ini
  89. SECTION_SETTINGS = "Settings"
  90. SECTION_HARDWARE = "Hardware"
  91.  
  92. # Get keyboard layout
  93. @staticmethod
  94. def GetLanguage():
  95. conf = keyValueSettings(recalboxFiles.recalboxConf)
  96. conf.loadFile(True)
  97. # Try to obtain from keyboard layout, then from system language, then fallback to us
  98. kl = conf.getOption("system.kblayout", conf.getOption("system.language", "en")[0:2]).lower()
  99. return kl
  100.  
  101. @staticmethod
  102. def GetEmulationstationLanguage():
  103. conf = keyValueSettings(recalboxFiles.recalboxConf)
  104. conf.loadFile(True)
  105. # Try to obtain from system language, then fallback to US or
  106. esLanguage = conf.getOption("system.language", "$")[0:2].upper()
  107. return esLanguage
  108.  
  109. # Get selected ratio
  110. @staticmethod
  111. def GetRatio():
  112. conf = keyValueSettings(recalboxFiles.recalboxConf)
  113. conf.loadFile(True)
  114. hasRatio = conf.getOption("gamecube.ratio", "$")
  115. return hasRatio
  116.  
  117. # Get netplay username
  118. @staticmethod
  119. def GetNetplay():
  120. conf = keyValueSettings(recalboxFiles.recalboxConf)
  121. conf.loadFile(True)
  122. speudo = conf.getOption("global.netplay.nickname", "$")
  123. return speudo
  124.  
  125. # Check if Gamecube bios IPL.bin in folders
  126. @staticmethod
  127. def CheckGamecubeIpl():
  128. ipl0 = "/usr/share/dolphin-emu/sys/GC/EUR/IPL.bin"
  129. ipl1 = "/usr/share/dolphin-emu/sys/GC/JP/IPL.bin"
  130. ipl2 = "/usr/share/dolphin-emu/sys/GC/USA/IPL.bin"
  131. # if os.path? return "True" set "False" for disable "SkipIpl=Video boot intro"
  132. if os.path.exists(ipl0 or ipl1 or ipl2):
  133. return("False")
  134. else:
  135. return("True")
  136.  
  137. # GameCube Controller Adapter for Wii U in Dolphin controllers if realgamecubepads=1 set in recalbox.conf
  138. @staticmethod
  139. def SetGamecubeWiiuAdapter():
  140. conf = keyValueSettings(recalboxFiles.recalboxConf)
  141. conf.loadFile(True)
  142. adapterStatus = conf.getOption("gamecube.realgamecubepads", "$")
  143. return adapterStatus
  144.  
  145. def mainConfiguration(self):
  146. # Get Languages
  147. language = self.GetLanguage()
  148. systemLanguage = self.GetEmulationstationLanguage()
  149. gamecubeLanguage = self.GAMECUBE_LANGUAGES[language] if language in self.GAMECUBE_LANGUAGES else 0
  150. wiiLanguage = self.WII_LANGUAGES[language] if language in self.WII_LANGUAGES else 0
  151. # Get Netplay configs
  152. nickname = self.GetNetplay()
  153. lobbyServer = self.NETPLAY_SERVERS[systemLanguage] if systemLanguage in self.NETPLAY_SERVERS else None
  154. ## Get if have all IPL.bin in folders Gc bios
  155. biosGamecube = self.CheckGamecubeIpl()
  156. ## set gamecube wiiu adapter
  157. padsgamecube = self.SetGamecubeWiiuAdapter()
  158.  
  159. # Load Configuration
  160. dolphinSettings = IniSettings(recalboxFiles.dolphinIni, True)
  161. dolphinSettings.loadFile(True)
  162.  
  163. # Analytics
  164. dolphinSettings.setOption(self.SECTION_ANALYTICS, "Enabled", "True")
  165. dolphinSettings.setOption(self.SECTION_ANALYTICS, "PermissionAsked", "True")
  166. # BluetoothPasstrough
  167. dolphinSettings.setOption(self.SECTION_BTPASSTHROUGH, "Enabled", "False")
  168. # Core
  169. dolphinSettings.setOption(self.SECTION_CORE, "SelectedLanguage", gamecubeLanguage)
  170. dolphinSettings.setOption(self.SECTION_CORE, "WiimoteContinuousScanning", "True")
  171. dolphinSettings.setOption(self.SECTION_CORE, "WiiKeyboard", "False")
  172. dolphinSettings.setOption(self.SECTION_CORE, "SkipIpl", biosGamecube)
  173. dolphinSettings.setOption(self.SECTION_CORE, "SIDevice0", "12" if padsgamecube == '1' else None)
  174. dolphinSettings.setOption(self.SECTION_CORE, "SIDevice1", "12" if padsgamecube == '1' else None)
  175. dolphinSettings.setOption(self.SECTION_CORE, "SIDevice2", "12" if padsgamecube == '1' else None)
  176. dolphinSettings.setOption(self.SECTION_CORE, "SIDevice3", "12" if padsgamecube == '1' else None)
  177. # GameList
  178. dolphinSettings.setOption(self.SECTION_GAMELIST, "ColumnID", "True")
  179. # General
  180. dolphinSettings.setOption(self.SECTION_GENERAL, "ISOPaths", "2")
  181. dolphinSettings.setOption(self.SECTION_GENERAL, "ISOPath0", "/recalbox/share/roms/gamecube")
  182. dolphinSettings.setOption(self.SECTION_GENERAL, "ISOPath1", "/recalbox/share/roms/wii")
  183. # Interface
  184. dolphinSettings.setOption(self.SECTION_INTERFACE, "LanguageCode", language)
  185. dolphinSettings.setOption(self.SECTION_INTERFACE, "AutoHideCursor", "True")
  186. dolphinSettings.setOption(self.SECTION_INTERFACE, "ConfirmStop", "False")
  187. dolphinSettings.setOption(self.SECTION_INTERFACE, "Language", wiiLanguage)
  188. # Netplay
  189. dolphinSettings.setOption(self.SECTION_NETPLAY, "Nickname", nickname)
  190. dolphinSettings.setOption(self.SECTION_NETPLAY, "UseUPNP", "True")
  191. dolphinSettings.setOption(self.SECTION_NETPLAY, "IndexName", nickname)
  192. dolphinSettings.setOption(self.SECTION_NETPLAY, "TraversalChoice", "traversal")
  193. dolphinSettings.setOption(self.SECTION_NETPLAY, "UseIndex", "True")
  194. dolphinSettings.setOption(self.SECTION_NETPLAY, "IndexRegion", lobbyServer)
  195.  
  196. # Save configuration
  197. dolphinSettings.saveFile()
  198.  
  199. def gfxConfiguration(self, system):
  200. # Get Ratio
  201. ratio = self.GetRatio()
  202. gameRatio = self.GAME_RATIO[ratio] if ratio in self.GAME_RATIO else 0
  203.  
  204. # Load Configuration
  205. gfxSettings = IniSettings(recalboxFiles.dolphinGFX, True)
  206. gfxSettings.loadFile(True)
  207.  
  208. # Hardware
  209. gfxSettings.setOption(self.SECTION_HARDWARE, "VSync", "True")
  210. # Settings
  211. gfxSettings.setOption(self.SECTION_SETTINGS, "ShowFPS", "True" if system.config['showFPS'] == 'true' else "False")
  212. gfxSettings.setOption(self.SECTION_SETTINGS, "AspectRatio", gameRatio)
  213.  
  214. # Save configuration
  215. gfxSettings.saveFile()
  216.  
  217. def generate(self, system, rom, playersControllers, demo, recalboxSettings):
  218. if not system.config['configfile']:
  219. # Controllers
  220. dolphinControllers.generateControllerConfig(system, playersControllers)
  221.  
  222. self.mainConfiguration()
  223. self.gfxConfiguration(system)
  224.  
  225. commandArray = [recalboxFiles.recalboxBins[system.config['emulator']], "-e", rom]
  226. if 'args' in system.config and system.config['args'] is not None:
  227. commandArray.extend(system.config['args'])
  228. return Command.Command(videomode=system.config['videomode'], array=commandArray, env={"XDG_CONFIG_HOME":recalboxFiles.CONF, "XDG_DATA_HOME":recalboxFiles.SAVES})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement