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
597 stars 42 forks source link

Side effects playing the game at 60 FPS #28

Closed Polymega closed 1 year ago

Polymega commented 6 years ago

You can use this save folder to reference some of the framerate issues mentioned below. Go to <path-to-game>\data\save\ and make a backup of your Folder 01 folder within here. Then, completely replace your Folder 01 folder with this new one.


Important (noticeably affects audio, visuals, gameplay)

Other

FMVs


To help visualize the to-do list a bit easier:

Issue 1.0 Fixed? 1.1 Fixed? DC Fixed?
The fog speed moves twice as fast (too fast). :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
For the Eddie boss rooms, the fog that slowly pours out the holes/vents in the walls is affected by the 60fps fog speed fix (right above). It will create a near-motionless "blanket" of fog on the wall. This would need its own, special adjustment. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The water animates/moves twice as fast. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The physics of the bullet casings dropping from the handgun and shotgun wig out. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The "Ritual" prison monster's footsteps go crazy fast. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
AudioClipDetection can crash the game when playing in 60 fps. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The animation process whenever James transcribes notes onto his map is twice as fast (too fast). :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The intensity/effectiveness of the motion blur is reduced by half. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
PS2CameraSpeed moves twice as fast (too fast). :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The visual range of the Lying Figure's spray attack is twice as long. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The visual range of the Hyper Spray's spray is twice as long. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
Enemies that hold you in place for attacks do twice as much damage. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The flashlight's light turns on and off twice as fast. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The flashlight dies out twice as fast in the prison bug room. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The low health indicator flashes twice as fast. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The flames in Angela's staircase move twice as fast, and the "animated lights" in this room (such as seen on James/Angela) move twice as fast. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The water drains twice as fast at the end of the RPT Apartment boss fight. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The water rises twice as fast when the Alternate Hotel elevator door opens. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
The time in which the game shows the pre-cutscene death animation of Eddie is cut in half. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
For the Eddie boss room, the physics of when the hanging meat is hit moves the meat twice as much/far. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
FMV playback is affected if FMVs are saved as 60 fps. :heavy_check_mark: :heavy_check_mark: :heavy_check_mark:
AeroWidescreen commented 6 years ago

Honestly, this is going to require a lot of patching and research and I'm not sure I can fix everything either. If I were to attempt this I would need help.

PS2CameraSpeed doesn't work, as you already know, but gosh it'd be nice to have a functioning version for 60 FPS, as well. It's almost unbearable to go back to the PC version's vanilla camera speeds after being spoiled by this mod.

The bullet casing SFX wigs out, as you already know. This affects the handgun and shotgun.

The flashlight dies out very quickly in the prison bug room.

I've fixed these during my own private testing.

The "Ritual" prison monster's footsteps go crazy fast.

I know for a fact I can't fix this. I spent all day trying and found nothing. I thought maybe this was the only problem remaining, but with the other things you've listed I'm afraid I'm going to have trouble fixing those as well.

There's a framerate variable the game uses to determine the speed of many, many things, but apparently the ritual monster isn't one of them.

Polymega commented 6 years ago

Oh, for sure. I didn't mean to overwhelm you with this but wrote this all down for posterity for you or anyone else curious to know how 60 FPS affects things. TBH work on this ought to be lower on the list anyways.

filipinowhiteboy commented 6 years ago

Do you know of a way to remove the shell casing sound effect? For me, it's the only offender when playing that 60 fps. I've tried editing the sddata.bin file myself and I found the shell casing sfx in question (It is sddata349.wav which not noted in the audio mapping so here you go). I tried deleting the file first before merging the rest into a new sddata file. But the sfx trigger for the shell casing was moved to the next available file, (sddata350.wav) which is a chainsaw sound effect. I tried deleting the contents of sddata349.wav while leaving the file to be merged but the problem still persists. Any idea what to do?

Polymega commented 6 years ago

Yes, if you delete the file all other sounds are moved over to fill the space. So sddata350 then becomes sddata349 in the game, sddata351 becomes sddata350, etc.

You simply need to create a silent .WAV file and save it out as sddata349.wav. Be sure you save it as a mono (not stereo) wave file. The length of the silent audio file shouldn't matter here.

Then, repeat the process of re-packaging the sound files to a new sddata.bin and you're good to go.

filipinowhiteboy commented 6 years ago

