private static void SummaryDoct(Doct doct, string file, TextWriter writer) { writer.WriteLine($"# DOCT ({Path.GetFileName(file)})"); writer.WriteLine(); writer.WriteLine($"- Version: {doct.Header.Version}"); writer.WriteLine($"- Unk2: {doct.Header.Unk2}"); writer.WriteLine(); writer.WriteLine("## Entry1"); writer.WriteLine(); writer.WriteLine("```"); foreach (var pair in doct.Entry1List.Select((it, index) => (it, index))) { writer.WriteLine($"{pair.index,4}:{pair.it}"); } writer.WriteLine("```"); writer.WriteLine(); writer.WriteLine("## Entry2"); writer.WriteLine(); writer.WriteLine("```"); foreach (var pair in doct.Entry2List.Select((it, index) => (it, index))) { writer.WriteLine($"{pair.index,4}:{pair.it}"); } writer.WriteLine("```"); }
public Kh2Map(GraphicsDevice graphics, IDataContent content, string path) { _graphics = graphics; var binarc = content.FileOpen(path).Using(Bar.Read); _skybox0MeshGroup = FromMdlx(graphics, binarc, "SK0") ?? Empty; _skybox1MeshGroup = FromMdlx(graphics, binarc, "SK1") ?? Empty; _mapMeshGroup = FromMdlx(graphics, binarc, "MAP") ?? Empty; CollisionOctalTree = binarc.ForEntry(x => x.Type == Bar.EntryType.CollisionOctalTree, Coct.Read); ColorOctalTree = binarc.ForEntry(x => x.Type == Bar.EntryType.ColorOctalTree, Coct.Read); CameraOctalTree = binarc.ForEntry(x => x.Type == Bar.EntryType.CameraOctalTree, Coct.Read); DrawOctalTree = binarc.ForEntry(x => x.Type == Bar.EntryType.DrawOctalTree, Doct.Read); _bobEntities = binarc.ForEntry(x => x.Type == Bar.EntryType.BgObjPlacement, BobDescriptor.Read)? .Select(x => new BobEntity(x)).ToList() ?? new List <BobEntity>(); var bobModels = binarc.ForEntries("BOB", Bar.EntryType.Model, Mdlx.Read).ToList(); var bobTextures = binarc.ForEntries("BOB", Bar.EntryType.ModelTexture, ModelTexture.Read).ToList(); _bobModels = new List <MeshGroup>(bobModels.Count); for (var i = 0; i < bobModels.Count; i++) { _bobModels.Add(new MeshGroup { MeshDescriptors = MeshLoader.FromKH2(bobModels[i]).MeshDescriptors, Textures = bobTextures[i].LoadTextures(graphics).ToArray() }); } }
protected int OnExecute(CommandLineApplication app) { var doct = File.OpenRead(DoctIn).Using(s => Doct.Read(s)); new DumpDoctUtil(doct, Console.Out); return(0); }
protected int OnExecute(CommandLineApplication app) { var doct = File.OpenRead(DoctIn).Using(s => Doct.Read(s)); SummaryDoct(doct, DoctIn, Console.Out); return(0); }
public DumpDoctUtil(Doct doct, TextWriter writer) { this.doct = doct; this.writer = writer; if (doct.Entry1List.Any()) { DumpEntry1(0, 0); } }
protected int OnExecute(CommandLineApplication app) { var doct = new Doct(); doct.Entry1List.Add(new Doct.Entry1 { }); doct.Entry2List.Add(new Doct.Entry2 { }); File.Create(DoctOut).Using(s => Doct.Write(s, doct)); return(0); }
protected int OnExecute(CommandLineApplication app) { var doctBin = File.ReadAllBytes(MapIn); var entries = File.OpenRead(MapIn).Using(s => Bar.Read(s)); var doctEntry = entries.Single(it => it.Type == Bar.EntryType.MeshOcclusion); var doct = Doct.Read(doctEntry.Stream); SummaryDoct(doct, MapIn, Console.Out); return(0); }
public void CreateDummyDoctAndReadIt() { using var stream = new MemoryStream(); var doct = new Doct(); doct.Entry1List.Add(new Doct.Entry1 { }); doct.Entry2List.Add(new Doct.Entry2 { }); Doct.Write(stream, doct); stream.Position = 0; Doct.Read(stream); // confirm that it throws nothing. }
public void TestMapGenUtil(string inputModel) { var outMap = Path.ChangeExtension(inputModel, ".map"); using var disposer = new FileDisposer(outMap); new MapGenUtil().Run(inputModel, outMap); var barEntries = File.OpenRead(outMap).Using(Bar.Read); { var doct = Doct.Read(barEntries.Single(it => it.Type == Bar.EntryType.DrawOctalTree).Stream); var writer = new StringWriter(); new DumpDoctUtil(doct, writer); var doctDumpFile = Path.ChangeExtension(inputModel, ".doct.dump"); Assert.Equal( expected: File.ReadAllText(doctDumpFile), actual: writer.ToString(), ignoreLineEndingDifferences: true ); } { var coct = Coct.Read(barEntries.Single(it => it.Type == Bar.EntryType.CollisionOctalTree).Stream); var writer = new StringWriter(); new DumpCoctUtil(coct, writer); var coctDumpFile = Path.ChangeExtension(inputModel, ".coct.dump"); Assert.Equal( expected: File.ReadAllText(coctDumpFile), actual: writer.ToString(), ignoreLineEndingDifferences: true ); } }
protected int OnExecute(CommandLineApplication app) { var isMap = Path.GetExtension(InputFile).ToLowerInvariant() == ".map"; if (isMap) { foreach (var entry in File.OpenRead(InputFile).Using(Bar.Read) .Where(entry => false || entry.Type == Bar.EntryType.MeshOcclusion ) ) { Console.WriteLine($"# {entry.Name}:{entry.Index} ({entry.Type})"); PrintSummary(Doct.Read(entry.Stream)); Console.WriteLine(); } } else { PrintSummary(File.OpenRead(InputFile).Using(Doct.Read)); } return(0); }
private void PrintSummary(Doct coct) { Console.WriteLine($"{coct.Entry1List.Count,8:#,##0} drawing mesh groups."); Console.WriteLine($"{coct.Entry2List.Count,8:#,##0} drawing meshes."); }
protected int OnExecute(CommandLineApplication app) { MapOut = Path.GetFullPath(MapOut ?? Path.GetFileName(MapIn)); Console.WriteLine($"Output map file: {MapOut}"); var entries = File.OpenRead(MapIn).Using(s => Bar.Read(s).ToArray()); var mapModel = Mdlx.Read(entries.Single(IsMapModel).Stream); var numVifPackets = mapModel.MapModel.VifPackets.Count; var numAlb2Groups = mapModel.MapModel.vifPacketRenderingGroup.Count; Console.WriteLine($"numVifPackets: {numVifPackets:#,##0}"); Console.WriteLine($"numAlb2Groups: {numAlb2Groups:#,##0}"); Console.WriteLine($"Note: this tool will build a unoptimized doct that renders all ALB2 {numAlb2Groups:#,##0} groups."); var doctStream = new MemoryStream(); { var doct = new Doct(); doct.Entry1List.Add( new Doct.Entry1 { Entry2Index = 0, Entry2LastIndex = Convert.ToUInt16(numAlb2Groups), // max 65535 } ); const float WorldBounds = 18000; doct.Entry2List.AddRange( Enumerable.Range(0, numAlb2Groups) .Select( index => new Doct.Entry2 { BoundingBox = new BoundingBox( new System.Numerics.Vector3(-WorldBounds), new System.Numerics.Vector3(WorldBounds) ) } ) ); Doct.Write(doctStream, doct); doctStream.Position = 0; } foreach (var entry in entries.Where(IsDoct)) { Console.WriteLine("DOCT entry replaced."); entry.Stream = doctStream; } File.Create(MapOut).Using(s => Bar.Write(s, entries)); Console.WriteLine("Output map file is written successfully."); return(0); }