void make_minidump(EXCEPTION_POINTERS* e) { write_text_to_log_file("Dump requested"); auto hDbgHelp = LoadLibraryA("dbghelp"); if (hDbgHelp == nullptr) return; auto pMiniDumpWriteDump = (decltype(&MiniDumpWriteDump))GetProcAddress(hDbgHelp, "MiniDumpWriteDump"); if (pMiniDumpWriteDump == nullptr) return; auto hFile = CreateFileA(get_storage_dir_path("ENT-minidump.dmp"), GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) return; MINIDUMP_EXCEPTION_INFORMATION exceptionInfo; exceptionInfo.ThreadId = GetCurrentThreadId(); exceptionInfo.ExceptionPointers = e; exceptionInfo.ClientPointers = FALSE; auto dumped = pMiniDumpWriteDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MINIDUMP_TYPE(MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory), e ? &exceptionInfo : nullptr, nullptr, nullptr); CloseHandle(hFile); write_text_to_log_file("Dump complete"); return; }
void main() { //reset_globals(); setGameInputToEnabled(true, true); setAirbrakeRelatedInputToBlocked(false, true); write_text_to_log_file("Setting up calls"); set_periodic_feature_call(update_features); write_text_to_log_file("Loading settings"); load_settings(); init_vehicle_feature(); write_text_to_log_file("Loaded settings OK"); // this creates a new locale based on the current application default // (which is either the one given on startup, but can be overriden with // std::locale::global) - then extends it with an extra facet that // controls numeric output. std::locale comma_locale(std::locale(), new comma_numpunct()); // tell cout to use our new locale. std::cout.imbue(comma_locale); set_status_text("~HUD_COLOUR_MENU_YELLOW~ENT ~HUD_COLOUR_WHITE~is ready!"); while (true) { if (trainer_switch_pressed()) { menu_beep(); set_menu_showing(true); process_main_menu(); set_menu_showing(false); } else if (airbrake_switch_pressed()) { menu_beep(); process_airbrake_menu(); } update_features(); WAIT(0); } }
int filterException(int code, PEXCEPTION_POINTERS ex) { set_status_text("Whoops, ENT crashed!"); write_text_to_log_file("ScriptMain exception"); make_minidump(ex); return EXCEPTION_EXECUTE_HANDLER; }
int keyNameToVal(char * input) { std::ostringstream ss; ss << "Searching for " << input; write_text_to_log_file(ss.str()); for (int i = 0; i < (sizeof ALL_KEYS / sizeof ALL_KEYS[0]); i++) { if (strcmp(input, ALL_KEYS[i].name) == 0) { ss.str(""); ss.clear(); ss << "Found match of " << ALL_KEYS[i].name << " with code " << ALL_KEYS[i].keyCode; write_text_to_log_file(ss.str()); return ALL_KEYS[i].keyCode; } } return -1; }
void do_spawn_prop(PropInfo prop, bool silent) { Hash propHash = GAMEPLAY::GET_HASH_KEY((char *)prop.model); if (!STREAMING::IS_MODEL_IN_CDIMAGE(propHash) || !STREAMING::IS_MODEL_VALID(propHash)) { if (!silent) { std::ostringstream ss; ss << "Model " << prop.model << " is not valid"; set_status_text(ss.str()); } std::ostringstream ss2; ss2 << "INVALID-MODEL: " << prop.model; write_text_to_log_file(ss2.str()); return; } do_spawn_model(propHash, prop.model, prop.label, silent); }
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); }
LONG CALLBACK unhandled_handler(EXCEPTION_POINTERS* e) { write_text_to_log_file("Exception occured"); make_minidump(e); return EXCEPTION_EXECUTE_HANDLER; }
int filterException(int code, PEXCEPTION_POINTERS ex) { write_text_to_log_file("ScriptMain exception"); make_minidump(ex); return EXCEPTION_EXECUTE_HANDLER; }
void KeyInputConfig::set_key(char* function, char* keyName) { std::ostringstream ss; ss << "Key function " << function << " being given " << keyName; write_text_to_log_file(ss.str()); int vkID = keyNameToVal(keyName); if (vkID == -1) { ss.str(""); ss.clear(); ss << "Key function " << keyName << " didn't correspond to a value"; write_text_to_log_file(ss.str()); return; } if (strcmp(function, "menu_up") == 0) { key_menu_up = vkID; } else if (strcmp(function, "menu_down") == 0) { key_menu_down = vkID; } else if (strcmp(function, "menu_left") == 0) { key_menu_left = vkID; } else if (strcmp(function, "menu_right") == 0) { key_menu_right = vkID; } else if (strcmp(function, "menu_select") == 0) { key_menu_confirm = vkID; } else if (strcmp(function,"menu_back") == 0) { key_menu_back = vkID; } else if (strcmp(function, "toggle_main_menu") == 0) { key_toggle_main_menu = vkID; } else if (strcmp(function, "veh_boost") == 0) { key_veh_boost = vkID; } else if (strcmp(function, "veh_stop") == 0) { key_veh_stop = vkID; } else if (strcmp(function, "veh_rockets") == 0) { key_veh_rockets = vkID; } else if (strcmp(function, "toggle_airbrake") == 0) { key_toggle_airbrake = vkID; } else if (strcmp(function, "airbrake_up") == 0) { key_airbrake_up = vkID; } else if (strcmp(function, "airbrake_down") == 0) { key_airbrake_down = vkID; } else if (strcmp(function, "airbrake_forward") == 0) { key_airbrake_forward = vkID; } else if (strcmp(function, "airbrake_back") == 0) { key_airbrake_back = vkID; } else if (strcmp(function, "airbrake_rotate_left") == 0) { key_airbrake_rotate_left = vkID; } else if (strcmp(function, "airbrake_rotate_right") == 0) { key_airbrake_rotate_right = vkID; } else if (strcmp(function, "airbrake_speed") == 0) { key_airbrake_speed = vkID; } else { ss.str(""); ss.clear(); ss << "Key function " << function << " didn't correspond to a known function"; write_text_to_log_file(ss.str()); } };
/**Read the XML config file. Currently contains keyboard choices.*/ void read_config_file() { TrainerConfig *result = new TrainerConfig(); CoInitialize(NULL); //read XML MSXML2::IXMLDOMDocumentPtr spXMLDoc; spXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60)); if (!spXMLDoc->load("ent-config.xml")) { write_text_to_log_file("No config found, using defaults"); config = result; //the default config } IXMLDOMNodeListPtr nodes = spXMLDoc->selectNodes(L"//ent-config/keys/key"); long length; nodes->get_length(&length); for (int i = 0; i < length; i++) { IXMLDOMNode *node; nodes->get_item(i, &node); IXMLDOMNamedNodeMap *attribs; node->get_attributes(&attribs); long length_attribs; attribs->get_length(&length_attribs); char *attrib_key_func = NULL; char *attrib_key_value = NULL; for (long j = 0; j < length_attribs; j++) { IXMLDOMNode *attribNode; attribs->get_item(j, &attribNode); attribNode->get_nodeName(&bstr); if (wcscmp(bstr, L"function") == 0) { VARIANT var; VariantInit(&var); attribNode->get_nodeValue(&var); attrib_key_func = _com_util::ConvertBSTRToString(V_BSTR(&var)); } else if (wcscmp(bstr, L"value") == 0) { VARIANT var; VariantInit(&var); attribNode->get_nodeValue(&var); attrib_key_value = _com_util::ConvertBSTRToString(V_BSTR(&var)); } SysFreeString(bstr); attribNode->Release(); } if (attrib_key_func != NULL && attrib_key_value != NULL) { result->get_key_config()->set_key(attrib_key_func, attrib_key_value); } delete attrib_key_func; delete attrib_key_value; attribs->Release(); node->Release(); } //nodes->Release(); //don't do this, it crashes on exit spXMLDoc.Release(); CoUninitialize(); config = result; }
void CallbackCallee::cb_func(){ write_text_to_log_file("GENERIC CALLBACK"); }