AshitaXI / Ashita

Issue tracker and wiki for the Ashita project.
https://ashitaxi.com/
7 stars 1 forks source link

[BUG] IDirect3DDevice8:GetVertexShaderConstant returns incorrectly sized array. #42

Closed Jyouya closed 12 months ago

Jyouya commented 1 year ago

Ashita Version (Type /ashita in-game to get this.) 4.1.0.2

FFXI Version (Type /version in-game to get this.) unknown

Windows Version (ie. Start > About Your PC) 19044.2965

Describe The Bug The function IDirect3DDevice8:GetVertexShaderConstant returns an array 4 times as large as it should. The constant registers are 128 bits, but the function allocates 16 floats (512 bits) per register.

Additional Information line 561 of idirect3d8device.lua should be changed from

local data  = ffi.new('float[?]', ConstantCount * 4 * 4);

to

local data  = ffi.new('float[?]', ConstantCount * 4);
atom0s commented 12 months ago

Hello, sorry for the delay in getting to this. After review, the current implementation is correct in how the shader constants are handled and expected. Constants passed to a shader are not single float values, they are passed as 4 floats per constant. (ie. D3DXVECTOR4)

As per the official documentation as well:

pConstantData

[in] Pointer to the data block holding the values to load into the vertex constant array. The size of the data block is (ConstantCount 4 sizeof(float)).

Jyouya commented 12 months ago

Isn't the second argument for ffi.new() the array length, not the number of bytes to allocate? The number of elements in the array is ConstantCount 4, while the size of the array in bytes is ConstantCount 4 * sizeof(float)

atom0s commented 12 months ago

Isn't the second argument for ffi.new() the array length, not the number of bytes to allocate? The number of elements in the array is ConstantCount 4, while the size of the array in bytes is ConstantCount 4 * sizeof(float)

Hello, sorry that is correct; my brain was on autopilot for C++ at the moment and overlooked that haha.