| 
									
										
										
										
											2023-10-31 17:23:15 +01:00
										 |  |  | use std::error::Error;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 17:59:53 +02:00
										 |  |  | use serde::{Deserialize, Serialize};
 | 
					
						
							| 
									
										
										
										
											2024-11-28 22:41:25 +01:00
										 |  |  | use vergen_gitcl::{Emitter, GitclBuilder};
 | 
					
						
							| 
									
										
										
										
											2024-01-08 00:22:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 17:59:53 +02:00
										 |  |  | #[derive(Clone, Deserialize, Serialize)]
 | 
					
						
							|  |  |  | struct InfoJson {
 | 
					
						
							|  |  |  |     build_number: usize,
 | 
					
						
							|  |  |  |     timestamp: String | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-31 17:23:15 +01:00
										 |  |  | fn download(url: &str, to: &str) -> Result<(), Box<dyn Error>> {
 | 
					
						
							|  |  |  |     let content = reqwest::blocking::get(url)
 | 
					
						
							|  |  |  |         .unwrap_or_else(|_| panic!("Downloading \"{to}\""))
 | 
					
						
							|  |  |  |         .text()
 | 
					
						
							|  |  |  |         .expect("Convert response to text");
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     std::fs::write(to, content)
 | 
					
						
							| 
									
										
										
										
											2023-11-28 01:14:37 +01:00
										 |  |  |     .expect("Write to file");
 | 
					
						
							| 
									
										
										
										
											2023-10-31 17:23:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Ok(())
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 17:59:53 +02:00
										 |  |  | fn build_number() -> Result<(), Box<dyn Error>> {
 | 
					
						
							|  |  |  |     let content = reqwest::blocking::get("https://raw.githubusercontent.com/a2x/cs2-dumper/main/output/info.json")
 | 
					
						
							|  |  |  |         .unwrap_or_else(|_| panic!("Downloading info.json"))
 | 
					
						
							|  |  |  |         .text()
 | 
					
						
							|  |  |  |         .expect("Convert response to text");
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let info = serde_json::from_str::<InfoJson>(&content)?;
 | 
					
						
							|  |  |  |     println!("cargo:rustc-env=CS2_BUILD_NUMBER={}", info.build_number);
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Ok(())
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-31 17:23:15 +01:00
										 |  |  | fn main() -> Result<(), Box<dyn Error>> {
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     download(
 | 
					
						
							| 
									
										
										
										
											2024-11-28 22:41:25 +01:00
										 |  |  |         "https://raw.githubusercontent.com/a2x/cs2-dumper/refs/heads/main/output/client_dll.rs",
 | 
					
						
							| 
									
										
										
										
											2024-04-03 17:59:53 +02:00
										 |  |  |         "./src/dma/cs2dumper/client_mod.rs"
 | 
					
						
							| 
									
										
										
										
											2023-11-28 01:14:37 +01:00
										 |  |  |     ).expect("Failed to download build file \"client.dll.rs\"");
 | 
					
						
							| 
									
										
										
										
											2023-10-31 17:23:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     download(
 | 
					
						
							| 
									
										
										
										
											2024-11-28 22:41:25 +01:00
										 |  |  |         "https://raw.githubusercontent.com/a2x/cs2-dumper/refs/heads/main/output/offsets.rs",
 | 
					
						
							| 
									
										
										
										
											2024-04-03 17:59:53 +02:00
										 |  |  |         "./src/dma/cs2dumper/offsets_mod.rs"
 | 
					
						
							| 
									
										
										
										
											2023-11-28 01:14:37 +01:00
										 |  |  |     ).expect("Failed to download build file \"offsets.rs\"");
 | 
					
						
							| 
									
										
										
										
											2023-10-31 17:23:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     download(
 | 
					
						
							| 
									
										
										
										
											2024-11-28 22:41:25 +01:00
										 |  |  |         "https://raw.githubusercontent.com/a2x/cs2-dumper/refs/heads/main/output/engine2_dll.rs",
 | 
					
						
							| 
									
										
										
										
											2024-04-03 17:59:53 +02:00
										 |  |  |         "./src/dma/cs2dumper/engine2_mod.rs"
 | 
					
						
							| 
									
										
										
										
											2023-11-28 01:14:37 +01:00
										 |  |  |     ).expect("Failed to download build file \"engine2.dll.rs\"");
 | 
					
						
							| 
									
										
										
										
											2023-10-31 17:23:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-03 17:59:53 +02:00
										 |  |  |     build_number()?;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-28 22:41:25 +01:00
										 |  |  |     let gitcl = GitclBuilder::all_git()?;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Emitter::new()
 | 
					
						
							|  |  |  |         .add_instructions(&gitcl)?
 | 
					
						
							| 
									
										
										
										
											2024-01-08 00:22:24 +01:00
										 |  |  |         .emit()?;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-31 17:23:15 +01:00
										 |  |  |     Ok(())
 | 
					
						
							|  |  |  | }
 |