Skip to content

Commit

Permalink
Render and Geo Declaration updates
Browse files Browse the repository at this point in the history
  • Loading branch information
expired6978 committed May 25, 2024
1 parent df81cc5 commit 887b20f
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 61 deletions.
105 changes: 76 additions & 29 deletions f4se/BSGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

class NiProperty;
struct ID3D11Buffer;
struct ID3D11ShaderResourceView;
struct ID3D11UnorderedAccessView;
struct ID3D11Texture2D;

// 38
struct BSGeometrySegmentFlagData
Expand Down Expand Up @@ -68,39 +71,83 @@ class BSGeometrySegmentData : public NiObject
bool bIgnoreSegments; // 3D
};

class BSGeometryData
namespace BSGraphics
{
public:
UInt64 vertexDesc;
struct Buffer
{
ID3D11Buffer* pBuffer;
void* pData;
Buffer* pNext;
ID3D11ShaderResourceView* pShaderResource;
ID3D11UnorderedAccessView* pUnorderedAccess;
void** pRequestEventToWait; // BSEventFlag
UInt32 uiMaxDataSize;
UInt32 uiDataSize;
UInt32 uiRefCount;
UInt32 SRAcquire; // Atomic
UInt32 UAVAcquire; // Atomic
UInt32 PendingRequests; // Atomic
UInt32 DataOffset;
bool InvalidCpuData;
bool HeapAllocated;
volatile bool PendingCopy;
};
struct VertexBuffer : public Buffer {};
struct IndexBuffer : public Buffer {};
struct ByteBuffer : public Buffer {};

struct VertexData
{
ID3D11Buffer * d3d11Buffer; // 00 - const CLayeredObjectWithCLS<class CBuffer>::CContainedObject::`vftable'{for `CPrivateDataImpl<struct ID3D11Buffer>'}
UInt8 * vertexBlock; // 08
UInt64 unk10; // 10
UInt64 unk18; // 18
UInt64 unk20; // 20
UInt64 unk28; // 28
UInt64 unk30; // 30
volatile SInt32 refCount; // 38
};
struct TriShape
{
UInt64 uiVertexDesc;
BSGraphics::VertexBuffer* pVB;
BSGraphics::IndexBuffer* pIB;
UInt32 uiRefCount;
};
struct DynamicTriShape : public TriShape
{
UInt32 uiDynamicBufferSize;
};

struct TriangleData
struct TextureStreamData
{
UInt32 uiRefCount;
UInt8 ucDataFileIndex;
UInt8 ucChunkCount;
UInt16 usMinLOD;
};
struct TextureHeader
{
union
{
ID3D11Buffer * d3d11Buffer; // 00 - Same buffer as VertexData
UInt16 * triangles; // 08
UInt64 unk10; // 10
UInt64 unk18; // 18
UInt64 unk20; // 20
UInt64 unk28; // 28
UInt64 unk30; // 30
volatile SInt32 refCount; // 38
};

VertexData * vertexData; // 08
TriangleData * triangleData; // 10
volatile SInt32 refCount; // 18
UInt64 ui64;
struct
{
UInt16 uiHeight;
UInt16 uiWidth;
UInt8 uiMipCount;
UInt8 uiFormat;
UInt8 uiFlags;
UInt8 uiTilemode;
} __s1;
} __u0;
};
struct Texture
{
ID3D11ShaderResourceView* pSRView;
ID3D11Texture2D* pTexture2D;
ID3D11UnorderedAccessView* pUAView;
BSGraphics::TextureStreamData* pStreamData;
void** pRequestEventToWait; // BSEventFlag
BSGraphics::TextureHeader Header;
UInt32 PendingRequests; // Atomic
UInt32 uiRefCount;
UInt32 uiCreationFrame;
UInt8 uiMinLOD;
UInt8 uiDegradeLevel;
UInt8 usDesiredDegradeLevel;
UInt8 usFlags;
};
}

// 160
class BSGeometry : public NiAVObject
Expand Down Expand Up @@ -160,7 +207,7 @@ class BSGeometry : public NiAVObject
kFlag_Unk8 = (1ULL << 55),
};

BSGeometryData * geometryData; // 148
void* pRendererData; // 148
UInt64 vertexDesc; // 150

UInt16 GetVertexSize() const { return (vertexDesc << 2) & 0x3C; } // 0x3C might be a compiler optimization, (vertexDesc & 0xF) << 2 makes more sense
Expand Down
5 changes: 4 additions & 1 deletion f4se/BSGraphics.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "f4se/BSGraphics.h"


RelocAddr<BSShaderutil::_ClearRenderPasses> BSShaderutil::ClearRenderPasses(0x0206BB00);

//
RelocPtr <ImageSpaceManager> g_imageSpaceManager(0x03CA2BA0);

Expand All @@ -10,7 +13,7 @@ RelocPtr <BSGraphics::Renderer> g_renderManager(0x03769600);
RelocPtr <BSGraphics::RenderTargetManager> g_renderTargetManager(0x02CDBED0);

//
RelocPtr <BSGraphics::ShaderResourceManager> g_shaderResourceManager(0x03192288);
RelocPtr <BSShaderResourceManager> g_shaderResourceManager(0x03192288);

//
RelocPtr <ID3D11Device> g_D3D11Device(0x03624CA8);
Expand Down
126 changes: 103 additions & 23 deletions f4se/BSGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,99 @@
#include "f4se/BSGeometry.h"
#include "f4se/NiTextures.h"

class BSGeometryData;
class BSLines;
class BSDynamicLines;
class NiDefaultAVObjectPalette;
class BSMeshLODTriShape;
class BSMultiStreamInstanceTriShape;
class NiPick;
class NiShadeProperty;
class NiStream;

class IShaderResourceManager
{
public:
virtual ~IShaderResourceManager();

struct FadeNodeSettings
{
const float* pFadeOutMultiplierAddr;
const float* pMeshLODLevel1FadeAddr;
const float* pMeshLODLevel2FadeAddr;
float fDistanceMultiplier;
float fMeshLODFadePercent;
float fMeshLODFadeTime;
float fFadeOutAlphaThreshold;
float fFadeInAlphaThreshold;
float fMaxFadeIncrement;
float fActorAlphaFadeSeconds;
float fFadeInTime;
float fFadeOutTime;
float fMeshLODFadeBound;
int iFadeCounter;
UInt32 uiFadeEnabled;
UInt32 uiDrawFadeEnabled;
};


virtual BSTriShape* CreateTriShape(UInt32 auiNumTriangles, UInt16* apIndices, UInt32 auiNumVertices, NiPoint3* apPositions, NiPoint2* apTexCoords0, NiColorA* apTexCoords1, NiPoint3* apNormals, NiPoint3* apBinormals, NiPoint3* apTangents, NiColorA* apColors, NiColorA* apSkinBoneWeights, UInt8* apSkinBoneIndices, NiColorA* apLandscapeData1, NiColorA* apLandscapeData2, float* apEyeData, bool aGeneratePositionData);
virtual BSTriShape* CreateTriShape(UInt32 auiNumTriangles, UInt32 auiNumVertices, NiPoint3* apPositions, NiPoint2* apTexCoords, NiColorA* apColors, UInt16* apIndices);
virtual void* CreateTriShape(NiStream* kStream, UInt64 auiVertexDesc, UInt32 auiVertexCount, UInt32 auiIndexCount, char** apDynData);
virtual void* CreateTriShapeRendererData(void* apVertexBuffer, UInt64 auiVertexDesc, UInt16* apIndices, UInt32 auiIndexCount);
virtual BSSubIndexTriShape* CreateSubIndexTriShape(UInt32 auiNumTriangles, UInt32 auiNumSegments, UInt16* apIndices, UInt32 auiNumVertices, NiPoint3* apPositions, NiPoint2* apTexCoords0, NiColorA* apTexCoords1, NiPoint3* apNormals, NiPoint3* apBinormals, NiPoint3* apTangents, NiColorA* apColors, NiColorA* apSkinBoneWeights, UInt8* apSkinBoneIndices, NiColorA* apLandscapeData1, NiColorA* apLandscapeData2, float* apEyeData);
virtual void IncRefTriShape(void* apRendererData);
virtual void DecRefTriShape(void* apRendererData);
virtual BSDynamicTriShape* CreateDynamicTriShape(UInt32 auiDynamicFlags, UInt32 auiNumTriangles, UInt16* apIndices, UInt32 auiNumVertices, NiPoint3* apPositions, NiPoint2* apTexCoords0, NiColorA* apTexCoords1, NiPoint3* apNormals, NiPoint3* apBinormals, NiPoint3* apTangents, NiColorA* apColors, NiColorA* apSkinBoneWeights, UInt8* apSkinBoneIndices, NiColorA* apLandscapeData1, NiColorA* apLandscapeData2, float* apEyeData);
virtual BSDynamicTriShape* CreateDynamicTriShape(UInt32, UInt32, UInt32, NiPoint3*, NiPoint2*, NiColorA*, UInt16*);
virtual void IncRefDynamicTriShape(void* apRendererData);
virtual void DecRefDynamicTriShape(void* apRendererData);
virtual void ConvertBSTriShapeToBSDynamicTriShape(NiNode* apRoot, NiDefaultAVObjectPalette* apObjectPal);
virtual void ApplyMaterials(NiAVObject* apRoot);
virtual void SetTriShapeStreamDynamicFlags(UInt32);
virtual void* CreateParticleShape();
virtual void IncRefParticleShape(void* apRendererData);
virtual void DecRefParticleShape(void* apRendererData);
virtual BSLines* CreateLineShape(UInt32, UInt16*, UInt32, NiPoint3*, NiPoint2*, NiColorA*, NiPoint3*, NiPoint3*, NiPoint3*, NiColorA*, NiColorA*, UInt8*, NiColorA*, NiColorA*, float*);
virtual BSDynamicLines* CreateDynamicLineShape(UInt32, UInt32, UInt32, NiPoint3*, NiPoint2*, NiColorA*, UInt16*);
virtual void* CreateDynamicLineShape(NiStream*, UInt64, UInt32, UInt32);
virtual BSDynamicLines* CreateDynamicLineShape(UInt32, UInt32, UInt16*, UInt32, NiPoint3*, NiPoint2*, NiColorA*, NiPoint3*, NiPoint3*, NiPoint3*, NiColorA*, NiColorA*, UInt8*, NiColorA*, NiColorA*, float*);
virtual void IncRefLines(void* apRendererData);
virtual void DecRefLines(void* apRendererData);
virtual void IncRefDynamicLines(void* apRendererData);
virtual void DecRefDynamicLines(void* apRendererData);
virtual void LoadTexture(NiTexture* apTexture);
virtual void CreateStreamingTexture(NiTexture* apTexture, const void* apUserDataIn, void* apUserDataOut);
virtual bool ReadStreamingTextureData(NiTexture* apTexture, void* apUserDataIn);
virtual bool CreateStreamingTextureArraySlice(NiTexture* apTexture, const void* apUserDataIn, void* apUserDataOut, UInt32 auiSlice);
virtual bool ReadStreamingTextureDataToArraySlice(NiTexture* apTexture, void* apUserDataIn, UInt32 auiSlice);
virtual void FinishStreamingTexture(NiTexture* apTexture);
virtual void IncRefTexture(BSGraphics::Texture* apRendererData);
virtual void DecRefTexture(BSGraphics::Texture* apRendererData);
virtual void GetTextureWidthHeight(NiTexture* apTexture, UInt32* auiWidth, UInt32* auiHeight);
virtual UInt32 GetTextureFormat(NiTexture* apTexture);
virtual bool UpdateTextureToDesiredMipLevel(NiTexture* apTexture, UInt32*);
virtual void LoadUpgradeTextureData(NiTexture* apTexture);
virtual bool UpdateStreamingTextureToDesiredMipLevel(NiTexture* apTexture, UInt32*, void*, void*);
virtual void FinishStreamingTextureUpgade(NiTexture* apTexture);
virtual void* CreateVertexBuffer(UInt32* auiDataSize, void* apData, UInt32 auiStride, UInt64);
virtual void DecRefVertexBuffer(void* apRendererData);
virtual NiShadeProperty* CreateDefaultEffectShaderProperty(bool abVertexColors, bool abSkinned);
virtual BSMeshLODTriShape* CreateMeshLODTriShape(UInt32*, UInt32, UInt64, UInt32, UInt32, void*);
virtual BSMeshLODTriShape* CreateMeshLODTriShape(BSTriShape*, UInt32*, UInt32);
virtual UInt32 UpdateIndexBufferForInstancing(BSMultiStreamInstanceTriShape*, UInt32);
virtual bool FindIntersectionsTriShapeFastPath(const NiPoint3*, const NiPoint3*, NiPick*, BSTriShape*);
virtual void CreateTangentSpace(UInt32, UInt16*, UInt32, NiPoint3*, NiPoint2*, NiPoint3*, NiPoint3*, NiPoint3*);
virtual float GetShaderFrameCount();
virtual float GetShaderTimerDelta();
virtual void GetFadeNodeSettings(FadeNodeSettings* abSkinned);
virtual void GetCameraVectors(NiPoint3* arUp, NiPoint3* arRight, NiPoint3* arDir);
};

class BSShaderResourceManager
{
public:
virtual ~BSShaderResourceManager();
};

namespace BSGraphics
{
Expand All @@ -16,30 +108,12 @@ class Renderer
UInt64 unk2588[0x2590 >> 3]; // 2588
CRITICAL_SECTION m_renderLock; // 2590

MEMBER_FN_PREFIX(Renderer);
DEFINE_MEMBER_FN(CreateBSGeometryData, BSGeometryData*, 0x016FD950, UInt32 * blockSize, UInt8 * vertexData, UInt64 vertexDesc, BSGeometryData::TriangleData * triData); // Creates a block with a vertex copy in the resource pool with a reference to the supplied triblock (partial deep copy)
DEFINE_MEMBER_FN_4(CreateTriShape, TriShape*, 0x016FD950, UInt32* arDataSize, void* apData, UInt64 auiVertexDesc, IndexBuffer* apIndexBuffer);
DEFINE_MEMBER_FN_3(CreateVertexBuffer, VertexBuffer*, 0x016FF1C0, UInt32* auiDataSize, SInt8* apData, UInt32 auiStride);
DEFINE_MEMBER_FN_2(CreateIndexBuffer, IndexBuffer*, 0x016FF4E0, UInt32 auiIndexCount, const UInt16* apIndices);
};
STATIC_ASSERT(offsetof(Renderer, m_renderLock) == 0x2590);

