rfancella

Demul (v0.5.8.2).ahk

Nov 13th, 2014
2,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.55 KB | None | 0 0
  1. MEmu = Demul
  2. MEmuV = v0.5.8.2
  3. MURL = http://demul.emulation64.com/
  4. MAuthor = djvj
  5. MVersion = 2.0.5 BETA
  6. MCRC = EFEE7501
  7. iCRC = F43FB746
  8. mId = 635211874656892855
  9. MSystem = "Gaelco","Sammy Atomiswave","Sega Dreamcast","Sega Hikaru","Sega Naomi","Sega Naomi 2"
  10. ;----------------------------------------------------------------------------
  11. ; Notes:
  12. ; Required - control and nvram files can be found in my user dir on the FTP at /Upload Here/djvj/Sega Naomi\Emulators. Additonal instructions from my orignal HL1.0 script at http://www.hyperspin-fe.com/forum/showpost.php?p=86093&postcount=104
  13. ; Required - moduleName ini example can be found on GIT in the Demul module folder
  14. ; moduleName ini must be placed in same folder as this module if you use the provided example, just be sure to rename it to just Demul.ini first so it matches the module's name
  15. ; GDI images must match mame zip names and be extracted and have a .dat extension
  16. ; Rom_Extension should include 7z|zip|gdi|cue|cdi|chd|mds|ccd|nrg
  17. ; Module will automatically set your rom path for you on first launch
  18. ;
  19. ; Make sure the awbios, dc, hikaru, naomi, naomi2, saturn.zip bios archives are in any of your rom paths as they are needed to play all the games.
  20. ; Set your Video Plugin to gpuDX11 and set your desired resolution there
  21. ; In case your control codes do not match mine, set your desired control type in demul, then open the demul.ini and find section PORTB and look for the device key. Use this number instead of the one I provided
  22. ; gpuDX10 and gpuDX11 are the only supported plugins. You can define what plugin you want to use for each game in the module settings in HLHQ
  23. ; Read the tooltip for the Fullscreen module setting in HLHQ on how to control windowed fullscreen, true fullscreen, or windowed mode
  24. ; Windowed fullscreen will take effect the 2nd time you run the emu. It has to calculate your resolution on first run.
  25. ;
  26. ; Controls:
  27. ; Start a game of each control type (look in the HLHQ's module settings for these types, they all have their own tabs) and configure your controls to play the game. After configuring your controls manually in Demul, open padDemul.ini and Copy/paste the JAMMA0_0 and JAMMA0_1 (for naomi) or the ATOMISWAVE0_0 and ATOMISWAVE0_1 (for atomiswave) into HLHQ's module settings for each controls tab (standard, sfstyle, etc).
  28. ; Each pair of control tabs designates another real arcade control schema for a grouping of games. Demul does not handle this like MAME, so the module does instead.
  29. ;
  30. ; Troubleshooting:
  31. ; For some reason demul's ini files can get corrupted and ahk can't read/write to them correctly.
  32. ; If your ini keys are not being read or not writing to their existing keys in the demul inis, create a new file and copy/paste everything from the old ini into the new one and save.
  33. ; If you use Fade_Out, the module will disable it. Demul crashes when Fade tries to draw on top of it in windowed and fullscreen modes.
  34. ;----------------------------------------------------------------------------
  35. StartModule()
  36. BezelGUI()
  37. ExtraFixedResBezelGUI()
  38. FadeInStart()
  39.  
  40. ; This object controls how the module reacts to different systems. Demul can play a few systems, but needs to know what system you want to run, so this module has to adapt.
  41. mType := Object("Gaelco","gaelco","Sammy Atomiswave","atomiswave","Sega Dreamcast","dc","Sega Hikaru","hikaru","Sega Naomi","naomi","Sega Naomi 2","naomi2")
  42. ident := mType[systemName] ; search object for the systemName identifier Demul uses
  43. If !ident
  44. ScriptError("Your systemName is: " . systemName . "`nIt is not one of the known supported systems for this Demul module: " . moduleName)
  45.  
  46. settingsFile := modulePath . "\" . moduleName . ".ini"
  47. demulFile := CheckFile(emuPath . "\Demul.ini", "Could not find Demul's ini. Please run Demul manually first and each of it's settings sections so the appropriate inis are created for you: " . emuPath . "\Demul.ini")
  48. padFile := CheckFile(emuPath . "\padDemul.ini", "Could not find Demul's control ini. Please run Demul manually first and set up your controls so this file is created for you: " . emuPath . "\padDemul.ini")
  49.  
  50. demulFileEncoding := COM_Invoke(HLObject, "getFileEncoding", demulFile)
  51. If demulFileEncoding {
  52. Log("Module - Recreating " . demulFile . " as ANSI because UTF-8 format cannot be read")
  53. If COM_Invoke(HLObject, "removeBOM", demulFile)
  54. Log("Module - Successfully converted " . demulFile . " to ANSI")
  55. Else
  56. Log("Module - Failed to convert " . demulFile . " to ANSI",3)
  57. }
  58.  
  59. maxHideTaskbar := IniReadCheck(settingsFile, "Settings", "MaxHideTaskbar", "true",,1)
  60. controllerCode := IniReadCheck(settingsFile, "Settings", "ControllerCode", "16777216",,1)
  61. mouseCode := IniReadCheck(settingsFile, "Settings", "MouseCode", "131072",,1)
  62. keyboardCode := IniReadCheck(settingsFile, "Settings", "KeyboardCode", "1073741824",,1)
  63. lightgunCode := IniReadCheck(settingsFile, "Settings", "LightgunCode", "-2147483648",,1)
  64. lastControlUsed := IniReadCheck(settingsFile, "Settings", "LastControlUsed",,,1)
  65. hideDemulGUI := IniReadCheck(settingsFile, "Settings", "HideDemulGUI", "true",,1)
  66. PerGameMemoryCards := IniReadCheck(settingsFile, "Settings", "PerGameMemoryCards", "true",,1)
  67. memCardPath := IniReadCheck(settingsFile, "Settings", "memCardPath", EmuPath . "\memsaves",,1)
  68. memCardPath := AbsoluteFromRelative(EmuPath, memCardPath)
  69.  
  70. fullscreen := IniReadCheck(settingsFile, "Settings|" . romName, "Fullscreen", "windowedfullscreen",,1)
  71. plugin := IniReadCheck(settingsFile, "Settings|" . romName, "Plugin", "gpuDX11",,1)
  72. shaderUsePass1 := IniReadCheck(settingsFile, "Settings|" . romName, "ShaderUsePass1", "false",,1)
  73. shaderUsePass2 := IniReadCheck(settingsFile, "Settings|" . romName, "ShaderUsePass2", "false",,1)
  74. shaderNamePass1 := IniReadCheck(settingsFile, "Settings|" . romName, "ShaderNamePass1",,,1)
  75. shaderNamePass2 := IniReadCheck(settingsFile, "Settings|" . romName, "ShaderNamePass2",,,1)
  76. listSorting := IniReadCheck(settingsFile, "Settings|" . romName, "ListSorting", "true",,1)
  77. OpaqueMod := IniReadCheck(settingsFile, "Settings|" . romName, "OModifier", "true",,1)
  78. TransMod := IniReadCheck(settingsFile, "Settings|" . romName, "TModifier", "true",,1)
  79. internalResolutionScale := IniReadCheck(settingsFile, "Settings|" . romName, "InternalResolutionScale", "1",,1)
  80. videomode := IniReadCheck(settingsFile, "Settings|" . romName, "VideoMode", "0",,1)
  81.  
  82. displayVMU := IniReadCheck(settingsFile, "Settings", "DisplayVMU", "true",,1)
  83. VMUPos := IniReadCheck(settingsFile, "Settings", "VMUPos", "topRight",,1) ; topRight, topCenter, topLeft, leftCenter, bottomLeft, bottomCenter, bottomRight, rightCenter
  84. VMUHideKey := IniReadCheck(settingsFile, "Settings", "VMUHideKey","F10",,1)
  85.  
  86. Bios := IniReadCheck(settingsFile, romName, "Bios",,,1)
  87. LoadDecrypted := IniReadCheck(settingsFile, romName, "LoadDecrypted",,,1) ; not currently supported
  88.  
  89. ; Read all the control values
  90. controls := IniReadCheck(settingsFile, romname, "Controls", "standard",,1) ; have to read this first so the below ini reads work
  91. push1_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "push1",,,1)
  92. push2_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "push2",,,1)
  93. push3_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "push3",,,1)
  94. push4_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "push4",,,1)
  95. push5_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "push5",,,1)
  96. push6_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "push6",,,1)
  97. push7_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "push7",,,1)
  98. push8_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "push8",,,1)
  99. service_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "SERVICE",,,1)
  100. start_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "START",,,1)
  101. coin_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "COIN",,,1)
  102. digitalup_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "DIGITALUP",,,1)
  103. digitaldown_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "DIGITALDOWN",,,1)
  104. digitalleft_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "DIGITALLEFT",,,1)
  105. digitalright_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "DIGITALRIGHT",,,1)
  106. analogup_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "ANALOGUP",,,1)
  107. analogdown_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "ANALOGDOWN",,,1)
  108. analogleft_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "ANALOGLEFT",,,1)
  109. analogright_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "ANALOGRIGHT",,,1)
  110. analogup2_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "ANALOGUP2",,,1)
  111. analogdown2_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "ANALOGDOWN2",,,1)
  112. analogleft2_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "ANALOGLEFT2",,,1)
  113. analogright2_0 := IniReadCheck(settingsFile, controls . "_JAMMA0_0", "ANALOGRIGHT2",,,1)
  114. push1_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "push1",,,1)
  115. push2_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "push2",,,1)
  116. push3_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "push3",,,1)
  117. push4_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "push4",,,1)
  118. push5_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "push5",,,1)
  119. push6_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "push6",,,1)
  120. push7_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "push7",,,1)
  121. push8_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "push8",,,1)
  122. service_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "SERVICE",,,1)
  123. start_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "START",,,1)
  124. coin_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "COIN",,,1)
  125. digitalup_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "DIGITALUP",,,1)
  126. digitaldown_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "DIGITALDOWN",,,1)
  127. digitalleft_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "DIGITALLEFT",,,1)
  128. digitalright_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "DIGITALRIGHT",,,1)
  129. analogup_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "ANALOGUP",,,1)
  130. analogdown_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "ANALOGDOWN",,,1)
  131. analogleft_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "ANALOGLEFT",,,1)
  132. analogright_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "ANALOGRIGHT",,,1)
  133. analogup2_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "ANALOGUP2",,,1)
  134. analogdown2_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "ANALOGDOWN2",,,1)
  135. analogleft2_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "ANALOGLEFT2",,,1)
  136. analogright2_1 := IniReadCheck(settingsFile, controls . "_JAMMA0_1", "ANALOGRIGHT2",,,1)
  137.  
  138. ; Verify user set desired gpu plugin name correctly
  139. If ( plugin != "gpuDX11" && plugin != "gpuDX10" && plugin != "")
  140. ScriptError(plugin . " is not a supported gpu plugin.`nLeave the plugin blank to use the default ""gpuDX11"".`nValid options are gpuDX11 or gpuDX10.")
  141.  
  142. ; Read and write videomode value for cable type
  143. IniRead, rvideomode, %demulFile%, main, videomode
  144. Log("Module - Demul is reading the config with videomode = " . rvideomode)
  145. IniWrite, %videomode%, %demulFile%, main, videomode
  146. Log("Module - Demul is updating the config with videomode = " . videomode)
  147. ;ExitApp
  148.  
  149. ; Handle Demul's rom paths so the user doesn't have to
  150. IniRead, romPathCount, %demulFile%, files, romsPathsCount
  151. Log("Module - Demul is configured with " . romPathCount . " rom path(s). Scanning these for a romPath to this rom.")
  152. Loop, %romPathCount%
  153. { demulRomPath := A_Index - 1 ; rompaths in demul start with 0
  154. IniRead, path%A_Index%, %demulFile%, files, roms%demulRomPath%
  155. Log("Module - Path" . demulRomPath . ": " . path%A_Index%)
  156. ; msgbox % path%A_Index%
  157. If (path%A_Index% = romPath . "\") ; demul tacks on the backslash at the end
  158. { romPathFound := 1 ; flag that demul has this romPath in its config and no need to add it
  159. Log("Module - Stopping search because Demul is already configured with the correct romPath to this rom: " . path%A_Index%)
  160. Break ; stop looking for a correct romPath
  161. }
  162. }
  163. If !romPathFound ; if demul doesn't have the romPath in its ini, add it
  164. { Log("Module - Demul does not have this romPath in Demul.ini, adding it for you.",2)
  165. nextPath := romPathCount + 1 ; add 1 to the romPathCount and write that to the ini
  166. IniWrite, %nextPath%, %demulFile%, files, romsPathsCount
  167. IniWrite, %romPath%\, %demulFile%, files, % "roms" . romPathCount ; write the rompath to the ini
  168. }
  169.  
  170. BezelStart("FixResMode")
  171.  
  172. ; Force Fade_Out to disabled as it causes demul to not close properly
  173. fadeOut = false
  174. Log("Module - Turning off Fade_Out because it doesn't let Demul exit properly.",2)
  175.  
  176. ; check for the specified gpu plugin
  177. gpuFile := CheckFile(emuPath . "\" . plugin . ".ini")
  178.  
  179. demulFileEncoding := COM_Invoke(HLObject, "getFileEncoding", gpuFile)
  180. If demulFileEncoding {
  181. Log("Module - Recreating " . gpuFile . " as ANSI because UTF-8 format cannot be read")
  182. If COM_Invoke(HLObject, "removeBOM", gpuFile)
  183. Log("Module - Successfully converted " . gpuFile . " to ANSI")
  184. Else
  185. Log("Module - Failed to convert " . gpuFile . " to ANSI",3)
  186. }
  187.  
  188. ; This updates the DX11gpu ini file to turn List Sorting on or off. Depending on the games, turning this on for some games may remedy missing graphics, having it off on other games may fix corrupted graphics. Untill they improve the DX11gpu, this is the best it's gonna get.
  189. If ListSorting = true
  190. IniWrite, 0, %gpuFile%, main, AutoSort
  191. Else
  192. IniWrite, 1, %gpuFile%, main, AutoSort
  193.  
  194. ; This will set the Opaque or Trans modifier for each game
  195. If OpaqueMod = true
  196. IniWrite, 0, %gpuFile%, main, OModifier
  197. Else
  198. IniWrite, 1, %gpuFile%, main, OModifier
  199.  
  200. If TransMod = true
  201. IniWrite, 0, %gpuFile%, main, TModifier
  202. Else
  203. IniWrite, 1, %gpuFile%, main, TModifier
  204.  
  205. ; This updates the DX10gpu or DX11gpu ini file to the scale you want to use for this game
  206. IniWrite, %InternalResolutionScale%, %gpuFile%, main, scaling
  207.  
  208. ; This updates the demul.ini with your gpu plugin choice for the selected rom
  209. IniWrite, %plugin%.dll, %demulFile%, plugins, gpu
  210.  
  211. ; This updates the demul.ini with your VMU display choice
  212. VMUscreendisable := if (displayVMU="true") ? "false" : "true"
  213. IniWrite, %VMUscreendisable% , %demulFile%, main, VMUscreendisable
  214.  
  215. ; Shader Effects
  216. Loop, 2 {
  217. shaderUsePass%A_Index% := If (ShaderUsePass%A_Index% != "" and ShaderUsePass%A_Index% != "ERROR" ? (ShaderUsePass%A_Index%) : (GlobalShaderUsePass%A_Index%)) ; determine what shaderUsePass to use
  218. IniRead, currentusePass%A_Index%, %gpuFile%, shaders, usePass%A_Index%
  219. If (shaderUsePass%A_Index% = "true")
  220. {
  221. shaderNamePass%A_Index% := If (ShaderNamePass%A_Index% != "" and ShaderNamePass%A_Index% != "ERROR" ? (ShaderNamePass%A_Index%) : (GlobalShaderNamePass%A_Index%)) ; determine what shaderNamePass to use
  222. If shaderNamePass%A_Index% not in FXAA,HDR-TV,SCANLINES,CARTOON,RGB DOT(MICRO),RGB DOT(TINY),BLUR
  223. ScriptError(shaderNamePass%A_Index% . " is not a valid choice for a shader. Your options are FXAA, HDR-TV, SCANLINES, CARTOON, RGB DOT(MICRO), RGB DOT(TINY), or BLUR.")
  224. If (currentusePass%A_Index% = 0)
  225. IniWrite, 1, %gpuFile%, shaders, usePass%A_Index% ; turn shader on in gpuDX11 ini
  226. IniWrite, % shaderNamePass%A_Index%, %gpuFile%, shaders, shaderPass%A_Index% ; update gpuDX11 ini with the shader name to use
  227. }Else If (shaderUsePass%A_Index% != "true" and currentusePass%A_Index% = 1)
  228. IniWrite, 0, %gpuFile%, shaders, usePass%A_Index% ; turn shader off in gpuDX11 ini
  229. }
  230.  
  231. If ident = dc
  232. {
  233. 7z(romPath, romName, romExtension, 7zExtractPath)
  234. If ( romExtension = ".cdi" || romExtension = ".mds" || romExtension = ".ccd" || romExtension = ".nrg" || romExtension = ".gdi" || romExtension = ".cue" ) {
  235. gdrImageFile := CreateDefaultGDROMIni("image")
  236. FileDelete, %gdrImageFile%
  237. Sleep, 500
  238. IniWrite, gdrImage.dll, %demulFile%, plugins, gdr
  239. IniWrite, false, %gdrImageFile%, Main, openDialog
  240. IniWrite, %romPath%\%romName%%romExtension%, %gdrImageFile%, Main, imagefilename
  241. } Else If romExtension = .chd
  242. {
  243. gdrCHDFile := CreateDefaultGDROMIni("chd")
  244. FileDelete, %gdrCHDFile%
  245. Sleep, 500
  246. IniWrite, false, %gdrCHDFile%, Main, openDialog
  247. IniWrite, gdrCHD.dll, %demulFile%, plugins, gdr
  248. IniWrite, %romPath%\%romName%%romExtension%, %gdrCHDFile%, Main, imagefilename
  249. } Else
  250. ScriptError(romExtension . " is not a supported file type for this " . moduleName . " module.")
  251.  
  252. IniWrite, 1, %demulFile%, main, region ; Set BIOS to Auto Region
  253. } Else { ; all other systems, Naomi and Atomiswave
  254. ; This updates the demul.ini with your Bios choice for the selected rom
  255. If ( Bios != "" && Bios != "ERROR" ) {
  256. Bios := RegExReplace(Bios,"\s.*") ; Cleans off the added text from the key's value so only the number is left
  257. IniWrite, false, %demulFile%, main, naomiBiosAuto ; turning auto bios off so we can use a specific one instead
  258. IniWrite, %Bios%, %demulFile%, main, naomiBios ; setting specific bios user has set from the moduleName ini
  259. } Else
  260. IniWrite, true, %demulFile%, main, naomiBiosAuto ; turning auto bios on if user did not specify a specific one
  261. }
  262.  
  263. ; This section writes your custom keys to the padDemul.ini. Naomi games had many control panel layouts. The only way we can accomodate these differing controls, is to keep track of them all and write them to the ini at the launch of each game.
  264. ; First we check if the last controls used are the same as the game we want to play, so we don't waste time updating the ini if it is not necessary. For example playing 2 sfstyle type games in a row, we wouldn't need to write to the ini.
  265.  
  266. ; This section tells demul what arcade control type should be connected to the game. Options are standard (aka controller), mouse, lightgun, or keyboard
  267. If ( controls = "lightgun" || controls = "mouse" ) {
  268. Log("Module - This game uses a Mouse or Lightgun control type.")
  269. IniWrite, %MouseCode%, %demulFile%, PORTB, device
  270. } Else If ( controls = "keyboard" ) {
  271. Log("Module - This game uses a Keyboard control type.")
  272. IniWrite, %KeyboardCode%, %demulFile%, PORTB, device
  273. } Else { ; accounts for all other control types
  274. Log("Module - This game uses a standard (controller) control type.")
  275. IniWrite, %ControllerCode%, %demulFile%, PORTB, device
  276. }
  277.  
  278. Log("Module - Last control scheme used was """ . lastControlUsed . """ and this game requires """ . controls . """")
  279. If ( LastControlUsed != controls ) { ; find out last controls used for the system we are launching
  280. WriteControls(padFile, 0,push1_0,push2_0,push3_0,push4_0,push5_0,push6_0,push7_0,push8_0,SERVICE_0,START_0,COIN_0,DIGITALUP_0,DIGITALDOWN_0,DIGITALLEFT_0,DIGITALRIGHT_0,ANALOGUP_0,ANALOGDOWN_0,ANALOGLEFT_0,ANALOGRIGHT_0,ANALOGUP2_0,ANALOGDOWN2_0,ANALOGLEFT2_0,ANALOGRIGHT2_0)
  281. WriteControls(padFile, 1,push1_1,push2_1,push3_1,push4_1,push5_1,push6_1,push7_1,push8_1,SERVICE_1,START_1,COIN_1,DIGITALUP_1,DIGITALDOWN_1,DIGITALLEFT_1,DIGITALRIGHT_1,ANALOGUP_1,ANALOGDOWN_1,ANALOGLEFT_1,ANALOGRIGHT_1,ANALOGUP2_1,ANALOGDOWN2_1,ANALOGLEFT2_1,ANALOGRIGHT2_1)
  282. IniWrite, %controls%, %settingsFile%, Settings, LastControlUsed
  283. Log("Module - Wrote " . controls . " controls to padDemul.ini.")
  284. } Else
  285. Log("Module - Not changing controls because the currently configured controls are the same for this game.")
  286.  
  287. ; This will check the save game files and create per game ones if enabled.
  288. If PerGameMemoryCards = true
  289. {
  290. IfNotExist, %memCardPath%
  291. FileCreateDir, %memCardPath% ; create memcard folder if it doesn't exist
  292. defaultMemCard := memCardPath . "\default_vms.bin" ; defining default blank VMU file
  293. If (FileExist(defaultMemCard))
  294. {
  295. Log("VMU - Default VMU file location - " . defaultMemCard,5)
  296. Loop, 4
  297. {
  298. outerLoop := A_Index
  299. If A_Index = 1
  300. {
  301. contrPort := "A"
  302. }
  303. Else If A_Index = 2
  304. {
  305. contrPort := "B"
  306. }
  307. Else If A_Index = 3
  308. {
  309. contrPort := "C"
  310. }
  311. Else If A_Index = 4
  312. {
  313. contrPort := "D"
  314. }
  315. IniRead, controllerPort%contrPort%, %demulFile%, PORT%contrPort%, device
  316. LOG("VMU - Config for controller PORT" . contrPort . " = " . controllerPort%contrPort%,5)
  317. If controllerPort%contrPort% = -1
  318. continue
  319. Loop, 2
  320. {
  321. SubCount := % A_Index - 1
  322. IniRead, VMUPort%SubCount%, %demulFile%, PORT%contrPort%, port%SubCount%
  323. LOG("VMU - Config Plugin VMUPort" . contrPort . SubCount . " for controller PORT" . contrPort . " = " . VMUPort%SubCount%,5)
  324. If (VMUPort%SubCount% <> -1)
  325. {
  326. IniRead, VMUPortFile%SubCount%, %demulFile%, VMS, VMS%contrPort%%SubCount%
  327. LOG("VMU - VMUPortFile" . contrPort . SubCount . " controllerVMU" . contrPort . SubCount . " " . "VMS" . contrPort . SubCount . " = " . VMUPortFile%SubCount%,5)
  328. memCardName := If romTable[1,5] ? romTable[1,4] : romName ; defining rom name for multi disc rom
  329. PerGameVMUIn := memCardPath . "\" . memCardName . "_vms_" . contrPort . SubCount . ".bin"
  330. LOG("VMU - PerGameVMUIn = " . PerGameVMUIn,5)
  331. If (FileExist(PerGameVMUIn))
  332. {
  333. LOG("VMU - PerGameVMU file exists at " . PerGameVMUIn,5)
  334. IniWrite, %PerGameVMUIn%, %demulFile%, VMS, VMS%contrPort%%SubCount%
  335. LOG("VMU - PerGameVMU file written to " . demulFile . " at section VMS to variable VMS" . contrPort . SubCount . " as " . PerGameVMUIn,5)
  336. } ELSE {
  337. LOG("VMU - PerGameVMU file does not exist. So we will create one at " . PerGameVMUIn,1)
  338. FileCopy, %defaultMemCard%, %PerGameVMUIn%
  339. LOG("VMU - PerGameVMU file written to " . demulFile . " at section VMS to variable VMS" . contrPort . SubCount . " as " . PerGameVMUIn,1)
  340. IniWrite, %PerGameVMUIn%, %demulFile%, VMS, VMS%contrPort%%SubCount%
  341. }
  342. } ELSE {
  343. LOG("VMU - No VMU Plugged In.",5)
  344. }
  345. }
  346. }
  347. } Else {
  348. Log("VMU - No default VMU file at " . defaultMemCard,5)
  349. }
  350. }
  351.  
  352.  
  353. ; Setting demul to use true fullscreen if defined in settings.ini, otherwise sets demul to run windowed. This is for gpuDX11 plugin only
  354. If plugin = gpuDX11
  355. If fullscreen = truefullscreen
  356. IniWrite, 1, %gpuFile%, main, UseFullscreen
  357. Else
  358. IniWrite, 0, %gpuFile%, main, UseFullscreen
  359.  
  360. If fullscreen = windowedfullscreen
  361. {
  362. If maxHideTaskbar = true
  363. {
  364. Log("Module - Hiding Taskbar and Start Button.")
  365. WinHide, ahk_class Shell_TrayWnd
  366. WinHide, Start ahk_class Button
  367. }
  368. ; Create black background to give the emu the fullscreen look
  369. Log("Module - Creating black background to simulate a fullscreen look.")
  370. Gui demulGUI: -Caption +ToolWindow
  371. Gui demulGUI: Color, Black
  372. Gui demulGUI: Show, x0 y0 h%A_ScreenHeight% w%A_ScreenWidth%
  373. }
  374.  
  375. Sleep, 250
  376.  
  377. ; Construct the CLI for demul and send romName if naomi or atomiswave. Dreamcast needs a full path and romName.
  378. If LoadDecrypted = true ; decrypted naomi rom
  379. romCLI := "-customrom=" . """" . romPath . "\" . romName . ".bin"""
  380. Else If ident = dc ; dreamcast game
  381. romCLI := " -image=" . """" . romPath . "\" . romName . romExtension . """"
  382. Else ; standard naomi rom
  383. romCLI := "-rom=" . romName
  384.  
  385. If hideDemulGUI = true
  386. SetTimer, HideGUIWindow, 50 ; start watching for gui window so it can be completely hidden
  387.  
  388. ; Run(executable . " -run=" . ident . " " . romCLI, emuPath,, emuPID)
  389. Run(executable . " -run=" . ident . " " . romCLI, emuPath, (If hideDemulGUI = "true" ? "min" : ""), emuPID) ; launching minimized, then restoring later hides the launch completely
  390. Sleep, 1000 ; Need a second for demul to launch, increase if yours takes longer and the emu is NOT appearing and staying minimized. This is required otherwise bezel backgrounds do not appear
  391.  
  392. DetectHiddenWindows, On
  393. Log("Module - Waiting for Demul to finish loading game.")
  394. Loop { ; looping until demul is done loading rom and gpu starts showing frames
  395. Sleep, 200
  396. WinGetTitle, winTitle, ahk_class window
  397. StringSplit, winTextSplit, winTitle, %A_Space%
  398. If ( winTextSplit5 = "gpu:" And winTextSplit6 != "0" And winTextSplit6 != "1" )
  399. Break
  400. }
  401. Log("Module - Demul finished loading game.")
  402.  
  403. If (InStr(systemName, "Gaelco") && fullscreen = "truefullscreen")
  404. Send !{Enter} ; Automatic fullscreen seems to be broken in the Gaelco driver, must alt+Enter to get fullscreen
  405.  
  406. ; This is where we calculate and maximize demul's window using our pseudo fullscreen code
  407. If fullscreen = windowedfullscreen
  408. {
  409. WinSet, Style, -0x40000, ahk_class window ; Removes the border of the game window
  410. WinSet, Style, -0xC00000, ahk_class window ; Removes the TitleBar
  411. Send, {F3} ; Removes the MenuBar
  412. MaximizeWindow("ahk_class window") ; this will take effect after you run demul once because we cannot stretch demul's screen while it is running.
  413. }
  414.  
  415. If hideDemulGUI = true
  416. { SetTimer, HideGUIWindow, Off
  417. WinSet, Transparent, Off, ahk_class window
  418. }
  419.  
  420. BezelDraw()
  421. If (displayVMU="true"){
  422. WinGet VMUWindowID, ID, LCD 0 ahk_class LCD 0
  423. ExtraFixedResBezelDraw(VMUWindowID, "VMU", VMUPos, 144, 96, 8, 8, 28, 8)
  424. VMUHideKey := xHotKeyVarEdit(VMUHideKey,"VMUHideKey","~","Add")
  425. xHotKeywrapper(VMUHideKey,"VMUHide")
  426. }
  427. FadeInExit()
  428. Process("WaitClose", executable)
  429.  
  430. If fullscreen = windowedfullscreen
  431. { Gui demulGUI: Destroy
  432. Log("Module - Destroyed black gui background.")
  433. }
  434.  
  435. BezelExit()
  436. ExtraFixedResBezelExit()
  437. FadeOutExit()
  438.  
  439. If (fullscreen = "windowedfullscreen" && maxHideTaskbar = "true") {
  440. Log("Module - Showing Taskbar and Start Button.")
  441. WinShow,ahk_class Shell_TrayWnd
  442. WinShow,Start ahk_class Button
  443. }
  444.  
  445. ExitModule()
  446.  
  447.  
  448. ; Write new controls to padDemul.ini
  449. WriteControls(file, player,push1,push2,push3,push4,push5,push6,push7,push8,service,start,coin,digitalup,digitaldown,digitalleft,digitalright,analogup,analogdown,analogleft,analogright,analogup2,analogdown2,analogleft2,analogright2) {
  450. IniWrite, %push1%, %file%, JAMMA0_%player%, PUSH1
  451. IniWrite, %push2%, %file%, JAMMA0_%player%, PUSH2
  452. IniWrite, %push3%, %file%, JAMMA0_%player%, PUSH3
  453. IniWrite, %push4%, %file%, JAMMA0_%player%, PUSH4
  454. IniWrite, %push5%, %file%, JAMMA0_%player%, PUSH5
  455. IniWrite, %push6%, %file%, JAMMA0_%player%, PUSH6
  456. IniWrite, %push7%, %file%, JAMMA0_%player%, PUSH7
  457. IniWrite, %push8%, %file%, JAMMA0_%player%, PUSH8
  458. IniWrite, %service%, %file%, JAMMA0_%player%, SERVICE
  459. IniWrite, %start%, %file%, JAMMA0_%player%, START
  460. IniWrite, %coin%, %file%, JAMMA0_%player%, COIN
  461. IniWrite, %digitalup%, %file%, JAMMA0_%player%, DIGITALUP
  462. IniWrite, %digitaldown%, %file%, JAMMA0_%player%, DIGITALDOWN
  463. IniWrite, %digitalleft%, %file%, JAMMA0_%player%, DIGITALLEFT
  464. IniWrite, %digitalright%, %file%, JAMMA0_%player%, DIGITALRIGHT
  465. IniWrite, %analogup%, %file%, JAMMA0_%player%, ANALOGUP
  466. IniWrite, %analogdown%, %file%, JAMMA0_%player%, ANALOGDOWN
  467. IniWrite, %analogleft%, %file%, JAMMA0_%player%, ANALOGLEFT
  468. IniWrite, %analogright%, %file%, JAMMA0_%player%, ANALOGRIGHT
  469. IniWrite, %analogup2%, %file%, JAMMA0_%player%, ANALOGUP2
  470. IniWrite, %analogdown2%, %file%, JAMMA0_%player%, ANALOGDOWN2
  471. IniWrite, %analogleft2%, %file%, JAMMA0_%player%, ANALOGLEFT2
  472. IniWrite, %analogright2%, %file%, JAMMA0_%player%, ANALOGRIGHT2
  473. }
  474.  
  475. MaximizeWindow(class) {
  476. Global MEmu,plugin,gpuFile
  477. Log("MaximizeWindow - Started")
  478. WinGetPos, appX, appY, appWidth, appHeight, %class%
  479. Log("MaximizeWindow - " . MEmu . " is currently x: " . appX . " y: " . appY . " w: " . appWidth . " h: " . appHeight,4)
  480. widthMaxPercenty := ( A_ScreenWidth / appWidth )
  481. heightMaxPercenty := ( A_ScreenHeight / appHeight )
  482.  
  483. If ( widthMaxPercenty < heightMaxPercenty )
  484. percentToEnlarge := widthMaxPercenty
  485. Else
  486. percentToEnlarge := heightMaxPercenty
  487.  
  488. appWidthNew := appWidth * percentToEnlarge
  489. appHeightNew := appHeight * percentToEnlarge
  490. Transform, appX, Round, %appX%
  491. Transform, appY, Round, %appY%
  492. Transform, appWidthNew, Round, %appWidthNew%
  493. Transform, appHeightNew, Round, %appHeightNew%
  494. appXPos := ( A_ScreenWidth / 2 ) - ( appWidthNew / 2 )
  495. appYPos := ( A_ScreenHeight / 2 ) - ( appHeightNew / 2 )
  496. If ( plugin = "gpuDX11" ) {
  497. IniWrite, %appWidthNew%, %gpuFile%, resolution, Width
  498. IniWrite, %appHeightNew%, %gpuFile%, resolution, Height
  499. } Else {
  500. IniWrite, %appWidthNew%, %gpuFile%, resolution, wWidth
  501. IniWrite, %appHeightNew%, %gpuFile%, resolution, wHeight
  502. }
  503. WinMove, %class%,, appXPos, appYPos
  504. Log("MaximizeWindow - " . MEmu . " resized to x: " . appX . " y: " . appY . " w: " . appWidthNew . " h: " . appHeightNew,4)
  505. Log("MaximizeWindow - Ended")
  506. }
  507.  
  508. ; Creates a default gdrCHD.ini or gdrImage.ini in your emu folder if one does not exist already.
  509. CreateDefaultGDROMIni(type) {
  510. Global emuPath
  511. defaultIni := "[main]`r`nimageFileName = `r`nopenDialog = false"
  512. IniType := If type = "chd" ? "gdrCHD.ini" : "gdrImage.ini"
  513. FileAppend, %defaultIni%, % emuPath . "\" . IniType
  514. Return emuPath . "\" . IniType
  515. }
  516.  
  517. HaltEmu:
  518. If fullscreen = truefullscreen
  519. Send !{ENTER}
  520. Return
  521. RestoreEmu:
  522. If fullscreen = truefullscreen
  523. Send !{ENTER}
  524. Return
  525.  
  526. HideGUIWindow:
  527. WinSet, Transparent, On, ahk_class window
  528. WinActivate ahk_class window ; once activated, demul starts loading the rom
  529. Return
  530.  
  531. VMUHide:
  532. If (VMUHidden) {
  533. WinSet, Transparent, off, ahk_ID %VMUWindowID%
  534. UpdateLayeredWindow(extraFixedRes_Bezel_hwnd, extraFixedRes_Bezel_hdc,0,0, A_ScreenWidth, A_ScreenHeight,255)
  535. ;WinSet, Transparent, off, ahk_ID %extraFixedRes_Bezel_hwnd%
  536. ;WinShow, extraFixedRes_Bezel_GUI
  537. ;WinShow, extraFixedRes_Bezel_GUI
  538. VMUHidden := false
  539. } Else {
  540. WinSet, Transparent, 0, ahk_ID %VMUWindowID%
  541. UpdateLayeredWindow(extraFixedRes_Bezel_hwnd, extraFixedRes_Bezel_hdc,0,0, A_ScreenWidth, A_ScreenHeight,0)
  542. ;WinSet, Transparent, 0, ahk_ID %extraFixedRes_Bezel_hwnd%
  543. ;WinHide, extraFixedRes_Bezel_GUI
  544. VMUHidden := true
  545. }
  546. Return
  547.  
  548. CloseProcess:
  549. FadeOutStart()
  550. PostMessage, 0x111, 40085,,,ahk_class window ; Stop emulation first for a clean exit
  551. Sleep, 5 ; just like to give a little time before closing
  552. PostMessage, 0x111, 40080,,,ahk_class window ; Exit
  553. Return
Advertisement
Add Comment
Please, Sign In to add comment