dosbox-pure icon indicating copy to clipboard operation
dosbox-pure copied to clipboard

Handling system changes on a per-game basis

Open alondero opened this issue 2 years ago • 6 comments

A few of the games I've installed so far seemingly add system files / dlls / registry edits. What's the best way to handle this as the .sav file only seems to track changes made to the D: drive. Should I enable the changes allowed to the C: drive setting when installing these games? It does mean I'm left with artefacts of the game in the system (for example Start Menu options and Program File folders (admittedly I could delete those). Or is there a better way of doing this?

alondero avatar Jun 30 '22 21:06 alondero

I'm all ears for suggestions regarding this.

The "Discard Disk Modifications" really does throw everything away as you mentioned so it certainly can break certain games if the option is active during the installation of a game that adds or modifies files on C: or depends on Registry changes.

The "Discard Disk Modifications" option was a last minute addition because I found it just too useful for testing to be able to just kill the core without bothering to do the shutdown procedure in Windows. Before I actually corrupted a few Windows installations by doing that which lead me to add it.

It's tricky to have a mode that writes any change made to the C: drive into the .SAV file while leaving the harddisk image untouched because it would mean as soon as the first set of changes are written to that external file, there needs to be a guarantee that the harddisk image does not change ever again. It would put a lot of onus on the user without the core being able to help out... Unless maybe it were to rename the .IMG file to something like .LOCKEDIMG?

schellingb avatar Jul 02 '22 16:07 schellingb

Happy user of the ”discard disk modification” behavior here. It’s very valuable for users who maintain a set of ready to run Windows games with confidence that if it worked once it would keep working because C drive state is kept and D drive changes can also be thrown away by deleting SAV file if desired.

I wonder to what degree DBP is aware of file system changes. It might be nice to allow viewing change stats (file name) to validate that nothing important has been written to C drive as a way to ensure the game is compatible with this set up.

ckeisc avatar Jul 03 '22 16:07 ckeisc

It's certainly not space efficient, but now that sizes up to 64GB are supported in 0.9.7 i've created a 20GB Windows installation and installed all games on drive C:. Some games will always save progress to C: anyway, even when they're installed on D:, so 'Discard OS Disk Modifications' can't be used in these cases.

And this way i don't have to shut down Windows or close the core in order to play another game. If a disc needs changing then Disc Control can be used. If i want to use tools like PowerStrip while running games then it's not a problem. Obviously if the OS ever gets fucked then all that time and effort will be lost, so i'll make occasional backups of the OS image (located inside the System folder).

But having said that, this sounds ideal if @schellingb manages to do it...

It's tricky to have a mode that writes any change made to the C: drive into the .SAV file while leaving the harddisk image untouched because it would mean as soon as the first set of changes are written to that external file, there needs to be a guarantee that the harddisk image does not change ever again. It would put a lot of onus on the user without the core being able to help out... Unless maybe it were to rename the .IMG file to something like .LOCKEDIMG?

BTW I think it's far more organised having separate "DOS" and "Windows" RetroArch playlists so i've made a Windows 95/98 icon here if anyone wants to use it:

icons

Place the icons in: RetroArch\assets\xmb\monochrome\png

Then to make the "Windows" playlist appear: Go to the RetroArch\playlist folder and copy paste the current DOS.lpl playlist file and rename it to Windows.lpl. Then you can edit it with any text editor. You just need to change 'path' to the location of each games .ZIP file, change 'label' to the name of each game, and change 'db_name' from DOS.lpl to Windows.lpl.

PoloniumRain avatar Jul 07 '22 19:07 PoloniumRain

This is my way of doing it with a game that uses the registry to save game-data. I described this briefly on issue #105 however this is my new and improved version.

  1. I have created a .bat file in the autostart folder called Autostart.bat which looks like this:
@echo off
IF NOT EXIST "D:\Run.bat" EXIT
CALL "D:\Run.bat"
CLS
EXIT

It looks for Run.bat on the D:\ drive and runs it, if it doesn't exist then it just closes the window.

  1. Then I created Run.bat in the root inside the .zip file which also contains the installed game and image files. Which looks like this example:
@ECHO OFF
:: Batchfile working directory
SET wd=D:\

