Talk:Spectate Mode

From wowdev
Revision as of 04:29, 13 February 2012 by NightQuest (talk | contribs) (Created page with 'This is actually editing the player flags (0x8 bytes past the player fields - the duel arbiter is at 0x0) The flag value for enabling this is actually plrFlags OR 0x00480000 (0x0…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This is actually editing the player flags (0x8 bytes past the player fields - the duel arbiter is at 0x0) The flag value for enabling this is actually plrFlags OR 0x00480000 (0x00400000|0x00080000).

Example (C++ - 2.4.3):

// Player offsets
#define PLAYER_BASE_PTR								0x00A28D28
#define PLAYER_FIELDS_OFFSET						0x00001190
#define PLAYER_DUEL_ARBITER							0x00000000
#define PLAYER_FLAGS								0x00000008

#define PLAYER_COMMENTATOR_X						0x008EE474
#define PLAYER_COMMENTATOR_Y						0x008EE478
#define PLAYER_COMMENTATOR_Z						0x008EE47C
#define PLAYER_COMMENTATOR_COLLISION				0x008EE4B0

#define PLAYER_POSITION_X_OFFSET					0x00000BF0
#define PLAYER_POSITION_Y_OFFSET					0x00000BF4
#define PLAYER_POSITION_Z_OFFSET					0x00000BF8
#define PLAYER_POSITION_O_OFFSET					0x00000BFC
enum PlayerFlags
{
	PLAYER_FLAGS_COMMENTATOR						= 0x00080000, // 19 
	PLAYER_FLAGS_CAN_USE_COMMENTATOR_COMMANDS		= 0x00400000, // 22 
};

// Does a bitwise OR operation on the player flags, adding whatever is passed.
// Returns true on success.
bool WoWPlayer::SetFlags(DWORD flags)
{
	PBYTE FlagsPtr = GetPlayerFlagsBase();
	DWORD PlrFlags = NULL;
	SIZE_T size = 0;

	if( !FlagsPtr )
		return false;

	// Read the player flags and do a bitwise OR on them, adding the passed flags to them
	PlrFlags = GetFlags() | flags;

	// Write the new flags back to the player flags in memory
	if( !WriteProcessMemory(hProcess, FlagsPtr, &PlrFlags, sizeof(DWORD), &size) || size != sizeof(DWORD) )
		return false;

	return true;
}

bool WoWPlayer::SetCommentatorMode(bool bEnable)
{
	// Retrieve the player flags
	DWORD PlrFlags = GetFlags();
	SIZE_T size = 0;

	if( bEnable )
	{
		// Read the players position
		Vec4 pos = GetPosition();

		// Increase the Z axis so the camera doesn't appear at ground level
		pos.Z += 10.0f;

		// Copy the players position to the commentator camera's position, with a slight offset to Z
		if( !WriteProcessMemory(hProcess, (baseAddress + PLAYER_COMMENTATOR_X), &pos.X, sizeof(float), &size) || size != sizeof(float) )
			return false;
		if( !WriteProcessMemory(hProcess, (baseAddress + PLAYER_COMMENTATOR_Y), &pos.Y, sizeof(float), &size) || size != sizeof(float) )
			return false;
		if( !WriteProcessMemory(hProcess, (baseAddress + PLAYER_COMMENTATOR_Z), &pos.Z, sizeof(float), &size) || size != sizeof(float) )
			return false;

		// Write the player flags back to memory, to enable commentator mode
		return SetFlags(PLAYER_FLAGS_COMMENTATOR|PLAYER_FLAGS_CAN_USE_COMMENTATOR_COMMANDS);
	}

	// Write the player flags back to memory, to disable commentator mode
	return RemoveFlags(PLAYER_FLAGS_COMMENTATOR|PLAYER_FLAGS_CAN_USE_COMMENTATOR_COMMANDS);
}

With that code, you'd just call

plr->SetCommentatorMode(true);

--NightQuest 02:29, 13 February 2012 (UTC)