elishacloud / Silent-Hill-2-Enhancements

A project designed to enhance Silent Hill 2 (SH2) graphics and audio for the PC. It also includes scripts to build or modify SH2 audio files (SFX, BGM and Dialog).
http://www.enhanced.townofsilenthill.com/SH2/
zlib License
596 stars 42 forks source link

[Guide] Steam Deck Guide and Unofficial Support #505

Open umbrellacorp53 opened 2 years ago

umbrellacorp53 commented 2 years ago

See here in the below thread for the SHS2EE Guide for the Steam Deck.


Hey everyone. I checked all the issues, open and closed, and I didn't see any mention of the possibility of SH2EE working on the Steam Deck. I'd love to hear whether or not you have any plans in this regard. Not sure if any of the devs have a Steam Deck or plan on getting one, but I'd be thrilled to play SH2EE on the Deck without having to sacrifice the OS and try and dual boot Windows.

I was a Q1 week 2 recipient of the SD and I've really been enjoying it so far. I was curious whether this would "just work" as a lot of games have. I have Silent Hill 2 on the Deck and installed your enhancements just to see how things go. The good news is that Silent Hill 2 - using your exe - works out of the box using "Proton Experimental", but no enhancements are active. I am able to play and use the built in controller (I believe it's emulating keyboard/mouse), but it is in a completely pre-EE state, including the audio loop bug and 4:3 aspect ratio.

When I use any other version of Proton, I've tried all of them, I either get an unresponsive white screen that hangs until I force close the game, or an instant CTD or crash to SteamOS depending on which mode I'm in. Performance is the same in desktop and SteamOS.

I'm curious if anyone has any insights as to how the project interacts with the exe and why it might not be having the intended effect.

I know my best hope is that someone in charge has a great deal of interest in the Deck or is planning on getting one themselves. That being said, I am willing to do any testing, share files, explain what's happening, post videos, screenshots, or anything else that might be helpful. This might not be something totally necessary for SH2EE, but having it run on the Deck would be a dream.

elishacloud commented 2 years ago

Does UseBestGraphics enable anything that isn't visible in the Advanced Graphics settings menu?

No, it should not. All the settings are configurable in the in-game menu. But as long as the UseBestGraphics option is enabled it will reset all the settings each time you start the game.

umbrellacorp53 commented 2 years ago

Thanks Elisha. I was starting to feel that could be the case. The only thing that throws me off is that when I run the 1.0 binary (after a handful of attempts) when it launches I have perfect performance and I am able to use everything that is enabled in the zip that I posted. Maybe that complies with the above disabled settings? I'll have to compare them.

This is I'm sure a matter of optimization and being stuck using a single core. After all, Doom Eternal runs on Ultra Nightmare settings at 800p native. That is not to be the expected performance across the board, but it has been thoroughly optimized with a massive budget. I'll try the new build in a minute and I'll keep my fingers crossed for a rewrite of the audio system. What a nightmare that has been I'm sure.

elishacloud commented 2 years ago

This is I'm sure a matter of optimization and being stuck using a single core. After all, Doom Eternal runs on Ultra Nightmare settings at 800p native.

The issue is the poor implementation that the SH2 engine has. It will use 100% of the CPU no matter how powerful it is. It has a loop that continues to use CPU time even when nothing is happening. Rather than waiting for something to need to be done it continually checks if something needs to be done. This "check" takes a lot of CPU time. It would be like this, imagine if instead of your phone ringing to tell you that someone is calling, instead you had to look at it every 2 seconds to see if someone is calling. That is what the game does.

BTW: I am not sure much about the hardware of the Steam Deck, but I think it uses the same chip for the GPU and CPU. I guess more work on the GPU reduces what can be done by the CPU and vise versa. So this game just has the worst possible case for the hardware.

umbrellacorp53 commented 2 years ago

I was just digging up the specs, because I always forget exactly. I know it shares performance on an APU but that APU has a CPU and GPU component:

"Steam Decks have a custom AMD quad-core Zen 2 APU that features eight threads, with a base clock of 2.4GHz and boost clock of 3.5GHz. It also has an RDNA 2 iGPU and 16GB of LPDDR5 RAM, which should help to future-proof the device nicely."

