altmp / altv-issues

Issues and roadmap for alt:V project
93 stars 16 forks source link

MemoryBuffer not working #972

Closed deluvas1911 closed 2 years ago

deluvas1911 commented 3 years ago

Client/server version 4.0-dev13

Current behavior If you use the MemoryBuffer to read data, all ints are returned as 0 and strings are empty. The same struct being used in scripthook returns valid data. The returned data for my provided sample is: [0,0,0,0,0,0,0,0,0,""]

Expected behavior Return the correct data

Steps to reproduce Either use the code provided in the samples or use this code:

const maxDrawables = native.getNumberOfPedDrawableVariations(alt.Player.local.scriptID, 11);
for (let drawableId = 0; drawableId < maxDrawables; drawableId++) {
    const maxTextures = native.getNumberOfPedTextureVariations(alt.Player.local.scriptID, 11, drawableId);
    for (let textureId = 0; textureId < maxTextures; textureId++) {
        const componentHash = native.getHashNameForComponent(alt.Player.local.scriptID,11,drawableId,textureId);
        const memoryBuffer = new alt.MemoryBuffer(136);
        native.getShopPedComponent(componentHash, memoryBuffer);
        const bufferData = [
            memoryBuffer.int(0),
            memoryBuffer.int(8),
            memoryBuffer.int(16),
            memoryBuffer.int(24),
            memoryBuffer.int(32),
            memoryBuffer.int(40),
            memoryBuffer.int(48),
            memoryBuffer.int(56),
            memoryBuffer.int(64),
            memoryBuffer.string(72, 64)
        ];
        alt.log(JSON.stringify(bufferData));
    }
}

Context (environment) Same behaviour with Steam, Epic & Rockstar GTA

Additional information This is the struct which is working in scripthook:

typedef struct
{
    int lockHash;
    int _pad1;
    int hash;
    int _pad2;
    int locate;
    int _pad3;
    int drawable;
    int _pad4;
    int texture;
    int _pad5;
    int f_5;
    int _pad6;
    int componentType;
    int _pad7;
    int f_7;
    int _pad8;
    int f_8;
    int _pad9;
    char gxt[64];
} PedComponent;

Here can be found more samples which have worked at some time with the memorybuffer, but now also only return 0.

lackos888 commented 3 years ago

Can also be reproduced on release.

LeonMrBonnie commented 3 years ago

I investigated this issue and it turns out that the problem is in the alt:V Core instead of the Client JS module. The MemoryBuffer is not even passed to the native because (probably all) natives that expect a struct, have the arg type that is supposed to be ARG_STRUCT set to ARG_INT32_PTR, so the JS module doesn't pass it correctly. After passing the memory buffer when the type is ARG_INT32_PTR it works as expected, so the problem is the wrong native arg type.

lackos888 commented 3 years ago

Still not working. Idk if it is affected by the new natives' argument parsing mechanism.

LeonMrBonnie commented 3 years ago

Still not working. Idk if it is affected by the new natives' argument parsing mechanism.

It is not. The change for this needs to be made in core. But there is already work being done to update the generator, so this issue will get fixed eventually.

LeonMrBonnie commented 2 years ago

Fixed in next dev. All natives that take a struct now have to be manually added to a list, so if you encounter a native that needs a MemoryBuffer as argument contact me or add it to this list yourself, and make a PR: https://github.com/altmp/altv-js-module/blob/08c991dd1a61bd837f2fc3384f09819ec6982fd1/client/src/bindings/V8Natives.cpp#L331

LeonMrBonnie commented 2 years ago

Nevermind, we will fix this in another way.

lackos888 commented 2 years ago

Missing natives:

getWeaponHudStats (arg: 1) getWeaponComponentHudStats (arg: 1)

C0kkie commented 2 years ago

Fixed in next dev