Ejemplo n.º 1
0
void* findAssetEverywhere(zoneInfo_t* info, int type, const char* name)
{
	void* ret = getAsset(info, type, name);
	if(ret) return ret;

	return DB_FindXAssetHeader(type, name);
}
snd_alias_list_t* FindSoundAliasHookFunc(assetType_t type, const char* name)
{
	snd_alias_list_t* aliases = (snd_alias_list_t*)DB_FindXAssetHeader(type, name);
	
	// the most hated sound at this point
	if (!_stricmp(name, "music_mainmenu_mp"))
	{
		static snd_alias_list_t newList;
		static snd_alias_t newAlias;
		static StreamFile newFile;

		// duplicate the asset as we can't modify pointers
		memcpy(&newList, aliases, sizeof(newList));

		memcpy(&newAlias, newList.aliases, sizeof(newAlias));
		newList.aliases = &newAlias;

		memcpy(&newFile, newAlias.stream, sizeof(newFile));
		newAlias.stream = &newFile;

		// and replace the filename.
		//newFile.file = "hz_boneyard_intro_LR_1.mp3";
		newFile.file = "ui_lobby_answering_the_call.mp3";

		// oh and this too
		aliases = &newList;
	}

	return aliases;
}
Ejemplo n.º 3
0
void * addSoundAlias(zoneInfo_t* info, const char* name, char* data, int dataLen)
{
	if (dataLen < 0) 
	{
		SoundAliasList* lst = (SoundAliasList*)data;
		if (lst->head->soundFile->type == SAT_STREAMED || lst->head->soundFile->type == SAT_LOADED)
		{
			return data; // no fixups needed
		}
		Com_Error(false, "Unknown sound type %d!\n", lst->head->soundFile->type);
		return NULL;
	}

	// why the hell can't I f*****g do string parsing?
	string l = string(data);
	int slash = l.find_last_of('/');
	bool hasfolder;
	string folder, file;

	if(slash == -1)
	{
		file = l;
		hasfolder = false;
	}
	else
	{
		folder = l.substr(0, slash);
		file = l.substr(slash + 1);
		hasfolder = true;
	}

	SoundAliasList* base = (SoundAliasList*)DB_FindXAssetHeader(ASSET_TYPE_SOUND, "AB_1mc_boost");
	SoundAliasList* snd = new SoundAliasList;
	memcpy(snd, base, sizeof(SoundAliasList));
	snd->name = strdup(name);
	snd->head->name = snd->name;

	if (hasfolder)
	{
		snd->head->soundFile->data.stream.dir = strdup((char*)folder.c_str());
	}
	else
	{
		snd->head->soundFile->data.stream.dir = NULL;
	}

	snd->head->soundFile->data.stream.name = strdup((char*)file.c_str());

	return snd;
}
void StringTable_GetAsset(char* filename, stringTable_t** table)
{
	if (!stringTables[filename])
	{
		stringTables[filename] = StringTable_Load(filename);
	}

	// 1 = get from XAsset DB
	if ((int)stringTables[filename] == 1)
	{
		*table = (stringTable_t*)DB_FindXAssetHeader(ASSET_TYPE_STRINGTABLE, filename);
	}
	else
	{
		*table = stringTables[filename];
	}
}
const char* SEH_GetLocalizedString(const char* key)
{
	google::dense_hash_map<std::string, std::string>::const_iterator iter = _localizedStrings.find(key);
 
	if (iter != _localizedStrings.end())
	{
		return (*iter).second.c_str();
	}
 
	localizedEntry_s* entry = (localizedEntry_s*)DB_FindXAssetHeader(ASSET_TYPE_LOCALIZE, key);
 
	if (entry)
	{
		return entry->value;
	}
	
	return NULL;
}
stringTable_t* StringTable_Load_LoadObj(const char* filename, const char* buffer)
{
	stringTable_t* origTable = (stringTable_t*)DB_FindXAssetHeader(ASSET_TYPE_STRINGTABLE, filename);

	strtk::token_grid::options options;
	options.set_row_delimiters("\r\n");
	options.set_column_delimiters(",");
	options.set_column_split_option(strtk::split_options::default_mode);
	options.set_row_split_option(strtk::split_options::default_mode);

	strtk::token_grid grid(buffer, strlen(buffer), options);
	int columns = grid.max_column_count();
	int rows = grid.row_count();

	stringTable_t* newTable = (stringTable_t*)malloc(sizeof(stringTable_t));
	newTable->fileName = (char*)filename;
	newTable->data = (char**)malloc(sizeof(char*) * rows * columns * 2);

	for (std::size_t ri = 0; ri < (std::size_t)rows; ri++)
	{
		strtk::token_grid::row_type r = grid.row(ri);

		for (std::size_t ci = 0; ci < r.size(); ci++)
		{
			std::string strSource = r.get<std::string>(ci);
			char* str = (char*)malloc(strSource.length() + 1);
			memcpy(str, strSource.c_str(), strSource.length() + 1);

			newTable->data[((ri * columns) + ci) * 2] = str;
			newTable->data[(((ri * columns) + ci) * 2) + 1] = (char*)StringTableHash(str);
		}
	}

	newTable->columns = columns;
	newTable->rows = rows;

	return newTable;
}
Ejemplo n.º 7
0
void* addXModel(zoneInfo_t* info, const char* name, char* data, size_t dataLen)
{
	if (data == NULL) return NULL;

	if(dataLen == 0)
	{
		XModel * model = (XModel*)data;
		short* boneNames = new short[model->numBones];

		for(int i=0; i<model->numBones; i++)
		{
			boneNames[i] = addScriptString(info, SL_ConvertToString(model->boneNames[i]));
		}

		model->boneNames = boneNames;

		for(int i=0; i<model->numSurfaces; i++)
		{
			// allow material overriding
			void* file;
			void* asset;

			if(int len = FS_ReadFile(va("zonebuilder/materials/%s.txt", model->materials[i]->name), &file) > 0)
			{
				asset = addMaterial(info, model->materials[i]->name, (char*)file, len);
				FS_FreeFile(file);
			}
			else
			{
				asset = addMaterial(info, model->materials[i]->name, (char*)model->materials[i], 0);
			}

			addAsset(info, ASSET_TYPE_MATERIAL, model->materials[i]->name, asset);
		}

		return data;
	}

	// copy stuff over
	XModel * base = (XModel*)DB_FindXAssetHeader(ASSET_TYPE_XMODEL, "viewmodel_mp5k");
	XModel * asset = new XModel;

	memcpy(asset, base, sizeof(XModel));
	asset->lods[0].surfaces = new XModelSurfaces;
	memcpy(asset->lods[0].surfaces, base->lods[0].surfaces, sizeof(XModelSurfaces));

	XModelSurfaces * surf = asset->lods[0].surfaces;
	surf->name = new char[strlen(name) + 6];
	sprintf((char*)surf->name, "%s_surf", name);

	BUFFER * buf = new BUFFER(data, dataLen);
	asset->name = new char[128];
	buf->readstr(asset->name, 128);
	buf->read(&asset->numBones, 4, 1);
	buf->read(&asset->numSubBones, 4, 1);
	buf->read(&asset->numSurfaces, 4, 1);
	surf->numSurfaces = asset->numSurfaces;
	asset->lods[0].numSurfs = surf->numSurfaces;

	asset->boneNames = new short[asset->numBones];

	for(int i=0; i<asset->numBones; i++)
	{
		char bone[64];
		buf->readstr(bone, 64);
		asset->boneNames[i] = addScriptString(info, bone);
	}

	// allocate stuff and load it
	if(asset->numBones - asset->numSubBones)
	{
		asset->parentList = new char[asset->numBones - asset->numSubBones];
		asset->tagAngles = new XModelAngle[asset->numBones - asset->numSubBones];
		asset->tagPositions = new XModelTagPos[asset->numBones - asset->numSubBones];

		buf->read(asset->parentList, sizeof(char), asset->numBones - asset->numSubBones);
		buf->read(asset->tagAngles, sizeof(XModelAngle), asset->numBones - asset->numSubBones);
		buf->read(asset->tagPositions, sizeof(XModelTagPos), asset->numBones - asset->numSubBones);
	}

	if(asset->numBones)
	{
		asset->partClassification = new char[asset->numBones];
		asset->animMatrix = new char[32 * asset->numBones];

		buf->read(asset->partClassification, sizeof(char), asset->numBones);
		buf->read(asset->animMatrix, 32, asset->numBones);
	}

	surf->surfaces = new XSurface[surf->numSurfaces];
	memset(surf->surfaces, 0, sizeof(XSurface) * surf->numSurfaces);
	
	for(int i=0; i<surf->numSurfaces; i++)
	{
		XSurface* s = &surf->surfaces[i];
		buf->read(&s->numVertices, 4, 1);
		buf->read(&s->numPrimitives, 4, 1);
		buf->read(&s->blendNum1, 4, 1);
		buf->read(&s->blendNum2, 4, 1);
		buf->read(&s->blendNum3, 4, 1);
		buf->read(&s->blendNum4, 4, 1);

		int blendCount = (s->blendNum4 * 7) + (s->blendNum3 * 5) + (s->blendNum2 * 3) + s->blendNum1;

		if(blendCount)
		{
			s->blendInfo = new char[blendCount * 2];
			buf->read(s->blendInfo, 2, blendCount);
		}
		else 
		{
			s->blendInfo = NULL;	
		}

		s->vertexBuffer = new GfxPackedVertex[s->numVertices];
		buf->read(s->vertexBuffer, 32, s->numVertices);

		int ct = 0;
		buf->read(&ct, 4, 1);

		if(ct)
		{
			buf->read(&s->numCT, 4, 1);
			s->ct = new XSurfaceCT[s->numCT];

			for(int j=0; j<s->numCT; j++)
			{
				XSurfaceCT* ct = &s->ct[j];
				buf->read(&ct->pad, 4, 1);
				buf->read(&ct->pad2, 4, 1);
				ct->entry = new XSurfaceCTEntry;
				buf->read(ct->entry, 24, 1);
				buf->read(&ct->entry->numNode, 4, 1);
				buf->read(&ct->entry->numLeaf, 4, 1);

				if(ct->entry->numNode)
				{
					ct->entry->node = new char[ct->entry->numNode * 16];
					buf->read(ct->entry->node, 16, ct->entry->numNode);
				}
				else
				{
					ct->entry->node = NULL;
				}

				if(ct->entry->numLeaf)
				{
					ct->entry->leaf = new short[ct->entry->numLeaf];
					buf->read(ct->entry->leaf, 2, ct->entry->numLeaf);
				}
				else
				{
					ct->entry->node = NULL;
				}
			}
		}
		else
		{
			s->ct = NULL;
			s->numCT = 0;
		}

		s->indexBuffer = new Face[s->numPrimitives];
		buf->read(s->indexBuffer, sizeof(Face), s->numPrimitives);
	}

	asset->materials = new Material*[asset->numSurfaces];

	// read the material stuff and load a material if we need it
	for(int i=0; i<asset->numSurfaces; i++)
	{
		char matName[64] = { 0 };
		char techName[64] = { 0 };
		char matFileName[78] = { 0 };

		buf->readstr(matName, 50);
		buf->readstr(techName, 64);

		char* filename = matName;

		// asset is already in db... dont re-add it
		if (containsAsset(info, ASSET_TYPE_MATERIAL, matName) > 0)
		{
			asset->materials[i] = (Material*)getAsset(info, ASSET_TYPE_MATERIAL, matName);
			continue;
		}

		if(!strncmp("mc/", matName, 3)) filename = matName + 3;

		_snprintf(matFileName, sizeof(matFileName), "materials/%s.txt", filename);

		void* matBuf;
		int len = FS_ReadFile(matFileName, &matBuf);

		if(len > 0)
		{
			asset->materials[i] = (Material*)addMaterial(info, matName, (char*)matBuf, len);
			FS_FreeFile(matBuf);
		}
		else
		{
			asset->materials[i] = (Material*)DB_FindXAssetHeader(ASSET_TYPE_MATERIAL, matName);
			addMaterial(info, matName, (char*)asset->materials[i], 0);
		}

		addAsset(info, ASSET_TYPE_MATERIAL, matName, asset->materials[i]);		
	}

	int test = 0;
	buf->read(&test, 4, 1);

	if(test) Com_Error(false, "Cause NTA said so!");

	buf->read(&test, 4, 1);

	if(!test) Com_Error(false, "Cause NTA said so!");

	asset->unknowns = new char[asset->numBones * 28];
	buf->read(asset->unknowns, 28, asset->numBones);

	return asset;
}
void DumpRawFiles()
{
	if (Cmd_Argc() != 2)
	{
		return;
	}

	rawFileNames[0] = Cmd_Argv(1);
	currentRawFile = 1;

	for (int i = 0; i < currentRawFile; i++)
	{
		const char* name = rawFileNames[i];
		memset(rawFileBuffer, 0, RAWFILE_BUFSIZE);

		if (LoadRawFile(name, rawFileBuffer, RAWFILE_BUFSIZE))
		{
			char filename[512];
			char dir[512];
			size_t length = strlen(rawFileBuffer);
			sprintf(filename, "%s/%s", "maw", name);

			GetCurrentDirectoryA(sizeof(dir), dir);
			strcat(dir, "/");
			strcat(dir, filename);
			*(strrchr(dir, '/')) = '\0';

			size_t strl = strlen(dir);

			for (size_t i = 0; i < strl; i++)
			{
				if (dir[i] == '/') dir[i] = '\\';
			}

			SHCreateDirectoryExA(NULL, dir, NULL);

			FILE* file = fopen(filename, "wb");

			if (file)
			{
				fwrite(rawFileBuffer, 1, length, file);
				fclose(file);
			}
		}
	}

	currentRawFile = 0;

	return;

	for (int i = 0; i < currentSTable; i++)
	{
		const char* name = sTableNames[i];
		stringTable_t* stringTable;

		if (stringTable = (stringTable_t*)DB_FindXAssetHeader(37, name))
		{
			char filename[512];
			char dir[512];
			sprintf(filename, "%s/%s", "raw", name);

			GetCurrentDirectoryA(sizeof(dir), dir);
			strcat(dir, "/");
			strcat(dir, filename);
			*(strrchr(dir, '/')) = '\0';

			size_t strl = strlen(dir);

			for (size_t i = 0; i < strl; i++)
			{
				if (dir[i] == '/') dir[i] = '\\';
			}

			SHCreateDirectoryExA(NULL, dir, NULL);

			FILE* file = fopen(filename, "w");

			if (file)
			{
				int currentColumn = 0;
				int currentRow = 0;
				int total = stringTable->columns * stringTable->rows;

				for (int i = 0; i < total; i++) {
					char* current = stringTable->data[i * 2];

					fprintf(file, "%s", current);

					bool isNext = ((i + 1) % stringTable->columns) == 0;

					if (isNext) {
						fprintf(file, "\n");
					} else {
						fprintf(file, ",");
					}

					fflush(file);
				}

				fclose(file);
			}
		}
	}

	currentSTable = 0;
}
void BG_PatchWeaponDef(char* weapon, AttachmentDef* attachment)
{
	Com_Printf(0, "Patching weapon %s using %s\n", *(char**)weapon, attachment->name);

	for (int i = 0; i < attachment->numPatches; i++)
	{
		AttachmentPatch* patch = &attachment->patches[i];
		weaponEntry_t* entry = FindWeaponEntry(patch->fieldName);

		if (!entry)
		{
			Com_Error(1, "Unknown weapon field %s in %s.", patch->fieldName, attachment->name);
		}

		assetType_t assetType;

		switch (entry->type)
		{
			case 0: // string
				{
					char** string = (char**)(weapon + entry->offset);

					if (patch->operation == APO_ADD)
					{
						*string = strdup(va("%s%s", *string, patch->string));
					}
					else
					{
						if (strchr(patch->string, ' '))
						{
							char* oldName = *(char**)(weapon + entry->offset);

							// TODO: needs to be changed to SL?
							*string = DoStringParse(oldName, patch);
							//char* newStr = DoStringParse(oldName, patch);
														
							//free(newStr);
						}
						else
						{
							*string = (char*)patch->string; // ?!
						}
					}

					break;
				}
			case 1: // char[1024]
			case 2: // char[64]
			case 3: // char[256]
				{
					if (strchr(patch->string, ' '))
					{
						char* oldName = (char*)(weapon + entry->offset);

						// TODO: needs to be changed to SL?
						char* str = DoStringParse(oldName, patch);
						sprintf((char*)(weapon + entry->offset), "%s", str);
						free(str);
					}
					else
					{
						sprintf((char*)(weapon + entry->offset), "%s", patch->string);
					}
					break;
				}

#define DO_NUM_PATCH(variable, source) if (patch->operation == APO_ADD) \
				{ \
					variable += source; \
				} else if (patch->operation == APO_MULTIPLY) { \
					variable *= source; \
				} else { \
					variable = source; \
				}

#define GET_NUM(patch) ((patch->type == APT_FLOAT) ? patch->value : ((patch->type == APT_INTEGER) ? patch->integer : atof(patch->string)))

			case 4:
			case 5: // bool-as-int
				{
					//*(int*)(weapon + entry->offset) = patch->integer;

					int oldNum = *(int*)(weapon + entry->offset);
					DO_NUM_PATCH(oldNum, GET_NUM(patch));
					*(int*)(weapon + entry->offset) = oldNum;

					break;
				}
			case 6:
				{
					*(bool*)(weapon + entry->offset) = patch->integer;
					break;
				}

			case 7:
				{
					float oldNum = *(float*)(weapon + entry->offset);

					DO_NUM_PATCH(oldNum, GET_NUM(patch));

					*(float*)(weapon + entry->offset) = oldNum;
					break;
				}
			case 8:
				{
					float oldNum = *(float*)(weapon + entry->offset) / 17.6f;

					DO_NUM_PATCH(oldNum, GET_NUM(patch));

					*(float*)(weapon + entry->offset) = oldNum * 17.6f; // miles/hour - inch/sec
					break;
				}
			case 9:
				{
					float oldNum = *(float*)(weapon + entry->offset) / 1000.f;

					DO_NUM_PATCH(oldNum, GET_NUM(patch));

					*(float*)(weapon + entry->offset) = oldNum * 1000.f;
					break;
				}
#define WEAPON_DO_ARRAY(arr, count) \
	{ \
		for (int i = 0; i < (count); i++) { \
			if (patch->type == APT_STRING && !_stricmp(*(char**)(arr + (i * 4)), patch->string)) { \
				*(int*)(weapon + entry->offset) = i; \
			} \
		} \
	}
			case 16:
				WEAPON_DO_ARRAY(0x795DA0, 4)
				break;
			case 17:
				WEAPON_DO_ARRAY(0x795DB0, 12)
				break;
			case 18:
				WEAPON_DO_ARRAY(0x795E68, 2)
				break;
			case 19:
				WEAPON_DO_ARRAY(0x795E10, 4)
				break;
			case 20:
				WEAPON_DO_ARRAY(0x795E20, 11)
					break;
			case 21:
				WEAPON_DO_ARRAY(0x795E70, 3)
					break;
			case 22:
				WEAPON_DO_ARRAY(0x795E4C, 7)
					break;
			case 23:
				WEAPON_DO_ARRAY(0x795E7C, 6)
					break;
			case 24:
				WEAPON_DO_ARRAY(0x7BE928, *(int*)0x7BDDDC)
					break;
			case 25:
				WEAPON_DO_ARRAY(0x795E94, 3)
					break;
			case 26:
				WEAPON_DO_ARRAY(0x795EA0, 4)
					break;
			case 28:
				WEAPON_DO_ARRAY(0x795EB0, 6)
					break;
			case 29:
				WEAPON_DO_ARRAY(0x795EC8, 3)
					break;
			case 30:
				WEAPON_DO_ARRAY(0x795DE0, 6)
					break;
			case 31:
				WEAPON_DO_ARRAY(0x795DF8, 6)
					break;
			case 32:
				WEAPON_DO_ARRAY(0x795ED4, 7)
					break;
			case 33:
				WEAPON_DO_ARRAY(0x795EF0, 3)
					break;
			case 34:
				WEAPON_DO_ARRAY(0x795EF0, 3) // same as 33
					break;
			case 35:
				WEAPON_DO_ARRAY(0x795EF0, 3) // same as 33
					break;
			case 36:
				WEAPON_DO_ARRAY(0x795EF0, 3) // same as 33
					break;
			case 37:
				WEAPON_DO_ARRAY(0x795EF0, 3) // same as 33
					break;
			/*case 13: // phys collmap
				break;*/
			case 10: // fx
				assetType = ASSET_TYPE_FX;
				goto loadThingAsset;
			case 11: // xmodel
				assetType = ASSET_TYPE_XMODEL;
				goto loadThingAsset;
			case 12: // material
				assetType = ASSET_TYPE_MATERIAL;
				goto loadThingAsset;
			case 14: // soundalias
				assetType = ASSET_TYPE_SOUND;
				goto loadThingAsset;
			case 15: // tracer
				assetType = ASSET_TYPE_TRACER;

loadThingAsset:
				{
					if (strchr(patch->string, ' '))
					{
						char* oldName = **(char***)(weapon + entry->offset);

						char* newStr = DoStringParse(oldName, patch);

						// and get the asset/free the string
						*(void**)(weapon + entry->offset) = DB_FindXAssetHeader(assetType, newStr);

						free(newStr);
					}
					else
					{
						*(void**)(weapon + entry->offset) = DB_FindXAssetHeader(assetType, patch->string);
					}
					break;
				}
			/*case 38: // hideTags
				{
					// hopefully we'll have useful shit here, as if we don't, we're screwed
					// for some reason this code made me go deja vu - seems like I've done SL_ConvertToString before.
					short* tags = (short*)data;
					for (int i = 0; i < 32; i++)
					{
						short tag = tags[i];

						if (tag)
						{
							fprintf(file, "%s%s", SL_ConvertToString(tag), (i == 31 || tags[i + 1] == 0) ? "" : "\n"); // it seems like a newline is needed for all but the last tag
						}
					}
					break;
				}
			case 27: // bounceSound; surface sound
				{
					char*** dat = *(char****)data;
					if (dat != 0)
					{
						char bounceName[128];
						strcpy(bounceName, **dat);
						strrchr(bounceName, '_')[0] = '\0';

						fprintf(file, "%s", bounceName);
					}
					break;
				}*/
			default:
				Com_Error(1, "Unhandled weapon field type %i in %s\n", entry->type, entry->name);
				break;
		}
	}
}