Fixes#2441. This error would occur when the memory
regions were allocated at particular addresses when
running a mono-compiled binary on a .net runtime.
The data would be copied to the pointer returned
from a fixed() statement, but the managed array
would *not* be updated with the new data. This
caused DecryptKey to silently return a bogus key
full of zeros, and the mix file header decryption
would subsequently fail.
Change callers of this method to use the ReadBytes extension method that ensures the requested amount of bytes are consumed.
Also tighten argument validation.
Automatically formatted all files via VS. This generally corrects indentation, removes trailing whitespace and corrects misplaced tabs or spaces. Manually tweaked a few files where required.
- Updated implementations to return a ReadOnlyList around an array (to reduce wasted memory from exposing lists or lazy enumerators around lists).
- Protect non-public ISpriteFrame classes by making them inner classes to prevent casting.
- Added an AsReadOnly extension method for lists.
- ShpReader will copy the input stream into memory just once rather than for every header.
- ShpReader.CopyImageData switched to use Array.Copy since that uses some unsafe magic for speed.
- In ActorInfo, cache a GetType call and prevent needless materialization in PrerequisitesOf.
- In ObjectCreator, cache type and ctor lookups since these are expensive and often repeated.
- Implement IReadOnlyDictionary<T, U> on Cache<T, U> to provide some supplementary functions.
- In TechTree.GatherOwnedPrerequisites, rearrange a Boolean 'and' expression to evaluate expensive functions later in the chain, and use ContainsKey to speed up name check.
- Almost all calls to Stream.Read were broken. These have been patched to all go through ReadBytes which itself has been fixed to function correctly. The key thing to note is that Stream.Read is very much allowed to return less than the requested number of bytes. If this happens and you're not checking the return result, you'll be working with partially initialized arrays and really bad stuff happens when you do that.
- Call CopyTo rather than copying between streams manually.
- Peek and ReadUInt8 have been changed to avoid a pointless array allocation which is significant overhead for such simple calls.