rem: ClearSemaphore (&GraphicsSem);
add: ClearSemaphore (GraphicsSem);
context: DoLoadTeam (INPUT_STATE InputState, PMELEE_STATE pMS){	SIZE index;	if (InputState & DEVICE_EXIT)		return (FALSE);	if (!pMS->Initialized)	{		SetSemaphore (&GraphicsSem);		Select (pMS->MeleeOption);		if ((pMS->TopTeamIndex = pMS->CurIndex) == (COUNT)~0)			pMS->TopTeamIndex = pMS->CurIndex = 0;		else if (pMS->TopTeamIndex <= MAX_VIS_TEAMS / 2)			pMS->TopTeamIndex = 0;		else			pMS->TopTeamIndex -= MAX_VIS_TEAMS / 2;		DrawFileStrings (pMS, -1);		pMS->Initialized = TRUE;		pMS->InputFunc = DoLoadTeam;		ClearSemaphore (&GraphicsSem);	}	else if (InputState & (DEVICE_BUTTON1 | DEVICE_BUTTON2))	{		if (!(InputState & DEVICE_BUTTON2))		{			pMS->TeamImage[pMS->side] = pMS->FileList[					pMS->CurIndex - pMS->TopTeamIndex					];			pMS->star_bucks[pMS->side] =					GetTeamValue (&pMS->TeamImage[pMS->side]);		}		pMS->InputFunc = DoMelee;		{			RECT r;						GetFrameRect (SetAbsFrameIndex (MeleeFrame, 28), &r);			SetSemaphore (&GraphicsSem);			RepairMeleeFrame (&r);			ClearSemaphore (&GraphicsSem);		}		InTime = GetTimeCounter ();	}	else	{		SIZE old_index, NewTop;		NewTop = pMS->TopTeamIndex;		index = old_index = pMS->CurIndex;		if (GetInputYComponent (InputState) < 0)		{			if (index-- == 0)				index = 0;			if (index < NewTop && (NewTop -= MAX_VIS_TEAMS) < 0)				NewTop = 0;		}		else if (GetInputYComponent (InputState) > 0)		{			if ((int)index < (int)GetDirEntryTableCount (pMS->TeamDE) + NUM_PREBUILT - 1)				++index;			if ((int)index > (int)pMS->BotTeamIndex)				NewTop = index;		}		else if (InputState & DEVICE_LEFTSHIFT)		{			if ((index -= MAX_VIS_TEAMS) < 0)				index = NewTop = 0;			else			{				if ((NewTop -= MAX_VIS_TEAMS) < 0)					NewTop = 0;			}		}		else if (InputState & DEVICE_RIGHTSHIFT)		{			if ((int)(index += MAX_VIS_TEAMS) <					(int)(GetDirEntryTableCount (pMS->TeamDE) + NUM_PREBUILT))				NewTop += MAX_VIS_TEAMS;			else			{				index = GetDirEntryTableCount (pMS->TeamDE) + NUM_PREBUILT - 1;				if (index - (MAX_VIS_TEAMS - 1) > NewTop)				{					if ((NewTop = index - (MAX_VIS_TEAMS - 1)) < 0)						NewTop = 0;				}			}		}		if (index != old_index)		{			SetSemaphore (&GraphicsSem);			if ((int)NewTop == (int)pMS->TopTeamIndex)				Deselect (pMS->MeleeOption);			else			{				pMS->TopTeamIndex = NewTop;				DrawFileStrings (pMS, -1);			}			pMS->CurIndex = index;			ClearSemaphore (&GraphicsSem);		}	}	return (TRUE);}