philippj / SteamworksPy

A working Python API system for Valve's Steamworks.
MIT License
212 stars 39 forks source link

Different callback output on Windows and Linux #75

Closed rimpy-custom closed 2 years ago

rimpy-custom commented 2 years ago

I am still getting issues. To make things clear, here is reproducible example: https://rentry.co/tskkp Output on Windows 10:

Item subscribed (<steamworks.structs.RemoteStorageSubscribePublishedFileResult_t object at 0x0000020DA6979C40>,) {}
9 1
Item unsubscribed (<steamworks.structs.RemoteStorageUnsubscribePublishedFileResult_t object at 0x0000020DA6979C40>,) {}
1 1

Output on Fedora 36 (probably any linux distro will have the same result):

Item subscribed (<steamworks.structs.RemoteStorageSubscribePublishedFileResult_t object at 0x7f05abal5c40>,) {}
-1415941056 4294967305
Item unsubscribed (<steamworks.structs.RemoteStorageUnsubscribePublishedFileResult_t object at 0x7f05abal5c40>,) {}
-1415941056 4294967297

Both OS are 64 bit, python is 64bit also. Looks like somethhing wrong with ctypes? Related to this https://github.com/philippj/SteamworksPy/issues/62

joseasoler commented 2 years ago

I have tested the same reproducible example on Arch Linux after compiling SteamworksPy and I also get a similar output.

One thing I noticed is that the result field of the RemoteStorageSubscribePublishedFileResult_t struct received on Python is a random number on each invocation of the script, with the same number appearing on both subscribe and unsubscribe. The publishedFileId member of the struct always returns the same number for subscribe and the same number for unsubscribe. I am getting the same publishedFileIds as rimpy-custom.

I added some logging to the Workshop::OnItemSubscribed and Workshop::OnItemUnsubscribed methods in the C++ code. At that point, result and publishedFileId seem to hold the expected results that SteamworksPy produces on Windows. This seems to indicate that there is some problem in the process of getting this data back to Python.

Here is my full output:

[S_API] SteamAPI_Init(): Loaded '/home/joseasoler/.local/share/Steam/linux64/steamclient.so' OK.
Setting breakpad minidump AppID = 294100
Steam_SetMinidumpSteamID:  Caching Steam ID:  76561198004603333 [API loaded no]
[C++] OnItemSubscribed | result:9, publishedFileId: 1 | bIOFailure: 0
[Python] Subscribe callback | result: 1046477216, publishedFileId: 4294967305
[C++] OnItemUnsubscribed | result: 1, publishedFileId: 1 | bIOFailure: 0
[Python] Unsubscribe callback | result: 1046477216, publishedFileId: 4294967297
philippj commented 2 years ago

So, I can confirm this error and also replicate it. The stack seems to contain 5 additional bytes of data, stemming from the SteamAPICall_t being returned for the UnsubscribeItem call.

You can add a quick fix by modifying your affected structs in structs.py like this:

class RemoteStorageUnsubscribePublishedFileResult_t(Structure):
    _fields_ = [
        ("SteamAPICall_t", c_byte*5),
        ("result", c_int),
        ("publishedFileId", c_uint)
    ]

A fix on main will take some time.