简体   繁体   中英

C# Steamworks GetSteamID AccessViolationException

So I'm currently trying to make use of the Steamworks API within my C# based mod for a game.

So far so good, however since the game doesn't have an inbuilt function I am trying to use the SteamWorks API (the DLL for which is packed with the game) to get the players Steam ID for later use in another process.

To get this started I've tried to define this in a string and call upon the SteamUser.GetSteamID to obtaint the information needed:

    public static string playerSteamID
        {
            get
            {
                return SteamUser.GetSteamID().ToString();
            }
        }

This presents no error within VS, however when this function is then called by the mod it throws out System.AccessViolationException "Attempted to read or write protected memory."

I've tried adapting to the ulogn version SteamUser.GetSteamID().m_SteamID but still leads to the same result.

At the moment all I have the mod trying to do is this:

InformationManager.DisplayMessage(new InformationMessage($"Steam ID is: {genStrings.playerSteamID}", Color.White));

Note, the first part is aspects of the games code in use, I'm not trying to write the string again just read it.

Screenshot of the error:

https://i.gyazo.com/09ea950b91abb4a6e4fc0a9ac577a253.png

You first need to call Steamworks.SteamAPI.Init or TaleWorlds.PlatformService.PlatformServices.Initialize if you want to use TaleWorlds API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM