|
1 | | -use obfstr::obfstr; |
2 | | -use thiserror::Error; |
3 | | - |
4 | | -#[derive(Error, Debug)] |
5 | | -pub enum InterfaceError { |
6 | | - #[error("failed to find any memory driver")] |
7 | | - NoDriverFound, |
8 | | - |
9 | | - #[error("failed to load driver: {0}")] |
10 | | - DriverLoadingError(#[from] libloading::Error), |
11 | | - |
12 | | - #[error("missing command handler execute export")] |
13 | | - DriverMissingExecuterExport, |
14 | | - |
15 | | - #[error("missing startup export")] |
16 | | - DriverMissingStartupExport, |
17 | | - |
18 | | - #[error( |
19 | | - "protocol miss match (expected {interface_protocol} but driver supports {driver_protocol})" |
20 | | - )] |
21 | | - DriverProtocolMismatch { |
22 | | - interface_protocol: u32, |
23 | | - driver_protocol: u32, |
24 | | - }, |
25 | | - |
26 | | - #[error("command failed: {message}")] |
27 | | - CommandGenericError { message: String }, |
28 | | - |
29 | | - #[error("feature is not supported")] |
30 | | - FeatureUnsupported, |
31 | | - |
32 | | - #[error("the driver is unavailable")] |
33 | | - InitializeDriverUnavailable, |
34 | | - |
35 | | - #[error("process unknown")] |
36 | | - ProcessUnknown, |
37 | | - |
38 | | - #[error("process is ubiquitous")] |
39 | | - ProcessUbiquitous, |
40 | | - |
41 | | - #[error("failed to access memory")] |
42 | | - MemoryAccessFailed, |
43 | | - |
44 | | - #[error("failed to access memory because the target memory has been paged out")] |
45 | | - MemoryAccessPagedOut, |
46 | | - |
47 | | - #[error("metrics report type too long")] |
48 | | - ReportTypeTooLong, |
49 | | - |
50 | | - #[error("failed to allocate a properly sized buffer")] |
51 | | - BufferAllocationFailed, |
52 | | -} |
53 | | - |
54 | | -pub type IResult<T> = std::result::Result<T, InterfaceError>; |
55 | | - |
56 | | -impl InterfaceError { |
57 | | - pub fn detailed_message(&self) -> Option<String> { |
58 | | - Some(match self { |
59 | | - &InterfaceError::NoDriverFound => { |
60 | | - [ |
61 | | - obfstr!("** PLEASE READ CAREFULLY **"), |
62 | | - obfstr!("No driver interface for the driver communication found."), |
63 | | - #[cfg(windows)] |
64 | | - obfstr!("Ensure that the according \"driver_[...].dll\" file is present."), |
65 | | - #[cfg(unix)] |
66 | | - obfstr!("Ensure that the according \"libdriver_[...].so\" file is present."), |
67 | | - obfstr!(""), |
68 | | - obfstr!("For more information please refer to"), |
69 | | - obfstr!("https://wiki.valth.run/troubleshooting/overlay/driver_interface_missing"), |
70 | | - ].join("\n") |
71 | | - }, |
72 | | - &InterfaceError::InitializeDriverUnavailable => { |
73 | | - [ |
74 | | - obfstr!("** PLEASE READ CAREFULLY **"), |
75 | | - obfstr!("Could not communicate with the driver."), |
76 | | - obfstr!("Most likely the Valthrun driver did not load successfully."), |
77 | | - obfstr!(""), |
78 | | - obfstr!("For more information please refer to"), |
79 | | - obfstr!( |
80 | | - "https://wiki.valth.run/troubleshooting/overlay/driver_interface_unavailable" |
81 | | - ), |
82 | | - ].join("\n") |
83 | | - } |
84 | | - &InterfaceError::DriverProtocolMismatch { |
85 | | - interface_protocol, |
86 | | - driver_protocol, |
87 | | - } => { |
88 | | - [ |
89 | | - obfstr!("Driver protocol mismatch."), |
90 | | - obfstr!("The driver interface is too old or new to be used with the current version of this application."), |
91 | | - &format!("{}: {}", obfstr!("Driver protocol version"), driver_protocol), |
92 | | - &format!("{}: {}", obfstr!("Application protocol version"), interface_protocol), |
93 | | - obfstr!(""), |
94 | | - obfstr!("For more information please refer to"), |
95 | | - obfstr!( |
96 | | - "https://wiki.valth.run/troubleshooting/overlay/driver_protocol_mismatch" |
97 | | - ), |
98 | | - ].join("\n") |
99 | | - } |
100 | | - &InterfaceError::ProcessUnknown => { |
101 | | - [ |
102 | | - obfstr!("Could not find CS2 process."), |
103 | | - obfstr!("Please start CS2 prior to executing this application!"), |
104 | | - ].join("\n") |
105 | | - } |
106 | | - _ => return None, |
107 | | - }) |
108 | | - } |
109 | | -} |
| 1 | +use obfstr::obfstr; |
| 2 | +use thiserror::Error; |
| 3 | + |
| 4 | +#[derive(Error, Debug)] |
| 5 | +pub enum InterfaceError { |
| 6 | + #[error("failed to find any memory driver")] |
| 7 | + NoDriverFound, |
| 8 | + |
| 9 | + #[error("failed to load driver: {0}")] |
| 10 | + DriverLoadingError(#[from] libloading::Error), |
| 11 | + |
| 12 | + #[error("missing command handler execute export")] |
| 13 | + DriverMissingExecuterExport, |
| 14 | + |
| 15 | + #[error("missing startup export")] |
| 16 | + DriverMissingStartupExport, |
| 17 | + |
| 18 | + #[error( |
| 19 | + "protocol miss match (expected {interface_protocol} but driver supports {driver_protocol})" |
| 20 | + )] |
| 21 | + DriverProtocolMismatch { |
| 22 | + interface_protocol: u32, |
| 23 | + driver_protocol: u32, |
| 24 | + }, |
| 25 | + |
| 26 | + #[error("command failed: {message}")] |
| 27 | + CommandGenericError { message: String }, |
| 28 | + |
| 29 | + #[error("feature is not supported")] |
| 30 | + FeatureUnsupported, |
| 31 | + |
| 32 | + #[error("the driver is unavailable")] |
| 33 | + InitializeDriverUnavailable, |
| 34 | + |
| 35 | + #[error("process unknown")] |
| 36 | + ProcessUnknown, |
| 37 | + |
| 38 | + #[error("process is ubiquitous")] |
| 39 | + ProcessUbiquitous, |
| 40 | + |
| 41 | + #[error("failed to access memory")] |
| 42 | + MemoryAccessFailed, |
| 43 | + |
| 44 | + #[error("failed to access memory because the target memory has been paged out")] |
| 45 | + MemoryAccessPagedOut, |
| 46 | + |
| 47 | + #[error("metrics report type too long")] |
| 48 | + ReportTypeTooLong, |
| 49 | + |
| 50 | + #[error("failed to allocate a properly sized buffer")] |
| 51 | + BufferAllocationFailed, |
| 52 | +} |
| 53 | + |
| 54 | +pub type IResult<T> = std::result::Result<T, InterfaceError>; |
| 55 | + |
| 56 | +impl InterfaceError { |
| 57 | + pub fn detailed_message(&self) -> Option<String> { |
| 58 | + Some(match self { |
| 59 | + &InterfaceError::NoDriverFound => { |
| 60 | + [ |
| 61 | + obfstr!("** PLEASE READ CAREFULLY **"), |
| 62 | + obfstr!("No driver interface for the driver communication found."), |
| 63 | + #[cfg(windows)] |
| 64 | + obfstr!("Ensure that the according \"driver_[...].dll\" file is present."), |
| 65 | + #[cfg(unix)] |
| 66 | + obfstr!("Ensure that the according \"libdriver_[...].so\" file is present."), |
| 67 | + obfstr!(""), |
| 68 | + obfstr!("For more information please refer to"), |
| 69 | + obfstr!("https://wiki.valth.run/link/3"), |
| 70 | + ].join("\n") |
| 71 | + }, |
| 72 | + &InterfaceError::InitializeDriverUnavailable => { |
| 73 | + [ |
| 74 | + obfstr!("** PLEASE READ CAREFULLY **"), |
| 75 | + obfstr!("Could not communicate with the driver."), |
| 76 | + obfstr!("Most likely the Valthrun driver did not load successfully."), |
| 77 | + obfstr!(""), |
| 78 | + obfstr!("For more information please refer to"), |
| 79 | + obfstr!( |
| 80 | + "https://wiki.valth.run/link/4" |
| 81 | + ), |
| 82 | + ].join("\n") |
| 83 | + } |
| 84 | + &InterfaceError::DriverProtocolMismatch { |
| 85 | + interface_protocol, |
| 86 | + driver_protocol, |
| 87 | + } => { |
| 88 | + [ |
| 89 | + obfstr!("Driver protocol mismatch."), |
| 90 | + obfstr!("The driver interface is too old or new to be used with the current version of this application."), |
| 91 | + &format!("{}: {}", obfstr!("Driver protocol version"), driver_protocol), |
| 92 | + &format!("{}: {}", obfstr!("Application protocol version"), interface_protocol), |
| 93 | + obfstr!(""), |
| 94 | + obfstr!("For more information please refer to"), |
| 95 | + obfstr!( |
| 96 | + "https://wiki.valth.run/link/5" |
| 97 | + ), |
| 98 | + ].join("\n") |
| 99 | + } |
| 100 | + &InterfaceError::ProcessUnknown => { |
| 101 | + [ |
| 102 | + obfstr!("Could not find CS2 process."), |
| 103 | + obfstr!("Please start CS2 prior to executing this application!"), |
| 104 | + ].join("\n") |
| 105 | + } |
| 106 | + _ => return None, |
| 107 | + }) |
| 108 | + } |
| 109 | +} |
0 commit comments