tralph3 / Steam-Metadata-Editor

An easy to use GUI that edits the metadata of your Steam Apps
GNU General Public License v3.0
161 stars 18 forks source link

Receiving "KeyError:133" when running the .py file #24

Closed bassclarinetl2 closed 1 year ago

bassclarinetl2 commented 1 year ago

Hello @tralph3 ,

I'm encountering an issue when attempting to run the ```steammetadataeditor.py" file. This occurs on both the Steam Deck (SteamOS) as well as Windows. A quick use of Google-Fu seems to indicate that this is related to an undefined definition being used. I'm not a developer, just an IT Analyst so I'm not sure where to go poking although I know just enough about python to get myself around. I have included the message encountered below, also I'm running Python 3.9.1 and TCL is installed. (details are in the png attached. Let me know what further you need from me.


Traceback (most recent call last):
  File "E:\Users\will.tardis-win10\Downloads\Steam-Metadata-Editor-master\Steam-Metadata-Editor-master\src\steammetadataeditor.py", line 1557, in <module>
    mainWindow = MainWindow(silent=args.silent, export=args.export)
  File "E:\Users\will.tardis-win10\Downloads\Steam-Metadata-Editor-master\Steam-Metadata-Editor-master\src\steammetadataeditor.py", line 103, in __init__
    self.create_main_window()
  File "E:\Users\will.tardis-win10\Downloads\Steam-Metadata-Editor-master\Steam-Metadata-Editor-master\src\steammetadataeditor.py", line 124, in create_main_window
    self.appInfoVdf = VDF()
  File "E:\Users\will.tardis-win10\Downloads\Steam-Metadata-Editor-master\Steam-Metadata-Editor-master\src\steammetadataeditor.py", line 1154, in __init__
    self.parsedAppInfo = self.read_all_apps()
  File "E:\Users\will.tardis-win10\Downloads\Steam-Metadata-Editor-master\Steam-Metadata-Editor-master\src\steammetadataeditor.py", line 1247, in read_all_apps
    app['sections'] = self.parse_subsections()
  File "E:\Users\will.tardis-win10\Downloads\Steam-Metadata-Editor-master\Steam-Metadata-Editor-master\src\steammetadataeditor.py", line 1194, in parse_subsections
    value = value_parsers[value_type]()
KeyError: 133```

![2023-01-06_18-48-02](https://user-images.githubusercontent.com/5884987/211128146-e9669f41-93e5-457f-b0ca-bf8e65d26949.png)
bassclarinetl2 commented 1 year ago

Looks like markdown mangled the png, lets try this again:

2023-01-06_18-48-02

tralph3 commented 1 year ago

Yeah this happens sometimes. I'm not exactly sure why to be honest. Either the appinfo.vfd eventually gets corrupted, or I have a very subtle bug in the code that parses it.

Anyway, deleting the file and letting Steam re-generate it usually fixes it. I'll probably add a check at some point that prompts people to do it for them, or, you know, properly investigate why it even happens in the first place...

The file is located in your steam installation directory, then appcache/appinfo.vdf

bassclarinetl2 commented 1 year ago

Let me give that a try and get back to you.

kevin-wijnen commented 1 year ago

Anyway, deleting the file and letting Steam re-generate it usually fixes it.

Tried doing this, wouldn't work sadly. Although, I noticed another error after trying to use SME and see the new appinfo.vdf:

Traceback (most recent call last):
    File "opt/sme/steammetadataeditor.py", line 1557, in <module>
        STEAM_PATH = get_steam_path()
    File "/opt/sme/steammetadataeditor.py", line 1528, in get_steam_path
        config.add_section('STEAMPATH')
    File "/usr/lib/python3.8/configparser.py", line 1208, in add_section
        super().add_section(section)
    File "/usr/lib/python3.8/configparser.py", line 659, in add_section
        raise DuplicateSectionError(section)
configparser.DuplicateSectionError: Section 'STEAMPATH' already exists

After that error passed, any future launches give the same error as OP.

Running this on SteamOS (Steam Deck), through an Ubuntu container with Distrobox. This allowed me to install the .deb file in a separate folder and install the .deb app and run it.

tralph3 commented 1 year ago

Oh... go to ~/.local/share/Steam-Metadata-Editor/config and remove the config.cfg file. I'll see if I can push a quick patch to avoid this from happening.

Alexejhero commented 1 year ago

I am having the same problem. Deleting the appinfo.vfd file did not work.

thatcobbyguy commented 1 year ago

This does appear to be an issue with the latest steam beta client. When I revert to stable I'm able to use the program, but once I join the client beta, I get key error at 133 again

OliverEricT commented 1 year ago

@tralph3 I could be wrong but I believe the original poster, @bassclarinetl2 , is trying to run on Windows; or at least his screenshot appears to be windows terminal to me. Is there a Windows equivalent to the ~/.local/share... location?

To add my own context, since I am seeing the same issue on windows whether I am in the beta client or not, is that as soon as the application hit's the parse_subsections function on line 1194, it parses in the initial byte value of 133 which as far as I can tell doesn't equate to anything. at least if I am reading the code right we should really only see a 0, 1, or 2 from the self.read_string() call. But I won't pretend to really understand the parsing/handling of byte information.

tralph3 commented 1 year ago

Yes, the ~/.local/share/Steam-Metadata-Editor is just the directory where the program is at on Windows. If you ask about the Steam one, well, it's Steam installation directory (which I believe is C:\Program Files (x86)\Steam.

I have tested it myself, and it does fail on the beta, but works on the stable branch, so they must have changed something, it's odd.

I'll have to take a look. You're correct in stating that the KeyError is due to it reading an incorrect byte. As to why this happens, well, that's what I need to figure out.

tralph3 commented 1 year ago

Well, I dug a bit. Valve has updated the format of the file. It seems the header is storing more data than before, I'll need to figure out what this new data is.

tralph3 commented 1 year ago

Okay... there's a new checksum. Simply modifying the program to have it read an extra 20 bytes makes it work again, but now I need to figure out how to compute this new checksum :)

kevin-wijnen commented 1 year ago

Okay... there's a new checksum. Simply modifying the program to have it read an extra 20 bytes makes it work again, but now I need to figure out how to compute this new checksum :)

Heads up about this: It might not work at all anymore, as they updated Stable Client ~4 hours ago (for the Steam Deck, at the very least, I assume this is the same to Steam's client on Windows and Linux in general as well).

tralph3 commented 1 year ago

That's fine, as long as they don't update the appinfo.vdf format, it should work.

tralph3 commented 1 year ago

Which btw, is documented here: https://github.com/SteamDatabase/SteamAppInfo

I didn't know this existed before, it would have saved me so much pain.

kevin-wijnen commented 1 year ago

Yeah, SteamDB got some wonderful resources put out for Steam files if I'm not mistaken. They pretty much monitor Steam 24/7 for new updates on games etc., in case you weren't aware of that site before.

kevin-wijnen commented 1 year ago

I need to figure out how to compute this new checksum :)

I assume you've seen it in the SteamAppInfo repo, but the second checksum is another SHA-1 checksum ,but for the binary_vdf (as mentioned in the README.md.

tralph3 commented 1 year ago

Yes, I got that working. Now the text checksum is failing for some reason...

kevin-wijnen commented 1 year ago

How are you currently calculating both checksums, to try and diagnose the issue? (As in: input of both SHA-1 calculations)

tralph3 commented 1 year ago

For the text checksum, I parse the python dictionary to the vdf format, taking care of adding an extra backslash whenever there is one, and sending that to SHA1. For the byte checksum, I simply send all the bytes through SHA1.

Now the byte checksum works, but the text checksum works. But apparently, this is not due to how I calculate them, for some reason, there's some added data whenever I modify an app.

image

Here is a diff for the appdata of Wolfenstein 3D. I modified its name to Wolfenstein 3E, that single byte modification is up top. To the left, is the original data, to the right, is the modified data. There is an extra chunk there and I have no idea why. It's a "sortas" key.

image

This bit right here. I guess it's added because the original Wolf3D doesn't have a sortas key, and I have no check in place to not add it.

However, it shouldn't make a difference.

I'll try to test with another game, see what happens.

kevin-wijnen commented 1 year ago

Ah I see. I was trying to see if I could manually figure out what SHA-1 it needs to calculate to verify it. But I can't find any games that would have a sortas key enabled, glancing at how my games are ordered by Steam itself.

Anyhow, thanks for trying to fix this once more! If this does get fixed, I'll definitely take another crack at the Flatpak issue to see if I can compile it and maintain a Flatpak build for Steam Deck users on this repo.

tralph3 commented 1 year ago

Oh my god, I am so stupid. You know why it wasn't working? Because I was computing the byte checksum with the original data! Not the modified one! So of course there was a discrepancy!

It works now!

kevin-wijnen commented 1 year ago

That's great to hear! When you have put out a Pull Request/got a branch going for additional testing by others, I'll give it a shot on the Steam Deck through the .deb install (via my Ubuntu container of Distrobox).

tralph3 commented 1 year ago

There you go, PR done, feel free to try it.

tralph3 commented 1 year ago

Should be fixed with latest pull request.