Layers of Fear (2016)

Layers of Fear (2016)

View Stats:
This topic has been locked
zment May 21, 2016 @ 5:57pm
A thing about the stutter... [Stutter fix; GOG and Steam]
Alright, it seems people are still experiencing the stutter to some degree, and are finding this thread when trying to fix it. THIS DOESN'T WORK ANYMORE!

This fix was for the version before the Inheritance DLC patch that came somewhere around fall 2016. The patch is incompatible with the new version. As the patch that came at the same time as the Inheritance DLC used one possible method to fix the issue, it shouldn't be an issue anymore for most of the people who experienced the stutter before. Unfortunately it seems it hasn't worked for everyone.

Either way, this patch doesn't work anymore, and as such, I'll remove the links. Other than that, I'll leave the post as it is, for posterity's sake, if for nothing else. Maybe it has some info the devs might find useful in fixing the stutter for everyone involved.

--------------
Update 6
--------------

EDIT:
What does this fix?
- Horizontal mouse sensitivity being less than vertical mouse sensitivity
- Mouse stutter when looking around
- Movement stutter when moving backwards or forwards or strafeing
- LastFox77 also reported tearing was lessened (if not completely gone) with this patch, although it should only affect that tangentially

PATCH!

First things first, a disclaimer.

I CANNOT BE HELD RESPONSIBLE FOR ANY AND ALL DAMAGES USING THIS EXE MIGHT RESULT IN, INCLUDING BUT NOT LIMITED TO COMPUTERS BREAKING, BANK ACCOUNT STOLEN, WIFE DIVORCING OR THE UNIVERSE ENDING.

...that said, I'm pretty sure none of that happens just by using this executable.