umbrellacorp53 commented 2 years ago

From what I've seen across quite a few games and applications, the weak point is the CPU, especially single thread performance.

elishacloud commented 2 years ago

Ok, let me know if you have other issues here. But I guess the update I gave you on this comment should work for you.

umbrellacorp53 commented 2 years ago

I'll test it out. I also am going to quickly compare it against the "crapshoot" ini and see what else might be enabled that I could get away with. I'll report back.

umbrellacorp53 commented 2 years ago

Comparing the two ini files, my "crapshoot" to the one you posted just now it's very similar. So, I just re-enabled:

d3dxto9, AdjustColorTemp, FixGPUAntiAliasing, AnisotropicFiltering. I left UseBestGraphics off, but in the settings I turned most of it back on. Can't play with the muddy textures. Most of these should probably remain off for most Deck users, but I'm going to play on the Deck's native screen and will maybe hear a stutter here or there. That's good enough for me for now.

The stuttering is far more under control than it was previously, and if I play the game on the native display that frees up a significant amount of performance. (from 1080p to 800p). It would be possible to squeeze slightly more out of the game if I could run it at a lower resolution and use the Deck's built in FSR.

Would it be possible to add 960 x 600 resolution to the game? Right now if I play on the built in screen it does not allow me to change the resolution to anything other than 1280 x 800.

elishacloud commented 2 years ago

d3dxto9, AdjustColorTemp, FixGPUAntiAliasing, AnisotropicFiltering. I left UseBestGraphics off, but in the settings I turned most of it back on. Can't play with the muddy textures. Most of these should probably remain off for most Deck users, but I'm going to play on the Deck's native screen and will maybe hear a stutter here or there. That's good enough for me for now.

👍

Would it be possible to add 960 x 600 resolution to the game?

If you have DynamicResolution enabled then the game will list all resolutions the OS supports. The reason that 960 x 600 resolution is because the OS is not advertising that resolution as supported. In other words, we already support 960 x 600 resolution if the hardware supports it.

I could add some logging to see why that resolution is not showing up, or I could create a custom build with that resolution hard coded in.

umbrellacorp53 commented 2 years ago

Ok. So there was still minor stuttering unless I dialed back the visuals, even with FSR on. I pulled up performance overlay and one CPU core was locked at 100%, well it actually said "core0" and "core1" were locked at 100%.

Then I tried the 1.0 binary one more time (I know, I know). Well, after 15 attempts it launched. Guess what? Basically all settings on, audio is better, but with performance overlay on it revealed that no cores are locked at 100%.

So that explains why the 1.0 binary was running better, although I imagine that at some point the audio will glitch since running on all cores is what causes issues on desktop PCs.

Kinda dumb but, any way to butcher the 1.1 binary to use all cores? As of now it actually runs and sounds better for me that way. I'd rather it crash 3 hours from now than be stuttery and low graphics. I have played with the 1.0 binary halfway through the apartments. So far the only issue I've faced is the obvious, inconsistent launch.

Oh and the missing resolution makes sense. Technically what happens with FSR is it let's the game run at a lower resolution but technically the display is running at the native 1280 x 800. The Deck then hooks into the game and upscales it. Devs are having to add extra resolutions, or people are adding them through ini tweaks.

elishacloud commented 2 years ago

Kinda dumb but, any way to butcher the 1.1 binary to use all cores?

Yes. If you set FixAudioThreadDeadlock = 0 in the ini file it should use all CPU cores.

Devs are having to add extra resolutions, or people are adding them through ini tweaks.

I could add an option in the ini file to allow custom resolutions to be added to the game.

Polymega commented 2 years ago

Kinda dumb but, any way to butcher the 1.1 binary to use all cores?

Keep your eye out here: https://github.com/elishacloud/Silent-Hill-2-Enhancements/issues/423#issuecomment-1098544182

I could add an option in the ini file to allow custom resolutions to be added to the game.

ResX and ResY can still be done, but you must disable DynamicResolution and type those two fixes back into the INI: http://enhanced.townofsilenthill.com/SH2/config.htm#ResXResY

elishacloud commented 2 years ago

ResX and ResY can still be done, but you must disable DynamicResolution and type those two fixes back into the INI