:: Game to launch
SET game="Program\Game studio\Game name\game.exe"

:: Change screenrelolution and color, (8=256colors, 16=16 bit, 24=24 bit)
SET screenres=640x480
SET color=16

:: Savename & extension
SET sn=Highscores
SET ext=reg

:: Regkey
SET rk=HKEY_LOCAL_MACHINE\Software\Game studio\Game name

:: Savebackup frequency (milliseconds)
SET fq=5000

:: Code starts below this line
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::Create SLEEP.EXE
IF EXIST C:\WINDOWS\SLEEP.EXE GOTO Skipsleep
ECHO Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>C:\WINDOWS\SLEEP.COM
ECHO 0DxFP,0Xx.t0P,=XtGs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_RUNDLLENTRY %screenres%x%color%

::Restore Savegame
IF NOT EXIST %wd%%sn%.%ext% GOTO Create .%ext%
REGEDIT.EXE /S %wd%%sn%.%ext%

:Run Game
%wd%%game%
SLEEP 10000

::Backup Savegame
:Tempbackup
REGEDIT.EXE /E %wd%%sn%.tmp "%rk%"
SLEEP %fq%
FC %wd%%sn%.%ext% %wd%%sn%.tmp | FIND "***">NUL
IF ERRORLEVEL 1 GOTO Tempbackup
REGEDIT.EXE /E %wd%%sn%.%ext% "%rk%"
SLEEP %fq%
GOTO Tempbackup

:Create .%ext%
ECHO REGEDIT4> %wd%%sn%.%ext%
ECHO.>> %wd%%sn%.%ext%
ECHO [%rk%]>> %wd%%sn%.%ext%
GOTO Run Game

Just change the variables above where the code starts to match your game and if everything works as it should the script will do the following:

  • It will look for SLEEP.exe and create it if it does not exist. If you already have the SLEEP.exe from the "Windows Resource Kit" you have to change the SLEEP timer to seconds instead of milliseconds.
  • Change screen settings to the desired resolution and bit depth.
  • Restore your previous savegame (Highscores.reg) to the registry. If it does not exist it will create an empty one, this is because it must have something to compare against later.
  • Run the game.
  • Now it will create a temporary backup of your desired registry-key, in this case Highscores.tmp and compare it to your previous save-game Highscores.reg (this is the one that was created before if you did not have a previous save).
  • If Highscores.tmp and Higscores.reg is the same (no new save has been written to the registry), then it will wait (5 seconds in this case) and then make a new Highscores.tmp and compare it once again.
  • If Highscores.tmp and Higscores.reg differs, it will now make a real backup (Highscores.reg) from the registry and save it to the D:\ drive.
  • It will repeat the three last steps over and over again until you close the script or close the emulator.

I'm not an expert on batch commands so if you have any tips on how to make this better please tell me. Also if your game needs .DLL files from C:\ then try to copy these to the installation directory on the D:\ drive, this works most of the time.

Here's a link to where i found out how to create SLEEP.exe from batch: "https://groups.google.com/g/alt.msdos.batch.win9x-me/c/CdvIKcyD368" You need SLEEP.exe to make a delay between some commands, else it will create a new backup one after another in a rapid pace and slow down your disc and emulation, maybe even crash the system.

Stellan90 avatar Jul 16 '22 15:07 Stellan90

I wonder. That kind of thing could be done by the emulator at the start (before boot) and before quit, instead of having a thread, if the emulator has access for reading and writing to the OS drive before boot and after quit (i suppose, may be wrong and it thinks the registry file is 'corrupt' if you do that).

I know it couldn't be done for everything and it's the rare game that saves user data like frigging savegames into the registry, but it could be option for the few that do that insanity.

i30817 avatar Jul 19 '22 20:07 i30817

The emulator could be changed to read from or write to the OS C: drive. Reading or even modifying the Windows Registry though I don't think is possible. Copying or overwriting the entire registry storage might be possible, I think it's just one or a few files for the early versions of the registry.

Though the question is, what should be written? If we can come up with a method that is powerful (so it works for various scenarios) and easy to use (so people can use it without it being as complex as writing custom scripts) then I'd be happy to implement something cool. I just haven't come up with an idea yet...

schellingb avatar Jul 28 '22 18:07 schellingb