rlabrecque / Steamworks.NET

Steamworks wrapper for Unity / C#
http://steamworks.github.io
MIT License
2.82k stars 368 forks source link

Inconsistent Functionality with Callbacks/CallResults #303

Open anpShawn opened 5 years ago

anpShawn commented 5 years ago

I'm currently using Unity 2018.4.3f1 and Steamworks SDK 1.43 I'm building for Windows.

My issue is that some callbacks/callresults that I listen for work, and others do not. I hesitated to open this issue since it seems to have plagued many devs over time for different reasons with the answer being slightly different each time.

I don't use the IL2CPP scripting backend, which should negate the issue raised here: https://github.com/rlabrecque/Steamworks.NET/issues/227

I've confirmed that SteamAPI.RunCallbacks() is indeed running regularly, which negates this information: https://steamcommunity.com/groups/steamworks/discussions/0/864980103815443758/

To my knowledge I'm not mixing up CallResults and Callbacks, which I've seen happen to other users. In most cases my code is taken almost verbatim from the Steamworks-Test repo: https://github.com/rlabrecque/Steamworks.NET-Test/blob/master/Assets/Scripts/SteamUserTest.cs

Not to mention, as indicated in the title, some of my callbacks work and some don't. For example, I can get these two to work correctly: RemoteStorageFileWriteAsyncComplete_t (callresult) MicroTxnAuthorizationResponse_t (callback)

But these do not work for me: ValidateAuthTicketResponse_t (callback) RemoteStorageFileReadAsyncComplete_t (callresult)

I do have workarounds- I switched my fileread to synchronous, and I'm able to send my auth tickets for validation immediately after requesting them. It works, but it's not ideal, and I feel I must be doing something wrong. I checked the commit history for this repo and didn't see anything that addressed callbacks since when I installed everything. The fileread in particular has always been broken for me, even when first installed the latest version of everything.

Any suggestions for any other routes I can take? I can post some example code if it helps but this is already longer than I wanted it to be. Just trying to think of what else could be causing this. Thanks for any help.

anpShawn commented 5 years ago

Here is my implementation of the AuthTicket stuff: (Backend.cs is not a monobehavior but a class that I instantiate from Start() in my main game entry point)

public class Backend
{
protected Callback<ValidateAuthTicketResponse_t> SteamValidateAuthTicketResponse;
private int AUTH_TICKET_BUFFER_SIZE = 1024;
protected byte[] authTicketBuffer;
protected uint authTicketLength;
protected HAuthTicket authTicketHandle;

public Backend()
{
       SteamValidateAuthTicketResponse = 
       Callback<ValidateAuthTicketResponse_t>.Create(OnSteamValidateAuthTicketResponse);
}
public void GenerateAuthTicket()
{
        //this gets called much later in the game
        authTicketBuffer = new byte[AUTH_TICKET_BUFFER_SIZE];
        authTicketHandle = SteamUser.GetAuthSessionTicket(authTicketBuffer, AUTH_TICKET_BUFFER_SIZE, out authTicketLength);
}
void OnSteamValidateAuthTicketResponse(ValidateAuthTicketResponse_t pCallback)
{
       //this never gets called
}
}
spajus commented 5 years ago

See #302 - could it be related?

Dakkers commented 4 years ago

@anpShawn did you solve this?

anpShawn commented 4 years ago

nope, just stuck with the workarounds I mentioned in the first post :/

Dakkers commented 4 years ago

Unfortunate :\ could you share your workaround for the auth ticket logic? I'm not sure how to implement the synchronous file reading you've mentioned.

On Sun, Jun 28, 2020, 8:04 PM anpShawn, notifications@github.com wrote:

nope, just stuck with the workarounds I mentioned in the first post :/

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rlabrecque/Steamworks.NET/issues/303#issuecomment-650841284, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGG54DWJ3I25OASR3KXYSDRY7LCRANCNFSM4IV3JRTQ .

anpShawn commented 4 years ago

My Auth Ticket implementation is a few posts above: https://github.com/rlabrecque/Steamworks.NET/issues/303#issuecomment-530618048

As for synchronous file reading, it's pretty straightforward since there are no callbacks:

private byte[] SteamCloudSaveRead()
    {
        int curBytes = SteamRemoteStorage.GetFileSize(CLOUD_SAVE_FILE_NAME);
        //if curBytes == 0 abort this process since no file exists yet that can be read from

        byte[] fileBytes = new byte[numBytes];
        SteamRemoteStorage.FileRead(CLOUD_SAVE_FILE_NAME, fileBytes, numBytes);
        return fileBytes;
    }
Dakkers commented 4 years ago

you said that the callback never gets called though right? does your auth ticket actually get verified by Steam then? I keep getting "Invalid ticket" from the web API when trying to use the ticket 😭

anpShawn commented 4 years ago

Hm- I believe so but I can't verify that personally. After requesting the auth ticket I send it to our backend server when requesting an IAP transaction. Another programmer works on our backend and I assume the ticket functions as needed for that purpose but I don't know his exact procedure. Sorry I can't be of more help.

Dakkers commented 4 years ago

no worries mate - today I tried it without waiting for the callback and I got a 200 from the Steam web API so... I guess it worked? not sure if it's reliable but I'm returning an error to the user to retry if it doesn't work anyway.

@rlabrecque if you could shed any light on our issues, that would be swell. 🙏

Akarinnnnn commented 3 years ago

The callback dispatching system wan changed on 2020/10/3, a new manual dispatch system replaced old C++ vtable based callbacks, your issue may related to it.