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
7struct FormUtil
8{
17 static RE::TESForm* GetFormFromString(const std::string& a_form_id_string)
18 {
19 if (a_form_id_string.empty())
20 {
21 return nullptr;
22 }
23
24 if (a_form_id_string.find('|') != std::string::npos)
25 {
26 std::istringstream ss{a_form_id_string};
27 std::string plugin, id;
28 std::getline(ss, plugin, '|');
29 std::getline(ss, id);
30
31 if (plugin.empty() || id.empty())
32 {
33 return nullptr;
34 }
35
36 RE::FormID rawFormID{};
37 std::istringstream(id) >> std::hex >> rawFormID;
38
39 if (!rawFormID)
40 {
41 return nullptr;
42 }
43
44 if (auto* dataHandler = RE::TESDataHandler::GetSingleton())
45 {
46 auto* form = dataHandler->LookupForm(rawFormID, plugin);
47 return form;
48 }
49 return nullptr;
50 }
51
52 if (auto* form = RE::TESForm::LookupByEditorID(a_form_id_string))
53 {
54 return form;
55 }
56 return nullptr;
57 }
58
61 static RE::SpellItem* GetSpellFromString(const std::string& a_form_id_string)
62 {
63 const auto form = GetFormFromString(a_form_id_string);
64 return form ? form->As<RE::SpellItem>() : nullptr;
65 }
66
69 static RE::EffectSetting* GetEffectSettingFromString(const std::string& a_form_id_string)
70 {
71 const auto form = GetFormFromString(a_form_id_string);
72 return form ? form->As<RE::EffectSetting>() : nullptr;
73 }
74
77 static RE::TESObjectWEAP* GetWeaponFromString(const std::string& a_form_id_string)
78 {
79 const auto form = GetFormFromString(a_form_id_string);
80 return form ? form->As<RE::TESObjectWEAP>() : nullptr;
81 }
82};
83} // namespace StyyxUtil
Definition st-actor.h:7
Definition st-forms.h:8
static RE::SpellItem * GetSpellFromString(const std::string &a_form_id_string)
Get Form from a string. GetFormFromString for usage details
Definition st-forms.h:61
static RE::TESObjectWEAP * GetWeaponFromString(const std::string &a_form_id_string)
Get Form from a string. GetFormFromString for usage details
Definition st-forms.h:77
static RE::EffectSetting * GetEffectSettingFromString(const std::string &a_form_id_string)
Get Form from a string. GetFormFromString for usage details
Definition st-forms.h:69
static RE::TESForm * GetFormFromString(const std::string &a_form_id_string)
Get Form from a string.
Definition st-forms.h:17