private void readClientInterop()
{
if (KSP.IO.File.Exists<KLFManager>(INTEROP_CLIENT_FILENAME))
{
byte[] bytes = null;
try
{
bytes = KSP.IO.File.ReadAllBytes<KLFManager>(INTEROP_CLIENT_FILENAME);
//Delete the screenshot now that it's been read
KSP.IO.File.Delete<KLFManager>(INTEROP_CLIENT_FILENAME);
}
catch
{
bytes = null;
Debug.LogWarning("*** Unable to read file " + INTEROP_CLIENT_FILENAME);
}
if (bytes != null && bytes.Length > 4)
{
//Read the file-format version
int file_version = KLFCommon.intFromBytes(bytes, 0);
if (file_version != KLFCommon.FILE_FORMAT_VERSION)
{
//Incompatible client version
Debug.LogError("KLF Client incompatible with plugin");
return;
}
//Parse the messages
int index = 4;
while (index < bytes.Length - KLFCommon.INTEROP_MSG_HEADER_LENGTH)
{
//Read the message id
int id_int = KLFCommon.intFromBytes(bytes, index);
KLFCommon.ClientInteropMessageID id = KLFCommon.ClientInteropMessageID.NULL;
if (id_int >= 0 && id_int < Enum.GetValues(typeof(KLFCommon.ClientInteropMessageID)).Length)
id = (KLFCommon.ClientInteropMessageID)id_int;
//Read the length of the message data
int data_length = KLFCommon.intFromBytes(bytes, index + 4);
index += KLFCommon.INTEROP_MSG_HEADER_LENGTH;
if (data_length <= 0)
handleInteropMessage(id, null);
else if (data_length <= (bytes.Length - index))
{
//Copy the message data
byte[] data = new byte[data_length];
Array.Copy(bytes, index, data, 0, data.Length);
handleInteropMessage(id, data);
}
if (data_length > 0)
index += data_length;
}
}
}
}