コード例 #1
0
        private bool InitSteam()
        {
            ISteamClient012 steamclient = Steamworks.CreateInterface <ISteamClient012>();

            if (steamclient == null)
            {
                Console.WriteLine("steamclient is null !");
                return(false);
            }

            int pipe = steamclient.CreateSteamPipe();

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

            int user = steamclient.ConnectToGlobalUser(pipe);

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

            steamuser = steamclient.GetISteamUser <ISteamUser016>(user, pipe);
            if (steamuser == null)
            {
                Console.WriteLine("steamuser is null !");
                return(false);
            }
            return(true);
        }
コード例 #2
0
        private static ErrorCodes ConnectToSteam()
        {
            if (!Steamworks.Load(true))
            {
                return(ErrorCodes.SteamworksFail);
            }

            _steamClient = Steamworks.CreateInterface <ISteamClient017>();
            if (_steamClient == null)
            {
                return(ErrorCodes.ClientFail);
            }

            var pipe = _steamClient.CreateSteamPipe();

            if (pipe == 0)
            {
                return(ErrorCodes.PipeFail);
            }

            var user = _steamClient.ConnectToGlobalUser(pipe);

            if (user == 0)
            {
                return(ErrorCodes.UserFail);
            }

            _steamApp = _steamClient.GetISteamApps <ISteamApps006>(user, pipe);
            return(_steamApp == null ? ErrorCodes.AppsFail : ErrorCodes.Success);
        }
コード例 #3
0
        public Server()
        {
            antiGCList  = new List <object>();
            IRCCommands = new IRCCommandList();

            BaseIRCLib.Database.SetDatabase(this);
            BaseIRCLib.Server.SetServer(this);

            Steamworks.Load();
            steamClient  = Steamworks.CreateInterface <ISteamClient009>("SteamClient009");
            clientEngine = Steamworks.CreateInterface <IClientEngine>("CLIENTENGINE_INTERFACE_VERSION001");

            pipe = steamClient.CreateSteamPipe();
            user = steamClient.ConnectToGlobalUser(pipe);

            clientFriends = Steamworks.CastInterface <IClientFriends>(clientEngine.GetIClientFriends(user, pipe, "CLIENTFRIENDS_INTERFACE_VERSION001"));
            clientUser    = Steamworks.CastInterface <ISteamUser014>(steamClient.GetISteamUser(user, pipe, "SteamUser014"));
            //clientUser = Steamworks.CastInterface<IClientUser>(clientEngine.GetIClientUser(user, pipe, "CLIENTUSER_INTERFACE_VERSION001"));

            Callback <PersonaStateChange_t>    stateChange   = new Callback <PersonaStateChange_t>(StateChange, PersonaStateChange_t.k_iCallback);
            Callback <FriendChatMsg_t>         friendMessage = new Callback <FriendChatMsg_t>(FriendMessage, FriendChatMsg_t.k_iCallback);
            Callback <ChatRoomMsg_t>           chatMessage   = new Callback <ChatRoomMsg_t>(ChatMessage, ChatRoomMsg_t.k_iCallback);
            Callback <ChatMemberStateChange_t> chatResult    = new Callback <ChatMemberStateChange_t>(ChatResult, ChatMemberStateChange_t.k_iCallback);
            Callback <ChatRoomInvite_t>        chatInvite    = new Callback <ChatRoomInvite_t>(ChatInvite, ChatRoomInvite_t.k_iCallback);

            if (File.Exists("clients.list"))
            {
                clientList = ClientList.LoadClients("clients.list");
            }
            else
            {
                clientList = new ClientList();
                clientList.Save("clients.list");
            }

            foreach (string f in Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "Commands"), "*.dll"))
            {
                Assembly fA = Assembly.LoadFile(f);
                foreach (Type m in fA.GetTypes())
                {
                    object a = fA.CreateInstance(m.FullName);
                    if (a == null)
                    {
                        Console.WriteLine("Skipping implementation of {0}", m.Name);
                        continue;
                    }

                    antiGCList.Add(a);

                    RegisterCommands(a);
                }
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: bmk10/hl2sb-src-1
        public static void Main()
        {
            File.WriteAllText("steam_appid.txt", "630");

            Steamworks.Load(true);

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

            int pipe = steamclient.CreateSteamPipe();
            int user = steamclient.ConnectToGlobalUser(pipe); // steamclient.CreateLocalUser(ref pipe); // steamclient.ConnectToGlobalUser(pipe);

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


            ISteam003 steam003 = Steamworks.CreateSteamInterface <ISteam003>();

            StringBuilder version = new StringBuilder();

            version.EnsureCapacity(256);

            steam003.GetVersion(version);

            TSteamError   error = new TSteamError();
            uint          sz    = 0;
            StringBuilder email = new StringBuilder();

            email.EnsureCapacity(256);

            steam003.GetCurrentEmailAddress(email, ref sz, ref error);

            CSteamID steamid = steamuser.GetSteamID();

            ISteamFriends003 friends  = steamclient.GetISteamFriends <ISteamFriends003>(user, pipe);
            ISteamFriends002 friends2 = steamclient.GetISteamFriends <ISteamFriends002>(user, pipe);

            int num = friends.GetFriendCount(EFriendFlags.k_EFriendFlagAll);

            for (int i = 0; i < num; i++)
            {
                CSteamID id   = friends.GetFriendByIndex(i, EFriendFlags.k_EFriendFlagAll);
                string   name = friends.GetFriendPersonaName(id);

                if (name == "Stan")
                {
                    byte[] buff = Encoding.ASCII.GetBytes("Oidy.");
                    friends2.SendMsgToFriend(id, EChatEntryType.k_EChatEntryTypeChatMsg, buff);
                }

                Debug.WriteLine(name);
            }
        }
コード例 #5
0
ファイル: SteamContext.cs プロジェクト: bmk10/hl2sb-src-1
        static void InitSteam3()
        {
            DebugLog.AppendText("Initializing Steam3...");

            if (!Steamworks.LoadSteamClient())
            {
                throw new InvalidOperationException("Unable to load steamclient.dll");
            }

            DebugLog.AppendText("Getting Steam3 interface: ISteamClient009...");
            SteamClient = Steamworks.CreateInterface <ISteamClient009>();
            DebugLog.AppendText(string.Format("ISteamClient009 = 0x{0:8X}", SteamClient.Interface));

            DebugLog.AppendText("Getting Steam3 interface: IClientEngine...");
            ClientEngine = Steamworks.CreateInterface <IClientEngine>();
            DebugLog.AppendText(string.Format("IClientEngine = 0x{0:8X}{1}", ClientEngine.Interface, Environment.NewLine));

            if (SteamClient == null || ClientEngine == null)
            {
                throw new InvalidOperationException("Unable to get required steamclient interfaces.");
            }


            DebugLog.AppendText("Creating steam pipe...");
            HSteamPipe = SteamClient.CreateSteamPipe();
            DebugLog.AppendText(string.Format("HSteamPipe = {0}", HSteamPipe));

            DebugLog.AppendText("Connecting to global user...");
            HSteamUser = SteamClient.ConnectToGlobalUser(HSteamPipe);
            DebugLog.AppendText(string.Format("HSteamUser = {0}{1}", HSteamUser, Environment.NewLine));

            if (HSteamUser == 0 || HSteamPipe == 0)
            {
                throw new InvalidOperationException("Unable to connect to global user.");
            }

            DebugLog.AppendText("Getting IClient interface: IClientApps...");
            ClientApps = ClientEngine.GetIClientApps <IClientApps>(HSteamUser, HSteamPipe);
            DebugLog.AppendText(string.Format("IClientApps = 0x{0:8X}", ClientApps.Interface));

            DebugLog.AppendText("Getting IClient interface: IClientUser...");
            ClientUser = ClientEngine.GetIClientUser <IClientUser>(HSteamUser, HSteamPipe);
            DebugLog.AppendText(string.Format("IClientUser = 0x{0:8X}", ClientUser.Interface));

            if (ClientApps == null || ClientUser == null)
            {
                throw new InvalidOperationException("Unable to get required interfaces.");
            }

            DebugLog.AppendText("Steam3 startup success." + Environment.NewLine);
        }
コード例 #6
0
ファイル: LogManager.cs プロジェクト: elitak/open-steamworks
        public bool GetSteamClient()
        {
            if ( !Steamworks.Load() )
                return false;

            steamClient = Steamworks.CreateInterface<ISteamClient008>( "SteamClient008" );
            clientEngine = Steamworks.CreateInterface<IClientEngine>( "CLIENTENGINE_INTERFACE_VERSION002" );

            if ( steamClient == null )
                return false;

            if ( clientEngine == null )
                return false;

            return true;
        }
コード例 #7
0
		/// <summary>
		/// Initializes the <c>SteamManager</c>.
		/// This MUST be called before other Steam operations are executed.
		/// </summary>
		/// <returns><c>true</c> if everything initialized properly, <c>false</c> otherwise.</returns>
		public static bool Init()
		{
			if (Enabled)
			{
				_log.Warn("Tried to call Init method when SteamManager has already been initialized! Aborting...");
				return false;
			}
			_log = LogManager.GetLogger(typeof(SteamManager));
			try
			{
				if (!Steamworks.Load())
				{
					_log.Error("Steamworks failed to load, throwing exception!");
					throw new SteamException("Steamworks failed to load.", SteamExceptionType.SteamworksLoadFail);
				}

				Client = Steamworks.CreateInterface<ISteamClient010>("SteamClient010");
				if (Client == null)
				{
					_log.Error("Steamclient is NULL!! Throwing exception!");
					throw new SteamException("Steamclient failed to load! Is the client running? (Sharpcraft.Steam.SteamManager.Client == null!)",
											 SteamExceptionType.SteamLoadFail);
				}

				Pipe = Client.CreateSteamPipe();
				User = Client.ConnectToGlobalUser(Pipe);

				Friends = Steamworks.CastInterface<ISteamFriends002>(Client.GetISteamFriends(User, Pipe, "SteamFriends002"));

				if (Friends == null)
					return false;

				FriendList = new SteamFriendList();

				_steamWatcher = new Timer(SteamCheck, null, 0, 1000);
			}
			catch (SteamException ex)
			{
				_log.Warn("Warning! SteamManager caught a SteamException exception, returning FALSE. Steam components will NOT LOAD!");
				_log.Warn("The SteamException type was: " + System.Enum.GetName(typeof(SteamExceptionType), ex.Type));
				return false;
			}
			_log.Info("SteamManager has been initialized!");
			SteamLoaded = true;
			Enabled = true;
			return true;
		}
コード例 #8
0
ファイル: CSGSITools_Form.cs プロジェクト: sp0ok3r/CSGSITools
        private int LoadSteam()
        {
            if (Steamworks.Load(true))
            {
                Console.WriteLine("Ok, Steam Works!");
            }
            else
            {
                MessageBox.Show("Failed, Steam Works!");
                Console.WriteLine("Failed, Steam Works!");

                return(-1);
            }

            steam006 = Steamworks.CreateSteamInterface <ISteam006>();

            steamclient     = Steamworks.CreateInterface <ISteamClient012>();
            pipe            = steamclient.CreateSteamPipe();
            user            = steamclient.ConnectToGlobalUser(pipe);
            steamuser       = steamclient.GetISteamUser <ISteamUser016>(user, pipe);
            steamfriends013 = steamclient.GetISteamFriends <ISteamFriends013>(user, pipe);
            steamfriends002 = steamclient.GetISteamFriends <ISteamFriends002>(user, pipe);
            CSteamID steamID = steamuser.GetSteamID();

            CurrentState = steamfriends002.GetFriendPersonaState(steamID);

            string ConvertTo64 = steamID.ConvertToUint64().ToString();

            txtBox_steamID.Text = ConvertTo64;
            steamid             = steamID;
            if (steam006 == null)
            {
                Console.WriteLine("steam006 is null !");
                return(-1);
            }
            if (steamclient == null)
            {
                Console.WriteLine("steamclient is null !");
                return(-1);
            }


            return(0);
        }
コード例 #9
0
        private static bool ConnectToSteam()
        {
            var    steamError = new TSteamError();
            string errorText  = "";

            if (!Steamworks.Load(true))
            {
                errorText = "Steamworks failed to load.";
                Console.WriteLine(errorText);
                return(false);
            }

            _steam006 = Steamworks.CreateSteamInterface <ISteam006>();
            if (_steam006.Startup(0, ref steamError) == 0)
            {
                errorText = "Steam startup failed. Is Steam running?";
                Console.WriteLine(errorText);
                return(false);
            }

            _steamClient012 = Steamworks.CreateInterface <ISteamClient012>();
            _clientEngine   = Steamworks.CreateInterface <IClientEngine>();

            _pipe = _steamClient012.CreateSteamPipe();
            if (_pipe == 0)
            {
                errorText = "Failed to create user pipe.";
                Console.WriteLine(errorText);
                return(false);
            }

            _user = _steamClient012.ConnectToGlobalUser(_pipe);
            if (_user == 0 || _user == -1)
            {
                errorText = "Failed to connect to global user.";
                Console.WriteLine(errorText);
                return(false);
            }

            _clientBilling = _clientEngine.GetIClientBilling <IClientBilling>(_user, _pipe);
            _clientUser    = _clientEngine.GetIClientUser <IClientUser>(_user, _pipe);
            return(true);
        }
コード例 #10
0
        public bool Initialize()
        {
            if (!Steamworks.Load())
            {
                return(false);
            }

            SteamClient = Steamworks.CreateInterface <ISteamClient008>("SteamClient008");
            if (SteamClient == null)
            {
                return(false);
            }


            Pipe = SteamClient.CreateSteamPipe();
            if (Pipe == 0)
            {
                return(false);
            }

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


            SteamFriends = Steamworks.CastInterface <ISteamFriends002>(SteamClient.GetISteamFriends(User, Pipe, "SteamFriends002"));
            if (SteamFriends == null)
            {
                return(false);
            }


            SteamUser = Steamworks.CastInterface <ISteamUser013>(SteamClient.GetISteamUser(User, Pipe, "SteamUser013"));
            if (SteamUser == null)
            {
                return(false);
            }

            return(true);
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: h4c3er/dota
        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);
        }
コード例 #12
0
ファイル: Program.cs プロジェクト: bmk10/hl2sb-src-1
        static void Main(string[] args)
        {
            CSteamID qq = 133724098;


            if (!Steamworks.Load())
            {
                return;
            }

            ISteamClient008 steamclient = Steamworks.CreateInterface <ISteamClient008>("SteamClient008");

            Console.WriteLine("client: " + steamclient);

            int pipe = steamclient.CreateSteamPipe();
            int user = steamclient.ConnectToGlobalUser(pipe);

            Console.WriteLine(user);
            Console.WriteLine(pipe);

            ISteamUtils004   utils   = Steamworks.CastInterface <ISteamUtils004>(steamclient.GetISteamUtils(pipe, "SteamUtils004"));
            ISteamFriends005 friends = Steamworks.CastInterface <ISteamFriends005>(steamclient.GetISteamFriends(user, pipe, "SteamFriends005"));

            int num = friends.GetFriendCount(EFriendFlags.k_EFriendFlagAll);

            for (int i = 0; i < num; i++)
            {
                CSteamID id   = friends.GetFriendByIndex(i, (int)EFriendFlags.k_EFriendFlagAll);
                string   name = friends.GetFriendPersonaName(id);

                Debug.WriteLine(name);
            }

            CallbackDispatcher.SpawnDispatchThread(pipe);
            Thread.Sleep(5000);
            CallbackDispatcher.StopDispatchThread(pipe);

            steamclient.ReleaseUser(pipe, user);
            steamclient.ReleaseSteamPipe(pipe);
        }
コード例 #13
0
        public bool GetSteamClient()
        {
            if (!Steamworks.Load())
            {
                return(false);
            }

            steamClient  = Steamworks.CreateInterface <ISteamClient008>("SteamClient008");
            clientEngine = Steamworks.CreateInterface <IClientEngine>("CLIENTENGINE_INTERFACE_VERSION001");

            if (steamClient == null)
            {
                return(false);
            }

            if (clientEngine == null)
            {
                return(false);
            }

            return(true);
        }
コード例 #14
0
        private bool connectToSteam()
        {
            var steamError = new TSteamError();

            if (!Steamworks.Load(true))
            {
                lblError.Text = "Steamworks failed to load.";
                return(false);
            }

            _steam006 = Steamworks.CreateSteamInterface <ISteam006>();
            if (_steam006.Startup(0, ref steamError) == 0)
            {
                lblError.Text = "Пожалуйста, включите программу Steam.";
                return(false);
            }

            _steamClient012 = Steamworks.CreateInterface <ISteamClient012>();
            _clientEngine   = Steamworks.CreateInterface <IClientEngine>();

            _pipe = _steamClient012.CreateSteamPipe();
            if (_pipe == 0)
            {
                lblError.Text = "Failed to create user pipe.";
                return(false);
            }

            _user = _steamClient012.ConnectToGlobalUser(_pipe);
            if (_user == 0 || _user == -1)
            {
                lblError.Text = "Failed to connect to global user.";
                return(false);
            }

            _clientBilling = _clientEngine.GetIClientBilling <IClientBilling>(_user, _pipe);
            _clientUser    = _clientEngine.GetIClientUser <IClientUser>(_user, _pipe);
            return(true);
        }
コード例 #15
0
ファイル: LogManager.cs プロジェクト: GEEKiDoS/TeknoMW3-M
        private void InitSteamworks()
        {
            int error;

            steamClient = ( SteamClient008 )Steamworks.CreateInterface(SteamClient008.InterfaceVersion, out error);

            if (error > 0 || steamClient == null)
            {
                Util.ShowFatalError(null, "Unable get SteamClient interface.");
                Initialized = false;
                return;
            }

            pipe = steamClient.CreateSteamPipe();
            if (pipe == SteamPipeHandle.InvalidHandle)
            {
                Util.ShowFatalError(null, "Unable to create steam pipe.\n\nPlease ensure steam is running.");
                Initialized = false;
                return;
            }

            user = steamClient.ConnectToGlobalUser(pipe);
            if (user == new SteamUserHandle(0))
            {
                Util.ShowFatalError(null, "Unable to connect to global user.\n\nPlease ensure you are logged into steam.");
                Initialized = false;
                return;
            }

            steamFriends = ( SteamFriends001 )steamClient.GetISteamFriends(user, pipe, SteamFriends001.InterfaceVersion);
            if (steamFriends == null)
            {
                Util.ShowFatalError(null, "Unable to get SteamFriends interface.");
                Initialized = false;
                return;
            }
        }
コード例 #16
0
        private bool connectToSteam()
        {
            var steamError = new TSteamError();

            if (!Steamworks.Load(true))
            {
                throw new SteamException("Steamworks failed to load.");
                return(false);
            }

            _steam006 = Steamworks.CreateSteamInterface <ISteam006>();
            if (_steam006.Startup(0, ref steamError) == 0)
            {
                throw new SteamException("Steam startup failed.");
                return(false);
            }

            _steamClient012 = Steamworks.CreateInterface <ISteamClient012>();
            _clientEngine   = Steamworks.CreateInterface <IClientEngine>();

            _pipe = _steamClient012.CreateSteamPipe();
            if (_pipe == 0)
            {
                throw new SteamException("Failed to create a pipe.");
                return(false);
            }

            _user = _steamClient012.ConnectToGlobalUser(_pipe);
            if (_user == 0 || _user == -1)
            {
                throw new SteamException("Failed to connect to global user.");
                return(false);
            }

            _clientBilling = _clientEngine.GetIClientBilling <IClientBilling>(_user, _pipe);
            return(true);
        }
コード例 #17
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);
        }
コード例 #18
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            ClassEditControl scout = new ClassEditControl("Scout");

            scout.ClassImage = Properties.Resources.scout;

            // heavy
            ClassEditControl heavy = new ClassEditControl("Heavy");

            heavy.ClassImage = Properties.Resources.heavy;

            // medic
            ClassEditControl medic = new ClassEditControl("Medic");

            medic.ClassImage = Properties.Resources.medic;

            // soldier
            ClassEditControl soldier = new ClassEditControl("Soldier");

            soldier.ClassImage = Properties.Resources.soldier;

            // engi
            ClassEditControl engineer = new ClassEditControl("Engineer");

            engineer.ClassImage = Properties.Resources.engineer;

            // spy
            ClassEditControl spy = new ClassEditControl("Spy");

            spy.ClassImage = Properties.Resources.spy;

            // sniper
            ClassEditControl sniper = new ClassEditControl("Sniper");

            sniper.ClassImage = Properties.Resources.sniper;

            // demo
            ClassEditControl demo = new ClassEditControl("Demoman");

            demo.ClassImage = Properties.Resources.demoman;

            // pyro
            ClassEditControl pyro = new ClassEditControl("Pyro");

            pyro.ClassImage = Properties.Resources.pyro;

            flowLayoutPanel1.Controls.Add(scout);
            flowLayoutPanel1.Controls.Add(heavy);
            flowLayoutPanel1.Controls.Add(medic);
            flowLayoutPanel1.Controls.Add(soldier);
            flowLayoutPanel1.Controls.Add(engineer);
            flowLayoutPanel1.Controls.Add(spy);
            flowLayoutPanel1.Controls.Add(sniper);
            flowLayoutPanel1.Controls.Add(demo);
            flowLayoutPanel1.Controls.Add(pyro);


            toolStripStatusLabel1.Text = "Initializing steamworks...";

            try
            {
                int error;
                client = ( SteamClient008 )Steamworks.CreateInterface(SteamClient008.InterfaceVersion, out error);

                if (client == null)
                {
                    throw new InvalidOperationException("Unable to create ISteamClient.");
                }

                pipe = client.CreateSteamPipe();
                if (pipe == SteamPipeHandle.InvalidHandle)
                {
                    throw new InvalidOperationException("Unable to create steam pipe.");
                }

                user = client.ConnectToGlobalUser(pipe);

                clientEngine = ( ClientEngine )Steamworks.CreateInterface(ClientEngine.InterfaceVersion, out error);

                if (clientEngine == null)
                {
                    throw new InvalidOperationException("Unable to create IClientEngine.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, "Unable to initialize steamworks. Please ensure the following:\n\n" +
                                " * steamclient.dll, tier0_s.dll, vstdlib_s.dll, are present in the running directory\n" +
                                " * You are logged into steam and are online.\n\nAdditional Details: " + ex.Message, "TF2 Stats Suite"
                                );

                this.Close();
                return;
            }

            toolStripStatusLabel1.Text = "Loading stats...";

            statsAcc = new StatsAccessor(client, pipe, user, 440);

            steamUser   = ( SteamUser012 )client.GetISteamUser(user, pipe, SteamUser012.InterfaceVersion);
            clientUtils = ( ClientUtils )clientEngine.GetIClientUtils(pipe, ClientUtils.InterfaceVersion);

            clientUtils.SetAppIDForCurrentPipe(new AppID(440));

            foreach (ClassEditControl cec in flowLayoutPanel1.Controls)
            {
                toolStripStatusLabel1.Text = "Loading stats for '" + cec.Class + "'...";
                cec.LoadStats(statsAcc);
                Application.DoEvents();
            }

            toolStripStatusLabel1.Text = "Stats fully loaded!";
        }
コード例 #19
0
ファイル: Steam.cs プロジェクト: Sharparam/SteamLib
        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);
        }
