示例#1
0
文件: editor.c 项目: eukos16/NGUNIX
/* EDITOR: COLORMAP VIEWER
 * =======================
 * Colormaps differ from lump files in the way that they don't start with a width | height header
 * Otherwise they are identical in how they refer to palette indexes for their color
 */
gint VID_EditorViewColormap(gpointer data)
{
	int i;
	GtkWidget *dialog;
	GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
	gint res;
	loadedfile_t *pic;

	dialog = gtk_file_chooser_dialog_new ("NGUNIXEd - Open Colormap (.lmp) File",
                                      NULL,
                                      action,
                                      ("_Cancel"),
                                      GTK_RESPONSE_CANCEL,
                                      ("_Open"),
                                      GTK_RESPONSE_ACCEPT,
                                      NULL);

	// Set the dialog and the default path (current directory)
	GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
	char path[MAX_OSPATH];
	sprintf(path, "file://%s", get_current_dir_name());
	gtk_file_chooser_set_current_folder_uri(chooser, path);

	// Add the filter for .lmp files
	GtkFileFilter *filter = gtk_file_filter_new ();
	gtk_file_filter_add_pattern (filter, "*.lmp");
	gtk_file_chooser_set_filter (chooser, filter);

	res = gtk_dialog_run (GTK_DIALOG (dialog));
	if (res == GTK_RESPONSE_ACCEPT)
  	{
    		char *filename;
    		filename = gtk_file_chooser_get_filename (chooser);

		pic = COM_LoadFile (filename, 2);
		
		if(pic)
		{	
			Con_Printf("[EDITOR] Previewing Colormap %s\n", filename);
			ed_file = malloc(16385 + (sizeof(int) * 2));

			ed_file->width = 256;
			ed_file->height = 64;

			for(i = 0; i < 256 * 64; i++)
				ed_file->data[i] = pic->data[i];
			
    			gtk_window_resize(ed_window, ed_file->width + ed_palfile->width, ed_file->height + ed_menubar->allocation.height);
		}

    		g_free (filename);
  	}

	gtk_widget_destroy (dialog);
	return 0;
}
示例#2
0
byte *COM_LoadStackFile(const char *path, void *buffer, int bufsize) { //4

   //This appears to load a file into the passed void * buffer.  If that buffer
   //is too small, temp allocation is done instead.  Never called in i386 as
   //far as I can see.  Almost line for line what's in QW.
   byte *buf;

   loadbuf = (byte *)buffer;
   loadsize = bufsize;
   buf = COM_LoadFile(path, 4, NULL);

   return(buf);
}
bool GetModelNameFromSourceFile( char const *filename, char *modelname, int maxlen )
{
	modelname[0]=0;

	int filelength;
	char *buffer = (char *)COM_LoadFile( filename, &filelength );
	if ( !buffer )
	{
		vprint( 0, "Couldn't load %s\n", filename );
		return false;
	}

	bool valid = false;

	// Parse tokens
	char *current = buffer;
	while ( current )
	{
		current = CC_ParseToken( current );
		if ( strlen( com_token ) <= 0 )
			break;

		if ( stricmp( com_token, "$modelname" ) )
			continue;

		current = CC_ParseToken( current );

		strcpy( modelname, com_token );
		_strlwr( modelname );

		Q_FixSlashes( modelname );

		Q_DefaultExtension( modelname, ".mdl", maxlen );

		valid = true;
		break;
	}

	COM_FreeFile( (unsigned char *)buffer );

	if ( !valid )
	{
		vprint( 0, ".qc file %s missing $modelname directive!!!\n", filename );
	}
	return valid;
}
示例#4
0
/* <845bc> ../engine/r_studio.c:5809 */
int R_GetStudioBounds(const char *filename, float *mins, float *maxs)
{
	int iret = 0;
	qboolean usingReadBuffer = 0;
	
	for (int i = 0; i < 3; i++)
		mins[0] = maxs[0] = vec3_origin[i];

	if (!Q_strstr(filename, "models") || !Q_strstr(filename, ".mdl"))
		return 0;


	FileHandle_t fp = FS_Open(filename, "rb");
	if (!fp)
		return 0;
	
	int length;
	char *pBuffer = (char *)FS_GetReadBuffer(fp, &length);
	if (pBuffer)
		usingReadBuffer = 1;
	else
		pBuffer = (char*) COM_LoadFile(filename, 5, 0);
		
	if (pBuffer)
	{
		if (LittleLong(*(unsigned int *)pBuffer) == 'TSDI')
			iret = R_StudioComputeBounds((unsigned char*)pBuffer, mins, maxs);
#ifndef REHLDS_FIXES
		//wrong release memory code	
		else
			COM_FreeFile(pBuffer);
#endif
	}

	if (usingReadBuffer)
		FS_ReleaseReadBuffer(fp, pBuffer);
	else
		COM_FreeFile(pBuffer);

	FS_Close(fp);

	return iret;
}
bool CCodeProcessor::LoadFile( char **buffer, char *filename, char const *module, bool forcequiet, 
	int depth, int& filelength, int& numheaders, int& skippedfiles,
	char const *srcroot, char const *root, char const *baseroot )
{
	for ( int i = 0; i < m_IncludePath.Count(); ++i )
	{
		// Load the base module
		sprintf( filename, "%s\\%s", m_IncludePath[i], module );
		strlwr( filename );

		if ( CheckShouldSkip( forcequiet, depth, filename, numheaders, skippedfiles ) )
		{
			return false;
		}

		*buffer = (char *)COM_LoadFile( filename, &filelength );
		if ( *buffer )
			return true;
	}

	return false;
}
示例#6
0
HLDS_DLLEXPORT byte * COM_LoadFileForMe(const char *filename, int *pLength) { //5
   return(COM_LoadFile(filename, 5, pLength));
}
示例#7
0
HLDS_DLLEXPORT void COM_LoadCacheFile(const char *path, cache_user_t *cu) { //3

   loadcache = cu;
   COM_LoadFile(path, 3, NULL);
}
示例#8
0
byte *COM_LoadTempFile(const char *path, int *pLength) { //2
   return(COM_LoadFile(path, 2, pLength));
}
示例#9
0
byte *COM_LoadHunkFile(const char *path) { //1
   return(COM_LoadFile(path, 1, NULL));
}
void CCodeProcessor::ProcessModule( bool forcequiet, int depth, int& maxdepth, int& numheaders, int& skippedfiles, const char *baseroot, const char *root, const char *module )
{
	char filename[ 256 ];

	bool checkroot = false;

	if ( depth > maxdepth )
	{
		maxdepth = depth;
	}

	// Load the base module
	sprintf( filename, "%s\\%s", root, module );
	strlwr( filename );

	bool firstheader = true;
retry:

	// Check module list
	for ( int i = 0; i < m_nModuleCount; i++ )
	{
		if ( !stricmp( m_Modules[ i ].name, filename ) )
		{
			if ( forcequiet )
			{
				m_nHeadersProcessed++;
				numheaders++;

				if ( m_Modules[ i ].skipped )
				{
					skippedfiles++;
				}
			}

			AddHeader( depth, filename, m_szCurrentCPP );

			return;
		}
	}

	int filelength;
	char *buffer = (char *)COM_LoadFile( filename, &filelength );
	if ( !buffer )
	{
		if ( !checkroot )
		{
			checkroot = true;
			// Load the base module
			sprintf( filename, "%s\\%s", baseroot, module );
			goto retry;
		}
		m_Modules[ m_nModuleCount ].skipped = true;
		strcpy( m_Modules[ m_nModuleCount++ ].name, filename );
		
		skippedfiles++;
		return;
	}

	m_nBytesProcessed += filelength;

	m_Modules[ m_nModuleCount ].skipped = false;
	strcpy( m_Modules[ m_nModuleCount++ ].name, filename );

	bool readonly = false;
	bool madechanges = false;
	CreateBackup( filename, readonly );

	if ( !forcequiet )
	{
		strcpy( m_szCurrentCPP, filename );
		
		vprint( 0, "- %s\n", (char *)&filename[ m_nOffset ] );
	}

	// Parse tokens looking for #include directives or class starts
	char *current = buffer;
	char *startofline;

	current = CC_ParseToken( current );
	while ( current )
	{
		// No more tokens
		if ( strlen( com_token ) <= 0 )
			break;

		if ( !stricmp( com_token, "#include" ) )
		{
			startofline = current - strlen( "#include" );

			current = CC_ParseToken( current );

			if ( strlen( com_token ) > 0)
			{
				vprint( 1, "#include %s", com_token );
				m_nHeadersProcessed++;
				numheaders++;				

				AddHeader( depth, filename, m_szCurrentCPP );

				bool dobuild = true;
				if ( firstheader )
				{
					if ( !stricmp( com_token, "cbase.h" ) )
					{
						dobuild = false;
					}

					if ( !TryBuild( baseroot, filename, (unsigned char *)buffer, filelength ) )
					{
						// build is broken, stop
						assert( 0 );
					}
				}

				firstheader = false;

				if ( dobuild )
				{
					// Try removing the header and compiling
					char saveinfo[2];
					memcpy( saveinfo, startofline, 2 );
					startofline[ 0 ] = '/';
					startofline[ 1 ] = '/';

					if ( TryBuild( baseroot, filename, (unsigned char *)buffer, filelength ) )
					{
						vprint( 0, ", unnecessary\n" );
						madechanges = true;
					}
					else
					{
						// Restore line
						memcpy( startofline, saveinfo, 2 );
						vprint( 0, "\n" );
					}
				}
				else
				{
					vprint( 0, "\n" );
				}
			}
		}

		current = CC_ParseToken( current );
	}

	// Save out last set of changes
	{
		FILE *fp;
		fp = fopen( filename, "wb" );
		if ( fp )
		{
			fwrite( buffer, filelength, 1, fp );
			fclose( fp );
		}
	}

	COM_FreeFile( (unsigned char *)buffer );

	if ( !madechanges )
	{
		RestoreBackup( filename, readonly );
	}

	if ( !forcequiet && !GetQuiet() )
	{
		vprint( 0, " %s: headers (%i)", (char *)&filename[ m_nOffset ], numheaders );
		if ( maxdepth > 1 )
		{
			vprint( 0, ", depth %i", maxdepth );
		}
		vprint( 0, "\n" );
	}

	m_nLinesOfCode += linesprocessed;
	linesprocessed = 0;
}
示例#11
0
unsigned char *SystemWrapper::LoadFile(const char *name, int *length)
{
	return COM_LoadFile(name, 5, length);
}
示例#12
0
文件: editor.c 项目: eukos16/NGUNIX
/* EDITOR: PALETTE SWITCHER
 * ========================
 * TODO: This somehow affects the main engine despite us using our own GdkColmap... 
 */
gint VID_EditorLoadPalette(gpointer data)
{
	int i;
	GtkWidget *dialog;
	GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
	gint res;
	loadedfile_t *palfile;
	unsigned int colors[256];

	dialog = gtk_file_chooser_dialog_new ("NGUNIXEd - Open Palette (.lmp) File",
                                      NULL,
                                      action,
                                      ("_Cancel"),
                                      GTK_RESPONSE_CANCEL,
                                      ("_Open"),
                                      GTK_RESPONSE_ACCEPT,
                                      NULL);

	// Set the dialog and the default path (current directory)
	GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
	char path[MAX_OSPATH];
	sprintf(path, "file://%s", get_current_dir_name());
	gtk_file_chooser_set_current_folder_uri(chooser, path);

	// Add the filter for .lmp files
	GtkFileFilter *filter = gtk_file_filter_new ();
	gtk_file_filter_add_pattern (filter, "*.lmp");
	gtk_file_chooser_set_filter (chooser, filter);

	res = gtk_dialog_run (GTK_DIALOG (dialog));
	if (res == GTK_RESPONSE_ACCEPT)
  	{
    		char *filename;
    		filename = gtk_file_chooser_get_filename (chooser);

		palfile = COM_LoadFile (filename, 2);
		
		if(palfile)
		{
			Con_Printf("[EDITOR] Switching palette to %s\n", filename);

			for(i=0; i < 16*16*3; i++)
				ed_palette[i] = palfile->data[i];

    			if (ed_cmap) 
				gdk_rgb_cmap_free(ed_cmap);

    			for (i = 0; i < 256; i++) 
			{
				unsigned char r, g, b;
				r = *ed_palette++;
				g = *ed_palette++;
				b = *ed_palette++;
				colors[i] = r << 16 | g << 8 | b;
    			}

    			ed_cmap = gdk_rgb_cmap_new(colors, 256);
		}
    		g_free (filename);
  	}

	gtk_widget_destroy (dialog);
	return 0;
}
示例#13
0
文件: editor.c 项目: eukos16/NGUNIX
/* EDITOR: LOAD PCX
 * ================
 * Loads a PCX into the editor as a pic...
 */
gint VID_EditorImportFile(gpointer data)
{
	GtkWidget *dialog;
	GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
	gint res;
	loadedfile_t *pic;

	dialog = gtk_file_chooser_dialog_new ("NGUNIXEd - Picture Exchange (.pcx) File",
                                      NULL,
                                      action,
                                      ("_Cancel"),
                                      GTK_RESPONSE_CANCEL,
                                      ("_Open"),
                                      GTK_RESPONSE_ACCEPT,
                                      NULL);

	// Set the dialog and the default path (current directory)
	GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
	char path[MAX_OSPATH];
	sprintf(path, "file://%s", get_current_dir_name());
	gtk_file_chooser_set_current_folder_uri(chooser, path);

	// Add the filter for .lmp files
	GtkFileFilter *filter = gtk_file_filter_new ();
	gtk_file_filter_add_pattern (filter, "*.pcx");
	gtk_file_chooser_set_filter (chooser, filter);

	res = gtk_dialog_run (GTK_DIALOG (dialog));
	if (res == GTK_RESPONSE_ACCEPT)
  	{
    		char *filename;
		byte *temp;
		filename = gtk_file_chooser_get_filename (chooser);

		pic = COM_LoadFile (filename, 2);

		if (pic)
		{
			int pic_width, pic_height;

			Con_Printf("[EDITOR] Importing PCX at %s...\n", filename);

			byte *pic_data = Hunk_Alloc(pic->filelen);
			pic_data = Image_ReadPCXFile(pic->data, pic->filelen, &pic_width, &pic_height, ed_palette);

			if(pic_data == NULL)
			{	
				g_free(filename);
				gtk_widget_destroy (dialog);
				return 0;
			}

			ed_file = Hunk_Alloc((sizeof(int) * 2) + (pic_width * pic_height));
			ed_file->width = pic_width;
			ed_file->height = pic_height;
			
			int i;
			for(i = 0; i < pic_width * pic_height; i++)
				ed_file->data[i] = pic_data[i];
				
    			gtk_window_resize(ed_window, ed_file->width + ed_palfile->width, ed_file->height + ed_menubar->allocation.height);
		}

    		g_free (filename);
  	}

	gtk_widget_destroy (dialog);
	return 0;
}
示例#14
0
/* <9a75> ../engine/com_custom.c:88 */
qboolean COM_CreateCustomization(customization_t *pListHead, resource_t *pResource, int playernumber, int flags, customization_t **pCustomization, int *nLumps)
{
	customization_t *pCust;                                      //    91
	qboolean bError;                                              //    92

	bError = FALSE;
	if (pCustomization)
		*pCustomization = NULL;
	pCust = (customization_t *)Mem_ZeroMalloc(sizeof(customization_t));

	Q_memcpy(&pCust->resource, pResource, sizeof(pCust->resource));
	if (pResource->nDownloadSize <= 0)
	{
		bError = TRUE;
		goto CustomizationError;
	}

	pCust->bInUse = TRUE;

	if (flags & FCUST_FROMHPAK)
	{
		if (!HPAK_GetDataPointer("custom.hpk", pResource, (uint8**)&pCust->pBuffer, NULL))
		{
			bError = TRUE;
			goto CustomizationError;
		}
	}
	else
	{
		pCust->pBuffer = COM_LoadFile(pResource->szFileName, 5, NULL);
	}

	if ((pCust->resource.ucFlags & RES_CUSTOM) && pCust->resource.type == t_decal)
	{
		pCust->resource.playernum = playernumber;
		if (!CustomDecal_Validate(pCust->pBuffer, pResource->nDownloadSize))
		{
			bError = TRUE;
			goto CustomizationError;
		}

		if (!(flags & RES_CUSTOM))
		{
			cachewad_t * pWad = (cachewad_t *)Mem_ZeroMalloc(sizeof(cachewad_t));
			pCust->pInfo = pWad;
			if (pResource->nDownloadSize >= 1024 && pResource->nDownloadSize <= 20480)
			{
				bError = (0 == CustomDecal_Init(pWad, pCust->pBuffer, pResource->nDownloadSize, playernumber));
				if (bError)
					goto CustomizationError;

				if (pWad->lumpCount > 0)
				{
					if (nLumps)
						*nLumps = pWad->lumpCount;

					pCust->bTranslated = TRUE;
					pCust->nUserData1 = 0;
					pCust->nUserData2 = pWad->lumpCount;
					if (flags & FCUST_WIPEDATA)
					{
						Mem_Free(pWad->name);
						Mem_Free(pWad->cache);
						Mem_Free(pWad->lumps);
						Mem_Free(pCust->pInfo);
						pCust->pInfo = NULL;
					}
				}
			}
		}
	}

CustomizationError:
	if (bError)
	{
		if (pCust->pBuffer)
			Mem_Free(pCust->pBuffer);
		if (pCust->pInfo)
			Mem_Free(pCust->pInfo);
		Mem_Free(pCust);
	}
	else
	{
		if (pCustomization)
			*pCustomization = pCust;
		pCust->pNext = pListHead->pNext;
		pListHead->pNext = pCust;
	}
	return bError == FALSE;
}