SHARE
TWEET

Demul module

djvj Nov 9th, 2016 165 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MEmu := "Demul"
  2. MEmuV := "v0.7a 221215"
  3. MURL := ["http://demul.emulation64.com/"]
  4. MAuthor := ["djvj","bleasby"]
  5. MVersion := "2.1.9"
  6. MCRC := "FA4E7CEF"
  7. iCRC := "D030B98E"
  8. MID := "636025126320548084"
  9. MSystem := ["Cave 3rd","Gaelco","Gaelco 3D","Sammy Atomiswave","Sega System SP","Sega Dreamcast","Sega Hikaru","Sega Naomi","Sega Naomi 2"]
  10. ;----------------------------------------------------------------------------
  11. ; Notes:
  12. ; Required - control and nvram files setup for each game/control type
  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 RocketLauncherUI
  23. ; Read the tooltip for the Fullscreen module setting in RocketLauncherUI 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 RocketLauncherUI'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 RocketLauncherUI'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. ; Gaelco:
  31. ; There is no known way to launch the desired Gaelco rom from CLI. You will always be presented with the rom selection window on launch.
  32. ; GPUDX11 does not yet support Gaelco in true fullscreen mode. Either use DX10 which does support fullscreen for Gaelco
  33. ; or if using DX11, choose fullscreen in the video options and then match the windows resolution to your desktop. This will give a pseudo fullscreen mode.
  34. ;
  35. ; Sega Hikaru:
  36. ; Windowed Fullscreen doesn't seem to work as demul does not allow stretching of its window
  37. ;
  38. ; Troubleshooting:
  39. ; For some reason demul's ini files can get corrupted and ahk can't read/write to them correctly.
  40. ; 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.
  41. ; 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.
  42. ;
  43. ;Bezel:
  44. ;If the game has the wrong aspect ratio, go to demul module settings, rom settings, and set the aspect ratio option to stretch. The game will follow the aspect ratio defined by the bezel.
  45. ;----------------------------------------------------------------------------
  46. StartModule()
  47. BezelGUI()
  48. ExtraFixedResBezelGUI()
  49. FadeInStart()
  50.  
  51. primaryExe := new Emulator(emuPath . "\" . executable)          ; instantiate emulator executable object
  52. emuPrimaryWindow := new Window(new WindowTitle("","window"))    ; instantiate primary emulator window object
  53. emuLCD0Window := new Window(new WindowTitle("LCD 0","LCD 0"))
  54.  
  55. ; 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.
  56. mType := Object("Cave 3rd","cave3rd","Gaelco","gaelco","Gaelco 3D","gaelco","Sammy Atomiswave","awave","Sega System SP","naomi","Sega Dreamcast","dc","Sega Hikaru","hikaru","Sega Naomi","naomi","Sega Naomi 2","naomi2")
  57. ident := mType[systemName]  ; search object for the systemName identifier Demul uses
  58. If !ident
  59.     ScriptError("Your systemName is: " . systemName . "`nIt is not one of the known supported systems for this Demul module: " . moduleName)
  60.  
  61. DemuleIni := new IniFile(emuPath . "\Demul.ini")
  62. PadIni := new IniFile(emuPath . "\padDemul.ini")
  63. DemuleIni.CheckFile("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: " . DemuleIni.FileFullPath)
  64. PadIni.CheckFile("Could not find Demul's control ini. Please run Demul manually first and set up your controls so this file is created for you: " . PadIni.FileFullPath)
  65.  
  66. demuleIniEncoding := RLObject.getFileEncoding(DemuleIni.FileFullPath)
  67. If demuleIniEncoding {
  68.     If (demuleIniEncoding = "ERROR")
  69.         RLLog.Warning("Module - Demul.ini set to Read-only and BOM cannot be changed. Check the DLL log for further details: " . DemuleIni.FileFullPath)
  70.     Else {
  71.         RLLog.Info("Module - Recreating " . DemuleIni.FileFullPath . " as ANSI because UTF-8 format cannot be read")
  72.         If RLObject.removeBOM(DemuleIni.FileFullPath)
  73.             RLLog.Info("Module - Successfully converted " . DemuleIni.FileFullPath . " to ANSI")
  74.         Else
  75.             RLLog.Error("Module - Failed to convert " . DemuleIni.FileFullPath . " to ANSI")
  76.     }
  77. }
  78.  
  79. maxHideTaskbar := moduleIni.Read("Settings", "MaxHideTaskbar", "true",,1)
  80. controllerCode := moduleIni.Read("Settings", "ControllerCode", "16777216",,1)
  81. mouseCode := moduleIni.Read("Settings", "MouseCode", "131072",,1)
  82. keyboardCode := moduleIni.Read("Settings", "KeyboardCode", "1073741824",,1)
  83. lightgunCode := moduleIni.Read("Settings", "LightgunCode", "-2147483648",,1)
  84. hideDemulGUI := moduleIni.Read("Settings", "HideDemulGUI", "true",,1)
  85. PerGameMemoryCards := moduleIni.Read("Settings", "PerGameMemoryCards", "true",,1)
  86. memCardPath := moduleIni.Read("Settings", "MemCardPath", emuPath . "\memsaves",,1)
  87. memCardPath := AbsoluteFromRelative(emuPath, memCardPath)
  88. demulShooterPath := moduleIni.Read("Settings", "DemulShooterPath",,,1)
  89.  
  90. fullscreen := moduleIni.Read(romName . "|Settings", "Fullscreen", "windowedfullscreen",,1)
  91. plugin := moduleIni.Read(romName . "|Settings", "Plugin", "gpuDX11",,1)
  92. shaderUsePass1 := moduleIni.Read(romName . "|Settings", "ShaderUsePass1", "false",,1)
  93. shaderUsePass2 := moduleIni.Read(romName . "|Settings", "ShaderUsePass2", "false",,1)
  94. shaderNamePass1 := moduleIni.Read(romName . "|Settings", "ShaderNamePass1",,,1)
  95. shaderNamePass2 := moduleIni.Read(romName . "|Settings", "ShaderNamePass2",,,1)
  96. listSorting := moduleIni.Read(romName . "|Settings", "ListSorting", "true",,1)
  97. OpaqueMod := moduleIni.Read(romName . "|Settings", "OModifier", "true",,1)
  98. TransMod := moduleIni.Read(romName . "|Settings", "TModifier", "true",,1)
  99. internalResolutionScale := moduleIni.Read(romName . "|Settings", "InternalResolutionScale", "1",,1)
  100. videomode := moduleIni.Read(romName . "|Settings", "VideoMode", "0",,1)
  101. aspectRatio := moduleIni.Read(romName . "|Settings", "AspectRatio", "1",,1)
  102. demulShooterEnabled := moduleIni.Read(romName . "|Settings", "DemulShooterEnabled", "false",,1)
  103.  
  104. showVMU := moduleIni.Read("Settings", "showVMU", "true",,1)
  105. VMU1Pos := moduleIni.Read("Settings", "VMU1Pos", "topLeft",,1) ; topRight, topCenter, topLeft, leftCenter, bottomLeft, bottomCenter, bottomRight, rightCenter
  106. VMU2Pos := moduleIni.Read("Settings", "VMU2Pos", "topRight",,1) ; topRight, topCenter, topLeft, leftCenter, bottomLeft, bottomCenter, bottomRight, rightCenter
  107. VMU3Pos := moduleIni.Read("Settings", "VMU3Pos", "bottomLeft",,1) ; topRight, topCenter, topLeft, leftCenter, bottomLeft, bottomCenter, bottomRight, rightCenter
  108. VMU4Pos := moduleIni.Read("Settings", "VMU4Pos", "bottomRight",,1) ; topRight, topCenter, topLeft, leftCenter, bottomLeft, bottomCenter, bottomRight, rightCenter
  109. VMUHideKey := moduleIni.Read("Settings", "VMUHideKey","F10",,1)
  110.  
  111. Bios := moduleIni.Read(romName, "Bios",,,1)
  112. LoadDecrypted := moduleIni.Read(romName, "LoadDecrypted",,,1)   ; not currently supported
  113.  
  114. ; Read all the control values
  115. controls := moduleIni.Read(romname, "Controls", "standard",,1)  ; have to read this first so the below ini reads work
  116. push1_0 := moduleIni.Read(controls . "_JAMMA0_0", "push1",,,1)
  117. push2_0 := moduleIni.Read(controls . "_JAMMA0_0", "push2",,,1)
  118. push3_0 := moduleIni.Read(controls . "_JAMMA0_0", "push3",,,1)
  119. push4_0 := moduleIni.Read(controls . "_JAMMA0_0", "push4",,,1)
  120. push5_0 := moduleIni.Read(controls . "_JAMMA0_0", "push5",,,1)
  121. push6_0 := moduleIni.Read(controls . "_JAMMA0_0", "push6",,,1)
  122. push7_0 := moduleIni.Read(controls . "_JAMMA0_0", "push7",,,1)
  123. push8_0 := moduleIni.Read(controls . "_JAMMA0_0", "push8",,,1)
  124. service_0 := moduleIni.Read(controls . "_JAMMA0_0", "SERVICE",,,1)
  125. start_0 := moduleIni.Read(controls . "_JAMMA0_0", "START",,,1)
  126. coin_0 := moduleIni.Read(controls . "_JAMMA0_0", "COIN",,,1)
  127. digitalup_0 := moduleIni.Read(controls . "_JAMMA0_0", "DIGITALUP",,,1)
  128. digitaldown_0 := moduleIni.Read(controls . "_JAMMA0_0", "DIGITALDOWN",,,1)
  129. digitalleft_0 := moduleIni.Read(controls . "_JAMMA0_0", "DIGITALLEFT",,,1)
  130. digitalright_0 := moduleIni.Read(controls . "_JAMMA0_0", "DIGITALRIGHT",,,1)
  131. analogup_0 := moduleIni.Read(controls . "_JAMMA0_0", "ANALOGUP",,,1)
  132. analogdown_0 := moduleIni.Read(controls . "_JAMMA0_0", "ANALOGDOWN",,,1)
  133. analogleft_0 := moduleIni.Read(controls . "_JAMMA0_0", "ANALOGLEFT",,,1)
  134. analogright_0 := moduleIni.Read(controls . "_JAMMA0_0", "ANALOGRIGHT",,,1)
  135. analogup2_0 := moduleIni.Read(controls . "_JAMMA0_0", "ANALOGUP2",,,1)
  136. analogdown2_0 := moduleIni.Read(controls . "_JAMMA0_0", "ANALOGDOWN2",,,1)
  137. analogleft2_0 := moduleIni.Read(controls . "_JAMMA0_0", "ANALOGLEFT2",,,1)
  138. analogright2_0 := moduleIni.Read(controls . "_JAMMA0_0", "ANALOGRIGHT2",,,1)
  139. push1_1 := moduleIni.Read(controls . "_JAMMA0_1", "push1",,,1)
  140. push2_1 := moduleIni.Read(controls . "_JAMMA0_1", "push2",,,1)
  141. push3_1 := moduleIni.Read(controls . "_JAMMA0_1", "push3",,,1)
  142. push4_1 := moduleIni.Read(controls . "_JAMMA0_1", "push4",,,1)
  143. push5_1 := moduleIni.Read(controls . "_JAMMA0_1", "push5",,,1)
  144. push6_1 := moduleIni.Read(controls . "_JAMMA0_1", "push6",,,1)
  145. push7_1 := moduleIni.Read(controls . "_JAMMA0_1", "push7",,,1)
  146. push8_1 := moduleIni.Read(controls . "_JAMMA0_1", "push8",,,1)
  147. service_1 := moduleIni.Read(controls . "_JAMMA0_1", "SERVICE",,,1)
  148. start_1 := moduleIni.Read(controls . "_JAMMA0_1", "START",,,1)
  149. coin_1 := moduleIni.Read(controls . "_JAMMA0_1", "COIN",,,1)
  150. digitalup_1 := moduleIni.Read(controls . "_JAMMA0_1", "DIGITALUP",,,1)
  151. digitaldown_1 := moduleIni.Read(controls . "_JAMMA0_1", "DIGITALDOWN",,,1)
  152. digitalleft_1 := moduleIni.Read(controls . "_JAMMA0_1", "DIGITALLEFT",,,1)
  153. digitalright_1 := moduleIni.Read(controls . "_JAMMA0_1", "DIGITALRIGHT",,,1)
  154. analogup_1 := moduleIni.Read(controls . "_JAMMA0_1", "ANALOGUP",,,1)
  155. analogdown_1 := moduleIni.Read(controls . "_JAMMA0_1", "ANALOGDOWN",,,1)
  156. analogleft_1 := moduleIni.Read(controls . "_JAMMA0_1", "ANALOGLEFT",,,1)
  157. analogright_1 := moduleIni.Read(controls . "_JAMMA0_1", "ANALOGRIGHT",,,1)
  158. analogup2_1 := moduleIni.Read(controls . "_JAMMA0_1", "ANALOGUP2",,,1)
  159. analogdown2_1 := moduleIni.Read(controls . "_JAMMA0_1", "ANALOGDOWN2",,,1)
  160. analogleft2_1 := moduleIni.Read(controls . "_JAMMA0_1", "ANALOGLEFT2",,,1)
  161. analogright2_1 := moduleIni.Read(controls . "_JAMMA0_1", "ANALOGRIGHT2",,,1)
  162.  
  163. ;Bezel settings
  164. bezelTopOffset := moduleIni.Read(romName . "|Settings", "Bezel_Top_Offset","0",,1)
  165. bezelBottomOffset := moduleIni.Read(romName . "|Settings", "Bezel_Bottom_Offset","0",,1)
  166. bezelRightOffset := moduleIni.Read(romName . "|Settings", "Bezel_Right_Offset", "0",,1)
  167. bezelLeftOffset := moduleIni.Read(romName . "|Settings", "Bezel_Left_Offset", "0",,1)
  168. If (plugin = "gpuDX11ng")   ; this is for legacy support. Original demul 0.7 used gpuDX11ng
  169.     plugin := "gpuDX11old"
  170.  
  171. If (InStr(systemName, "Hikaru") && plugin != "gpuDX11")
  172.     plugin := "gpuDX11"     ; Hikaru does not work with gpuDX10 gpu plugin, setting it dumps an error
  173.  
  174. ; Verify user set desired gpu plugin name correctly
  175. If (plugin != "gpuDX11old" && plugin != "gpuDX11" && plugin != "gpuDX10" && plugin != "")
  176.     ScriptError(plugin . " is not a supported gpu plugin.`nLeave the plugin blank to use the default ""gpuDX11"".`nValid options are gpuDX11old, gpuDX11 or gpuDX10.")
  177.  
  178. ; Read and write videomode value for cable type
  179. rvideomode := DemuleIni.Read("main", "videomode")
  180. RLLog.Info("Module - Demul is reading the config with videomode = " . rvideomode)
  181. DemuleIni.Write(videomode, "main", "videomode")
  182. RLLog.Info("Module - Demul is updating the config with videomode = " . videomode)
  183.  
  184. ; Handle Demul's rom paths so the user doesn't have to
  185. romPathCount := DemuleIni.Read("files", "romsPathsCount")
  186. RLLog.Info("Module - Demul is configured with " . romPathCount . " rom path(s). Scanning these for a romPath to this rom.")
  187. Loop % romPathCount
  188. {   demulRomPath := A_Index - 1 ; rompaths in demul start with 0
  189.     path%A_Index% := DemuleIni.Read("files", "roms" . demulRomPath)
  190.     RLLog.Info("Module - Path" . demulRomPath . ": " . path%A_Index%)
  191.     ; msgbox % path%A_Index%
  192.     If (path%A_Index% = romPath . "\")  ; demul tacks on the backslash at the end
  193.     {   romPathFound := 1   ; flag that demul has this romPath in its config and no need to add it
  194.         RLLog.Info("Module - Stopping search because Demul is already configured with the correct romPath to this rom: " . path%A_Index%)
  195.         Break   ; stop looking for a correct romPath
  196.     }
  197. }
  198. If !romPathFound    ; if demul doesn't have the romPath in its ini, add it
  199. {   RLLog.Warning("Module - Demul does not have this romPath in Demul.ini, adding it for you.")
  200.     nextPath := romPathCount + 1    ; add 1 to the romPathCount and write that to the ini
  201.     DemuleIni.Write(nextPath, "files", "romsPathsCount")
  202.     DemuleIni.Write(romPath . "\", "files", "roms" . romPathCount)  ; write the rompath to the ini
  203. }
  204.  
  205. ; Force Fade_Out to disabled as it causes demul to not close properly
  206. ; fadeOut = false
  207. ; RLLog.Warning("Module - Turning off Fade_Out because it doesn't let Demul exit properly.")
  208.  
  209. GpuIni := new IniFile(emuPath . "\" . plugin . ".ini")
  210. GpuIni.CheckFile("Please run Demul manually first and select the " . plugin . " gpu plugin so it creates this file for you: " . GpuIni.FileFullPath)
  211.  
  212. demulFileEncoding := RLObject.getFileEncoding(GpuIni.FileFullPath)
  213. If demulFileEncoding {
  214.     If (demulFileEncoding = "ERROR")
  215.         RLLog.Warning("Module - GPU ini set to Read-only and BOM cannot be changed. Check the DLL log for further details: " . GpuIni.FileFullPath)
  216.     Else {
  217.         RLLog.Info("Module - Recreating " . GpuIni.FileFullPath . " as ANSI because UTF-8 format cannot be read")
  218.         If RLObject.removeBOM(GpuIni.FileFullPath)
  219.             RLLog.Info("Module - Successfully converted " . GpuIni.FileFullPath . " to ANSI")
  220.         Else
  221.             RLLog.Error("Module - Failed to convert " . GpuIni.FileFullPath . " to ANSI")
  222.     }
  223. }
  224.  
  225. BezelStart()
  226.  
  227. ; Setting emu resolution if bezel is enabled
  228. If (BezelPath)
  229. {   If (plugin = "gpuDX11" || plugin = "gpuDX11old") {
  230.         GpuIni.Write(bezelScreenWidth, "resolution", "Width")
  231.         GpuIni.Write(bezelScreenHeight, "resolution", "Height")
  232.     } Else {
  233.         GpuIni.Write(bezelScreenWidth, "resolution", "wWidth")
  234.         GpuIni.Write(bezelScreenHeight, "resolution", "wHeight")
  235.     }
  236. }
  237.  
  238. ; 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.
  239. If (ListSorting = "true")
  240.     GpuIni.Write(0, "main", "AutoSort")
  241. Else
  242.     GpuIni.Write(1, "main", "AutoSort")
  243.    
  244. ; This will set the Opaque or Trans modifier for each game
  245. If (OpaqueMod = "true")
  246.     GpuIni.Write(0, "main", "OModifier")
  247. Else
  248.     GpuIni.Write(1, "main", "OModifier")
  249.  
  250. If (TransMod = "true")
  251.     GpuIni.Write(0, "main", "TModifier")
  252. Else
  253.     GpuIni.Write(1, "main", "TModifier")
  254.  
  255. ; This updates the DX10gpu or DX11gpu ini file to the ratio and scale you want to use for this game
  256. GpuIni.Write(aspectRatio, "main", "aspect")
  257. GpuIni.Write(InternalResolutionScale, "main", "scaling")
  258.  
  259. ; This updates the demul.ini with your gpu plugin choice for the selected rom
  260. DemuleIni.Write(plugin . ".dll", "plugins", "gpu")
  261.  
  262. ; This updates the demul.ini with your VMU display choice
  263. VMUscreendisable := If (showVMU = "true") ? "false" : "true"
  264. DemuleIni.Write(VMUscreendisable, "main", "VMUscreendisable")
  265.  
  266.  ; Shader Effects
  267. Loop, 2 {
  268.     shaderUsePass%A_Index% := If (ShaderUsePass%A_Index% != "" and ShaderUsePass%A_Index% != "ERROR" ? (ShaderUsePass%A_Index%) : (GlobalShaderUsePass%A_Index%))   ; determine what shaderUsePass to use
  269.     currentusePass%A_Index% := GpuIni.Read("shaders", "usePass" . A_Index)
  270.     If (shaderUsePass%A_Index% = "true")
  271.     {
  272.         shaderNamePass%A_Index% := If (ShaderNamePass%A_Index% != "" and ShaderNamePass%A_Index% != "ERROR" ? (ShaderNamePass%A_Index%) : (GlobalShaderNamePass%A_Index%))  ; determine what shaderNamePass to use
  273.         If !StringUtils.Contains(shaderNamePass%A_Index%,"FXAA|HDR-TV|SCANLINES|CARTOON|RGB DOT\(MICRO\)|RGB DOT\(TINY\)|BLUR")
  274.             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.")
  275.         If (currentusePass%A_Index% = 0)
  276.             GpuIni.Write(1, "shaders", "usePass" . A_Index) ; turn shader on in gpuDX11 ini
  277.         GpuIni.Write(shaderNamePass%A_Index%, "shaders", "shaderPass" . A_Index)    ; update gpuDX11 ini with the shader name to use
  278.     }Else If (shaderUsePass%A_Index% != "true" and currentusePass%A_Index% = 1)
  279.         GpuIni.Write(0, "shaders", "usePass" . A_Index) ; turn shader off in gpuDX11 ini
  280. }
  281.  
  282. If (ident = "dc")
  283. {
  284.     7z(romPath, romName, romExtension, sevenZExtractPath)
  285.     defaultIni := "[main]`r`nimageFileName = `r`nopenDialog = false"
  286.     If (romExtension = ".cdi" || romExtension = ".mds" || romExtension = ".ccd" || romExtension = ".nrg" || romExtension = ".gdi" || romExtension = ".cue") {
  287.         GdrImageIni := new IniFile(emuPath . "\gdrImage.ini")
  288.         If !GdrImageIni.Exist() {
  289.             GdrImageIni.Append(defaultIni)      ; Create a default gdrImage.ini in your emu folder if one does not exist already.
  290.             ; GdrImageIni.Delete(gdrImageFile)  ; don't know why this was in the old module, no point in deleting the file I just made
  291.         }
  292.         TimerUtils.Sleep(500)
  293.         DemuleIni.Write("gdrImage.dll", "plugins", "gdr")
  294.         GdrImageIni.Write("false", "Main", "openDialog")
  295.         GdrImageIni.Write(romPath . "\" . romName . romExtension, "Main", "imagefilename")
  296.     } Else If (romExtension = ".chd")
  297.     {
  298.         GdrCHDIni := new IniFile(emuPath . "\gdrCHD.ini")
  299.         If !GdrCHDIni.Exist() {
  300.             GdrCHDIni.Append(defaultIni)        ; Create a default gdrCHD.ini in your emu folder if one does not exist already.
  301.             ; GdrCHDIni.Delete(gdrCHDFile)  ; don't know why this was in the old module, no point in deleting the file I just made
  302.         }
  303.         TimerUtils.Sleep(500)
  304.         GdrCHDIni.Write("false", "Main", "openDialog")
  305.         DemuleIni.Write("gdrCHD.dll", "plugins", "gdr")
  306.         GdrCHDIni.Write(romPath . "\" . romName . romExtension, "Main", "imagefilename")
  307.     } Else
  308.         ScriptError(romExtension . " is not a supported file type for this " . moduleName . " module.")
  309.  
  310.     DemuleIni.Write(1, "main", "region")    ; Set BIOS to Auto Region
  311. } Else {    ; all other systems, Naomi and Atomiswave
  312.     ; This updates the demul.ini with your Bios choice for the selected rom
  313.     If (Bios != "" && Bios != "ERROR") {
  314.         Bios := StringUtils.RegExReplace(Bios,"\s.*")   ; Cleans off the added text from the key's value so only the number is left
  315.         DemuleIni.Write("false", "main", "naomiBiosAuto")   ; turning auto bios off so we can use a specific one instead
  316.         DemuleIni.Write(Bios, "main", "naomiBios")      ; setting specific bios user has set from the moduleName ini
  317.     } Else
  318.         DemuleIni.Write("true", "main", "naomiBiosAuto")    ; turning auto bios on if user did not specify a specific one
  319. }
  320.  
  321. ; 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.
  322. ; 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.
  323.  
  324. ; This section tells demul what arcade control type should be connected to the game. Options are standard (aka controller), mouse, lightgun, or keyboard
  325. If (controls = "lightgun" || controls = "mouse") {
  326.     RLLog.Info("Module - This game uses a Mouse or Lightgun control type.")
  327.     DemuleIni.Write(MouseCode, "PORTB", "device")
  328. } Else If (controls = "keyboard") {
  329.     RLLog.Info("Module - This game uses a Keyboard control type.")
  330.     DemuleIni.Write(KeyboardCode, "PORTB", "device")
  331. } Else { ; accounts for all other control types
  332.     RLLog.Info("Module - This game uses a standard (controller) control type.")
  333.     DemuleIni.Write(ControllerCode, "PORTB", "device")
  334. }
  335.  
  336. WriteControls(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)
  337.  
  338. WriteControls(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)
  339.  
  340. RLLog.Info("Module - Wrote " . controls . " controls to padDemul.ini.")
  341.  
  342. ; This will check the save game files and create per game ones if enabled.
  343. If (PerGameMemoryCards = "true")
  344. {
  345.     MemCardFolder := new Folder(memCardPath)
  346.     DefaultMemCard := new File(memCardPath . "\default_vms.bin")    ; defining default blank VMU file
  347.     If !DefaultMemCard.Exist("Folder")
  348.         DefaultMemCard.CreateDir()  ; create memcard folder if it doesn't exist
  349.     If defaultMemCard.Exist()
  350.     {
  351.         RLLog.Info("VMU - Default VMU file location - " . defaultMemCard.FileFullPath)
  352.         Loop, 4
  353.         {
  354.             outerLoop := A_Index
  355.             If (A_Index = 1)
  356.                 contrPort := "A"
  357.             Else If (A_Index = 2)
  358.                 contrPort := "B"
  359.             Else If (A_Index = 3)
  360.                 contrPort := "C"
  361.             Else If (A_Index = 4)
  362.                 contrPort := "D"
  363.             controllerPort%contrPort% := DemuleIni.Read("PORT" . contrPort, "device")
  364.             RLLog.Info("VMU - Config for controller PORT" . contrPort . " = " . controllerPort%contrPort%)
  365.             If (controllerPort%contrPort% = -1)
  366.                 Continue
  367.             Loop, 2
  368.             {
  369.                 SubCount := A_Index - 1
  370.                 VMUPort%SubCount% := DemuleIni.Read("PORT" . contrPort, "port" . SubCount)
  371.                 RLLog.Info("VMU - Config Plugin VMUPort" . contrPort . SubCount . " for controller PORT" . contrPort . " = " . VMUPort%SubCount%)
  372.                 If (VMUPort%SubCount% <> -1)
  373.                 {
  374.                     VMUPortFile%SubCount% := DemuleIni.Read("VMS", "VMS" . contrPort . SubCount)
  375.                     RLLog.Info("VMU - VMUPortFile" . contrPort . SubCount . " controllerVMU" . contrPort .  SubCount . " " . "VMS" . contrPort . SubCount . " = " . VMUPortFile%SubCount%)
  376.                     memCardName := If romTable[1,5] ? romTable[1,4] : romName   ; defining rom name for multi disc rom
  377.                     PerGameVMUBin%A_Index% := new File(memCardPath . "\" . memCardName . "_vms_" . contrPort . SubCount . ".bin")
  378.                     RLLog.Info("VMU - PerGameVMUBin = " . PerGameVMUBin%A_Index%.FileFullPath)
  379.                     If PerGameVMUBin%A_Index%.Exist()
  380.                     {
  381.                         RLLog.Info("VMU - PerGameVMU file exists at " . PerGameVMUBin%A_Index%.FileFullPath)
  382.                     } Else {
  383.                         RLLog.Info("VMU - PerGameVMU file does not exist. So we will create one at " . PerGameVMUBin%A_Index%.FileFullPath)
  384.                         DefaultMemCard.Copy(PerGameVMUBin%A_Index%.FileFullPath)
  385.                     }
  386.                     DemuleIni.Write(PerGameVMUBin%A_Index%.FileFullPath, "VMS", "VMS" . contrPort . SubCount)
  387.                     RLLog.Info("VMU - PerGameVMU file written to " . DemuleIni.FileFullPath . " at section VMS to variable VMS" . contrPort . SubCount . " as " . PerGameVMUBin%A_Index%.FileFullPath)
  388.                 } Else {
  389.                     RLLog.Info("VMU - No VMU Plugged In.")
  390.                 }
  391.             }
  392.         }
  393.     } Else {
  394.         RLLog.Info("VMU - No default VMU file at " . DefaultMemCard.FileFullPath)
  395.     }
  396. }
  397.  
  398. ; Setting demul to use true fullscreen if defined in settings.ini, otherwise sets demul to run windowed. This is for gpuDX11 plugin only
  399. If (plugin = "gpuDX11" || plugin = "gpuDX11old")
  400.     If (fullscreen = "truefullscreen")
  401.         GpuIni.Write(1, "main", "UseFullscreen")
  402.     Else
  403.         GpuIni.Write(0, "main", "UseFullscreen")
  404.  
  405. If (fullscreen = "windowedfullscreen")
  406. {
  407.     If (plugin = "gpuDX11" || plugin = "gpuDX11old") {
  408.         GpuIni.Write(appWidthNew, "resolution", "Width")
  409.         GpuIni.Write(appHeightNew, "resolution", "Height")
  410.     } Else {
  411.         GpuIni.Write(appWidthNew, "resolution", "wWidth")
  412.         GpuIni.Write(appHeightNew, "resolution", "wHeight")
  413.     }
  414.     If (maxHideTaskbar = "true") {
  415.         RLLog.Info("Module - Hiding Taskbar and Start Button.")
  416.         MiscUtils.TaskBar("off")
  417.     }
  418.     ; Create black background to give the emu the fullscreen look
  419.     RLLog.Info("Module - Creating black background to simulate a fullscreen look.")
  420.     Gui demulGUI: -Caption +ToolWindow +0x08000000
  421.     Gui demulGUI: Color, Black
  422.     Gui demulGUI: Show, x0 y0 h%A_ScreenHeight% w%A_ScreenWidth%
  423. }
  424.  
  425. If demulShooterEnabled {    ; If demulshooter is enabled for this game, launch it with relevant options
  426.     DemulShooterExe := New DemulShooter(demulShooterPath)
  427.     DemulShooterExe.Run("demul07a",romName,"-noresize")
  428. }
  429.  
  430. TimerUtils.Sleep(250)
  431.  
  432. ;  Construct the CLI for demul and send romName if naomi or atomiswave. Dreamcast needs a full path and romName.
  433. If (LoadDecrypted = "true")     ; decrypted naomi rom
  434.     romCLI := "-customrom=" . """" . romPath . "\" . romName . ".bin"""
  435. Else If (ident = "dc")  ; dreamcast game
  436.     romCLI := " -image=" . """" . romPath . "\" . romName . romExtension . """"
  437. Else    ; standard naomi rom
  438.     romCLI := "-rom=" . romName
  439.  
  440. hideEmuObj := Object(emuLCD0Window,0,emuPrimaryWindow,1)
  441. HideAppStart(hideEmuObj,hideEmu)
  442.  
  443. primaryExe.Run(" -run=" . ident . " " . romCLI, (If hideDemulGUI = "true" ? "min" : ""))    ; launching minimized, then restoring later hides the launch completely
  444.  
  445. TimerUtils.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
  446.  
  447. DetectHiddenWindows, On
  448. If (hideDemulGUI = "true")
  449. {  
  450.     emuPrimaryWindow.Restore()
  451.     emuPrimaryWindow.Activate()
  452. }
  453.  
  454. RLLog.Info("Module - Waiting for Demul to finish loading game.")
  455. winTextSplit := []
  456. Loop {  ; looping until demul is done loading rom and gpu starts showing frames
  457.     TimerUtils.Sleep(200,0)
  458.     winTitle := emuPrimaryWindow.GetTitle(0)    ; do not update the wintitle otherwise emu won't close on exit
  459.     winTextSplit := StringUtils.Split(winTitle, A_Space)
  460.     If (winTextSplit[5] = "gpu:" And winTextSplit[6] != "0" And winTextSplit[6] != "1")
  461.         Break
  462. }
  463. RLLog.Info("Module - Demul finished loading game.")
  464.  
  465. If (StringUtils.Contains(systemName, "Gaelco|Hikaru") && fullscreen = "truefullscreen")
  466.     KeyUtils.Send("!{Enter}")   ; Automatic fullscreen seems to be broken in the Gaelco driver, must alt+Enter to get fullscreen
  467.  
  468. ; This is where we calculate and maximize demul's window using our pseudo fullscreen code
  469. If (fullscreen = "windowedfullscreen")
  470. {
  471.     emuPrimaryWindow.Maximize() ; this will take effect after you run demul once because we cannot stretch demul's screen while it is running.
  472. }
  473.  
  474. BezelDraw()
  475.  
  476. If (showVMU = "true"){
  477.     ExtraFixedResBezel := new Window(new WindowTitle("ahk_ID " . extraFixedRes_Bezel_hwnd))
  478.     SetTimer, CheckforVMU, 5000
  479. }
  480.  
  481. HideAppEnd(hideEmuObj,hideEmu)
  482. FadeInExit()
  483. primaryExe.Process("WaitClose")
  484.  
  485. If (fullscreen = "windowedfullscreen")
  486. {   Gui demulGUI: Destroy
  487.     RLLog.Info("Module - Destroyed black gui background.")
  488. }
  489.  
  490. If (ident = "dc")
  491.     7zCleanUp()
  492.  
  493. BezelExit()
  494. ExtraFixedResBezelExit()
  495. FadeOutExit()
  496.  
  497. If (fullscreen = "windowedfullscreen" && maxHideTaskbar = "true") {
  498.     RLLog.Info("Module - Showing Taskbar and Start Button.")
  499.     MiscUtils.TaskBar("on")
  500. }
  501.  
  502. ExitModule()
  503.  
  504.  
  505.  ; Write new controls to padDemul.ini
  506. WriteControls(player,push1,push2,push3,push4,push5,push6,push7,push8,service,start,coin,digitalup,digitaldown,digitalleft,digitalright,analogup,analogdown,analogleft,analogright,analogup2,analogdown2,analogleft2,analogright2) {
  507.     Global PadIni
  508.     PadIni.Write(push1, "JAMMA0_" . player, "PUSH1")
  509.     PadIni.Write(push2, "JAMMA0_" . player, "PUSH2")
  510.     PadIni.Write(push3, "JAMMA0_" . player, "PUSH3")
  511.     PadIni.Write(push4, "JAMMA0_" . player, "PUSH4")
  512.     PadIni.Write(push5, "JAMMA0_" . player, "PUSH5")
  513.     PadIni.Write(push6, "JAMMA0_" . player, "PUSH6")
  514.     PadIni.Write(push7, "JAMMA0_" . player, "PUSH7")
  515.     PadIni.Write(push8, "JAMMA0_" . player, "PUSH8")
  516.     PadIni.Write(service, "JAMMA0_" . player, "SERVICE")
  517.     PadIni.Write(start, "JAMMA0_" . player, "START")
  518.     PadIni.Write(coin, "JAMMA0_" . player, "COIN")
  519.     PadIni.Write(digitalup, "JAMMA0_" . player, "DIGITALUP")
  520.     PadIni.Write(digitaldown, "JAMMA0_" . player, "DIGITALDOWN")
  521.     PadIni.Write(digitalleft, "JAMMA0_" . player, "DIGITALLEFT")
  522.     PadIni.Write(digitalright, "JAMMA0_" . player, "DIGITALRIGHT")
  523.     PadIni.Write(analogup, "JAMMA0_" . player, "ANALOGUP")
  524.     PadIni.Write(analogdown, "JAMMA0_" . player, "ANALOGDOWN")
  525.     PadIni.Write(analogleft, "JAMMA0_" . player, "ANALOGLEFT")
  526.     PadIni.Write(analogright, "JAMMA0_" . player, "ANALOGRIGHT")
  527.     PadIni.Write(analogup2, "JAMMA0_" . player, "ANALOGUP2")
  528.     PadIni.Write(analogdown2, "JAMMA0_" . player, "ANALOGDOWN2")
  529.     PadIni.Write(analogleft2, "JAMMA0_" . player, "ANALOGLEFT2")
  530.     PadIni.Write(analogright2, "JAMMA0_" . player, "ANALOGRIGHT2")
  531. }
  532.  
  533. HaltEmu:
  534.     If (fullscreen = "truefullscreen")
  535.         KeyUtils.Send("!{Enter}")
  536.     If VMUHideKey
  537.         XHotKeywrapper(VMUHideKey,"VMUHide","OFF")
  538. Return
  539. RestoreEmu:
  540.     If (fullscreen = "truefullscreen")
  541.         KeyUtils.Send("!{Enter}")
  542.     If (showVMU = "true") {
  543.         Loop, 4
  544.         {   VMUWindow%A_Index%.Set("Transparent", 0)
  545.             VMUWindow%A_Index%.Activate()
  546.             VMUWindow%A_Index%.Set("AlwaysOnTop", "On")
  547.             ExtraFixedResBezel.Set("AlwaysOnTop", "On")
  548.             If !(VMUHidden)
  549.                 VMUWindow%A_Index%.Set("Transparent", "off")
  550.         }
  551.         emuPrimaryWindow.Activate()
  552.     }
  553.     If VMUHideKey
  554.         XHotKeywrapper(VMUHideKey,"VMUHide","ON")
  555. Return
  556.  
  557. HideGUIWindow:
  558.     emuPrimaryWindow.Set("Transparent", "On")
  559.     emuPrimaryWindow.Activate()     ; once activated, demul starts loading the rom
  560. Return
  561.  
  562. CheckforVMU:
  563.     Loop, 4
  564.     {   Transform, letter, Chr, % A_Index + asc("A") - 1  ; transform number to letter
  565.         If ((!(VMUWindow%A_Index%)) and (VMUScreenID%A_Index%:=WinExist("PORT " . letter . " VMU 0 ahk_class PORT " . letter . " VMU 0")))
  566.         {   VMUWindow%A_Index% := new Window(new WindowTitle("ahk_ID " . VMUScreenID%A_Index%))
  567.             VMUWindow%A_Index%.Set("Transparent", 0)
  568.             ExtraFixedResBezelDraw(VMUScreenID%A_Index%, "VMU",VMU%A_Index%Pos, 144, 96, 8, 8, 28, 8)
  569.             VMUWindow%A_Index%.Activate()
  570.             VMUWindow%A_Index%.Set("AlwaysOnTop", "On")
  571.             ExtraFixedResBezel.Set("AlwaysOnTop", "On")
  572.             VMU%A_Index%Draw := true
  573.             If !(VMUHidden)
  574.                 VMUWindow%A_Index%.Set("Transparent", "off")
  575.             If !(VMULoaded){
  576.                 VMUHideKey := xHotKeyVarEdit(VMUHideKey,"VMUHideKey","~","Add")
  577.                 xHotKeywrapper(VMUHideKey,"VMUHide")
  578.                 VMULoaded := true
  579.             }
  580.             emuPrimaryWindow.Activate()
  581.         }
  582.     }
  583.     If ((VMU1Draw) and (VMU2Draw) and (VMU3Draw) and (VMU4Draw))
  584.         SetTimer, CheckforVMU, off
  585. Return 
  586.  
  587. VMUHide:
  588.     If VMUHidden {
  589.         Loop, 4
  590.             VMUWindow%a_index%.Set("Transparent", "off")
  591.         UpdateLayeredWindow(extraFixedRes_Bezel_hwnd, extraFixedRes_Bezel_hdc,0,0, A_ScreenWidth, A_ScreenHeight,255)
  592.         VMUHidden := false
  593.     } Else {
  594.         Loop, 4
  595.             VMUWindow%a_index%.Set("Transparent", 0)
  596.         UpdateLayeredWindow(extraFixedRes_Bezel_hwnd, extraFixedRes_Bezel_hdc,0,0, A_ScreenWidth, A_ScreenHeight,0)
  597.         VMUHidden := true
  598.     }
  599. Return
  600.  
  601. CloseProcess:
  602.     FadeOutStart()
  603.     If demulShooterEnabled {
  604.         DemulShooterExe.Close()
  605.     }
  606.     emuPrimaryWindow.PostMessage("0x111", "40085")  ; Stop emulation first for a clean exit
  607.     TimerUtils.Sleep(5) ; just like to give a little time before closing
  608.     emuPrimaryWindow.PostMessage("0x111", "40080")  ; Exit
  609. Return
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top