Fix IDE0055

This rule no longer appears to be buggy, so enforce it. Some of the automated fixes are adjusted in order to improve the result. #pragma directives have no option to control indentation, so remove them where possible.
This commit is contained in:
RoosterDragon
2023-11-09 19:56:52 +00:00
committed by Pavel Penev
parent 60cbf79c9b
commit 360f24f609
58 changed files with 719 additions and 714 deletions

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Cnc.Activities
// The target may become hidden between the initial order request and the first tick (e.g. if queued)
// Moving to any position (even if quite stale) is still better than immediately giving up
if ((target.Type == TargetType.Actor && target.Actor.CanBeViewedByPlayer(self.Owner))
|| target.Type == TargetType.FrozenActor || target.Type == TargetType.Terrain)
|| target.Type == TargetType.FrozenActor || target.Type == TargetType.Terrain)
{
lastVisibleTarget = Target.FromPos(target.CenterPosition);
lastVisibleMinRange = attack.GetMinimumRangeVersusTarget(target);

View File

@@ -171,53 +171,53 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
{
// Sound data
case 1:
{
if (block.Length < 2)
throw new InvalidDataException("Invalid sound data block length in voc file");
var freqDiv = stream.ReadUInt8();
block.SampleBlock.Rate = GetSampleRateFromVocRate(freqDiv);
var codec = stream.ReadUInt8();
if (codec != 0)
throw new InvalidDataException("Unhandled codec used in voc file");
skip = block.Length - 2;
block.SampleBlock.Samples = skip;
block.SampleBlock.Offset = stream.Position;
// See if last block contained additional information
if (blockList.Count > 0)
{
if (block.Length < 2)
throw new InvalidDataException("Invalid sound data block length in voc file");
var freqDiv = stream.ReadUInt8();
block.SampleBlock.Rate = GetSampleRateFromVocRate(freqDiv);
var codec = stream.ReadUInt8();
if (codec != 0)
throw new InvalidDataException("Unhandled codec used in voc file");
skip = block.Length - 2;
block.SampleBlock.Samples = skip;
block.SampleBlock.Offset = stream.Position;
// See if last block contained additional information
if (blockList.Count > 0)
var b = blockList.Last();
if (b.Code == 8)
{
var b = blockList.Last();
if (b.Code == 8)
{
block.SampleBlock.Rate = b.SampleBlock.Rate;
blockList.Remove(b);
}
block.SampleBlock.Rate = b.SampleBlock.Rate;
blockList.Remove(b);
}
sampleRate = Math.Max(sampleRate, block.SampleBlock.Rate);
break;
}
sampleRate = Math.Max(sampleRate, block.SampleBlock.Rate);
break;
}
// Silence
case 3:
{
if (block.Length != 3)
throw new InvalidDataException("Invalid silence block length in voc file");
block.SampleBlock.Offset = 0;
block.SampleBlock.Samples = stream.ReadUInt16() + 1;
var freqDiv = stream.ReadUInt8();
block.SampleBlock.Rate = GetSampleRateFromVocRate(freqDiv);
break;
}
{
if (block.Length != 3)
throw new InvalidDataException("Invalid silence block length in voc file");
block.SampleBlock.Offset = 0;
block.SampleBlock.Samples = stream.ReadUInt16() + 1;
var freqDiv = stream.ReadUInt8();
block.SampleBlock.Rate = GetSampleRateFromVocRate(freqDiv);
break;
}
// Repeat start
case 6:
{
if (block.Length != 2)
throw new InvalidDataException("Invalid repeat start block length in voc file");
block.LoopBlock.Count = stream.ReadUInt16() + 1;
break;
}
{
if (block.Length != 2)
throw new InvalidDataException("Invalid repeat start block length in voc file");
block.LoopBlock.Count = stream.ReadUInt16() + 1;
break;
}
// Repeat end
case 7:
@@ -225,23 +225,23 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
// Extra info
case 8:
{
if (block.Length != 4)
throw new InvalidDataException("Invalid info block length in voc file");
int freqDiv = stream.ReadUInt16();
if (freqDiv == 65536)
throw new InvalidDataException("Invalid frequency divisor 65536 in voc file");
var codec = stream.ReadUInt8();
if (codec != 0)
throw new InvalidDataException("Unhandled codec used in voc file");
var channels = stream.ReadUInt8() + 1;
if (channels != 1)
throw new InvalidDataException("Unhandled number of channels in voc file");
block.SampleBlock.Offset = 0;
block.SampleBlock.Samples = 0;
block.SampleBlock.Rate = (int)(256000000L / (65536L - freqDiv));
break;
}
{
if (block.Length != 4)
throw new InvalidDataException("Invalid info block length in voc file");
int freqDiv = stream.ReadUInt16();
if (freqDiv == 65536)
throw new InvalidDataException("Invalid frequency divisor 65536 in voc file");
var codec = stream.ReadUInt8();
if (codec != 0)
throw new InvalidDataException("Unhandled codec used in voc file");
var channels = stream.ReadUInt8() + 1;
if (channels != 1)
throw new InvalidDataException("Unhandled number of channels in voc file");
block.SampleBlock.Offset = 0;
block.SampleBlock.Samples = 0;
block.SampleBlock.Rate = (int)(256000000L / (65536L - freqDiv));
break;
}
// Sound data (New format)
case 9:

View File

@@ -251,9 +251,7 @@ namespace OpenRA.Mods.Cnc.FileFormats
*op++ = *ip++;
if (t > 2)
{
#pragma warning disable IDE0047
(*op++) = *ip++;
#pragma warning restore IDE0047
*op++ = *ip++;
}
}

View File

@@ -68,13 +68,13 @@ namespace OpenRA.Mods.Cnc.FileFormats
// Decode FORM chunk
if (stream.ReadASCII(4) != "FORM")
throw new InvalidDataException("Invalid vqa (invalid FORM section)");
/*var length = */stream.ReadUInt32();
stream.ReadUInt32(); // length
if (stream.ReadASCII(8) != "WVQAVQHD")
throw new InvalidDataException("Invalid vqa (not WVQAVQHD)");
/*var length2 = */stream.ReadUInt32();
stream.ReadUInt32(); // length2
/*var version = */stream.ReadUInt16();
stream.ReadUInt16(); // version
videoFlags = stream.ReadUInt16();
FrameCount = stream.ReadUInt16();
Width = stream.ReadUInt16();
@@ -87,20 +87,20 @@ namespace OpenRA.Mods.Cnc.FileFormats
blocks = new int2(Width / blockWidth, Height / blockHeight);
numColors = stream.ReadUInt16();
/*var maxBlocks = */stream.ReadUInt16();
/*var unknown1 = */stream.ReadUInt16();
/*var unknown2 = */stream.ReadUInt32();
stream.ReadUInt16(); // maxBlocks
stream.ReadUInt16(); // unknown1
stream.ReadUInt32(); // unknown2
// Audio
SampleRate = stream.ReadUInt16();
AudioChannels = stream.ReadUInt8();
SampleBits = stream.ReadUInt8();
/*var unknown3 =*/stream.ReadUInt32();
/*var unknown4 =*/stream.ReadUInt16();
/*maxCbfzSize =*/stream.ReadUInt32(); // Unreliable
stream.ReadUInt32(); // unknown3
stream.ReadUInt16(); // unknown4
stream.ReadUInt32(); // maxCbfzSize, unreliable
/*var unknown5 =*/stream.ReadUInt32();
stream.ReadUInt32(); // unknown5
if (IsHqVqa)
{
@@ -131,8 +131,8 @@ namespace OpenRA.Mods.Cnc.FileFormats
throw new NotSupportedException($"Vqa uses unknown Subtype: {type}");
}
/*var length = */stream.ReadUInt16();
/*var unknown4 = */stream.ReadUInt16();
stream.ReadUInt16(); // length
stream.ReadUInt16(); // unknown4
// Frame offsets
offsets = new uint[FrameCount];

View File

@@ -45,13 +45,13 @@ namespace OpenRA.Mods.Cnc.FileFormats
FrameCount = stream.ReadUInt16();
/*var x = */stream.ReadUInt16();
/*var y = */stream.ReadUInt16();
stream.ReadUInt16(); // x
stream.ReadUInt16(); // y
Width = stream.ReadUInt16();
Height = stream.ReadUInt16();
/*var delta = */stream.ReadUInt16(); /* + 37*/
stream.ReadUInt16(); // delta (+37)
var flags = stream.ReadUInt16();
frameOffsets = new uint[FrameCount + 2];

View File

@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
try
{
/* var signature = */ s.ReadASCII(4);
s.ReadASCII(4); // signature
// Total archive size.
s.ReadUInt32();

View File

@@ -113,7 +113,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
{
s.Seek(offset, SeekOrigin.Begin);
var numFiles = s.ReadUInt16();
/*uint dataSize = */s.ReadUInt32();
s.ReadUInt32(); // dataSize
var items = new List<PackageEntry>();
for (var i = 0; i < numFiles; i++)

View File

@@ -69,38 +69,38 @@ namespace OpenRA.Mods.Cnc.FileSystem
switch (type)
{
case PackageHashType.Classic:
{
for (var p = 0; p < padding; p++)
upperPaddedName[paddedLength - 1 - p] = '\0';
{
for (var p = 0; p < padding; p++)
upperPaddedName[paddedLength - 1 - p] = '\0';
var asciiBytes = paddedLength < 64 ? stackalloc byte[paddedLength] : new byte[paddedLength];
Encoding.ASCII.GetBytes(upperPaddedName, asciiBytes);
var asciiBytes = paddedLength < 64 ? stackalloc byte[paddedLength] : new byte[paddedLength];
Encoding.ASCII.GetBytes(upperPaddedName, asciiBytes);
var data = MemoryMarshal.Cast<byte, uint>(asciiBytes);
var result = 0u;
foreach (var next in data)
result = ((result << 1) | (result >> 31)) + next;
var data = MemoryMarshal.Cast<byte, uint>(asciiBytes);
var result = 0u;
foreach (var next in data)
result = ((result << 1) | (result >> 31)) + next;
return result;
}
return result;
}
case PackageHashType.CRC32:
{
var length = name.Length;
var lengthRoundedDownToFour = length / 4 * 4;
if (length != lengthRoundedDownToFour)
{
var length = name.Length;
var lengthRoundedDownToFour = length / 4 * 4;
if (length != lengthRoundedDownToFour)
{
upperPaddedName[length] = (char)(length - lengthRoundedDownToFour);
for (var p = 1; p < padding; p++)
upperPaddedName[length + p] = upperPaddedName[lengthRoundedDownToFour];
}
var asciiBytes = paddedLength < 64 ? stackalloc byte[paddedLength] : new byte[paddedLength];
Encoding.ASCII.GetBytes(upperPaddedName, asciiBytes);
return CRC32.Calculate(asciiBytes);
upperPaddedName[length] = (char)(length - lengthRoundedDownToFour);
for (var p = 1; p < padding; p++)
upperPaddedName[length + p] = upperPaddedName[lengthRoundedDownToFour];
}
var asciiBytes = paddedLength < 64 ? stackalloc byte[paddedLength] : new byte[paddedLength];
Encoding.ASCII.GetBytes(upperPaddedName, asciiBytes);
return CRC32.Calculate(asciiBytes);
}
default: throw new NotImplementedException($"Unknown hash type `{type}`");
}
}

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Cnc.Graphics
}
[Desc("A sprite sequence that can have tileset-specific variants and has the oddities " +
"that come with first-generation Westwood titles.")]
"that come with first-generation Westwood titles.")]
public class ClassicTilesetSpecificSpriteSequence : ClassicSpriteSequence
{
[Desc("Dictionary of <tileset name>: filename to override the Filename key.")]

View File

@@ -37,7 +37,8 @@ namespace OpenRA.Mods.Cnc.Graphics
: this(renderer, models, pos, zOffset, camera, scale,
lightSource, lightAmbientColor, lightDiffuseColor,
color, normals, shadow, 1f,
float3.Ones, TintModifiers.None) { }
float3.Ones, TintModifiers.None)
{ }
public ModelRenderable(
ModelRenderer renderer, IEnumerable<ModelAnimation> models, WPos pos, int zOffset, in WRot camera, float scale,

View File

@@ -172,26 +172,26 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
{
case Format.XORPrev:
case Format.XORLCW:
{
if (h.RefImage.Data == null)
{
if (h.RefImage.Data == null)
{
++recurseDepth;
Decompress(h.RefImage);
--recurseDepth;
}
h.Data = CopyImageData(h.RefImage.Data);
XORDeltaCompression.DecodeInto(shpBytes, h.Data, (int)(h.FileOffset - shpBytesFileOffset));
break;
++recurseDepth;
Decompress(h.RefImage);
--recurseDepth;
}
h.Data = CopyImageData(h.RefImage.Data);
XORDeltaCompression.DecodeInto(shpBytes, h.Data, (int)(h.FileOffset - shpBytesFileOffset));
break;
}
case Format.LCW:
{
var imageBytes = new byte[Size.Width * Size.Height];
LCWCompression.DecodeInto(shpBytes, imageBytes, (int)(h.FileOffset - shpBytesFileOffset));
h.Data = imageBytes;
break;
}
{
var imageBytes = new byte[Size.Width * Size.Height];
LCWCompression.DecodeInto(shpBytes, imageBytes, (int)(h.FileOffset - shpBytesFileOffset));
h.Data = imageBytes;
break;
}
default:
throw new InvalidDataException();

View File

@@ -196,18 +196,24 @@ namespace OpenRA.Mods.Cnc.Traits
}
public Activity MoveTo(CPos cell, int nearEnough = 0, Actor ignoreActor = null,
bool evaluateNearestMovableCell = false, Color? targetLineColor = null) { return null; }
bool evaluateNearestMovableCell = false, Color? targetLineColor = null)
{ return null; }
public Activity MoveWithinRange(in Target target, WDist range,
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{ return null; }
public Activity MoveWithinRange(in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{ return null; }
public Activity MoveFollow(Actor self, in Target target, WDist minRange, WDist maxRange,
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{ return null; }
public Activity ReturnToCell(Actor self) { return null; }
public Activity MoveToTarget(Actor self, in Target target,
WPos? initialTargetPosition = null, Color? targetLineColor = null) { return null; }
WPos? initialTargetPosition = null, Color? targetLineColor = null)
{ return null; }
public Activity MoveOntoTarget(Actor self, in Target target, in WVec offset,
WAngle? facing, Color? targetLineColor = null) { return null; }
WAngle? facing, Color? targetLineColor = null)
{ return null; }
public Activity MoveIntoTarget(Actor self, in Target target) { return null; }
public Activity LocalMove(Actor self, WPos fromPos, WPos toPos) { return null; }

View File

@@ -194,7 +194,7 @@ namespace OpenRA.Mods.Cnc.Traits
var correctionTransform = Util.MatrixMultiply(translateMtx, FlipMtx);
var shadowCorrectionTransform = Util.MatrixMultiply(shadowTranslateMtx, ShadowScaleFlipMtx);
doRender.Add((sprite.Sheet, () =>
void RenderFunc()
{
foreach (var m in models)
{
@@ -235,7 +235,9 @@ namespace OpenRA.Mods.Cnc.Traits
ShadowAmbient, ShadowDiffuse, shadowPalette.TextureIndex, normals.TextureIndex);
}
}
}));
}
doRender.Add((sprite.Sheet, RenderFunc));
var screenLightVector = Util.MatrixVectorMultiply(invShadowTransform, ZVector);
screenLightVector = Util.MatrixVectorMultiply(cameraTransform, screenLightVector);

View File

@@ -119,10 +119,10 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
var rx = mf.ReadUInt16();
var ry = mf.ReadUInt16();
var tilenum = mf.ReadUInt16();
/*var zero1 = */mf.ReadInt16();
mf.ReadInt16(); // zero1
var subtile = mf.ReadUInt8();
var z = mf.ReadUInt8();
/*var zero2 = */mf.ReadUInt8();
mf.ReadUInt8(); // zero2
var uv = ToMPos(rx, ry, fullSize.X);

View File

@@ -115,8 +115,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
var templateWidth = s.ReadUInt32();
var templateHeight = s.ReadUInt32();
/* var tileWidth = */s.ReadInt32();
/* var tileHeight = */s.ReadInt32();
s.ReadInt32(); // tileWidth
s.ReadInt32(); // tileHeight
var offsets = new uint[templateWidth * templateHeight];
for (var j = 0; j < offsets.Length; j++)
offsets[j] = s.ReadUInt32();

View File

@@ -40,15 +40,15 @@ namespace OpenRA.Mods.Cnc.VideoLoaders
if (frames <= 1) // TODO: find a better way to differentiate .shp icons
return false;
/* var x = */ s.ReadUInt16();
/* var y = */ s.ReadUInt16();
s.ReadUInt16(); // x
s.ReadUInt16(); // y
var width = s.ReadUInt16();
var height = s.ReadUInt16();
if (width <= 0 || height <= 0)
return false;
/*var delta = */ s.ReadUInt16(); /* + 37;*/
s.ReadUInt16(); // delta (+37)
var flags = s.ReadUInt16();
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Cnc.VideoLoaders
if (flags == 1)
{
/* var palette = */ s.ReadBytes(768);
s.ReadBytes(768); // palette
for (var i = 0; i < offsets.Length; i++)
offsets[i] += 768;
}