clean up the script snippits and fix anything you see fit, don't change things that are unknown.

private void ServiceQueueRepeatedly<TQueueItem>(IConcurrentQueue<TQueueItem> queue, Action<TQueueItem> action)
{
	uint limit = _config.LimitQueueItemsPerUpdateTo;
	uint count = 0;
	do
	{
		if (!queue.TryDequeue(out var item) || item is null) return;
		action(item);
	} while (count++ < limit);
}

bool DoOneDecodedMesh()
{
	if (!_decodedMeshQueue.TryDequeue(out var item) || item is null) return false;
	// DoDecodedMesh(item);
	this.meshObjectManager.SetupMeshObject(item);
	return true;
}

public ConcurrentQueue<ScenePrimData> unTexturedPrims = new();

void AllObjectsUpdate(float t)
{
	while (objectUpdates.TryDequeue(out var update) && update is not null)
	{
		if (update.IsNew && !scenePrims.ContainsKey(update.Prim.LocalID))
		{
			MkOBJ.NewObject(update.Prim);
			continue;
		}
		else if (scenePrims.ContainsKey(update.Prim.LocalID))
		{
			scenePrims[update.Prim.LocalID].UpdateObject(update, t);
		}
	}

}

void ObjectBlockUpdates(float t)
{
	while (objectDataBlockUpdates.TryDequeue(out var update) && update is not null)
	{
		if (scenePrims.ContainsKey(update.Prim.LocalID))
		{
			scenePrims[update.Prim.LocalID].ObjectBlockUpdate(update, t);
		}
	}
}

public void TerrainEventHandler(object sender, LandPatchReceivedEventArgs e)
{
	simulators[e.Simulator.Handle].terrain.TerrainPatchUpdate(e);
}


public ConcurrentQueue<TerseObjectUpdateEventArgs> terseUpdates = new();

void Objects_TerseObjectUpdate(object sender, TerseObjectUpdateEventArgs e)
{
	this.objectProximityHandler.AddPrimPositionID(e.Prim);
	terseUpdates.Enqueue(e);
}

void TerseUpdates(float t)
{
	while (terseUpdates.TryDequeue(out var update) && update is not null)
	{
		if (scenePrims.ContainsKey(update.Update.LocalID))
		{
			scenePrims[update.Update.LocalID].TerseUpdate(update, t);
		}
	}
}

public ConcurrentQueue<PrimEventArgs> objectUpdates = new();
public ObjectProximityHandler objectProximityHandler;
void Objects_ObjectUpdate(object sender, PrimEventArgs _event)
{
	objectProximityHandler.AddObject(_event);
}

public ConcurrentDictionary<UUID, uint> scenePrimIndexUUID = new();

public ConcurrentDictionary<uint, ScenePrimData> scenePrims = new();
public Dictionary<uint, List<Primitive>> orphanedPrims = new();

public class MeshRequestData
{
	public uint localID;
	public UUID sculptTextureUUID;
	public GameObject meshHolder;
	public MeshRequestData(uint lid, UUID uuid, GameObject mh)
	{
		localID = lid;
		sculptTextureUUID = uuid;
		meshHolder = mh;
	}
}

public List<MeshRequestData> meshRequests = new();

public static void PreTextureFace(Primitive prim, int j, Renderer rendr)
{
	TextureEntryFace tef = prim.Textures.GetFace((uint)j);
	UUID uuid = tef.TextureID;
	Color color = tef.RGBA.ToUnity();

	if (!ClientManager.assetManager.materialContainer.ContainsKey(uuid))
	{
		ClientManager.assetManager.materialContainer.Add(uuid, new MaterialContainer(uuid, Texture2D.Instantiate(Texture2D.whiteTexture), 3));
		if (!ClientManager.assetManager.materials.ContainsKey(uuid))
		{
			ClientManager.assetManager.materials.Add(uuid, new List<Renderer>());
		}
		ClientManager.assetManager.materials[uuid].Add(rendr);
	}

	DissolveIn dis = rendr.gameObject.AddComponent<DissolveIn>();
	dis.texture = ClientManager.assetManager.materialContainer[uuid].texture;
	dis.color = color;
	dis.newMat = ClientManager.assetManager.materialContainer[uuid].GetMaterial(color, tef.Glow, tef.Fullbright);
}

public void TextureFace(Primitive prim, int subMeshIndex, Renderer rendr)
{
	if (prim.Textures == null)
	{

	}

	TextureEntryFace textureEntryFace = prim.Textures.GetFace((uint)subMeshIndex);
	textureEntryFace.GetOSD(subMeshIndex);

	Color color = textureEntryFace.RGBA.ToUnity();

	Material newMaterial = ClientManager.assetManager.RequestTexture(textureEntryFace.TextureID, rendr, subMeshIndex, color, textureEntryFace.Glow, textureEntryFace.Fullbright);

	if (textureEntryFace.Fullbright) rendr.gameObject.layer = 7;
	else rendr.gameObject.layer = 0;

	if (scenePrims.ContainsKey(prim.LocalID))
	{
		if (IsHUD(scenePrims[prim.LocalID].prim))
		{
			rendr.gameObject.layer = 8;
		}
		if (scenePrims.ContainsKey(scenePrims[prim.LocalID].prim.ParentID))
		{
			if (IsHUD(scenePrims[scenePrims[prim.LocalID].prim.ParentID].prim))
			{
				rendr.gameObject.layer = 8;
			}
		}
	}
}

void ScanForFaces()
{
	if (!ClientManager.active && Time.frameCount % 20 != 0) return;

	var unProcessed = new List<ScenePrimData>();
	while (unTexturedPrims.TryDequeue(out var kvp))
	{
		if (kvp.obj == null) continue;
		var pis = kvp.obj.transform.GetChild(0).GetComponentsInChildren<PrimInfo>();

		if (pis.Length == 0)
		{
			unProcessed.Add(kvp); continue;
		}

		foreach (PrimInfo _pi in pis)
		{
			kvp.obj.name += " " + _pi.face;

			if (!_pi.isTextured && _pi.face > -1)
			{
				//validate++;
				_pi.isTextured = true;
				try
				{
					TextureFace(_pi.prim, _pi.face, _pi.GetComponent<Renderer>());
				}
				catch (Exception e)
				{
					Debug.LogWarning(e);
				}
			}
		}

	}

	foreach (var pi in unProcessed)
	{
		unTexturedPrims.Enqueue(pi);
	}
}