rfancella

NullDC.ahk New

Feb 28th, 2015
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.78 KB | None | 0 0
  1. MEmu = NullDC
  2. MEmuV = r141
  3. MURL = https://code.google.com/p/nulldc/
  4. MAuthor = djvj & bleasby
  5. MVersion = 2.0.6
  6. MCRC = E9F6474E
  7. iCRC = C2786503
  8. MID = 635038268910409317
  9. MSystem = "Sega Dreamcast"
  10. ;----------------------------------------------------------------------------
  11. ; NullDC works with these disc images:
  12. ; - CDI: Padus DiscJuggler image
  13. ; - MDS: Alcohol 120% Media Descriptor image (must be accompanied by a MDF file)
  14. ; - NRG: Nero Burning ROM image
  15. ; - GDI: Raw GDI dump
  16. ; - CHD: MAME's Compressed Hunk of Data
  17. ;
  18. ; Helpful guide for getting the basics setup for NullDC: http://www.dgemu.com/forums/index.php/topic/474318-guide-configuring-nulldc-104-r136/
  19. ; If you want to use specific configs per game, create a folder called Cfg inside nullDC folder and copy your nullDC.cfg
  20. ; config files into it naming them to match the database names. Make sure you keep a copy of nullDC.cfg on the Cfg folder as well.
  21. ;
  22. ; If you want to convert your roms from gdi to chd, see here: http://www.emutalk.net/showthread.php?t=51502
  23. ; FileDelete(s) are in the script because sometimes demul will corrupt the ini and make it crash. The script recreates a clean ini for you.
  24. ;
  25. ; Setup the user settings in the moduleName ini to your liking
  26. ; Games can have a custom Cable Type (per game). Not all games work on VGA, so use the below option in the ini
  27. ; Cable can be 0 (VGA(0)(RGB)), 1 (VGA(1)(RGB)), 2 (TV(RGB)) or 3 (TV(VBS/Y+S/C)), default is 0.
  28. ;
  29. ; For additional setup steps prior to running, see this link: http://www.hyperspin-fe.com/forum/showpost.php?p=99852&postcount=138
  30. ; Not all builds work with swapping discs, it's mostly broken and is a nulldc problem, not HyperLaunch's. See here: http://code.google.com/p/nulldc/issues/detail?id=264
  31. ;----------------------------------------------------------------------------
  32. StartModule()
  33. BezelGUI()
  34. ExtraFixedResBezelGUI()
  35.  
  36. If systemName not contains dreamcast,dc
  37. ScriptError(systemName . " is not a supported system for this module. Only " . MSystem . " is supported.")
  38.  
  39. FadeInStart()
  40.  
  41. settingsFile := modulePath . "\" . moduleName . ".ini"
  42. nullDCcfg := checkFile(emuPath . "\nullDC.cfg")
  43.  
  44. fullscreen := IniReadCheck(settingsFile, "Settings", "Fullscreen","true",,1)
  45. dualMonitors := IniReadCheck(settingsFile, "NullDC", "DualMonitors","false",,1)
  46. autoStart := IniReadCheck(settingsFile, "NullDC", "autoStart","1",,1)
  47. noConsole := IniReadCheck(settingsFile, "NullDC", "noConsole","1",,1)
  48. autoHideMenu := IniReadCheck(settingsFile, "NullDC", "autoHideMenu","0",,1)
  49. alwaysOnTop := IniReadCheck(settingsFile, "NullDC", "alwaysOnTop","1",,1)
  50. showVMU := IniReadCheck(settingsFile, "NullDC", "showVMU","0",,1)
  51. VMU1Pos := IniReadCheck(settingsFile, "NullDC", "VMU1Pos","topLeft",,1) ; topRight, topCenter, topLeft, leftCenter, bottomLeft, bottomCenter, bottomRight, rightCenter
  52. VMU2Pos := IniReadCheck(settingsFile, "NullDC", "VMU2Pos","topRight",,1) ; topRight, topCenter, topLeft, leftCenter, bottomLeft, bottomCenter, bottomRight, rightCenter
  53. VMU3Pos := IniReadCheck(settingsFile, "NullDC", "VMU3Pos","bottomLeft",,1) ; topRight, topCenter, topLeft, leftCenter, bottomLeft, bottomCenter, bottomRight, rightCenter
  54. VMU4Pos := IniReadCheck(settingsFile, "NullDC", "VMU4Pos","bottomRight",,1) ; topRight, topCenter, topLeft, leftCenter, bottomLeft, bottomCenter, bottomRight, rightCenter
  55. VMUHideKey := IniReadCheck(settingsFile, "Settings", "VMUHideKey","F10",,1)
  56. loadDefaultImage := IniReadCheck(settingsFile, "NullDC", "loadDefaultImage","1",,1)
  57. patchRegion := IniReadCheck(settingsFile, "NullDC", "patchRegion","1",,1)
  58. cable := IniReadCheck(settingsFile, romName, "Cable","0",,1)
  59. PerGameMemoryCards := IniReadCheck(settingsFile, "NullDC", "PerGameMemoryCards","true",,1)
  60. memCardPath := IniReadCheck(settingsFile, "Settings", "memCardPath", EmuPath . "\Game VMU",,1)
  61. memCardPath := AbsoluteFromRelative(EmuPath, memCardPath)
  62.  
  63. hideEmuObj := Object("ahk_class ConsoleWindowClass",0,"nullDC ahk_class ndc_main_window",1) ; Hide_Emu will hide these windows. 0 = will never unhide, 1 = will unhide later
  64. 7z(romPath, romName, romExtension, 7zExtractPath)
  65.  
  66. specialCfg = %emuPath%\cfg\%romName%.cfg
  67. defaultCfg = %emuPath%\cfg\nullDC.cfg
  68. If (FileExist(specialCfg) && FileExist(defaultCfg))
  69. FileCopy, %specialCfg%, %emuPath%\nullDC.cfg, 1
  70. Else If FileExist(defaultCfg)
  71. FileCopy, %defaultCfg%, %emuPath%\nullDC.cfg, 1
  72.  
  73. ;Detect game region based on rom name
  74. IfInString, romName, (Europe)
  75. region = 2
  76. Else IfInString, romName, (Japan)
  77. region = 0
  78. Else IfInString, romName, (World)
  79. region = 2
  80. Else
  81. region = 1
  82.  
  83. If romExtension In %7zformats%
  84. ScriptError(MEmu . " does not support compressed formats. Please extract your images first or enable 7z.")
  85.  
  86. BezelStart()
  87.  
  88. ;Write Settings
  89. IniWrite, % (If (Fullscreen = "true" )?("1"):("0")), %nullDCcfg%, nullDC_GUI, Fullscreen
  90. IniWrite, %autoStart%, %nullDCcfg%, nullDC, Emulator.AutoStart
  91. IniWrite, %noConsole%, %nullDCcfg%, nullDC, Emulator.NoConsole
  92. IniWrite, %autoHideMenu%, %nullDCcfg%, nullDC_GUI, AutoHideMenu
  93. IniWrite, %alwaysOnTop%, %nullDCcfg%, nullDC_GUI, AlwaysOnTop
  94. IniWrite, %showVMU%, %nullDCcfg%, drkMaple, VMU.Show
  95. IniWrite, %loadDefaultImage%, %nullDCcfg%, ImageReader, LoadDefaultImage
  96. IniWrite, %patchRegion%, %nullDCcfg%, ImageReader, PatchRegion
  97. IniWrite, %region%, %nullDCcfg%, nullDC, Dreamcast.Region
  98. IniWrite, %cable%, %nullDCcfg%, nullDC, Dreamcast.Cable
  99. Log("Module - Telling ImageReader plugin to load this game: """ . romPath . "\" . romname . RomExtension)
  100. IniWrite, %romPath%\%romname%%RomExtension%, %nullDCcfg%, ImageReader, DefaultImage
  101.  
  102. ;Fixes hanging previous nullDC on bad exits or loads
  103. Process("Exist", executable)
  104. If !ErrorLevel = 0
  105. Process("Close", executable)
  106.  
  107. ; This hides nullDC's menu when running dual screens
  108. If dualMonitors = true
  109. { MouseGetPos X, Y
  110. SetDefaultMouseSpeed, 0
  111. MouseMove %A_ScreenWidth%,%A_ScreenHeight%
  112. }
  113.  
  114. If PerGameMemoryCards = true
  115. {
  116. defaultMemCard := emuPath . "\Data\vmu_default.bin" ; defining default blank VMU file
  117. If (FileExist(defaultMemCard))
  118. {
  119. Log("VMU - Default VMU file location - " . defaultMemCard,5)
  120. Log("VMU - Per game memory card path - " . memCardPath,5)
  121. IfNotExist, %memCardPath%
  122. FileCreateDir, %memCardPath%
  123. Loop, 4
  124. {
  125. outerLoop := A_Index
  126. VMUCount := % outerLoop - 1
  127. controllerVMU%VMUCount% := IniReadCheck(nullDCcfg, "nullDC_plugins", "Current_maple" . VMUCount . "_" . "5",,,1)
  128. LOG("VMU - Config Plugin controllerVMU" . VMUCount . " - " . controllerVMU%VMUCount%,5)
  129. If controllerVMU%VMUCount% = NULL
  130. continue
  131. Loop, 2
  132. {
  133. SubCount := % A_Index - 1
  134. controllerVMU%VMUCount%SubDev%SubCount% := IniReadCheck(nullDCcfg, "nullDC_plugins", "Current_maple" . VMUCount . "_" . SubCount,,,1)
  135. LOG("VMU - Config Plugin controllerVMU" . VMUCount . " Sub " . SubCount . " - " . controllerVMU%VMUCount%SubDev%SubCount%,5)
  136. if (controllerVMU%VMUCount%SubDev%SubCount% = "drkMapleDevices_Win32.dll:2") or (controllerVMU%VMUCount%SubDev%SubCount% = "G15_drkMapleDevices_Win32.dll:2")
  137. {
  138. If VMUCount = 0
  139. {
  140. VMUPort := "0"
  141. }
  142. Else If VMUCount = 1
  143. {
  144. VMUPort := "4"
  145. }
  146. Else If VMUCount = 2
  147. {
  148. VMUPort := "8"
  149. }
  150. Else If VMUCount = 3
  151. {
  152. VMUPort := "C"
  153. }
  154. VMUGameName := If romTable[1,5] ? romTable[1,4] : romName ; defining rom name for multi disc rom
  155. PerGameVMUIn := memCardPath . "\" . VMUGameName . "_port" . VMUPort . A_Index . ".bin"
  156. PerGameVMUOut := emuPath . "\vmu_data_port" . VMUPort . A_Index . ".bin"
  157. If (FileExist(PerGameVMUIn))
  158. {
  159. LOG("VMU - Per game VMU in file """ . PerGameVMUIn . """ exists. Copying to emu folder as """ . PerGameVMUOut . """",1)
  160. FileCopy, %PerGameVMUIn%, %PerGameVMUOut%, 1
  161. } Else {
  162. FileCopy, %defaultMemCard%, %PerGameVMUOut%, 1
  163. LOG("VMU - Per game VMU out file """ . PerGameVMUIn . """ does not exist, so """ . PerGameVMUOut . """ is created.",1)
  164. }
  165. }
  166. }
  167. }
  168. } Else {
  169. Log("VMU - No default VMU file at " . defaultMemCard,5)
  170. }
  171. }
  172.  
  173. HideEmuStart() ; This fully ensures windows are completely hidden even faster than winwait
  174.  
  175. Run(executable, emuPath)
  176.  
  177. ; TESTING TO HIDE THE CONSOLE WINDOW POPUP, NOTHING WORKS
  178. ; WinWait("nullDC ahk_class ndc_main_window")
  179. ; WinSet, Transparent, On, nullDC ahk_class ndc_main_window
  180. ; WinSet, Transparent, On, ahk_class ConsoleWindowClass ; makes the console window transparent so you don't see it on exit
  181. ; Sleep, 2000 ; Enough to hide the startup logo
  182. ; WinHide, ahk_class ConsoleWindowClass
  183.  
  184. WinWait("nullDC ahk_class ndc_main_window")
  185. WinWaitActive("nullDC ahk_class ndc_main_window")
  186.  
  187. ndcID:=WinExist("A") ; storing the window's PID so we can toggle it later
  188. ToggleMenu(ndcID) ; Removes the MenuBar
  189. ; DllCall("SetMenu", uint, WinActive( "A" ), uint, 0) ; Removes the MenuBar
  190.  
  191. ;Let's completely hide the menu by slighly moving the window off screen
  192. ;nullDC will self adjust once the menu autohides
  193. If fullScreen = true
  194. { yOffset = -20
  195. winHeight := A_ScreenHeight - yOffset
  196. WinMove, nullDC,, 0, %yOffset%, %A_ScreenWidth%, %winHeight%
  197. }
  198.  
  199. ; WinShow, nullDC ahk_class ndc_main_window ; without these, nullDC may stay hidden behind HS
  200. ; WinActivate, nullDC ahk_class ndc_main_window
  201. HideEmuEnd()
  202. BezelDraw()
  203. If !(showVMU="0")
  204. SetTimer, CheckforVMU, 10000
  205. FadeInExit()
  206. WinSet, Transparent, Off, nullDC ahk_class ndc_main_window
  207. Process("WaitClose", executable)
  208. 7zCleanUp()
  209. BezelExit()
  210. ExtraFixedResBezelExit()
  211.  
  212. If PerGameMemoryCards = true
  213. {
  214. Loop, 4
  215. {
  216. outerLoop := A_Index
  217. VMUCount := % outerLoop - 1
  218. Log("VMU - Config Plugin controllerVMU" . VMUCount . " - " . controllerVMU%VMUCount%,5)
  219. if controllerVMU%VMUCount% = NULL
  220. continue
  221. Loop, 2
  222. {
  223. SubCount := % A_Index - 1
  224. if (controllerVMU%VMUCount%SubDev%SubCount% = "drkMapleDevices_Win32.dll:2") or (controllerVMU%VMUCount%SubDev%SubCount% = "G15_drkMapleDevices_Win32.dll:2")
  225. {
  226. If VMUCount = 0
  227. {
  228. VMUPort := "0"
  229. }
  230. Else If VMUCount = 1
  231. {
  232. VMUPort := "4"
  233. }
  234. Else If VMUCount = 2
  235. {
  236. VMUPort := "8"
  237. }
  238. Else If VMUCount = 3
  239. {
  240. VMUPort := "C"
  241. }
  242. PerGameVMUIn := memCardPath . "\" . VMUGameName . "_port" . VMUPort . A_Index . ".bin"
  243. PerGameVMUOut := emuPath . "\vmu_data_port" . VMUPort . A_Index . ".bin"
  244. If (FileExist(PerGameVMUOut))
  245. {
  246. FileCopy, %PerGameVMUOut%, %PerGameVMUIn%, 1
  247. Log("VMU - VMUFile " . PerGameVMUOut . " exists. Backing up to " . PerGameVMUIn,1)
  248. }
  249. }
  250. }
  251. }
  252. }
  253.  
  254. FadeOutExit()
  255. ExitModule()
  256.  
  257.  
  258. ; Toggle the MenuBar
  259. !a::
  260. ToggleMenu(ndcID)
  261. Return
  262.  
  263. MultiGame:
  264. ; msgbox % "selectedRom = " . selectedRom . "`nselected game = " . currentButton . "`nmgRomPath = " . mgRomPath . "`nmgRomExt = " . mgRomExt . "`nmgRomName = " . mgRomName
  265. ToggleMenu(ndcID) ; Restore the MenuBar
  266. Loop {
  267. WinMenuSelectItem,nullDC ahk_class ndc_main_window,,Options,GDRom,Select Default Image
  268. WinWait("Select Image File ahk_class #32770")
  269. WinWaitActive("Select Image File ahk_class #32770")
  270. If WinActive("Select Image File ahk_class #32770")
  271. Break
  272. }
  273. OpenROM("Select Image File ahk_class #32770", mgRomPath . "\" . mgRomName . "." . mgRomExt) ; unsure if Select Image File needs to be translated via i18n
  274. WinWaitActive("nullDC ahk_class ndc_main_window")
  275. Sleep, 300 ; giving time for emu to mount the new image
  276. WinMenuSelectItem,nullDC ahk_class ndc_main_window,,Options,GDRom,Swap Disc ; DC does not support swapping discs on-the-fly like psx because the console reset when the drive was opened. This basically tells the emu to reset.
  277. ToggleMenu(ndcID) ; Removes the MenuBar
  278. Return
  279.  
  280. BezelLabel:
  281. disableHideToggleMenu := true
  282. Return
  283.  
  284. HaltEmu:
  285. If VMUHideKey
  286. XHotKeywrapper(VMUHideKey,"VMUHide","OFF")
  287. Return
  288.  
  289. RestoreEmu:
  290. If VMULoaded
  291. { Loop, 4
  292. { WinSet, Transparent, 0, % "ahk_ID " . VMUScreenID%A_Index%
  293. WinSet, AlwaysOnTop, On, % "ahk_ID " . VMUScreenID%A_Index%
  294. WinShow, % "ahk_ID " . VMUScreenID%A_Index%
  295. }
  296. WinSet, AlwaysOnTop, On, ahk_ID %extraFixedRes_Bezel_hwnd%
  297. WinShow, ahk_ID %extraFixedRes_Bezel_hwnd%
  298. If !(VMUHidden)
  299. Loop, 4
  300. WinSet, Transparent, off, % "ahk_ID " . VMUScreenID%A_Index%
  301. }
  302. If VMUHideKey
  303. XHotKeywrapper(VMUHideKey,"VMUHide","ON")
  304. Return
  305.  
  306. CheckforVMU:
  307. Loop, 4
  308. { Transform, letter, Chr, % A_Index + asc("A") - 1 ; transform number to letter
  309. If ((!(VMU%A_Index%Draw)) and (VMUScreenID%A_Index%:=WinExist("nullDC VMU " . letter . "0 ahk_class #32770")))
  310. { WinSet, Transparent, 0, % "ahk_ID " . VMUScreenID%A_Index%
  311. WinSet, AlwaysOnTop, On, % "ahk_ID " . VMUScreenID%A_Index%
  312. ExtraFixedResBezelDraw(VMUScreenID%A_Index%, "VMU",VMU%A_Index%Pos, 144, 96, 8, 8, 28, 8)
  313. WinShow, % "ahk_ID " . VMUScreenID%A_Index%
  314. WinSet, AlwaysOnTop, On, ahk_ID %extraFixedRes_Bezel_hwnd%
  315. WinShow, ahk_ID %extraFixedRes_Bezel_hwnd%
  316. WinSet, Transparent, off, % "ahk_ID " . VMUScreenID%A_Index%
  317. VMU%A_Index%Draw := true
  318. If !(VMULoaded){
  319. VMUHideKey := xHotKeyVarEdit(VMUHideKey,"VMUHideKey","~","Add")
  320. xHotKeywrapper(VMUHideKey,"VMUHide")
  321. VMULoaded := true
  322. }
  323. }
  324. }
  325. If ((VMU1Draw) and (VMU2Draw) and (VMU3Draw) and (VMU4Draw))
  326. SetTimer, CheckforVMU, off
  327. Return
  328.  
  329. VMUHide:
  330. If (VMUHidden)
  331. { Loop, 4
  332. WinSet, Transparent, off, % "ahk_ID " . VMUScreenID%A_Index%
  333. UpdateLayeredWindow(extraFixedRes_Bezel_hwnd, extraFixedRes_Bezel_hdc,0,0, A_ScreenWidth, A_ScreenHeight,255)
  334. VMUHidden := false
  335. } Else {
  336. Loop, 4
  337. WinSet, Transparent, 0, % "ahk_ID " . VMUScreenID%A_Index%
  338. UpdateLayeredWindow(extraFixedRes_Bezel_hwnd, extraFixedRes_Bezel_hdc,0,0, A_ScreenWidth, A_ScreenHeight,0)
  339. VMUHidden := true
  340. }
  341. Return
  342.  
  343. CloseProcess:
  344. If VMULoaded
  345. SetTimer, checkforVMU, off
  346. FadeOutStart()
  347. ; WinClose("ahk_class ConsoleWindowClass")
  348. WinClose("nullDC ahk_class ndc_main_window")
  349. Return
Advertisement
Add Comment
Please, Sign In to add comment