Fix StyleCop warnings in OpenRA.Game

This commit is contained in:
Hellhake
2015-01-01 23:04:18 +01:00
parent e9989496c4
commit 5a97a4b63b
119 changed files with 547 additions and 529 deletions

View File

@@ -142,9 +142,9 @@ namespace OpenRA.FileFormats
}
} while (len != 0);
}
// literal value
else
{
// literal value
var symbol = EncodedLiterals ? Decode(litcode, br) : br.ReadBits(8);
outBuffer[next++] = (byte)symbol;
if (next == MAXWIN)

View File

@@ -26,7 +26,7 @@ namespace OpenRA.FileFormats
uint l = 0, r = 0;
for (var i = 0; i < 18; )
for (var i = 0; i < 18;)
{
Encrypt(ref l, ref r);
m_p[i++] = l;
@@ -34,7 +34,7 @@ namespace OpenRA.FileFormats
}
for (var i = 0; i < 4; ++i)
for (var j = 0; j < 256; )
for (var j = 0; j < 256;)
{
Encrypt(ref l, ref r);
m_s[i, j++] = l;
@@ -45,7 +45,7 @@ namespace OpenRA.FileFormats
public uint[] Encrypt(uint[] data) { return RunCipher(data, Encrypt); }
public uint[] Decrypt(uint[] data) { return RunCipher(data, Decrypt); }
delegate void CipherFunc( ref uint a, ref uint b );
delegate void CipherFunc(ref uint a, ref uint b);
static uint[] RunCipher(uint[] data, CipherFunc f)
{
@@ -56,7 +56,7 @@ namespace OpenRA.FileFormats
while (size-- > 0)
{
var a = SwapBytes(data[i]);
var b = SwapBytes(data[i+1]);
var b = SwapBytes(data[i + 1]);
f(ref a, ref b);
@@ -73,13 +73,14 @@ namespace OpenRA.FileFormats
_a ^= m_p[0];
var x = false;
for( var i = 1; i <= 16; i++, x ^= true)
for (var i = 1; i <= 16; i++, x ^= true)
{
if (x)
Round(ref _a, _b, i);
else
Round(ref _b, _a, i);
}
_b ^= m_p[17];
a = _b;
@@ -99,6 +100,7 @@ namespace OpenRA.FileFormats
else
Round(ref _b, _a, i);
}
_b ^= m_p[0];
a = _b;
@@ -400,7 +402,6 @@ namespace OpenRA.FileFormats
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
}
};
}
}

View File

@@ -25,6 +25,7 @@ namespace OpenRA.FileFormats
public uint[] key2 = new uint[64];
public uint len;
}
PublicKey pubkey = new PublicKey();
uint[] glob1 = new uint[64];
@@ -81,6 +82,7 @@ namespace OpenRA.FileFormats
keylen = key[j];
j++;
}
if (keylen <= len * 4)
move_key_to_big(n, key.Skip(j).ToArray(), keylen, len);
}
@@ -105,6 +107,7 @@ namespace OpenRA.FileFormats
mask >>= 1;
bitlen--;
}
return bitlen;
}
@@ -124,13 +127,13 @@ namespace OpenRA.FileFormats
static int cmp_bignum(uint[] n1, uint[] n2, uint len)
{
while (len > 0)
{
--len;
if (n1[len] < n2[len]) return -1;
if (n1[len] > n2[len]) return 1;
}
return 0;
}
@@ -149,6 +152,7 @@ namespace OpenRA.FileFormats
for (; i < len; i++) n[i] = 0;
bits = bits % 32;
}
if (bits == 0) return;
for (i = 0; i < len - 1; i++) n[i] = (n[i] >> bits) | (n[i + 1] << (32 -
bits));
@@ -166,6 +170,7 @@ namespace OpenRA.FileFormats
for (; i > 0; i--) n[i] = 0;
bits = bits % 32;
}
if (bits == 0) return;
for (i = len - 1; i > 0; i--) n[i] = (n[i] << bits) | (n[i - 1] >> (32 -
bits));
@@ -196,6 +201,7 @@ namespace OpenRA.FileFormats
}
}
}
return carry;
}
@@ -215,8 +221,8 @@ namespace OpenRA.FileFormats
i2 = *ps2++;
*pd++ = (ushort)(i1 - i2 - carry);
if (((i1 - i2 - carry) & 0x10000) != 0) carry = 1; else carry = 0;
}
return carry;
}
@@ -245,6 +251,7 @@ namespace OpenRA.FileFormats
sub_bignum(n_tmp, n_tmp, n2, 0, (int)len);
n1[j] |= bit;
}
bit >>= 1;
if (bit == 0)
{
@@ -252,6 +259,7 @@ namespace OpenRA.FileFormats
bit = 0x80000000;
}
}
init_bignum(n_tmp, 0, len);
}
@@ -278,6 +286,7 @@ namespace OpenRA.FileFormats
shr_bignum(glob1_hi_inv, 1, 2);
glob1_hi_bitlen--;
}
glob1_hi_inv_lo = (ushort)glob1_hi_inv[0];
glob1_hi_inv_hi = (ushort)(glob1_hi_inv[0] >> 16);
}
@@ -311,8 +320,8 @@ namespace OpenRA.FileFormats
unsafe
{
fixed( uint * _psrc2 = &src2[0] )
fixed(uint* _pdest = &dest[0])
fixed (uint* _psrc2 = &src2[0])
fixed (uint* _pdest = &dest[0])
{
var psrc2 = (ushort*)_psrc2;
var pdest = (ushort*)_pdest;
@@ -360,7 +369,7 @@ namespace OpenRA.FileFormats
uint g2_len_x2, len_diff;
unsafe
{
fixed( uint* g1 = &glob1[0])
fixed (uint* g1 = &glob1[0])
fixed (uint* g2 = &glob2[0])
{
mul_bignum(glob2, n2, n3, len);
@@ -383,13 +392,15 @@ namespace OpenRA.FileFormats
mul_bignum_word(esi, glob1, tmp, 2 * len);
if ((*edi & 0x8000) == 0)
{
if (0 != sub_bignum((uint*)esi, (uint*)esi, g1, 0, (int)len)) (*edi)--;
if (0 != sub_bignum((uint*)esi, (uint*)esi, g1, 0, (int)len))(*edi)--;
}
}
}
neg_bignum(glob2, len);
dec_bignum(glob2, len);
}
mov_bignum(n1, glob2, len);
}
}
@@ -437,6 +448,7 @@ namespace OpenRA.FileFormats
bit_mask = 0x80000000;
pn3--;
}
calc_a_bignum(n_tmp, n1, n1, n4_len);
if ((*pn3 & bit_mask) != 0)
calc_a_bignum(n1, n_tmp, n2, n4_len);
@@ -444,6 +456,7 @@ namespace OpenRA.FileFormats
mov_bignum(n1, n_tmp, n4_len);
bit_mask >>= 1;
}
init_bignum(n_tmp, 0, n4_len);
clear_tmp_vars(len);
}
@@ -455,7 +468,7 @@ namespace OpenRA.FileFormats
while (len-- != 0) *dest++ = *src++;
}
unsafe void process_predata(byte* pre, uint pre_len, byte *buf)
unsafe void process_predata(byte* pre, uint pre_len, byte* buf)
{
var n2 = new uint[64];
var n3 = new uint[64];
@@ -464,12 +477,12 @@ namespace OpenRA.FileFormats
while (a + 1 <= pre_len)
{
init_bignum(n2, 0, 64);
fixed( uint * pn2 = &n2[0] )
memcpy((byte *)pn2, pre, (int)a + 1);
fixed (uint* pn2 = &n2[0])
memcpy((byte*)pn2, pre, (int)a + 1);
calc_a_key(n3, n2, pubkey.key2, pubkey.key1, 64);
fixed( uint * pn3 = &n3[0] )
memcpy(buf, (byte *)pn3, (int)a);
fixed (uint* pn3 = &n3[0])
memcpy(buf, (byte*)pn3, (int)a);
pre_len -= a + 1;
pre += a + 1;
@@ -488,6 +501,7 @@ namespace OpenRA.FileFormats
fixed (byte* psrc = &src[0])
process_predata(psrc, len_predata(), pdest);
}
return dest.Take(56).ToArray();
}
}

View File

@@ -10,7 +10,6 @@
namespace OpenRA.FileFormats
{
/// <summary>
/// Static class that uses a lookup table to calculates CRC32
/// checksums of input strings.
@@ -104,6 +103,7 @@ namespace OpenRA.FileFormats
crc ^= polynomial;
return crc;
}
public static uint Calculate(byte[] data)
{
return Calculate(data, 0xFFFFFFFF);
@@ -125,6 +125,7 @@ namespace OpenRA.FileFormats
crc ^= polynomial;
return crc;
}
public static unsafe uint Calculate(byte* data, uint len)
{
return Calculate(data, len, 0xFFFFFFFF);

View File

@@ -50,7 +50,7 @@ namespace OpenRA.FileFormats
if ((count & 0x8000) == 0)
{
// case 2
destIndex += (count & 0x7FFF);
destIndex += count & 0x7FFF;
}
else if ((count & 0x4000) == 0)
{

View File

@@ -22,20 +22,20 @@ namespace OpenRA.FileFormats
public HvaReader(Stream s)
{
// Index swaps for transposing a matrix
var ids = new byte[]{0,4,8,12,1,5,9,13,2,6,10,14};
var ids = new byte[] { 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14 };
s.Seek(16, SeekOrigin.Begin);
FrameCount = s.ReadUInt32();
LimbCount = s.ReadUInt32();
// Skip limb names
s.Seek(16*LimbCount, SeekOrigin.Current);
Transforms = new float[16*FrameCount*LimbCount];
s.Seek(16 * LimbCount, SeekOrigin.Current);
Transforms = new float[16 * FrameCount * LimbCount];
for (var j = 0; j < FrameCount; j++)
for (var i = 0; i < LimbCount; i++)
{
// Convert to column-major matrices and add the final matrix row
var c = 16*(LimbCount*j + i);
var c = 16 * (LimbCount * j + i);
Transforms[c + 3] = 0;
Transforms[c + 7] = 0;
Transforms[c + 11] = 0;

View File

@@ -41,7 +41,7 @@ namespace OpenRA.FileFormats
Color[] palette = null;
var data = new List<byte>();
for (; ; )
for (;;)
{
var length = IPAddress.NetworkToHostOrder(br.ReadInt32());
var type = Encoding.UTF8.GetString(br.ReadBytes(4));
@@ -54,7 +54,6 @@ namespace OpenRA.FileFormats
{
case "IHDR":
{
var width = IPAddress.NetworkToHostOrder(cr.ReadInt32());
var height = IPAddress.NetworkToHostOrder(cr.ReadInt32());
var bitDepth = cr.ReadByte();
@@ -67,8 +66,8 @@ namespace OpenRA.FileFormats
if (interlace != 0) throw new InvalidDataException("Interlacing not supported");
bitmap = new Bitmap(width, height, MakePixelFormat(bitDepth, colorType));
}
break;
case "PLTE":
@@ -80,6 +79,7 @@ namespace OpenRA.FileFormats
palette[i] = Color.FromArgb(r, g, b);
}
}
break;
case "tRNS":
@@ -87,12 +87,14 @@ namespace OpenRA.FileFormats
for (var i = 0; i < length; i++)
palette[i] = Color.FromArgb(cr.ReadByte(), palette[i]);
}
break;
case "IDAT":
{
data.AddRange(content);
}
break;
case "IEND":
@@ -168,8 +170,8 @@ namespace OpenRA.FileFormats
}
[Flags]
enum PngColorType { Indexed = 1, Color = 2, Alpha = 4 };
enum PngFilter { None, Sub, Up, Average, Paeth };
enum PngColorType { Indexed = 1, Color = 2, Alpha = 4 }
enum PngFilter { None, Sub, Up, Average, Paeth }
static PixelFormat MakePixelFormat(byte bitDepth, PngColorType colorType)
{

View File

@@ -42,11 +42,11 @@ namespace OpenRA.FileFormats
static void ReadVoxelData(Stream s, VxlLimb l)
{
var baseSize = l.Size[0]*l.Size[1];
var baseSize = l.Size[0] * l.Size[1];
var colStart = new int[baseSize];
for (var i = 0; i < baseSize; i++)
colStart[i] = s.ReadInt32();
s.Seek(4*baseSize, SeekOrigin.Current);
s.Seek(4 * baseSize, SeekOrigin.Current);
var dataStart = s.Position;
// Count the voxels in this limb
@@ -65,12 +65,12 @@ namespace OpenRA.FileFormats
var count = s.ReadUInt8();
z += count;
l.VoxelCount += count;
s.Seek(2*count + 1, SeekOrigin.Current);
s.Seek(2 * count + 1, SeekOrigin.Current);
} while (z < l.Size[2]);
}
// Read the data
l.VoxelMap = new Dictionary<byte, VxlElement>[l.Size[0],l.Size[1]];
l.VoxelMap = new Dictionary<byte, VxlElement>[l.Size[0], l.Size[1]];
for (var i = 0; i < baseSize; i++)
{
// Empty column
@@ -82,7 +82,7 @@ namespace OpenRA.FileFormats
var x = (byte)(i % l.Size[0]);
var y = (byte)(i / l.Size[0]);
byte z = 0;
l.VoxelMap[x,y] = new Dictionary<byte, VxlElement>();
l.VoxelMap[x, y] = new Dictionary<byte, VxlElement>();
do
{
z += s.ReadUInt8();
@@ -93,9 +93,10 @@ namespace OpenRA.FileFormats
v.Color = s.ReadUInt8();
v.Normal = s.ReadUInt8();
l.VoxelMap[x,y].Add(z, v);
l.VoxelMap[x, y].Add(z, v);
z++;
}
// Skip duplicate count
s.ReadUInt8();
} while (z < l.Size[2]);
@@ -104,7 +105,6 @@ namespace OpenRA.FileFormats
public VxlReader(Stream s)
{
if (!s.ReadASCII(16).StartsWith("Voxel Animation"))
throw new InvalidDataException("Invalid vxl header");
@@ -124,7 +124,7 @@ namespace OpenRA.FileFormats
}
// Skip to the Limb footers
s.Seek(802 + 28*LimbCount + BodySize, SeekOrigin.Begin);
s.Seek(802 + 28 * LimbCount + BodySize, SeekOrigin.Begin);
var LimbDataOffset = new uint[LimbCount];
for (var i = 0; i < LimbCount; i++)
@@ -143,7 +143,7 @@ namespace OpenRA.FileFormats
for (var i = 0; i < LimbCount; i++)
{
s.Seek(802 + 28*LimbCount + LimbDataOffset[i], SeekOrigin.Begin);
s.Seek(802 + 28 * LimbCount + LimbDataOffset[i], SeekOrigin.Begin);
ReadVoxelData(s, Limbs[i]);
}
}

View File

@@ -30,7 +30,7 @@ namespace OpenRA.FileFormats
public readonly int DataSize;
public readonly byte[] RawOutput;
public enum WaveType { Pcm = 0x1, ImaAdpcm = 0x11 };
public enum WaveType { Pcm = 0x1, ImaAdpcm = 0x11 }
public static WaveType Type { get; private set; }
public WavLoader(Stream s)
@@ -69,6 +69,7 @@ namespace OpenRA.FileFormats
UncompressedSize = s.ReadInt32();
s.ReadBytes(chunkSize - 4);
}
break;
case "data":
DataSize = s.ReadInt32();
@@ -80,6 +81,7 @@ namespace OpenRA.FileFormats
var chunkSize = s.ReadInt32();
s.ReadBytes(chunkSize);
}
break;
}
}

View File

@@ -34,7 +34,7 @@ namespace OpenRA.FileFormats
entries.Add(new string(chars.ToArray()));
// Skip comment
while ((c = reader.ReadChar()) != 0);
while ((c = reader.ReadChar()) != 0) { }
}
}

View File

@@ -47,9 +47,9 @@ namespace OpenRA.FileFormats
using (var writer = new BinaryWriter(data))
{
writer.Write(Encoding.ASCII.GetBytes("XCC by Olaf van der Spek"));
writer.Write(new byte[] {0x1A,0x04,0x17,0x27,0x10,0x19,0x80,0x00});
writer.Write(new byte[] { 0x1A, 0x04, 0x17, 0x27, 0x10, 0x19, 0x80, 0x00 });
writer.Write((int)(Entries.Aggregate(Entries.Length, (a,b) => a + b.Length) + 52)); // Size
writer.Write((int)(Entries.Aggregate(Entries.Length, (a, b) => a + b.Length) + 52)); // Size
writer.Write((int)0); // Type
writer.Write((int)0); // Version
writer.Write((int)0); // Game/Format (0 == TD)
@@ -64,4 +64,4 @@ namespace OpenRA.FileFormats
return data.ToArray();
}
}
}
}