aik002 / RSBypass

Rocksmith 2014 Remastered Edition dylib patch for loading and playing CDLC
112 stars 16 forks source link

Autodetect correct steamapps folder #5

Open xenein opened 1 year ago

xenein commented 1 year ago

First of all, thank you for all your work and developing and providing these tools.

Say, one would have split out steam games on several places, but wanted to use the provided .command file. what do? I recently moved my steamapps to another SSD. Afterwards I had to re-patch Rocksmith, and the provided .command didn't quite work, so I figured out some stuff:

all steamapp folders are listed in ~/Library/Application Support/Steam/steamapps/libraryfolders.vdf

the file looks something like this

{
        "0"
        {
                "path"          "/Users/XXXXX/Library/Application Support/Steam"
                "label"         ""
                "contentid"             "123456489"
                "totalsize"             "0"
                "update_clean_bytes_tally"              "0"
                "time_last_update_corruption"           "0"
                "apps"
                {
                        "1111111"         "123456"
                        "22222"         "654321"
                }
        }
        "1"
        {
                "path"          "/Volumes/VVVVVV/SteamLibrary"
                "label"         ""
                "contentid"             "845646271515284213"
                "totalsize"             "1000169668608"
                "update_clean_bytes_tally"              "131883596112"
                "time_last_update_corruption"           "0"
                "apps"
                {
                        "221680"                "87651513"
                }
        }
}

RS2014's steam app id is: 221680. So in that case, we'd want to patch things in /Volumes/VVVVVV/SteamLibrary

I assume we can not bring in any external dependencies, but we could bring in some vanilla python, as it comes with macOS.

I cooked up a litte python script without any external dependencies to find the correct library folder.

"""
Find out where RS2014 lives by asking steam in which libraryfolder it is placed

how do we do it? Steam keeps a database in vdf-format for that.
We only need the app id, which can be looked up at:
https://steamdb.info/ - it's 221680

1) Parse ~/Library/Application Support/Steam/steamapps/libraryfolders.vdf
2) find the "path" which holds RS2014's app id (221680)

Usually we would use a library to parse vdf and do it the right way(TM).
We can't bring one here, so what we do is: 

1) read vdf line by line
2) if line contains "path", extract the path and store it
3) if line cotains "apps" a list of (steam) apps in that path follows, we start looking for RS2014
4) if line contains "221680" we stop looping and print the stored path
5) if line contains "}" we stop looking for rs2014, clear any stored path and go back to (2)
6) if end of file is reached and the RS2014 has not been found, we print an error message

"""
import os

RS_STEAM_ID = "221680"
RS_LIB_PATH = os.path.expanduser(
    "~/Library/Application Support/Steam/steamapps/libraryfolders.vdf"
)

rs_path = ""
apps_section = False

if not os.path.exists(RS_LIB_PATH):
    print("Error: Could not find libraryfolders.vdf.")
    exit(1)

with open(RS_LIB_PATH) as vdf:
    for line in vdf:
        if "path" in line:
            rs_path = line.replace('"path"', "").strip().replace('"', "")

        if "apps" in line:
            apps_section = True

        if apps_section and RS_STEAM_ID in line:
            break

        if "}" in line:
            apps_section = False
            rs_path = ""

if rs_path != "":
    print(rs_path)
else:
    print("Error, could not find Rocksmith 2014 in installed steamapps.")
    exit(1)

feel free to use it for future releases if so desired. I could also provide a full pull request. Please let me know if you have any kind of template for those and/or if I should change up anything before submitting.

aik002 commented 1 year ago

Thanks a lot for your suggestion, I will include it in 1.8 and of course give credit. I actually have issues on my own Mac that would be fixed by this so thanks a lot

aik002 commented 1 year ago

If you want you can put in a PR, there is no template or requirements other than checking the latest .command from https://github.com/aik002/RSBypass/releases/1.8pre

aik002 commented 1 year ago

There's an even newer .command on 1.8pre2, see PR #10 and use it as a base for your changes.

glebb commented 1 year ago

I was worried this might not work with older systems which ship with Python 2, but I tested it quickly and it works ok. Good job! I might copy this to my convert tool as well, as it also tries to set default dlc folder upon first open and is currently only trying the default path. I'll give you credit for sure.

xenein commented 1 year ago

There's an even newer .command on 1.8pre2, see PR #10 and use it as a base for your changes.

I just submitted based on main. my only changes in die command-file directly are in the top of the file, so it should merge fine either way.