Ejemplo n.º 1
0
        private static bool ConnectToSteam()
        {
            if (!Steamworks.Load(true))
            {
                ShowError("Steamworks failed to load.");
                return(false);
            }

            _steamClient012 = Steamworks.CreateInterface <ISteamClient012>();
            if (_steamClient012 == null)
            {
                ShowError("Failed to create Steam Client inferface.");
                return(false);
            }

            int pipe = _steamClient012.CreateSteamPipe();

            if (pipe == 0)
            {
                ShowError("Failed to create Steam pipe.");
                return(false);
            }

            int user = _steamClient012.ConnectToGlobalUser(pipe);

            if (user == 0)
            {
                ShowError("Failed to connect to Steam user.");
                return(false);
            }

            _steamApps001 = _steamClient012.GetISteamApps <ISteamApps001>(user, pipe);
            if (_steamApps001 == null)
            {
                ShowError("Failed to create Steam Apps inferface.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public static void Init()
        {
            if (!Steamworks.Load())
            {
                throw new SteamException("Unable to load steamclient library.");
            }

            if (SteamClient == null)
            {
                SteamClient = Steamworks.CreateInterface <ISteamClient009>();

                if (SteamClient == null)
                {
                    throw new SteamException("Unable to get ISteamClient interface.");
                }
            }

            if (Pipe == 0)
            {
                Pipe = SteamClient.CreateSteamPipe();

                if (Pipe == 0)
                {
                    throw new SteamException("Unable to create steam pipe.");
                }
            }

            if (User == 0)
            {
                User = SteamClient.ConnectToGlobalUser(Pipe);

                if (User == 0)
                {
                    throw new SteamException("Unable to connect to global user.");
                }
            }

            if (SteamUser == null)
            {
                SteamUser = SteamClient.GetISteamUser <ISteamUser015>(User, Pipe);

                if (SteamUser == null)
                {
                    throw new SteamException("Unable to get ISteamUser interface.");
                }
            }

            if (SteamFriends == null)
            {
                SteamFriends = SteamClient.GetISteamFriends <ISteamFriends009>(User, Pipe);

                if (SteamFriends == null)
                {
                    throw new SteamException("Unable to get ISteamFriends interface.");
                }
            }

            if (SteamApps == null)
            {
                SteamApps = SteamClient.GetISteamApps <ISteamApps001>(User, Pipe);

                if (SteamApps == null)
                {
                    throw new SteamException("Unable to get ISteamApps interface.");
                }
            }

            CallbackDispatcher.SpawnDispatchThread(Pipe);
        }
Ejemplo n.º 3
0
        public static void Init()
        {

            if ( !Steamworks.Load() )
            {
                throw new SteamException( "Unable to load steamclient library." );
            }

            if ( SteamClient == null )
            {
                SteamClient = Steamworks.CreateInterface<ISteamClient009>();

                if ( SteamClient == null )
                {
                    throw new SteamException( "Unable to get ISteamClient interface." );
                }
            }

            if ( Pipe == 0 )
            {
                Pipe = SteamClient.CreateSteamPipe();

                if ( Pipe == 0 )
                {
                    throw new SteamException( "Unable to create steam pipe." );
                }
            }

            if ( User == 0 )
            {
                User = SteamClient.ConnectToGlobalUser( Pipe );

                if ( User == 0 )
                {
                    throw new SteamException( "Unable to connect to global user." );
                }
            }

            if ( SteamUser == null )
            {
                SteamUser = SteamClient.GetISteamUser<ISteamUser015>( User, Pipe );

                if ( SteamUser == null )
                {
                    throw new SteamException( "Unable to get ISteamUser interface." );
                }
            }

            if ( SteamFriends == null )
            {
                SteamFriends = SteamClient.GetISteamFriends<ISteamFriends009>( User, Pipe );

                if ( SteamFriends == null )
                {
                    throw new SteamException( "Unable to get ISteamFriends interface." );
                }
            }

            if ( SteamApps == null )
            {
                SteamApps = SteamClient.GetISteamApps<ISteamApps001>( User, Pipe );

                if ( SteamApps == null )
                {
                    throw new SteamException( "Unable to get ISteamApps interface." );
                }
            }

            CallbackDispatcher.SpawnDispatchThread( Pipe );

        }
Ejemplo n.º 4
0
        public Steam()
        {
            _log = LogManager.GetLogger(this);

            _log.Info("Steam initializing...");

            if (!Steamworks.Load())
            {
                _log.Error("Failed to load Steamworks.");
                throw new SteamException("Failed to load Steamworks");
            }

            _log.Debug("Creating SteamClient012 interface...");

            SteamClient012 = Steamworks.CreateInterface <ISteamClient012>();

            if (SteamClient012 == null)
            {
                _log.Error("Failed to create SteamClient012 interface");
                throw new SteamException("Failed to create SteamClient012 interface");
            }

            _log.Debug("Creating steam pipe and connecting to global user...");

            _pipe = SteamClient012.CreateSteamPipe();

            if (_pipe == 0)
            {
                _log.Error("Failed to create Steam pipe");
                throw new SteamException("Failed to create Steam pipe");
            }

            _user = SteamClient012.ConnectToGlobalUser(_pipe);

            if (_user == 0)
            {
                _log.Error("Failed to connect user");
                throw new SteamException("Failed to connect to global user");
            }

            _log.Debug("Getting SteamUtils005 interface...");

            SteamUtils005 = SteamClient012.GetISteamUtils <ISteamUtils005>(_pipe);

            if (SteamUtils005 == null)
            {
                _log.Error("Failed to obtain Steam utils");
                throw new SteamException("Failed to obtain Steam utils");
            }

            _log.Debug("Getting SteamUser016 interface...");

            SteamUser016 = SteamClient012.GetISteamUser <ISteamUser016>(_user, _pipe);

            if (SteamUser016 == null)
            {
                _log.Error("Failed to obtain Steam user interface");
                throw new SteamException("Failed to obtain Steam user interface");
            }

            _log.Debug("Getting SteamFriends002 interface...");

            SteamFriends002 = SteamClient012.GetISteamFriends <ISteamFriends002>(_user, _pipe);

            if (SteamFriends002 == null)
            {
                _log.Error("Failed to obtain Steam friends (002)");
                throw new SteamException("Failed to obtain Steam friends (002)");
            }

            _log.Debug("Getting SteamFriends014 interface...");

            SteamFriends014 = SteamClient012.GetISteamFriends <ISteamFriends014>(_user, _pipe);

            if (SteamFriends014 == null)
            {
                _log.Error("Failed to obtain Steam friends (013)");
                throw new SteamException("Failed to obtain Steam friends (013)");
            }

            SteamApps001 = SteamClient012.GetISteamApps <ISteamApps001>(_user, _pipe);

            if (SteamApps001 == null)
            {
                _log.Error("Failed to obtain SteamApps006");
                throw new SteamException("Failed to obtain SteamApps006");
            }

            SteamApps006 = SteamClient012.GetISteamApps <ISteamApps006>(_user, _pipe);

            if (SteamApps006 == null)
            {
                _log.Error("Failed to obtain Steam apps (006)");
                throw new SteamException("Failed to obtain Steam apps (006)");
            }

            SteamInstallPath = Steamworks.GetInstallPath();
            SteamConfigPath  = Path.Combine(SteamInstallPath, "config", "config.vdf");

            _log.DebugFormat("Steam installed at {0}, config at {1}", SteamInstallPath, SteamConfigPath);

            // Set up callbacks
            _log.Debug("Setting up Steam callbacks...");
            _personaStateChange        = new Callback <PersonaStateChange_t>(HandlePersonaStateChange);
            _friendProfileInfoResponse = new Callback <FriendProfileInfoResponse_t>(HandleFriendProfileInfoResponse);
            _friendAdded         = new Callback <FriendAdded_t>(HandleFriendAdded);
            _friendChatMessage   = new Callback <FriendChatMsg_t>(HandleFriendChatMessage);
            _appEventStateChange = new Callback <AppEventStateChange_t>(HandleAppEventStateChange);

            LocalUser = new LocalUser(this);
            Friends   = new Friends(this);
            Apps      = new Apps(this);

            // Spawn dispatch thread
            CallbackDispatcher.SpawnDispatchThread(_pipe);
        }
Ejemplo n.º 5
0
        public static int Main()
        {
            //Environment.SetEnvironmentVariable("SteamAppId", "730");

            Console.Write("Loading Steam2 and Steam3... ");

            if (Steamworks.Load(false))
            {
                Console.WriteLine("Ok");
            }
            else
            {
                Console.WriteLine("Failed");
                return(-1);
            }

            Console.WriteLine("\nSteam2 tests:");

            //ISteam006 steam006 = Steamworks.CreateSteamInterface<ISteam006>();
            //if (steam006 == null)
            //{
            //    Console.WriteLine("steam006 is null !");
            //    return -1;
            //}


            TSteamError steamError = new TSteamError();


            //Console.Write("GetVersion: ");
            //StringBuilder version = new StringBuilder();
            //if (steam006.GetVersion(version) != 0)
            //{
            //    Console.WriteLine("Ok (" + version.ToString() + ")");
            //}
            //else
            //{
            //    Console.WriteLine("Failed");
            //    return -1;
            //}

            //steam006.ClearError(ref steamError);

            //Console.Write("Startup: ");
            //if (steam006.Startup(0, ref steamError) != 0)
            //{
            //    Console.WriteLine("Ok");
            //}
            //else
            //{
            //    Console.WriteLine("Failed (" + steamError.szDesc + ")");
            //    return -1;
            //}

            //Console.Write("OpenTmpFile: ");
            //uint hFile;
            //if ((hFile = steam006.OpenTmpFile(ref steamError)) != 0)
            //{
            //    Console.WriteLine("Ok");
            //}
            //else
            //{
            //    Console.WriteLine("Failed (" + steamError.szDesc + ")");
            //    return -1;
            //}

            //Console.Write("WriteFile: ");
            //byte[] fileContent = System.Text.UTF8Encoding.UTF8.GetBytes("test");
            //if (steam006.WriteFile(fileContent, (uint)fileContent.Length, hFile, ref steamError) == fileContent.Length)
            //{
            //    Console.WriteLine("Ok");
            //}
            //else
            //{
            //    Console.WriteLine("Failed (" + steamError.szDesc + ")");
            //    return -1;
            //}

            //Console.Write("CloseFile: ");
            //if (steam006.CloseFile(hFile, ref steamError) == 0)
            //{
            //    Console.WriteLine("Ok");
            //}
            //else
            //{
            //    Console.WriteLine("Failed (" + steamError.szDesc + ")");
            //    return -1;
            //}

            Console.WriteLine("\nSteam3 tests:");

            ISteamClient017 steamclient = Steamworks.CreateInterface <ISteamClient017>();

            //ISteamClient009 steamclient9 = Steamworks.CreateInterface<ISteamClient009>();
            if (steamclient == null)
            {
                Console.WriteLine("steamclient is null !");
                return(-1);
            }

            IClientEngine clientengine = Steamworks.CreateInterface <IClientEngine>();

            if (clientengine == null)
            {
                Console.WriteLine("clientengine is null !");
                return(-1);
            }

            int pipe = steamclient.CreateSteamPipe();

            if (pipe == 0)
            {
                Console.WriteLine("Failed to create a pipe");
                return(-1);
            }

            int user = steamclient.ConnectToGlobalUser(pipe);

            if (user == 0 || user == -1)
            {
                Console.WriteLine("Failed to connect to global user");
                return(-1);
            }

            ISteamUser016 steamuser = steamclient.GetISteamUser <ISteamUser016>(user, pipe);

            if (steamuser == null)
            {
                Console.WriteLine("steamuser is null !");
                return(-1);
            }
            ISteamUtils005 steamutils = steamclient.GetISteamUtils <ISteamUtils005>(pipe);

            if (steamutils == null)
            {
                Console.WriteLine("steamutils is null !");
                return(-1);
            }
            ISteamUserStats002 userstats002 = steamclient.GetISteamUserStats <ISteamUserStats002>(user, pipe);

            if (userstats002 == null)
            {
                Console.WriteLine("userstats002 is null !");
                return(-1);
            }
            ISteamUserStats010 userstats010 = steamclient.GetISteamUserStats <ISteamUserStats010>(user, pipe);

            if (userstats010 == null)
            {
                Console.WriteLine("userstats010 is null !");
                return(-1);
            }
            IClientUser clientuser = clientengine.GetIClientUser <IClientUser>(user, pipe);

            if (clientuser == null)
            {
                Console.WriteLine("clientuser is null !");
                return(-1);
            }

            ISteamApps001 clientapps = steamclient.GetISteamApps <ISteamApps001>(user, pipe);

            if (clientapps == null)
            {
                Console.WriteLine("clientapps is null !");
                return(-1);
            }

            ISteamApps006 clientapps6 = steamclient.GetISteamApps <ISteamApps006>(user, pipe);

            if (clientapps6 == null)
            {
                Console.WriteLine("clientapps6 is null !");
                return(-1);
            }

            IClientFriends clientfriends = clientengine.GetIClientFriends <IClientFriends>(user, pipe);

            if (clientfriends == null)
            {
                Console.WriteLine("clientfriends is null !");
                return(-1);
            }

            //Console.Write("RequestCurrentStats: ");
            //if (userstats002.RequestCurrentStats(steamutils.GetAppID()))
            //{
            //    Console.WriteLine("Ok");
            //}
            //else
            //{
            //    Console.WriteLine("Failed");
            //    return -1;
            //}

            //uint a = steam006.RequestAccountsByEmailAddressEmail("*****@*****.**", ref steamError);
            //Console.WriteLine(steamError.nDetailedErrorCode);
            //Console.ReadLine();

            Console.Write("Waiting for stats... ");

            //CallbackMsg_t callbackMsg = new CallbackMsg_t();
            //bool statsReceived = false;
            //while (!statsReceived)
            //{
            //    while (Steamworks.GetCallback(pipe, ref callbackMsg) && !statsReceived)
            //    {
            //        Console.WriteLine(callbackMsg.m_iCallback);
            //        if (callbackMsg.m_iCallback == UserStatsReceived_t.k_iCallback)
            //        {
            //            UserStatsReceived_t userStatsReceived = (UserStatsReceived_t)Marshal.PtrToStructure(callbackMsg.m_pubParam, typeof(UserStatsReceived_t));
            //            if (userStatsReceived.m_steamIDUser == steamuser.GetSteamID() && userStatsReceived.m_nGameID == steamutils.GetAppID())
            //            {
            //                if (userStatsReceived.m_eResult == EResult.k_EResultOK)
            //                {
            //                    Console.WriteLine("Ok");
            //                    statsReceived = true;
            //                }
            //                else
            //                {
            //                    Console.WriteLine("Failed (" + userStatsReceived.m_eResult + ")");
            //                    return -1;
            //                }
            //            }
            //        }
            //        Steamworks.FreeLastCallback(pipe);
            //    }
            //    System.Threading.Thread.Sleep(100);
            //}

            Console.WriteLine("Stats for the current game :");
            uint numStats = userstats002.GetNumStats(steamutils.GetAppID());

            for (uint i = 0; i < numStats; i++)
            {
                string             statName = userstats002.GetStatName(steamutils.GetAppID(), i);
                ESteamUserStatType statType = userstats002.GetStatType(steamutils.GetAppID(), statName);
                switch (statType)
                {
                case ESteamUserStatType.k_ESteamUserStatTypeINT:
                {
                    int value = 0;
                    Console.Write("\t" + statName + " ");
                    if (userstats002.GetStat(steamutils.GetAppID(), statName, ref value))
                    {
                        Console.WriteLine(value);
                    }
                    else
                    {
                        Console.WriteLine("Failed");
                        return(-1);
                    }

                    break;
                }

                case ESteamUserStatType.k_ESteamUserStatTypeFLOAT:
                {
                    float value = 0;
                    Console.Write("\t" + statName + " ");
                    if (userstats002.GetStat(steamutils.GetAppID(), statName, ref value))
                    {
                        Console.WriteLine(value);
                    }
                    else
                    {
                        Console.WriteLine("Failed");
                        return(-1);
                    }
                    break;
                }
                }
            }

            Console.Write("GetNumberOfCurrentPlayers: ");
            ulong getNumberOfCurrentPlayersCall = userstats010.GetNumberOfCurrentPlayers();
            bool  failed = false;

            while (!steamutils.IsAPICallCompleted(getNumberOfCurrentPlayersCall, ref failed) && !failed)
            {
                System.Threading.Thread.Sleep(100);
            }

            if (failed)
            {
                Console.WriteLine("Failed (IsAPICallCompleted failure)");
                return(-1);
            }

            IntPtr pData = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(NumberOfCurrentPlayers_t)));

            if (!Steamworks.GetAPICallResult(pipe, getNumberOfCurrentPlayersCall, pData, Marshal.SizeOf(typeof(NumberOfCurrentPlayers_t)), NumberOfCurrentPlayers_t.k_iCallback, ref failed))
            {
                Console.WriteLine("Failed (GetAPICallResult failure: " + steamutils.GetAPICallFailureReason(getNumberOfCurrentPlayersCall) + ")");
                return(-1);
            }

            NumberOfCurrentPlayers_t numberOfCurrentPlayers = (NumberOfCurrentPlayers_t)Marshal.PtrToStructure(pData, typeof(NumberOfCurrentPlayers_t));

            if (!System.Convert.ToBoolean(numberOfCurrentPlayers.m_bSuccess))
            {
                Console.WriteLine("Failed (numberOfCurrentPlayers.m_bSuccess is false)");
                return(-1);
            }
            Console.WriteLine("Ok (" + numberOfCurrentPlayers.m_cPlayers + ")");

            Marshal.FreeHGlobal(pData);


            Console.Write("Games running: ");
            for (int i = 0; i < clientuser.NumGamesRunning(); i++)
            {
                CGameID gameID = clientuser.GetRunningGameID(i);
                Console.Write(gameID);
                if (i + 1 < clientuser.NumGamesRunning())
                {
                    Console.Write(", ");
                }
                else
                {
                    Console.Write("\n");
                }
            }

            Console.ReadKey();

            FriendSessionStateInfo_t sessionStateInfo = clientfriends.GetFriendSessionStateInfo(clientuser.GetSteamID());

            clientfriends.SetPersonaState(EPersonaState.k_EPersonaStateAway);

            Console.WriteLine("m_uiOnlineSessionInstances: " + sessionStateInfo.m_uiOnlineSessionInstances);
            Console.WriteLine("m_uiPublishedToFriendsSessionInstance: " + sessionStateInfo.m_uiPublishedToFriendsSessionInstance);

            Console.Write("RequestFriendProfileInfo: ");
            ulong requestFriendProfileInfoCall = clientfriends.RequestFriendProfileInfo(steamuser.GetSteamID());

            while (!steamutils.IsAPICallCompleted(requestFriendProfileInfoCall, ref failed) && !failed)
            {
                System.Threading.Thread.Sleep(100);
            }

            if (failed)
            {
                Console.WriteLine("Failed (IsAPICallCompleted failure)");
                return(-1);
            }

            pData = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FriendProfileInfoResponse_t)));

            if (!Steamworks.GetAPICallResult(pipe, requestFriendProfileInfoCall, pData, Marshal.SizeOf(typeof(FriendProfileInfoResponse_t)), FriendProfileInfoResponse_t.k_iCallback, ref failed))
            {
                Console.WriteLine("Failed (GetAPICallResult failure: " + steamutils.GetAPICallFailureReason(requestFriendProfileInfoCall) + ")");
                return(-1);
            }

            FriendProfileInfoResponse_t friendProfileInfoResponse = (FriendProfileInfoResponse_t)Marshal.PtrToStructure(pData, typeof(FriendProfileInfoResponse_t));

            if (friendProfileInfoResponse.m_eResult != EResult.k_EResultOK)
            {
                Console.WriteLine("Failed (friendProfileInfoResponse.m_eResult = " + friendProfileInfoResponse.m_eResult + ")");
                return(-1);
            }
            if (friendProfileInfoResponse.m_steamIDFriend == clientuser.GetSteamID())
            {
                Console.WriteLine("Ok");
            }
            else
            {
                Console.WriteLine("Failed (SteamIDs doesn't match)");
            }

            Marshal.FreeHGlobal(pData);

            Console.ReadKey();
            return(0);
        }