<commit_before>﻿using System.Collections;
using System.Reflection;
using UnityEngine;
using UnityEngine.Networking;

public abstract class GameMessageBase : MessageBase
{
	public GameObject NetworkObject;
	public GameObject[] NetworkObjects;

	public abstract IEnumerator Process();

	protected IEnumerator WaitFor(NetworkInstanceId id)
	{
		if (id.IsEmpty()) 
		{
			Logger.LogWarning($"{this} tried to wait on an empty (0) id", Category.NetMessage);
			yield break;
		}

		int tries = 0;
		while ((NetworkObject = ClientScene.FindLocalObject(id)) == null)
		{
			if (tries++ > 10)
			{
				Logger.LogWarning($"{this} could not find object with id {id}", Category.NetMessage);
				yield break;
			}

			yield return YieldHelper.EndOfFrame;
		}
	}

	protected short GetMessageType()
	{
		const BindingFlags FLAGS = BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Public;
		FieldInfo field = this.GetType().GetField("MessageType", FLAGS);
		return (short) field.GetValue(null);
	}

	protected IEnumerator WaitFor(params NetworkInstanceId[] ids)
	{
		NetworkObjects = new GameObject[ids.Length];

		while (!AllLoaded(ids))
		{
			yield return YieldHelper.EndOfFrame;
		}
	}

	private bool AllLoaded(NetworkInstanceId[] ids)
	{
		for (int i = 0; i < ids.Length; i++)
		{
			GameObject obj = ClientScene.FindLocalObject(ids[i]);
			if (obj == null)
			{
				return false;
			}

			NetworkObjects[i] = obj;<commit_msg>Support for null GameObjects in NetMessages<commit_after>﻿using System.Collections;
using System.Reflection;
using UnityEngine;
using UnityEngine.Networking;

public abstract class GameMessageBase : MessageBase
{
	public GameObject NetworkObject;
	public GameObject[] NetworkObjects;

	public abstract IEnumerator Process();

	protected IEnumerator WaitFor(NetworkInstanceId id)
	{
		if (id.IsEmpty())
		{
			Logger.LogWarning($"{this} tried to wait on an empty (0) id", Category.NetMessage);
			yield break;
		}

		int tries = 0;
		while ((NetworkObject = ClientScene.FindLocalObject(id)) == null)
		{
			if (tries++ > 10)
			{
				Logger.LogWarning($"{this} could not find object with id {id}", Category.NetMessage);
				yield break;
			}

			yield return YieldHelper.EndOfFrame;
		}
	}

	protected short GetMessageType()
	{
		const BindingFlags FLAGS = BindingFlags.Static | BindingFlags.FlattenHierarchy | BindingFlags.Public;
		FieldInfo field = this.GetType().GetField("MessageType", FLAGS);
		return (short) field.GetValue(null);
	}

	protected IEnumerator WaitFor(params NetworkInstanceId[] ids)
	{
		NetworkObjects = new GameObject[ids.Length];

		while (!AllLoaded(ids))
		{
			yield return YieldHelper.EndOfFrame;
		}
	}

	private bool AllLoaded(NetworkInstanceId[] ids)
	{
		for (int i = 0; i < ids.Length; i++)
		{
			var netId = ids[i];
			if ( netId == NetworkInstanceId.Invalid ) {
				continue;
			}
			GameObject obj = ClientScene.FindLocalObject(netId);
			if (obj == null)
			{
				return false;
			}

			NetworkObjects[i] = obj;
{'fraction_non_alphanumeric': 0.11271385441127138, 'fraction_numerical': 0.0033545790003354577, 'mean_word_length': 4.159169550173011, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2887715', 'n_tokens_mistral': 1082, 'n_tokens_neox': 936, 'n_words': 241}