Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sekiro trainer FPS and aspect ratio features #4

Closed
SvdB-nonp opened this issue Jan 4, 2023 · 7 comments
Closed

Sekiro trainer FPS and aspect ratio features #4

SvdB-nonp opened this issue Jan 4, 2023 · 7 comments

Comments

@SvdB-nonp
Copy link
Contributor

SvdB-nonp commented Jan 4, 2023

I kept the issue name a bit generic, as I found something in the existing trainer, as well as my new one. This is just some first playing around with the sekiro trainer and my own additions.

Since both features did not match patterns, I was wondering whether this is due to my setup or whether they were untested anyway.

Just an FYI: I found this sekirofpsunlock tool, which looks like an adapted copy of FPSUnlockAnd More for linux. Could be handy for some sekiro-specific stuff.
Edit: This mod works perfectly for me, setting ultrawide and FPS, so the memory pattern replacement of this one is correct.

Current output

With the current sekiro.toml, see attached, I get the following output. The code mentioned in the other sections are examples from this file. I was too lazy today to already make a branch or fork, can create this later.

[user@fedora ~]$ sudo -E env "PATH=$PATH" tuxtrain -t ~/dev/tuxtrain/trainers/sekiro.toml
==> Sekiro Trainer 0.0.2
	Set FPS Framelock (to 165)
	  - Error: Unable to find pattern.
	Fix game speed for framelock (to 84)
	  - Error: Unable to find pattern.
	Disable 16:9 aspect ratio lock.
	  - Error: EFAULT: Bad address

Changes done

Feature "Set FPS Framelock (to 165)"

At first this raised a bad address error. I noticed in SekiroFpsUnlockAndMore line 26 that they mention the 88 (index 5) could be an 89 (due to rounding of floating point?). This does fix the bad address error, but since it is not matching anything, I am not sure this is correct.

[[feature]]
name = "Set FPS Framelock (to 165)"
pattern = "C7 43 __ __ 88 89 3C 4C 89 AB"
replace = "__ __ __ 0C 98 C6 3B __ __ __"
enable = true

Feature "Fix game speed for framelock (to 84)"

No change made. I just noticed that this is again not finding any matches. I checked the other mods, and they only verified that this pattern is correct (as far as I could tell).

Feature "Disable 16:9 aspect ratio lock."

So, I drafted this based on the source code of SekiroFpsUnlockAndMore. I think this should be simple enough, first three bytes change, but I get the Bad address error which I do not know what to do with. I have no clue how a correct address looks like, so I cannot debug this reliably.

(I did already notice I could have the replace pattern have underscore-only after the first three bytes, but it is for now not yet relevant I think anyway.)

# Pattern taken from Sekiro FPS Unlock And More project:
# https://github.com/uberhalit/SekiroFpsUnlockAndMore/blob/d6312c6b0af0bcdf987568e1490b7d842548ae99/SekiroFpsUnlockAndMore/GameData.cs#L140
[[feature]]
name = "Disable 16:9 aspect ratio lock."
pattern = "85 C9 74 __ 47 8B __ __ __ __ __ __ 45 __ __ 74"
replace = "90 90 EB __ 47 8B __ __ __ __ __ __ 45 __ __ 74"
enable = true

Feature "Add ultrawide resolution entry 3440x1440 in place of 720p."

I am not sure whether this is needed, as my native resolution (3440x1440) is present in the list when running in fullscreen. However, as I already made this, I thought it couldn't hurt including this. I remember this needed to be added specifically when playing Sekiro on windows with FPS unlocked and widescreen patched, but that can of course have changed in the mean time.

# Pattern taken from Sekiro FPS Unlock And More project:
# https://github.com/uberhalit/SekiroFpsUnlockAndMore/blob/d6312c6b0af0bcdf987568e1490b7d842548ae99/SekiroFpsUnlockAndMore/GameData.cs#L126
# New values identified from https://www.wsgf.org/article/common-hex-values, Formatted Value column.
# 1280x720 = '00 05 __ __ D0 02 __ __ '
# 3440x1440 = '70 0D __ __ A0 05 __ __'

[[feature]]
name = "Add ultrawide resolution entry 3440x1440 in place of 720p."
pattern = "00 05 __ __ D0 02 __ __ A0 05 __ __ 2A 03 __ __"
replace = "70 0D 00 00 A0 05 00 00 A0 05 __ __ 2A 03 __ __"
enable = false

sekiro.zip

@leaty
Copy link
Owner

leaty commented Jan 5, 2023

Thanks for the writeup.

Since both features did not match patterns, I was wondering whether this is due to my setup or whether they were untested anyway.

Partially untested, I had not tested the Sekiro trainer personally except looking at the original source patterns (I assumed the contributor got it working). But after testing, the issue becomes apparent. After fiddling slightly with the patterns it successfully finds them, unfortunately I reach the same EFAULT: Bad address error. This was new to me, but after checking /proc/pid/maps I can see that the range in which these patterns exist do not have write access (unlike Elden Ring/Dark Souls III). See below.

140000000-140001000 r--p 00000000 103:04 1434518827   /path/to/sekiro.exe
140001000-142929000 r-xp 00000000 00:00 0 
142929000-143af9000 r--p 00000000 00:00 0
140000000-140001000 rwxp 00000000 103:02 2213939433   /path/to/DarkSoulsIII.exe
140001000-144955000 rwxp 00000000 00:00 0 
144955000-1463df000 rwxp 00000000 00:00 0

This causes process_vm_writev to fail even with sudo giving the EFAULT: Bad address error, which I am not entirely sure as to why- perhaps it's supposed to work that way? However, modifying the code to use ptrace and manually opening /proc/pid/mem as writable works. I'd like to find the actual reason behind this before pushing though, I feel like process_vm_writev should always work.

In any case I might push a PR soon with the changes if you'd like to test it that way.

@leaty
Copy link
Owner

leaty commented Jan 5, 2023

Update: As far as I can deduce, process_vm_writev respects page protection settings and it doesn't seem like there is any way to disable it (or I'm blind), so it's looking like I'll have to use a slower option.

EDIT: Actually I think I'll add ptrace as an option for each feature, where you'd enable it if the pattern exists within a protected map. This seems like the best option.

leaty added a commit that referenced this issue Jan 15, 2023
leaty added a commit that referenced this issue Jan 15, 2023
@leaty
Copy link
Owner

leaty commented Jan 16, 2023

After making a couple of patches it should work now, I'd be thankful if you could confirm. Also, I chose to use ptrace as an automatic fallback instead.

Note that I moved "Fix game speed for framelock" to the bottom of the trainer because it seems to be broken (wrong), see:

# NOTICE: In my experience this just crashes the game, I don't think this is correct.
# According to this: https://github.com/Lahvuun/sekirofpsunlock/blob/1ccc98c0de847dd0c1837381ef6e05ea423b8d2d/src/fps.c#L142
# It finds the pattern at pos 5376960685 just like this does, but then
# proceeds to write all the way over at pos 5421699608 instead.
# More research needed.

@SvdB-nonp SvdB-nonp changed the title Sekiro trainer issues & drafts Sekiro trainer FPS and aspect ratio features Jan 24, 2023
@SvdB-nonp
Copy link
Contributor Author

SvdB-nonp commented Jan 24, 2023

I made it work with your new changes, was pretty easy now as I only had to change the region a bit. There is a pull request now for the change, however I am not sure how to link it to this issue.

In a short test it enabled 165hz and widescreen succesfully. Needed to change the region for FPS slightly to make that work.

@leaty
Copy link
Owner

leaty commented Jan 25, 2023

Do you want to try getting Add ultrawide resolution entry 3440x1440 in place of 720p. to work as well? I can probably try by using gamescope this weekend otherwise, although I am not sure how accurate a test without an ultrawide monitor really is.

@SvdB-nonp
Copy link
Contributor Author

For now there is no benefit to it, as in fullscreen it is there (in fullscreen mode) with no fix at all. I think the other mod used it to add it to window mode, as they used that mode for the FPS fix (in the past).

@leaty
Copy link
Owner

leaty commented Jan 25, 2023

Sounds good, I'll give it a shot just in case it can solve it for windowed mode. But thanks for the contrib! It really helped in finding some flaws in the code (and me learning I should probably test trainers from a PR, although to be fair to the contributor it probably did work back then on an older version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants