MisfitMaid / tm-bonk

bonk! when you bonk
https://openplanet.dev/plugin/bonk
MIT License
1 stars 5 forks source link

use vehicle state values as option for bonk detection #14

Open ezio416 opened 8 months ago

ezio416 commented 8 months ago

In CSceneVehicleVisState there are some hidden values that trigger when I crash, either from the front, back, or at all. I thought these were related to accel penalty but now I think they're actually sparks. Taken from Current Effects plugin, some safety removed for brevity:

uint16 penalty1Offset = 0;
int GetPenalty1(CSceneVehicleVisState@ state) {  // front/back impact strength? 0 - 16,843,009
    if (penalty1Offset == 0) {
        const Reflection::MwClassInfo@ type = Reflection::GetType("CSceneVehicleVisState");
        penalty1Offset = type.GetMember("WaterImmersionCoef").Offset - 8;
    }

    return Dev::GetOffsetInt32(state, penalty1Offset);
}

uint16 penalty2Offset = 0;
int GetPenalty2(CSceneVehicleVisState@ state) {  // back impact? 0 - 1
    if (penalty2Offset == 0) {
        const Reflection::MwClassInfo@ type = Reflection::GetType("CSceneVehicleVisState");
        penalty2Offset = type.GetMember("WaterImmersionCoef").Offset - 4;
    }

    return Dev::GetOffsetInt32(state, penalty2Offset);
}

uint16 penalty3Offset = 0;
int GetPenalty3(CSceneVehicleVisState@ state) {  // any impact? 0 - ~1,065,000,000
    if (penalty3Offset == 0) {
        const Reflection::MwClassInfo@ type = Reflection::GetType("CSceneVehicleVisState");
        penalty3Offset = type.GetMember("WetnessValue01").Offset + 8;
    }

    return Dev::GetOffsetInt32(state, penalty3Offset);
}
sylae commented 4 months ago

Hi sorry this got lost in between the cracks there

Is there a way to do this without memory access? I'd really rather avoid Dev:: work, i'm no xert

ezio416 commented 4 months ago

Not that I know of, but I'm 99% sure just pulling integers out is completely safe. I don't really care either way - I don't use this plugin, but I thought you might be interested in a different detection method. Feel free to close if you don't like it (although the official vehicle state plugin does exactly this for a bunch of other hidden values like side speed, wheel dirt, etc)