Exemple #1
0
	void RunTest (std::string const & src, std::string const & password, std::ostream & out)
	{
		std::string cypher;
		{
			Crypt::Streamer streamer (password);
			streamer.SetInput (&src [0], src.size ());
			std::ostringstream out;
			streamer.Encrypt (out);
			cypher = out.str ();
		}
		std::string decoded;
		{
			Crypt::Streamer streamer (password);
			streamer.SetInput (&cypher [0], cypher.size ());
			std::ostringstream out;
			streamer.Decrypt (out);
			decoded = out.str ();
		}
		Assert (decoded.size () == src.size ());
		Assert (decoded == src);
	}
Exemple #2
0
//static
LLSD LLModel::writeModel(
	std::ostream& ostr,
	LLModel* physics,
	LLModel* high,
	LLModel* medium,
	LLModel* low,
	LLModel* impostor,
	const LLModel::Decomposition& decomp,
	BOOL upload_skin,
	BOOL upload_joints,
	BOOL nowrite,
	BOOL as_slm,
	int submodel_id)
{
	LLSD mdl;

	LLModel* model[] = 
	{
		impostor,
		low,
		medium,
		high,
		physics
	};

	bool skinning = upload_skin && high && !high->mSkinWeights.empty();

	if (skinning)
	{ //write skinning block
		mdl["skin"] = high->mSkinInfo.asLLSD(upload_joints);
	}

	if (!decomp.mBaseHull.empty() ||
		!decomp.mHull.empty())		
	{
		mdl["physics_convex"] = decomp.asLLSD();
		if (!decomp.mHull.empty() && !as_slm)
		{ //convex decomposition exists, physics mesh will not be used (unless this is an slm file)
			model[LLModel::LOD_PHYSICS] = NULL;
		}
	}
	else if (submodel_id)
	{
		const LLModel::Decomposition fake_decomp;
		mdl["secondary"] = true;
        mdl["submodel_id"] = submodel_id;
		mdl["physics_convex"] = fake_decomp.asLLSD();
		model[LLModel::LOD_PHYSICS] = NULL;
	}

	if (as_slm)
	{ //save material list names
		for (U32 i = 0; i < high->mMaterialList.size(); ++i)
		{
			mdl["material_list"][i] = high->mMaterialList[i];
		}
	}

	for (U32 idx = 0; idx < MODEL_NAMES_LENGTH; ++idx)
	{
		if (model[idx] && (model[idx]->getNumVolumeFaces() > 0) && model[idx]->getVolumeFace(0).mPositions != NULL)
		{
			LLVector3 min_pos = LLVector3(model[idx]->getVolumeFace(0).mPositions[0].getF32ptr());
			LLVector3 max_pos = min_pos;

			//find position domain
			for (S32 i = 0; i < model[idx]->getNumVolumeFaces(); ++i)
			{ //for each face
				const LLVolumeFace& face = model[idx]->getVolumeFace(i);
				for (U32 j = 0; j < (U32)face.mNumVertices; ++j)
				{
					update_min_max(min_pos, max_pos, face.mPositions[j].getF32ptr());
				}
			}

			LLVector3 pos_range = max_pos - min_pos;

			for (S32 i = 0; i < model[idx]->getNumVolumeFaces(); ++i)
			{ //for each face
				const LLVolumeFace& face = model[idx]->getVolumeFace(i);
				if (face.mNumVertices < 3)
				{ //don't export an empty face
					mdl[model_names[idx]][i]["NoGeometry"] = true;
					continue;
				}
				LLSD::Binary verts(face.mNumVertices*3*2);
				LLSD::Binary tc(face.mNumVertices*2*2);
				LLSD::Binary normals(face.mNumVertices*3*2);
				LLSD::Binary indices(face.mNumIndices*2);

				U32 vert_idx = 0;
				U32 norm_idx = 0;
				U32 tc_idx = 0;
			
				LLVector2* ftc = (LLVector2*) face.mTexCoords;
				LLVector2 min_tc;
				LLVector2 max_tc;

				if (ftc)
				{
					min_tc = ftc[0];
					max_tc = min_tc;
					
					//get texture coordinate domain
					for (U32 j = 0; j < (U32)face.mNumVertices; ++j)
					{
						update_min_max(min_tc, max_tc, ftc[j]);
					}
				}

				LLVector2 tc_range = max_tc - min_tc;

				for (U32 j = 0; j < (U32)face.mNumVertices; ++j)
				{ //for each vert
		
					F32* pos = face.mPositions[j].getF32ptr();
										
					//position
					for (U32 k = 0; k < 3; ++k)
					{ //for each component
						//convert to 16-bit normalized across domain
						U16 val = (U16) (((pos[k]-min_pos.mV[k])/pos_range.mV[k])*65535);

						U8* buff = (U8*) &val;
						//write to binary buffer
						verts[vert_idx++] = buff[0];
						verts[vert_idx++] = buff[1];
					}

					if (face.mNormals)
					{ //normals
						F32* norm = face.mNormals[j].getF32ptr();

						for (U32 k = 0; k < 3; ++k)
						{ //for each component
							//convert to 16-bit normalized
							U16 val = (U16) ((norm[k]+1.f)*0.5f*65535);
							U8* buff = (U8*) &val;

							//write to binary buffer
							normals[norm_idx++] = buff[0];
							normals[norm_idx++] = buff[1];
						}
					}
					
					//texcoord
					if (face.mTexCoords)
					{
						F32* src_tc = (F32*) face.mTexCoords[j].mV;

						for (U32 k = 0; k < 2; ++k)
						{ //for each component
							//convert to 16-bit normalized
							U16 val = (U16) ((src_tc[k]-min_tc.mV[k])/tc_range.mV[k]*65535);

							U8* buff = (U8*) &val;
							//write to binary buffer
							tc[tc_idx++] = buff[0];
							tc[tc_idx++] = buff[1];
						}
					}
				}

				U32 idx_idx = 0;
				for (U32 j = 0; j < (U32)face.mNumIndices; ++j)
				{
					U8* buff = (U8*) &(face.mIndices[j]);
					indices[idx_idx++] = buff[0];
					indices[idx_idx++] = buff[1];
				}

				//write out face data
				mdl[model_names[idx]][i]["PositionDomain"]["Min"] = min_pos.getValue();
				mdl[model_names[idx]][i]["PositionDomain"]["Max"] = max_pos.getValue();
				mdl[model_names[idx]][i]["Position"] = verts;
				
				if (face.mNormals)
				{
					mdl[model_names[idx]][i]["Normal"] = normals;
				}

				if (face.mTexCoords)
				{
					mdl[model_names[idx]][i]["TexCoord0Domain"]["Min"] = min_tc.getValue();
					mdl[model_names[idx]][i]["TexCoord0Domain"]["Max"] = max_tc.getValue();
					mdl[model_names[idx]][i]["TexCoord0"] = tc;
				}

				mdl[model_names[idx]][i]["TriangleList"] = indices;

				if (skinning)
				{
					//write out skin weights

					//each influence list entry is up to 4 24-bit values
					// first 8 bits is bone index
					// last 16 bits is bone influence weight
					// a bone index of 0xFF signifies no more influences for this vertex

					std::stringstream ostr;

					for (U32 j = 0; j < (U32)face.mNumVertices; ++j)
					{
						LLVector3 pos(face.mPositions[j].getF32ptr());

						weight_list& weights = high->getJointInfluences(pos);

						S32 count = 0;
						for (weight_list::iterator iter = weights.begin(); iter != weights.end(); ++iter)
						{
							if (iter->mJointIdx < 255 && iter->mJointIdx >= 0)
							{
								U8 idx = (U8) iter->mJointIdx;
								ostr.write((const char*) &idx, 1);

								U16 influence = (U16) (iter->mWeight*65535);
								ostr.write((const char*) &influence, 2);

								++count;
							}		
						}
						U8 end_list = 0xFF;
						if (count < 4)
						{
							ostr.write((const char*) &end_list, 1);
						}
					}

					//copy ostr to binary buffer
					std::string data = ostr.str();
					const U8* buff = (U8*) data.data();
					U32 bytes = data.size();

					LLSD::Binary w(bytes);
					for (U32 j = 0; j < bytes; ++j)
					{
						w[j] = buff[j];
					}

					mdl[model_names[idx]][i]["Weights"] = w;
				}
			}
		}
	}
	
	return writeModelToStream(ostr, mdl, nowrite, as_slm);
}
void print_in_readelf_style(std::ostream& s, const encap::frame_instrlist& instrs, Dwarf_Addr initial_loc)
{
	Dwarf_Addr loc = initial_loc;
	auto reg = [](int regnum) {
		std::ostringstream s;
		s << "r" << regnum << " (" << dwarf_regnames_for_elf_machine(elf_machine)[regnum]
					<< ")";
		return s.str();
	};
	
	for (auto i_instr = instrs.begin(); i_instr != instrs.end(); ++i_instr)
	{
		const char *opcode_name;
		int encoded_opcode = i_instr->fp_base_op << 6 | i_instr->fp_extended_op;
		int ret = lib::dwarf_get_CFA_name(encoded_opcode, &opcode_name);
		assert(ret == DW_DLV_OK);
		if (string(opcode_name) == "DW_CFA_extended") opcode_name = "DW_CFA_nop";
		s << "  " << opcode_name;
		
		switch (encoded_opcode)
		{
			// "packed" two-bit opcodes
			case DW_CFA_advance_loc: 
			case DW_CFA_advance_loc1:
			case DW_CFA_advance_loc2:
			case DW_CFA_advance_loc4:
				loc += i_instr->fp_offset_or_block_len;
				s << ": " << i_instr->fp_offset_or_block_len << " to " << setw(16) << setfill('0') << std::hex << loc << std::dec;
				break;
			case DW_CFA_offset:
				s << ": " << reg(i_instr->fp_register) 
					<< " at cfa" << std::showpos << (lib::Dwarf_Signed)(i_instr->fp_offset_or_block_len) << std::noshowpos;
				break;
			case DW_CFA_restore_extended: goto register_only;
			case DW_CFA_undefined: goto register_only;
			case DW_CFA_same_value: goto register_only;
			case DW_CFA_def_cfa_register: goto register_only;
			case DW_CFA_restore: goto register_only;
			register_only:
				s << ": " << reg(i_instr->fp_register);
				break;
			// DW_CFA_extended and DW_CFA_nop are the same value, BUT
			case DW_CFA_nop: goto no_args;      // this is a full zero byte
			// extended opcodes follow
			case DW_CFA_remember_state: goto no_args;
			case DW_CFA_restore_state: goto no_args;
			no_args:
				break;
			case DW_CFA_set_loc:
				goto unsupported_for_now; // FIXME
				break;

			case DW_CFA_offset_extended_sf: goto register_and_offset;
			case DW_CFA_def_cfa_sf: goto register_and_offset;
			case DW_CFA_register: goto register_and_offset;
			case DW_CFA_offset_extended: goto register_and_offset;
			case DW_CFA_def_cfa: goto register_and_offset;
			case DW_CFA_val_offset: goto register_and_offset;
			case DW_CFA_val_offset_sf: goto register_and_offset;
			register_and_offset: // FIXME: second register goes where? I've put it in fp_offset_or_block_len
				s << ": " << reg(i_instr->fp_register) << " ofs " << i_instr->fp_offset_or_block_len;
				break;

			case DW_CFA_def_cfa_offset_sf: goto offset_only;
			case DW_CFA_def_cfa_offset: goto offset_only;
			offset_only:
				s << ": " << i_instr->fp_offset_or_block_len;
				break;

			case DW_CFA_expression:
				goto unsupported_for_now; // FIXME

			case DW_CFA_def_cfa_expression: goto expression;
			case DW_CFA_val_expression: goto expression;
			expression:
				s << " (";
				print_in_readelf_style(s, encap::loc_expr(dbg, i_instr->fp_expr_block, i_instr->fp_offset_or_block_len));
				s << ")";
				break;

			default: goto unsupported_for_now;
			unsupported_for_now:
				s << "FIXME";
				break;
		}
		
		s << endl;
	}
}