コード例 #20
0
        /// <summary>
        /// Initialize steam stuff
        /// </summary>
        private void Init()
        {
            // load library
            if (!Steamworks.Load())
            {
                Error("Unable to load steam library");
            }

            // load client
            if (m_SteamClient == null)
            {
                m_SteamClient = Steamworks.CreateInterface <ISteamClient010>();

                if (m_SteamClient == null)
                {
                    Error("Unable to create steam client interface");
                }
            }

            // load tube
            if (m_Pipe == 0)
            {
                m_Pipe = m_SteamClient.CreateSteamPipe();

                if (m_Pipe == 0)
                {
                    Error("Unable to create tube");
                }
            }

            // load user
            if (m_User == 0)
            {
                m_User = m_SteamClient.ConnectToGlobalUser(m_Pipe);

                if (m_User == 0)
                {
                    Error("Unable to connect to user");
                }
            }

            // load steam user
            if (m_SteamUser == null)
            {
                m_SteamUser = m_SteamClient.GetISteamUser <ISteamUser016>(m_User, m_Pipe);

                if (m_SteamUser == null)
                {
                    Error("Unable to create steam user interface");
                }
            }

            // load steam friends
            if (m_SteamFriends == null)
            {
                m_SteamFriends = m_SteamClient.GetISteamFriends <ISteamFriends009>(m_User, m_Pipe);

                if (m_SteamFriends == null)
                {
                    Error("Unable to create steam friends interface");
                }
            }

            // load steam friends 002
            if (m_SteamFriends002 == null)
            {
                m_SteamFriends002 = m_SteamClient.GetISteamFriends <ISteamFriends002>(m_User, m_Pipe);

                if (m_SteamFriends002 == null)
                {
                    Error("Unable to create steam friends (002) interface");
                }
            }


            // load steam apps
            if (m_SteamApps == null)
            {
                m_SteamApps = m_SteamClient.GetISteamApps <ISteamApps004>(m_User, m_Pipe);

                if (m_SteamApps == null)
                {
                    Error("Unable to create steam apps interface");
                }
            }

            // load steam utils
            if (m_SteamUtils == null)
            {
                m_SteamUtils = m_SteamClient.GetISteamUtils <ISteamUtils005>(m_Pipe);

                if (m_SteamUtils == null)
                {
                    Error("Unable to create steam utils interface");
                }
            }
        }
コード例 #21
0
ファイル: Program.cs プロジェクト: GEEKiDoS/TeknoMW3-M
        static void Main(string[] args)
        {
            int error;

            steamClient = (SteamClient008)Steamworks.CreateInterface(SteamClient008.InterfaceVersion, out error);
            if (steamClient == null)
            {
                Console.WriteLine("Unable to get SteamClient.");
                return;
            }

            pipe = steamClient.CreateSteamPipe();
            user = steamClient.ConnectToGlobalUser(pipe);


            _handler += new EventHandler(ConsoleEvent);
            SetConsoleCtrlHandler(_handler, true);

            steamFriends = ( SteamFriends001 )steamClient.GetISteamFriends(user, pipe, SteamFriends001.InterfaceVersion);
            steamUser    = (SteamUser012)steamClient.GetISteamUser(user, pipe, SteamUser012.InterfaceVersion);

            FriendsName = steamFriends.GetPersonaName();

            RelayTargets = new List <RelayUser>();

            ircClient = new IrcClient(RelayNick);
            ircClient.AlternateNickname = RelayNick + "`";

            ircClient.Debugger.Debugging = DebugMode.All;

            ConnectionParser connection = ircClient.ConnectionParser;
            MessageParser    message    = ircClient.MessageParser;

            connection.Connected   += new EventHandler <InfoEventArgs>(connection_Connected);
            message.ChannelMessage += new EventHandler <MessageEventArgs>(message_ChannelMessage);

            running = ircClient.Connect(RelayNetwork);

            DateTime lastUpdate = DateTime.Now;

            while (running)
            {
                ircClient.UpdateIn();

                if ((DateTime.Now - lastUpdate) >= RelayDelay && connected)
                {
                    ircClient.UpdateOut();
                    lastUpdate = DateTime.Now;
                }
                else
                {
                    ircClient.UpdateOut();
                }

                if (!connected)
                {
                    continue;
                }

                Callback        callback;
                SteamCallHandle steamCall;

                if (Steamworks.Steam_BGetCallback(pipe, out callback, out steamCall))
                {
                    Console.WriteLine("Callback: " + callback.CallbackNum);

                    if (callback.CallbackNum == FriendChatMsg.Callback)
                    {
                        FriendChatMsg chatMsg = ( FriendChatMsg )callback.CallbackObject;

                        SteamID sender   = new SteamID(chatMsg.Sender);
                        SteamID reciever = new SteamID(chatMsg.Reciever);

                        if (sender.Equals(steamUser.GetSteamID()))
                        {
                            Steamworks.Steam_FreeLastCallback(pipe);
                            continue;
                        }

                        string        msg;
                        FriendMsgType msgType;
                        steamFriends.GetChatMessage(reciever, ( int )chatMsg.ChatID, out msg, 400, out msgType);

                        if (msgType != FriendMsgType.Chat)
                        {
                            Steamworks.Steam_FreeLastCallback(pipe);
                            continue;
                        }

                        string senderStr = steamFriends.GetFriendPersonaName(sender);
                        msg = msg.Replace("\n", " ").Replace("\r", " ").Replace("DCC", "");

                        RelayUser ru = new RelayUser()
                        {
                            SteamID     = sender,
                            LastMessage = DateTime.Now.Subtract(TimeSpan.FromSeconds(1)),
                        };

                        if (!RelayTargets.Contains(ru))
                        {
                            RelayTargets.Add(ru);
                        }

                        RelayUser realUser = RelayTargets.Find(new Predicate <RelayUser>((ruser) => { return(ruser.SteamID.Equals(sender)); }));


                        if (msg.StartsWith("!relayon"))
                        {
                            realUser.RelayingIRC = true;
                            steamFriends.SendMsgToFriend(sender, FriendMsgType.ChatSent, "You are now added to the relay list.");
                        }
                        else if (msg.StartsWith("!relayoff"))
                        {
                            realUser.RelayingIRC = false;
                            steamFriends.SendMsgToFriend(sender, FriendMsgType.ChatSent, "You have been removed from the relay list.");
                        }
                        else
                        {
                            if (!realUser.RelayingIRC)
                            {
                                Steamworks.Steam_FreeLastCallback(pipe);
                                continue;
                            }

                            if ((DateTime.Now - realUser.LastMessage) >= TimeSpan.FromSeconds(1))
                            {
                                realUser.LastMessage = DateTime.Now;
                                ircClient.SendMessage(RelayChannel, senderStr + ": " + msg);
                            }
                            else
                            {
                                steamFriends.SendMsgToFriend(sender, FriendMsgType.ChatSent, "You are sending messages too fast.");
                            }
                        }
                    }

                    Steamworks.Steam_FreeLastCallback(pipe);
                }
            }
        }
コード例 #22
0
        public static void Initialize()
        {
            if (!Steamworks.Load())
            {
                throw new SteamException("Unable to load steamclient library.");
            }

            try
            {
                ClientEngine = Steamworks.CreateInterface <IClientEngine>("CLIENTENGINE_INTERFACE_VERSION002");
            }
            catch (Exception ex)
            {
                throw new SteamException("Unable to get IClientEngine interface.", ex);
            }

            try
            {
                SteamClient = Steamworks.CreateInterface <ISteamClient009>("SteamClient009");
            }
            catch (Exception ex)
            {
                throw new SteamException("Unable to get ISteamClient interface.", ex);
            }

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

            Pipe = ClientEngine.CreateSteamPipe();

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

            User = ClientEngine.ConnectToGlobalUser(Pipe);

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


            ClientFriends = GetInterface <IClientFriends>(
                () => { return(ClientEngine.GetIClientFriends(User, Pipe, "CLIENTFRIENDS_INTERFACE_VERSION001")); },
                "Unable to get IClientFriends interface."
                );

            SteamUser = GetInterface <ISteamUser014>(
                () => { return(SteamClient.GetISteamUser(User, Pipe, "SteamUser014")); },
                "Unable to get ISteamUser interface."
                );

            SteamUtils = GetInterface <ISteamUtils005>(
                () => { return(SteamClient.GetISteamUtils(Pipe, "SteamUtils005")); },
                "Unable to get ISteamUtils interface."
                );

            OnStateChange = new Callback <PersonaStateChange_t>(PersonaStateChange_t.k_iCallback);
        }
コード例 #23
0
ファイル: Program.cs プロジェクト: h4c3er/dota
        public static int Main()
        {
            //Environment.SetEnvironmentVariable("SteamAppId", "730");

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

            if (Steamworks.Load(true))
            {
                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 = 0;

            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:");

            ISteamClient012 steamclient  = Steamworks.CreateInterface <ISteamClient012>();
            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);
            }

            Console.ReadKey();

            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);
            }
            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.WriteLine("Current user SteamID: " + steamuser.GetSteamID());

            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);

            return(0);
        }
