From 7c0ebc07daa8028ea7c27eb5e757ed64bcd3ed94 Mon Sep 17 00:00:00 2001 From: NotAndreh <39744335+NotAndreh@users.noreply.github.com> Date: Tue, 22 Jul 2025 17:27:53 +0200 Subject: [PATCH] Better logging in case of errors and new checks --- Cargo.lock | 10 +++++----- Cargo.toml | 2 +- src/main.rs | 33 +++++++++++++++++++++++++++------ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 938000e..549e00a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,15 +124,15 @@ checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "rustix" -version = "1.0.7" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" +checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] @@ -143,7 +143,7 @@ checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" [[package]] name = "steam-ticket-generator" -version = "1.1.0" +version = "1.2.0" dependencies = [ "base64", "dialoguer", @@ -153,7 +153,7 @@ dependencies = [ [[package]] name = "steamworks-sys" version = "0.12.0" -source = "git+https://github.com/Noxime/steamworks-rs#d9ab145702f246019ad59658615547513a9558ee" +source = "git+https://github.com/Noxime/steamworks-rs#bf8738b4ac640b176e3c5117a87bf82ae7817298" [[package]] name = "syn" diff --git a/Cargo.toml b/Cargo.toml index 2cd0881..b37638a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "steam-ticket-generator" authors = ["NotAndreh"] -version = "1.1.0" +version = "1.2.0" edition = "2024" [dependencies] diff --git a/src/main.rs b/src/main.rs index 8e7b446..554515e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,8 @@ -use std::{io::{Read, Write}, time::Duration}; +use std::{error::Error, io::{Read, Write}, time::Duration}; use base64::{prelude::BASE64_STANDARD, Engine as _}; use dialoguer::theme::ColorfulTheme; +use steamworks_sys::ESteamAPIInitResult; fn main() { let app_id = dialoguer::Input::::with_theme(&ColorfulTheme::default()) @@ -9,13 +10,34 @@ fn main() { .interact() .unwrap(); + if let Err(e) = generate_ticket(app_id) { + eprintln!("Error while generating ticket: {}", e); + eprintln!("Make sure you have the Steam client running and logged in. Check also that the account owns the game"); + return; + } + + println!("Press Enter to exit..."); + std::io::stdin().read(&mut [0]).unwrap(); +} + +fn generate_ticket(app_id: u32) -> Result<(), Box> { unsafe { std::env::set_var("SteamAppId", &app_id.to_string()); std::env::set_var("SteamGameId", app_id.to_string()); - steamworks_sys::SteamAPI_InitFlat(std::ptr::null_mut()); + let init_result = steamworks_sys::SteamAPI_InitFlat(std::ptr::null_mut()); steamworks_sys::SteamAPI_ManualDispatch_Init(); + match init_result { + ESteamAPIInitResult::k_ESteamAPIInitResult_FailedGeneric => { + return Err("Failed to initialize Steam API".into()); + }, + ESteamAPIInitResult::k_ESteamAPIInitResult_NoSteamClient => { + return Err("Steam client is not running".into()); + } + _ => {} + } + let user = steamworks_sys::SteamAPI_SteamUser_v023(); steamworks_sys::SteamAPI_ISteamUser_RequestEncryptedAppTicket(user, std::ptr::null_mut(), 0); @@ -31,7 +53,7 @@ fn main() { let success = steamworks_sys::SteamAPI_ISteamUser_GetEncryptedAppTicket(user, ticket.as_mut_ptr() as *mut _, 2048, &mut ticket_len); if !success { - panic!("Failed to get encrypted app ticket"); + return Err("Failed to get encrypted app ticket, does the account own the game?".into()); } ticket.truncate(ticket_len as usize); @@ -56,9 +78,8 @@ fn main() { } } } - - println!("Press Enter to exit..."); - std::io::stdin().read(&mut [0]).unwrap(); + + Ok(()) } fn run_callbacks(pipe: i32) -> Option {