Advertisement
expired6978

perks

Jan 31st, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.22 KB | None | 0 0
  1. #include "PapyrusPerk.h"
  2.  
  3. #include "GameForms.h"
  4. #include "GameObjects.h"
  5. #include "GameRTTI.h"
  6.  
  7. namespace papyrusPerk
  8. {
  9.     UInt32 GetNumEntries(BGSPerk * perk)
  10.     {
  11.         return perk->perkEntries.count;
  12.     }
  13.  
  14.     UInt32 GetNthEntryRank(BGSPerk * perk, UInt32 n)
  15.     {
  16.         BGSPerkEntry * perkEntry;
  17.         if(!perk->perkEntries.GetNthItem(n, perkEntry))
  18.             return 0;
  19.  
  20.         return perkEntry->rank;
  21.     }
  22.  
  23.     UInt32 GetNthEntryPriority(BGSPerk * perk, UInt32 n)
  24.     {
  25.         BGSPerkEntry * perkEntry;
  26.         if(!perk->perkEntries.GetNthItem(n, perkEntry))
  27.             return 0;
  28.  
  29.         return perkEntry->priority;
  30.     }
  31.  
  32.     // Quest Perk Entry
  33.     TESQuest * GetNthEntryQuest(BGSPerk * perk, UInt32 n)
  34.     {
  35.         BGSPerkEntry * perkEntry;
  36.         if(!perk->perkEntries.GetNthItem(n, perkEntry))
  37.             return NULL;
  38.  
  39.         BGSQuestPerkEntry * questEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSQuestPerkEntry);
  40.         if(!questEntry)
  41.             return NULL;
  42.  
  43.         return questEntry->quest;
  44.     }
  45.  
  46.     UInt32 GetNthEntryStage(BGSPerk * perk, UInt32 n)
  47.     {
  48.         BGSPerkEntry * perkEntry;
  49.         if(!perk->perkEntries.GetNthItem(n, perkEntry))
  50.             return 0;
  51.  
  52.         BGSQuestPerkEntry * questEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSQuestPerkEntry);
  53.         if(!questEntry)
  54.             return 0;
  55.  
  56.         return questEntry->stage;
  57.     }
  58.  
  59.     // Ability Perk Entry
  60.     // EntryPoint Perk Entry
  61.     SpellItem * GetNthEntrySpell(BGSPerk * perk, UInt32 n)
  62.     {
  63.         BGSPerkEntry * perkEntry;
  64.         if(!perk->perkEntries.GetNthItem(n, perkEntry))
  65.             return NULL;
  66.  
  67.         BGSAbilityPerkEntry * abilityEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSAbilityPerkEntry);
  68.         if(abilityEntry)
  69.             return abilityEntry->spellItem;
  70.  
  71.         BGSEntryPointPerkEntry * entryPointEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSEntryPointPerkEntry);
  72.         if(entryPointEntry) {
  73.             BGSEntryPointFunctionDataSpellItem * functionDataSpell = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataSpellItem);
  74.             if(functionDataSpell)
  75.                 return functionDataSpell->spellItem;
  76.  
  77.             BGSEntryPointFunctionDataActivateChoice * functionDataActivation = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataActivateChoice);
  78.             if(functionDataActivation)
  79.                 return functionDataActivation->appliedSpell;
  80.         }
  81.  
  82.         return NULL;
  83.     }
  84.  
  85.     TESLevItem * GetNthEntryLeveledList(BGSPerk * perk, UInt32 n)
  86.     {
  87.         BGSPerkEntry * perkEntry;
  88.         if(!perk->perkEntries.GetNthItem(n, perkEntry))
  89.             return NULL;
  90.  
  91.         BGSEntryPointPerkEntry * entryPointEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSEntryPointPerkEntry);
  92.         if(entryPointEntry) {
  93.             BGSEntryPointFunctionDataLeveledList * functionDataLeveledList = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataLeveledList);
  94.             if(functionDataLeveledList)
  95.                 return functionDataLeveledList->leveledList;
  96.         }
  97.  
  98.         return NULL;
  99.     }
  100.  
  101.     BSFixedString GetNthEntryText(BGSPerk * perk, UInt32 n)
  102.     {
  103.         BGSPerkEntry * perkEntry;
  104.         if(!perk->perkEntries.GetNthItem(n, perkEntry))
  105.             return NULL;
  106.  
  107.         BGSEntryPointPerkEntry * entryPointEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSEntryPointPerkEntry);
  108.         if(entryPointEntry) {
  109.             BGSEntryPointFunctionDataText * functionDataText = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataText);
  110.             if(functionDataText)
  111.                 return functionDataText->text;
  112.  
  113.             BGSEntryPointFunctionDataActivateChoice * functionDataActivation = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataActivateChoice);
  114.             if(functionDataActivation)
  115.                 return functionDataActivation->label;
  116.  
  117.             BGSEntryPointFunctionDataBooleanGraphVariable * functionDataGraphVar = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataBooleanGraphVariable);
  118.             if(functionDataGraphVar)
  119.                 return functionDataGraphVar->variable;
  120.         }
  121.  
  122.         return NULL;
  123.     }
  124.  
  125.     float GetNthEntryValue(BGSPerk * perk, UInt32 n, UInt32 i)
  126.     {
  127.         if(i < 0 || i >= BGSEntryPointFunctionDataTwoValue::kNumValues)
  128.             return 0.0;
  129.  
  130.         BGSPerkEntry * perkEntry;
  131.         if(!perk->perkEntries.GetNthItem(n, perkEntry))
  132.             return 0.0;
  133.  
  134.         BGSEntryPointPerkEntry * entryPointEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSEntryPointPerkEntry);
  135.         if(entryPointEntry) {
  136.             BGSEntryPointFunctionDataOneValue * functionOne = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataOneValue);
  137.             if(functionOne)
  138.                 return functionOne->value;
  139.  
  140.             BGSEntryPointFunctionDataTwoValue * functionTwo = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataTwoValue);
  141.             if(functionTwo)
  142.                 return functionTwo->value[i];
  143.         }
  144.  
  145.         return 0.0;
  146.     }
  147.  
  148.     bool SetNthEntryRank(BGSPerk * perk, UInt32 n, UInt32 value)
  149.     {
  150.         BGSPerkEntry * perkEntry;
  151.         if(perk->perkEntries.GetNthItem(n, perkEntry)) {
  152.             perkEntry->rank = value;
  153.             return true;
  154.         }
  155.  
  156.         return false;
  157.     }
  158.  
  159.     bool SetNthEntryPriority(BGSPerk * perk, UInt32 n, UInt32 value)
  160.     {
  161.         BGSPerkEntry * perkEntry;
  162.         if(perk->perkEntries.GetNthItem(n, perkEntry)) {
  163.             perkEntry->priority = value;
  164.             return true;
  165.         }
  166.  
  167.         return false;
  168.     }
  169.  
  170.     // Quest Perk Entry
  171.     bool SetNthEntryQuest(BGSPerk * perk, UInt32 n, TESQuest * quest)
  172.     {
  173.         BGSPerkEntry * perkEntry;
  174.         if(perk->perkEntries.GetNthItem(n, perkEntry)) {
  175.             BGSQuestPerkEntry * questEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSQuestPerkEntry);
  176.             if(questEntry) {
  177.                 questEntry->quest = quest;
  178.                 return true;
  179.             }
  180.         }
  181.  
  182.         return false;
  183.     }
  184.  
  185.     bool SetNthEntryStage(BGSPerk * perk, UInt32 n, UInt32 stage)
  186.     {
  187.         BGSPerkEntry * perkEntry;
  188.         if(perk->perkEntries.GetNthItem(n, perkEntry)) {
  189.             BGSQuestPerkEntry * questEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSQuestPerkEntry);
  190.             if(questEntry) {
  191.                 questEntry->stage = stage;
  192.                 return true;
  193.             }
  194.         }
  195.  
  196.         return false;
  197.     }
  198.  
  199.     // Ability Perk Entry
  200.     // EntryPoint Perk Entry
  201.     bool SetNthEntrySpell(BGSPerk * perk, UInt32 n, SpellItem * spell)
  202.     {
  203.         BGSPerkEntry * perkEntry;
  204.         if(perk->perkEntries.GetNthItem(n, perkEntry)) {
  205.             BGSAbilityPerkEntry * abilityEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSAbilityPerkEntry);
  206.             if(abilityEntry) {
  207.                 abilityEntry->spellItem = spell;
  208.                 return true;
  209.             }
  210.  
  211.             BGSEntryPointPerkEntry * entryPointEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSEntryPointPerkEntry);
  212.             if(entryPointEntry) {
  213.                 BGSEntryPointFunctionDataSpellItem * functionDataSpell = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataSpellItem);
  214.                 if(functionDataSpell) {
  215.                     functionDataSpell->spellItem = spell;
  216.                     return true;
  217.                 }
  218.  
  219.                 BGSEntryPointFunctionDataActivateChoice * functionDataActivation = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataActivateChoice);
  220.                 if(functionDataActivation) {
  221.                     functionDataActivation->appliedSpell = spell;
  222.                     return true;
  223.                 }
  224.             }
  225.         }
  226.  
  227.         return false;
  228.     }
  229.  
  230.     bool SetNthEntryLeveledList(BGSPerk * perk, UInt32 n, TESLevItem * leveledList)
  231.     {
  232.         BGSPerkEntry * perkEntry;
  233.         if(perk->perkEntries.GetNthItem(n, perkEntry)) {
  234.             BGSEntryPointPerkEntry * entryPointEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSEntryPointPerkEntry);
  235.             if(entryPointEntry) {
  236.                 BGSEntryPointFunctionDataLeveledList * functionDataLeveledList = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataLeveledList);
  237.                 if(functionDataLeveledList) {
  238.                     functionDataLeveledList->leveledList = leveledList;
  239.                     return true;
  240.                 }
  241.             }
  242.         }
  243.  
  244.         return false;
  245.     }
  246.  
  247.     bool SetNthEntryText(BGSPerk * perk, UInt32 n, BSFixedString str)
  248.     {
  249.         BGSPerkEntry * perkEntry;
  250.         if(perk->perkEntries.GetNthItem(n, perkEntry)) {
  251.             BGSEntryPointPerkEntry * entryPointEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSEntryPointPerkEntry);
  252.             if(entryPointEntry) {
  253.                 BGSEntryPointFunctionDataText * functionDataText = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataText);
  254.                 if(functionDataText) {
  255.                     functionDataText->text = str;
  256.                     return true;
  257.                 }
  258.  
  259.                 BGSEntryPointFunctionDataActivateChoice * functionDataActivation = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataActivateChoice);
  260.                 if(functionDataActivation) {
  261.                     functionDataActivation->label = str;
  262.                     return true;
  263.                 }
  264.  
  265.                 BGSEntryPointFunctionDataBooleanGraphVariable * functionDataGraphVar = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataBooleanGraphVariable);
  266.                 if(functionDataGraphVar) {
  267.                     functionDataGraphVar->variable = str;
  268.                     return true;
  269.                 }
  270.             }
  271.         }
  272.  
  273.         return false;
  274.     }
  275.  
  276.     bool SetNthEntryValue(BGSPerk * perk, UInt32 n, UInt32 i, float value)
  277.     {
  278.         if(i >= 0 && i < BGSEntryPointFunctionDataTwoValue::kNumValues) {
  279.             BGSPerkEntry * perkEntry;
  280.             if(perk->perkEntries.GetNthItem(n, perkEntry)) {
  281.                 BGSEntryPointPerkEntry * entryPointEntry = DYNAMIC_CAST(perkEntry, BGSPerkEntry, BGSEntryPointPerkEntry);
  282.                 if(entryPointEntry) {
  283.                     BGSEntryPointFunctionDataOneValue * functionOne = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataOneValue);
  284.                     if(functionOne) {
  285.                         functionOne->value = value;
  286.                         return true;
  287.                     }
  288.  
  289.                     BGSEntryPointFunctionDataTwoValue * functionTwo = DYNAMIC_CAST(entryPointEntry->data, BGSEntryPointFunctionData, BGSEntryPointFunctionDataTwoValue);
  290.                     if(functionTwo) {
  291.                         functionTwo->value[i] = value;
  292.                         return true;
  293.                     }
  294.                 }
  295.             }
  296.         }
  297.  
  298.         return false;
  299.     }
  300. }
  301.  
  302. #include "PapyrusVM.h"
  303. #include "PapyrusNativeFunctions.h"
  304.  
  305. void papyrusPerk::RegisterFuncs(VMClassRegistry* registry)
  306. {
  307.     registry->RegisterFunction(
  308.         new NativeFunction0<BGSPerk, UInt32>("GetNumEntries", "Perk", papyrusPerk::GetNumEntries, registry));
  309.  
  310.     registry->RegisterFunction(
  311.         new NativeFunction1<BGSPerk, UInt32, UInt32>("GetNthEntryRank", "Perk", papyrusPerk::GetNthEntryRank, registry));
  312.  
  313.     registry->RegisterFunction(
  314.         new NativeFunction1<BGSPerk, UInt32, UInt32>("GetNthEntryPriority", "Perk", papyrusPerk::GetNthEntryPriority, registry));
  315.  
  316.     registry->RegisterFunction(
  317.         new NativeFunction1<BGSPerk, TESQuest*, UInt32>("GetNthEntryQuest", "Perk", papyrusPerk::GetNthEntryQuest, registry));
  318.  
  319.     registry->RegisterFunction(
  320.         new NativeFunction1<BGSPerk, UInt32, UInt32>("GetNthEntryStage", "Perk", papyrusPerk::GetNthEntryStage, registry));
  321.  
  322.     registry->RegisterFunction(
  323.         new NativeFunction1<BGSPerk, SpellItem*, UInt32>("GetNthEntrySpell", "Perk", papyrusPerk::GetNthEntrySpell, registry));
  324.  
  325.     registry->RegisterFunction(
  326.         new NativeFunction1<BGSPerk, TESLevItem*, UInt32>("GetNthEntryLeveledList", "Perk", papyrusPerk::GetNthEntryLeveledList, registry));
  327.  
  328.     registry->RegisterFunction(
  329.         new NativeFunction1<BGSPerk, BSFixedString, UInt32>("GetNthEntryText", "Perk", papyrusPerk::GetNthEntryText, registry));
  330.  
  331.     registry->RegisterFunction(
  332.         new NativeFunction2<BGSPerk, float, UInt32, UInt32>("GetNthEntryValue", "Perk", papyrusPerk::GetNthEntryValue, registry));
  333.  
  334.     registry->RegisterFunction(
  335.         new NativeFunction2<BGSPerk, bool, UInt32, UInt32>("SetNthEntryRank", "Perk", papyrusPerk::SetNthEntryRank, registry));
  336.  
  337.     registry->RegisterFunction(
  338.         new NativeFunction2<BGSPerk, bool, UInt32, UInt32>("SetNthEntryPriority", "Perk", papyrusPerk::SetNthEntryPriority, registry));
  339.  
  340.     registry->RegisterFunction(
  341.         new NativeFunction2<BGSPerk, bool, UInt32, TESQuest*>("SetNthEntryQuest", "Perk", papyrusPerk::SetNthEntryQuest, registry));
  342.  
  343.     registry->RegisterFunction(
  344.         new NativeFunction2<BGSPerk, bool, UInt32, UInt32>("SetNthEntryStage", "Perk", papyrusPerk::SetNthEntryStage, registry));
  345.  
  346.     registry->RegisterFunction(
  347.         new NativeFunction2<BGSPerk, bool, UInt32, SpellItem*>("SetNthEntrySpell", "Perk", papyrusPerk::SetNthEntrySpell, registry));
  348.  
  349.     registry->RegisterFunction(
  350.         new NativeFunction2<BGSPerk, bool, UInt32, TESLevItem*>("SetNthEntryLeveledList", "Perk", papyrusPerk::SetNthEntryLeveledList, registry));
  351.  
  352.     registry->RegisterFunction(
  353.         new NativeFunction2<BGSPerk, bool, UInt32, BSFixedString>("SetNthEntryText", "Perk", papyrusPerk::SetNthEntryText, registry));
  354.  
  355.     registry->RegisterFunction(
  356.         new NativeFunction3<BGSPerk, bool, UInt32, UInt32, float>("SetNthEntryValue", "Perk", papyrusPerk::SetNthEntryValue, registry));
  357. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement