From be0ae2c6d4a70331c35fb8c6103af50df57a8fce Mon Sep 17 00:00:00 2001 From: powerof3 <32599957+powerof3@users.noreply.github.com> Date: Tue, 12 Sep 2023 20:42:44 +0530 Subject: [PATCH] feat: add formtypes (#34) --- CommonLibSF/include/RE/A/Actor.h | 1 + CommonLibSF/include/RE/B/BGSKeyword.h | 1 + CommonLibSF/include/RE/B/BGSListForm.h | 1 + CommonLibSF/include/RE/B/BGSLocation.h | 1 + CommonLibSF/include/RE/B/BGSScene.h | 1 + CommonLibSF/include/RE/F/FORM_ENUM_STRING.h | 21 ++ CommonLibSF/include/RE/F/FormTypes.h | 273 ++++++++++++++++++++ CommonLibSF/include/RE/T/TESForm.h | 20 +- CommonLibSF/include/RE/T/TESNPC.h | 1 + CommonLibSF/include/RE/T/TESObjectARMO.h | 1 + CommonLibSF/include/RE/T/TESObjectCELL.h | 1 + CommonLibSF/include/RE/T/TESObjectREFR.h | 1 + CommonLibSF/include/RE/T/TESQuest.h | 1 + CommonLibSF/include/RE/T/TESRace.h | 1 + CommonLibSF/include/RE/T/TESTopicInfo.h | 1 + CommonLibSF/include/SFSE/Impl/PCH.h | 2 + CommonLibSF/src/RE/F/FormTypes.cpp | 22 ++ 17 files changed, 341 insertions(+), 9 deletions(-) create mode 100644 CommonLibSF/include/RE/F/FORM_ENUM_STRING.h create mode 100644 CommonLibSF/include/RE/F/FormTypes.h create mode 100644 CommonLibSF/src/RE/F/FormTypes.cpp diff --git a/CommonLibSF/include/RE/A/Actor.h b/CommonLibSF/include/RE/A/Actor.h index d6df0ed0..6aaf42c7 100644 --- a/CommonLibSF/include/RE/A/Actor.h +++ b/CommonLibSF/include/RE/A/Actor.h @@ -9,6 +9,7 @@ namespace RE { public: SF_RTTI_VTABLE(Actor); + SF_FORMTYPE(ACHR); ~Actor() override; // 00 diff --git a/CommonLibSF/include/RE/B/BGSKeyword.h b/CommonLibSF/include/RE/B/BGSKeyword.h index 3195b513..97859989 100644 --- a/CommonLibSF/include/RE/B/BGSKeyword.h +++ b/CommonLibSF/include/RE/B/BGSKeyword.h @@ -8,5 +8,6 @@ namespace RE { public: SF_RTTI_VTABLE(BGSKeyword); + SF_FORMTYPE(KYWD); }; } diff --git a/CommonLibSF/include/RE/B/BGSListForm.h b/CommonLibSF/include/RE/B/BGSListForm.h index 2cd0a1c9..c796aa34 100644 --- a/CommonLibSF/include/RE/B/BGSListForm.h +++ b/CommonLibSF/include/RE/B/BGSListForm.h @@ -9,5 +9,6 @@ namespace RE { public: SF_RTTI_VTABLE(BGSListForm); + SF_FORMTYPE(FLST); }; } diff --git a/CommonLibSF/include/RE/B/BGSLocation.h b/CommonLibSF/include/RE/B/BGSLocation.h index f3d80a6a..37ffe42b 100644 --- a/CommonLibSF/include/RE/B/BGSLocation.h +++ b/CommonLibSF/include/RE/B/BGSLocation.h @@ -10,5 +10,6 @@ namespace RE { public: SF_RTTI_VTABLE(BGSLocation); + SF_FORMTYPE(LCTN); }; } diff --git a/CommonLibSF/include/RE/B/BGSScene.h b/CommonLibSF/include/RE/B/BGSScene.h index 78344ba1..a1c448fa 100644 --- a/CommonLibSF/include/RE/B/BGSScene.h +++ b/CommonLibSF/include/RE/B/BGSScene.h @@ -11,6 +11,7 @@ namespace RE { public: SF_RTTI_VTABLE(BGSScene); + SF_FORMTYPE(SCEN); // }; diff --git a/CommonLibSF/include/RE/F/FORM_ENUM_STRING.h b/CommonLibSF/include/RE/F/FORM_ENUM_STRING.h new file mode 100644 index 00000000..b5e72ba3 --- /dev/null +++ b/CommonLibSF/include/RE/F/FORM_ENUM_STRING.h @@ -0,0 +1,21 @@ +#pragma once + +namespace RE +{ + enum class FormType; + + struct FORM_ENUM_STRING + { + public: + [[nodiscard]] static std::span GetFormEnumString() + { + REL::Relocation formEnumString{ REL::Offset(0x50136A0) }; + return { *formEnumString }; + } + + // members + const char* formString; // 00 + FormType formType; // 08 + }; + static_assert(sizeof(FORM_ENUM_STRING) == 0x10); +} diff --git a/CommonLibSF/include/RE/F/FormTypes.h b/CommonLibSF/include/RE/F/FormTypes.h new file mode 100644 index 00000000..ab04de6a --- /dev/null +++ b/CommonLibSF/include/RE/F/FormTypes.h @@ -0,0 +1,273 @@ +#pragma once + +namespace RE +{ + enum class FormType + { + kNONE = 0, // 00 + kTES4, // 01 + kGRUP, // 02 + kGMST, // 03 + kKYWD, // 04 BGSKeyword + kFFKW, // 05 BGSFormFolderKeywordList + kLCRT, // 06 BGSLocationRefType + kAACT, // 07 BGSAction + kTRNS, // 08 BGSTransform + kTXST, // 09 BGSTextureSet + kGLOB, // 0A TESGlobal + kDMGT, // 0B BGSDamageType + kCLAS, // 0C TESClass + kFACT, // 0D TESFaction + kAFFE, // 0E BGSAffinityEvent + kHDPT, // 0F BGSHeadPart + kEYES, // 10 TESEyes + kRACE, // 11 TESRace + kSOUN, // 12 TESSound + kSECH, // 13 BGSSoundEcho + kASPC, // 14 BGSAcousticSpace + kAOPF, // 15 BGSAudioOcclusionPrimitive + kSKIL, // 16 + kMGEF, // 17 EffectSetting + kSCPT, // 18 Script + kLTEX, // 19 TESLandTexture + kPDCL, // 1A BGSProjectedDecal + kENCH, // 1B EnchantmentItem + kSPEL, // 1C SpellItem + kSCRL, // 1D ScrollItem + kACTI, // 1E TESObjectACTI + kTACT, // 1F BGSTalkingActivator + kCURV, // 20 BGSCurveForm + kCUR3, // 21 BGSCurve3DForm + kARMO, // 22 TESObjectARMO + kBOOK, // 23 TESObjectBOOK + kCONT, // 24 TESObjectCONT + kDOOR, // 25 TESObjectDOOR + kINGR, // 26 IngredientItem + kLIGH, // 27 TESObjectLIGH + kMISC, // 28 TESObjectMISC + kSTAT, // 29 TESObjectSTAT + kSCOL, // 2A BGSStaticCollection + kPKIN, // 2B BGSPackIn + kMSTT, // 2C BGSMovableStatic + kGRAS, // 2D TESGrass + kFLOR, // 2E TESFlora + kFURN, // 2F TESFurniture + kWEAP, // 30 TESObjectWEAP + kAMMO, // 31 TESAmmo + kNPC_, // 32 TESNPC + kLVLN, // 33 TESLevCharacter + kLVLP, // 34 BGSLevPackIn + kKEYM, // 35 TESKey + kALCH, // 36 AlchemyItem + kIDLM, // 37 BGSIdleMarker + kBMMO, // 38 BGSBiomeMarkerObject + kNOTE, // 39 BGSNote + kPROJ, // 3A BGSProjectile + kHAZD, // 3B BGSHazard + kBNDS, // 3C BGSBendableSpline + kSLGM, // 3D TESSoulGem + kTERM, // 3E BGSTerminal + kLVLI, // 3F TESLevItem + kGBFT, // 40 BGSGenericBaseFormTemplate + kGBFM, // 41 BGSGenericBaseForm + kLVLB, // 42 BGSLevGenericBaseForm + kWTHR, // 43 TESWeather + kWTHS, // 44 BGSWeatherSettingsForm + kCLMT, // 45 TESClimate + kSPGD, // 46 BGSShaderParticleGeometryData + kREGN, // 47 TESRegion + kNAVI, // 48 NavMeshInfoMap + kCELL, // 49 TESObjectCELL + kREFR, // 4A TESObjectREFR + kACHR, // 4B Actor + kPMIS, // 4C MissileProjectile + kPARW, // 4D ArrowProjectile + kPGRE, // 4E GrenadeProjectile + kPBEA, // 4F BeamProjectile + kPFLA, // 50 FlameProjectile + kPCON, // 51 ConeProjectile + kPPLA, // 52 PlasmaProjectile + kPBAR, // 53 BarrierProjectile + kPEMI, // 54 EmitterProjectile + kPHZD, // 55 Hazard + kWRLD, // 56 TESWorldSpace + kNAVM, // 57 NavMesh + kTLOD, // 58 + kDIAL, // 59 TESTopic + kINFO, // 5A TESTopicInfo + kQUST, // 5B TESQuest + kIDLE, // 5C TESIdleForm + kPACK, // 5D TESPackage + kCSTY, // 5E TESCombatStyle + kLSCR, // 5F TESLoadScreen + kLVSP, // 60 TESLevSpell + kANIO, // 61 TESObjectANIO + kWATR, // 62 TESWaterForm + kEFSH, // 63 TESEffectShader + kTOFT, // 64 + kEXPL, // 65 BGSExplosion + kDEBR, // 66 BGSDebris + kIMGS, // 67 TESImageSpace + kIMAD, // 68 TESImageSpaceModifier + kFLST, // 69 BGSListForm + kPERK, // 6A BGSPerk + kBPTD, // 6B BGSBodyPartData + kADDN, // 6C BGSAddonNode + kAVIF, // 6D ActorValueInfo + kCAMS, // 6E BGSCameraShot + kCPTH, // 6F BGSCameraPath + kVTYP, // 70 BGSVoiceType + kMATT, // 71 BGSMaterialType + kIPCT, // 72 BGSImpactData + kIPDS, // 73 BGSImpactDataSet + kARMA, // 74 TESObjectARMA + kLCTN, // 75 BGSLocation + kMESG, // 76 BGSMessage + kRGDL, // 77 + kDOBJ, // 78 BGSDefaultObjectManager + kDFOB, // 79 BGSDefaultObject + kLGTM, // 7A BGSLightingTemplate + kMUSC, // 7B BGSMusicType + kFSTP, // 7C BGSFootstep + kFSTS, // 7D BGSFootstepSet + kSMBN, // 7E BGSStoryManagerBranchNode + kSMQN, // 7F BGSStoryManagerQuestNode + kSMEN, // 80 BGSStoryManagerEventNode + kDLBR, // 81 BGSDialogueBranch + kMUST, // 82 BGSMusicTrackFormWrapper + kDLVW, // 83 + kWOOP, // 84 TESWordOfPower + kSHOU, // 85 TESShout + kEQUP, // 86 BGSEquipSlot + kRELA, // 87 BGSRelationship + kSCEN, // 88 BGSScene + kASTP, // 89 BGSAssociationType + kOTFT, // 8A BGSOutfit + kARTO, // 8B BGSArtObject + kMATO, // 8C BGSMaterialObject + kMOVT, // 8D BGSMovementType + kDUAL, // 8E BGSDualCastData + kCOLL, // 8F BGSCollisionLayer + kCLFM, // 90 BGSColorForm + kREVB, // 91 BGSReverbParameters + kRFGP, // 92 BGSReferenceGroup + kAMDL, // 93 BGSAimModel + kAAMD, // 94 BGSAimAssistModel + kMAAM, // 95 BGSMeleeAimAssistModel + kLAYR, // 96 + kCOBJ, // 97 BGSConstructibleObject + kOMOD, // 98 BGSMod::Attachment::Mod + kZOOM, // 99 BGSAimDownSightModel + kINNR, // 9A BGSInstanceNamingRules + kKSSM, // 9B BGSSoundKeywordMapping + kSCCO, // 9C + kAORU, // 9D BGSAttractionRule + kSTAG, // 9E BGSSoundTagSet + kIRES, // 9F BGSResource + kBIOM, // A0 BGSBiome + kNOCM, // A1 NavMeshObstacleCoverManager + kLENS, // A2 BGSLensFlare + kLSPR, // A3 + kOVIS, // A4 BGSObjectVisibilityManager + kDLYR, // A5 + kSTND, // A6 BGSSnapTemplateNode + kSTMP, // A7 BGSSnapTemplate + kGCVR, // A8 BGSGroundCover + kMRPH, // A9 BGSMorphableObject + kTRAV, // AA BGSTraversal + kRSGD, // AB BGSResourceGenerationData + kOSWP, // AC BGSObjectSwap + kATMO, // AD BGSAtmosphere + kLVSC, // AE BGSLevSpaceCell + kSPCH, // AF BGSSpeechChallengeObject + kRESO, // B0 + kAAPD, // B1 BGSAimAssistPoseData + kVOLI, // B2 BGSVolumetricLighting + kSFBK, // B3 BGSSurface::Block + kSFPC, // B4 + kSFPT, // B5 BGSSurface::Pattern + kSFTR, // B6 BGSSurface::Tree + kPCMT, // B7 BGSPlanetContentManagerTree + kBMOD, // B8 BGSBoneModifier + kSTBH, // B9 BGSSnapBehavior + kPNDT, // BA BGSPlanet::PlanetData + kIUTF, // BB + kCNDF, // BC BGSConditionForm + kPCBN, // BD BGSPlanetContentManagerBranchNode + kPCCN, // BE BGSPlanetContentManagerContentNode + kSTDT, // BF BSGalaxy::BGSStar + kWWED, // C0 BGSWwiseEventForm + kRSPJ, // C1 BGSResearchProjectForm + kAOPS, // C2 BGSAimOpticalSightModel + kAMBS, // C3 BGSAmbienceSet + kWBAR, // C4 BGSWeaponBarrelModel + kPTST, // C5 BGSSurface::PatternStyle + kLMSW, // C6 BGSLayeredMaterialSwap + kFORC, // C7 BGSForceData + kTMLM, // C8 BGSTerminalMenu + kEFSQ, // C9 BGSEffectSequenceForm + kSDLT, // CA BGSSecondaryDamageList + kMTPT, // CB BGSMaterialPathForm + kCLDF, // CC BGSCloudForm + kFOGV, // CD BGSFogVolumeForm + kWKMF, // CE BGSWwiseKeywordMapping + kLGDI, // CF BGSLegendaryItem + kPSDC, // D0 BGSParticleSystemDefineCollection + kSUNP, // D1 BSGalaxy::BGSSunPresetForm + kPMFT, // D2 BGSPhotoModeFeature + kTODD, // D3 BGSTimeOfDayData + kAVMD, // D4 BGSAVMData + kPERS, // D5 TESDataHandlerPersistentCreatedUtil::BGSPersistentIDsForm + kCHAL, // D6 BGSChallengeForm + + kTotal // D7 + }; + + [[nodiscard]] const char* FormTypeToString(FormType a_formType); + [[nodiscard]] FormType StringToFormType(std::string_view a_formType); +} + +namespace std +{ + [[nodiscard]] inline std::string to_string(RE::FormType a_formType) + { + return RE::FormTypeToString(a_formType); + } +} + +namespace fmt +{ + template <> + struct formatter + { + template + constexpr auto parse(ParseContext& a_ctx) + { + return a_ctx.begin(); + } + + template + auto format(const RE::FormType& a_formType, FormatContext& a_ctx) + { + return fmt::format_to(a_ctx.out(), "{}", RE::FormTypeToString(a_formType)); + } + }; +} + +#ifdef __cpp_lib_format +namespace std +{ + template + struct formatter : std::formatter + { + template + auto format(RE::FormType a_formType, FormatContext& a_ctx) + { + return formatter::format(RE::FormTypeToString(a_formType), a_ctx); + } + }; +} +#endif + +#define SF_FORMTYPE(TYPE) \ + inline static constexpr auto FORMTYPE = RE::FormType::k##TYPE diff --git a/CommonLibSF/include/RE/T/TESForm.h b/CommonLibSF/include/RE/T/TESForm.h index 5af5d01b..995c0101 100644 --- a/CommonLibSF/include/RE/T/TESForm.h +++ b/CommonLibSF/include/RE/T/TESForm.h @@ -119,16 +119,18 @@ namespace RE virtual void Unk_60(); // 60 virtual void Unk_61(); // 61 + [[nodiscard]] FormType GetFormType() const noexcept { return *formType; } + // members - std::uint64_t sourceFiles; // 18 - TESFileContainer - std::uint32_t unk20; // 20 - std::uint32_t unk24; // 24 - std::uint32_t formFlags; // 28 - std::uint32_t unk2C; // 2C - std::uint32_t formID; // 30 - std::uint8_t unk34; // 34 - also flag - std::uint8_t unk35; // 35 - std::uint8_t formType; // 36 + std::uint64_t sourceFiles; // 18 - TESFileContainer + std::uint32_t unk20; // 20 + std::uint32_t unk24; // 24 + std::uint32_t formFlags; // 28 + std::uint32_t unk2C; // 2C + std::uint32_t formID; // 30 + std::uint8_t unk34; // 34 - also flag + std::uint8_t unk35; // 35 + stl::enumeration formType; // 36 }; static_assert(sizeof(TESForm) == 0x38); } diff --git a/CommonLibSF/include/RE/T/TESNPC.h b/CommonLibSF/include/RE/T/TESNPC.h index 737c908a..227f96fb 100644 --- a/CommonLibSF/include/RE/T/TESNPC.h +++ b/CommonLibSF/include/RE/T/TESNPC.h @@ -17,6 +17,7 @@ namespace RE { public: SF_RTTI_VTABLE(TESNPC); + SF_FORMTYPE(NPC_); // members /* diff --git a/CommonLibSF/include/RE/T/TESObjectARMO.h b/CommonLibSF/include/RE/T/TESObjectARMO.h index f53352b0..522ea14f 100644 --- a/CommonLibSF/include/RE/T/TESObjectARMO.h +++ b/CommonLibSF/include/RE/T/TESObjectARMO.h @@ -9,5 +9,6 @@ namespace RE { public: SF_RTTI_VTABLE(TESObjectARMO); + SF_FORMTYPE(ARMO); }; } diff --git a/CommonLibSF/include/RE/T/TESObjectCELL.h b/CommonLibSF/include/RE/T/TESObjectCELL.h index d49ef7ff..256f6767 100644 --- a/CommonLibSF/include/RE/T/TESObjectCELL.h +++ b/CommonLibSF/include/RE/T/TESObjectCELL.h @@ -11,6 +11,7 @@ namespace RE { public: SF_RTTI_VTABLE(TESObjectCELL); + SF_FORMTYPE(CELL); // }; diff --git a/CommonLibSF/include/RE/T/TESObjectREFR.h b/CommonLibSF/include/RE/T/TESObjectREFR.h index 21f03fbf..d31ef2d2 100644 --- a/CommonLibSF/include/RE/T/TESObjectREFR.h +++ b/CommonLibSF/include/RE/T/TESObjectREFR.h @@ -24,6 +24,7 @@ namespace RE { public: SF_RTTI_VTABLE(TESObjectREFR); + SF_FORMTYPE(REFR); ~TESObjectREFR() override; // 00 diff --git a/CommonLibSF/include/RE/T/TESQuest.h b/CommonLibSF/include/RE/T/TESQuest.h index f268997c..abc3a5b0 100644 --- a/CommonLibSF/include/RE/T/TESQuest.h +++ b/CommonLibSF/include/RE/T/TESQuest.h @@ -6,5 +6,6 @@ namespace RE { public: SF_RTTI_VTABLE(TESQuest); + SF_FORMTYPE(QUST); }; } diff --git a/CommonLibSF/include/RE/T/TESRace.h b/CommonLibSF/include/RE/T/TESRace.h index 944f52b9..a0e24169 100644 --- a/CommonLibSF/include/RE/T/TESRace.h +++ b/CommonLibSF/include/RE/T/TESRace.h @@ -9,5 +9,6 @@ namespace RE { public: SF_RTTI_VTABLE(TESRace); + SF_FORMTYPE(RACE); }; } diff --git a/CommonLibSF/include/RE/T/TESTopicInfo.h b/CommonLibSF/include/RE/T/TESTopicInfo.h index c3e2d053..a759730d 100644 --- a/CommonLibSF/include/RE/T/TESTopicInfo.h +++ b/CommonLibSF/include/RE/T/TESTopicInfo.h @@ -8,6 +8,7 @@ namespace RE { public: SF_RTTI_VTABLE(TESTopicInfo); + SF_FORMTYPE(INFO); // members std::uint64_t unk38; // 38 diff --git a/CommonLibSF/include/SFSE/Impl/PCH.h b/CommonLibSF/include/SFSE/Impl/PCH.h index 8949f0e9..78ba539e 100644 --- a/CommonLibSF/include/SFSE/Impl/PCH.h +++ b/CommonLibSF/include/SFSE/Impl/PCH.h @@ -671,4 +671,6 @@ namespace REL #include "RE/Offsets_RTTI.h" #include "RE/Offsets_VTABLE.h" +#include "RE/F/FormTypes.h" + #undef cdecl // Workaround for Clang. diff --git a/CommonLibSF/src/RE/F/FormTypes.cpp b/CommonLibSF/src/RE/F/FormTypes.cpp new file mode 100644 index 00000000..eff4c0d3 --- /dev/null +++ b/CommonLibSF/src/RE/F/FormTypes.cpp @@ -0,0 +1,22 @@ +#include "RE/F/FormTypes.h" + +#include "RE/F/FORM_ENUM_STRING.h" + +namespace RE +{ + const char* FormTypeToString(FormType a_formType) + { + return FORM_ENUM_STRING::GetFormEnumString()[stl::to_underlying(a_formType)].formString; + } + + FormType StringToFormType(std::string_view a_formType) + { + for (auto& iter : FORM_ENUM_STRING::GetFormEnumString()) { + if (_stricmp(iter.formString, a_formType.data()) == 0) { + return iter.formType; + } + } + + return FormType::kNONE; + } +}