Exemplo n.º 1
0
void UOpenALAudioSubsystem::RegisterMusic( UMusic* Music )
{
	guard(UOpenALAudioSubsystem::RegisterMusic);

	checkSlow(Music);
	if( !Music->Handle )
	{
		// Set the handle to avoid reentrance.
		Music->Handle = (void*)-1;

		// Load the data.
		Music->Data.Load();
		debugf( NAME_DevMusic, TEXT("Register music: %s (%i)"), Music->GetPathName(), Music->Data.Num() );
		check(Music->Data.Num()>0);

		// Load the module.
		MREADER* Reader = BuildMikModMemoryReader( &Music->Data(0), Music->Data.Num() );
		MODULE* Module = Player_LoadGeneric( Reader, 64, 0 );
		DestroyMikModMemoryReader( Reader );
		if( Module == NULL )
			appErrorf(
				TEXT("Couldn't load music '%s': %s"),
				Music->GetPathName(), MikMod_strerror( MikMod_errno )
			);
		Music->Handle = Module;

		// Enable looping and wrapping.
		Module->loop = Module->wrap = 1;

		// Unload the data.
		Music->Data.Unload();
	}

	unguard;
}
FArchive* FFileManagerWindows::InternalCreateFileReader( const TCHAR* Filename, DWORD Flags, FOutputDevice* Error )
{
	INT StatsHandle = FILE_IO_STATS_GET_HANDLE( Filename );
	SCOPED_FILE_IO_READ_OPEN_STATS( StatsHandle );

	DWORD  Access    = GENERIC_READ;
	DWORD  WinFlags  = FILE_SHARE_READ;
	DWORD  Create    = OPEN_EXISTING;
	HANDLE Handle    = CreateFileW( Filename, Access, WinFlags, NULL, Create, FILE_ATTRIBUTE_NORMAL, NULL );
	if( Handle==INVALID_HANDLE_VALUE )
	{
		if( Flags & FILEREAD_NoFail )
		{
			appErrorf( TEXT("Failed to read file: %s"), Filename );
		}
		return NULL;
	}

	FArchive* retArch = new FArchiveFileReaderWindows(Handle,StatsHandle,Filename,Error,GetFileSize(Handle,NULL));
	if( retArch && (Flags & FILEREAD_SaveGame) )
	{
		retArch->SetIsSaveGame( TRUE );
	}
	return retArch;
}
Exemplo n.º 3
0
void UOpenALAudioSubsystem::RegisterSound( USound* Sound )
{
	guard(UOpenALAudioSubsystem::RegisterSound);

	checkSlow(Sound);
	if( !Sound->Handle )
	{
		// Set the handle to avoid reentrance.
		Sound->Handle = (void*)-1;

		// Load the data.
		Sound->Data.Load();
		debugf( NAME_DevSound, TEXT("Register sound: %s (%i)"), Sound->GetPathName(), Sound->Data.Num() );
		check(Sound->Data.Num()>0);

		// Flush errors.
		alGetError();

		// Create the buffer.
		FAudioBuffer *Sample = new FAudioBuffer;
		Sample->Id = alureCreateBufferFromMemory( &Sound->Data(0), Sound->Data.Num() );
		if( Sample->Id == AL_NONE )
			appErrorf(
				TEXT("Couldn't create buffer for sound '%s': %s"),
				Sound->GetPathName(), alureGetErrorString()
			);
		Sound->Handle = Sample;

		// Unload the data.
		Sound->Data.Unload();
	}

	unguard;
}
Exemplo n.º 4
0
UBOOL CreateAudioThread(AudioThread* NewThread, void* (*ThreadRoutine)(void*) )
{
	// Allocate a new thread.
	pthread_t* NewPosixThread;
	NewPosixThread = (pthread_t*) appMalloc(sizeof(pthread_t), TEXT("POSIX Thread"));

	// Initialize parameters.
	pthread_attr_t NewThreadAttributes;
	pthread_attr_init(&NewThreadAttributes);
	pthread_attr_setdetachstate(&NewThreadAttributes, PTHREAD_CREATE_JOINABLE);

	// Try to create the thread.
	NewThread->Valid = 1;
	INT Error = pthread_create(NewPosixThread, &NewThreadAttributes, ThreadRoutine, NULL);
	if (Error != 0)
	{
		// Some error occured.
		NewThread->Valid = 0;
		appErrorf( TEXT("Failed to create a valid mixing thread.") );
		return 0;
	}
	NewThread->Thread = NewPosixThread;
	NewThread->Exited = 0;
	debugf( NAME_Init, TEXT("Created a new audio thread.") );

	return 1;
}
Exemplo n.º 5
0
// Convert an 8 bit unsigned voice to the current rate.
// Maintains unsignedness.
void ConvertVoice8( Voice* InVoice )
{
	// How fast is this sample?
	INT VoiceRate = InVoice->pSample->SamplesPerSec;
	if ((VoiceRate != 11025) && (VoiceRate != 22050) && (VoiceRate != 44100))
		appErrorf( TEXT("Unsupported playback rate: %i"), VoiceRate );
	if (VoiceRate > AudioRate)
	{
		// This voice is slower than our current rate.
		INT RateFactor = VoiceRate / AudioRate;
		INT NewSize;
		if (InVoice->pSample->Length % 2 == 1)
			NewSize = (InVoice->pSample->Length+1) / RateFactor;
		else
			NewSize = InVoice->pSample->Length / RateFactor;
		BYTE* Source = (BYTE*) InVoice->pSample->Data;
		BYTE* NewData = (BYTE*) appMalloc(NewSize, TEXT("Sample Data"));
		check(NewData);
		BYTE* Dest = NewData;

		appMemset( Dest, 0x80, NewSize );
		for (INT i=0; i<InVoice->pSample->Length; i += RateFactor)
		{
			*Dest = Source[i];
			Dest++;
		}

		InVoice->PlayPosition = 0;
		InVoice->pSample->SamplesPerSec = AudioRate;
		InVoice->pSample->Length = NewSize;
		void* OldData = InVoice->pSample->Data;
		InVoice->pSample->Data = NewData;
		appFree( OldData );
	} else {
		// This voice is faster than our current rate.
		INT RateFactor = AudioRate / VoiceRate;
		INT NewSize = InVoice->pSample->Length * RateFactor;

		BYTE* Source = (BYTE*) InVoice->pSample->Data;
		BYTE* NewData = (BYTE*) appMalloc(NewSize, TEXT("Sample Data"));
		check(NewData);
		BYTE* Dest = NewData;

		appMemset( Dest, 0x80, NewSize );
		for (INT i=0; i<NewSize; i++)
		{
			Dest[i] = *Source;
			if (i%RateFactor == 1)
				Source++;
		}

		InVoice->PlayPosition = 0;
		InVoice->pSample->SamplesPerSec = AudioRate;
		InVoice->pSample->Length = NewSize;
		void* OldData = InVoice->pSample->Data;
		InVoice->pSample->Data = (void*) NewData;
		appFree( OldData );
	}
}
Exemplo n.º 6
0
static void CheckALErrorFlag( const TCHAR* Tag )
{
	guard(CheckALErrorFlag);

	ALenum Error = alGetError();
	if( Error != AL_NO_ERROR )
	{
		const ALchar* Msg = alGetString( Error );
		if( Msg == NULL ) Msg = "Unknown error";
		appErrorf( TEXT("%s failure: %s (%d)"), Tag, Msg, Error );
	}

	unguard;
}
Exemplo n.º 7
0
void VEngine::Init()
{
	InitStaticData();

	if( ParseParam(appCmdLine(), TEXT("FIXEDSEED")) )
	{
		appRandInit(0);
	}
	else
	{
		appRandInit(appCycles());
	}

	// Init client
	_GameClient = Cast<VWindowClient>(VObject::StaticConstructObject(_GameViewportClass));
	_GameClient->Init();

	// Init GameViewport
	VGameViewportClientPtr ViewportClient = NULL;
	if( _GameClient )
	{
		ViewportClient = Cast<VGameViewportClient>(VObject::StaticConstructObject(_GameClientClass));
		_GameViewport = ViewportClient;
	}

	if( ViewportClient )
	{
		FString Error;
		if( !ViewportClient->Init(Error) )
		{
			appErrorf(TEXT("%s"), Error.c_str());
			return;
		}

		FViewport* Viewport = _GameClient->CreateViewport(ViewportClient, TEXT("Product"), 800, 600, FALSE);
		_GameViewport->SetViewport(Viewport);
	}

	GLog->Log(NAME_Init, TEXT("Game engine initialized"));
}
FArchive* FFileManagerWindows::InternalCreateFileWriter( const TCHAR* Filename, DWORD Flags, FOutputDevice* Error )
{
	INT StatsHandle = FILE_IO_STATS_GET_HANDLE( Filename );
	SCOPED_FILE_IO_WRITE_OPEN_STATS( StatsHandle );

	MakeDirectory(*FFilename(Filename).GetPath(), TRUE);

	if( (GFileManager->FileSize (Filename) >= 0) && (Flags & FILEWRITE_EvenIfReadOnly) )
	{
		SetFileAttributesW(Filename, 0);
	}
	DWORD  Access    = GENERIC_WRITE;
	DWORD  WinFlags  = (Flags & FILEWRITE_AllowRead) ? FILE_SHARE_READ : 0;
	DWORD  Create    = (Flags & FILEWRITE_Append) ? OPEN_ALWAYS : (Flags & FILEWRITE_NoReplaceExisting) ? CREATE_NEW : CREATE_ALWAYS;
	HANDLE Handle    = CreateFileW( Filename, Access, WinFlags, NULL, Create, FILE_ATTRIBUTE_NORMAL, NULL );
	INT    Pos       = 0;
	if( Handle==INVALID_HANDLE_VALUE )
	{
		if( Flags & FILEWRITE_NoFail )
		{
			const DWORD LastError = GetLastError();
			appErrorf( TEXT("Failed to create file: %s, GetLastError %u"), Filename, LastError );
		}
		return NULL;
	}
	if( Flags & FILEWRITE_Append )
	{
		Pos = SetFilePointer( Handle, 0, NULL, FILE_END );
	}
	FArchive* retArch = new FArchiveFileWriterWindows(Handle,StatsHandle,Filename,Error,Pos);
	if( retArch && (Flags & FILEWRITE_SaveGame) )
	{
		retArch->SetIsSaveGame( TRUE );
	}
	return retArch;
}
Exemplo n.º 9
0
//
// Constructor.
//
UXViewport::UXViewport()
:	UViewport()
,	ViewportStatus( X_ViewportOpening )
{
	guard(UXViewport::UXViewport);

	// Open the display.
	XDisplay = XOpenDisplay(0);
	if (!XDisplay)
		appErrorf( TEXT("Can't open X server display.  XViewport requires X windows.") );

	// Create the default window.
	XSetWindowAttributes swa;
	swa.colormap = DefaultColormap(XDisplay, DefaultScreen(XDisplay));
	swa.border_pixel = 0;
	swa.override_redirect = True;
//	swa.override_redirect = False;
	swa.event_mask = ExposureMask | StructureNotifyMask | 
		KeyPressMask | KeyReleaseMask | ButtonPressMask | 
		ButtonReleaseMask | ButtonMotionMask | ResizeRedirectMask |
		PointerMotionMask | FocusChangeMask;
	XWindow = XCreateWindow(
		XDisplay,
		DefaultRootWindow(XDisplay),
		0, 0,
		640, 480,
		0,
		DefaultDepth(XDisplay, DefaultScreen(XDisplay)),
		InputOutput, DefaultVisual(XDisplay, DefaultScreen(XDisplay)),
		CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &swa
	);

	TCHAR WindowName[80];
	appSprintf( WindowName, TEXT("Unreal Tournament") );
	XStoreName( XDisplay, XWindow, WindowName );

	XMapWindow(XDisplay, XWindow);
	Mapped = True;

	// Set color bytes based on screen resolution.
	switch( DefaultDepth( XDisplay, 0 ) )
	{
		case 8:
			ColorBytes  = 2;
			break;
		case 16:
			ColorBytes  = 2;
			Caps       |= CC_RGB565;
			break;
		case 24:
			ColorBytes  = 4;
			break;
		case 32: 
			ColorBytes  = 4;
			break;
		default: 
			ColorBytes  = 2; 
			Caps       |= CC_RGB565;
			break;
	}

	// Zero out Keysym map.
	for (INT i=0; i<65536; i++)
		KeysymMap[i] = 0;
		
	// Remap important keys.

	// TTY Functions.
	KeysymMap[XK_BackSpace]	= IK_Backspace;
	KeysymMap[XK_Tab]		= IK_Tab;
	KeysymMap[XK_Return]	= IK_Enter;
	KeysymMap[XK_Pause]		= IK_Pause;
	KeysymMap[XK_Escape]	= IK_Escape;
	KeysymMap[XK_Delete]	= IK_Delete;

	// Modifiers.
	KeysymMap[XK_Shift_L]	= IK_LShift;
	KeysymMap[XK_Shift_R]	= IK_RShift;
	KeysymMap[XK_Control_L]	= IK_LControl;
	KeysymMap[XK_Control_R]	= IK_RControl;
	KeysymMap[XK_Meta_L]	= IK_Alt;
	KeysymMap[XK_Meta_R]	= IK_Alt;
	KeysymMap[XK_Alt_L]		= IK_Alt;
	KeysymMap[XK_Alt_R]		= IK_Alt;
	
	// Special remaps.
	KeysymMap[XK_grave]		= IK_Tilde;

	// Misc function keys.
	KeysymMap[XK_F1]		= IK_F1;
	KeysymMap[XK_F2]		= IK_F2;
	KeysymMap[XK_F3]		= IK_F3;
	KeysymMap[XK_F4]		= IK_F4;
	KeysymMap[XK_F5]		= IK_F5;
	KeysymMap[XK_F6]		= IK_F6;
	KeysymMap[XK_F7]		= IK_F7;
	KeysymMap[XK_F8]		= IK_F8;
	KeysymMap[XK_F9]		= IK_F9;
	KeysymMap[XK_F10]		= IK_F10;
	KeysymMap[XK_F11]		= IK_F11;
	KeysymMap[XK_F12]		= IK_F12;

	// Cursor control and motion.
	KeysymMap[XK_Home]		= IK_Home;
	KeysymMap[XK_Left]		= IK_Left;
	KeysymMap[XK_Up]		= IK_Up;
	KeysymMap[XK_Right]		= IK_Right;
	KeysymMap[XK_Down]		= IK_Down;
	KeysymMap[XK_Page_Up]	= IK_PageUp;
	KeysymMap[XK_Page_Down]	= IK_PageDown;
	KeysymMap[XK_End]		= IK_End;

	// Keypad functions and numbers.
	KeysymMap[XK_KP_Enter]		= IK_Enter;
	KeysymMap[XK_KP_0]			= IK_NumPad0;
	KeysymMap[XK_KP_1]			= IK_NumPad1;
	KeysymMap[XK_KP_2]			= IK_NumPad2;
	KeysymMap[XK_KP_3]			= IK_NumPad3;
	KeysymMap[XK_KP_4]			= IK_NumPad4;
	KeysymMap[XK_KP_5]			= IK_NumPad5;
	KeysymMap[XK_KP_6]			= IK_NumPad6;
	KeysymMap[XK_KP_7]			= IK_NumPad7;
	KeysymMap[XK_KP_8]			= IK_NumPad8;
	KeysymMap[XK_KP_9]			= IK_NumPad9;
	KeysymMap[XK_KP_Multiply]	= IK_GreyStar;
	KeysymMap[XK_KP_Add]		= IK_GreyPlus;
	KeysymMap[XK_KP_Separator]	= IK_Separator;
	KeysymMap[XK_KP_Subtract]	= IK_GreyMinus;
	KeysymMap[XK_KP_Decimal]	= IK_NumPadPeriod;
	KeysymMap[XK_KP_Divide]		= IK_GreySlash;

	// Other
	KeysymMap[XK_minus]			= IK_Minus;
	KeysymMap[XK_equal]			= IK_Equals;
	
	// Zero out ShiftMask map.
	for (i=0; i<256; i++)
		ShiftMaskMap[i] = 0;

	// ShiftMask map.
	ShiftMaskMap['1']			= '!';
	ShiftMaskMap['2']			= '@';
	ShiftMaskMap['3']			= '#';
	ShiftMaskMap['4']			= '$';
	ShiftMaskMap['5']			= '%';
	ShiftMaskMap['6']			= '^';
	ShiftMaskMap['7']			= '&';
	ShiftMaskMap['8']			= '*';
	ShiftMaskMap['9']			= '(';
	ShiftMaskMap['0']			= ')';
	ShiftMaskMap['-']			= '_';
	ShiftMaskMap['=']			= '+';
	ShiftMaskMap['[']			= '{';
	ShiftMaskMap[']']			= '}';
	ShiftMaskMap['\\']			= '|';
	ShiftMaskMap[';']			= ':';
	ShiftMaskMap['\'']			= '\"';
	ShiftMaskMap[',']			= '<';
	ShiftMaskMap['.']			= '>';
	ShiftMaskMap['/']			= '?';

	// WM_CHAR allowables.
	for (i=0; i<256; i++)
		WMCharMap[i] = 0;
	for (i='A'; i<='Z'; i++)
		WMCharMap[i] = 1;
	for (i='a'; i<='z'; i++)
		WMCharMap[i] = 1;
	WMCharMap[IK_Backspace]		= 1;
	WMCharMap[IK_Space]			= 1;
	WMCharMap[IK_Tab]			= 1;
	WMCharMap[IK_Enter]			= 1;
	WMCharMap['1']				= 1;
	WMCharMap['2']				= 1;
	WMCharMap['3']				= 1;
	WMCharMap['4']				= 1;
	WMCharMap['5']				= 1;
	WMCharMap['6']				= 1;
	WMCharMap['7']				= 1;
	WMCharMap['8']				= 1;
	WMCharMap['9']				= 1;
	WMCharMap['0']				= 1;
	WMCharMap['-']				= 1;
	WMCharMap['=']				= 1;
	WMCharMap['[']				= 1;
	WMCharMap[']']				= 1;
	WMCharMap['\\']				= 1;
	WMCharMap[';']				= 1;
	WMCharMap['\'']				= 1;
	WMCharMap[',']				= 1;
	WMCharMap['.']				= 1;
	WMCharMap['/']				= 1;
	WMCharMap['!']				= 1;
	WMCharMap['@']				= 1;
	WMCharMap['#']				= 1;
	WMCharMap['$']				= 1;
	WMCharMap['%']				= 1;
	WMCharMap['^']				= 1;
	WMCharMap['&']				= 1;
	WMCharMap['*']				= 1;
	WMCharMap['(']				= 1;
	WMCharMap[')']				= 1;
	WMCharMap['_']				= 1;
	WMCharMap['+']				= 1;
	WMCharMap['{']				= 1;
	WMCharMap['}']				= 1;
	WMCharMap['|']				= 1;
	WMCharMap[':']				= 1;
	WMCharMap['\"']				= 1;
	WMCharMap['<']				= 1;
	WMCharMap['>']				= 1;
	WMCharMap['?']				= 1;
	
	// Zero out KeyRepeat map.
	for (i=0; i<256; i++)
		KeyRepeatMap[i] = 0;

	// Remember pointer settings.
	XGetPointerControl(XDisplay, &MouseAccel_N, &MouseAccel_D, &MouseThreshold);

	debugf( TEXT("Created and initialized a new X viewport.") );

	unguard;
}
Exemplo n.º 10
0
UBOOL UOpenALAudioSubsystem::Init()
{
	guard(UOpenALAudioSubsystem::Init);

	INT Rate = GetActualOutputRate();


	// OpenAL / ALURE initialization
	ALCint ContextAttrs[] = { ALC_FREQUENCY, Rate, 0 };
	if( alureInitDevice( NULL, ContextAttrs ) == AL_FALSE )
		appErrorf( TEXT("Couldn't initialize OpenAL: %s"), alureGetErrorString() );

	alDistanceModel( AL_LINEAR_DISTANCE_CLAMPED );
	CheckALErrorFlag( TEXT("alDistanceModel") );

	alDopplerFactor( DopplerFactor );
	CheckALErrorFlag( TEXT("alDopplerFactor") );

	// Metre per second to units per second, where units per meter is 52.5.
	// Taken from: http://wiki.beyondunreal.com/Legacy:General_Scale_And_Dimensions
	alSpeedOfSound( 343.3f * 52.5f );
	CheckALErrorFlag( TEXT("alSpeedOfSound") );

	ALuint* NewSources = new ALuint[NumSources + 1];
	Sources = new FAudioSource[NumSources];
	alGenSources( NumSources + 1, NewSources );
	CheckALErrorFlag( TEXT("alGenSources") );
	MusicSource = NewSources[0];
	for( INT i=0; i<NumSources; i++ )
		Sources[i].Id = NewSources[i+1];
	delete[] NewSources;

	// Fix the music source to 0 values
	alSource3f(	MusicSource, AL_POSITION,			0.f, 0.f, 0.f );
	alSource3f(	MusicSource, AL_VELOCITY,			0.f, 0.f, 0.f );
	alSource3f(	MusicSource, AL_DIRECTION,			0.f, 0.f, 0.f );
	alSourcef(	MusicSource, AL_ROLLOFF_FACTOR,		0.f );
	alSourcei(	MusicSource, AL_SOURCE_RELATIVE,	AL_TRUE );

	SetVolumes();
	CheckALErrorFlag( TEXT("SetVolumes") );


	// MikMod initialization
	//kipz - remove this because it breaks on new mikmod
	//MikMod_RegisterDriver( &MusicDriver );
	MikMod_RegisterAllDrivers();
	// Register only formats that are known to be supported by UT.
	// Taken from: http://wiki.beyondunreal.com/Music
	MikMod_RegisterLoader( &load_mod );
	MikMod_RegisterLoader( &load_s3m );
	MikMod_RegisterLoader( &load_stm );
	MikMod_RegisterLoader( &load_it  );
	MikMod_RegisterLoader( &load_xm  );
	MikMod_RegisterLoader( &load_far );
	MikMod_RegisterLoader( &load_669 );

	md_mixfreq = Rate;
	if ( HighQualityMusic )
		md_mode |= DMODE_HQMIXER;
	if( MikMod_Init( "" ) )
		appErrorf( TEXT("Couldn't initialize MikMod: %s"), MikMod_strerror( MikMod_errno ) );


	// Initialized!
	USound::Audio = this;
	UMusic::Audio = this;
	Initialized = 1;

	return 1;
	unguard;
}
Exemplo n.º 11
0
void USetupDefinition::Init()
{
	guard(USetupDefinition::Init);

	// Figure out source folder.
	SrcPath = appBaseDir();
	if( SrcPath.Right(1)==PATH_SEPARATOR )
		SrcPath = SrcPath.LeftChop( 1 );
	while( SrcPath.Len() && SrcPath.Right(1)!=PATH_SEPARATOR )
		SrcPath = SrcPath.LeftChop( 1 );
	if( SrcPath.Len() )
		SrcPath = SrcPath.LeftChop( 1 );

	// See if installing a packed .umod file.
	FString Token;
	const TCHAR* Cmd = appCmdLine();
	ParseToken( Cmd, Token, 0 );
	if( Token==TEXT("install") || (Token==TEXT("") && MasterProduct==TEXT("")) )
	{
		// Installing.
		if( Token==TEXT("install") )
		{
			// Verify that the specified module exists.
			ParseToken( Cmd, Token, 0 );
			GFileManager = new FFileManagerArc(GFileManager,*Token,1);
			GFileManager->Init(0);
			Token = TEXT("");
			ParseToken( Cmd, Token, 0 );

			// Reload config from the new filer manager.
			GConfig->Flush(1,MANIFEST_FILE MANIFEST_EXT);
			LoadConfig();
			LoadLocalized();
		}

		// Detach configuration file so we can modify it locally.
		GConfig->Detach( *ConfigFile );
		Manifest = 1;
	}
	else if( Token==TEXT("reallyuninstall") )
	{
		// Running uninstaller from temp folder.
		ParseToken( Cmd, Product, 0 );
		Parse( appCmdLine(), TEXT("PATH="), DestPath );
		if( DestPath.Right(1)==PATH_SEPARATOR )
			DestPath = DestPath.LeftChop( 1 );
		while( DestPath.Len() && DestPath.Right(1)!=PATH_SEPARATOR )
			DestPath = DestPath.LeftChop( 1 );
		Uninstalling = 1;
	}
	else if( Token==TEXT("uninstall") || (Token==TEXT("") && MasterProduct!=TEXT("")) )
	{
		// Running uninstaller for the first time.
		NoRun = 1;
		if( Token==TEXT("uninstall") )
			ParseToken( Cmd, Product, 0 );
		else
			Product = MasterProduct;
		PerformUninstallCopy();
	}
	else appErrorf(TEXT("Setup: Unknown disposition"));

	// Validate everything.
	if( !appAtoi(*Version) && !Uninstalling && !NoRun )
		appErrorf( TEXT("Setup: Missing version number") );

	// Determine whether known to be installed.
	Exists
	=	GetRegisteredProductFolder( Product, RegistryFolder )
	&&	GFileManager->FileSize(*(RegistryFolder*TEXT("System")*SETUP_INI))>0;

	// If this is a mod, find required product's path.
	FolderExists = Exists;
	if( !Exists && !Uninstalling && !NoRun )
	{
		FString RequiredProduct, FindFolder;
		for( TArray<FString>::TIterator It(Requires); It; ++It )
			if(	GConfig->GetString(**It, TEXT("Product"), RequiredProduct, *ConfigFile) )
			{
				if( RequiredProduct==TEXT("Unreal Tournament") )
					RequiredProduct = TEXT("UnrealTournament");
				if( GetRegisteredProductFolder(RequiredProduct, FindFolder)
				&&	GFileManager->FileSize(*(FindFolder*TEXT("System")*SETUP_INI)) )
				{
					RegistryFolder = FindFolder;
					FolderExists   = 1;
					break;
				}
			}
	}

	// Figure language.
	FString Str;
	if( GConfig->GetString(TEXT("Engine.Engine"),TEXT("Language"),Str,*(RegistryFolder*TEXT("System\\Default.ini"))) )
		UObject::SetLanguage( *Str );
	LanguageChange();

	unguard;
}
Exemplo n.º 12
0
void USetupDefinition::ProcessCopy( FString Key, FString Value, UBOOL Selected, FInstallPoll* Poll )
{
	guard(USetupDefinition::ProcessCopy);
	BYTE Buffer[4096];
	if( Selected && Key==TEXT("File") )
	{
		// Get source and dest filenames.
		FFileInfo Info(*Value);
		if( Info.Lang==TEXT("") || Info.Lang==UObject::GetLanguage() )
		{
			if( Info.Dest==TEXT("") )
				Info.Dest = Info.Src;
			if( !LocateSourceFile(Info.Src) )
				LocalizedFileError( TEXT("MissingInstallerFile"), Patch ? TEXT("AdviseBadDownload") : TEXT("AdviseBadMedia"), *Info.Src );
			FString FullDest  = DestPath * Info.Dest;
			FString FullSrc   = Info.Ref==TEXT("") ? Info.Src : GetFullRef(*Info.Ref);
			FString FullPatch = FullDest + TEXT("_tmp");

			// Update uninstallation log.
			UninstallLogAdd( TEXT("File"), *Info.Dest, 0, 1 );

			// Make destination directory.
			if( !GFileManager->MakeDirectory( *BasePath(FullDest), 1 ) )
				LocalizedFileError( TEXT("FailedMakeDir"), TEXT("AdviseBadDest"), *FullDest );

			// Status display.
			if( !Poll->Poll(*FullDest,0,0,RunningBytes,TotalBytes) )
				DidCancel();

			// Copy SrcAr -> DestAr.
			INT CalcOldCRC = 0;
			guard(CopyFile);
			FString ThisDest = Info.Ref==TEXT("") ? FullDest : FullPatch;
			debugf( TEXT("Copying %s to %s"), *FullSrc, *ThisDest);
			FArchive* SrcAr = GFileManager->CreateFileReader( *FullSrc );
			if( !SrcAr )
				LocalizedFileError( TEXT("FailedOpenSource"), Patch ? TEXT("AdviseBadDownload") : TEXT("AdviseBadMedia"), *FullSrc );
			INT Size = SrcAr->TotalSize();
			FArchive* DestAr = GFileManager->CreateFileWriter( *ThisDest, FILEWRITE_EvenIfReadOnly );
			if( !DestAr )
				LocalizedFileError( TEXT("FailedOpenDest"), TEXT("AdviseBadDest"), *ThisDest );

			if( FullSrc.Right(3).Caps() == TEXT(".UZ") && ThisDest.Right(3).Caps() != TEXT(".UZ"))
			{
				INT Signature;
				FString OrigFilename;
				*SrcAr << Signature;
				if( Signature != 5678 )
					LocalizedFileError( TEXT("FailedOpenSource"), TEXT("AdviseBadMedia"), *FullSrc );
				else
				{
					*SrcAr << OrigFilename;
					FCodecFull Codec;
					Codec.AddCodec(new FCodecRLE);
					Codec.AddCodec(new FCodecBWT);
					Codec.AddCodec(new FCodecMTF);
					Codec.AddCodec(new FCodecRLE);
					Codec.AddCodec(new FCodecHuffman);
					Codec.Decode( *SrcAr, *DestAr );
					if( !Poll->Poll(*FullDest,Size,Size,RunningBytes+=Size,TotalBytes) )					{
						delete SrcAr;
						delete DestAr;
						DidCancel();
					}
				}
			}
			else
			{
				for( SQWORD Pos=0; Pos<Size; Pos+=sizeof(Buffer) )
				{
					INT Count = Min( Size-Pos, (SQWORD)sizeof(Buffer) );
					SrcAr->Serialize( Buffer, Count );
					if( SrcAr->IsError() )
					{
						delete SrcAr;
						delete DestAr;
						LocalizedFileError( TEXT("FailedReadingSource"), Patch ? TEXT("AdviseBadDownload") : TEXT("AdviseBadMedia"), *FullSrc );
					}
					if( Info.Ref!=TEXT("") )
					{
						CalcOldCRC = appMemCrc( Buffer, Count, CalcOldCRC );
					}
					DestAr->Serialize( Buffer, Count );
					if( DestAr->IsError() )
					{
						delete SrcAr;
						delete DestAr;
						LocalizedFileError( TEXT("FailedWritingDest"), TEXT("AdviseBadDest"), *ThisDest );
					}
					if( !Poll->Poll(*FullDest,Pos,Size,RunningBytes+=Count,TotalBytes) )
					{
						delete SrcAr;
						delete DestAr;
						DidCancel();
					}
				}
			}
			delete SrcAr;
			if( !DestAr->Close() )
				LocalizedFileError( TEXT("FailedClosingDest"), TEXT("AdviseBadDest"), *ThisDest );
			delete DestAr;
			unguard;

			// Patch SrcAr + DeltaFile -> DestAr.
			if( Info.Ref!=TEXT("") )
			{
				guard(PatchFile);
				BYTE Buffer[4096];

				// Open files.
				FString ThisSrc = FullPatch;
				FArchive* SrcAr = GFileManager->CreateFileReader( *ThisSrc );
				if( !SrcAr )
					LocalizedFileError( TEXT("FailedOpenSource"), Patch ? TEXT("AdviseBadDownload") : TEXT("AdviseBadMedia"), *ThisSrc );
				INT Size = SrcAr->TotalSize();
				FArchive* DestAr = GFileManager->CreateFileWriter(*FullDest,FILEWRITE_EvenIfReadOnly);
				if( !DestAr )
					LocalizedFileError( TEXT("FailedOpenDest"), TEXT("AdviseBadDest"), *FullDest );

				// Load delta file.
				TArray<BYTE> Delta;
				FString DeltaName = Info.Src;
				if( !appLoadFileToArray( Delta, *DeltaName ) )
					LocalizedFileError( TEXT("FailedLoadingUpdate"), TEXT("AdviseBadDownload"), *Info.Src );
				debugf( TEXT("Patching %s to %s with %s"), *ThisSrc, *FullDest, *DeltaName );

				// Decompress variables.
				INT PrevSpot=0, CountSize=0, CRC=0;
				INT Magic=0, OldSize=0, OldCRC=0, NewSize=0, NewCRC;
				FBufferReader Reader( Delta );
				Reader << Magic << OldSize << OldCRC << NewSize << NewCRC;

				// Validate.
				if( Magic!=0x92f92912 )
					appErrorf( LineFormat(LocalizeError("PatchCorrupt")), *DeltaName, LocalizeError("AdviseBadDownload") );
				if( OldSize!=Size || OldCRC!=CalcOldCRC )
					appErrorf( LocalizeError("CdFileMismatch"), *Info.Ref, *LocalProduct );

				// Delta decode it.
				INT OldCountSize=0;
				while( !Reader.AtEnd() )
				{
					INT Index;
					Reader << AR_INDEX(Index);
					if( Index<0 )
					{
						CRC = appMemCrc( &Delta(Reader.Tell()), -Index, CRC );
						DestAr->Serialize( &Delta(Reader.Tell()), -Index );
						if( DestAr->IsError() )
							LocalizedFileError( TEXT("FailedWritingDest"), TEXT("AdviseBadDest"), *FullDest );
						Reader.Seek( Reader.Tell() - Index );
						CountSize -= Index;
					}
					else
					{
						INT CopyPos;
						Reader << AR_INDEX(CopyPos);
						CopyPos += PrevSpot;
						check(CopyPos>=0);
						check(CopyPos+Index<=Size);
						SrcAr->Seek( CopyPos );
						for( INT Base=Index; Base>0; Base-=sizeof(Buffer) )
						{
							INT Move = Min(Base,(INT)sizeof(Buffer));
							SrcAr->Serialize( Buffer, Move );
							if( SrcAr->IsError() )
								LocalizedFileError( TEXT("FailedReadingSource"), Patch ? TEXT("AdviseBadDownload") : TEXT("AdviseBadDownload"), *ThisSrc );
							CRC = appMemCrc( Buffer, Move, CRC );
							DestAr->Serialize( Buffer, Move );
							if( DestAr->IsError() )
								LocalizedFileError( TEXT("FailedWritingDest"), TEXT("AdviseBadDest"), *FullDest );
						}
						CountSize += Index;
						PrevSpot = CopyPos + Index;
					}
					if( ((CountSize^OldCountSize)&~(sizeof(Buffer)-1)) || Reader.AtEnd() )
					{
						if( !Poll->Poll(*FullDest,CountSize,Info.Size,RunningBytes+=(CountSize-OldCountSize),TotalBytes) )
						{
							delete SrcAr;
							delete DestAr;
							DidCancel();
						}
						OldCountSize = CountSize;
					}
				}
				if( NewSize!=CountSize || NewCRC!=CRC )
					appErrorf( LineFormat(LocalizeError("PatchCorrupt")), *DeltaName, LocalizeError("AdviseBadDownload") );
				delete SrcAr;
				if( !DestAr->Close() )
					LocalizedFileError( TEXT("FailedClosingDest"), TEXT("AdviseBadDest"), *FullDest );
				delete DestAr;
				GFileManager->Delete( *ThisSrc );
				unguard;
			}
		}
	}
	unguard;
}
Exemplo n.º 13
0
void USetupDefinition::DidCancel()
{
	guard(DidCancel);
	appErrorf( NAME_FriendlyError, LocalizeGeneral(TEXT("DidCancel"))), LocalizeGeneral(TEXT("InstallCancel") );
	unguard;
}
Exemplo n.º 14
0
void D3D11GraphicsCommand::SetRenderTarget(const Surface *NewRenderTarget, const Surface *NewDepthStencilTarget)
{
	D3D11Surface *d3dRT = (D3D11Surface *)NewRenderTarget;
	D3D11Surface *d3dDS = (D3D11Surface *)NewDepthStencilTarget;

	Microsoft::WRL::ComPtr<ID3D11RenderTargetView> RTV;
	Microsoft::WRL::ComPtr<ID3D11DepthStencilView> DSV;

	if ( NewRenderTarget )
	{
		RTV = d3dRT->RenderTargetView;
	}
	if ( NewDepthStencilTarget )
	{
		bCurrentDSTIsReadonly = CurrentDepthState.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ZERO;
		// Set the appropriate depth stencil view depending on whether depth writes are enabled or not
		if ( bCurrentDSTIsReadonly )
		{
			DSV = d3dDS->ReadOnlyDepthStencilView;
		}
		else
		{
			DSV = d3dDS->DepthStencilView;
		}
	}

	bool bMRTSet = false;
	for ( UINT RenderTargetIndex = 1; RenderTargetIndex < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++RenderTargetIndex )
	{
		bMRTSet = bMRTSet || CurrentRenderTargets[RenderTargetIndex];
	}

	// Only set the render target if different than the currently bound RT
	if ( RTV != CurrentRenderTargets[0] || DSV != CurrentDepthStencilTarget || bMRTSet )
	{
		// Reset all texture references to this render target
		if ( NewRenderTarget )
		{
			d3dRT->UnsetTextureReferences(m_deviceContext.Get());
		}
		if ( NewDepthStencilTarget )
		{
			d3dDS->UnsetTextureReferences(m_deviceContext.Get());
		}

		CurrentDepthSurface = d3dDS;
		CurrentDepthStencilTarget = DSV;
		CurrentRenderTargets[0] = RTV;
		for ( UINT RenderTargetIndex = 1; RenderTargetIndex < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++RenderTargetIndex )
		{
			CurrentRenderTargets[RenderTargetIndex] = nullptr;
		}

		ID3D11RenderTargetView* RTArray[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
		for ( UINT RenderTargetIndex = 0; RenderTargetIndex < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++RenderTargetIndex )
		{
			RTArray[RenderTargetIndex] = CurrentRenderTargets[RenderTargetIndex].Get();
		}
		m_deviceContext->OMSetRenderTargets(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, RTArray, CurrentDepthStencilTarget.Get());

#if _DEBUG	
		// A check to allow you to pinpoint what is using mismatching targets
		// We filter our d3ddebug spew that checks for this as the d3d runtime's check is wrong.
		// For filter code, see D3D11Device.cpp look for "OMSETRENDERTARGETS_INVALIDVIEW"
		if ( RTV && DSV )
		{
			// Set the viewport to the full size of the surface
			D3D11_TEXTURE2D_DESC RTTDesc;
			ID3D11Texture2D *RenderTargetTexture = NULL;
			RTV->GetResource((ID3D11Resource**)&RenderTargetTexture);
			RenderTargetTexture->GetDesc(&RTTDesc);
			RenderTargetTexture->Release();

			D3D11_TEXTURE2D_DESC DTTDesc;
			ID3D11Texture2D *DepthTargetTexture = NULL;
			DSV->GetResource((ID3D11Resource**)&DepthTargetTexture);
			DepthTargetTexture->GetDesc(&DTTDesc);
			DepthTargetTexture->Release();

			// enforce color target is <= depth and MSAA settings match
			if ( RTTDesc.Width > DTTDesc.Width || RTTDesc.Height > DTTDesc.Height ||
				RTTDesc.SampleDesc.Count != DTTDesc.SampleDesc.Count ||
				RTTDesc.SampleDesc.Quality != DTTDesc.SampleDesc.Quality )
			{
				FatalAssert(1 == 0);
#if UE
				appErrorf(TEXT("RTV(%i,%i c=%i,q=%i) and DSV(%i,%i c=%i,q=%i) have mismatching dimensions and/or MSAA levels!"),
					RTTDesc.Width, RTTDesc.Height, RTTDesc.SampleDesc.Count, RTTDesc.SampleDesc.Quality,
					DTTDesc.Width, DTTDesc.Height, DTTDesc.SampleDesc.Count, DTTDesc.SampleDesc.Quality);
#endif
			}
		}
#endif
	}
	
	// Detect when the back buffer is being set, and set the correct viewport.
	// TODO: не нужно - вьюпорт и так поставится
	/*if ( DrawingViewport && (!NewRenderTarget || NewRenderTarget == DrawingViewport->GetBackBuffer()) )
	{
		SetViewport(0, 0, 0.0f, DrawingViewport->GetSizeX(), DrawingViewport->GetSizeY(), 1.0f);
	}
	else */if ( RTV )
	{
		// Set the viewport to the full size of the surface
		// TODO: лучше кешировать размер
		D3D11_TEXTURE2D_DESC Desc;
		ID3D11Texture2D *BaseResource = NULL;
		RTV->GetResource((ID3D11Resource**)&BaseResource);
		BaseResource->GetDesc(&Desc);
		SetViewport(0, 0, 0.0f, Desc.Width, Desc.Height, 1.0f);
		BaseResource->Release();
	}

	// Determine whether the new render target is multisample.
	if ( RTV )
	{
		D3D11_RENDER_TARGET_VIEW_DESC RenderTargetViewDesc;
		RTV->GetDesc(&RenderTargetViewDesc);
		bCurrentRenderTargetIsMultisample =
			(RenderTargetViewDesc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMS) ||
			(RenderTargetViewDesc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY);

		// Update the rasterizer state to take into account whether new render target is multi-sample.
		//ID3D11RasterizerState *CachedState = GetCachedRasterizerState(CurrentRasterizerState, CurrentScissorEnable, bCurrentRenderTargetIsMultisample);
		//m_deviceContext->RSSetState(CachedState);
	}
}