I see. I thought deleting the content in sddata349.wav and saving it as a blank wav file would be enough though. Am I doing something wrong?

Polymega commented 6 years ago

I thought [...] saving it as a blank wav file would be enough though

Are you just renaming a blank .txt to .wav or something? That would be the problem why, then. You'll need an actual, legit silent audio .wav file for it to work.

You can open a short .wav file in Audacity, select the track image, click the "silence" button image, and save it out as sddata349.wav. Just be sure to save it as mono and not stereo.

Edit: Here's a roughly 1-second silent .wav file for you to use: sddata349.zip

Polymega commented 6 years ago

I thought [...] saving it as a blank wav file would be enough though

Oh, I think I understand now. You deleted the entire track of sddata349.wav and saved it out as-is? If so, there's no track for the game to play then, so it won't work. There needs to be a track for sddata349. So make it a second or two of silence. When you open the track in Audacity, you need to see some sort of track, if that makes sense.

Edit: Here's a roughly 1-second silent .wav file for you to use: sddata349.zip

filipinowhiteboy commented 6 years ago

I see. Thank you for specifying....and for the instruction on how to create a silent wav file. ^_^

EDIT: Works like a charm! thanks for telling me what to do. Like I said, I find the shell casing sound effect to be the only problem. The other issues you described seem rather negligible. The game is quite playable at 60 fps after the sfx is removed

kartur commented 6 years ago

This is to be expected due to my aging GeForce GTX 670 FTW

I have a GTX 1060 and expierience framedrops when playing with 60fps, also in SH3. I don't think it's really our hardware not able to keep up with a 15 years old PC game. :)

Polymega commented 6 years ago

True. :) I can't speak for SH3, but I know forcing SH2 PC to run on a single core doesn't take advantage of multi-core processing to help with performance. But we must run the game on a single core to alleviate the severe sound loop bug.

Keith94 commented 6 years ago

I'm curious to see the fixes Aero has planned for us. 60 FPS is the only way to play :)

Polymega commented 6 years ago

There's potential for some more really nice fixes down the line thanks to Aero, Elisha, Bigmanjapan, and others. :)

kartur commented 6 years ago

Actually I think I have to revoke what I said earlier. Last time I tried playing with 60fps was one or two years ago, now (perhaps due to the opengl-wrapper?) it actually runs pretty smooth (tested for about 10min).

CPU-Load on Core 0 is always 100%, it doesn't matter if 30 or 60 FPS GPU-Load is 10-25%

desktop 2018 08 31 - 23 56 14 01 mp4_snapshot_00 41_ 2018 09 01_00 13 49 desktop 2018 08 31 - 23 56 14 01 mp4_snapshot_02 27_ 2018 09 01_00 14 18 desktop 2018 08 31 - 23 56 14 01 mp4_snapshot_04 16_ 2018 09 01_00 14 53

filipinowhiteboy commented 6 years ago

I've been getting fairly consistent FPS myself. The streets are the only areas where the the fps....doesn't drop but hitch for a fraction of a second and it doesn't happen often.

OregonPacifist commented 6 years ago

Can anyone link the edited sound file (replacing the bullet casing sound with silence) on here for easy access? I’d love to be able to play either 30 or 60 fps with as little trouble as possible.

filipinowhiteboy commented 6 years ago

OregonPacifist, Polymega posted a link to the edited sddata file a few comments up. Just remember to back up your original sddata file before using it.

OregonPacifist commented 6 years ago

@filipinowhiteboy thanks for the reply. I was looking for an already edited version of sddata.bin. The only file I saw that was posted is a silent sddata349.wav file.

filipinowhiteboy commented 6 years ago

@OregonPacifist Oh! I see. Give me a second, I'll link mine.

EDIT: Here you go https://drive.google.com/drive/folders/10NfcCB73bsNDkchRLHAY8B7_myTcBIwd?usp=sharing

Now remember, You want to backup your old sddata file in case you change your mind and want to keep the sfx and play at 30fps. Also, the sddata file I sent you, must be placed in the sh2e/sound folder. This file will NOT work with the main sound from the data folder.

OregonPacifist commented 6 years ago

@filipinowhiteboy Thanks for the link. I haven't used any audio editing software before and don't have enough time to learn it lol. I will be sure to save the two different versions of the file separately in case I want to play 30 or 60 FPS. You've just made my day!

filipinowhiteboy commented 6 years ago

@OregonPacifist You're welcome. Let me know if there's a problem.

DonelBueno commented 4 years ago

Are all these issues still present in the latest release when playing at 60 fps?

filipinowhiteboy commented 4 years ago

@DonelBueno Yes, it is. I think they might have updated the enhanced sound file recently. I might have to make a new version of the sdata file if they did.

Polymega commented 4 years ago

Besides any issues checked off, they are still present in the game, yes.

illusion0001 commented 3 years ago

I would like to have some sort of a starting point to improve and try to fix the various issues that is caused by high framerates, @AeroWidescreen would you be able give me some help with that? Also in need of save files to diagnose the various issues. As a sidenote, is there a way to boot the game with a breakpoint set on a specific instructions on startup?

AeroWidescreen commented 3 years ago

Framerate Integer Add FPSLimit = 60 to d3d8.ini to enable 60fps.

// Default: 30(int)
0x4F6CA3 0x1E

Framerate Float

// Default: 30(float)
0x6388A8 0x41F00000

Frametime Float 1 / FPSLimit = Float

// Default: 0.03333333507(float)
0x6BC194 0x3D088889

*Flashlight Speed Integer 2 FPSLimit = Integer**

// Default: 60(int)
0x50A5BD 0x003C

Fog Speed Assembly Code

0x489120 call FogSpeedCodeCave

FogSpeedCodeCave:
fld dword ptr ds : [0x932D48] // Variable Frametime Float
fdiv dword ptr ds : [ ] // Divide by 2(float)
ret

Bullet Shell Physics Assembly Code

0x4F0EAC call BulletShellPhysicsCodeCave
004F0EF5 call BulletShellPhysicsCodeCave
0x4F0F12 call BulletShellPhysicsCodeCave
0x4F0F23 call BulletShellPhysicsCodeCave

BulletShellPhysicsCodeCave:
fld dword ptr ds : [0x932D48] // Variable Frametime Float
fmul dword ptr ds : [ ] // Multiply by 2(float)
ret

It appears that most of the framerate problems can be attributed to this frametime variable:

sub_447830:
0x447830 fld dword ptr ds : [0x932D48]
0x447836 ret 

But changing it at this location just causes more problems. This is why I have separate code for the Bullet Shell and Fog Speed.

And the remaining issues might be constants that need adjusting, like the Flashlight Speed. This is all I know, this is all I have.

Polymega commented 3 years ago

Hi @illusion0001,

Thanks for taking an interest in this project and wanting to look into high framerate issues. Looks like Aero has you covered with all his research on the matter. Here's a link to general save points throughout the entire game:

http://www.igotaletter.com/temp/sh2pc/General_Saves.zip

Completely replace your <path-to-game>\data\save\Folder 01 with this Folder 01. If you need more specific/customized save files directly at the various high framerate issue spots, let me know and I can make some for you.

Any other questions please ask and we'll be happy to do our best to assist. Thanks again

illusion0001 commented 3 years ago

@AeroWidescreen sub_447830 has over 320 references, yikes. tried out some of the codes and they do work, any ways I could track other issues down or is it just testing if x2 or div2 of frametime and replacing existing subroutine calls the only way?

Since 2.0f ptr is missing, I used 0x52b6c9 instead.

Frametime_Division2
FLD  dword ptr [0x932D48]
FDIV dword ptr [0x52b6c9] //40000000 2.0f
RET

Frametime_Multiply2
FLD  dword ptr [0x932D48]
FMUL dword ptr [0x52b6c9] //40000000 2.0f
RET 
AeroWidescreen commented 3 years ago

any ways I could track other issues down or is it just testing if x2 or div2 of frametime and replacing existing subroutine calls the only way?

That's the only way I know of. It's extremely tedious, which is why I haven't gotten really far with it. I was hoping someone more skilled would know a better way, but I guess it isn't that easy. ☹️

AwesumSource commented 2 years ago

Hey @Polymega, I tried to send you an email but I think you didn't see it, so I was thinking about something and I'd like to hear some input on it. I believe it's not very common to have framerate that varies depending on the "context" of the game but I was remembering how The Legend of Zelda Ocarina of Time runs at 30FPS on pause menus (item seleciton, map, equipment screen etc), 60FPS on the file select screen, and otherwise the game runs at 20FPS. Do you think something like that could work for SH2? As in, the framerate changes to 60 when you are in the memo list, map, inventory, full screen puzzles, save screen, etc.

