Example #1
0
        static int TryFindAppIdInternal()
        {
            var steam_app_id = Environment.GetEnvironmentVariable("SteamAppId");

            if (steam_app_id != null)
            {
                try
                {
                    return(Int32.Parse(steam_app_id));
                }
                catch
                {
                }
            }

            ClientLog.WriteLine("SteamAppId not set.");


            // Try and read steam_appid.txt
            // steamclient does this in a number of ways...
            // It will first check the local working directory for steam_appid.txt
            // It will then check in the host apps directory for steam_appid.txt

            // Otherwise it will just be an empty string

            try
            {
                steam_app_id = File.ReadAllText("steam_appid.txt");
                return(Int32.Parse(steam_app_id));
            }
            catch
            {
                ClientLog.WriteLine("steam_appid.txt not in current working directory.");
            }

            try
            {
                var main_exe = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
                var exe_path = Path.GetDirectoryName(main_exe);
                ClientLog.WriteLine("note: exe_path: '{0}'", exe_path);

                steam_app_id = Path.Combine(exe_path, "steam_appid.txt");

                return(Int32.Parse(steam_app_id));
            }
            catch
            {
                ClientLog.WriteLine("steam_appid.txt not found in root exe folder.");
            }

            return(0);
        }
Example #2
0
        public static void TryFindAppId(int pipe_id)
        {
            var found = TryFindAppIdInternal();

            if (found == 0)
            {
                return;
            }

            ClientLog.WriteLine("Found appid {0}", found);

            Server.SetAppId(pipe_id, found);
        }
Example #3
0
        public static object CallSerializedFunction(int pipe_id, int client_id, int interface_id, string name, object[] args)
        {
            // The pipeid that comes in here is the real unique pipe_id, the message PipeId is the clientside unique pipeid

            if (client_id == -1 && interface_id == -1)
            {
                // TODO: handle special server related functions
                switch (name)
                {
                case "CreateClient":
                {
                    return(CreateNewClient(pipe_id));
                }

                case "CreateInterface":
                {
                    return(CreateInterfaceNoUser(pipe_id, (string)args[0]).InterfaceId);
                }

                case "NextCallback":
                {
                    return(CallbackHandler.GetCallbackForPipe(pipe_id));
                }
                }

                return(null);
            }
            else if (client_id == -1 && interface_id != -1)
            {
                var iface = NoUserInterface[interface_id];
                var mi    = iface.Implementation.methods.Find(x => x.Name == name);

                if (mi != null)
                {
                    return(mi.Invoke(NoUserInterface[interface_id], args));
                }

                ClientLog.WriteLine("Unable to find method \"{0}\" from interface \"{1}\"", name, iface.Implementation.name);

                return(null);
            }

            if (!GetClient(client_id).ConnectedPipes.Contains(pipe_id))
            {
                ClientLog.WriteLine("Pipe {0} is not connected to Client {1}", pipe_id, client_id);
                return(null);
            }

            return(GetClient(client_id).CallSerializedFunction(pipe_id, interface_id, name, args));
        }
Example #4
0
        public static CallbackMsg?GetCallback(int pipe_id)
        {
            // Ask the server for the callback
            var c = Server.NextCallback(pipe_id);

            // No new callback from server
            if (c == null)
            {
                return(null);
            }

            bool found = CallbackAllocHandles.TryGetValue(pipe_id, out IntPtr current_value);

            if (found && current_value != IntPtr.Zero)
            {
                // This mimics the behaviour of the steam functions that do this
                ClientLog.WriteLine("Attempt to alloc new callback before old one has been freed\nTHIS IS A PROGRAMMING ERROR");

                // Free it for them...
                FreeCallback(pipe_id);
            }

            // Allocate space for the data portion of the msg
            CallbackAllocHandles[pipe_id] = Marshal.AllocHGlobal(c.data.Length);
            Marshal.Copy(c.data, 0, CallbackAllocHandles[pipe_id], c.data.Length);

            return(new CallbackMsg
            {
                // Make sure to convert from the server userid to the client userid
                // TODO: we should be very explicit about this
                user_id = c.user_id,
                callback_id = c.callback_id,
                data = CallbackAllocHandles[pipe_id],
                data_size = c.data.Length,
            });
        }