styyx-util 1.0
Utility Header for SKSE Plugin development
Loading...
Searching...
No Matches
st-forms.h
Go to the documentation of this file.
1#pragma once
2
3namespace StyyxUtil {
4
5
6 struct FormUtil {
15 static RE::TESForm* GetFormFromString(const std::string& a_form_id_string)
16 {
17 if (a_form_id_string.empty()) {
18 return nullptr;
19 }
20
21 if (a_form_id_string.find('|') != std::string::npos) {
22 std::istringstream ss{ a_form_id_string };
23 std::string plugin, id;
24 std::getline(ss, plugin, '|');
25 std::getline(ss, id);
26
27 if (plugin.empty() || id.empty()) {
28 return nullptr;
29 }
30
31 RE::FormID rawFormID{};
32 std::istringstream(id) >> std::hex >> rawFormID;
33
34 if (!rawFormID) {
35 return nullptr;
36 }
37
38 if (auto* dataHandler = RE::TESDataHandler::GetSingleton()) {
39 auto* form = dataHandler->LookupForm(rawFormID, plugin);
40 return form;
41 }
42 return nullptr;
43 }
44
45 if (auto* form = RE::TESForm::LookupByEditorID(a_form_id_string)) {
46 return form;
47 }
48 return nullptr;
49 }
50
53 static RE::SpellItem* GetSpellFromString(const std::string& a_form_id_string)
54 {
55 const auto form = GetFormFromString(a_form_id_string);
56 return form ? form->As<RE::SpellItem>() : nullptr;
57 }
58
61 static RE::EffectSetting* GetEffectSettingFromString(const std::string& a_form_id_string)
62 {
63 const auto form = GetFormFromString(a_form_id_string);
64 return form ? form->As<RE::EffectSetting>() : nullptr;
65 }
66
69 static RE::TESObjectWEAP* GetWeaponFromString(const std::string& a_form_id_string)
70 {
71 const auto form = GetFormFromString(a_form_id_string);
72 return form ? form->As<RE::TESObjectWEAP>() : nullptr;
73 }
74
75 };
76}
Definition st-actor.h:7
Definition st-forms.h:6
static RE::SpellItem * GetSpellFromString(const std::string &a_form_id_string)
Get Form from a string. GetFormFromString for usage details
Definition st-forms.h:53
static RE::TESObjectWEAP * GetWeaponFromString(const std::string &a_form_id_string)
Get Form from a string. GetFormFromString for usage details
Definition st-forms.h:69
static RE::EffectSetting * GetEffectSettingFromString(const std::string &a_form_id_string)
Get Form from a string. GetFormFromString for usage details
Definition st-forms.h:61
static RE::TESForm * GetFormFromString(const std::string &a_form_id_string)
Get Form from a string.
Definition st-forms.h:15