Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ******************************************************************
- PapyrusHeadPart.cpp (Full File)
- ******************************************************************
- */
- #include "PapyrusHeadPart.h"
- #include "GameObjects.h"
- #include "PapyrusVM.h"
- #include "PapyrusNativeFunctions.h"
- namespace papyrusHeadPart
- {
- UInt32 GetType(BGSHeadPart* thisPart)
- {
- if(!thisPart)
- return 0;
- return thisPart->type;
- }
- UInt32 GetNumExtraParts(BGSHeadPart* thisPart)
- {
- return (thisPart) ? thisPart->extraParts.count : 0;
- }
- BGSHeadPart* GetNthExtraPart(BGSHeadPart* thisPart, UInt32 n)
- {
- BGSHeadPart* headPart;
- if(!thisPart || !thisPart->extraParts.GetNthItem(n, headPart))
- return NULL;
- return headPart;
- }
- bool HasExtraPart(BGSHeadPart* thisPart, BGSHeadPart* extraPart)
- {
- return (thisPart && thisPart->extraParts.GetItemIndex(extraPart) != -1) ? true : false;
- }
- UInt32 GetIndexOfExtraPart(BGSHeadPart* thisPart, BGSHeadPart* extraPart)
- {
- return (thisPart) ? thisPart->extraParts.GetItemIndex(extraPart) : 0;
- }
- BGSListForm* GetValidRaces(BGSHeadPart* thisPart)
- {
- return (thisPart) ? thisPart->validRaces : NULL;
- }
- void SetValidRaces(BGSHeadPart* thisPart, BGSListForm* raceList)
- {
- if(thisPart && raceList) {
- thisPart->validRaces = raceList;
- }
- }
- void RegisterFuncs(VMClassRegistry* registry)
- {
- registry->RegisterForm(BGSHeadPart::kTypeID, "HeadPart");
- registry->RegisterFunction(
- new NativeFunction0<BGSHeadPart, UInt32>("GetType", "HeadPart", papyrusHeadPart::GetType, registry));
- registry->RegisterFunction(
- new NativeFunction0<BGSHeadPart, UInt32>("GetNumExtraParts", "HeadPart", papyrusHeadPart::GetNumExtraParts, registry));
- registry->RegisterFunction(
- new NativeFunction1<BGSHeadPart, BGSHeadPart*, UInt32>("GetNthExtraPart", "HeadPart", papyrusHeadPart::GetNthExtraPart, registry));
- registry->RegisterFunction(
- new NativeFunction1<BGSHeadPart, bool, BGSHeadPart*>("HasExtraPart", "HeadPart", papyrusHeadPart::HasExtraPart, registry));
- registry->RegisterFunction(
- new NativeFunction1<BGSHeadPart, UInt32, BGSHeadPart*>("GetIndexOfExtraPart", "HeadPart", papyrusHeadPart::GetIndexOfExtraPart, registry));
- registry->RegisterFunction(
- new NativeFunction0<BGSHeadPart, BGSListForm*>("GetValidRaces", "HeadPart", papyrusHeadPart::GetValidRaces, registry));
- registry->RegisterFunction(
- new NativeFunction1<BGSHeadPart, void, BGSListForm*>("SetValidRaces", "HeadPart", papyrusHeadPart::SetValidRaces, registry));
- }
- }
- /*
- ******************************************************************
- PapyrusHeadPart.h (Full File)
- ******************************************************************
- */
- #pragma once
- class BGSHeadPart;
- class BGSListForm;
- class VMClassRegistry;
- namespace papyrusHeadPart
- {
- void RegisterFuncs(VMClassRegistry* registry);
- UInt32 GetType(BGSHeadPart* thisPart);
- UInt32 GetNumExtraParts(BGSHeadPart* thisPart);
- BGSHeadPart* GetNthExtraPart(BGSHeadPart* thisPart, UInt32 n);
- bool HasExtraPart(BGSHeadPart* thisPart, BGSHeadPart* extraPart);
- UInt32 GetIndexOfExtraPart(BGSHeadPart* thisPart, BGSHeadPart* extraPart);
- BGSListForm* GetValidRaces(BGSHeadPart* thisPart);
- void SetValidRaces(BGSHeadPart* thisPart, BGSListForm* raceList);
- };
- /*
- ******************************************************************
- PapyrusColorForm.cpp (Full File)
- ******************************************************************
- */
- #include "PapyrusColorForm.h"
- #include "GameForms.h"
- #include "GameObjects.h"
- #include "GameRTTI.h"
- #define MIN3(x,y,z) ((y) <= (z) ? ((x) <= (y) ? (x) : (y)) : ((x) <= (z) ? (x) : (z)))
- #define MAX3(x,y,z) ((y) >= (z) ? ((x) >= (y) ? (x) : (y)) : ((x) >= (z) ? (x) : (z)))
- struct HSVColor {
- UInt8 hue; // Hue between 0 and 255
- UInt8 sat; // Saturation between 0 and 255
- UInt8 val; // Value between 0 and 255
- };
- HSVColor GetHSV(BGSColorForm* colorForm) {
- HSVColor hsv;
- UInt8 rgb_min, rgb_max;
- rgb_min = MIN3(colorForm->color.red, colorForm->color.green, colorForm->color.blue);
- rgb_max = MAX3(colorForm->color.red, colorForm->color.green, colorForm->color.blue);
- // Value
- hsv.val = rgb_max;
- if(hsv.val == 0) {
- hsv.hue = hsv.sat = 0;
- return hsv;
- }
- // Saturation
- hsv.sat = 255 * long(rgb_max - rgb_min) / hsv.val;
- if(hsv.sat == 0) {
- hsv.hue = 0;
- return hsv;
- }
- // Hue
- if (rgb_max == colorForm->color.red)
- hsv.hue = 0 + 43 * (colorForm->color.green - colorForm->color.blue) / (rgb_max - rgb_min);
- else if (rgb_max == colorForm->color.green)
- hsv.hue = 85 + 43 * (colorForm->color.blue - colorForm->color.red) / (rgb_max - rgb_min);
- else
- hsv.hue = 171 + 43 * (colorForm->color.red - colorForm->color.green) / (rgb_max - rgb_min);
- return hsv;
- }
- namespace papyrusColorForm
- {
- UInt32 GetRed(BGSColorForm* colorForm)
- {
- return (colorForm) ? colorForm->color.red : 0;
- }
- UInt32 GetGreen(BGSColorForm* colorForm)
- {
- return (colorForm) ? colorForm->color.green : 0;
- }
- UInt32 GetBlue(BGSColorForm* colorForm)
- {
- return (colorForm) ? colorForm->color.blue : 0;
- }
- // RGB aren't always the most useful values
- UInt32 GetHue(BGSColorForm* colorForm)
- {
- if(!colorForm)
- return 0;
- HSVColor hsv = GetHSV(colorForm);
- return hsv.hue;
- }
- UInt32 GetSaturation(BGSColorForm* colorForm)
- {
- if(!colorForm)
- return 0;
- HSVColor hsv = GetHSV(colorForm);
- return hsv.sat;
- }
- UInt32 GetLuminosity(BGSColorForm* colorForm)
- {
- if(!colorForm)
- return 0;
- HSVColor hsv = GetHSV(colorForm);
- return hsv.val;
- }
- }
- #include "PapyrusVM.h"
- #include "PapyrusNativeFunctions.h"
- void papyrusColorForm::RegisterFuncs(VMClassRegistry* registry)
- {
- registry->RegisterForm(BGSColorForm::kTypeID, "ColorForm");
- registry->RegisterFunction(
- new NativeFunction0 <BGSColorForm, UInt32>("GetRed", "ColorForm", papyrusColorForm::GetRed, registry));
- registry->RegisterFunction(
- new NativeFunction0 <BGSColorForm, UInt32>("GetGreen", "ColorForm", papyrusColorForm::GetGreen, registry));
- registry->RegisterFunction(
- new NativeFunction0 <BGSColorForm, UInt32>("GetBlue", "ColorForm", papyrusColorForm::GetBlue, registry));
- registry->RegisterFunction(
- new NativeFunction0 <BGSColorForm, UInt32>("GetHue", "ColorForm", papyrusColorForm::GetHue, registry));
- registry->RegisterFunction(
- new NativeFunction0 <BGSColorForm, UInt32>("GetSaturation", "ColorForm", papyrusColorForm::GetSaturation, registry));
- registry->RegisterFunction(
- new NativeFunction0 <BGSColorForm, UInt32>("GetLuminosity", "ColorForm", papyrusColorForm::GetLuminosity, registry));
- }
- /*
- ******************************************************************
- PapyrusColorForm.h (Full File)
- ******************************************************************
- */
- #pragma once
- class BGSColorForm;
- class VMClassRegistry;
- namespace papyrusColorForm
- {
- void RegisterFuncs(VMClassRegistry* registry);
- UInt32 GetRed(BGSColorForm* colorForm);
- UInt32 GetGreen(BGSColorForm* colorForm);
- UInt32 GetBlue(BGSColorForm* colorForm);
- UInt32 GetHue(BGSColorForm* colorForm);
- UInt32 GetSaturation(BGSColorForm* colorForm);
- UInt32 GetLuminosity(BGSColorForm* colorForm);
- }
- /*
- ******************************************************************
- GameForms.h (Segments)(2)
- ******************************************************************
- */
- // 24
- class BGSColorForm : public TESForm
- {
- public:
- enum { kTypeID = kFormType_ColorForm };
- // parents
- TESFullName fullName; // 14
- union {
- struct Color {
- UInt8 red, green, blue, alpha; // The alpha isn't actually used here so its usually zero
- } color;
- UInt32 abgr; // 1C
- };
- UInt32 unk20; // 20
- };
- // 98
- class BGSHeadPart : public TESForm
- {
- public:
- enum { kTypeID = kFormType_HeadPart };
- // parents
- TESFullName fullName; // 14
- TESModelTextureSwap model; // 1C
- // members
- UInt8 unk38; // 38 // Flag Inconsistencies (Is Extra Part?) (Use Solid Tint?)
- UInt8 pad39[3]; // 39
- enum {
- kTypeMisc = 0,
- kTypeFace,
- kTypeEyes,
- kTypeHair,
- kTypeFacialHair,
- kTypeScar,
- kTypeBrows
- };
- UInt32 type; // 3C
- tArray<BGSHeadPart*> extraParts; // 40
- void * textureSet; // 4C
- TESModelTri unk50[3]; // 50
- UInt32 unk8C; // 8C
- BGSListForm * validRaces; // 90
- StringCache::Ref unk94; // 94
- };
- /*
- ******************************************************************
- GameObjects.h (Segment)
- ******************************************************************
- */
- // 164
- class TESNPC : public TESActorBase
- {
- public:
- enum { kTypeID = kFormType_NPC };
- // parents
- TESRaceForm race; // 0C0
- BGSOverridePackCollection overridePacks; // 0C8
- BSTEventSink <void *> menuOpenCloseEvent; // 0DC - MenuOpenCloseEvent
- // members @0E0
- UInt8 unk0E0[0x12]; // 0E0 - init'd to 5 // Seem rather odd, could be skill modifiers
- UInt8 unk0F2[0x12]; // 0F2 - init'd to 0
- UInt8 pad104[0x10A - 0x104]; // 104 // Some of these appeared as Dec 100
- UInt16 unk10A; // 10A
- TESClass* npcClass; // 10C
- struct HeadData {
- BGSColorForm * hairColor;
- BGSTextureSet * headTexture; // Only seems to apply to the player
- };
- HeadData * headData; // 110
- UInt32 unk114; // 114
- TESCombatStyle* combatStyle;// 118
- UInt32 unk11C; // 11C
- UInt32 unk120; // 120
- UInt32 unk124; // 124
- float unk128; // 128
- float weight; // 12C
- UInt32 pad130; // 130
- StringCache::Ref unk134; // 134
- UInt32 unk138; // 138
- BGSOutfit* defaultOutfit; // 13C
- BGSOutfit* sleepOutfit; // 140
- void * unk144; // 144 // Appeared as a FormList once
- TESFaction* faction; // 148
- BGSHeadPart ** headparts; // 14C
- UInt8 numHeadParts; // 150
- UInt8 unk151; // 151
- UInt8 unk152; // 152
- UInt8 unk153; // 153
- UInt8 unk154; // 154
- UInt8 unk155; // 155
- UInt8 unk156; // 156
- UInt8 pad157; // 157
- void * unk158; // 158 // Unknown PTR Relationships?
- struct FaceMorphs {
- float option[19];
- UInt32 presets[4];
- };
- FaceMorphs * faceMorph; // 15C
- UInt32 unk160; // 160
- };
- /*
- ******************************************************************
- PapyrusActorBase.cpp (Segments)(4)
- ******************************************************************
- */
- UInt32 GetNumHeadParts(TESNPC* thisNPC)
- {
- return (thisNPC) ? thisNPC->numHeadParts : NULL;
- }
- BGSHeadPart* GetNthHeadPart(TESNPC* thisNPC, UInt32 index)
- {
- return (thisNPC && index >= thisNPC->numHeadParts) ? thisNPC->headparts[index] : NULL;
- }
- void SetNthHeadPart(TESNPC* thisNPC, BGSHeadPart* headPart, UInt32 index )
- {
- if (thisNPC) {
- if(index < thisNPC->numHeadParts) {
- if(headPart) {
- thisNPC->headparts[index] = headPart;
- }
- }
- }
- }
- // Hair Color
- BGSColorForm* GetHairColor(TESNPC* thisNPC)
- {
- return thisNPC->headData->hairColor;
- }
- void SetHairColor(TESNPC* thisNPC, BGSColorForm* colorForm)
- {
- if(colorForm) {
- thisNPC->headData->hairColor = colorForm;
- }
- }
- registry->RegisterFunction(
- new NativeFunction0 <TESNPC, UInt32>("GetNumHeadParts", "ActorBase", papyrusActorBase::GetNumHeadParts, registry));
- registry->RegisterFunction(
- new NativeFunction1 <TESNPC, BGSHeadPart*, UInt32>("GetNthHeadPart", "ActorBase", papyrusActorBase::GetNthHeadPart, registry));
- registry->RegisterFunction(
- new NativeFunction2 <TESNPC, void, BGSHeadPart*, UInt32>("SetNthHeadPart", "ActorBase", papyrusActorBase::SetNthHeadPart, registry));
- // Hair Color
- registry->RegisterFunction(
- new NativeFunction0 <TESNPC, BGSColorForm*>("GetHairColor", "ActorBase", papyrusActorBase::GetHairColor, registry));
- registry->RegisterFunction(
- new NativeFunction1 <TESNPC, void, BGSColorForm*>("SetHairColor", "ActorBase", papyrusActorBase::SetHairColor, registry));
- /*
- ******************************************************************
- ColorForm.psc (Full File)
- ******************************************************************
- */
- Scriptname ColorForm extends Form Hidden
- int Function GetRed() native
- int Function GetGreen() native
- int Function GetBlue() native
- int Function GetHue() native
- int Function GetSaturation() native
- int Function GetLuminosity() native
- /*
- ******************************************************************
- HeadPart.psc (Full File)
- ******************************************************************
- */
- Scriptname HeadPart extends Form Hidden
- ; Returns the head part type
- int Function GetType() native
- int Function GetNumExtraParts() native
- HeadPart Function GetNthExtraPart(int n) native
- bool Function HasExtraPart(HeadPart p) native
- int Function GetIndexOfExtraPart(HeadPart p) native
- ; Returns a formlist of the valid races for this head part
- FormList Function GetValidRaces() native
- Function SetValidRaces(FormList vRaces) native
- /*
- ******************************************************************
- ActorBase.psc (Segment)
- ******************************************************************
- */
- ; Get/Set actors HeadPart by index (This changes)
- int Function GetNumHeadParts() native
- HeadPart Function GetNthHeadPart(int slotPart) native
- Function SetNthHeadPart(HeadPart part, int slotPart) native
- ColorForm Function GetHairColor() native
- Function SetHairColor(ColorForm color) native
- /*
- ******************************************************************
- PapyrusTestCode.psc (Segment)
- ******************************************************************
- */
- ActorBase asNpc = akTarget.GetActorBase()
- ColorForm color = asNpc.GetHairColor()
- Debug.Trace(color + " R:" + color.GetRed() + " G:" + color.GetGreen() + " B:" + color.GetBlue() + " H:" + color.GetHue() + " S:" + color.GetSaturation() + " L:" + color.GetLuminosity())
- int misc = -1
- int eyes = -1
- int face = -1
- int brows = -1
- int scar = -1
- int facial = -1
- int hair = -1
- int index = 0
- While index < asNpc.GetNumHeadParts()
- HeadPart part = asNpc.GetNthHeadPart(index)
- If part
- Debug.Trace(asNpc + " Part: " + index + " - " + part + " Type: " + part.GetType())
- If part.GetType() == 0
- misc = index
- Elseif part.GetType() == 1
- face = index
- Elseif part.GetType() == 2
- eyes = index
- Elseif part.GetType() == 3
- hair = index
- Elseif part.GetType() == 4
- facial = index
- Elseif part.GetType() == 5
- scar = index
- Elseif part.GetType() == 6
- brows = index
- EndIf
- PrintExtraParts(part)
- Debug.Trace("Valid Races:" + part.GetValidRaces())
- EndIf
- index += 1
- EndWhile
- Function PrintExtraParts(HeadPart p)
- int i = 0
- While i < p.GetNumExtraParts()
- Debug.Trace(p + " EXTRA:" + p.GetNthExtraPart(i))
- i += 1
- EndWhile
- EndFunction
- /*
- ******************************************************************
- PapyrusTestCodeOutput (Segment)
- ******************************************************************
- */
- [05/05/2012 - 08:10:24PM] [ColorForm < (000F7565)>] R:16 G:18 B:18 H:128 S:28 L:18
- [05/05/2012 - 08:10:24PM] [ActorBase < (09000D64)>] Part: 0 - [HeadPart <FemaleEyesHumanAmber (0007291B)>] Type: 2
- [05/05/2012 - 08:10:24PM] Valid Races:[FormList < (000A8026)>]
- [05/05/2012 - 08:10:24PM] [ActorBase < (09000D64)>] Part: 1 - [HeadPart <ApachiiHairF21 (08002313)>] Type: 3
- [05/05/2012 - 08:10:24PM] [HeadPart <ApachiiHairF21 (08002313)>] EXTRA:[HeadPart <ApachiiHairLineF21 (08001DA6)>]
- [05/05/2012 - 08:10:24PM] Valid Races:[FormList < (000A803F)>]
- [05/05/2012 - 08:10:24PM] [ActorBase < (09000D64)>] Part: 2 - [HeadPart <ApachiiHairLineF21 (08001DA6)>] Type: 0
- [05/05/2012 - 08:10:24PM] Valid Races:[FormList < (000A803F)>]
- [05/05/2012 - 08:10:24PM] [ActorBase < (09000D64)>] Part: 3 - [HeadPart <FemaleBrowsHuman11 (000E4DA8)>] Type: 6
- [05/05/2012 - 08:10:24PM] Valid Races:[FormList < (000A803F)>]
- [05/05/2012 - 08:10:24PM] [ActorBase < (09000D64)>] Part: 4 - [HeadPart <MarksFemaleHumanoid00NoGash (000EC1B2)>] Type: 5
- [05/05/2012 - 08:10:24PM] Valid Races:[FormList < (000A803F)>]
- [05/05/2012 - 08:10:25PM] [ActorBase < (09000D64)>] Part: 5 - [HeadPart <FemaleHeadNord (00051623)>] Type: 1
- [05/05/2012 - 08:10:25PM] Valid Races:[FormList < (000A8033)>]
- [05/05/2012 - 08:10:25PM] [ActorBase < (09000D64)>] Part: 6 - [HeadPart <FemaleMouthHumanoidDefault (0005150F)>] Type: 0
- [05/05/2012 - 08:10:25PM] Valid Races:[FormList < (000A8023)>]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement