コード例 #1
0
ファイル: DataSourceKey.cpp プロジェクト: DrMcCoy/NWNTools
void CDataSourceKey::GetResourceText (DataElement *pElement, 
	LPTSTR pszText, int cchMaxText)
{

	//
	// Based on the type
	//

	switch (pElement ->usType)
	{
		case Type_Root:
			if (m_nID != 0)
			{
				LoadString (_Module .GetResourceInstance (), 
					m_nID, pszText, cchMaxText); 
			}
			else
			{
				strncpy (pszText, m_strFileName, cchMaxText);
				pszText [cchMaxText - 1] = 0;
			}
			break;

		case Type_Bif:
			m_pKeyFile ->GetBifName (pElement ->ulIndex1, 
				pszText, cchMaxText);
			break;

		case TypeResourceClass:
			LoadString (_Module .GetResourceInstance (), 
				IDS_RESCLASS_FIRST + pElement ->usIndex2, 
				pszText, cchMaxText); 
			break;

		case TypeResourceource:
			{
				const CNwnKeyFile::Resource *psRes = &m_pasRes [pElement ->ulIndex1];
				char szName [17];
				memcpy (szName, psRes ->szName, 16);
				szName [16] = 0;
				strncpy (pszText, szName, cchMaxText);
				pszText [cchMaxText - 1] = 0;
				LPCTSTR pszExt = NwnGetResTypeExtension (
					(NwnResType) psRes ->usType);
				TCHAR szTemp [32];
				if (pszExt == NULL)
				{
					_stprintf (szTemp, ".%X", psRes ->usType);
					pszExt = szTemp;
				}
				strncat (pszText, pszExt, cchMaxText);
			}
			break;
	}
}
コード例 #2
0
ファイル: NWNXResMan.cpp プロジェクト: HellSinker/nwnx2-win32
char* CNWNXResMan::DemandRes(CResStruct* cRes, char* resRef, NwnResType resType)
{
	unsigned long size;

	if (!resRef)
		return NULL;

	if (cRes->pResName)
	{
		if (m_LogLevel == logAll)
			Log("o Request for internal resource = %s (type %X)\n", resRef, resType);
		// nothing for us to do
		return NULL;
	}

	// try to load external resource
	char resPath[MAXPATH + 16];
	strcpy(resPath, m_sourcePath);
	strcat(resPath, resRef);

	strcat(resPath, NwnGetResTypeExtension(resType));
	size = LoadResource(resPath);
	if (size == 0)
		return NULL;

	// resource loaded	
	// set resStruct
	cRes->pResData = pScriptBuffer;
	cRes->pResName = saveName;
	cRes->resSize = size;
	cRes->unk2 = 1;
	cRes->unk4 = 4;
	cRes->loaded = 1;
	cRes->loaded2 = 1;
	cRes->resSize2 = size;
	cRes->pResData2 = pScriptBuffer;

	cRes->id1 = 0;
	cRes->id2 = 0;
	cRes->id3 = 0;
	cRes->id4 = 0;

	// Call server function which sets various data pointers
	if (cRes->pClass)
	{
		char* pFunc = cRes->pClass;
		pFunc = (char*)(*(int*)(pFunc+0x10));
		__asm {
			mov ecx, cRes
			call pFunc
		}
	}
コード例 #3
0
ファイル: ERF.cpp プロジェクト: TerrahKitsune/NWNX
bool ERF::ExtractResource( KeyEntry * key, const char * folder ){

	ResEntry ret = GetResEntry( key );
	if( ret.OffsetToResource == 0 || ret.ResourceSize == 0 )
		return false;

	char ResRef[30]={0};
	char File[MAX_PATH];
	DWORD fLen = strlen( folder );

	for( int n=0;n<16;n++ ){
		if( key->ResRef[n] == '\0' )
			break;
		ResRef[n]=key->ResRef[n];
	}
	strcat( ResRef, NwnGetResTypeExtension( key->ResType ) );

	if( strlen( ResRef )+fLen >= MAX_PATH )
		return false;

	if( folder[fLen-1] == '/' || folder[fLen-1] == '\\' )
		sprintf( File, "%s%s", folder, ResRef );
	else
		sprintf( File, "%s/%s", folder, ResRef );

	FILE * fOut = fopen( File, "wb" );
	if( !fOut )
		return false;

	char Buffer[65536];
	DWORD left=ret.ResourceSize;
	DWORD last=0;
	fseek( fFile, ret.OffsetToResource, SEEK_SET );
	while( left > 0 ){

		if( left > 65536 )
			last = 65536;
		else
			last = left;
		
		fread( Buffer, 1, last, fFile );
		fwrite( Buffer, 1, last, fOut );
		left=left-last;
	}

	fclose( fOut );

	return true;
}
コード例 #4
0
ファイル: NwnStdLoader.cpp プロジェクト: deltreey/NWNTools
bool CNwnStdLoader::AddModuleHaks ()
{
	static const char *pszName = "module";
	static const NwnResType nResType = NwnResType_IFO;
	unsigned char *pauchData = NULL;
	UINT32 ulSize = 0;
	bool fAllocated = false;

	//
	// Try the module
	//

	if (m_pModule)
	{
		pauchData = m_pModule ->LoadRes (pszName, 
			nResType, &ulSize, &fAllocated);
	}

	//
	// Next, try to load the file from the current dir
	//
	
	if (pauchData == NULL)
	{
		std::string str = pszName;
		str += NwnGetResTypeExtension (nResType);
		pauchData = NwnLoadFile (str .c_str (), &ulSize);
		fAllocated = true;
	}

	//
	// If we can't find the module file, then return
	//

	if (pauchData == NULL)
		return false;

	//
	// Locate the hak file name
	//

	CNwnHierarchy ifo (pauchData, ulSize, fAllocated);
	return LookForHak (ifo, 0);
}
コード例 #5
0
ファイル: NmcContext.cpp プロジェクト: deltreey/NWNTools
unsigned char *CNmcContext::LoadResource (const char *pszName, 
	NwnResType nResType, UINT32 *pulSize, bool *pfAllocated)
{


	//
	// First, try to load the file
	//
	
	char szText [512];
	strcpy (szText, pszName);
	strcat (szText, NwnGetResTypeExtension (nResType));
	unsigned char *pauchData = NwnLoadFile (szText, pulSize);
	if (pauchData != NULL)
	{
		if (pfAllocated)
			*pfAllocated = true;
		return pauchData;
	}

	//
	// Try the key files
	//

	for (int i = (int) m_vpKeyFiles .GetCount (); i-- > 0;)
	{
		if (m_vpKeyFiles [i] ->IsOpen ())
		{
			pauchData = m_vpKeyFiles [i] ->LoadRes (pszName, 
				nResType, pulSize, pfAllocated);
			if (pauchData != NULL)
				return pauchData;
		}
	}
	return NULL;
}
コード例 #6
0
ファイル: NwnStdLoader.cpp プロジェクト: deltreey/NWNTools
unsigned char *CNwnStdLoader::LoadResource (const char *pszName, 
	NwnResType nResType, UINT32 *pulSize, bool *pfAllocated)
{
	unsigned char *pauchData;

	//
	// Try the module
	//

	if (m_pModule)
	{
		pauchData = m_pModule ->LoadRes (pszName, 
			nResType, pulSize, pfAllocated);
		if (pauchData)
			return pauchData;
	}
	//
	// Try from the default dir
	//

	if (m_strDefaultDir .length () > 0)
	{
		std::string str (m_strDefaultDir);
		str += pszName;
		str += NwnGetResTypeExtension (nResType);
		pauchData = NwnLoadFile (str .c_str (), pulSize);
		if (pauchData != NULL)
		{
			if (pfAllocated)
				*pfAllocated = true;
			return pauchData;
		}
	}

	//
	// Try to load the file from the current dir
	//
	
	std::string str (pszName);
	str += NwnGetResTypeExtension (nResType);
	pauchData = NwnLoadFile (str .c_str (), pulSize);
	if (pauchData != NULL)
	{
		if (pfAllocated)
			*pfAllocated = true;
		return pauchData;
	}

	//
	// Try to load the file from the haks
	//

	for (int i = 0; i < (int) m_apHaks .GetCount (); i++)
	{
		pauchData = m_apHaks [i] ->LoadRes (pszName, 
			nResType, pulSize, pfAllocated);
		if (pauchData)
			return pauchData;
	}

	//
	// If override is enabled, try it
	//

	if (m_fOverride)
	{
		str = m_strOverride;
		str += pszName;
		str += NwnGetResTypeExtension (nResType);
		unsigned char *pauchData = NwnLoadFile (str .c_str (), pulSize);
		if (pauchData != NULL)
		{
			if (pfAllocated)
				*pfAllocated = true;
			return pauchData;
		}
	}

	// 
	// Try the key files
	//

	for (int i = _countof (m_asKeyFiles); i-- > 0;)
	{
		if (m_asKeyFiles [i] .IsOpen ())
		{
			pauchData = m_asKeyFiles [i] .LoadRes (pszName, 
				nResType, pulSize, pfAllocated);
			if (pauchData != NULL)
				return pauchData;
		}
	}
	return NULL;
}