mirror of
https://github.com/a2x/cs2-dumper.git
synced 2025-05-14 04:55:35 +08:00
Write enum member values in hexadecimal
This commit is contained in:
parent
413ae710b1
commit
8b79c3ba8d
@ -73,7 +73,7 @@ impl<'a> CodeGen for Item<'a> {
|
|||||||
fn to_cs(&self, results: &Results, indent_size: usize) -> Result<String> {
|
fn to_cs(&self, results: &Results, indent_size: usize) -> Result<String> {
|
||||||
match self {
|
match self {
|
||||||
Item::Buttons(buttons) => buttons.to_cs(results, indent_size),
|
Item::Buttons(buttons) => buttons.to_cs(results, indent_size),
|
||||||
Item::Interfaces(interfaces) => interfaces.to_cs(results, indent_size),
|
Item::Interfaces(ifaces) => ifaces.to_cs(results, indent_size),
|
||||||
Item::Offsets(offsets) => offsets.to_cs(results, indent_size),
|
Item::Offsets(offsets) => offsets.to_cs(results, indent_size),
|
||||||
Item::Schemas(schemas) => schemas.to_cs(results, indent_size),
|
Item::Schemas(schemas) => schemas.to_cs(results, indent_size),
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ impl<'a> CodeGen for Item<'a> {
|
|||||||
fn to_hpp(&self, results: &Results, indent_size: usize) -> Result<String> {
|
fn to_hpp(&self, results: &Results, indent_size: usize) -> Result<String> {
|
||||||
match self {
|
match self {
|
||||||
Item::Buttons(buttons) => buttons.to_hpp(results, indent_size),
|
Item::Buttons(buttons) => buttons.to_hpp(results, indent_size),
|
||||||
Item::Interfaces(interfaces) => interfaces.to_hpp(results, indent_size),
|
Item::Interfaces(ifaces) => ifaces.to_hpp(results, indent_size),
|
||||||
Item::Offsets(offsets) => offsets.to_hpp(results, indent_size),
|
Item::Offsets(offsets) => offsets.to_hpp(results, indent_size),
|
||||||
Item::Schemas(schemas) => schemas.to_hpp(results, indent_size),
|
Item::Schemas(schemas) => schemas.to_hpp(results, indent_size),
|
||||||
}
|
}
|
||||||
@ -91,7 +91,7 @@ impl<'a> CodeGen for Item<'a> {
|
|||||||
fn to_json(&self, results: &Results, indent_size: usize) -> Result<String> {
|
fn to_json(&self, results: &Results, indent_size: usize) -> Result<String> {
|
||||||
match self {
|
match self {
|
||||||
Item::Buttons(buttons) => buttons.to_json(results, indent_size),
|
Item::Buttons(buttons) => buttons.to_json(results, indent_size),
|
||||||
Item::Interfaces(interfaces) => interfaces.to_json(results, indent_size),
|
Item::Interfaces(ifaces) => ifaces.to_json(results, indent_size),
|
||||||
Item::Offsets(offsets) => offsets.to_json(results, indent_size),
|
Item::Offsets(offsets) => offsets.to_json(results, indent_size),
|
||||||
Item::Schemas(schemas) => schemas.to_json(results, indent_size),
|
Item::Schemas(schemas) => schemas.to_json(results, indent_size),
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ impl<'a> CodeGen for Item<'a> {
|
|||||||
fn to_rs(&self, results: &Results, indent_size: usize) -> Result<String> {
|
fn to_rs(&self, results: &Results, indent_size: usize) -> Result<String> {
|
||||||
match self {
|
match self {
|
||||||
Item::Buttons(buttons) => buttons.to_rs(results, indent_size),
|
Item::Buttons(buttons) => buttons.to_rs(results, indent_size),
|
||||||
Item::Interfaces(interfaces) => interfaces.to_rs(results, indent_size),
|
Item::Interfaces(ifaces) => ifaces.to_rs(results, indent_size),
|
||||||
Item::Offsets(offsets) => offsets.to_rs(results, indent_size),
|
Item::Offsets(offsets) => offsets.to_rs(results, indent_size),
|
||||||
Item::Schemas(schemas) => schemas.to_rs(results, indent_size),
|
Item::Schemas(schemas) => schemas.to_rs(results, indent_size),
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,10 @@ impl CodeGen for SchemaMap {
|
|||||||
|fmt| {
|
|fmt| {
|
||||||
for enum_ in enums {
|
for enum_ in enums {
|
||||||
let ty = match enum_.ty.as_str() {
|
let ty = match enum_.ty.as_str() {
|
||||||
"int8" => "sbyte",
|
"uint8" => "byte",
|
||||||
"int16" => "short",
|
"uint16" => "ushort",
|
||||||
"int32" => "int",
|
"uint32" => "uint",
|
||||||
"int64" => "long",
|
"uint64" => "ulong",
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -40,13 +40,13 @@ impl CodeGen for SchemaMap {
|
|||||||
fmt.block(
|
fmt.block(
|
||||||
&format!("public enum {} : {}", sanitize_name(&enum_.name), ty),
|
&format!("public enum {} : {}", sanitize_name(&enum_.name), ty),
|
||||||
|fmt| {
|
|fmt| {
|
||||||
let members: Vec<_> = enum_
|
let members = enum_
|
||||||
.members
|
.members
|
||||||
.iter()
|
.iter()
|
||||||
.map(|member| {
|
.map(|member| {
|
||||||
format!("{} = {}", member.name, member.value)
|
format!("{} = {:#X}", member.name, member.value)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect::<Vec<_>>()
|
||||||
.join(",\n");
|
.join(",\n");
|
||||||
|
|
||||||
writeln!(fmt, "{}", members)
|
writeln!(fmt, "{}", members)
|
||||||
@ -111,10 +111,10 @@ impl CodeGen for SchemaMap {
|
|||||||
|fmt| {
|
|fmt| {
|
||||||
for enum_ in enums {
|
for enum_ in enums {
|
||||||
let ty = match enum_.ty.as_str() {
|
let ty = match enum_.ty.as_str() {
|
||||||
"int8" => "int8_t",
|
"uint8" => "uint8_t",
|
||||||
"int16" => "int16_t",
|
"uint16" => "uint16_t",
|
||||||
"int32" => "int32_t",
|
"uint32" => "uint32_t",
|
||||||
"int64" => "int64_t",
|
"uint64" => "uint64_t",
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -128,13 +128,13 @@ impl CodeGen for SchemaMap {
|
|||||||
ty
|
ty
|
||||||
),
|
),
|
||||||
|fmt| {
|
|fmt| {
|
||||||
let members: Vec<_> = enum_
|
let members = enum_
|
||||||
.members
|
.members
|
||||||
.iter()
|
.iter()
|
||||||
.map(|member| {
|
.map(|member| {
|
||||||
format!("{} = {}", member.name, member.value)
|
format!("{} = {:#X}", member.name, member.value)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect::<Vec<_>>()
|
||||||
.join(",\n");
|
.join(",\n");
|
||||||
|
|
||||||
writeln!(fmt, "{}", members)
|
writeln!(fmt, "{}", members)
|
||||||
@ -276,10 +276,10 @@ impl CodeGen for SchemaMap {
|
|||||||
|fmt| {
|
|fmt| {
|
||||||
for enum_ in enums {
|
for enum_ in enums {
|
||||||
let ty = match enum_.ty.as_str() {
|
let ty = match enum_.ty.as_str() {
|
||||||
"int8" => "i8",
|
"uint8" => "u8",
|
||||||
"int16" => "i16",
|
"uint16" => "u16",
|
||||||
"int32" => "i32",
|
"uint32" => "u32",
|
||||||
"int64" => "i64",
|
"uint64" => "u64",
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -295,13 +295,13 @@ impl CodeGen for SchemaMap {
|
|||||||
|fmt| {
|
|fmt| {
|
||||||
// TODO: Handle the case where multiple members share
|
// TODO: Handle the case where multiple members share
|
||||||
// the same value.
|
// the same value.
|
||||||
let members: Vec<_> = enum_
|
let members = enum_
|
||||||
.members
|
.members
|
||||||
.iter()
|
.iter()
|
||||||
.map(|member| {
|
.map(|member| {
|
||||||
format!("{} = {}", member.name, member.value)
|
format!("{} = {:#X}", member.name, member.value)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect::<Vec<_>>()
|
||||||
.join(",\n");
|
.join(",\n");
|
||||||
|
|
||||||
writeln!(fmt, "{}", members)
|
writeln!(fmt, "{}", members)
|
||||||
|
@ -23,10 +23,10 @@ impl SchemaEnumInfoData {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn type_name(&self) -> &str {
|
pub fn type_name(&self) -> &str {
|
||||||
match self.alignment {
|
match self.alignment {
|
||||||
1 => "int8",
|
1 => "uint8",
|
||||||
2 => "int16",
|
2 => "uint16",
|
||||||
4 => "int32",
|
4 => "uint32",
|
||||||
8 => "int64",
|
8 => "uint64",
|
||||||
_ => "unknown",
|
_ => "unknown",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user