Using VPatch (http://www.tibed.net/vpatch/) I created an exe file that can be used to patch the game according to the changes I made to the game's main dll. Thanks to the devs I got my hands on a GOG version of the game, and have provided a patch for that version as well. Download the version appropriate for you:

[Link removed: doesn't work for the newest version]

[Link removed: doesn't work for the newest version]

To use it, navigate to the game's folder. (Steam Library -> Right-click on game -> Properties -> Local files). Then open Layers Of Fear_Data -folder, and go into Managed folder. Copy the VPatch.exe to this folder. From there, Shift-Right-Click anywhere on the window except a file, and select Open command prompt here.. from the context menu.

Now you need to make a copy of the file we are going to patch, as VPatch can't write in-place. You also get a backup of the modified file so that's a good thing.

copy Assembly-CSharp.dll Assembly-CSharp_dll.bak

Then just patch the dll with
VPatch.exe Assembly-CSharp_dll.bak Assembly-CSharp.dll

[EDIT: It seems the call the provided exe you might need to type the .exe to the end of the command as well, and not just the name of the file. Instructions fixed to reflect that. Although when I tested it both ways worked for me - even though the VPatch help file states this as well.]

And now the game shouldn't experience stutters anymore. I hope I got it, since I don't have anymore ideas on how to fix it!

The patch employs the mouse stutter fix and the proper manual extrapolation fix, but not the workaround fix by increasing the logic/physic FPS. If you are unsure about running arbitrary exes created by random strangers from the internet, ask for the videos/tutorials on how to do this yourself, and I shall record some videos. As my time is limited, I decided to just do the patch and leave it at that... unless people want the videos as well, if for nothing else than to learn how to do this stuff?

Also, if you decide to try this out, please give me some feedback on whether or not this actually works for you. If the stutter you have experienced is indeed the same stutter I identified, it SHOULD fix that. But I can't be sure, as some don't even see the stutter, so this is a highly subjective area (even if I know for a fact that there is a syncing problem.)

Now off you (and I!) go enjoying the great game that we know Layers of Fear is (Kudos BT and Aspyr, the game's awesome!) all stutter-free!

QUICK EDIT: Oh, and this still might break something from the game. It SHOULDN'T, but as I'm going about this from the wrong end (ie. I'm not the developer of the game and I don't have access to the source code), I might have missed something on how the game is designed. As far as I know and have played, it doesn't break anything, though, if that means anything. If you are inclined to try this patch, please give feedback on whether it breaks something or not. OH, and this actually fixes the less sensitive horizontal mouse movement as well. At least on some cases, I think.

--------------
Update 5
--------------

Oh my. My idea about injecting a gameobject to the hierarchy between the rigidbody and camera objects and extrapolating the position manually in the graphics update actually worked! And nothing seems to be broken, not even headbob! I'll try to find time to prepare either videos or tutorials with pictures on how to fix it yourself by either the quick fix workaround way or the proper fix (which is a bit more complex to do). Also, if I come up with a way to patch the dll with a patch file, I'll be sure to include it in here. Would be easier than hitting the code yourself.


--------------
Update 4
--------------

No objections from the devs yet, so I'll go ahead and start preparing an info package on how you can fix the stutter yourself. It's not straightforward, so I'll try to come up with an alternate, easier way to do it, but I can't really offer the modified dll itself, as that's the property of the developers and publishers. Maybe some patch file thingy? We'll see.

I tested some stuff out too, and I managed to "fix" the underlying problem itself as well. As Unity's own rigidbody extrapolation (or interpolation for that matter) worked only sporadically, I tried manually extrapolating the position of the camera. The stutter was gone, but so was the height differential as well as camera bob. So this is definitely not something simple. I could try injecting a gameobject to the hierarchy between the rigidbody object and the camera object, and have that injected object function as the extrapolation position, but haven't yet had time to try it out.

In the meantime, I'll post the steps to the workaround this week at some point (perhaps a video might be easier to follow?), which should alleviate the problem quite a lot, and possibly some easier way to apply the fix than just manually following complex directions. :D

Also, I just want to reiterate that I do this for fun and to help people enjoy the game, as for some the stutter is so prevalent that it prevents them from enjoying it. As I understand the problem, the problem is present in every computer, as it is not really a performance issue per se, but more an issue in synchronizing game logic/physics updates with graphics updates, and with vsync on and very unvariable framerate the problem is so small that some don't even see the stutter (which I can assure you is there, even though I belong to the set of people who don't mind it). Also, as I'm not the developer of the game, they have every right to pull the plug and tell me to stop what I'm doing. I'd ask though that they wouldn't - what I'm doing is a service for everyone (and free at that!). If however you do decide to pull the plug, please take to heart what I have found out about the stutter. For some players this is a gamebreaking "bug" (not a programming bug per se, actually, it's more of a design decision that is hard to change at this point of the development cycle).

--------------
Update 3
--------------

I managed to find a combination of settings that REALLY make the stutter prevalent. By hitting the lowest graphics quality and lowest resolution and disabling Vsync, the stutter was so prevalent that playing was impossible. After comparing the original with my modified one, I have to say I must be on to something, as the stuttering was nearly completely if not completely gone. Will at least make a video about it, but I'm gonna wait until next week to post a step-by-step on how you can fix it, so that the devs have time to react to this and tell me not to do it if they don't feel comfortable with me posting a workaround to the stutter problem. It's still not easy to do, but anyone can do it though.

--------------
Update 2
--------------

It might be possible to alleviate if not completely fix the stutter by setting the player characters rigidbody interpolation to either interpolate or extrapolate. I shall investigate when I have more time...

--------------
Update 1
--------------

As suspected there are a lot more tie-ins to the physics engine than I hoped. To really fix the issue, there would need to be some separation of first person camera and physics elements of the player, and I'm not quite sure that would be something feasible with reverse engineering. Nor warranted. As I understand, the devs gearing up for an update for the judder/stutter, which should fix it. I hope it does, even though I can manage the game well enough with my own quick fix.

In the meantime, my workaround is to increase the physics update interval to a humongous amount (4x fps) to ensure smooth movement, and disable the mouse lookaround tie-in to physics. Smooth as almost-butter.

I'll be glad to detail how I did it so others can do it as well, but I'll wait a while in case the devs decide it's not something they want out in the open. As a developer myself, I understand hitting the code like this is not something liked much upon (although I've never had a problem with people peeking my code). So, I'll come up with the details in a few if people want to know how and if the devs don't oppose to it. In the meanwhile, all you need is ILSpy, Reflexil, and know-how of the Unity game engine.

Oh, and btw, managed to get some playing time as well, and it's looking (and feeling!) good! Very good atmosphere and got a few scares already as well.

--------------

Now, just a quick disclaimer: I'm not involved in any way with the developers or publishers, and to be honest, the judder doesn't bother me much, even if it is noticeable. However, being a developer myself, I'm prone to get interested in bugs that I could conceivably find in my own work. Bugs that I would need to fix.

So I gathered why not try to fix this thing. Armed with ILSpy and Reflexil (devs, I know you might not appreciate me jumping into the code, but this is for a good cause!) and with an inkling that it might have something to do with coupling the movement code to the physics update, I set out to prove myself right.

And right I was. If I forced the fixedDeltaTime to 0.005f (which is the equivalent to 200 FPS), the movement is smoother, although the judder (or microstutter) is not still completely gone. If I set the fixedDeltaTime to 0.1f (which is the equivalent of 10FPS) it is absolutely certain the movement is done in the physics update.

Setting the fixedDeltaTime to 0.005f does help a lot with it. However, as I only played it briefly, I have no idea what effects it would have on performance or physics itself (or if the game even uses physics much). Also, as it is mostly always out of sync of the frames themselves, it will always stutter a bit however smooth it is. You COULD try setting it to 60 FPS (0.1667f) and use Vsync. Would only work on 60Hz though. Or if you would set it to your monitors refresh and use Vsync. However, that would be an ugly workaround and might not help that much, if anything else, it would need testing.

Best thing would be to uncouple the movement from physics to graphics update and make it framerate independent in there using deltaTime to it's intended use. However, that might have implications to other parts of the game, depending on how much the game uses the physics engine (which could be lots, even though there would not be lot of physics-based gameplay). As I said, I'm not the developer of this game. This is probably not an easy issue to solve at this point in the development cycle.

If anyone is interested, I have the time, and the devs don't object, I could go deeper into the code and try to find out if it's an easy fix (ie. just change updates to be frame-based instead of physics-based) or not. Heck, I probably will anyway, but if the devs object, I'm not gonna post anymore about my findings.
Last edited by zment; Dec 20, 2016 @ 9:17pm
< >
Showing 1-15 of 126 comments
peter.tron May 22, 2016 @ 8:26am 
your efforts are much appreciated! hopefully they won't mind.
im_gema May 22, 2016 @ 8:33am 
Thank you for doing this
an@rk1 May 22, 2016 @ 10:55am 
Wow. Glad to hear of your research. Hope the devs won´t mind and all comes to a Happy End. !!! Maybe it can help their efforts too and it will find a way into a future patch..
Last edited by an@rk1; May 22, 2016 @ 10:59am
Stutter not Judder

:p
zment May 22, 2016 @ 3:59pm 
@Snake Plissken indeed, the terming was not quite correct when I first made the post. Fixed, at least the topic.
You're a good man, and excellent work on the thorough investigation you have done
All this timely effort can only help the Devs imo, so good on you for doing it

:sadgoo:
zment May 24, 2016 @ 2:53pm 
PATCH!

First things first, a disclaimer.

I CANNOT BE HELD RESPONSIBLE FOR ANY AND ALL DAMAGES USING THIS EXE MIGHT RESULT IN, INCLUDING BUT NOT LIMITED TO COMPUTERS BREAKING, BANK ACCOUNT STOLEN, WIFE DIVORCING OR THE UNIVERSE ENDING.

...that said, I'm pretty sure none of that happens just by using this executable.

Using VPatch (http://www.tibed.net/vpatch/) I created an exe file that can be used to patch the game according to the changes I made to the game's main dll.

https://dl.dropboxusercontent.com/u/2057069/LayersOfFear/VPatch.exe

To use it, navigate to the game's folder. (Steam Library -> Right-click on game -> Properties -> Local files). Then open Layers Of Fear_Data -folder, and go into Managed folder. Copy the VPatch.exe to this folder. From there, Shift-Right-Click anywhere on the window except a file, and select Open command prompt here.. from the context menu.

Now you need to make a copy of the file we are going to patch, as VPatch can't write in-place. You also get a backup of the modified file so that's a good thing.

copy Assembly-CSharp.dll Assembly-CSharp_dll.bak

Then just patch the dll with
VPatch Assembly-CSharp_dll.bak Assembly-CSharp.dll

And now the game shouldn't experience stutters anymore. I hope I got it, since I don't have anymore ideas on how to fix it!

The patch employs the mouse stutter fix and the proper manual extrapolation fix, but not the workaround fix by increasing the logic/physic FPS. If you are unsure about running arbitrary exes created by random strangers from the internet, ask for the videos/tutorials on how to do this yourself, and I shall record some videos. As my time is limited, I decided to just do the patch and leave it at that... unless people want the videos as well, if for nothing else than to learn how to do this stuff?

Also, if you decide to try this out, please give me some feedback on whether or not this actually works for you. If the stutter you have experienced is indeed the same stutter I identified, it SHOULD fix that. But I can't be sure, as some don't even see the stutter, so this is a highly subjective area (even if I know for a fact that there is a syncing problem.)

Now off you (and I!) go enjoying the great game that we know Layers of Fear is (Kudos BT and Aspyr, the game's awesome!) all stutter-free!

QUICK EDIT: Oh, and this still might break something from the game. It SHOULDN'T, but as I'm going about this from the wrong end (ie. I'm not the developer of the game and I don't have access to the source code), I might have missed something on how the game is designed. As far as I know and have played, it doesn't break anything, though, if that means anything. If you are inclined to try this patch, please give feedback on whether it breaks something or not. OH, and this actually fixes the less sensitive horizontal mouse movement as well. At least on some cases, I think.
Last edited by zment; May 24, 2016 @ 3:34pm
Nice work bro

:happypolice:
👽H€L¡XX® May 24, 2016 @ 6:49pm 
@ZodiacMentor:

What you have done is quite commendable and deserving of kudos of the highest order !

That said, has anyone at Bloober team contacted you in regards to your findings and possible patch?

The only comment I see is from a person who doesn't own the game, and while I really don't have issues with it personally, I do realise that a % of players do, and this "fix" might help them.

Maybe Bloober team should get with you and do a download patch?

Personally I would hesitate to mod any files in this game without the express written consent of Bloober team.
Last edited by 👽H€L¡XX®; May 25, 2016 @ 5:06am
zment May 24, 2016 @ 7:23pm 
Indeed, you have to be careful when running files downloaded from the internet. I try to make that clear. However, for those that the stuttering issue makes the game unplayable, it might be worth a shot to try. I can personally assure though that the exe doesn't have anything wrong with it, it shouldn't break anything, and the modding it does to the main game dll doesn't modify it in any other way than the way I have described. As a person's word is worth as much in the (especially when hiding behind a nickname) internet as a wet cloth is useful for drying stuff up, that doesn't mean much; thus also the disclaimer, so that people think twice before using it. That said, it should work okay and make things smooooooooth(-er?).

I can't be sure that it doesn't mess up the game in some other way though, it might have some interconnecting issues, as developing a game has a huge amount of interconnected parts, and it would require testing. As far as I know though, it doesn't affect the rest of the game adversely.

I could write up/make a video on what I did to fix the problem, if people are interested. I am willing to work with Blooper Team as well if they want. In the meantime, until they have a patch online, I would be grateful if this was left untouched in case people want to try it out.

Of course they have all the pull here, so I'm not gonna press the issue if they want all this taken away - it's their right to do so. As I said before, in that case, I'd be happy if they just took what I know and used that knowledge for a patch.

But yeah. As a developer myself, I know that these aren't simple black and white things, and there are a lot of stuff to consider and take care of. Layers of Fear gave me a nice little puzzle before I even got properly into the game, and that alone makes it one of the most memorable for me for awhile - not to mention that I like the game as it was intended quite a lot as well (as in I've been pooping my pants for the whole night - gotta watch some stupid cat videos before going to sleep :D)
Originally posted by ZodiacMentor:
Indeed, you have to be careful when running files downloaded from the internet. I try to make that clear. However, for those that the stuttering issue makes the game unplayable, it might be worth a shot to try. I can personally assure though that the exe doesn't have anything wrong with it, it shouldn't break anything, and the modding it does to the main game dll doesn't modify it in any other way than the way I have described. As a person's word is worth as much in the (especially when hiding behind a nickname) internet as a wet cloth is useful for drying stuff up, that doesn't mean much; thus also the disclaimer, so that people think twice before using it. That said, it should work okay and make things smooooooooth(-er?).

I can't be sure that it doesn't mess up the game in some other way though, it might have some interconnecting issues, as developing a game has a huge amount of interconnected parts, and it would require testing. As far as I know though, it doesn't affect the rest of the game adversely.

I could write up/make a video on what I did to fix the problem, if people are interested. I am willing to work with Blooper Team as well if they want. In the meantime, until they have a patch online, I would be grateful if this was left untouched in case people want to try it out.

Of course they have all the pull here, so I'm not gonna press the issue if they want all this taken away - it's their right to do so. As I said before, in that case, I'd be happy if they just took what I know and used that knowledge for a patch.

But yeah. As a developer myself, I know that these aren't simple black and white things, and there are a lot of stuff to consider and take care of. Layers of Fear gave me a nice little puzzle before I even got properly into the game, and that alone makes it one of the most memorable for me for awhile - not to mention that I like the game as it was intended quite a lot as well (as in I've been pooping my pants for the whole night - gotta watch some stupid cat videos before going to sleep :D)

The fact that we both understand the underlying issue and you have attempted a fix which I think includes a fps locking of 50HZ possibly?
You're in tune with physics engine being out of sync with the GPU adapter thus your. dll offering
Maybe a breif breakdown of what it does will cure enquiring minds?

As for your cat vids, sneezing panda ftw
zment May 24, 2016 @ 8:27pm 
Basically the stuttering happens because the underlying logic is updated 50 fps, but graphics are updated on a variable frame rate, or usually capped at 60 fps. What this means is that if whenever a graphics update is done, the logic (and player character) has moved a variable time ago. Say, for one logic frame, we get a next graphics update 5 ms later. For the next logic update, we get a graphics update 10 ms later. Some time we might get a graphics update 7 ms later. Also, we could get multiple graphics frames drawn before another logic update is done, resulting in duplicate screen renders.

The reason it's mostly not seen (or really easily dismissable) when capping to 60Hz vsync (or 60 fps) is that the difference is not that much (a bit over 3 ms). As the time difference increases this much every frame, we get a small jumpy effect, unnoticeable or not annoying for some people. Using the workaround method, we could set the logic updates to a multiple of 60 (yes, even the same fps might work for the logic update interval) or even try to limit the graphics fps to 50 (which is a lot harder than changing the logic fps), but as graphics updates are still not guaranteed (at least not as much guaranteed as the fixed updates) to be updated on the same interval, we get random skewing on timedelta between the frames, so that really is just a workaround.

What I did to fix it, is evaluate the position of the player character when doing a graphics update between the last logic update and the next logic update (based on its velocity). So, if we updated the positions of the player character at 100 ms, and we get a graphics update at 105 ms, we calculate 100 - 105 = 5 ms. 50 fps is 20 ms per frame, thus when we divide that 5 ms with 20 ms, we get 0.25. This is the position from 0-1, where 0 is the last logic (or position) update and 1 is the next position update. Now we update the position of the player character using this normalized position delta with a velocity vector for the player character. Thus we get an evaluated (extrapolated) position that smoothly transitions from a graphics update frame to the next.

I had to inject a gameobject between the rigidbody and the camera objects in the hierarchy for this to work, and thus isn't as simple as just the workaround method.
Last edited by zment; May 24, 2016 @ 8:29pm
Originally posted by ZodiacMentor:
Basically the stuttering happens because the underlying logic is updated 50 fps, but graphics are updated on a variable frame rate, or usually capped at 60 fps. What this means is that if whenever a graphics update is done, the logic (and player character) has moved a variable time ago. Say, for one logic frame, we get a next graphics update 5 ms later. For the next logic update, we get a graphics update 10 ms later. Some time we might get a graphics update 7 ms later. Also, we could get multiple graphics frames drawn before another logic update is done, resulting in duplicate screen renders.

The reason it's mostly not seen (or really easily dismissable) when capping to 60Hz vsync (or 60 fps) is that the difference is not that much (a bit over 3 ms). As the time difference increases this much every frame, we get a small jumpy effect, unnoticeable or not annoying for some people. Using the workaround method, we could set the logic updates to a multiple of 60 (yes, even the same fps might work for the logic update interval) or even try to limit the graphics fps to 50 (which is a lot harder than changing the logic fps), but as graphics updates are still not guaranteed (at least not as much guaranteed as the fixed updates) to be updated on the same interval, we get random skewing on timedelta between the frames, so that really is just a workaround.

What I did to fix it, is evaluate the position of the player character when doing a graphics update between the last logic update and the next logic update (based on its velocity). So, if we updated the positions of the player character at 100 ms, and we get a graphics update at 105 ms, we calculate 100 - 105 = 5 ms. 50 fps is 20 ms per frame, thus when we divide that 5 ms with 20 ms, we get 0.25. This is the position from 0-1, where 0 is the last logic (or position) update and 1 is the next position update. Now we update the position of the player character using this normalized position delta with a velocity vector for the player character. Thus we get an evaluated (extrapolated) position that smoothly transitions from a graphics update frame to the next.

I had to inject a gameobject between the rigidbody and the camera objects in the hierarchy for this to work, and thus isn't as simple as just the workaround method.

That is bfrilliant work, kudos to you. I'll be showing someone this who understands 100% what you've done
Thanks for the great explanation as it should put some people's minds at rest re the mod you've done

CardinalStorm May 25, 2016 @ 9:23am 
ZodiacMentor, you, my friend, are AMAZING!

Your patch took me seconds to implement and the game is now perfectly smooth! I've not tested it for a huge amount of time, but I doubt this will cause any issues.

Thank you so much for taking the time to fix this game for us paying customers.

WELL DONE and THANK YOU!

EDIT: I've altered my update options for this game and will now only run in offline mode to ensure an official patch isn't installed.
Last edited by CardinalStorm; May 25, 2016 @ 9:43am
zment May 25, 2016 @ 9:41am 
I'm glad it works! Thanks for trying it out. And hey, there's nothing the developers should be ashamed of: the game is awesome. The stutter is an unfortunate "bug" that isn't really a simple thing to fix. I'm just glad I could be of help!
Last edited by zment; May 25, 2016 @ 9:42am
< >
Showing 1-15 of 126 comments
Per page: 1530 50