Advertisement
expired6978

Quest/Alias

May 15th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.30 KB | None | 0 0
  1. /*
  2. ******************************************************************
  3.             PapyrusQuest.cpp (Full File)
  4. ******************************************************************
  5. */
  6.  
  7. #include "PapyrusQuest.h"
  8.  
  9. #include "GameForms.h"
  10.  
  11. #include "PapyrusVM.h"
  12. #include "PapyrusNativeFunctions.h"
  13. #include <algorithm>
  14.  
  15. namespace papyrusQuest
  16. {
  17.     BSFixedString GetId(TESQuest* thisQuest)
  18.     {
  19.         return (thisQuest) ? thisQuest->questID.Get() : NULL;
  20.     }
  21.  
  22.     UInt32 GetPriority(TESQuest* thisQuest)
  23.     {
  24.         return (thisQuest) ? thisQuest->unk07C.priority : 0;
  25.     }
  26.  
  27.     UInt32 GetNumAliases(TESQuest* thisQuest)
  28.     {
  29.         return (thisQuest) ? thisQuest->aliases.count : 0;
  30.     }
  31.  
  32.     BGSBaseAlias* GetNthAlias(TESQuest* thisQuest, UInt32 n)
  33.     {
  34.         if(!thisQuest || n > thisQuest->aliases.count)
  35.             return NULL;
  36.            
  37.         BGSBaseAlias* alias = NULL;
  38.         thisQuest->aliases.GetNthItem(n, alias);
  39.         if(alias) {
  40.             return alias;
  41.         }
  42.  
  43.         return NULL;
  44.     }
  45.  
  46.     BGSBaseAlias* GetAliasByName(TESQuest* thisQuest, BSFixedString s)
  47.     {
  48.         if(!thisQuest || !s.data)
  49.             return NULL;
  50.  
  51.         // Stored name's case is ambiguous due to CK quirks, convert both to lower
  52.         UInt32 length1 = strlen(s.data);
  53.         std::string str1(s.data);
  54.         std::transform(str1.begin(), str1.end(), str1.begin(), tolower);
  55.        
  56.         for(UInt32 n = 0; n < thisQuest->aliases.count; n++) {
  57.             BGSBaseAlias* alias = NULL;
  58.             thisQuest->aliases.GetNthItem(n, alias);
  59.             if(alias) {
  60.                 if(length1 != strlen(alias->name.data)) // Skip if different lengths
  61.                     continue;
  62.                 std::string str2(alias->name.data);
  63.                 std::transform(str2.begin(), str2.end(), str2.begin(), tolower);
  64.                 if(strcmp(str1.c_str(), str2.c_str()) == 0) {
  65.                     return alias;
  66.                 }
  67.             }
  68.         }
  69.        
  70.         return NULL;
  71.     }
  72.  
  73.     void RegisterFuncs(VMClassRegistry* registry)
  74.     {
  75.         registry->RegisterFunction(
  76.             new NativeFunction0 <TESQuest, BSFixedString> ("GetId", "Quest", papyrusQuest::GetId, registry));
  77.  
  78.         registry->RegisterFunction(
  79.             new NativeFunction0 <TESQuest, UInt32> ("GetPriority", "Quest", papyrusQuest::GetPriority, registry));
  80.  
  81.         registry->RegisterFunction(
  82.             new NativeFunction0 <TESQuest, UInt32> ("GetNumAliases", "Quest", papyrusQuest::GetNumAliases, registry));
  83.  
  84.         registry->RegisterFunction(
  85.             new NativeFunction1 <TESQuest, BGSBaseAlias*, UInt32> ("GetNthAlias", "Quest", papyrusQuest::GetNthAlias, registry));
  86.  
  87.         registry->RegisterFunction(
  88.             new NativeFunction1 <TESQuest, BGSBaseAlias*, BSFixedString> ("GetAliasByName", "Quest", papyrusQuest::GetAliasByName, registry));
  89.     }
  90. }
  91.  
  92. /*
  93. ******************************************************************
  94.             PapyrusAlias.cpp (Full File)
  95. ******************************************************************
  96. */
  97.  
  98.  
  99. #include "PapyrusAlias.h"
  100.  
  101. #include "GameForms.h"
  102.  
  103. #include "PapyrusVM.h"
  104. #include "PapyrusNativeFunctions.h"
  105.  
  106. namespace papyrusAlias
  107. {
  108.     BSFixedString GetName(BGSBaseAlias* thisAlias)
  109.     {
  110.         return (thisAlias) ? thisAlias->name.data : NULL;
  111.     }
  112.  
  113.     UInt32 GetId(BGSBaseAlias* thisAlias)
  114.     {
  115.         return (thisAlias) ? thisAlias->aliasId : -1;
  116.     }
  117.  
  118.     void RegisterFuncs(VMClassRegistry* registry)
  119.     {
  120.         registry->RegisterFunction(
  121.             new NativeFunction0 <BGSBaseAlias, BSFixedString> ("GetName", "Alias", papyrusAlias::GetName, registry));
  122.  
  123.         registry->RegisterFunction(
  124.             new NativeFunction0 <BGSBaseAlias, UInt32> ("GetId", "Alias", papyrusAlias::GetId, registry));
  125.     }
  126. }
  127.  
  128. /*
  129. ******************************************************************
  130.             GameForms.h (Segment)
  131. ******************************************************************
  132. */
  133.  
  134. class TESQuest;
  135.  
  136. class BGSBaseAlias : public BaseFormComponent // Not actually a form, but its used like one in Papyrus
  137. {
  138. public:
  139.     enum { kTypeID = kFormType_Alias };
  140.  
  141.     StringCache::Ref name;  // 04
  142.     TESQuest * owner;       // 08
  143.     UInt32 aliasId;         // 0C
  144.     UInt32 flags;           // 10
  145. };
  146.  
  147. class BGSRefAlias : public BGSBaseAlias
  148. {
  149. public:
  150.     enum { kTypeID = kFormType_ReferenceAlias };
  151.  
  152.     UInt32 unk14[0x04]; // One of these is the filltype/filltype filter
  153. };
  154.  
  155. class BGSLocAlias : public BGSBaseAlias
  156. {
  157. public:
  158.     enum { kTypeID = kFormType_LocationAlias };
  159.  
  160.     UInt32 unk14[0x08];
  161. };
  162.  
  163. // 158
  164. class TESQuest : public BGSStoryManagerTreeForm
  165. {
  166. public:
  167.     enum { kTypeID = kFormType_Quest };
  168.  
  169.     // parents
  170.     TESFullName fullName;   // 18
  171.  
  172.     // members
  173.  
  174.     // 20
  175.     struct Data03C
  176.     {
  177.         UInt8   data[0x20]; // ### todo
  178.     };
  179.  
  180.     // 20
  181.     struct Data05C
  182.     {
  183.         UInt8   data[0x20]; // ### todo
  184.     };
  185.  
  186.     // 8
  187.     struct Data07C
  188.     {
  189.         UInt32  unk0;
  190.         UInt16  flags;
  191.         UInt8   priority;
  192.         UInt8   type;
  193.     };
  194.  
  195.     // 8
  196.     struct Data088
  197.     {
  198.         void*   unk0;
  199.         void*   unk4;
  200.     };
  201.  
  202.     // 20
  203.     struct Data0A0
  204.     {
  205.         UInt8   data[0x20]; // ### todo
  206.     };
  207.  
  208.     UnkArray    unk020;     // 020
  209.     UInt32      unk02C;     // 02C
  210.     tArray<BGSBaseAlias*>   aliases;        // 030 - Aliases
  211.     Data03C     unk03C;     // 03C
  212.     Data05C     unk05C;     // 05C
  213.     Data07C     unk07C;     // 07C
  214.     UInt32      unk084;     // 084
  215.     Data088     unk088;     // 088
  216.     Data088     unk090;     // 090
  217.     void        * unk098;   // 098 - linked list
  218.     void        * unk09C;   // 09C - linked list
  219.     Data0A0     unk0A0[2];  // 0A0
  220.     UnkArray    unk0E0[6];  // 0E0
  221.     UnkArray    unk128;     // 128
  222.     void        * unk134;   // 134 - linked list
  223.     UInt16      unk138;     // 138
  224.     UInt8       unk13A;     // 13A
  225.     UInt8       pad13B;     // 13B
  226.     BSString    questID;    // 13C
  227.     UInt32      unk144;     // 144
  228.     UInt32      unk148;     // 148
  229.     UnkArray    unk14C;     // 14C
  230. };
  231.  
  232. STATIC_ASSERT(sizeof(TESQuest) == 0x158);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement