Exemple #1
0
static int fetch(float *avatar_pos, float *avatar_front, float *avatar_top, float *camera_pos, float *camera_front, float *camera_top, std::string &context, std::wstring &identity) {
    for (int i=0; i<3; i++) {
        avatar_pos[i] = avatar_front[i] = avatar_top[i] = camera_pos[i] = camera_front[i] = camera_top[i] = 0.0f;
    }

    // Memory addresses
    char game_name[20];
    procptr64_t state_address, in_game_address, avatar_pos_address, camera_pos_address, avatar_base_address, camera_front_address, camera_top_address, player_address, vehicle_address, location_address, street_address;

#define VERSION_EQ(buf, strlit) \
	memcmp(buf, strlit, std::min(sizeof(buf), sizeof(strlit)-1)) == 0

    // Steam version
    if (peekProc(pModule + 0x17C6330, game_name) && VERSION_EQ(game_name, "Grand Theft Auto V")) {
        state_address = pModule + 0x268C370;
        in_game_address = pModule + 0x1B76454;
        avatar_pos_address = pModule + 0x1F05230;
        camera_pos_address = pModule + 0x1C08080;
        avatar_base_address = pModule + 0x1B463D0;
        camera_front_address = pModule + 0x1C09B40;
        camera_top_address = pModule + 0x1EDA440;
        player_address = pModule + 0x2696B0C;
        vehicle_address = pModule + 0x228DDC0;
        location_address = pModule + 0x228D79B;
        street_address = pModule + 0x228A550;
        // Retail version
    } else if (peekProc(pModule + 0x17C3280, game_name) && VERSION_EQ(game_name, "Grand Theft Auto V")) {
        state_address = pModule + 0x2688DB0;
        in_game_address = pModule + 0x1B73ED4;
        avatar_pos_address = pModule + 0x1F01E40;
        camera_pos_address = pModule + 0x1C06950;
        avatar_base_address = pModule + 0x1B433D0;
        camera_front_address = pModule + 0x1C06960;
        camera_top_address = pModule + 0x1ED6FF0;
        player_address = pModule + 0x26934AC;
        vehicle_address = pModule + 0x228A9A0;
        location_address = pModule + 0x228A38B;
        street_address = pModule + 0x22870C0;
        // Unknown version
    } else {
        generic_unlock();
        return false;
    }

    // Avatar pointer
    procptr64_t avatar_base = peekProc<procptr64_t>(avatar_base_address);
    if (!avatar_base) return false;

    // Boolean value to check if game addresses retrieval is successful
    bool ok;
    // Create containers to stuff our raw data into, so we can convert it to Mumble's coordinate system
    float avatar_pos_corrector[3], camera_pos_corrector[3], avatar_front_corrector[3], avatar_top_corrector[3], camera_front_corrector[3], camera_top_corrector[3];
    // Char values for extra features
    char state, in_game, player[50], vehicle[50], location[50], street[50];

    // Peekproc and assign game addresses to our containers, so we can retrieve positional data
    ok = peekProc(state_address, &state, 1) && // Magical state value: 0 when in single player, 2 when online and 3 when in a lobby.
         peekProc(in_game_address, &in_game, 1) && // 0 when loading or not in-game, 1 when in-game.
         peekProc(avatar_pos_address, avatar_pos_corrector, 12) && // Avatar Position values (X, Z and Y).
         peekProc(camera_pos_address, camera_pos_corrector, 12) && // Camera Position values (X, Z and Y).
         peekProc(avatar_base + 0x70, avatar_front_corrector, 12) && // Avatar Front Vector values (X, Z and Y).
         peekProc(avatar_base + 0x80, avatar_top_corrector, 12) && // Avatar Top Vector values (X, Z and Y).
         peekProc(camera_front_address, camera_front_corrector, 12) && // Camera Front Vector values (X, Z and Y).
         peekProc(camera_top_address, camera_top_corrector, 12) && // Camera Top Vector values (X, Z and Y).
         peekProc(player_address, player) && // Player nickname.
         peekProc(vehicle_address, vehicle) && // Vehicle name if in a vehicle, empty if not.
         peekProc(location_address, location) && // Location name.
         peekProc(street_address, street); // Street name if on a street, empty if not.

    // This prevents the plugin from linking to the game in case something goes wrong during values retrieval from memory addresses.
    if (! ok)
        return false;

    // State
    if (state != 2 || in_game == 0) { // If not in-game
        context.clear(); // Clear context
        identity.clear(); // Clear identity
        // Set vectors values to 0.
        for (int i=0; i<3; i++)
            avatar_pos[i] = avatar_front[i] = avatar_top[i] = camera_pos[i] =  camera_front[i] = camera_top[i] = 0.0f;

        return true; // This tells Mumble to ignore all vectors.
    }
    /*
    // Begin context
    std::ostringstream ocontext;

    // Host
    escape(host);
    if (strcmp(host, "") != 0 && strstr(host, "127.0.0.1") == NULL) { // Set host string as empty if "127.0.0.1" is found in it.
    	ocontext << " {\"Host\": \"" << host << "\"}"; // Set context with IP address and port
    }

    context = ocontext.str();
    // End context
    */
    // Begin identity
    std::wostringstream oidentity;
    oidentity << "{";

    // Player
    escape(player, sizeof(player));
    if (strcmp(player, "") != 0) {
        oidentity << std::endl;
        oidentity << "\"Player\": \"" << player << "\","; // Set player nickname in identity.
    } else {
        oidentity << std::endl << "\"Player\": null,";
    }

    // Vehicle
    escape(vehicle, sizeof(vehicle));
    if (strcmp(vehicle, "") != 0) {
        oidentity << std::endl;
        oidentity << "\"Vehicle\": \"" << vehicle << "\","; // Set vehicle name in identity.
    } else {
        oidentity << std::endl << "\"Vehicle\": null,";
    }

    // Location
    escape(location, sizeof(location));
    if (strcmp(location, "") != 0) {
        oidentity << std::endl;
        oidentity << "\"Location\": \"" << location << "\","; // Set location name in identity.
    } else {
        oidentity << std::endl << "\"Location\": null,";
    }

    // Street
    escape(street, sizeof(street));
    if (strcmp(street, "") != 0) {
        oidentity << std::endl;
        oidentity << "\"Street\": \"" << street << "\""; // Set street name in identity.
    } else {
        oidentity << std::endl << "\"Street\": null";
    }

    oidentity << std::endl << "}";
    identity = oidentity.str();
    // End identity

    /*
    Mumble | Game
    X      | X
    Y      | Z
    Z      | Y
    */
    avatar_pos[0] = avatar_pos_corrector[0];
    avatar_pos[1] = avatar_pos_corrector[2];
    avatar_pos[2] = avatar_pos_corrector[1];

    camera_pos[0] = camera_pos_corrector[0];
    camera_pos[1] = camera_pos_corrector[2];
    camera_pos[2] = camera_pos_corrector[1];

    avatar_front[0] = avatar_front_corrector[0];
    avatar_front[1] = avatar_front_corrector[2];
    avatar_front[2] = avatar_front_corrector[1];

    avatar_top[0] = avatar_top_corrector[0];
    avatar_top[1] = avatar_top_corrector[2];
    avatar_top[2] = avatar_top_corrector[1];

    camera_front[0] = camera_front_corrector[0];
    camera_front[1] = camera_front_corrector[2];
    camera_front[2] = camera_front_corrector[1];

    camera_top[0] = camera_top_corrector[0];
    camera_top[1] = camera_top_corrector[2];
    camera_top[2] = camera_top_corrector[1];

    return true;
}
Exemple #2
0
static int trylock(const std::multimap<std::wstring, unsigned long long int> &pids)
{
	if (!initialize(pids, L"Borderlands2.exe")) {
		return false;
	}

	unsigned char detected_version[32];

	// Note for further versions:
	// The "version" string above change. However, it looks like it will always start
	// with "WILLOW2-". Everything after this can change between versions.
	// Position vectors are read as triplet (X,Y,Z). The tree triplet are in this order:
	// front, top, position.
	// When entering the game, in Sanctuary (after liftoff), with the character Zero,
	// the reading are the following (rounded):
	// front.X = 0
	// front.Y = 0
	// front.Z = 1
	// top.X = 0
	// top.Y = 1
	// top.Z = 0
	// pos.X = -8109
	// pos.Y = 3794
	// pos.Z = 2930
	// The "state" ptr is just a value that reliably alternate between 0 (in main menu)
	// and 1 (not in main menu). There is a lot of value that keep reliably changing even 
	// across restart, change of characters...
	// Note that I couldn't find an address that would do this reliably with the game "pause" 
	// menu, only the main menu (when you initially start the game, or completely exit your
	// current game)

	// VERSION_EQ safely checks whether the content of `buf'
	// (a buffer in the form of a C-style array of unsigned char)
	// contains the byte-level content of the string literal `strlit'.
	//
	// The NUL terminator of the string literal is not considered in
	// this equality check.
#define VERSION_EQ(buf, strlit) \
	memcmp(buf, strlit, std::min(sizeof(buf), sizeof(strlit)-1)) == 0

	// 1.3.1
	if (peekProc(pModule + 0x1E6D048, detected_version)
		&& VERSION_EQ(detected_version, "WILLOW2-PCSAGE-28-CL697606"))
	{
		vects_ptr = pModule + 0x1E792B0;
		state_ptr = pModule + 0x1E79BC8;
		character_name_ptr_loc = pModule + 0x1E7302C;
	}
	// 1.4.0
	else if (peekProc(pModule + 0x1E8D1D8, detected_version)
		&& VERSION_EQ(detected_version, "WILLOW2-PCSAGE-77-CL711033"))
	{
		vects_ptr = pModule + 0x1E993F0;
		state_ptr = pModule + 0x1E99D08;
		character_name_ptr_loc = pModule + 0x1E93194;
	}
	// 1.5.0
	else if (peekProc(pModule + 0x01E9F338, detected_version)
		&& VERSION_EQ(detected_version, "WILLOW2-PCLILAC-60-CL721220"))
	{
		vects_ptr = pModule + 0x1EAB650;
		state_ptr = pModule + 0x1EABF68;
		character_name_ptr_loc = pModule + 0x01EA5384;
	}
	// 1.7.0
	else if (peekProc(pModule + 0x01ED53A8, detected_version)
		&& VERSION_EQ(detected_version, "WILLOW2-PCALLIUM-55-CL770068"))
	{
		vects_ptr = pModule + 0x1EE18E0;
		state_ptr = pModule + 0x1EE21F8;
		character_name_ptr_loc = pModule + 0x01EDB5B4;
	}
	else
	{
		generic_unlock();
		return false;
	}

	// Check if we can get meaningful data from it
	float apos[3], afront[3], atop[3];
	float cpos[3], cfront[3], ctop[3];
	std::wstring sidentity;
	std::string scontext;

	if (fetch(apos, afront, atop, cpos, cfront, ctop, scontext, sidentity)) {
		return true;
	} else {
		generic_unlock();
		return false;
	}
}