Advertisement
expired6978

SKSE Submission 2

May 5th, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.25 KB | None | 0 0
  1. /*
  2. ******************************************************************
  3.             PapyrusHeadPart.cpp (Full File)
  4. ******************************************************************
  5. */
  6.  
  7. #include "PapyrusHeadPart.h"
  8.  
  9. #include "GameObjects.h"
  10. #include "PapyrusVM.h"
  11. #include "PapyrusNativeFunctions.h"
  12.  
  13. namespace papyrusHeadPart
  14. {
  15.     UInt32 GetType(BGSHeadPart* thisPart)
  16.     {
  17.         if(!thisPart)
  18.             return 0;
  19.  
  20.         return thisPart->type;
  21.     }
  22.  
  23.     UInt32 GetNumExtraParts(BGSHeadPart* thisPart)
  24.     {
  25.         return (thisPart) ? thisPart->extraParts.count : 0;
  26.     }
  27.  
  28.     BGSHeadPart* GetNthExtraPart(BGSHeadPart* thisPart, UInt32 n)
  29.     {
  30.         BGSHeadPart* headPart;
  31.         if(!thisPart || !thisPart->extraParts.GetNthItem(n, headPart))
  32.             return NULL;
  33.  
  34.         return headPart;
  35.     }
  36.  
  37.     bool HasExtraPart(BGSHeadPart* thisPart, BGSHeadPart* extraPart)
  38.     {
  39.         return (thisPart && thisPart->extraParts.GetItemIndex(extraPart) != -1) ? true : false;
  40.     }
  41.  
  42.     UInt32 GetIndexOfExtraPart(BGSHeadPart* thisPart, BGSHeadPart* extraPart)
  43.     {
  44.         return (thisPart) ? thisPart->extraParts.GetItemIndex(extraPart) : 0;
  45.     }
  46.  
  47.     BGSListForm* GetValidRaces(BGSHeadPart* thisPart)
  48.     {
  49.         return (thisPart) ? thisPart->validRaces : NULL;
  50.     }
  51.  
  52.     void SetValidRaces(BGSHeadPart* thisPart, BGSListForm* raceList)
  53.     {
  54.         if(thisPart && raceList) {
  55.             thisPart->validRaces = raceList;
  56.         }
  57.     }
  58.  
  59.     void RegisterFuncs(VMClassRegistry* registry)
  60.     {
  61.         registry->RegisterForm(BGSHeadPart::kTypeID, "HeadPart");
  62.  
  63.         registry->RegisterFunction(
  64.             new NativeFunction0<BGSHeadPart, UInt32>("GetType", "HeadPart", papyrusHeadPart::GetType, registry));
  65.  
  66.         registry->RegisterFunction(
  67.             new NativeFunction0<BGSHeadPart, UInt32>("GetNumExtraParts", "HeadPart", papyrusHeadPart::GetNumExtraParts, registry));
  68.  
  69.         registry->RegisterFunction(
  70.             new NativeFunction1<BGSHeadPart, BGSHeadPart*, UInt32>("GetNthExtraPart", "HeadPart", papyrusHeadPart::GetNthExtraPart, registry));
  71.  
  72.         registry->RegisterFunction(
  73.             new NativeFunction1<BGSHeadPart, bool, BGSHeadPart*>("HasExtraPart", "HeadPart", papyrusHeadPart::HasExtraPart, registry));
  74.  
  75.         registry->RegisterFunction(
  76.             new NativeFunction1<BGSHeadPart, UInt32, BGSHeadPart*>("GetIndexOfExtraPart", "HeadPart", papyrusHeadPart::GetIndexOfExtraPart, registry));
  77.  
  78.         registry->RegisterFunction(
  79.             new NativeFunction0<BGSHeadPart, BGSListForm*>("GetValidRaces", "HeadPart", papyrusHeadPart::GetValidRaces, registry));
  80.  
  81.         registry->RegisterFunction(
  82.             new NativeFunction1<BGSHeadPart, void, BGSListForm*>("SetValidRaces", "HeadPart", papyrusHeadPart::SetValidRaces, registry));
  83.     }
  84. }
  85.  
  86. /*
  87. ******************************************************************
  88.             PapyrusHeadPart.h (Full File)
  89. ******************************************************************
  90. */
  91.  
  92. #pragma once
  93.  
  94. class BGSHeadPart;
  95. class BGSListForm;
  96. class VMClassRegistry;
  97.  
  98. namespace papyrusHeadPart
  99. {
  100.     void RegisterFuncs(VMClassRegistry* registry);
  101.  
  102.     UInt32 GetType(BGSHeadPart* thisPart);
  103.     UInt32 GetNumExtraParts(BGSHeadPart* thisPart);
  104.     BGSHeadPart* GetNthExtraPart(BGSHeadPart* thisPart, UInt32 n);
  105.     bool HasExtraPart(BGSHeadPart* thisPart, BGSHeadPart* extraPart);
  106.     UInt32 GetIndexOfExtraPart(BGSHeadPart* thisPart, BGSHeadPart* extraPart);
  107.     BGSListForm* GetValidRaces(BGSHeadPart* thisPart);
  108.     void SetValidRaces(BGSHeadPart* thisPart, BGSListForm* raceList);
  109. };
  110.  
  111. /*
  112. ******************************************************************
  113.             PapyrusColorForm.cpp (Full File)
  114. ******************************************************************
  115. */
  116. #include "PapyrusColorForm.h"
  117.  
  118. #include "GameForms.h"
  119. #include "GameObjects.h"
  120. #include "GameRTTI.h"
  121.  
  122. #define MIN3(x,y,z)  ((y) <= (z) ? ((x) <= (y) ? (x) : (y)) : ((x) <= (z) ? (x) : (z)))
  123. #define MAX3(x,y,z)  ((y) >= (z) ? ((x) >= (y) ? (x) : (y)) : ((x) >= (z) ? (x) : (z)))
  124.  
  125. struct HSVColor {
  126.     UInt8 hue; // Hue between 0 and 255
  127.     UInt8 sat; // Saturation between 0 and 255
  128.     UInt8 val; // Value between 0 and 255
  129. };
  130.  
  131. HSVColor GetHSV(BGSColorForm* colorForm) {
  132.     HSVColor hsv;
  133.     UInt8 rgb_min, rgb_max;
  134.     rgb_min = MIN3(colorForm->color.red, colorForm->color.green, colorForm->color.blue);
  135.     rgb_max = MAX3(colorForm->color.red, colorForm->color.green, colorForm->color.blue);
  136.  
  137.     // Value
  138.     hsv.val = rgb_max;
  139.     if(hsv.val == 0) {
  140.         hsv.hue = hsv.sat = 0;
  141.         return hsv;
  142.     }
  143.  
  144.     // Saturation
  145.     hsv.sat = 255 * long(rgb_max - rgb_min) / hsv.val;
  146.     if(hsv.sat == 0) {
  147.         hsv.hue = 0;
  148.         return hsv;
  149.     }
  150.  
  151.     // Hue
  152.     if (rgb_max == colorForm->color.red)
  153.         hsv.hue = 0 + 43 * (colorForm->color.green - colorForm->color.blue) / (rgb_max - rgb_min);
  154.     else if (rgb_max == colorForm->color.green)
  155.         hsv.hue = 85 + 43 * (colorForm->color.blue - colorForm->color.red) / (rgb_max - rgb_min);
  156.     else
  157.         hsv.hue = 171 + 43 * (colorForm->color.red - colorForm->color.green) / (rgb_max - rgb_min);
  158.  
  159.     return hsv;
  160. }
  161.  
  162. namespace papyrusColorForm
  163. {
  164.     UInt32 GetRed(BGSColorForm* colorForm)
  165.     {
  166.         return (colorForm) ? colorForm->color.red : 0;
  167.     }
  168.  
  169.     UInt32 GetGreen(BGSColorForm* colorForm)
  170.     {
  171.         return (colorForm) ? colorForm->color.green : 0;
  172.     }
  173.  
  174.     UInt32 GetBlue(BGSColorForm* colorForm)
  175.     {
  176.         return (colorForm) ? colorForm->color.blue : 0;
  177.     }
  178.  
  179.     // RGB aren't always the most useful values
  180.     UInt32 GetHue(BGSColorForm* colorForm)
  181.     {
  182.         if(!colorForm)
  183.             return 0;
  184.  
  185.         HSVColor hsv = GetHSV(colorForm);
  186.         return hsv.hue;
  187.     }
  188.  
  189.     UInt32 GetSaturation(BGSColorForm* colorForm)
  190.     {
  191.         if(!colorForm)
  192.             return 0;
  193.  
  194.         HSVColor hsv = GetHSV(colorForm);
  195.         return hsv.sat;
  196.     }
  197.  
  198.     UInt32 GetLuminosity(BGSColorForm* colorForm)
  199.     {
  200.         if(!colorForm)
  201.             return 0;
  202.  
  203.         HSVColor hsv = GetHSV(colorForm);
  204.         return hsv.val;
  205.     }
  206. }
  207.  
  208. #include "PapyrusVM.h"
  209. #include "PapyrusNativeFunctions.h"
  210.  
  211. void papyrusColorForm::RegisterFuncs(VMClassRegistry* registry)
  212. {
  213.     registry->RegisterForm(BGSColorForm::kTypeID, "ColorForm");
  214.  
  215.     registry->RegisterFunction(
  216.         new NativeFunction0 <BGSColorForm, UInt32>("GetRed", "ColorForm", papyrusColorForm::GetRed, registry));
  217.  
  218.     registry->RegisterFunction(
  219.         new NativeFunction0 <BGSColorForm, UInt32>("GetGreen", "ColorForm", papyrusColorForm::GetGreen, registry));
  220.  
  221.     registry->RegisterFunction(
  222.         new NativeFunction0 <BGSColorForm, UInt32>("GetBlue", "ColorForm", papyrusColorForm::GetBlue, registry));
  223.  
  224.     registry->RegisterFunction(
  225.         new NativeFunction0 <BGSColorForm, UInt32>("GetHue", "ColorForm", papyrusColorForm::GetHue, registry));
  226.  
  227.     registry->RegisterFunction(
  228.         new NativeFunction0 <BGSColorForm, UInt32>("GetSaturation", "ColorForm", papyrusColorForm::GetSaturation, registry));
  229.  
  230.     registry->RegisterFunction(
  231.         new NativeFunction0 <BGSColorForm, UInt32>("GetLuminosity", "ColorForm", papyrusColorForm::GetLuminosity, registry));
  232. }
  233.  
  234. /*
  235. ******************************************************************
  236.             PapyrusColorForm.h (Full File)
  237. ******************************************************************
  238. */
  239.  
  240. #pragma once
  241.  
  242. class BGSColorForm;
  243. class VMClassRegistry;
  244.  
  245. namespace papyrusColorForm
  246. {
  247.     void RegisterFuncs(VMClassRegistry* registry);
  248.  
  249.     UInt32 GetRed(BGSColorForm* colorForm);
  250.     UInt32 GetGreen(BGSColorForm* colorForm);
  251.     UInt32 GetBlue(BGSColorForm* colorForm);
  252.     UInt32 GetHue(BGSColorForm* colorForm);
  253.     UInt32 GetSaturation(BGSColorForm* colorForm);
  254.     UInt32 GetLuminosity(BGSColorForm* colorForm);
  255. }
  256.  
  257. /*
  258. ******************************************************************
  259.             GameForms.h (Segments)(2)
  260. ******************************************************************
  261. */
  262. // 24
  263. class BGSColorForm : public TESForm
  264. {
  265. public:
  266.     enum { kTypeID = kFormType_ColorForm };
  267.  
  268.     // parents
  269.     TESFullName fullName;   // 14
  270.  
  271.     union {
  272.         struct Color {
  273.             UInt8   red, green, blue, alpha; // The alpha isn't actually used here so its usually zero
  274.         } color;
  275.         UInt32 abgr;    // 1C
  276.     };
  277.     UInt32  unk20;  // 20
  278. };
  279.  
  280.  
  281. // 98
  282. class BGSHeadPart : public TESForm
  283. {
  284. public:
  285.     enum { kTypeID = kFormType_HeadPart };
  286.  
  287.  
  288.     // parents
  289.     TESFullName         fullName;   // 14
  290.     TESModelTextureSwap model;      // 1C
  291.  
  292.     // members
  293.     UInt8       unk38;      // 38 // Flag Inconsistencies (Is Extra Part?) (Use Solid Tint?)
  294.     UInt8       pad39[3];   // 39
  295.     enum {
  296.         kTypeMisc = 0,
  297.         kTypeFace,
  298.         kTypeEyes,
  299.         kTypeHair,
  300.         kTypeFacialHair,
  301.         kTypeScar,
  302.         kTypeBrows
  303.     };
  304.     UInt32      type;       // 3C
  305.     tArray<BGSHeadPart*> extraParts; // 40
  306.     void *  textureSet;     // 4C
  307.     TESModelTri unk50[3];   // 50
  308.     UInt32      unk8C;      // 8C
  309.     BGSListForm * validRaces;   // 90
  310.     StringCache::Ref    unk94;  // 94
  311. };
  312.  
  313. /*
  314. ******************************************************************
  315.             GameObjects.h (Segment)
  316. ******************************************************************
  317. */
  318.  
  319. // 164
  320. class TESNPC : public TESActorBase
  321. {
  322. public:
  323.     enum { kTypeID = kFormType_NPC };
  324.  
  325.     // parents
  326.     TESRaceForm     race;   // 0C0
  327.     BGSOverridePackCollection   overridePacks;  // 0C8
  328.     BSTEventSink <void *>   menuOpenCloseEvent; // 0DC - MenuOpenCloseEvent
  329.  
  330.     // members @0E0
  331.     UInt8       unk0E0[0x12];   // 0E0 - init'd to 5 // Seem rather odd, could be skill modifiers
  332.     UInt8       unk0F2[0x12];   // 0F2 - init'd to 0
  333.  
  334.     UInt8       pad104[0x10A - 0x104];  // 104 // Some of these appeared as Dec 100
  335.  
  336.     UInt16      unk10A;         // 10A
  337.     TESClass*   npcClass;       // 10C
  338.  
  339.     struct HeadData {
  340.         BGSColorForm * hairColor;
  341.         BGSTextureSet * headTexture;    // Only seems to apply to the player
  342.     };
  343.  
  344.     HeadData    * headData;     // 110
  345.     UInt32      unk114;         // 114
  346.     TESCombatStyle* combatStyle;// 118
  347.     UInt32      unk11C;         // 11C
  348.     UInt32      unk120;         // 120
  349.     UInt32      unk124;         // 124
  350.     float       unk128;         // 128
  351.     float       weight;         // 12C
  352.  
  353.     UInt32      pad130;         // 130
  354.    
  355.     StringCache::Ref    unk134; // 134
  356.     UInt32      unk138;         // 138
  357.     BGSOutfit*  defaultOutfit;      // 13C
  358.     BGSOutfit*  sleepOutfit;        // 140
  359.     void *      unk144;         // 144 // Appeared as a FormList once
  360.     TESFaction* faction;        // 148
  361.     BGSHeadPart ** headparts;   // 14C
  362.     UInt8       numHeadParts;   // 150
  363.     UInt8       unk151;         // 151
  364.     UInt8       unk152;         // 152
  365.     UInt8       unk153;         // 153
  366.     UInt8       unk154;         // 154
  367.     UInt8       unk155;         // 155
  368.     UInt8       unk156;         // 156
  369.     UInt8       pad157;         // 157
  370.     void *      unk158;         // 158 // Unknown PTR Relationships?
  371.  
  372.     struct FaceMorphs {
  373.         float option[19];
  374.         UInt32 presets[4];
  375.     };
  376.     FaceMorphs      * faceMorph;        // 15C
  377.     UInt32      unk160;         // 160
  378. };
  379.  
  380. /*
  381. ******************************************************************
  382.             PapyrusActorBase.cpp (Segments)(4)
  383. ******************************************************************
  384. */
  385.     UInt32 GetNumHeadParts(TESNPC* thisNPC)
  386.     {
  387.         return (thisNPC) ? thisNPC->numHeadParts : NULL;
  388.     }
  389.  
  390.     BGSHeadPart* GetNthHeadPart(TESNPC* thisNPC, UInt32 index)
  391.     {
  392.         return (thisNPC && index >= thisNPC->numHeadParts) ? thisNPC->headparts[index] : NULL;
  393.     }
  394.  
  395.     void SetNthHeadPart(TESNPC* thisNPC, BGSHeadPart* headPart, UInt32 index )
  396.     {
  397.         if (thisNPC) {
  398.             if(index < thisNPC->numHeadParts) {
  399.                 if(headPart) {
  400.                     thisNPC->headparts[index] = headPart;
  401.                 }
  402.             }
  403.         }
  404.     }
  405.  
  406.  
  407.  
  408.  
  409.     // Hair Color
  410.     BGSColorForm* GetHairColor(TESNPC* thisNPC)
  411.     {
  412.         return thisNPC->headData->hairColor;
  413.     }
  414.  
  415.     void SetHairColor(TESNPC* thisNPC, BGSColorForm* colorForm)
  416.     {
  417.         if(colorForm) {
  418.             thisNPC->headData->hairColor = colorForm;
  419.         }
  420.     }
  421.  
  422.  
  423.  
  424.     registry->RegisterFunction(
  425.         new NativeFunction0 <TESNPC, UInt32>("GetNumHeadParts", "ActorBase", papyrusActorBase::GetNumHeadParts, registry));
  426.  
  427.     registry->RegisterFunction(
  428.         new NativeFunction1 <TESNPC, BGSHeadPart*, UInt32>("GetNthHeadPart", "ActorBase", papyrusActorBase::GetNthHeadPart, registry));
  429.  
  430.     registry->RegisterFunction(
  431.         new NativeFunction2 <TESNPC, void, BGSHeadPart*, UInt32>("SetNthHeadPart", "ActorBase", papyrusActorBase::SetNthHeadPart, registry));
  432.  
  433.  
  434.  
  435.  
  436.     // Hair Color
  437.  
  438.     registry->RegisterFunction(
  439.         new NativeFunction0 <TESNPC, BGSColorForm*>("GetHairColor", "ActorBase", papyrusActorBase::GetHairColor, registry));
  440.  
  441.     registry->RegisterFunction(
  442.         new NativeFunction1 <TESNPC, void, BGSColorForm*>("SetHairColor", "ActorBase", papyrusActorBase::SetHairColor, registry));
  443.  
  444.  
  445.  
  446.  
  447. /*
  448. ******************************************************************
  449.             ColorForm.psc (Full File)
  450. ******************************************************************
  451. */
  452.  
  453. Scriptname ColorForm extends Form Hidden
  454.  
  455. int Function GetRed() native
  456. int Function GetGreen() native
  457. int Function GetBlue() native
  458.  
  459. int Function GetHue() native
  460. int Function GetSaturation() native
  461. int Function GetLuminosity() native
  462.  
  463.  
  464. /*
  465. ******************************************************************
  466.             HeadPart.psc (Full File)
  467. ******************************************************************
  468. */
  469.  
  470.  
  471. Scriptname HeadPart extends Form Hidden
  472.  
  473. ; Returns the head part type
  474. int Function GetType() native
  475.  
  476. int Function GetNumExtraParts() native
  477. HeadPart Function GetNthExtraPart(int n) native
  478.  
  479. bool Function HasExtraPart(HeadPart p) native
  480. int Function GetIndexOfExtraPart(HeadPart p) native
  481.  
  482. ; Returns a formlist of the valid races for this head part
  483. FormList Function GetValidRaces() native
  484. Function SetValidRaces(FormList vRaces) native
  485.  
  486.  
  487. /*
  488. ******************************************************************
  489.             ActorBase.psc (Segment)
  490. ******************************************************************
  491. */
  492. ; Get/Set actors HeadPart by index (This changes)
  493. int Function GetNumHeadParts() native
  494. HeadPart Function GetNthHeadPart(int slotPart) native
  495. Function SetNthHeadPart(HeadPart part, int slotPart) native
  496.  
  497. ColorForm Function GetHairColor() native
  498. Function SetHairColor(ColorForm color) native
  499.  
  500.  
  501. /*
  502. ******************************************************************
  503.             PapyrusTestCode.psc (Segment)
  504. ******************************************************************
  505. */
  506.     ActorBase asNpc = akTarget.GetActorBase()
  507.    
  508.     ColorForm color = asNpc.GetHairColor()
  509.     Debug.Trace(color + " R:" + color.GetRed() + " G:" + color.GetGreen() + " B:" + color.GetBlue() + " H:" + color.GetHue() + " S:" + color.GetSaturation() + " L:" + color.GetLuminosity())
  510.        
  511.     int misc = -1
  512.     int eyes = -1
  513.     int face = -1
  514.     int brows = -1
  515.     int scar = -1
  516.     int facial = -1
  517.     int hair = -1
  518.    
  519.     int index = 0
  520.     While index < asNpc.GetNumHeadParts()
  521.         HeadPart part = asNpc.GetNthHeadPart(index)
  522.         If part
  523.             Debug.Trace(asNpc + " Part: " + index + " - " + part + " Type: " + part.GetType())
  524.             If part.GetType() == 0
  525.                 misc = index
  526.             Elseif part.GetType() == 1
  527.                 face = index
  528.             Elseif part.GetType() == 2
  529.                 eyes = index
  530.             Elseif part.GetType() == 3
  531.                 hair = index
  532.             Elseif part.GetType() == 4
  533.                 facial = index
  534.             Elseif part.GetType() == 5
  535.                 scar = index
  536.             Elseif part.GetType() == 6
  537.                 brows = index
  538.             EndIf
  539.             PrintExtraParts(part)
  540.             Debug.Trace("Valid Races:" + part.GetValidRaces())
  541.         EndIf
  542.         index += 1
  543.     EndWhile
  544.  
  545.  
  546. Function PrintExtraParts(HeadPart p)
  547.     int i = 0
  548.     While i < p.GetNumExtraParts()
  549.         Debug.Trace(p + " EXTRA:" + p.GetNthExtraPart(i))
  550.         i += 1
  551.     EndWhile
  552. EndFunction
  553.  
  554.  
  555. /*
  556. ******************************************************************
  557.             PapyrusTestCodeOutput (Segment)
  558. ******************************************************************
  559. */
  560. [05/05/2012 - 08:10:24PM] [ColorForm < (000F7565)>] R:16 G:18 B:18 H:128 S:28 L:18
  561. [05/05/2012 - 08:10:24PM] [ActorBase < (09000D64)>] Part: 0 - [HeadPart <FemaleEyesHumanAmber (0007291B)>] Type: 2
  562. [05/05/2012 - 08:10:24PM] Valid Races:[FormList < (000A8026)>]
  563. [05/05/2012 - 08:10:24PM] [ActorBase < (09000D64)>] Part: 1 - [HeadPart <ApachiiHairF21 (08002313)>] Type: 3
  564. [05/05/2012 - 08:10:24PM] [HeadPart <ApachiiHairF21 (08002313)>] EXTRA:[HeadPart <ApachiiHairLineF21 (08001DA6)>]
  565. [05/05/2012 - 08:10:24PM] Valid Races:[FormList < (000A803F)>]
  566. [05/05/2012 - 08:10:24PM] [ActorBase < (09000D64)>] Part: 2 - [HeadPart <ApachiiHairLineF21 (08001DA6)>] Type: 0
  567. [05/05/2012 - 08:10:24PM] Valid Races:[FormList < (000A803F)>]
  568. [05/05/2012 - 08:10:24PM] [ActorBase < (09000D64)>] Part: 3 - [HeadPart <FemaleBrowsHuman11 (000E4DA8)>] Type: 6
  569. [05/05/2012 - 08:10:24PM] Valid Races:[FormList < (000A803F)>]
  570. [05/05/2012 - 08:10:24PM] [ActorBase < (09000D64)>] Part: 4 - [HeadPart <MarksFemaleHumanoid00NoGash (000EC1B2)>] Type: 5
  571. [05/05/2012 - 08:10:24PM] Valid Races:[FormList < (000A803F)>]
  572. [05/05/2012 - 08:10:25PM] [ActorBase < (09000D64)>] Part: 5 - [HeadPart <FemaleHeadNord (00051623)>] Type: 1
  573. [05/05/2012 - 08:10:25PM] Valid Races:[FormList < (000A8033)>]
  574. [05/05/2012 - 08:10:25PM] [ActorBase < (09000D64)>] Part: 6 - [HeadPart <FemaleMouthHumanoidDefault (0005150F)>] Type: 0
  575. [05/05/2012 - 08:10:25PM] Valid Races:[FormList < (000A8023)>]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement