Enable BHI1001 and fix noncompliance

"Do not use anonymous delegates"
This commit is contained in:
YoshiRulz 2022-07-14 02:52:03 +10:00
parent 395aa0755b
commit 056db314d4
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
15 changed files with 61 additions and 120 deletions

View File

@ -2,7 +2,7 @@
<RuleSet Name="BizHawk Rules" Description="Applies to all projects in the solution -- or, it will eventually." ToolsVersion="14.0">
<Rules AnalyzerId="BizHawk.Analyzer" RuleNamespace="BizHawk.Analyzer">
<!-- Do not use anonymous delegates -->
<Rule Id="BHI1001" Action="Hidden" />
<Rule Id="BHI1001" Action="Error" />
<!-- Do not use anonymous types (classes) -->
<Rule Id="BHI1002" Action="Hidden" />

View File

@ -156,7 +156,7 @@ namespace BizHawk.Client.Common
protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
{
bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.Movieheader, abort: true, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
@ -176,7 +176,7 @@ namespace BizHawk.Client.Common
}
});
bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.Input, abort: true, tr =>
{
IsCountingRerecords = false;
ExtractInputLog(tr, out _);
@ -188,7 +188,7 @@ namespace BizHawk.Client.Common
return;
}
bl.GetLump(BinaryStateLump.Comments, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.Comments, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
@ -200,7 +200,7 @@ namespace BizHawk.Client.Common
}
});
bl.GetLump(BinaryStateLump.Subtitles, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.Subtitles, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
@ -214,7 +214,7 @@ namespace BizHawk.Client.Common
Subtitles.Sort();
});
bl.GetLump(BinaryStateLump.SyncSettings, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.SyncSettings, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
@ -229,16 +229,10 @@ namespace BizHawk.Client.Common
if (StartsFromSavestate)
{
bl.GetCoreState(
delegate(BinaryReader br, long length)
{
BinarySavestate = br.ReadBytes((int)length);
},
delegate(TextReader tr)
{
TextSavestate = tr.ReadToEnd();
});
(br, length) => BinarySavestate = br.ReadBytes((int) length),
tr => TextSavestate = tr.ReadToEnd());
bl.GetLump(BinaryStateLump.Framebuffer, false,
delegate(BinaryReader br, long length)
(br, length) =>
{
SavestateFramebuffer = new int[length / sizeof(int)];
for (int i = 0; i < SavestateFramebuffer.Length; i++)
@ -250,10 +244,7 @@ namespace BizHawk.Client.Common
else if (StartsFromSaveRam)
{
bl.GetLump(BinaryStateLump.MovieSaveRam, false,
delegate(BinaryReader br, long length)
{
SaveRam = br.ReadBytes((int)length);
});
(br, length) => SaveRam = br.ReadBytes((int) length));
}
}
}

View File

@ -123,7 +123,7 @@ namespace BizHawk.Client.Common
var nusertext = new IndexedStateLump(BinaryStateLump.BranchUserText);
foreach (var b in this)
{
bs.PutLump(nheader, delegate(TextWriter tw)
bs.PutLump(nheader, tw =>
{
// if this header needs more stuff in it, handle it sensibly
tw.WriteLine(JsonConvert.SerializeObject(new
@ -134,12 +134,9 @@ namespace BizHawk.Client.Common
}));
});
bs.PutLump(ncore, delegate(Stream s)
{
s.Write(b.CoreData, 0, b.CoreData.Length);
});
bs.PutLump(ncore, (Stream s) => s.Write(b.CoreData, 0, b.CoreData.Length));
bs.PutLump(ninput, delegate(TextWriter tw)
bs.PutLump(ninput, tw =>
{
int todo = b.InputLog.Count;
for (int i = 0; i < todo; i++)
@ -148,27 +145,21 @@ namespace BizHawk.Client.Common
}
});
bs.PutLump(nframebuffer, delegate(Stream s)
bs.PutLump(nframebuffer, s =>
{
var vp = new BitmapBufferVideoProvider(b.OSDFrameBuffer);
_quickBmpFile.Save(vp, s, b.OSDFrameBuffer.Width, b.OSDFrameBuffer.Height);
});
bs.PutLump(ncoreframebuffer, delegate(Stream s)
bs.PutLump(ncoreframebuffer, s =>
{
var vp = new BitmapBufferVideoProvider(b.CoreFrameBuffer);
_quickBmpFile.Save(vp, s, b.CoreFrameBuffer.Width, b.CoreFrameBuffer.Height);
});
bs.PutLump(nmarkers, delegate(TextWriter tw)
{
tw.WriteLine(b.Markers.ToString());
});
bs.PutLump(nmarkers, tw => tw.WriteLine(b.Markers.ToString()));
bs.PutLump(nusertext, delegate(TextWriter tw)
{
tw.WriteLine(b.UserText);
});
bs.PutLump(nusertext, tw => tw.WriteLine(b.UserText));
nheader.Increment();
ncore.Increment();
@ -196,7 +187,7 @@ namespace BizHawk.Client.Common
{
var b = new TasBranch();
if (!bl.GetLump(nheader, false, delegate(TextReader tr)
if (!bl.GetLump(nheader, abort: false, tr =>
{
var header = (dynamic)JsonConvert.DeserializeObject(tr.ReadLine());
b.Frame = (int)header.Frame;
@ -226,13 +217,13 @@ namespace BizHawk.Client.Common
return;
}
bl.GetLump(ncore, true, delegate(Stream s, long length)
bl.GetLump(ncore, abort: true, (Stream s, long length) =>
{
b.CoreData = new byte[length];
s.Read(b.CoreData, 0, b.CoreData.Length);
});
bl.GetLump(ninput, true, delegate(TextReader tr)
bl.GetLump(ninput, abort: true, tr =>
{
b.InputLog = StringLogUtil.MakeStringLog();
string line;
@ -242,20 +233,20 @@ namespace BizHawk.Client.Common
}
});
bl.GetLump(nframebuffer, true, delegate(Stream s, long length)
bl.GetLump(nframebuffer, abort: true, (s, _) =>
{
_quickBmpFile.LoadAuto(s, out var vp);
b.OSDFrameBuffer = new BitmapBuffer(vp.BufferWidth, vp.BufferHeight, vp.GetVideoBuffer());
});
bl.GetLump(ncoreframebuffer, false, delegate(Stream s, long length)
bl.GetLump(ncoreframebuffer, abort: false, (s, _) =>
{
_quickBmpFile.LoadAuto(s, out var vp);
b.CoreFrameBuffer = new BitmapBuffer(vp.BufferWidth, vp.BufferHeight, vp.GetVideoBuffer());
});
b.Markers = new TasMovieMarkerList(movie);
bl.GetLump(nmarkers, false, delegate(TextReader tr)
bl.GetLump(nmarkers, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
@ -267,7 +258,7 @@ namespace BizHawk.Client.Common
}
});
bl.GetLump(nusertext, false, delegate(TextReader tr)
bl.GetLump(nusertext, abort: false, tr =>
{
string line;
if ((line = tr.ReadLine()) != null)

View File

@ -81,12 +81,9 @@ namespace BizHawk.Client.Common
private void LoadTasprojExtras(ZipStateLoader bl)
{
bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr)
{
LagLog.Load(tr);
});
bl.GetLump(BinaryStateLump.LagLog, abort: false, tr => LagLog.Load(tr));
bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.Markers, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
@ -101,7 +98,7 @@ namespace BizHawk.Client.Common
if (GetClientSettingsOnLoad != null)
{
string clientSettings = "";
bl.GetLump(BinaryStateLump.ClientSettings, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.ClientSettings, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
@ -119,7 +116,7 @@ namespace BizHawk.Client.Common
}
}
bl.GetLump(BinaryStateLump.VerificationLog, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.VerificationLog, abort: false, tr =>
{
VerificationLog.Clear();
while (true)
@ -139,7 +136,7 @@ namespace BizHawk.Client.Common
Branches.Load(bl, this);
bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.Session, abort: false, tr =>
{
var json = tr.ReadToEnd();
try
@ -153,7 +150,7 @@ namespace BizHawk.Client.Common
});
ZwinderStateManagerSettings settings = new ZwinderStateManagerSettings();
bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.StateHistorySettings, abort: false, tr =>
{
var json = tr.ReadToEnd();
try
@ -166,7 +163,7 @@ namespace BizHawk.Client.Common
}
});
bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length)
bl.GetLump(BinaryStateLump.StateHistory, abort: false, (br, _) =>
{
try
{

View File

@ -97,7 +97,7 @@ namespace BizHawk.Client.Common
if (_movieSession.Movie.IsActive())
{
bs.PutLump(BinaryStateLump.Input,
delegate(TextWriter tw)
tw =>
{
// this never should have been a core's responsibility
tw.WriteLine("Frame {0}", _emulator.Frame);
@ -108,7 +108,7 @@ namespace BizHawk.Client.Common
if (_userBag.Any())
{
bs.PutLump(BinaryStateLump.UserData,
delegate(TextWriter tw)
tw =>
{
var data = ConfigService.SaveWithType(_userBag);
tw.WriteLine(data);
@ -117,11 +117,7 @@ namespace BizHawk.Client.Common
if (_movieSession.Movie.IsActive() && _movieSession.Movie is ITasMovie)
{
bs.PutLump(BinaryStateLump.LagLog,
delegate(TextWriter tw)
{
((ITasMovie)_movieSession.Movie).LagLog.Save(tw);
});
bs.PutLump(BinaryStateLump.LagLog, tw => ((ITasMovie) _movieSession.Movie).LagLog.Save(tw));
}
}
@ -177,7 +173,7 @@ namespace BizHawk.Client.Common
}
string userData = "";
bl.GetLump(BinaryStateLump.UserData, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.UserData, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
@ -198,10 +194,7 @@ namespace BizHawk.Client.Common
if (_movieSession.Movie.IsActive() && _movieSession.Movie is ITasMovie)
{
bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr)
{
((ITasMovie)_movieSession.Movie).LagLog.Load(tr);
});
bl.GetLump(BinaryStateLump.LagLog, abort: false, tr => ((ITasMovie) _movieSession.Movie).LagLog.Load(tr));
}
return true;

View File

@ -123,31 +123,13 @@ namespace BizHawk.Client.Common
}
public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader> callback)
{
return GetLump(lump, abort, delegate(Stream s, long unused)
{
var br = new BinaryReader(s);
callback(br);
});
}
=> GetLump(lump, abort, (s, _) => callback(new(s)));
public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader, long> callback)
{
return GetLump(lump, abort, delegate(Stream s, long length)
{
var br = new BinaryReader(s);
callback(br, length);
});
}
=> GetLump(lump, abort, (s, length) => callback(new(s), length));
public bool GetLump(BinaryStateLump lump, bool abort, Action<TextReader> callback)
{
return GetLump(lump, abort, delegate(Stream s, long unused)
{
var tr = new StreamReader(s);
callback(tr);
});
}
=> GetLump(lump, abort, (s, _) => callback(new StreamReader(s)));
/// <exception cref="Exception">couldn't find Binary or Text savestate</exception>
public void GetCoreState(Action<BinaryReader, long> callbackBinary, Action<TextReader> callbackText)

View File

@ -42,7 +42,7 @@ namespace BizHawk.Client.Common
public void PutLump(BinaryStateLump lump, Action<BinaryWriter> callback)
{
PutLump(lump, delegate(Stream s)
PutLump(lump, s =>
{
var bw = new BinaryWriter(s);
callback(bw);
@ -52,7 +52,7 @@ namespace BizHawk.Client.Common
public void PutLump(BinaryStateLump lump, Action<TextWriter> callback)
{
PutLump(lump, delegate(Stream s)
PutLump(lump, s =>
{
TextWriter tw = new StreamWriter(s);
callback(tw);

View File

@ -87,10 +87,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME
var name = $"{ deviceName } : { read } : 0x{ firstOffset:X}-0x{ lastOffset:X}";
domains.Add(new MemoryDomainDelegate(name, lastOffset - firstOffset + 1, endian,
delegate (long addr)
{
return _peek(addr, firstOffset, size);
},
addr => _peek(addr, firstOffset, size),
read == "rom"
? null
: (long addr, byte val) => _poke(addr, val, firstOffset, size),
@ -99,10 +96,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME
}
domains.Add(new MemoryDomainDelegate(deviceName + " : System Bus", size, endian,
delegate (long addr)
{
return _peek(addr, 0, size);
},
addr => _peek(addr, 0, size),
null, dataWidth));
_memoryDomains = new MemoryDomainList(domains);

View File

@ -26,15 +26,8 @@ namespace BizHawk.Emulation.Cores.Components.H6280
string dis = DisassembleExt(
0,
out unused,
delegate(ushort addr)
{
return md.PeekByte(addr + i);
},
delegate(ushort addr)
{
return md.PeekUshort(addr + i, false);
}
);
addr => md.PeekByte(addr + i),
addr => md.PeekUshort(addr + i, bigEndian: false));
w.WriteLine("0x{0:x8}: {1}", i, dis);
}
}

View File

@ -31,7 +31,7 @@ namespace BizHawk.Emulation.Cores.Calculators.Emu83
CreateMemoryDomain(LibEmu83.MemoryArea_t.MEM_VRAM, "VRAM");
_memoryDomains.Add(new MemoryDomainDelegate("System Bus", 0x10000, MemoryDomain.Endian.Little,
delegate(long addr)
addr =>
{
if (addr < 0 || addr >= 0x10000)
{
@ -40,7 +40,7 @@ namespace BizHawk.Emulation.Cores.Calculators.Emu83
return LibEmu83.TI83_ReadMemory(Context, (ushort)addr);
},
delegate(long addr, byte val)
(addr, val) =>
{
if (addr < 0 || addr >= 0x10000)
{

View File

@ -38,7 +38,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
mm.Add(_cwram = new MemoryDomainDelegate("Combined WRAM", (256 + 32) * 1024, le, null, null, 4));
mm.Add(new MemoryDomainDelegate("System Bus", 0x10000000, le,
delegate (long addr)
addr =>
{
var a = (uint)addr;
if (a >= 0x10000000)
@ -48,7 +48,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA
return LibmGBA.BizReadBus(Core, a);
},
delegate (long addr, byte val)
(addr, val) =>
{
var a = (uint)addr;
if (a >= 0x10000000)

View File

@ -37,7 +37,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
// also add a special memory domain for the system bus, where calls get sent directly to the core each time
_memoryDomains.Add(new MemoryDomainDelegate("System Bus", 65536, MemoryDomain.Endian.Little,
delegate(long addr)
addr =>
{
if (addr < 0 || addr >= 65536)
{
@ -46,7 +46,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Gameboy
return LibGambatte.gambatte_cpuread(GambatteState, (ushort)addr);
},
delegate(long addr, byte val)
(addr, val) =>
{
if (addr < 0 || addr >= 65536)
{

View File

@ -32,7 +32,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
"System Bus",
0x10000,
MemoryDomain.Endian.Unknown,
delegate(long addr)
addr =>
{
if (addr < 0 || addr >= 0x10000)
{
@ -41,7 +41,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES
return QN.qn_peek_prgbus(Context, (int)addr);
},
delegate(long addr, byte val)
(addr, val) =>
{
if (addr < 0 || addr >= 0x10000)
{

View File

@ -44,7 +44,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Sameboy
// also add a special memory domain for the system bus, where calls get sent directly to the core each time
_memoryDomains.Add(new MemoryDomainDelegate("System Bus", 65536, MemoryDomain.Endian.Little,
delegate(long addr)
addr =>
{
if (addr < 0 || addr >= 65536)
{
@ -53,7 +53,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Sameboy
return LibSameboy.sameboy_cpuread(SameboyState, (ushort)addr);
},
delegate(long addr, byte val)
(addr, val) =>
{
if (addr < 0 || addr >= 65536)
{

View File

@ -34,14 +34,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
// vram pokes need to go through hook which invalidates cached tiles
byte* p = (byte*)area;
mm.Add(new MemoryDomainDelegate(name, size, MemoryDomain.Endian.Unknown,
delegate (long addr)
addr =>
{
if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException();
using (_elf.EnterExit())
return p[addr ^ 1];
},
delegate (long addr, byte val)
(addr, val) =>
{
if (addr < 0 || addr >= 65536)
throw new ArgumentOutOfRangeException();
@ -59,14 +59,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
}
}
var m68Bus = new MemoryDomainDelegate("M68K BUS", 0x1000000, MemoryDomain.Endian.Big,
delegate (long addr)
addr =>
{
var a = (uint)addr;
if (a >= 0x1000000)
throw new ArgumentOutOfRangeException();
return Core.gpgx_peek_m68k_bus(a);
},
delegate (long addr, byte val)
(addr, val) =>
{
var a = (uint)addr;
if (a >= 0x1000000)
@ -79,14 +79,14 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx
if (IsMegaCD)
{
var s68Bus = new MemoryDomainDelegate("S68K BUS", 0x1000000, MemoryDomain.Endian.Big,
delegate (long addr)
addr =>
{
var a = (uint)addr;
if (a >= 0x1000000)
throw new ArgumentOutOfRangeException();
return Core.gpgx_peek_s68k_bus(a);
},
delegate (long addr, byte val)
(addr, val) =>
{
var a = (uint)addr;
if (a >= 0x1000000)