class ShaderResourceManager
{
public:
virtual ~ShaderResourceManager();

virtual void Unk_01();
virtual void Unk_02();
virtual void Unk_03();
virtual void Unk_04();
virtual void Unk_05();
virtual void Unk_06();
virtual void Unk_07();
virtual void IncGeometryRef(BSGeometryData * geomData);
virtual void DefGeometryRef(BSGeometryData * geomData); // Will auto-destroy the block when it reaches zero
//...

// Unk_21(BSRenderData * rendererData); // Release texture?
};

// ??
class RenderTargetManager
{
Expand Down Expand Up @@ -69,6 +143,12 @@ class RenderTargetManager
};
}

namespace BSShaderutil
{
typedef void (*_ClearRenderPasses)(NiAVObject* object);
extern RelocAddr< _ClearRenderPasses> ClearRenderPasses;
}

// 1B8
class ImageSpaceManager
{
Expand All @@ -82,6 +162,6 @@ struct ID3D11Device;
extern RelocPtr <ImageSpaceManager> g_imageSpaceManager;
extern RelocPtr <BSGraphics::Renderer> g_renderManager;
extern RelocPtr <BSGraphics::RenderTargetManager> g_renderTargetManager;
extern RelocPtr <BSGraphics::ShaderResourceManager> g_shaderResourceManager;
extern RelocPtr <BSShaderResourceManager> g_shaderResourceManager;
extern RelocPtr <ID3D11Device> g_D3D11Device;
extern RelocPtr <ID3D11DeviceContext> g_D3D11DeviceContext;
4 changes: 4 additions & 0 deletions f4se/GameCustomization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ RelocAddr <uintptr_t> s_BGSCharacterTint_Template_PaletteVtbl(0x022943C8);
// ??_7TextureSet@Template@BGSCharacterTint@@6B@
RelocAddr <uintptr_t> s_BGSCharacterTint_Template_TextureSetVtbl(0x022943F8);

RelocAddr<BSFaceGenUtils::_PrepareHeadPartForShaders> BSFaceGenUtils::PrepareHeadPartForShaders(0x0069AFB0);

RelocAddr<BSFaceGenUtils::_StartFaceCustomizationGenerationForNPC> BSFaceGenUtils::StartFaceCustomizationGenerationForNPC(0x006985F0);

bool BGSCharacterTint::Entry::IsEqual(Entry * rhs)
{
return GetType() == rhs->GetType() && tintIndex == rhs->tintIndex && percent == rhs->percent;
Expand Down
12 changes: 12 additions & 0 deletions f4se/GameCustomization.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class ActorValueInfo;
class Condition;
class NiAVObject;
class BSTriShape;
class BSFaceGenNiNode;
struct BSFaceGenPendingHeadData;
struct FaceGenData;

class BGSCharacterTint
{
Expand Down Expand Up @@ -472,3 +475,12 @@ extern RelocAddr <_CreateMergeTintTextures> CreateMergeTintTextures;
extern RelocAddr<uintptr_t> s_BGSCharacterTint_Template_MaskVtbl;
extern RelocAddr<uintptr_t> s_BGSCharacterTint_Template_PaletteVtbl;
extern RelocAddr<uintptr_t> s_BGSCharacterTint_Template_TextureSetVtbl;

namespace BSFaceGenUtils
{
typedef void (*_PrepareHeadPartForShaders)(BSFaceGenNiNode* apNode, BGSHeadPart* apHeadPart, TESNPC* apNPC, BSFaceGenPendingHeadData* apPendingHeadData);
extern RelocAddr<_PrepareHeadPartForShaders> PrepareHeadPartForShaders;

typedef void (*_StartFaceCustomizationGenerationForNPC)(TESNPC* arNPC, const BSTArray<BGSCharacterTint::Entry*>& arData, FaceGenData* arFaceGenData, void* apCustomizationBuffer, UInt32 auiLoadingPriority, bool abForceMaxLayers);
extern RelocAddr<_StartFaceCustomizationGenerationForNPC> StartFaceCustomizationGenerationForNPC;
}
29 changes: 23 additions & 6 deletions f4se/GameReferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class Actor : public TESObjectREFR
UInt64 unk2D8[(0x300-0x2D8)/8]; // 2D8

// Lots of misc data goes here, equipping, perks, etc
struct MiddleProcess
struct AIProcess
{
void * unk00; // 00

Expand Down Expand Up @@ -430,10 +430,27 @@ class Actor : public TESObjectREFR

Data08 * unk08; // 08

MEMBER_FN_PREFIX(MiddleProcess);
DEFINE_MEMBER_FN(UpdateEquipment, void, 0x00CA12C0, Actor * actor, UInt32 flags);
enum RESET_3D_FLAGS
{
RESET_MODEL = (1 << 0),
RESET_SKIN = (1 << 1),
RESET_HEAD = (1 << 2),
RESET_FACE = (1 << 3),
RESET_SCALE = (1 << 4),
RESET_SKELETON = (1 << 5),
RESET_INIT_DEFAULT = (1 << 6),
RESET_SKY_CELL_SKIN = (1 << 7),
RESET_HAVOK = (1 << 8),
RESET_DONT_ADD_OUTFIT = (1 << 9),
RESET_KEEP_HEAD = (1 << 10),
RESET_DISMEMBERMENT = (1 << 11),
};

DEFINE_MEMBER_FN_1(Set3DUpdateFlag, void, 0x00CB0400, UInt32 flags);
DEFINE_MEMBER_FN_2(DoUpdate3dModel, void, 0x00CA12C0, Actor * actor, UInt32 flags);
DEFINE_MEMBER_FN_2(Update3DModel, void, 0x00C7C640, Actor* apActor, bool abQueueUpdate);
};
MiddleProcess * middleProcess; // 300
AIProcess * middleProcess; // 300
UInt64 unk308[(0x338-0x308)/8];

struct ActorValueData
Expand Down Expand Up @@ -468,13 +485,13 @@ class Actor : public TESObjectREFR
bool GetEquippedExtraData(UInt32 slotIndex, ExtraDataList ** extraData);

MEMBER_FN_PREFIX(Actor);
DEFINE_MEMBER_FN(QueueUpdate, void, 0x00BEE320, bool bDoFaceGen, UInt32 unk2, bool DoQueue, UInt32 flags); // 0, 0, 1, 0
DEFINE_MEMBER_FN_4(Reset3D, void, 0x00BEE320, bool abReloadAll, UInt32 auiAdditionalFlags, bool abQueueReset, UInt32 auiExcludeFlags); // 0, 0, 1, 0
DEFINE_MEMBER_FN(IsHostileToActor, bool, 0x00BF5BD0, Actor * actor);
DEFINE_MEMBER_FN(UpdateEquipment, void, 0x004BBED0); // TESObjectREFR::ReplaceModel
};
STATIC_ASSERT(offsetof(Actor, biped) == 0x428);
STATIC_ASSERT(offsetof(Actor, uiFlags) == 0x43C);
STATIC_ASSERT(offsetof(Actor::MiddleProcess::Data08, equipData) == 0x288);
STATIC_ASSERT(offsetof(Actor::AIProcess::Data08, equipData) == 0x288);
STATIC_ASSERT(sizeof(Actor) == 0x490);

// E10
Expand Down
Loading

0 comments on commit 887b20f

Please sign in to comment.