From d4843adcab6296f3cd2bf629b55628e130af4818 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Tue, 16 Apr 2019 21:51:54 +0100 Subject: [PATCH] Update README.md --- README.md | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 126 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a2edc9f..99837f6 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,22 @@ C# is meant to make things easier. So lets try to wrap it up in a way that makes ## What -So say you want to print a list of your friends? +### Get your own information ```csharp -foreach ( var friend in client.Friends.All ) +SteamClient.SteamId // Your SteamId +SteamClient.Name // Your Name +``` + +### View your friends list + +```csharp +foreach ( var friend in SteamFriends.GetFriends() ) { - Console.WriteLine( "{0}: {1}", friend.Id, friend.Name ); + Console.WriteLine( "{friend.Id}: {friend.Name}" ); + Console.WriteLine( "{friend.IsOnline} / {friend.SteamLevel}" ); + + friend.SendMessage( "Hello Friend" ); } ``` @@ -31,11 +41,122 @@ But what if you want to get a list of friends playing the same game that we're p ```csharp foreach ( var friend in client.Friends.All.Where( x => x.IsPlayingThisGame ) ) { - Console.WriteLine( "{0}: {1}", friend.Id, friend.Name ); + // } ``` -You can view examples of everything in the Facepunch.Steamworks.Test project. +### App Info + +```csharp +Console.WriteLine( SteamApps.GameLanguage ); // Print the current game language +var installDir = SteamApps.AppInstallDir( 4000 ); // Get the path to the Garry's Mod install folder + +var fileinfo = await SteamApps.GetFileDetailsAsync( "hl2.exe" ); // async get file details +DoSomething( fileinfo.SizeInBytes, fileinfo.Sha1 ); +``` + +### Get Avatars + +```csharp +var image = await SteamFriends.GetLargeAvatarAsync( steamid ); +if ( !image.HasValue ) return DefaultImage; + +return MakeTextureFromRGBA( image.Data, image.Width, image.Height ); +``` + +### Get a list of servers + +```csharp +using ( var list = new ServerList.Internet() ) +{ + list.AddFilter( "map", "de_dust" ); + await list.RunQueryAsync(); + + foreach ( var server in list.Responsive ) + { + Console.WriteLine( $"{server.Address} {server.Name}" ); + } +} +``` + +### Achievements + +List them + +```csharp +foreach ( var a in SteamUserStats.Achievements ) +{ + Console.WriteLine( $"{a.Name} ({a.State}})" ); +} +``` + +Unlock them + +```csharp +var ach = new Achievement( "GM_PLAYED_WITH_GARRY" ); +ach.Trigger(); +``` + +### Voice + +```csharp + +SteamUser.VoiceRecord = KeyDown( "V" ); + +if ( SteamUser.HasVoiceData ) +{ + var bytesrwritten = SteamUser.ReadVoiceData( stream ); + // Send Stream Data To Server or Something +} + +``` + + +### Auth + +```csharp + +// Client sends ticket data to server somehow +var ticket = SteamUser.GetAuthSessionTicket(); + + +// server listens to event +SteamServer.OnValidateAuthTicketResponse += ( steamid, ownerid, rsponse ) => +{ + if ( rsponse == AuthResponse.OK ) + TellUserTheyCanBeOnServer( steamid ); + else + KickUser( steamid ); +}; + +// server gets ticket data from client, calls this function.. which either returns +// false straight away, or will issue a TicketResponse. +if ( !SteamServer.BeginAuthSession( ticketData, clientSteamId ) ) +{ + KickUser( clientSteamId ); +} + +// +// Client is leaving, cancels their ticket OnValidateAuth is called on the server again +// this time with AuthResponse.AuthTicketCanceled +// +ticket.Cancel(); + +``` + +### Utils + +```csharp +SteamUtils.SecondsSinceAppActive; +SteamUtils.SecondsSinceComputerActive; +SteamUtils.IpCountry; +SteamUtils.UsingBatteryPower; +SteamUtils.CurrentBatteryPower; +SteamUtils.AppId; +SteamUtils.IsOverlayEnabled; +SteamUtils.IsSteamRunningInVR; +SteamUtils.IsSteamInBigPictureMode; +``` # Usage