Skip to content

Commit

Permalink
implement IDE suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mzxrules committed Aug 30, 2021
1 parent 56e7fc1 commit 449bb30
Show file tree
Hide file tree
Showing 54 changed files with 459 additions and 583 deletions.
28 changes: 14 additions & 14 deletions Atom/DisassemblyTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class DisassemblyTask
{
public class SectionList
{
public List<Section> Values = new List<Section>();
public List<Section> Values = new();

public bool IsWithinCode(N64Ptr ptr)
{
Expand All @@ -29,17 +29,17 @@ public bool IsWithinCode(N64Ptr ptr)
public N64PtrRange VRam { get; protected set; }
public FileAddress VRom { get; protected set; }

public SectionList Sections = new SectionList();
public SectionList Sections = new();

public List<Overlay.RelocationWord> Relocations = new List<Overlay.RelocationWord>();
public List<Overlay.RelocationWord> Relocations = new();

//used for oot decomp
public N64PtrRange HeaderAndReloc { get; protected set; }

public bool SplitFunctions { get; protected set; }

public List<Label> Functions = new List<Label>();
public List<Action<Stream>> PreparseActions = new List<Action<Stream>>();
public List<Label> Functions = new();
public List<Action<Stream>> PreparseActions = new();


public enum OvlType
Expand Down Expand Up @@ -72,7 +72,7 @@ public static DisassemblyTask New(JFileInfo file)
foreach(var item in file.Sections)
{
var ram = item.Ram.Convert();
Section section = new Section(item.Name, task.VRam.Start, ram.Start, ram.Size, item.Subsection, item.IsCode);
Section section = new(item.Name, task.VRam.Start, ram.Start, ram.Size, item.Subsection, item.IsCode);
task.Sections.Values.Add(section);
}
return task;
Expand All @@ -83,7 +83,7 @@ private static DisassemblyTask New(List<JDmaData> dmadata, int index, OverlayRec
{
string name = GetTaskName(dmadata, index, ovlInfo, nameClass);

DisassemblyTask task = new DisassemblyTask()
DisassemblyTask task = new()
{
Name = name,
VRam = ovlInfo.VRam,
Expand All @@ -100,20 +100,20 @@ private static void OverlayPreprocess(DisassemblyTask task, Stream file, Overlay
var overlay = new Overlay();
if (ovlInfo.VRom.Size != 0)
{
BinaryReader br = new BinaryReader(file);
BinaryReader br = new(file);
overlay = new Overlay(br);
}
task.Relocations = overlay.Relocations;

N64Ptr fstart = task.VRam.Start;

Section text = new Section("text", fstart, fstart, overlay.TextSize, 0, true);
Section data = new Section("data", fstart, text.VRam + text.Size, overlay.DataSize, 0);
Section rodata = new Section("rodata", fstart, data.VRam + data.Size, overlay.RodataSize, 0);
Section text = new("text", fstart, fstart, overlay.TextSize, 0, true);
Section data = new("data", fstart, text.VRam + text.Size, overlay.DataSize, 0);
Section rodata = new("rodata", fstart, data.VRam + data.Size, overlay.RodataSize, 0);
long off = task.VRam.Start + task.VRom.Size;

task.HeaderAndReloc = new N64PtrRange(task.VRam.Start + overlay.header_offset, off);
Section bss = new Section("bss", fstart, off, overlay.BssSize, 0);
Section bss = new("bss", fstart, off, overlay.BssSize, 0);

task.Sections.Values.Add(text);
task.Sections.Values.Add(data);
Expand Down Expand Up @@ -153,7 +153,7 @@ private static void GetActorSymbolNames(DisassemblyTask task, Rom rom, ActorOver
private static void GetActorInfoSymbols(DisassemblyTask task, N64Ptr startAddr, N64Ptr vramActorInfo, Stream file)
{
file.Position = vramActorInfo - startAddr;
ActorInit actorInfo = new ActorInit(new BinaryReader(file));
ActorInit actorInfo = new(new BinaryReader(file));

BindSymbol(vramActorInfo, Label.Type.VAR, "InitVars");
BindSymbol(actorInfo.init_func, Label.Type.FUNC, "Init");
Expand All @@ -176,7 +176,7 @@ void BindSymbol(N64Ptr ptr, Label.Type type, string name)

public static List<DisassemblyTask> CreateTaskList(Rom rom)
{
List<DisassemblyTask> taskList = new List<DisassemblyTask>();
List<DisassemblyTask> taskList = new();
List<JDmaData> dmadata;

if (rom.Version.Game == Game.OcarinaOfTime)
Expand Down
8 changes: 4 additions & 4 deletions Atom/r4300/parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ internal static void DataDisassembly(StreamWriter sw, BinaryReader br, Section s
br.BaseStream.Position = section.Offset;
pc = section.VRam;

List<byte> byteChain = new List<byte>();
List<byte> byteChain = new();
N64Ptr end = section.VRam + section.Size;
N64Ptr chainStart = pc;
while (pc < end)
Expand Down Expand Up @@ -241,7 +241,7 @@ private static void DumpByteChain(StreamWriter outputf, N64Ptr chainStart, ref L

static string GetLineByte(List<byte> chain, int index, int count)
{
List<string> values = new List<string>();
List<string> values = new();
foreach (var item in chain.GetRange(index, count))
{
values.Add($"0x{item:X2}");
Expand All @@ -251,7 +251,7 @@ static string GetLineByte(List<byte> chain, int index, int count)

static string GetLineWord(List<byte> chain, int index, int count)
{
List<string> values = new List<string>();
List<string> values = new();
List<byte> items = chain.GetRange(index, count);
for (int i = 0; i < count; i += 4)
{
Expand Down Expand Up @@ -449,7 +449,7 @@ private static void InitRelocationLabels(BinaryReader br, DisassemblyTask task)

private static List<N64PtrRange> GetTextSectionRanges(DisassemblyTask task)
{
List<N64PtrRange> textSections = new List<N64PtrRange>();
List<N64PtrRange> textSections = new();
foreach (var section in task.Sections.Values.Where(x => x.IsCode))
{
textSections.Add(new N64PtrRange(section.VRam, section.VRam + section.Size));
Expand Down
8 changes: 4 additions & 4 deletions Experimental/Data/MMEntranceTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ static partial class Get
{
public static void MMEntranceTable(IExperimentFace face, List<string> file)
{
MRom rom = new MRom(file[0], MRom.Build.U0);
MRom rom = new(file[0], MRom.Build.U0);

//scenes (7 bits, 0x6E max)
//entrance sets (5 bits, 32 max)

//entrance setups(32 max)
StringBuilder sb = new StringBuilder();
StringBuilder sb = new();
RomFile code = rom.Files.GetFile(MRom.FileList.code);
BinaryReader br = new BinaryReader(code);
BinaryReader br = new(code);
int sceneBase;

//Sets of entrance records per scene
Expand All @@ -41,7 +41,7 @@ public static void MMEntranceTable(IExperimentFace face, List<string> file)
for (int scene = 0; scene < 0x6E; scene++)
{
//get offset of pointer to the entrance sets
entranceSetsPointerAddr = sceneBase + (sizeof(Int32) * 3) * scene + 4;
entranceSetsPointerAddr = sceneBase + (sizeof(int) * 3) * scene + 4;

//move the stream to the entrance sets pointer
br.BaseStream.Position = code.Record.GetRelativeAddress(entranceSetsPointerAddr);
Expand Down
58 changes: 27 additions & 31 deletions Experimental/Data/PartialCutscene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ class InCutsceneData

private int GetRamAddress()
{
_Scene s;
if (GetSceneDelegate == null ||
!GetSceneDelegate(scene, out s))
if (GetSceneDelegate != null &&
GetSceneDelegate(scene, out _Scene s))
{
return 0;
return s.RamStart + offset;
}
return s.RamStart + offset;
return 0;
}
public InCutsceneData(int scene, int setup, int offset)
{
Expand Down Expand Up @@ -91,7 +90,7 @@ public static void GetCutsceneExitAsm(IExperimentFace face, List<string> file)
{
List<InCutsceneData> cutsceneData;
Dictionary<int, _Scene> sceneInfo;
StringBuilder sb = new StringBuilder();
StringBuilder sb = new();
ORom rom;
string romLoc = file[0];

Expand Down Expand Up @@ -129,7 +128,7 @@ public static string GetPartialCutscene()
{
List<InCutsceneData> cutsceneData;
Dictionary<int, _Scene> sceneInfo;
StringBuilder sb = new StringBuilder();
StringBuilder sb = new();
ORom rom;
string romLoc = string.Empty;

Expand All @@ -146,11 +145,10 @@ public static string GetPartialCutscene()

InCutsceneData.GetSceneDelegate = sceneInfo.TryGetValue;

for (int sceneId = 0; sceneId < 101; sceneId++)// in sceneIdList)
for (int sceneId = 0; sceneId < 101; sceneId++)
{
_Scene scene;
RomFile file;
sceneInfo.TryGetValue(sceneId, out scene);
sceneInfo.TryGetValue(sceneId, out _Scene scene);
file = rom.Files.GetSceneFile(sceneId);

foreach (InCutsceneData inData in cutsceneData)
Expand All @@ -176,10 +174,9 @@ public static string GetPartialCutscene()

private static ResultData GetData(_Scene scene, RomFile file, InCutsceneData inData)
{
ResultData outdata = new ResultData(scene, inData);
int romAddr;
ResultData outdata = new(scene, inData);

if (!scene.TryConvertToRom(inData.RamStart, out romAddr))
if (!scene.TryConvertToRom(inData.RamStart, out int romAddr))
{
outdata.result = ResultData.ResultType.Limit_UnallocatedSpace;
return outdata;
Expand All @@ -190,7 +187,7 @@ private static ResultData GetData(_Scene scene, RomFile file, InCutsceneData inD

try
{
Cutscene cs = new Cutscene(file);
Cutscene cs = new(file);

if (cs.CommandCount < 0 || cs.Frames < 0)
outdata.result = ResultData.ResultType.Success_InvalidCutscene;
Expand All @@ -211,8 +208,8 @@ private static ResultData GetData(_Scene scene, RomFile file, InCutsceneData inD

private static List<InCutsceneData> GetCutsceneOffsetData()
{
List<string> cutsceneStr = new List<string>();
List<InCutsceneData> cutsceneData = new List<InCutsceneData>();
List<string> cutsceneStr = new();
List<InCutsceneData> cutsceneData = new();

using (TextReader reader = System.IO.File.OpenText(CUTSCENE_OFFSET_DATA_LOC))
{
Expand All @@ -239,12 +236,14 @@ private static List<InCutsceneData> GetCutsceneOffsetData()

private static Dictionary<int, _Scene> GetSceneInfo(ORom rom)
{
Dictionary<int, _Scene> result = new Dictionary<int, _Scene>();
for (int sceneId = 0; sceneId < 101; sceneId++)// in sceneIdList)
Dictionary<int, _Scene> result = new();
for (int sceneId = 0; sceneId < 101; sceneId++)
{
_Scene s = new _Scene();
s.Id = sceneId;
s.Address = rom.Files.GetSceneVirtualAddress(sceneId);
_Scene s = new()
{
Id = sceneId,
Address = rom.Files.GetSceneVirtualAddress(sceneId)
};
result.Add(sceneId, s);
}
return result;
Expand Down Expand Up @@ -334,29 +333,28 @@ from row in ReadFrom(@"C:\Users\mzxrules\Google Drive\Documents\Visual Studio 20
{
Scene = int.Parse(columns[0]),
Setup = int.Parse(columns[1]),
Offset = (int.Parse(columns[2], NumberStyles.HexNumber, new CultureInfo("en-US")) & 0xFFFFFF)
Offset = int.Parse(columns[2], NumberStyles.HexNumber, new CultureInfo("en-US")) & 0xFFFFFF
};

Dictionary<int, SceneData> stuff = new Dictionary<int, SceneData>();
Dictionary<int, SceneData> stuff = new();


foreach(var item in csvData)
{
if (!stuff.ContainsKey(item.Scene))
{
stuff.Add(item.Scene, new SceneData(item.Scene));
stuff.Add(item.Scene, new(item.Scene));
}

stuff[item.Scene].Cutscenes.Add(new CutsceneData(item.Offset, item.Setup, "?"));

}

//DataContractJsonSerializer dmaSerializer =
// new DataContractJsonSerializer(typeof(List<DmaData_Wiki>));


DataContractJsonSerializer dmaNewSerializer =
new DataContractJsonSerializer(typeof(List<SceneData>));
new(typeof(List<SceneData>));

//List<DmaData_Wiki> dmaOld;
//List<DmaData> dma;
Expand All @@ -377,11 +375,9 @@ from row in ReadFrom(@"C:\Users\mzxrules\Google Drive\Documents\Visual Studio 20
// dma.Add(d);
//}

using (FileStream sw = new FileStream("sceneCs.json", FileMode.OpenOrCreate))
{
dmaNewSerializer.WriteObject(sw, stuff.Values.ToList());
//filesNewSerializer.WriteObject(sw, newItems);
}
using FileStream sw = new("sceneCs.json", FileMode.OpenOrCreate);
dmaNewSerializer.WriteObject(sw, stuff.Values.ToList());
//filesNewSerializer.WriteObject(sw, newItems);
}

}
Expand Down
Loading

0 comments on commit 449bb30

Please sign in to comment.