Advertisement
expired6978

ModInfo

Jun 11th, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.40 KB | None | 0 0
  1. /* GameData.h */
  2.  
  3. #pragma once
  4.  
  5. #include "GameTypes.h"
  6. #include "GameForms.h"
  7. #include "GameObjects.h"
  8. #include "GameReferences.h"
  9.  
  10. class BSFile;
  11.  
  12. struct FormRecordData
  13. {
  14.     UInt8       typeID;     // corresponds to kFormType_XXX
  15.     UInt32      typeCode;   // i.e. 'GMST', 'FACT'
  16.     UInt32      unk08;      // only seen zero
  17. };
  18.  
  19. struct ChunkHeader
  20. {
  21.     UInt32  type : 4;   // i.e. 'XGRD', 'DATA'
  22.     UInt16  size : 2;
  23. };
  24.  
  25. struct ModInfo      // referred to by game as TESFile
  26. {
  27.     ModInfo();
  28.     ~ModInfo();
  29.  
  30.     // 18 info about currently loading form
  31.     struct FormInfo
  32.     {
  33.         UInt32      recordType;         // 00 i.e. 'FACT', 'GMST'
  34.         UInt32      unk04;              // 04 looks like size of entire record
  35.         UInt32      formFlags;          // 08 copied to TESForm->flags
  36.         UInt32      formID;             // 0C
  37.         UInt32      unk10;              // 10
  38.         UInt16      unk14;              // 14 always initialized to 0F on SaveForm.
  39.         UInt16      unk16;
  40.     };
  41.  
  42.     tList<UInt32>                       unkList;            // 000
  43.     UInt32 /*NiTPointerMap<TESFile*>*/  * pointerMap;       // 008
  44.     UInt32                              unk00C;             // 00C
  45.     BSFile*                             unkFile;            // 010
  46.     UInt32                              unk014;             // 014
  47.     void                                * unk018;           // 018 seen all zeroes. size unknown
  48.     void                                * unk01C;           // 01C as above
  49.     char                                name[0x104];        // 020
  50.     char                                filepath[0x104];    // 124
  51.     UInt32                              unk228;             // 228
  52.     UInt32                              unk22C;             // init'd to dword_F469CC (0x2800) same val as BSFile+10?
  53.     UInt32                              unk230;             // 230
  54.     UInt32                              unk234;             // 234
  55.     UInt32                              unk238;             // 238
  56.     UInt32                              unk23C;             // 23C
  57.     FormInfo                            formInfo;           // 240
  58.     ChunkHeader                         subRecord;          // 258
  59.     UInt32                              unk260;             // 260
  60.     UInt32                              fileOffset;         // 264
  61.     UInt32                              dataOffset;         // 268 index into dataBuf
  62.     UInt32                              subrecordBytesRead; // 26C generates error on Read if != expected length
  63.     UInt32                      unk268[(0x298-0x270) >> 2]; // 270
  64.     UInt8                               unk298;             // 298
  65.     UInt8                               bIsBigEndian;       // 299
  66.     UInt8                               unk29A;             // 29A
  67.     UInt8                               pad29B;
  68.     WIN32_FIND_DATA                     fileData;           // 29C
  69.     float                               unk3DC;             // 3DC init'd to 0.94
  70.     UInt32                              unk3E0;             // 3E0
  71.     UInt32                              flags;              // 3E4 init'd to 0x00000800. 4000 and 40000 do stuff
  72.     UInt8                               unk3E8;             // 3E8
  73.     UInt8                               pad3E9[3];
  74.     UInt32                              unk3EC;             // 3EC
  75.     UInt32                              unk3F0;             // 3F0
  76.     UInt32                              unk3F4;             // 3F4
  77.     UInt32                              unk3F8;             // 3F8
  78.     UInt32                              numRefMods;         // 3FC related to modindex; see 4472D0
  79.                                                                 // formIDs in mod are as saved in GECK, must fix up at runtime
  80.     ModInfo                             ** refModInfo;      // 400 used to look up modInfo based on fixed mod index, double-check
  81.     UInt32                              unk404;             // 404
  82.     UInt32                              unk408;             // 408
  83.     UInt8                               modIndex;           // 40C init to 0xFF
  84.     UInt8                               pad40D[3];
  85.     BSString                            author;             // 410
  86.     BSString                            description;        // 418
  87.     void                                * dataBuf;          // 420
  88.     UInt32                              unk424;             // 424 looks like size of entire record
  89.     UInt8                               unk428;             // 428
  90.     UInt8                               pad429[3];
  91.    
  92.     bool IsLoaded() const { return true; }
  93. };
  94.  
  95. struct ModList
  96. {
  97.     tList<ModInfo>      modInfoList;
  98.     UInt32              loadedModCount;
  99.     ModInfo*            loadedMods[0xFF];
  100. };
  101.  
  102. class DataHandler
  103. {
  104. public:
  105.     static DataHandler* GetSingleton();
  106.  
  107.     // loads of tArrays of object types, at least a good number in formType order
  108.     UInt32                      unk000;
  109.     UInt32                      unk004;
  110.     UnkFormArray                unk008;
  111.     UnkFormArray                unk014;
  112.     UnkFormArray                unk020;
  113.     UnkFormArray                unk02C;
  114.     tArray<BGSKeyword*>         keywords;
  115.     tArray<BGSLocationRefType*> locRefTypes;
  116.     tArray<BGSAction*>          actions;
  117.     tArray<BGSTextureSet*>      textureSets;
  118.     tArray<BGSMenuIcon*>            menuIcons;
  119.     tArray<TESGlobal*>          globals;
  120.     tArray<TESClass*>           classes;
  121.     tArray<TESFaction*>         factions;
  122.     tArray<BGSHeadPart*>            headParts;
  123.     tArray<TESEyes*>                eyes;
  124.     tArray<TESRace*>                races;
  125.     tArray<TESSound*>           sounds;
  126.     tArray<BGSAcousticSpace*>   acousticSpaces;
  127.     UnkFormArray                unkSkills;
  128.     tArray<EffectSetting*>      magicEffects;
  129.     tArray<Script*>             scripts;
  130.     tArray<TESLandTexture*>     landTextures;
  131.     tArray<EnchantmentItem*>    enchantments;
  132.     tArray<SpellItem*>          spellItems;
  133.     tArray<ScrollItem*>         scrolls;
  134.     tArray<TESObjectACTI*>      activators;
  135.     tArray<BGSTalkingActivator*>    talkingActivators;
  136.     tArray<TESObjectARMO*>      armors;
  137.     tArray<TESObjectBOOK*>      books;
  138.     tArray<TESObjectCONT*>      containers;
  139.     tArray<TESObjectDOOR*>      doors;
  140.     tArray<IngredientItem*>     ingredients;
  141.     tArray<TESObjectLIGH*>      lights;
  142.     tArray<TESObjectMISC*>      miscObjects;
  143.     tArray<BGSApparatus*>       apparatuses;
  144.     tArray<TESObjectSTAT*>      statics;
  145.     tArray<BGSStaticCollection*>    staticCollections;
  146.     tArray<BGSMovableStatic*>   movableStatics;
  147.     tArray<TESGrass*>           grasses;
  148.     tArray<TESObjectTREE*>      trees;
  149.     tArray<TESFlora*>           flora;
  150.     tArray<TESFurniture*>       furniture;
  151.     tArray<TESObjectWEAP*>      weapons;
  152.     tArray<TESAmmo*>                ammo;
  153.     tArray<TESNPC*>             npcs;
  154.     tArray<TESLevCharacter*>        levCharacters;
  155.     tArray<TESKey*>             keys;
  156.     tArray<AlchemyItem*>            potions;
  157.     tArray<BGSIdleMarker*>      idleMarkers;
  158.     tArray<BGSNote*>                notes;
  159.     tArray<BGSConstructibleObject*> constructibles;
  160.     tArray<BGSProjectile*>      projectiles;
  161.     tArray<BGSHazard*>          bgsHazards;
  162.     tArray<TESSoulGem*>         soulGems;
  163.     tArray<TESLevItem*>         levItems;
  164.     tArray<TESWeather*>         weather;
  165.     tArray<TESClimate*>         climates;
  166.     tArray<BGSShaderParticleGeometryData*>  shaderParticleGeometryData;
  167.     tArray<BGSReferenceEffect*> referenceEffects;
  168.     tArray<TESRegion*>          regions;
  169.     tArray<NavMeshInfoMap*>     navMeshInfoMaps;
  170.     tArray<TESObjectCELL*>      cells;
  171.     tArray<TESObjectREFR*>      refs;   // could be actors
  172.     tArray<Character*>          characters;
  173.     tArray<MissileProjectile*>  missleProjs;
  174.     tArray<ArrowProjectile*>        arrowProjs;
  175.     tArray<GrenadeProjectile*>  grenadeProjs;
  176.     tArray<BeamProjectile*>     beamProjs;
  177.     tArray<FlameProjectile*>        flameProjs;
  178.     tArray<ConeProjectile*>     coneProjs;
  179.     tArray<BarrierProjectile*>  barrierProjs;
  180.     tArray<Hazard*>             hazards;
  181.     tArray<TESWorldSpace*>      worldSpaces;
  182.     tArray<TESObjectLAND*>      lands;
  183.     tArray<NavMesh*>                navMeshes;
  184.     UnkFormArray                unkTLOD;
  185.     tArray<TESTopic*>           topics;
  186.     tArray<TESTopicInfo*>       topicInfos;
  187.     tArray<TESQuest*>           quests;
  188.     tArray<TESIdleForm*>            idleForms;
  189.     tArray<TESPackage*>         packages;
  190.     tArray<TESCombatStyle*>     combatStyles;
  191.     tArray<TESLoadScreen*>      loadScreens;
  192.     tArray<TESLevSpell*>            levSpells;
  193.     tArray<TESObjectANIO*>      anios;
  194.     tArray<TESWaterForm*>       waterForms;
  195.     tArray<TESEffectShader*>        effectShaders;
  196.     UnkFormArray                unkTOFTs;
  197.     tArray<BGSExplosion*>       explosions;
  198.     tArray<BGSDebris*>          debris;
  199.     tArray<TESImageSpace*>      imageSpaces;
  200.     tArray<TESImageSpaceModifier*>  imageSpaceModifiers;
  201.     tArray<BGSListForm*>            listForms;
  202.     tArray<BGSPerk*>                perks;
  203.     tArray<BGSBodyPartData*>        bodyPartData;
  204.     tArray<BGSAddonNode*>       addonNodes;
  205.     tArray<ActorValueInfo*>     actorValueInfos;
  206.     tArray<BGSCameraShot*>      cameraShots;
  207.     tArray<BGSCameraPath*>      cameraPaths;
  208.     tArray<BGSVoiceType*>       voiceTypes;
  209.     tArray<BGSMaterialType*>        materialTypes;
  210.     tArray<BGSImpactData*>      impactData;
  211.     tArray<BGSImpactDataSet*>   impactDataSets;
  212.     tArray<TESObjectARMA*>      armorAddons;
  213.     tArray<BGSEncounterZone*>   encounterZones;
  214.     tArray<BGSLocation*>            locations;
  215.     tArray<BGSMessage*>         messages;
  216.     tArray<BGSRagdoll*>         ragdolls;
  217.     UnkFormArray                unkDOBJs;
  218.     tArray<BGSLightingTemplate*>    lightingTemplates;
  219.     tArray<BGSMusicType*>       musicTypes;
  220.     tArray<BGSFootstep*>            footsteps;
  221.     tArray<BGSFootstepSet*>     footstepSets;
  222.     tArray<BGSStoryManagerBranchNode*>  branchNodes;
  223.     tArray<BGSStoryManagerQuestNode*>   questNodes;
  224.     tArray<BGSStoryManagerEventNode*>   eventNodes;
  225.     tArray<BGSDialogueBranch*>  dialogBranches;
  226.     tArray<BGSMusicTrackFormWrapper*>   musicTrackFormWrappers;
  227.     UnkFormArray                unkDLVWs;
  228.     tArray<TESWordOfPower*>     wordOfPowers;
  229.     tArray<TESShout*>           shouts;
  230.     tArray<BGSEquipSlot*>           equipSlots;
  231.     tArray<BGSRelationship*>        relationships;
  232.     tArray<BGSScene*>           scenes;
  233.     tArray<BGSAssociationType*> associationTypes;
  234.     tArray<BGSOutfit*>          outfits;
  235.     tArray<BGSArtObject*>       artObjects;
  236.     tArray<BGSMaterialObject*>  materialObjects;
  237.     tArray<BGSMovementType*>        movementTypes;
  238.     tArray<BGSSoundDescriptorForm*> soundDescriptors;
  239.     tArray<BGSDualCastData*>        dualCastData;
  240.     tArray<BGSSoundCategory*>   soundCategories;
  241.     tArray<BGSSoundOutput*>     soundOutputs;
  242.     tArray<BGSCollisionLayer*>  collisonLayers;
  243.     tArray<BGSColorForm*>       colors;
  244.     tArray<BGSReverbParameters*>    reverbParams;
  245.     UInt32 unks[0x0E];
  246.     ModList                         modList;
  247.  
  248.     const ModInfo* LookupModByName(const char* modName);
  249.     UInt8 GetModIndex(const char* modName);
  250. };
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258. /* PapyrusGame.cpp */
  259.     UInt32 GetModCount(StaticFunctionTag*)
  260.     {
  261.         DataHandler* pDataHandler = DataHandler::GetSingleton();
  262.         return pDataHandler->modList.loadedModCount;
  263.     }
  264.  
  265.     UInt32 GetModByName(StaticFunctionTag*, BSFixedString name)
  266.     {
  267.         DataHandler* pDataHandler = DataHandler::GetSingleton();
  268.         return pDataHandler->GetModIndex(name.data);
  269.     }
  270.  
  271.     BSFixedString GetModName(StaticFunctionTag*, UInt32 index)
  272.     {
  273.         if(index < 0 || index > 255)
  274.             return NULL;
  275.         DataHandler* pDataHandler = DataHandler::GetSingleton();
  276.         ModInfo* modInfo = pDataHandler->modList.modInfoList.GetNthItem(index);
  277.         return (modInfo) ? modInfo->name : NULL;
  278.     }
  279.  
  280.     BSFixedString GetModAuthor(StaticFunctionTag*, UInt32 index)
  281.     {
  282.         if(index < 0 || index > 255)
  283.             return NULL;
  284.         DataHandler* pDataHandler = DataHandler::GetSingleton();
  285.         ModInfo* modInfo = pDataHandler->modList.modInfoList.GetNthItem(index);
  286.         return (modInfo) ? modInfo->author.Get() : NULL;
  287.     }
  288.  
  289.     BSFixedString GetModDescription(StaticFunctionTag*, UInt32 index)
  290.     {
  291.         if(index < 0 || index > 255)
  292.             return NULL;
  293.         DataHandler* pDataHandler = DataHandler::GetSingleton();
  294.         ModInfo* modInfo = pDataHandler->modList.modInfoList.GetNthItem(index);
  295.         return (modInfo) ? modInfo->description.Get() : NULL;
  296.     }
  297.  
  298.     UInt32 GetModDependencyCount(StaticFunctionTag*, UInt32 index)
  299.     {
  300.         if(index < 0 || index > 255)
  301.             return NULL;
  302.         DataHandler* pDataHandler = DataHandler::GetSingleton();
  303.         ModInfo* modInfo = pDataHandler->modList.modInfoList.GetNthItem(index);
  304.         return (modInfo) ? modInfo->numRefMods : 0;
  305.     }
  306.  
  307.     UInt32 GetModDependency(StaticFunctionTag*, UInt32 index, UInt32 dep_index)
  308.     {
  309.         if(index < 0 || index > 255)
  310.             return NULL;
  311.         DataHandler* pDataHandler = DataHandler::GetSingleton();
  312.         ModInfo* modInfo = pDataHandler->modList.modInfoList.GetNthItem(index);
  313.         return (modInfo && dep_index > 0 && dep_index < modInfo->numRefMods) ? modInfo->refModInfo[dep_index]->modIndex : 0;
  314.     }
  315.  
  316.  
  317.  
  318.  
  319.  
  320.     // Mods
  321.     registry->RegisterFunction(
  322.         new NativeFunction0 <StaticFunctionTag, UInt32>("GetModCount", "Game", papyrusGame::GetModCount, registry));
  323.  
  324.     registry->RegisterFunction(
  325.         new NativeFunction1 <StaticFunctionTag, UInt32, BSFixedString>("GetModByName", "Game", papyrusGame::GetModByName, registry));
  326.  
  327.     registry->RegisterFunction(
  328.         new NativeFunction1 <StaticFunctionTag, BSFixedString, UInt32>("GetModName", "Game", papyrusGame::GetModName, registry));
  329.  
  330.     registry->RegisterFunction(
  331.         new NativeFunction1 <StaticFunctionTag, BSFixedString, UInt32>("GetModAuthor", "Game", papyrusGame::GetModAuthor, registry));
  332.  
  333.     registry->RegisterFunction(
  334.         new NativeFunction1 <StaticFunctionTag, BSFixedString, UInt32>("GetModDescription", "Game", papyrusGame::GetModDescription, registry));
  335.  
  336.     registry->RegisterFunction(
  337.         new NativeFunction1 <StaticFunctionTag, UInt32, UInt32>("GetModDependencyCount", "Game", papyrusGame::GetModDependencyCount, registry));
  338.  
  339.     registry->RegisterFunction(
  340.         new NativeFunction2 <StaticFunctionTag, UInt32, UInt32, UInt32>("GetModDependency", "Game", papyrusGame::GetModDependency, registry));
  341.  
  342.  
  343.  
  344.  
  345. /* GameData.cpp */
  346.  
  347. class LoadedModFinder
  348. {
  349.     const char * m_stringToFind;
  350.  
  351. public:
  352.     LoadedModFinder(const char * str) : m_stringToFind(str) { }
  353.  
  354.     bool Accept(ModInfo* modInfo)
  355.     {
  356.         return _stricmp(modInfo->name, m_stringToFind) == 0;
  357.     }
  358. };
  359.  
  360. const ModInfo * DataHandler::LookupModByName(const char * modName)
  361. {
  362.     return modList.modInfoList.Find(LoadedModFinder(modName));
  363. }
  364.  
  365. UInt8 DataHandler::GetModIndex(const char* modName)
  366. {
  367.     return modList.modInfoList.GetIndexOf(LoadedModFinder(modName));
  368. }
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375. /* Game.psc */
  376. int Function GetModCount() native global
  377.  
  378. int Function GetModByName(string name) native global
  379.  
  380. string Function GetModName(int index) native global
  381.  
  382. string Function GetModAuthor(int index) native global
  383.  
  384. string Function GetModDescription(int index) native global
  385.  
  386. int Function GetModDependencyCount(int index) native global
  387.  
  388. int Function GetModDependency(int index, int dep_index) native global
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement