Ejemplo n.º 1
0
	int Write(lua_State* L)
	{
		//takes a pts data table, returns a .eqg directory entry table
		Util::PrepareWrite(L, ".pts");

		//write .pts data
		Header header;
		header.magic[0] = 'E';
		header.magic[1] = 'Q';
		header.magic[2] = 'P';
		header.magic[3] = 'T';
		header.version = 1;
		header.data_count = lua_objlen(L, 1);

		Util::Buffer buf;
		buf.Add(&header, Header::SIZE);

		for (uint32 i = 1; i <= header.data_count; ++i)
		{
			lua_pushinteger(L, i);
			lua_gettable(L, 1);

			Data d;
			snprintf(d.particle_name, 64, "%s", Util::GetString(L, -1, "particle_name"));
			snprintf(d.attach_name, 64, "%s", Util::GetString(L, -1, "attach_name"));

			lua_getfield(L, -1, "translation");
			d.translation[0] = Util::GetFloat(L, -1, "z");
			d.translation[1] = Util::GetFloat(L, -1, "y");
			d.translation[2] = Util::GetFloat(L, -1, "x");
			lua_pop(L, 1);

			lua_getfield(L, -1, "rotation");
			d.rotation[0] = Util::GetFloat(L, -1, "z");
			d.rotation[1] = Util::GetFloat(L, -1, "y");
			d.rotation[2] = Util::GetFloat(L, -1, "x");
			lua_pop(L, 1);

			lua_getfield(L, -1, "scale");
			d.scale[0] = Util::GetFloat(L, -1, "z");
			d.scale[1] = Util::GetFloat(L, -1, "y");
			d.scale[2] = Util::GetFloat(L, -1, "x");
			lua_pop(L, 1);

			buf.Add(&d, Data::SIZE);

			lua_pop(L, 1);
		}

		return Util::FinishWrite(L, buf);
	}
Ejemplo n.º 2
0
	int Write(lua_State* L)
	{
		//takes a prt data table, returns a .eqg directory entry table
		Util::PrepareWrite(L, ".prt");

		Header header;
		header.magic[0] = 'P';
		header.magic[1] = 'T';
		header.magic[2] = 'C';
		header.magic[3] = 'L';
		header.version = 4;
		header.particle_count = lua_objlen(L, 1);

		Util::Buffer buf;
		buf.Add(&header, sizeof(Header));

		for (uint32 i = 1; i <= header.particle_count; ++i)
		{
			lua_pushinteger(L, i);
			lua_gettable(L, 1);

			DataV4 d;
			d.particle_id = Util::GetInt(L, -1, "particle_id");
			snprintf(d.particle_name, 64, "%s", Util::GetString(L, -1, "particle_name"));
			d.duration = Util::GetInt(L, -1, "duration");

			lua_getfield(L, -1, "unknown");
			for (int j = 1; j <= 5; ++j)
			{
				d.unknownA[j - 1] = Util::GetInt(L, -2, j);
			}
			d.unknownB = Util::GetInt(L, -2, 6);
			lua_pushinteger(L, 7);
			lua_gettable(L, -2);
			double u = lua_tonumber(L, -1);
			uint32 a = static_cast<uint32>(u);
			d.unknownFFFFFFFF = 0;
			d.unknownFFFFFFFF |= a;
			lua_pop(L, 1);
			d.unknownC = Util::GetInt(L, -2, 8);
			lua_pop(L, 1);

			buf.Add(&d, sizeof(DataV4));

			lua_pop(L, 1);
		}

		return Util::FinishWrite(L, buf);
	}