SH4 does something a little odd which is that it runs at 30FPS, but when you enter the hole to move between the "dream dimension" and room 302 there's a very short cutscene of you "crawling" into/back out and it runs at 60 (at least I could swear it runs at 60 because it's a lot smoother than everything else and it's not ore-rendered either), and it really makes those transitions stand out.

Like, obviously it wouldn't make that big of a difference but I think it could be pretty kino as a stop-gap between having 30FPS only and having the option of playing on 60.

Btw, I really appreciate the work the team has put on SH2EE. Thank you for your hard work.

Polymega commented 2 years ago

Hi @AwesumSource,

I sent you a response the other week but it might have not gone through. I'll copy + paste my message here:


About 60 fps: The Xbox version of SH2 actually does this. It has 60 fps in the inventory screen (and I also think in the save/load screen), but is 30 fps everywhere else. I'm still holding out hope that we can properly fix most/all 60 fps issues so we can simply have high framerate throughout the entire game, but this has been a "compromise" that I have kept in my back pocket if it turns out we can't address most of the high framerate issues. To answer your question specifically: It's something I have planned to bring up if all other options fail for a 60 fps patch.

[...]

Thank you for reaching out to me and sharing your thoughts! I'm confident that a really good 60 fps solution will come at some point. It might not be soon, but it'll come in due time, I'm sure. :)

AwesumSource commented 2 years ago

Hi @AwesumSource,

I sent you a response the other week but it might have not gone through. I'll copy + paste my message here:

About 60 fps: The Xbox version of SH2 actually does this. It has 60 fps in the inventory screen (and I also think in the save/load screen), but is 30 fps everywhere else. I'm still holding out hope that we can properly fix most/all 60 fps issues so we can simply have high framerate throughout the entire game, but this has been a "compromise" that I have kept in my back pocket if it turns out we can't address most of the high framerate issues. To answer your question specifically: It's something I have planned to bring up if all other options fail for a 60 fps patch.

[...]

Thank you for reaching out to me and sharing your thoughts! I'm confident that a really good 60 fps solution will come at some point. It might not be soon, but it'll come in due time, I'm sure. :)

Just making sure to let you know: I did receive the response and already replied, sorry for the confusion.

Thank you for your attention!

illusion0001 commented 2 years ago

Thanks for the saves, I will dedicate my time into this soon.

Polymega commented 2 years ago

Thanks, illusion. ❤️ We're here to assist. And for this one:

The intensity/effectiveness of the motion blur is reduced by half.

^ Aero_, Bigmanjapan, and I spearheaded the restoration of these post-processing effects and maybe to fix this for 60 fps might be as simple as multiplying or dividing the values we've used by two. We can look into that in the future.

illusion0001 commented 2 years ago

Instruction trace makes things slightly easier, water seems to use some shared subroutine https://youtu.be/EHGDuuuELp8

Polymega commented 2 years ago

Awesome to see you starting to dip your toes into this!

I should mention that, for this particular save for testing water, you'll need to enter the blue door in front of you and fight Pyramid Head. Six or seven handgun shots should trigger the siren. Once you hear the siren, avoid Pyramid Head and wait for him to walk down into the water and a cutscene will happen of the water draining. Both the water's "idle" animation (which you can also study in save Data 58, Data 59. and Data 60) and the animation of it draining (found in Data 57) is what moves twice as fast.

It wasn't possible to put a save in this room, which is why I put it in front of that door.

illusion0001 commented 2 years ago

I traced 00447830 for water but to no avail. here's two missing bulletshell subs 004F0EB1, 004F0EFA

Polymega commented 2 years ago

Oh, a very useful page to bookmark: https://github.com/JokieW/SilentHillDatabase/blob/master/SH2/SH2%20PC%20memory%20addresses

If you find any other notable addresses please add to the list.

Polymega commented 2 years ago

The low health indicator flashes twice as fast.

It looks like this can be fixed by changing 007F3E10 float from 0.0333f to 0.0165f.

I'm just not sure if this address affects other things in the game. If someone smarter than me could confirm this, that would be a great help.

Polymega commented 2 years ago

The final boss tentacle attack does twice as much damage. This could make her unbeatable in certain situations.

  • This might hold true for other enemies that hold you until you break free, such as Flesh Lips or Abstract Daddies.

I have yet to find the damage multiplier for when enemies hold you in place, but 01FB80D4 float acts as a timer for how long they will hold you in place. At least, for Beginner Action. I tried monitoring this address to trace the damage multiplier from it, but have been unsuccessful so far. Maybe this address can lead someone else in the right direction?

Polymega commented 2 years ago

The flames in Angela's staircase move twice as fast, and the "animated lights" in this room (such as seen on James/Angela) move twice as fast. The water animates/moves twice as fast.

I believe I found the address to fix this. Check it out here.

To slow down the water and flame animations: Change 006BC194 float from 0.0333f to 0.0165f.

To slow down the animated lighting effects in the Alternate Hotel staircase fire room: Change 0070AE40 float from 0.0005555444513f to 0.00027777222565f.

AeroWidescreen commented 2 years ago

I'll take a look at this later today.

AeroWidescreen commented 2 years ago

Change 006BC194 float from 0.0333f to 0.0165f

Angela staircase flames / water animation. Okay... there are 54 references. Just standing in the staircase I get 5 instructions from 5 different functions that are using this for the flames. And then leaving this room, I get another 5 instructions that are using it for the water.

I think it's safe to change this. My reasoning is that every instruction listed is fadd dword ptr [006BC194], and each one seems to do the same thing: it loads a variable from the source, adds the 0.0333f to that variable, then overwrites the variable at the source. It's probably all used for animation speed.

Additionally, all 54 references are within a small address range. From 004CB762 to 004EC4DF. This means the code is fairly close to each other. This usually isn't the case for global variables that shouldn't be directly changed, as those are typically used by a large variety of functions throughout the exe.

With that being said, I could be wrong. Sometimes there are two or three instructions that break something, even though the rest are fine. I suggest doing a playthrough with the value set high to ensure it's not changing anything we don't want to be changed. But my guess is that it's fine.

It looks like this can be fixed by changing 007F3E10 float from 0.0333f to 0.0165f.

Health indicator flashing speed. This has 3 references that are all from the same function. This is absolutely safe to change.

matheusvb3 commented 2 years ago

I tried to find the address for the water height in the apartment staircase but I couldn't, I thought it would be a simple float being subtracted from it every frame which could then be halved. Does 60FPS affect the part in the hotel where the elevator door opens and the water floods in? If so, these may share a similar routine/function (not sure what it's called).

Polymega commented 2 years ago

Does 60FPS affect the part in the hotel where the elevator door opens and the water floods in?

It does. I've included that beside the water draining twice as fast on the RPT apartment fight. There's a likely chance that if one can be resolved it will also affect/resolve the other.

Polymega commented 2 years ago

In regards to the Lying Figure's spray being twice as long (too long), I did find that sh2pc.exe+A4247 - mov [esp+7C],3F800000 is the relative position of the spray to the Lying Figure. Change 3F800000 (1.00) to something minor like 3F7D70A4 (0.99) to see the spray being positioned askew from the creature. Perhaps this memory region has what we're looking for?

illusion0001 commented 2 years ago

Are you sure this addr is correct? @Polymega image

Polymega commented 2 years ago

It was... Until I relaunched the game and went back to this address for this instruction. I have no clue what happened. :-/

I found something else possibly relevant: 01DB96AC and 01DB96A8

Monitor these addresses as you spray the Hyper Spray or have a Lying Figure spray at you. It's four instructions that become active. Maybe these can be traced? To get the Hyper Spray in your inventory, add 01F7A7E0 to your list and set its value to 0xFFFFFFFF. When I get home I'll show you a nifty/easy way to test for the Lying Figure spray.

illusion0001 commented 2 years ago

Found instruction for it 004a4247 yours have a typo, will investigate this function

Polymega commented 2 years ago

Thanks for figuring that out. I really thought I was going crazy for a second. 😅 004A4247 looks to only be relevant to the Lying Figure's spray and not the Hyper Spray's spray, whereas the instructions for 01DB96AC and 01DB96A8 look to be shared between the two. I'd maybe investigate the latter two addresses before the former.

illusion0001 commented 2 years ago

Motionblur activation function 00478290, 2 is blur, 1 and 0 is blue ghosting