Facepunch / Facepunch.Steamworks

Another fucking c# Steamworks implementation
MIT License
2.94k stars 353 forks source link

Add Steamworks.SteamServer.SteamId #544

Open JaySlex opened 3 years ago

JaySlex commented 3 years ago

I looked up in the doc and it showed : https://wiki.facepunch.com/steamworks/SteamServer.SteamId, but it doesnt seems to exist.

Add a way to get the server steamId, unless it doesnt exist anymore, but I know it's still used in Steamworks.Net

redseiko commented 3 years ago

I was able to get this property using reflection (which isn't great)...

    static SteamId GetSteamId() {
      object steamGameServer =
          typeof(SteamServer)
              .GetProperty(
                  "Internal", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
              .GetValue(null);

      return (SteamId) steamGameServer
          .GetType()
          .GetMethod(
              "GetSteamID", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
          .Invoke(steamGameServer, null);
    }
JaySlex commented 3 years ago

I was able to get this property using reflection (which isn't great)...

    static SteamId GetSteamId() {
      object steamGameServer =
          typeof(SteamServer)
              .GetProperty(
                  "Internal", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
              .GetValue(null);

      return (SteamId) steamGameServer
          .GetType()
          .GetMethod(
              "GetSteamID", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
          .Invoke(steamGameServer, null);
    }

I found how to access it directly, update to the last version by compilling it. Not the release