bool airbrake_switch_pressed() { bool result = IsKeyJustUp(KeyConfig::KEY_TOGGLE_AIRBRAKE) || IsControllerButtonJustUp(KeyConfig::KEY_TOGGLE_AIRBRAKE); if (result) { //avoid repeat of key press DWORD maxTickCount = GetTickCount() + 200; do { UpdateXInputControlState(); make_periodic_feature_call(); WAIT(0); } while (GetTickCount() < maxTickCount); } return result; }
std::string show_keyboard(char* title_id, char* prepopulated_text) { DWORD time = GetTickCount() + 400; while (GetTickCount() < time) { make_periodic_feature_call(); WAIT(0); } /* Any x; GAMEPLAY::START_SAVE_DATA(&x, 1, 1); GAMEPLAY::REGISTER_TEXT_LABEL_TO_SAVE(&x, "XYZ123"); GAMEPLAY::STOP_SAVE_DATA(); */ GAMEPLAY::DISPLAY_ONSCREEN_KEYBOARD( true, (title_id == NULL ? "HUD_TITLE" : title_id), "", (prepopulated_text == NULL ? "" : prepopulated_text), "", "", "", 64); while (GAMEPLAY::UPDATE_ONSCREEN_KEYBOARD() == 0) { //update_status_text(); WAIT(0); } std::stringstream ss; if (!GAMEPLAY::GET_ONSCREEN_KEYBOARD_RESULT()) { return std::string(""); } else { return std::string(GAMEPLAY::GET_ONSCREEN_KEYBOARD_RESULT()); } }
/** * Many props don't play nicely with PLACE_OBJECT_ON_GROUND_PROPERLY. * Therefore we use one that is known to work properly to determine * the height of the ground, and therefore the position for the other * prop, by spawning one and then deleting it. */ bool get_ground_height_at_position(Vector3 coords, float* result) { Hash propHash = GAMEPLAY::GET_HASH_KEY("prop_veg_crop_03_cab"); STREAMING::REQUEST_MODEL(propHash); DWORD now = GetTickCount(); while (!STREAMING::HAS_MODEL_LOADED(propHash) && GetTickCount() < now + 5000) { make_periodic_feature_call(); WAIT(0); } if (!STREAMING::HAS_MODEL_LOADED(propHash)) { return false; } Vector3 minDimens; Vector3 maxDimens; GAMEPLAY::GET_MODEL_DIMENSIONS(propHash, &minDimens, &maxDimens); Object obj = OBJECT::CREATE_OBJECT_NO_OFFSET(propHash, coords.x, coords.y, coords.z, creationParam1, creationParam2, creationParam3); ENTITY::SET_ENTITY_VISIBLE(obj, false); OBJECT::PLACE_OBJECT_ON_GROUND_PROPERLY(obj); Vector3 objLocation = ENTITY::GET_ENTITY_COORDS(obj, 0); float objHeight = ENTITY::GET_ENTITY_HEIGHT(obj, objLocation.x, objLocation.y, objLocation.z, 1, 0); *result = objLocation.z - objHeight; if (minDimens.z < 0) { *result += minDimens.z; } OBJECT::DELETE_OBJECT(&obj); return true; }
void do_spawn_model(Hash propHash, char* model, std::string title, bool silent) { STREAMING::REQUEST_MODEL(propHash); DWORD now = GetTickCount(); while (!STREAMING::HAS_MODEL_LOADED(propHash) && GetTickCount() < now + 5000 ) { make_periodic_feature_call(); WAIT(0); } if (!STREAMING::HAS_MODEL_LOADED(propHash)) { std::ostringstream ss2; ss2 << "TIMEOUT: " << model; write_text_to_log_file(ss2.str()); return; } Ped playerPed = PLAYER::PLAYER_PED_ID(); FLOAT look = ENTITY::GET_ENTITY_HEADING(playerPed); FLOAT lookAni = look + 180.00; FLOAT lookOff = look + 90.00; FLOAT vecX = 0; FLOAT vecY = 0; BOOL getPosParam1 = 1; BOOL getPosParam2 = 1; BOOL getPosParam3 = 1; FLOAT spawnOffX = 0.0f; FLOAT spawnOffY = 3.5f; FLOAT spawnOffZ = 0.0f; Vector3 minDimens; Vector3 maxDimens; GAMEPLAY::GET_MODEL_DIMENSIONS(propHash, &minDimens, &maxDimens); spawnOffY = max(3.5f, 1.3f * max(maxDimens.x-minDimens.x, maxDimens.y-minDimens.y)); spawnOffZ = 0.0f; Vector3 coords = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(playerPed, spawnOffX, spawnOffY, spawnOffZ); float objZBase = 0; bool translatable = get_ground_height_at_position(coords, &objZBase); Object obj = OBJECT::CREATE_OBJECT_NO_OFFSET(propHash, coords.x, coords.y, coords.z, creationParam1, creationParam2, creationParam3); ENTITY::SET_ENTITY_VELOCITY(obj, 0.0f, 0.0f, 0.0f); ENTITY::SET_ENTITY_ROTATION(obj, 0, 0, 0, 0, false); if (ENTITY::DOES_ENTITY_EXIST(obj)) { ENTITY::SET_ENTITY_COLLISION(obj, 1, 0); //place on the ground doesn't work on half the items, so do it ourselves Vector3 curLocation = ENTITY::GET_ENTITY_COORDS(obj, 0); if (translatable) { if (minDimens.z < 0) { objZBase -= minDimens.z; } ENTITY::SET_ENTITY_COORDS_NO_OFFSET(obj, curLocation.x, curLocation.y, objZBase, 1, 1, 1); } else { //best effort in case of failure OBJECT::PLACE_OBJECT_ON_GROUND_PROPERLY(obj); } ENTITY::SET_ENTITY_HAS_GRAVITY(obj, propCreationHasGravity); if (propCreationIsInvincible) { ENTITY::SET_ENTITY_INVINCIBLE(obj, TRUE); ENTITY::SET_ENTITY_PROOFS(obj, 1, 1, 1, 1, 1, 1, 1, 1); ENTITY::SET_ENTITY_CAN_BE_DAMAGED(obj, FALSE); } ENTITY::FREEZE_ENTITY_POSITION(obj, propCreationIsImmovable); if (!propCreationIsImmovable) { //this unfreezes it ENTITY::APPLY_FORCE_TO_ENTITY(obj, 3, 0, 0, 0.1, 0, 0, 0, 0, 1, 1, 0, 0, 1); OBJECT::SET_ACTIVATE_OBJECT_PHYSICS_AS_SOON_AS_IT_IS_UNFROZEN(obj, TRUE); } ENTITY::SET_ENTITY_LOAD_COLLISION_FLAG(obj, true); if (propCreationIsOnFire) { FIRE::START_ENTITY_FIRE(obj); } ENTITY::SET_ENTITY_ALPHA(obj, ALPHA_VALUES[propCreationAlphaIndex], false); SpawnedPropInstance* record = new SpawnedPropInstance(); record->instance = obj; record->title = title; record->counter = find_highest_instance_num_of_prop(propHash) + 1; record->isInvincible = propCreationIsInvincible; record->isImmovable = propCreationIsImmovable; record->hasGravity = propCreationHasGravity; propsWeCreated.push_back(record); manage_prop_set(); } else { if (!silent) { std::ostringstream ss; ss << "Failed to create " << title; set_status_text(ss.str()); } std::ostringstream ss2; ss2 << "INVALID-PROP: " << model; write_text_to_log_file(ss2.str()); return; } if (!silent) { std::ostringstream ss; ss << "Spawned " << title; set_status_text(ss.str()); } STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(propHash); //ENTITY::SET_OBJECT_AS_NO_LONGER_NEEDED(&obj); }
// Updates all features that can be turned off by the game, being called each game frame void update_features() { /*int* gp = reinterpret_cast<int *>(getGlobalPtr(0x1801D9)); *gp = 1; gp = reinterpret_cast<int *>(getGlobalPtr(0x187385 + 0x10F18)); *gp = 1; gp = reinterpret_cast<int *>(getGlobalPtr(0x250FDB + 0xf158D)); *gp = 0; int* gp = reinterpret_cast<int *>(getGlobalPtr(0x42CA + 0x9)); *gp = 0xFF; */ everInitialised = true; game_frame_num++; if (game_frame_num >= 100000) { game_frame_num = 0; } if (game_frame_num % 1000 == 0) { DWORD myThreadID; HANDLE myHandle = CreateThread(0, 0, save_settings_thread, 0, 0, &myThreadID); CloseHandle(myHandle); } UpdateXInputControlState(); check_for_hotkey_presses(); if (is_menu_showing() || is_in_airbrake_mode()) { if (is_input_blocked_in_menu() || is_in_airbrake_mode()) { setGameInputToEnabled(false); } else { setGameInputToEnabled(true); } } else { setGameInputToEnabled(true); } if (is_in_airbrake_mode()) { setAirbrakeRelatedInputToBlocked(true); } else { setAirbrakeRelatedInputToBlocked(false); } update_centre_screen_status_text(); update_vehicle_guns(); update_world_features(); check_player_model(); //debug_native_investigation(); // common variables Player player = PLAYER::PLAYER_ID(); Ped playerPed = PLAYER::PLAYER_PED_ID(); BOOL bPlayerExists = ENTITY::DOES_ENTITY_EXIST(playerPed); //PLAYER::DISABLE_PLAYER_FIRING(playerPed, TRUE); // player invincible if (featurePlayerInvincibleUpdated) { if (bPlayerExists && !featurePlayerInvincible) PLAYER::SET_PLAYER_INVINCIBLE(player, FALSE); featurePlayerInvincibleUpdated = false; } if (featurePlayerInvincible) { if (bPlayerExists) PLAYER::SET_PLAYER_INVINCIBLE(player, TRUE); } //Wanted Level Frozen - prevents stars increasing/decreasing if (featureWantedLevelFrozen) { if (featureWantedLevelFrozenUpdated) { frozenWantedLevel = PLAYER::GET_PLAYER_WANTED_LEVEL(player); PLAYER::SET_MAX_WANTED_LEVEL(frozenWantedLevel); featureWantedLevelFrozenUpdated = false; if (frozenWantedLevel > 0) { std::stringstream ss; ss << "Wanted Level Frozen at: " << frozenWantedLevel << " Star"; if (frozenWantedLevel > 1){ ss << "s"; } set_status_text(ss.str()); } } if (frozenWantedLevel > 0) { if (bPlayerExists) { PLAYER::SET_PLAYER_WANTED_LEVEL(player, frozenWantedLevel, 0); PLAYER::SET_PLAYER_WANTED_LEVEL_NOW(player, 0); } } else { featureWantedLevelFrozen = false; set_status_text("You must have a Wanted Level first."); } } if (featureWantedLevelFrozenUpdated) { if (!featureWantedLevelFrozen) { set_status_text("Wanted Level Unfrozen"); PLAYER::SET_MAX_WANTED_LEVEL(5); } featureWantedLevelFrozenUpdated = false; } // player never wanted if (featurePlayerNeverWanted) { if (bPlayerExists) { PLAYER::CLEAR_PLAYER_WANTED_LEVEL(player); PLAYER::SET_MAX_WANTED_LEVEL(0); } } else if (featurePlayerNeverWantedUpdated) { PLAYER::SET_MAX_WANTED_LEVEL(5); } // police ignore player if (featurePlayerIgnoredByPolice) { if (bPlayerExists) { PLAYER::SET_POLICE_IGNORE_PLAYER(player, true); } } else if (featurePlayerIgnoredByPoliceUpdated) { if (bPlayerExists) { PLAYER::SET_POLICE_IGNORE_PLAYER(player, false); } featurePlayerIgnoredByPoliceUpdated = false; } // everyone ignores player if (featurePlayerIgnoredByAll) { update_nearby_peds(playerPed, 50); if (bPlayerExists) { PLAYER::SET_POLICE_IGNORE_PLAYER(player, true); PLAYER::SET_EVERYONE_IGNORE_PLAYER(player, true); PLAYER::SET_PLAYER_CAN_BE_HASSLED_BY_GANGS(player, false); PLAYER::SET_IGNORE_LOW_PRIORITY_SHOCKING_EVENTS(player, true); if (game_frame_num % 5 == 0) { set_all_nearby_peds_to_calm(); } } } else if (featurePlayerIgnoredByAllUpdated) { if (bPlayerExists) { PLAYER::SET_POLICE_IGNORE_PLAYER(player, featurePlayerIgnoredByPolice); PLAYER::SET_EVERYONE_IGNORE_PLAYER(player, false); PLAYER::SET_PLAYER_CAN_BE_HASSLED_BY_GANGS(player, true); PLAYER::SET_IGNORE_LOW_PRIORITY_SHOCKING_EVENTS(player, false); } featurePlayerIgnoredByAllUpdated = false; } // player special ability if (featurePlayerUnlimitedAbility) { if (bPlayerExists) PLAYER::_RECHARGE_SPECIAL_ABILITY(player, 1); } // player no noise if (featurePlayerNoNoiseUpdated) { if (bPlayerExists && !featurePlayerNoNoise) PLAYER::SET_PLAYER_NOISE_MULTIPLIER(player, 1.0); featurePlayerNoNoiseUpdated = false; } if (featurePlayerNoNoise) PLAYER::SET_PLAYER_NOISE_MULTIPLIER(player, 0.0); // player fast swim if (featurePlayerFastSwimUpdated) { if (bPlayerExists && !featurePlayerFastSwim) PLAYER::_SET_SWIM_SPEED_MULTIPLIER(player, 1.0); featurePlayerFastSwimUpdated = false; } if (featurePlayerFastSwim) PLAYER::_SET_SWIM_SPEED_MULTIPLIER(player, 1.49); // player fast run if (featurePlayerFastRunUpdated) { if (bPlayerExists && !featurePlayerFastRun) PLAYER::_SET_MOVE_SPEED_MULTIPLIER(player, 1.0); featurePlayerFastRunUpdated = false; } if (featurePlayerFastRun) PLAYER::_SET_MOVE_SPEED_MULTIPLIER(player, 1.49); // player super jump if (featurePlayerSuperJump) { if (bPlayerExists) GAMEPLAY::SET_SUPER_JUMP_THIS_FRAME(player); } //Player Invisible if (featurePlayerInvisibleUpdated) { featurePlayerInvisibleUpdated = false; if (bPlayerExists && featurePlayerInvisible) ENTITY::SET_ENTITY_VISIBLE(playerPed, false); else if (bPlayerExists){ ENTITY::SET_ENTITY_VISIBLE(playerPed, true); } } if (featurePlayerDrunkUpdated) { featurePlayerDrunkUpdated = false; if (featurePlayerDrunk) { STREAMING::REQUEST_ANIM_SET((char*)CLIPSET_DRUNK); while (!STREAMING::HAS_ANIM_SET_LOADED((char*)CLIPSET_DRUNK)) { make_periodic_feature_call(); WAIT(0); } PED::SET_PED_MOVEMENT_CLIPSET(playerPed, (char*)CLIPSET_DRUNK, 1.0f); CAM::SHAKE_GAMEPLAY_CAM("DRUNK_SHAKE", 1.0f); } else { PED::RESET_PED_MOVEMENT_CLIPSET(playerPed, 1.0f); CAM::STOP_GAMEPLAY_CAM_SHAKING(true); } AUDIO::SET_PED_IS_DRUNK(playerPed, featurePlayerDrunk); } update_weapon_features(bPlayerExists, player); update_vehicle_features(bPlayerExists, playerPed); update_misc_features(bPlayerExists, playerPed); update_time_features(player); //Disable airbrake on death if (ENTITY::IS_ENTITY_DEAD(playerPed)) { exit_airbrake_menu_if_showing(); } //----Hotkeys---- //Move through door (use '-key) //Pushes player through solid door objects. if (bPlayerExists) { bool throughDoorPressed = IsKeyJustUp(KeyConfig::KEY_HOT_AIRBRAKE_THROUGH_DOOR) || IsControllerButtonJustUp(KeyConfig::KEY_HOT_AIRBRAKE_THROUGH_DOOR); //bool disablePolicePressed = IsKeyJustUp(VK_OEM_6); if (throughDoorPressed) { moveThroughDoor(); } } }
//Test for airbrake command. void process_airbrake_menu() { exitFlag = false; const float lineWidth = 250.0; const int lineCount = 1; bool loadedAnims = false; std::string caption = "Airbrake"; //draw_menu_header_line(caption,350.0f,50.0f,15.0f,0.0f,15.0f,false); DWORD waitTime = 150; Ped playerPed = PLAYER::PLAYER_PED_ID(); bool inVehicle = PED::IS_PED_IN_ANY_VEHICLE(playerPed, 0) ? true : false; if (!inVehicle) { STREAMING::REQUEST_ANIM_DICT(AIRBRAKE_ANIM_A); while (!STREAMING::HAS_ANIM_DICT_LOADED(AIRBRAKE_ANIM_A)) { WAIT(0); } loadedAnims = true; } while (true && !exitFlag) { // timed menu draw, used for pause after active line switch DWORD maxTickCount = GetTickCount() + waitTime; do { // draw menu draw_menu_header_line(caption, 350.0f, 50.0f, 15.0f, 0.0f, 15.0f, false); //draw_menu_line(caption, lineWidth, 15.0, 18.0, 0.0, 5.0, false, true); make_periodic_feature_call(); WAIT(0); } while (GetTickCount() < maxTickCount); waitTime = 0; airbrake(inVehicle); //// process buttons //bool bSelect, bBack, bUp, bDown; //get_button_state(&bSelect, &bBack, &bUp, &bDown, NULL, NULL); if (airbrake_switch_pressed()) { menu_beep(); break; } } if (!inVehicle) { AI::CLEAR_PED_TASKS_IMMEDIATELY(PLAYER::PLAYER_PED_ID()); } exitFlag = false; }