Beispiel #1
0
BYTE * readExtendedSaveFile(char* name, DWORD* size)//WORKS
{
	char filename[512];
	BYTE* data;
	d2_assert(!name, "Bad file name (NULL)", __FILE__, __LINE__);
	D2FogGetSavePath( filename, 512-5);
	strncat(filename, name, 512 - strlen(filename) - 5);
	strcat(filename, ".d2x");

	log_msg("Extended file to read : %s\n",filename);

	FILE* file = fopen(filename, "rb");
	if (file)
	{
		fseek(file, 0, SEEK_END);
		*size = ftell(file);
		fseek(file, 0, SEEK_SET);
		data = (BYTE*)D2FogMemAlloc(*size,__FILE__,__LINE__,0);
		DWORD nbRead = fread(data, 1, *size, file);
		fclose(file);
		d2_assert(nbRead != *size , "nbRead from extented save file != size", __FILE__, __LINE__);
	} else {
		log_msg("Can't open extented save file in mode \"rb\" (is not an error if it's a new player)\n");
		DWORD maxSize = 100;
		data = (BYTE*)D2FogMemAlloc(maxSize,__FILE__,__LINE__,0);
		*size = 14;
		*((DWORD*)&data[0])  = FILE_EXTENDED; //"CSTM"
		*((WORD *)&data[4])  = FILE_VERSION;
		*((DWORD*)&data[6])  = 0;// not used
		*((DWORD*)&data[10]) = 0;// number of stash

		TCustomDll* currentDll = customDlls;
		while (currentDll)
		{
			currentDll->initExtendedSaveFile(&data, &maxSize, size);
			currentDll=currentDll->nextDll;
		}
	}
	return data;
}
Beispiel #2
0
//6FC8CE8A  |. E8 A16BFAFF    CALL D2Game.6FC33A30
//$+C0     >            1F 00 00 00 03 00 00 06                  .....
// 28  0010 1000
BYTE* readSharedSaveFile(char* name, DWORD* size)
{
	char filename[512];
	BYTE* data=NULL;
	BYTE isHardCore=0;
	FILE* file=NULL;

	if (separateHardSoftStash)//Get hardcore flag
	{
		D2FogGetSavePath( filename, 512-strlen(name)-5);
		strcat(filename,name);
		strcat(filename,".d2s");
		log_msg("Normal file to read if it's hardcore character : %s\n",filename);
		file = fopen(filename, "rb");
		if (file)
		{
			fseek(file, 0x24, SEEK_SET);
			DWORD nbRead = fread(&isHardCore, 1, 1, file);
			isHardCore = (nbRead==1)? ((isHardCore & 4) == 4) : 0;
			fclose(file);
			file=NULL;
		}
		log_msg("%s is a HardCore character = %d\n",name,isHardCore);
	}

	if (active_sharedStash)
	{
		D2FogGetSavePath( filename, 512-strlen("_LOD_HC_SharedStashSave")-5);
		strcat(filename,isHardCore? "_LOD_HC_" : "_LOD_");
		strcat(filename, sharedStashFilename);
		strcat(filename,".sss");

		log_msg("Shared file to read : %s\n",filename);

		file = fopen(filename, "rb");
	}

	if (file)
	{
		fseek(file, 0, SEEK_END);
		*size = ftell(file);
		fseek(file, 0, SEEK_SET);
		data = (BYTE*)D2FogMemAlloc(*size,__FILE__,__LINE__,0);
		DWORD nbRead = fread(data, 1, *size, file);
		fclose(file);
		d2_assert(nbRead != *size , "nbRead from shared save file != size", __FILE__, __LINE__);
	} else {
		log_msg("Can't open shared save file in mode \"rb\" (is not an error if it's the first start of the mod)\n");
		*size = 14;
		DWORD maxSize = 100;
		data = (BYTE*)D2FogMemAlloc(maxSize,__FILE__,__LINE__,0);
		*((DWORD *)&data[0]) = FILE_SHAREDSTASH;
		*((WORD *)&data[4]) = FILE_VERSION;
		*((DWORD *)&data[6]) = 0;
		*((DWORD *)&data[10]) = 0;// number of stash

		TCustomDll* currentDll = customDlls;
		while (currentDll)
		{
			currentDll->initSharedSaveFile(&data, &maxSize, size);
			currentDll=currentDll->nextDll;
		}
	}

	return data;
}