コード例 #24
0
        private static void StartAndWaitForSteam()
        {
            if (Process.GetProcessesByName("Steam").Length == 0 && Directory.Exists(steamDir))
            {
                Environment.SetEnvironmentVariable("SteamAppId", "000");
                Stopwatch stopwatch = null;
                if (!Steamworks.Load(true))
                {
                    Println("Steamworks could not be loaded, falling back to older method...", "warning");
                    LegacyStartAndWaitForSteam();
                    return;
                }

                if (!firstRun)
                {
                    steamclient = Steamworks.CreateInterface <ISteamClient017>();
                }

                if (steamclient == null)
                {
                    Println("Steamworks could not be loaded, falling back to older method...", "warning");
                    LegacyStartAndWaitForSteam();
                    return;
                }

                int pipe = steamclient.CreateSteamPipe();
                if (pipe == 0)
                {
                    Println("Starting Steam...");
                    Process.Start(steamDir + "\\Steam.exe", steamargs);
                    Println("Waiting for friends list to connect...");
                    stopwatch = Stopwatch.StartNew();
                    while (pipe == 0 && stopwatch.Elapsed.Seconds < Timeout)
                    {
                        pipe = steamclient.CreateSteamPipe();
                        Thread.Sleep(100);
                    }

                    stopwatch.Stop();
                    if (stopwatch.Elapsed.Seconds >= Timeout && pipe == 0)
                    {
                        Println("Steamworks could not be loaded, falling back to older method...", "warning");
                        steamclient.BShutdownIfAllPipesClosed();
                        LegacyStartAndWaitForSteam();
                        return;
                    }
                }

                int user = steamclient.ConnectToGlobalUser(pipe);
                if (user == 0 || user == -1)
                {
                    Println("Steamworks could not be loaded, falling back to older method...", "warning");
                    steamclient.BReleaseSteamPipe(pipe);
                    steamclient.BShutdownIfAllPipesClosed();
                    LegacyStartAndWaitForSteam();
                    return;
                }

                if (!firstRun)
                {
                    steamfriends = steamclient.GetISteamFriends <ISteamFriends015>(user, pipe);
                    firstRun     = true;
                }

                if (steamfriends == null)
                {
                    Println("Steamworks could not be loaded, falling back to older method...", "warning");
                    steamclient.BReleaseSteamPipe(pipe);
                    steamclient.BShutdownIfAllPipesClosed();
                    LegacyStartAndWaitForSteam();
                    return;
                }

                CallbackMsg_t callbackMsg         = default(CallbackMsg_t);
                bool          stateChangeDetected = false;
                stopwatch = Stopwatch.StartNew();
                while (!stateChangeDetected && stopwatch.Elapsed.Seconds < Timeout)
                {
                    while (Steamworks.GetCallback(pipe, ref callbackMsg) && !stateChangeDetected && stopwatch.Elapsed.Seconds < Timeout)
                    {
                        if (callbackMsg.m_iCallback == PersonaStateChange_t.k_iCallback)
                        {
                            PersonaStateChange_t onPersonaStateChange = (PersonaStateChange_t)Marshal.PtrToStructure(callbackMsg.m_pubParam, typeof(PersonaStateChange_t));
                            if (onPersonaStateChange.m_nChangeFlags.HasFlag(EPersonaChange.k_EPersonaChangeComeOnline))
                            {
                                stateChangeDetected = true;
                                Println("Friends list connected!", "success");
                                break;
                            }
                        }

                        Steamworks.FreeLastCallback(pipe);
                    }

                    Thread.Sleep(100);
                }

                stopwatch.Stop();
                Steamworks.FreeLastCallback(pipe);
                steamclient.ReleaseUser(pipe, user);
                steamclient.BReleaseSteamPipe(pipe);
                steamclient.BShutdownIfAllPipesClosed();
                if (stopwatch.Elapsed.Seconds >= Timeout)
                {
                    Println("Steamworks could not be loaded, falling back to older method...", "warning");
                    LegacyStartAndWaitForSteam();
                    return;
                }
            }
        }
コード例 #25
0
        private int LoadSteam()
        {
            if (Steamworks.Load(true))
            {
                Console.WriteLine("Ok, Steam Works!");
            }
            else
            {
                MessageBox.Show("Failed, Steam Works!");
                Console.WriteLine("Failed, Steam Works!");

                return(-1);
            }

            steam006 = Steamworks.CreateSteamInterface <ISteam006>();
            TSteamError steamError = new TSteamError();

            version = new StringBuilder();
            steam006.ClearError(ref steamError);

            steamclient  = Steamworks.CreateInterface <ISteamClient012>();
            clientengine = Steamworks.CreateInterface <IClientEngine>();
            pipe         = steamclient.CreateSteamPipe();
            user         = steamclient.ConnectToGlobalUser(pipe);
            steamuser    = steamclient.GetISteamUser <ISteamUser016>(user, pipe);

            steamutils      = steamclient.GetISteamUtils <ISteamUtils005>(pipe);
            userstats002    = steamclient.GetISteamUserStats <ISteamUserStats002>(user, pipe);
            userstats010    = steamclient.GetISteamUserStats <ISteamUserStats010>(user, pipe);
            steamfriends013 = steamclient.GetISteamFriends <ISteamFriends013>(user, pipe);
            steamfriends002 = steamclient.GetISteamFriends <ISteamFriends002>(user, pipe);
            clientuser      = clientengine.GetIClientUser <IClientUser>(user, pipe);
            clientfriends   = clientengine.GetIClientFriends <IClientFriends>(user, pipe);

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


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


            Console.Write("GetVersion: ");


            if (steam006.GetVersion(version, (uint)version.Capacity) != 0)
            {
                Console.WriteLine("Ok (" + version.ToString() + "), Version!");
            }
            else
            {
                Console.WriteLine("Failed, Get Version!");
                return(-1);
            }

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


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


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


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


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


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

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

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

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

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

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

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

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

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


            return(0);
        }