Skip to content

Instantly share code, notes, and snippets.

@indilo53
Last active November 22, 2023 02:08
Show Gist options
  • Save indilo53/e917dd0f319bc147f0b037f367f76736 to your computer and use it in GitHub Desktop.
Save indilo53/e917dd0f319bc147f0b037f367f76736 to your computer and use it in GitHub Desktop.
alt:V MemoryBuffer usage example
function getDlcWeaponData(dlcWeaponIndex) {
const buffer = new alt.MemoryBuffer(312);
game.getDlcWeaponData(dlcWeaponIndex, buffer);
const data = [
buffer.int(0), // int emptyCheck; //use DLC1::_IS_DLC_DATA_EMPTY on this
buffer.int(8), // int weaponHash;
buffer.int(16), // int unk;
buffer.int(24), // int weaponCost;
buffer.int(32), // int ammoCost;
buffer.int(40), // int ammoType;
buffer.int(48), // int defaultClipSize;
buffer.string(56, 64), // char nameLabel[64];
buffer.string(120, 64), // char descLabel[64];
buffer.string(184, 64), // char desc2Label[64]; // usually "the" + name
buffer.string(248, 64), // char upperCaseNameLabel[64];
];
buffer.free();
return data;
}
function getDlcWeaponComponentData(dlcWeaponIndex, dlcWeaponComponentIndex) {
const buffer = new alt.MemoryBuffer(176);
game.getDlcWeaponComponentData(dlcWeaponIndex, dlcWeaponComponentIndex, buffer);
const data = [
buffer.int(0), // int attachBone;
buffer.int(8), // int activeByDefault;
buffer.int(16), // int unk;
buffer.int(24), // int componentHash;
buffer.int(32), // int unk2;
buffer.int(40), // int componentCost;
buffer.string(48, 64), // char nameLabel[64];
buffer.string(112, 64), // char descLabel[64];
];
buffer.free();
return data;
}
const weaponCount = game.getNumDlcWeapons();
for(let i=0; i<weaponCount; i++) {
const [emptyCheck, weaponHash, unk, weaponCost, ammoCost, ammoType, defaultClipSize, nameLabel, descLabel, desc2Label, upperCaseNameLabel] = getDlcWeaponData(i);
alt.log(emptyCheck, weaponHash, unk, weaponCost, ammoCost, ammoType, defaultClipSize, nameLabel, descLabel, desc2Label, upperCaseNameLabel);
const componentCount = game.getNumDlcWeaponComponents(i);
for(let j=0; j<componentCount; j++) {
const [attachBone, activeByDefault, unk, componentHash, unk2, componentCost, nameLabel, descLabel] = getDlcWeaponComponentData(i, j);
alt.log(attachBone, activeByDefault, unk, componentHash, unk2, componentCost, nameLabel, descLabel);
}
}
function getPedHeadBlendData(ped) {
const buffer = new alt.MemoryBuffer(77);
game.getPedHeadBlendData(ped, buffer);
const data = [
buffer.int(0),
// padding 4
buffer.int(8),
// padding 4
buffer.int(16),
// padding 4
buffer.int(24),
// padding 4
buffer.int(32),
// padding 4
buffer.int(40),
// padding 4
buffer.floatLE(48),
// padding 4
buffer.floatLE(56),
// padding 4
buffer.floatLE(64),
// padding 4
// bool isParent
// padding 4
];
buffer.free();
return data;
}
let localPlayer = alt.getLocalPlayer();
let localPlayerId = localPlayer.scriptID;
game.setPedHeadBlendData(localPlayerId, 1, 1, 1, 5, 1, 1, 0.25, 0.5, 1.0, false);
const [shapeFirst, shapeSecond, shapeThird, skinFirst, skinSecond, skinThird, shapeMix, skinMix, thirdMix] = getPedHeadBlendData(localPlayerId);
alt.log(shapeFirst, shapeSecond, shapeThird, skinFirst, skinSecond, skinThird, shapeMix, skinMix, thirdMix); // 1 1 1 5 1 1 0.25 0.5 1
/* Temp shit */
function parseFloat(str) {
var float = 0, sign, order, mantissa,exp,int = 0, multi = 1;
if (/^0x/.exec(str)) {
int = parseInt(str,16);
}else{
for (var i = str.length -1; i >=0; i -= 1) {
if (str.charCodeAt(i)>255) {
console.log('Wrong string parametr');
return false;
}
int += str.charCodeAt(i) * multi;
multi *= 256;
}
}
sign = (int>>>31)?-1:1;
exp = (int >>> 23 & 0xff) - 127;
mantissa = ((int & 0x7fffff) + 0x800000).toString(2);
for (i=0; i<mantissa.length; i+=1){
float += parseInt(mantissa[i])? Math.pow(2,exp):0;
exp--;
}
return float * sign;
}
alt.MemoryBuffer.prototype.floatLE = function(offset) {
const bytes = [
this.ubyte(offset),
this.ubyte(offset + 1),
this.ubyte(offset + 2),
this.ubyte(offset + 3),
];
const val =
bytes[0] |
bytes[1] << 8 |
bytes[2] << 16 |
bytes[3] << 24
;
return parseFloat('0x' + val.toString(16));
}
/* End of temp shit */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment