Jump to content
LaunchBox Community Forums

[HOW TO] Automatically set correct mouse (light guns) bindings in Supermodel 3 config file


Hamburglin

Recommended Posts

I'm cross posting this here for visibility because I feel that it solves a really annoying issue that has been plaguing light gun users in supermodel 3 games for years now. The solution can be ran before games launch in additional apps if desired:

 

 

 

Windows does not keep or report back a consistent list of mice that are plugged in. That means that after every boot or new usb device is connected that your mouse assignments might change. In turn, you need to update your Supermodel.ini file to reference the correct number for your mice (light guns). This is super annoying.

I've automated the process of determining what your light gun's mice assignments are and then auto updating the Supermodel.ini to reflect that. The powershell script is INCREDIBLY naive and needs manual editing of variable to get working on your machine. If anyone want's to generalize it make it more efficient, please do!

The trick----------
The novel part of this that I don't think people knew about until today is this:
1. You can assign unique names to your "Generic HID Comapitable" devices via the registry.
2. This lets you run "supermodel.exe print-inputs" and programmatically determine your gun's mouse indexes from that output.


Requirements-----------
Here are the things you must do to prepare to run the script:

  1. Ensure that you have mouse bindings in your Supermodel.ini already. The numbers can be wrong, that's alright. Just bind the buttons you want to be updated when the assignments change. If you want to have non-mouse bindings in addition to your mouse bindings, put those to the right of your mouse bindings. Example: InputCoin1 = MOUSE5_MIDDLE_BUTTON,5
  2. Go to device manager and drop down the mice. You'll see a bunch of "HID compatible devices". We want to find our guns and change that description to something unique. To do this, find your gun's hardware ID (gun4ir's starts with 2341 always) by right clicking each HID device -> Details -> Hardware ID in the dropdown. Then copy its "driver key" value from the same area
  3. Open up regedit and go to SYSTEM -> CurrentControlSet001 -> Enum -> HID. Now ctrl+f and find your devices. Edit their "DeviceDescr" key and add something unique to the very end, and differentiate each gun. Example for my first player's gun: @msmouse.inf,%hid.mousedevice%;HID-compliant mouseGUN1
  4. While you're there, add a brand new value called "FriendlyName". Set that value to reference the same as above. This will change the name in the device manager so you can find the guns easily again if needed instead of it reading "HID compliant device"
  5. Take a moment and understand what we're doing: open the command prompt, cd to your supermodel 3 directory and run "supermodel.exe -print-inputs". You MUST be IN that directory or else it will complain about not finding supermodel.ini. Ok, you ran it. Now scroll up until you see it reporting your mice. You should see the "HID compliant devices" but also your new, unique DeviceDesc values (gun1 etc). Great! Now we have a consistent way to map our lightguns!


Setting up the script------------
At this point, you can simply update your config manually using the numbers on the left for each lightgun. However, I've provided a powershell script you can manually edit and then run to find the devices from that output and update the config for you:
 

 
#Set working di rto supermodel diretory so that it can read Supermodel.ini and not error out
Set-Location -Path "C:\Emulation\Emulators\Supermodel 3 rawinput\"
#Get-Location

#Find gun1's mouse index
$inputs = & "C:\Emulation\Emulators\Supermodel 3 rawinput\Supermodel.exe" -input-system=rawinput -print-inputs 
$gun1info = ($inputs | Select-String "GUN1").Line
$gun1index = $gun1info.Substring(1,1)
$gun1formatted = "MOUSE" + $gun1index
Write-Output $gun1formatted

#Find gun2's mouse index
$inputs = & "C:\Emulation\Emulators\Supermodel 3 rawinput\Supermodel.exe" -input-system=rawinput -print-inputs 
$gun2info = ($inputs | Select-String "GUN2").Line
$gun2index = $gun2info.Substring(1,1)
$gun2formatted = "MOUSE" + $gun2index
Write-Output $gun2formatted

#Read in Supermodel.ini
$content = Get-Content -Path 'C:\Emulation\Emulators\Supermodel 3 rawinput\Config\Supermodel.ini'

#Edit Supermodel.ini mouse related lines
#This assumes you have one mouse assigned per bind/value already. It will not touch any bindings to the RIGHT of the mouse text
#(Need backtick in front of capture group variable in the replacement else it won't print the value)

#Update gun1
$content = $content -replace '(InputStart1.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3" 
$content = $content -replace '(InputCoin1.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputGunX.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3" 
$content = $content -replace '(InputGunY.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputTrigger.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputOffscreen.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputAnalogGunX.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputAnalogGunY.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputAnalogTriggerLeft.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputAnalogTriggerRight.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"

#Update gun2
$content = $content -replace '(InputStart2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputCoin2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputGunX2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3" 
$content = $content -replace '(InputGunY2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputTrigger2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputOffscreen2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputAnalogGunX2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputAnalogGunY2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputAnalogTriggerLeft2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputAnalogTriggerRight2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"

#Write new file
#Write-Output $content
$content | Set-Content -Path "C:\Emulation\Emulators\Supermodel 3 rawinput\Config\Supermodel.ini"

#Make guns rumble so we know this all worked
cmd.exe /c "echo F.1.2.1 > \\.\COM11"
cmd.exe /c "echo F.1.2.1 > \\.\COM12"

 


The script is very primitive and requires you to change these variables or lines:

  1. Set-Location -Path... to your supermodel 3 folder
  2. The value to search for after Select-String (ex:GUN1) in the $gun1info and $gun2info lines
  3. Your supermodel3  exe location in the $inputs lines
  4. The path to your supermodel.ini file after the "#Read in Supermodel.ini" line
  5. Your supermodel.ini path again after the "#Write-Output $content" line
  6. The most complicated part: adding or removing buttons you want bound in the big chunks under the "#Update gunX" lines. SImply copy and paste one of the lines and put in extra button you want bound. Please recall that you need the mouse's already bound to all of these in the supermodel.ini else the script can't match on them to update the numbers. Simply delete specific lines if you dont want some bound (like coin and start for example).


Auto running the script---------
You can now set the script to run at startup or launchbox game start if you make a batch or cmd file to execute it. Instead of that, you can easily convert the ps1 script into an executable by installing PS2EXE via " Install-Module -Name ps2exe " in powershell and then running something like "Invoke-PS2EXE \thisscript.ps1 \newexecutable.exe"

Dump a shortcut to that exe in your windows startup folder, or point to it with additional apps in launchbox

Sorry if this is confusing. I just realized this was possible today and figured out this process and script. Between this and issuing COM commands to gun4ir via echo, this should make supermodel 3 "just work" for light guns! I hope it helps!

Edited by Hamburglin
Link to comment
Share on other sites

I updated the script to force the use of rawinput mode when grabbing the mouse ID's. Sometimes it would use directinput (no idea why) and not be able to find the gun IDs. Secondly, there was a bug if you only had MOUSE in the config instead of MOUSE2 or MOUSE3 and the regex wouldn't find the correct pattern to update with the gun ID.

Link to comment
Share on other sites

  • 1 month later...

Thank you for this! I'm going to give this a go when I get around to tinkering with Supermodel 3. A couple questions... Have you made a video tutorial by chance? Can I use AHK to create this script rather than Powershell? I'm more familiar with the former. Finally, does it have to be rawinput?

Edited by Ronderal
Link to comment
Share on other sites

Hey  glad you found this. Try to follow it and let me know if you need help.

You have to run it in powershell because AHK isn't a real scripting language. It just automates pushing keys.

And yes, the config for lightgun games need to be set to raw input. I have two directories because of this. One for lightgun games and one for the others.

Link to comment
Share on other sites

  • 1 month later...

Tried this, ran the script as a bat file but does not change the gun mappings. Can you check i have the script correct.

 

Set-Location -Path "C:\LaunchBox\Emulators\Model3\Config"
#Get-Location

#Find gun1's mouse index
$inputs = & "C:\LaunchBox\Emulators\Model3\Supermodel.exe" -print-inputs 
$gun1info = ($inputs | Select-String "mouseGUN1").Line
$gun1index = $gun1info.Substring(1,1)
$gun1formatted = "MOUSE" + $gun1index
Write-Output $gun1formatted

#Find gun2's mouse index
$inputs = & "C:\LaunchBox\Emulators\Model3\Supermodel.exe" -print-inputs 
$gun2info = ($inputs | Select-String "mouseGUN2").Line
$gun2index = $gun2info.Substring(1,1)
$gun2formatted = "MOUSE" + $gun2index
Write-Output $gun2formatted

#Read in Supermodel.ini
$content = Get-Content -Path "C:\LaunchBox\Emulators\Model3\Config\Supermodel.ini"

#Edit Supermodel.ini mouse related lines
#This assumes you have one mouse assigned per bind/value already. It will not touch any bindings to the RIGHT of the mouse text
#(Need backtick in front of capture group variable in the replacement else it won't print the value)

#Update gun1
$content = $content -replace '(InputStart1.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3" 
$content = $content -replace '(InputCoin1.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputGunX.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3" 
$content = $content -replace '(InputGunY.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputTrigger.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputOffscreen.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputAnalogGunX.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputAnalogGunY.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputAnalogTriggerLeft.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputAnalogTriggerRight.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"

#Update gun2
$content = $content -replace '(InputStart2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputCoin2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputGunX2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3" 
$content = $content -replace '(InputGunY2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputTrigger2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputOffscreen2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputAnalogGunX2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputAnalogGunY2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputAnalogTriggerLeft2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputAnalogTriggerRight2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"

#Write new file
#Write-Output $content
$content | Set-Content -Path "C:\LaunchBox\Emulators\Model3\Config\Supermodel.ini"

Link to comment
Share on other sites

Posted (edited)
5 hours ago, leefaster said:

Tried this, ran the script as a bat file but does not change the gun mappings. Can you check i have the script correct.

 

Set-Location -Path "C:\LaunchBox\Emulators\Model3\Config"
#Get-Location

#Find gun1's mouse index
$inputs = & "C:\LaunchBox\Emulators\Model3\Supermodel.exe" -print-inputs 
$gun1info = ($inputs | Select-String "mouseGUN1").Line
$gun1index = $gun1info.Substring(1,1)
$gun1formatted = "MOUSE" + $gun1index
Write-Output $gun1formatted

#Find gun2's mouse index
$inputs = & "C:\LaunchBox\Emulators\Model3\Supermodel.exe" -print-inputs 
$gun2info = ($inputs | Select-String "mouseGUN2").Line
$gun2index = $gun2info.Substring(1,1)
$gun2formatted = "MOUSE" + $gun2index
Write-Output $gun2formatted

#Read in Supermodel.ini
$content = Get-Content -Path "C:\LaunchBox\Emulators\Model3\Config\Supermodel.ini"

#Edit Supermodel.ini mouse related lines
#This assumes you have one mouse assigned per bind/value already. It will not touch any bindings to the RIGHT of the mouse text
#(Need backtick in front of capture group variable in the replacement else it won't print the value)

#Update gun1
$content = $content -replace '(InputStart1.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3" 
$content = $content -replace '(InputCoin1.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputGunX.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3" 
$content = $content -replace '(InputGunY.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputTrigger.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputOffscreen.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputAnalogGunX.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputAnalogGunY.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputAnalogTriggerLeft.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"
$content = $content -replace '(InputAnalogTriggerRight.*?)(MOUSE.*?)(_)',"`$1$gun1formatted`$3"

#Update gun2
$content = $content -replace '(InputStart2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputCoin2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputGunX2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3" 
$content = $content -replace '(InputGunY2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputTrigger2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputOffscreen2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputAnalogGunX2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputAnalogGunY2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputAnalogTriggerLeft2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"
$content = $content -replace '(InputAnalogTriggerRight2.*?)(MOUSE.*?)(_)',"`$1$gun2formatted`$3"

#Write new file
#Write-Output $content
$content | Set-Content -Path "C:\LaunchBox\Emulators\Model3\Config\Supermodel.ini"

That's probably because it's a powershell script, needs to be have the .ps1 file extension, and needs to be ran by powershell. It's not a bat file that can be run by windows command line.

I also think the very first directory at the top doesn't need the /Config part. It just needs to be pointed to the top level of the supermodel3 folder.

If that doesn't do it... do you see all of those lines that start with Write-Output....? Those will show you if it's working correctly. Look at their output in the powershell command window after you run the script. Check that each step looks correct.

Make sure to uncomment the final one at the bottom first, too. That will show you the entire ini file that's about to written. If that looks right and the gun lines look good, make sure that the file you're pointing to actually got written and matches that.

Finally, did you also edit the registry to give your guns a name? Looks like you're using mouseGUN1 and 2 if so.

Edited by Hamburglin
Link to comment
Share on other sites

Thanks for the reply Hamburglin,

I have edited the registry and set the friendly names as mouseGUN1 and mouseGUN2.

Will try it through powershell and let you know how i get on.

Mis read your original post which is why i saved it as a bat file.

Thanks for the help 

 

  • Like 1
Link to comment
Share on other sites

All works now, as you said it needed to run in powershell. Wrote a bat file to execute this and added this bat file to additional apps in game in launchbox. So all is good. Many thanks for this.

Just realized another problem, when i start the game the bat file runs, executes the powershell script, before the game starts but the game starts before the config file is written.   The easy way around this is to close and restart the game. Do you know a way to run the bat file (in additional apps) and delay the game start?

  • Like 1
Link to comment
Share on other sites

Posted (edited)
11 minutes ago, leefaster said:

All works now, as you said it needed to run in powershell. Wrote a bat file to execute this and added this bat file to additional apps in game in launchbox. So all is good. Many thanks for this.

Just realized another problem, when i start the game the bat file runs, executes the powershell script, before the game starts but the game starts before the config file is written.   The easy way around this is to close and restart the game. Do you know a way to run the bat file (in additional apps) and delay the game start?

Awesome!

So, I turned it into an executable so it could be run at windows startup. I type "shell:startup" into run and drop the executable in there.

Otherwise... I thought there was an option or checkbox to make launchbox wait for the program to finish running before launching the game. If not, you could add a sleep timer to it as well. I believe that's on the startup script autohotkey section.

Edited by Hamburglin
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...