Advertisement
djvj

Model 2 module

Dec 19th, 2023
837
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. MEmu := "Sega Model 2 Emulator"
  2. MEmuV := "v1.0"
  3. MURL := ["http://nebula.emulatronia.com/"]
  4. MAuthor := ["djvj","ghutch92"]
  5. MVersion := "2.0.9"
  6. MCRC := "14EECBD4"
  7. iCRC := "3732EFE4"
  8. MID := "635175648125374429"
  9. MSystem := ["Sega Model 2"]
  10. ;----------------------------------------------------------------------------
  11. ; Notes:
  12. ; Manually launch the Sega Model 2 Emulator.
  13. ; Under Video enable "auto switch to fullscreen".
  14. ; model2.zip must exist in your rom path which contains the needed bios files for the system.
  15. ; Module settings overwrite what you have set in the emulator itself.
  16. ;
  17. ; For Multiplayer Support:
  18. ; To enable the linked games support, set Link_Enabled to true in the module settings in RocketLauncherUI
  19. ; The module has an internal list of games that it will only enable it for. Not all of the games work in this emu. See below for more info.
  20. ;
  21. ; 1.) Multiplayer does not work when the emulator is launched using the same executable in the same path.
  22. ; 2.) Multiplayer only works if player 1 is set to be in master mode and players 2-4 are set to be in slave mode. (this info is stored in the emupath\NVDATA folder, press F2 to set in game)
  23. ; 3.) Singleplayer only works if player 1 is set to be in single mode. (this info is stored in the emupath\NVDATA folder, press F2 to set in game)
  24. ; 4.) Only the active window accepts keyboard input.
  25. ;
  26. ; Fixed Issue 1 by having folders in the emupath named Player 2, Player 3, and Player 4  and within each of these folsers there are separate installs of sega model 2 emulator.
  27. ; Fixed Issue 2 and 3 for Player 1 by having a folder named "Multi" in the NVDATA folder for multiplayer dat files and a folder name "Single" in the NVDATA folder for single player dat files.
  28. ; Fixed Issue 4 by activating the first player window so first player always has the keyboard and players 2-4 have to use a joystick(gamepad).
  29. ;
  30. ;Games that have a working link:
  31. ; daytona,daytonagtx,daytonam,daytonas,daytonat,indy500,indy500d,manxtt,motoraid,skisuprg,srallyc,srallycb,srallyp,stcc,stcce,von,vonj,waverunr
  32. ;
  33. ; overrev and sgt24h both look like they can support link but I couldn't get it working, because I think m2emulator uses a linking hack to get these games to work in stand alone mode.
  34. ; Still need to see if waverunr, stcc, stcce, von, and vonj can link, I couldn't get these working, I think my processor is the issue here. Saw video of stcc & waverunr link working though.
  35. ; von and vonj can only do a 2 player link
  36. ;----------------------------------------------------------------------------
  37. StartModule()
  38. BezelGUI()
  39.  
  40. settingsFile := modulePath . "\" . moduleName . ".ini"
  41. linkEnabled := IniReadCheck(settingsFile, "Settings|" . romName, "Link_Enabled", "false",,1)
  42. demulShooterEnabled := IniReadCheck(settingsFile, "Settings|" . romName, "DemulShooterEnabled", "false",,1)
  43.  
  44. SplitScreen2PlayersMode := IniReadCheck(settingsFile, "Settings", "SplitScreen_2_Players","Vertical",,1) ;horizontal or vertical
  45. SplitScreen3PlayersMode := IniReadCheck(settingsFile, "Settings", "SplitScreen_3_Players","P1top",,1) ; For Player1 screen to be on left: P1left. For Player1 screen to be on top: P1top. For Player1 screen to be on bottom: P1bottom. For Player1 screen to be on right: P1right.
  46.  
  47. If romName in daytona,daytonagtx,daytonam,daytonas,daytonat,indy500,indy500d,manxtt,motoraid,skisuprg,srallyc,srallycb,srallyp,stcc,stcce,von,vonj,waverunr
  48.     If (linkEnabled = "true") {
  49.         Log("Module - Link mode enabled")
  50.         linkEnabledGame := 1
  51.     }
  52.  
  53. If linkEnabledGame
  54.     If (romName = "von") or (romName = "vonj")
  55.         SelectedNumberofPlayers := NumberOfPlayersSelectionMenu(2)
  56.     Else
  57.         SelectedNumberofPlayers := NumberOfPlayersSelectionMenu(4)
  58.  
  59. FadeInStart()
  60.  
  61. fullscreen := IniReadCheck(settingsFile, "Settings", "Fullscreen","true",,1)
  62. fullScreenWidth := IniReadCheck(settingsFile, "Settings", "FullScreenWidth",A_ScreenWidth,,1)
  63. fullScreenHeight := IniReadCheck(settingsFile, "Settings", "FullScreenHeight",A_ScreenHeight,,1)
  64. emupath2 := IniReadCheck(settingsFile, "Settings", "Player2_EmulatorPath",emupath . "\Player 2",,1) ;must be a unique path to same version of the emulator
  65. emupath3 := IniReadCheck(settingsFile, "Settings", "Player3_EmulatorPath",emupath . "\Player 3",,1) ;must be a unique path to same version of the emulator
  66. emupath4 := IniReadCheck(settingsFile, "Settings", "Player4_EmulatorPath",emupath . "\Player 4",,1) ;must be a unique path to same version of the emulator
  67.  
  68. CheckFile(romPath . "\model2.zip","Could not locate ""model2.zip"" which contains the bios files for this emulator. Please make sure it exists in the same folder as your roms.")
  69.  
  70. m2Ini := CheckFile(emuPath . "\EMULATOR.INI")
  71. m2RomDir1 := IniReadCheck(m2Ini, "RomDirs", "Dir1",,,1)
  72. If (m2RomDir1 != romPath)
  73.     IniWrite, %romPath%, %m2Ini%, RomDirs, Dir1 ; write the correct romPath to the emu's ini so the user does not need to define this
  74.  
  75. If SelectedNumberofPlayers > 1
  76.     BezelStart(SelectedNumberofPlayers)
  77. Else
  78.     BezelStart()
  79.  
  80. hideEmuObj := Object("AHK_class MYWIN",1)   ; Hide_Emu will hide these windows. 0 = will never unhide, 1 = will unhide later
  81. 7z(romPath, romName, romExtension, 7zExtractPath)
  82.  
  83. ; Write settings to m2's ini file - this needs to change also
  84. IniWrite, % (If fullscreen = "true" ? 1 : 0), %m2Ini%, Renderer, AutoFull
  85. IniWrite, %fullScreenWidth%, %m2Ini%, Renderer, FullScreenWidth
  86. IniWrite, %fullScreenHeight%, %m2Ini%, Renderer, FullScreenHeight
  87.  
  88. If (demulShooterEnabled = "true") { ; If demulshooter is enabled for this game, launch it with relevant options
  89.     demulShooterTarget := StringUtils.Contains(executable,"multicpu") ? "model2m" : "model2"
  90.     DemulShooterExe := New DemulShooter()
  91.     DemulShooterExe.Launch(demulShooterTarget,romName,"-noresize")
  92. }
  93.  
  94. If (SelectedNumberofPlayers = 1 || !linkEnabledGame) {
  95.     ; Changing Cabinent Settings for player 1 this is because we will need to switch between master controller mode and single mode
  96.     ; this info is stored in the NVDATA folder
  97.     ; store single player settings in the NVDATA\Single folder and the Multiplayer Settings in the NVDATA\Multi folder
  98.     If (FileExist(emupath . "\NVDATA\Single\" . romName . ".DAT") && linkEnabledGame) {
  99.         Log("Overwriting " . emupath . "\NVDATA\" . romName . ".DAT with " . emupath . "\NVDATA\Single\" . romName . ".DAT")
  100.         FileCopy,%emupath%\NVDATA\Single\%romName%.DAT,%emupath%\NVDATA,1
  101.     }
  102.    
  103.     HideEmuStart()  ; This fully ensures windows are completely hidden even faster than winwait
  104.  
  105.     Run(executable . A_Space . romName, emuPath, "Hide")    ; Hides the emulator on launch. When bezel is enabled, this helps not show the emu before the rom is loaded
  106.     WinWait("ahk_class MYWIN",,,"Model 2 Emulator")
  107.     ;WinWaitActive("ahk_class MYWIN",,,"Model 2 Emulator") ;this line only works if fade in is enabled
  108.     Sleep, 1000 ; Increase if your Front End is getting a quick flash in before the game loads
  109. } Else {
  110.     ;screen positions
  111.     If (SelectedNumberofPlayers = 2)
  112.         If SplitScreen2PlayersMode = Vertical
  113.             X1 := 0 , Y1 := 0 , W1 := A_ScreenWidth//2 , H1 := A_ScreenHeight , X2 := A_ScreenWidth//2 , Y2 := 0 ,  W2 := A_ScreenWidth//2 , H2 := A_ScreenHeight
  114.         Else
  115.             X1 := 0 , Y1 := 0 , W1 := A_ScreenWidth , H1 := A_ScreenHeight//2 , X2 := 0 , Y2 := A_ScreenHeight//2 , W2 := A_ScreenWidth , H2 := A_ScreenHeight//2
  116.     Else If (SelectedNumberofPlayers = 3)
  117.         If SplitScreen3PlayersMode = P1left
  118.             X1 := 0 , Y1 := 0 , W1 := A_ScreenWidth//2 , H1 := A_ScreenHeight , X2 := A_ScreenWidth//2 , Y2 := 0 ,  W2 := A_ScreenWidth//2 , H2 := A_ScreenHeight//2 , X3 := A_ScreenWidth//2 , Y3 := A_ScreenHeight//2 ,   W3 := A_ScreenWidth//2 , H3 := A_ScreenHeight//2
  119.         Else If SplitScreen3PlayersMode = P1bottom
  120.             X1 := 0 , Y1 := A_ScreenHeight//2 , W1 := A_ScreenWidth , H1 := A_ScreenHeight//2 , X2 := 0 , Y2 := 0 , W2 := A_ScreenWidth//2 , H2 := A_ScreenHeight//2 , X3 := A_ScreenWidth//2 , Y3 := 0 ,   W3 := A_ScreenWidth//2 , H3 := A_ScreenHeight//2
  121.         Else If SplitScreen3PlayersMode = P1right
  122.             X1 := A_ScreenWidth//2 , Y1 := 0 ,  W1 := A_ScreenWidth//2 , H1 := A_ScreenHeight , X2 := 0 , Y2 := 0 , W2 := A_ScreenWidth//2 , H2 := A_ScreenHeight//2 , X3 := 0 , Y3 := A_ScreenHeight//2 ,  W3 := A_ScreenWidth//2 , H3 := A_ScreenHeight//2
  123.         Else    ; top
  124.             X1 := 0 , Y1 := 0 , W1 := A_ScreenWidth , H1 := A_ScreenHeight//2, X2 := 0 , Y2 := A_ScreenHeight//2 ,  W2 := A_ScreenWidth//2 , H2 := A_ScreenHeight//2, X3 := A_ScreenWidth//2 , Y3 := A_ScreenHeight//2 , W3 := A_ScreenWidth//2 , H3 := A_ScreenHeight//2
  125.     Else
  126.         X1 := 0 , Y1 := 0 , W1 := A_ScreenWidth//2 , H1 := A_ScreenHeight//2 , X2 := A_ScreenWidth//2 , Y2 := 0 ,   W2 := A_ScreenWidth//2 , H2 := A_ScreenHeight//2 , X3 := 0 , Y3 := A_ScreenHeight//2 ,  W3 := A_ScreenWidth//2 , H3 := A_ScreenHeight//2 , X4 := A_ScreenWidth//2 , Y4 := A_ScreenHeight//2 ,   W4 := A_ScreenWidth//2 , H4 := A_ScreenHeight//2
  127.    
  128.     HideEmuStart()  ; This fully ensures windows are completely hidden even faster than winwait
  129.  
  130.     ;this loop is for error checking since this emulator needs multiple instances of the emulator starting from different locations to run
  131.     Loop, %SelectedNumberofPlayers%
  132.     {
  133.         LinkedEmuPath := (A_Index = 1) ? (emupath) : (emupath%A_Index%)
  134.         CheckFile(LinkedEmuPath . "\" . executable)
  135.         CheckFile(LinkedEmuPath . "\EMULATOR.INI")
  136.     }
  137.     ; Changing Cabinent Settings for player 1 this is because we will need to switch between master controller mode and single mode
  138.     ; this info is stored in the NVDATA folder
  139.     ; store single player settings in the NVDATA\Single folder and the Multiplayer Settings in the NVDATA\Multi folder
  140.     If FileExist(emupath . "\NVDATA\Multi\" . romName . ".DAT") {
  141.         Log("Overwriting " . emupath . "\NVDATA\" . romName . ".DAT with " . emupath . "\NVDATA\Multi\" . romName . ".DAT")
  142.         FileCopy,%emupath%\NVDATA\Multi\%romName%.DAT,%emupath%\NVDATA,1
  143.     }
  144.        
  145.     Loop, %SelectedNumberofPlayers%
  146.     {
  147.         LinkedEmuPath := (A_Index = 1) ? (emupath) : (emupath%A_Index%)
  148.         m2ini := LinkedEmuPath . "\EMULATOR.INI"        ;no need to checkfile it here since it's already been done
  149.         m2RomDir1 := IniReadCheck(m2Ini, "RomDirs", "Dir1",,,1)
  150.         If (m2RomDir1 != romPath)
  151.             IniWrite, %romPath%, %m2Ini%, RomDirs, Dir1 ; write the correct romPath to the emu's ini so the user does not need to define this
  152.         ; Removing Fullscreen
  153.         IniWrite, 0, %m2Ini%, Renderer, AutoFull
  154.         ; Creating the link
  155.         IniWrite,127.0.0.1,%LinkedEmuPath%\m2network.ini,network,NextIp     ;127.0.0.1 is local address
  156.         IniWrite,% (1978 + A_Index - 1),%LinkedEmuPath%\m2network.ini,network,RxPort        ;Recieving port
  157.         ;the last player sends information to the first player completing the circle
  158.         IniWrite,% (If (A_Index = SelectedNumberofPlayers) ? 1978 : (1978 + A_Index)),%LinkedEmuPath%\m2network.ini,network,NextPort    ;Sending Port
  159.         Run(executable . A_Space . romName, LinkedEmuPath, "Hide",Screen%A_Index%PID)
  160.         WinWait("ahk_pid " . Screen%A_Index%PID)
  161.         WinGet, Screen%A_Index%ID, ID, % "ahk_pid " . Screen%A_Index%PID
  162.         If Fullscreen = true
  163.         {   WinSet, Style, -0xC00000, % "ahk_id " . Screen%A_Index%ID
  164.             ToggleMenu(Screen%A_Index%ID)
  165.             WinSet, Style, -0xC40000, % "ahk_id " . Screen%A_Index%ID
  166.             currentScreen := A_Index
  167.             Log("Moving window " . currentScreen . " to " .  X%currentScreen% . "`," . Y%currentScreen% . " with W" . W%currentScreen% . " H" . H%currentScreen%)
  168.             WinMove,  % "ahk_id " . Screen%currentScreen%ID, , % X%currentScreen%, % Y%currentScreen%, % W%currentScreen%, % H%currentScreen%
  169.             ;check If window moved
  170.             timeout := A_TickCount
  171.             Loop
  172.             {   WinGetPos, X, Y, W, H, % "ahk_id " . Screen%currentScreen%ID
  173.                 If (X=X%currentScreen%) and (Y=Y%currentScreen%) and (W=W%currentScreen%) and (H=H%currentScreen%)
  174.                     break
  175.                 If (timeout<A_TickCount-2000)
  176.                     Break
  177.                 Sleep, 50
  178.                 WinMove, % "ahk_id " . Screen%currentScreen%ID, , % X%currentScreen%, % Y%currentScreen%, % W%currentScreen%, % H%currentScreen%
  179.             }
  180.         }
  181.         Sleep, 50
  182.     }
  183. }
  184.  
  185. BezelDraw()
  186. HideEmuEnd()
  187.  
  188. If (SelectedNumberofPlayers = 1 || !linkEnabledGame) {
  189.     WinShow, ahk_class MYWIN    ; Show the emulator
  190. } Else {
  191.     Loop %SelectedNumberofPlayers%
  192.         WinShow, % "ahk_id " . Screen%a_index%ID    ; Show the emulator
  193.     WinActivate, ahk_id %Screen1ID%     ; activate first player window so that first player can use keyboard instead of last player
  194. }
  195.  
  196. ;I find that the fade in exit looks better after the winshow lines
  197. FadeInExit()
  198.  
  199. Process("WaitClose", executable)
  200. BezelExit()
  201. FadeOutExit()
  202. ExitModule()
  203.  
  204. CloseProcess:
  205.     FadeOutStart()
  206.     If (demulShooterEnabled = "true") {
  207.         DemulShooterExe.Close()
  208.     }
  209.     If (SelectedNumberofPlayers>1) {
  210.         Loop, %SelectedNumberofPlayers%
  211.         {   WinClose("ahk_id " . Screen%A_Index%ID)
  212.             WinWaitClose("ahk_id " . Screen%A_Index%ID)
  213.         }
  214.     } Else
  215.         WinClose("AHK_class MYWIN")
  216. Return
  217.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement