commonlibsse_ng\re\g/
GameSettingCollection.rs1use core::fmt;
7use std::collections::HashMap;
8
9use crate::re::Setting::{Setting, SettingValue};
10use crate::re::SettingCollectionMap::SettingCollectionMap;
11use crate::re::offsets_rtti::RTTI_GameSettingCollection;
12use crate::re::offsets_vtable::VTABLE_GameSettingCollection;
13use crate::rel::id::VariantID;
14
15#[repr(C)]
23#[derive(Clone, PartialEq)]
24pub struct GameSettingCollection {
25 pub __base: SettingCollectionMap<Setting>, }
27const _: () = {
28 assert!(core::mem::offset_of!(GameSettingCollection, __base) == 0x0);
29 assert!(core::mem::size_of::<GameSettingCollection>() == 0x140);
30};
31
32impl fmt::Debug for GameSettingCollection {
33 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34 let mut map = f.debug_map();
35 for (key, value) in self.__base.settings.__base.__base.__base.iter() {
36 let key_str = unsafe {
37 if key.is_null() {
38 "<null>"
39 } else {
40 core::ffi::CStr::from_ptr(*key).to_str().unwrap_or("<invalid utf8>")
41 }
42 };
43 let value = unsafe { value.as_ref().map(|p| p.get_value()).unwrap_or_default() };
44 map.entry(&key_str, &value);
45 }
46 map.finish()
47 }
48}
49
50impl GameSettingCollection {
51 pub const RTTI: VariantID = RTTI_GameSettingCollection;
53
54 pub const VTABLE: [VariantID; 1] = VTABLE_GameSettingCollection;
56
57 #[commonlibsse_ng_derive_internal::relocate(
59 cast_as = "*mut *mut GameSettingCollection",
60 default = "None",
61 deref_once,
62 id(se = 514622, ae = 400782)
63 )]
64 pub fn get_singleton() -> Option<&'static GameSettingCollection> {
65 |deref_type: DerefType| unsafe { deref_type.as_ref() }
66 }
67
68 pub fn to_hashmap(&self) -> HashMap<&str, SettingValue<'_>> {
69 let mut map = std::collections::HashMap::new();
70 for (key, value) in self.__base.settings.__base.__base.__base.iter() {
71 let key_str = unsafe {
72 if key.is_null() {
73 "<null>"
74 } else {
75 core::ffi::CStr::from_ptr(*key).to_str().unwrap_or("<invalid utf8>")
76 }
77 };
78 let value = unsafe { value.as_ref().map(|p| p.get_value()).unwrap_or_default() };
79 map.insert(key_str, value);
80 }
81 map
82 }
83}
84
85#[repr(C)]
89pub struct GameSettingCollectionVtbl {
90 pub CxxDrop: fn(this: &mut GameSettingCollection),
92
93 pub WriteSetting: fn(this: &mut GameSettingCollection, setting: &Setting) -> bool,
95
96 pub ReadSetting: fn(this: &mut GameSettingCollection, setting: &mut Setting) -> bool,
98
99 pub OpenHandle: fn(this: &mut GameSettingCollection, create: bool) -> bool,
101
102 pub CloseHandle: fn(this: &mut GameSettingCollection) -> bool,
104
105 pub Unk_0A: fn(this: &mut GameSettingCollection),
107}
108
109impl Default for GameSettingCollectionVtbl {
110 #[inline]
111 fn default() -> Self {
112 Self::new()
113 }
114}
115
116impl GameSettingCollectionVtbl {
117 #[inline]
119 pub const fn new() -> Self {
120 const fn CxxDrop(_this: &mut GameSettingCollection) {}
121
122 const fn WriteSetting(_this: &mut GameSettingCollection, _setting: &Setting) -> bool {
123 false
124 }
125
126 const fn ReadSetting(_this: &mut GameSettingCollection, _setting: &mut Setting) -> bool {
127 true
128 }
129
130 const fn OpenHandle(_this: &mut GameSettingCollection, _create: bool) -> bool {
131 true
132 }
133
134 const fn CloseHandle(_this: &mut GameSettingCollection) -> bool {
135 true
136 }
137
138 const fn Unk_0A(_this: &mut GameSettingCollection) {}
139
140 Self { CxxDrop, WriteSetting, ReadSetting, OpenHandle, CloseHandle, Unk_0A }
141 }
142}