Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Disclaimer: I've no motion rig so this is guess work at best.
- * I'm more looking into telemetry for a home cockpit - that means hard targeting data,
- * enemy position, scan status, loadout, stuff like that. Nothing of this is here :/
- *
- * This is based on the early access 0.66 of G-Rebels and uses the
- * *extended* Telemetry output via UDP of the ingame options and nothing else.
- *
- * AFTER this was guessed https://reakktor.com/htm/gr_telemetry.htm was released
- * from the official developers - that also gets updated.
- *
- * This is a demo snippet for NodeJS - just run it with 'node' and the game starts
- * blabbing once the extended telemetry is enabled in the game.
- *
- * Should be enough to get you started 🤓
- *
- * -- bekopharm
- * */
- const dgram = require('dgram');
- const server = dgram.createSocket('udp4');
- const PORT = 33001;
- const HOST = '127.0.0.1';
- // Verified fixed offsets for the G-Rebels 236-byte telemetry packet
- const TEXT1_START = 0; // "api"
- const TEXT2_START = 8; // "G-Rebels"
- const TEXT3_START = 58; // "X-Type" (Vehicle blueprint class name)
- const TEXT4_START = 108; // "BP_SECTOR_C_..." (World sector or asset ID??)
- const TELEMETRY_START = 160; // Start of the Float32 flight dynamics values
- // Gameplay telemetry zone at the end of the packet
- const LASER_SHOTS_START = 212; // Primary weapon count (Int32)
- const MISSILE_SHOTS_START = 216; // Missiles fired counter (Int32)
- const ENEMY_HITS_START = 220; // Incoming damage hits counter from enemies (Int32)
- const IMPACT_START = 224; // Wall/Environment collision counter (Int32)
- const SHIELD_IMP_START = 232; // Final Float: Shield impact absorption impulse?? (Delta)
- // Change tracking storage for event triggers
- let lastLaserCount = null;
- let lastMissileCount = null;
- let lastHitCount = null;
- let lastImpactCount = null;
- function parseText(buffer, startOffset, maxLength) {
- const segment = buffer.subarray(startOffset, startOffset + maxLength);
- const nullIndex = segment.indexOf(0);
- return nullIndex === -1
- ? segment.toString('ascii')
- : segment.subarray(0, nullIndex).toString('ascii');
- }
- server.on('message', (msg, rinfo) => {
- if (msg.length !== 236) return;
- // 1. Parse text fields
- const text3 = parseText(msg, TEXT3_START, 50);
- const text4 = parseText(msg, TEXT4_START, 52);
- // 2. Read motion dynamics (Float32 Little Endian)
- const pitch = msg.readFloatLE(TELEMETRY_START + 0);
- const roll = msg.readFloatLE(TELEMETRY_START + 4);
- const rawYaw = msg.readFloatLE(TELEMETRY_START + 8);
- // IN-GAME COMPASS SYNC: Map raw Unreal Engine Yaw to 0-360° HUD heading
- let headingDeg = rawYaw + 86.05; // or 90? hard to tell
- if (headingDeg >= 360) headingDeg -= 360;
- if (headingDeg < 0) headingDeg += 360;
- // Linear acceleration (Float32 LE)
- const accLongitudinal = msg.readFloatLE(TELEMETRY_START + 16); // Surge acceleration
- const accLateral = msg.readFloatLE(TELEMETRY_START + 20); // Sway acceleration
- const accVertical = msg.readFloatLE(TELEMETRY_START + 24); // Heave acceleration
- // Thrust input controls (Float32 LE, -1..+1)
- const thrustForward = msg.readFloatLE(TELEMETRY_START + 40); // Forward/reverse throttle
- const thrustVertical = msg.readFloatLE(TELEMETRY_START + 44); // Vertical thrust
- const thrustLateral = msg.readFloatLE(TELEMETRY_START + 48); // Lateral thrust
- // Translate Unreal Engine Units (cm/s) directly into km/h
- const speedCmS = msg.readFloatLE(TELEMETRY_START + 28);
- const speedKmh = (speedCmS / 100) * 3.6;
- // Local cockpit translation/strafe forces (G-forces? little hight…)
- const gSwayLocal = msg.readFloatLE(TELEMETRY_START + 32); // Left (-) / Right (+)
- const gHeaveLocal = msg.readFloatLE(TELEMETRY_START + 36); // Up (-) / Down (+)
- // 3. Read gameplay event counters
- const currentLaserCount = msg.readInt32LE(LASER_SHOTS_START);
- const currentMissileCount = msg.readInt32LE(MISSILE_SHOTS_START);
- const currentHitCount = msg.readInt32LE(ENEMY_HITS_START);
- const currentImpactCount = msg.readInt32LE(IMPACT_START);
- const hitStrength = msg.readFloatLE(228);
- const shieldImpulse = msg.readFloatLE(SHIELD_IMP_START);
- // Calculate event triggers for tactile hardware/shakers
- const laserFired = (lastLaserCount !== null && currentLaserCount > lastLaserCount);
- const missileFired = (lastMissileCount !== null && currentMissileCount > lastMissileCount);
- const hitSustained = (lastHitCount !== null && currentHitCount > lastHitCount);
- const wallCollision = (lastImpactCount !== null && currentImpactCount > lastImpactCount);
- // Store current state for next tick comparisons
- lastLaserCount = currentLaserCount;
- lastMissileCount = currentMissileCount;
- lastHitCount = currentHitCount;
- lastImpactCount = currentImpactCount;
- // Output formatted live console dump
- console.clear();
- console.log(`[G-Rebels Telemetry | Motion Rig Parser]`);
- console.log(`==================================================`);
- console.log(`Vehicle Class: "${text3}"`);
- console.log(`World Sector: "${text4}"`);
- console.log(`--------------------------------------------------`);
- console.log(`Orientation & Navigation (HUD Synced):`);
- console.log(` Pitch (Attitude): ${pitch.toFixed(2)}°`);
- console.log(` Roll (Bank): ${roll.toFixed(2)}°`);
- console.log(` Compass (Heading): ${headingDeg.toFixed(1)}°`);
- console.log(`--------------------------------------------------`);
- console.log(`Rig Dynamics (Direct Actuator Forces):`);
- console.log(` Flight Speed: ${speedKmh.toFixed(0)} km/h`);
- console.log(` Acceleration: Longitudinal: ${accLongitudinal.toFixed(2)} | Lateral: ${accLateral.toFixed(2)} | Vertical: ${accVertical.toFixed(2)}`);
- console.log(` Cockpit Strafe (G): Sway (Lateral): ${gSwayLocal.toFixed(3)} ??`);
- console.log(` Heave (Vert): ${gHeaveLocal.toFixed(3)} ??`);
- console.log(` Thrust Inputs: Forward: ${thrustForward.toFixed(2)} | Vertical: ${thrustVertical.toFixed(2)} | Lateral: ${thrustLateral.toFixed(2)}`);
- console.log(`--------------------------------------------------`);
- console.log(`Gameplay Counters & Game State:`);
- console.log(` Laser / Missile Fire: ${currentLaserCount} / ${currentMissileCount}`);
- console.log(` Enemy Hits / Crashes: ${currentHitCount} / ${currentImpactCount}`);
- console.log(` Hit Strength (Δ) ???: ${hitStrength.toFixed(4)}`);
- console.log(` Shield Impulse (Δ) ??: ${shieldImpulse.toFixed(4)}`);
- console.log(`==================================================`);
- // Haptic/Motion triggers ready to map to hardware profiles
- if (laserFired) console.log(`[FEEDBACK] RECOIL: Laser gun fired!`);
- if (missileFired) console.log(`[FEEDBACK] RECOIL: Missile launched!`);
- if (hitSustained) console.log(`[FEEDBACK] DAMAGE: Vehicle hit by enemy!`);
- if (wallCollision) console.log(`[FEEDBACK] IMPACT: Vehicle crashed into obstacle!`);
- });
- server.on('listening', () => {
- const address = server.address();
- console.log(`G-Rebels UDP Parser actively listening on ${address.address}:${address.port}`);
- });
- server.bind(PORT, HOST);
Advertisement
Add Comment
Please, Sign In to add comment