Yes, good point. I added an option so that if a user adds ResX and ResY to the ini file then that resolution will be added to the list as a custom resolution. With this build it will work with DynamicResolution enabled.

Here is the updated build: d3dx.zip

Just add the following to the ini file to add 960 x 600 as a custom resolution:

ResX = 960
ResY = 600
umbrellacorp53 commented 2 years ago

Weird. 960 x 600 is a 16:10 aspect ratio but it's not working. Maybe it isn't supported. This makes me wonder what resolutions people are adding to games for FSR to work. Really hard to Google this though. It's all basic articles about the Deck supporting FSR in general. Too much buzz.

elishacloud commented 2 years ago

I wonder if you try 640x400?

https://www.reddit.com/r/SteamDeck/comments/te1go2/any_way_to_force_640x400_resolution_to_get_fsr_in/

Polymega commented 2 years ago

I added an option so that if a user adds ResX and ResY to the ini file then that resolution will be added to the list as a custom resolution.

Cool feature. Should there be a safety check that this custom resolution will only be used/shown in the list if playing in ScreenMode = 1 (and 2?)? If playing in fullscreen mode (3), could this freeze/crash the game? I know it'll freeze/crash if launching the game in a resolution that isn't supported by your display.

umbrellacorp53 commented 2 years ago

Should there be a safety check that this custom resolution will only be used/shown in the list if playing in ScreenMode = 1 (and 2?)? If playing in fullscreen mode (3), could this freeze/crash the game? I know it'll freeze/crash if launching the game in a resolution that isn't supported by your display.

This was it. I'm dumb. Switching to ScreenMode = 1 fixed the issue with 960 x 600. Looks pretty good with FSR although it didn't seem to squeeze out any extra performance. Tomorrow I am going to do some more testing to try and find the sweet spot. Unfortunately I may have spoken too soon about the performance being acceptable. I had been testing all day at that point.

Also, turning off FixAudioThreadDeadlock basically instantly caused freezing and bad looping, so scratch that. Something else must be going on with the 1.0 binary. It's very mysterious. It's much more performant and has no/few audio issues. I'll post a video comparison. If only the fucking thing would launch consistently. Sometimes it opens the first try. Sometimes the 20th, but its the most stable once launched. Not sure what the original port team did to the 1.1 exe to "fix the audio bugs" but they DID NOT fix it. /rant.

elishacloud commented 2 years ago

Should there be a safety check that this custom resolution will only be used/shown in the list if playing in ScreenMode = 1 (and 2?)? If playing in fullscreen mode (3), could this freeze/crash the game?

I prefer not to limit it. I see this as an advanced feature. There may be cases where someone needs to do this in ScreenMode 3.

Actually, in the future I want to make it so that in ScreenMode 1 you can resize the window using your cursor, like you can with other windows.

umbrellacorp53 commented 2 years ago

Hmm. ScreenMode 1 and 2 both have issues with screens overlaying or flashing. Like it'll flash white between menu selections, or if I pull up inventory, close it then pause, it sometimes layers the pause screen over a sort of static image of the inventory.

elishacloud commented 2 years ago

Try enabling this option: FixGPUAntiAliasing

umbrellacorp53 commented 2 years ago

steam-14553715730156617728 (failed).log steam-14553715730156617728 (successful).log

I have two massive log files. One from a failed launch and one from a success... any idea how I can make a comparison without dying of old age? Anyone can chime in. Binary 1.0 is a lost cause but when I obsess I'm relentless.

elishacloud commented 2 years ago

Anyone can chime in. Binary 1.0 is a lost cause but when I obsess I'm relentless.

I think the issue with 1.0 binary has to do with some multi-threading issue. That was what was fixed in 1.1. I doubt there will be to much useful data in those logs.

You could try this build and see if it helps the startup of v1.0. This will set the CPU affinity to 1 during the startup of the game to help prevent thread issues: d3dx.zip

umbrellacorp53 commented 2 years ago

Well, well... It now launches consistently... with audio issues. Having cake and eating cake are mutually exclusive activities. God is dead.

Ok that's a bit dramatic. It's actually great that the issues are pretty much isolated now. Still a bit of a bummer, but it's good to know exactly what we're dealing with.

umbrellacorp53 commented 2 years ago

I will return for more testing when the audio system is rewritten or the single core utilization is sorted out. Thank you for all the hands on support.

I'm going to edit out some of my redundant comments to help anyone in the future to find the useful information in this issue post.

umbrellacorp53 commented 2 years ago

https://m.youtube.com/watch?v=RLriROG890Q

Ok. I have to bring up one last thing. Any speculation as to why the game is working without stutter or inconsistent launching when the OS is Windows 10?

Hardware is the same. Processor limitations are the same. Maybe Proton is reducing the system performance.

efigr commented 2 years ago

https://m.youtube.com/watch?v=RLriROG890Q

Ok. I have to bring up one last thing. Any speculation as to why the game is working without stutter or inconsistent launching when the OS is Windows 10?

Hardware is the same. Processor limitations are the same. Maybe Proton is reducing the system performance.

Good point, actually. I found the video a while back but this never clicked with me. Has to be something to do with Proton/Wine,

I'll try and mess around in protontricks to see if I can get something going.

efigr commented 2 years ago

Alright, got some stuff to report:

Using the default provided EXE and d3d8 files, I've managed to get the game to run via protontricks.

  1. Set d3d8to9 = 0 (the game instant crashes with this set to 1)
  2. Open up protontricks, select sh2pc.exe
  3. Select winecfg
  4. Go on Libraries tab, add d3d8 - this should say d3d8 (native, builtin) after adding
  5. Apply, launch the game.

With this, the game launches consistently, no audio issues even with the Enhanced Edition files - except for the fact that after you leave the bathroom, you get terrible performance - This happens regardless of EE files being present.

efigr commented 2 years ago

Even if we manage to fix the performance issues with this method of running the game, I'm not sure how you'd be able to distribute a version of the game's files that work without going into protontricks and doing these things. Or maybe I'm misunderstanding something here, I'm pretty new to Linux and Proton.

efigr commented 2 years ago

I think I got it working perfectly now.

I disabled RestoreBrightnessSelector, set d3d8to9 back to 1 I also grabbed the provided D3DX9 files and unzipped them into the game folder. After that, I went into winecfg via protontricks and also added d3dx9_43 and d3dcompiler_43 and both are set to (native, builtin).

The game runs and sounds perfectly fine now. How much of this is necessary apart from just disabling RestoreBrightnessSelector, I'm not sure.

umbrellacorp53 commented 2 years ago

I think I got it working perfectly now.

I disabled RestoreBrightnessSelector, set d3d8to9 back to 1 I also grabbed the provided D3DX9 files and unzipped them into the game folder. After that, I went into winecfg via protontricks and also added d3dx9_43 and d3dcompiler_43 and both are set to (native, builtin).

The game runs and sounds perfectly fine now. How much of this is necessary apart from just disabling RestoreBrightnessSelector, I'm not sure.

Awesome work! I'm going to test this step by step and see what's necessary. I'm glad you set d3d8to9 back on because most of the project requires this. The issue I was having was trying to figure out how to get proton to load additional files consistently and I think you just did it. I was trying to set launch options through Steam and searching forums but most of what I found was either outdated or unhelpful.

The biggest issue with this is if it was required for Deck users to add extra software and do extra steps. As a personal solution this is great but not for the average user.

I wonder if it's possible to create an ini that would send the same instructions to proton?

efigr commented 2 years ago

I'll also see what the minimum amount of steps are to get the game running perfectly, once we've got that we can think about how to make it easier for the average user.

umbrellacorp53 commented 2 years ago

I'll also see what the minimum amount of steps are to get the game running perfectly, once we've got that we can think about how to make it easier for the average user.

Random thought, but the EE team are working on an installer for the next update. A SteamOS check box could potentially streamline this. The installer could be run through wine or by adding it to steam as a non-steam game... Or maybe a flatpak could be added to Discover.

efigr commented 2 years ago

Full installation guide for the Steam Deck:

  1. Install Silent Hill 2

  2. Download provided Enhanced Executable 2a. Download provided Enhancements Module 2b. Download these D3DX9 dlls 2c. Extract all of these to game install location.

  3. Add sh2pc.exe as a Non-Steam Game, then right-click and select 'Properties...' 3a. Click on 'Compatability' tab, check the "Force use of a specific Steam Play compatability tool" box, then select Proton Experimental from the dropdown box

  4. Run the game once, it will crash on a white screen, but it is necessary to generate the compatdata folder for the next step(s)

  5. Install Protontricks from the Discovery Store

  6. Open up Protontricks and click sh2pc.exe from the list (Ignore any warnings) 6a. Keep "Select the default wineprefix" selected 6b. Select "Run winecfg" 6c. Click on the Libraries tab, then add d3d8 from the overrides dropdown menu, and press 'Add', then 'Apply'

  7. Go to the game's directory, find d3d8.ini and set ScreenMode = 3 and RestoreBrightnessSelector = 0

  8. Download and add the remaining Enhanced Edition files from steps 4 to 8.

  9. Play the game.

efigr commented 2 years ago

You see, I do sometimes have some issues when trying to quit the game/exit to menu or sometimes the game won't correctly fade out of an FMV, although that may need the other winecfg steps to completely fix. I will keep on testing.

efigr commented 2 years ago

Even adding d3dx9_43 and d3dcompiler_43 via winecfg it still hangs when trying to exit, which is annoying.

umbrellacorp53 commented 2 years ago

Full installation guide for the Steam Deck:

  1. Install Silent Hill 2
  2. Download provided Enhanced Executable 2a. Download provided Enhancements Module 2b. Download these D3DX9 dlls 2c. Extract all of these to game install location.
  3. Add sh2pc.exe as a Non-Steam Game, then right-click and select 'Properties...' 3a. Click on 'Compatability' tab, check the "Force use of a specific Steam Play compatability tool" box, then select Proton Experimental from the dropdown box
  4. Run the game once, it will crash on a white screen, but it is necessary to generate the compatdata folder for the next step(s)
  5. Install Protontricks from the Discovery Store
  6. Open up Protontricks and click sh2pc.exe from the list (Ignore any warnings) 6a. Keep "Select the default wineprefix" selected 6b. Select "Run winecfg" 6c. Click on the Libraries tab, then add d3d8 from the overrides dropdown menu, and press 'Add', then 'Apply'
  7. Go to the game's directory, find d3d8.ini and set ScreenMode = 3 and RestoreBrightnessSelector = 0
  8. Download and add the remaining Enhanced Edition files from steps 4 to 8.
  9. Play the game.

Wow. I'll try this right now. If we can figure out what protontricks is doing under the GUI then maybe similar code could be added to the installer.

I have also had the game hang on exit but I'm pretty sure it was intermittent. As far as the FMV issue could it be related to FixGPUAntiAliasing? It sounds like an issue I was having before.

umbrellacorp53 commented 2 years ago

To clarify, the hang on exit issue was present with the 1.1 binary using d3dx.ini. just not every time.

efigr commented 2 years ago

If we can figure out what protontricks is doing under the GUI then maybe similar code could be added to the installer.

I know that you can use protontricks via the Terminal to execute certain commands, such as: protontricks <COMPATDATA_NUMBER> <ARGs> (although you have to add protontricks to PATH) and I did stuff like this to install dependencies such as QuickTime and other files, but I'm not sure if you can use this to change winecfg properties. I'll do some more digging.

As far as the FMV issue could it be related to FixGPUAntiAliasing?

This one is fairly rare for me, and it hasn't happened for a while again. Not sure if it's really an issue. If I encounter it again I'll try editing the FixGPUAntiAliasing value.

Let me know if my thrown together tutorial works.

elishacloud commented 2 years ago

I'm glad you set d3d8to9 back on because most of the project requires this.

The only things that require d3d8to9 are the shaders below. However, the project does seem to run better using d3d9 on some systems so it is nice to have that enabled, if possible.

[SHADERS]
; Adjusts the color temperature of the overall game image to give it a slight cool tint, to match the PS2 version. Requires d3d8to9 = 1 to work. (0|1)
AdjustColorTemp = 1

; Enables SMAA anti-aliasing. Good for anti-aliasing on lower-end computers. It is recommended to disable this if using GPU-based anti-aliasing. Requires d3d8to9 = 1 to work. (0|1)
EnableSMAA = 0

; Restores the ability to adjust the brightness level in the game's options menu. Requires d3d8to9 = 1 to work. (0|1)
RestoreBrightnessSelector = 1
efigr commented 2 years ago

Doing some digging, it seems that wine stores the winecfg stuff in <WINEPREFIX>/pfx/user.reg as shown by the line: "d3d8"="native,builtin" under the [Software\\Wine\\DllOverrides] <some number> section. I'll see if changing this affects anything, if it does then it means we can just shove this line into the correct place via some sort of script.

However, the project does seem to run better using d3d9 on some systems so it is nice to have that enabled, if possible.

It's basically a requirement from my testing with this, the game ran horribly before I switched it back on.

efigr commented 2 years ago

I'll see if changing this affects anything, if it does then it means we can just shove this line into the correct place via some sort of script.

Apparently all wine does is change some settings in the registry, so it could be possible to create a key and add it to the registry.

image

Although I'm unsure of how to do this from outside regedit.

elishacloud commented 2 years ago

Try running Regedit sh2pc.reg

sh2pc.reg:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wine\DllOverrides]
"d3d8"="native,builtin"
efigr commented 2 years ago

Try running Regedit sh2pc.reg

Can't seem to get this to work, it only opens regedit.

Tried: protontricks 4126890990 regedit /home/deck/Downloads/sh2pc.reg - this just opens regedit protontricks -c "wine regedit /home/deck/Downloads/sh2pc.reg" 4126890990 - this pretends to do something

Not really sure.

umbrellacorp53 commented 2 years ago

Doing some digging, it seems that wine stores the winecfg stuff in <WINEPREFIX>/pfx/user.reg as shown by the line: "d3d8"="native,builtin" under the [Software\\Wine\\DllOverrides] <some number> section. I'll see if changing this affects anything, if it does then it means we can just shove this line into the correct place via some sort of script.

Could the "<some number>" portion be the game App ID? Steam generates an App ID for any game run through Steam, including non-Steam games.

efigr commented 2 years ago

Hold on, I think I got it. Just need to check, because I think there's a problem with the current version of Protontricks.

efigr commented 2 years ago

protontricks --no-bwrap -c "wine regedit /home/deck/Downloads/sh2pc.reg" <WINEPREFIX_NUMBER> seems to do the trick. There's an issue with protontricks atm, although I'm not sure if this is truly the cause or not.

efigr commented 2 years ago

Could the "<some number>" portion be the game App ID? Steam generates an App ID for any game run through Steam, including non-Steam games.

Looking at it again, this number seems to be different than the generated wineprefix/compatdata number.

efigr commented 2 years ago

Small correction @elishacloud, the reg file should be:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Wine\DllOverrides]
"d3d8"="native,builtin"

Then, run: protontricks --no-bwrap -c "wine regedit <path/to/reg>" <WINEPREFIX_NUMBER>

It should theoretically be able to make an installer script for SteamOS, like you mentioned @umbrellacorp53. The only thing I'm unsure of is that in order to generate the wineprefix/compatdata folder, the game has to run once. Maybe there's a way to silently run the game or something, though, I'm not sure.

After this, the only remaining issue seems to be that the game hangs on exit.

umbrellacorp53 commented 2 years ago

Small correction @elishacloud, the reg file should be:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Wine\DllOverrides]
"d3d8"="native,builtin"

Then, run: protontricks --no-bwrap -c "wine regedit <path/to/reg>" <WINEPREFIX_NUMBER>

It should theoretically be able to make an installer script for SteamOS, like you mentioned @umbrellacorp53. The only thing I'm unsure of is that in order to generate the wineprefix/compatdata folder, the game has to run once. Maybe there's a way to silently run the game or something, though, I'm not sure.

After this, the only remaining issue seems to be that the game hangs on exit.

Depending on what is actually generated in the compatdata folder it might be possible to just create one with the installer and package the files. As long as their isn't a weird licensing issue, but I doubt it if Proton/Wine can do it.

umbrellacorp53 commented 2 years ago

So are the install steps the same or would this reg file skip the step of using Protontricks?