function bool mutatorBroadcastMessage(Actor sender, Pawn receiver, out coerce string msg, optional bool bBeep, out optional name type) {
	//log("[DBG] mutatorBroadcastMessage(" $ sender $ ", " $ receiver $ ", " $ msg $ ", " $ type);
    if (nextMessageMutator != none) {
        return nextMessageMutator.mutatorBroadcastMessage(sender, receiver, msg, bBeep, type);
    } else {
        return true;
    }
}



function bool mutatorBroadcastLocalizedMessage(Actor sender, Pawn receiver, out class<LocalMessage> message, out optional int switch, out optional PlayerReplicationInfo relatedPRI_1, out optional PlayerReplicationInfo relatedPRI_2, out optional Object optionalObject) {
	//log("[DBG] mutatorBroadcastLocalizedMessage(" $ sender $ ", " $ receiver $ ", " $ message $ ", " $ switch $ ", " $ relatedPRI_1 $ ", " $ relatedPRI_2 $ ", " $ optionalObject);
    if (nextMessageMutator != none) {
        return nextMessageMutator.mutatorBroadcastLocalizedMessage(sender, receiver, message, switch, relatedPRI_1, relatedPRI_2, optionalObject);
    } else {
        return true;
    }
}


// HUD replacement settings.
var config bool bUseNexgenHUD;
var config string replacementClass[10];

bUseNexgenHUD = true;
replacementClass[0] = "BotPack.ChallengeCTFHUD=" $ class'NexgenUtil'.default.packageName $ ".NexgenCTFHUD";

if (sConf.bUseNexgenHUD) {
	setReplacementHUDClass();
}
	
/***************************************************************************************************
 *
 *  $DESCRIPTION  Attemps to replace the default HUD class with a Nexgen HUD class.
 *
 **************************************************************************************************/
function setReplacementHUDClass() {
	local string hudClassName;
	local string hudReplaceClassName;
	local class<HUD> replacementClass;
	local bool bFound;
	local int index;
	local int tokenIndex;
	
	// Find a suitable replacement class for the current HUD class.
	hudClassName = string(level.game.HUDType);
	while (!bFound && index < arrayCount(sConf.replacementClass) && sConf.replacementClass[index] != "") {
		tokenIndex = instr(sConf.replacementClass[index], "=");
		if (tokenIndex > 0 && left(sConf.replacementClass[index], tokenIndex) ~= hudClassName) {
			// Get replacement class.
			hudReplaceClassName = mid(sConf.replacementClass[index], tokenIndex + 1);
			replacementClass = class<HUD>(dynamicLoadObject(hudReplaceClassName, class'Class'));
			
			// Valid replacement class?
			if (replacementClass != none && classIsChildOf(replacementClass, level.game.HUDType)) {
				bFound = true;
			} else {
				index++;
			} 
		} else {
			index++;
		}
	}
	
	// Apply new HUD class if found.
	if (bFound) {
		level.game.HUDType = replacementClass;
	} else {
		nscLog("No replacement class found for" @ hudClassName);
	}
}



/***************************************************************************************************
 *
 *  $DESCRIPTION  Creates the windows for the Nexgen GUI at the client.
 *  $REQUIRE      !windowsInitialized
 *  $ENSURE       windowsInitialized && consoleWindow != none && popupWindow != none
 *
 **************************************************************************************************/
simulated function initializeWindows() {
	local float wWidth;
	local float wHeight;
	local float wTop;
	local float wLeft;
	local UWindowWindow window;
	
	// Setup console window.
	consoleWindow = WindowConsole(player.player.console);
	if (consoleWindow.bShowConsole) {
		consoleWindow.hideConsole();
	}
	if (consoleWindow.root == none) {
		consoleWindow.createRootWindow(none);
	}
	
	// Create popup window.
	wWidth = class'NexgenPopupFrame'.default.windowWidth;
	wHeight = class'NexgenPopupFrame'.default.windowHeight;
	wLeft = fMax(0.0, (consoleWindow.root.winWidth - wWidth) / 2.0);
	wTop = fMax(0.0,(consoleWindow.root.winHeight - wHeight) / 2.0);
	window = consoleWindow.root.createWindow(class'NexgenPopupFrame', wLeft, wTop, wWidth, wHeight);
	popupWindow = NexgenPopupFrame(window);
	popupWindow.gc = gc;
	popupWindow.sc = sc;
	popupWindow.serverID = sConf.serverID;
	popupWindow.close();
	
	// Create main window.
	wWidth = class'NexgenMainFrame'.default.windowWidth;
	wHeight = class'NexgenMainFrame'.default.windowHeight;
	wLeft = fMax(0.0,(consoleWindow.root.winWidth - wWidth) / 2.0);
	wTop = fMax(0.0,(consoleWindow.root.winHeight - wHeight) / 2.0);
	window = consoleWindow.root.createWindow(class'NexgenMainFrame', wLeft, wTop, wWidth, wHeight);
	mainWindow = NexgenMainFrame(window);
	mainWindow.close();
	
	// Add panels to the main window.
	mainWindow.mainPanel.addPanel("About", class'NexgenAboutPanel');
		
	windowsInitialized = true;
}