/// <summary> /// A very hacky method of returning the implementation of this model in its string form so that if Clyde can't read it, we can still see its name. This returns the full class name.<para/> /// This is only functional for extensions of <see cref="ModelConfig"/>. /// </summary> /// <param name="datFile"></param> /// <param name="isCompressed"></param> /// <returns></returns> private static string HackyGetImplementation(FileInfo datFile, bool isCompressed) { // This is mainly intended for Spiral Knights's ProjectXModelConfig. // SK Animator Tools relied on being in the game directory (like Spiral Spy did) to detect ^ // This allows reading arbitrary class names, even for hypothetical cases where it's a completely different game that uses Clyde. FileInputStream fileIn = new FileInputStream(datFile.FullName); fileIn.skip(8); byte[] buffer; if (isCompressed) { DataInputStream dat = new DataInputStream(new InflaterInputStream(fileIn)); buffer = ByteStreams.toByteArray(dat); } else { buffer = ByteStreams.toByteArray(fileIn); } string modelAsString = Encoding.ASCII.GetString(buffer); int index = modelAsString.IndexOf(IMPLEMENTATION_TAG) + IMPLEMENTATION_TAG.Length; index += 4; // Accomodate for int of space taken after that string. I don't know what purpose it serves (maybe class size?) byte typeLength = buffer[index]; // Length of the string storing the name of the type. string clip = modelAsString.Substring(index + 1, typeLength); return(clip); }
/// <summary> /// Creates an instance from an input stream. /// <para> /// This method use the supplier to open the input stream, extract the bytes and close the stream. /// It is intended that invoking the supplier opens the stream. /// It is not intended that an already open stream is supplied. /// /// </para> /// </summary> /// <param name="inputStreamSupplier"> the supplier of the input stream </param> /// <returns> the byte source </returns> /// <exception cref="UncheckedIOException"> if an IO error occurs </exception> public static ArrayByteSource from(CheckedSupplier <Stream> inputStreamSupplier) { return(Unchecked.wrap(() => { using (Stream @in = inputStreamSupplier()) { sbyte[] bytes = Unchecked.wrap(() => ByteStreams.toByteArray(@in)); return new ArrayByteSource(bytes); } })); }