diff --git a/GameFiles/FileTypes/YmapFile.cs b/GameFiles/FileTypes/YmapFile.cs index 06395e3..d3f6bea 100644 --- a/GameFiles/FileTypes/YmapFile.cs +++ b/GameFiles/FileTypes/YmapFile.cs @@ -937,6 +937,12 @@ namespace CodeWalker.GameFiles } + public YmapEntityDef() + { + Scale = Vector3.One; + Position = Vector3.One; + Orientation = Quaternion.Identity; + } public YmapEntityDef(YmapFile ymap, int index, ref CEntityDef def) { Ymap = ymap; diff --git a/GameFiles/GameFileCache.cs b/GameFiles/GameFileCache.cs index d03e39b..6ac729e 100644 --- a/GameFiles/GameFileCache.cs +++ b/GameFiles/GameFileCache.cs @@ -133,6 +133,7 @@ namespace CodeWalker.GameFiles InitDlc(); + //TestYcds(); //TestYmaps(); //TestPlacements(); //TestDrawables(); @@ -2015,6 +2016,29 @@ namespace CodeWalker.GameFiles + public void TestYcds() + { + foreach (RpfFile file in AllRpfs) + { + foreach (RpfEntry entry in file.AllEntries) + { + try + { + if (entry.NameLower.EndsWith(".ycd")) + { + UpdateStatus(string.Format(entry.Path)); + YcdFile ycdfile = RpfMan.GetFile(entry); + if ((ycdfile != null))// && (ycdfile.Meta != null)) + { } + } + } + catch (Exception ex) + { + UpdateStatus("Error! " + ex.ToString()); + } + } + } + } public void TestYmaps() { foreach (RpfFile file in AllRpfs) @@ -2418,7 +2442,6 @@ namespace CodeWalker.GameFiles } - public void DecodeRelFiles() { UpdateStatus("Decoding REL files"); diff --git a/GameFiles/MetaTypes/MetaTypes.cs b/GameFiles/MetaTypes/MetaTypes.cs index 70a48ce..d07e6f8 100644 --- a/GameFiles/MetaTypes/MetaTypes.cs +++ b/GameFiles/MetaTypes/MetaTypes.cs @@ -3452,6 +3452,7 @@ namespace CodeWalker.GameFiles _Data.LookUps = new CScenarioPointLookUps(); //this shouldn't happen... } + mb.AddString("Made with CodeWalker by dexyfex. " + DateTime.Now.ToString()); return mb.AddItemPtr(MetaName.CScenarioPointRegion, _Data); } diff --git a/GameFiles/Resources/Clip.cs b/GameFiles/Resources/Clip.cs index 799bd55..3f85b1c 100644 --- a/GameFiles/Resources/Clip.cs +++ b/GameFiles/Resources/Clip.cs @@ -383,6 +383,7 @@ namespace CodeWalker.GameFiles //public byte Unknown_02h { get; set; } //public byte Unknown_03h { get; set; } public MetaHash Unknown_00h { get; set; } + public MetaName Unknown_00hn { get; set; } public uint DataLength { get; set; } public uint Unknown_08h { get; set; } // 0x00000000 ..sequence header offset? public uint Unknown_0Ch { get; set; } //[uv1:] bytes used by sequence "header"? offset to data items @@ -392,13 +393,15 @@ namespace CodeWalker.GameFiles public ushort Unknown_18h { get; set; } //[uv1:8] stride of data item? public ushort Unknown_1Ah { get; set; } public ushort Unknown_1Ch { get; set; } - public ushort Unknown_1Eh { get; set; } + public byte Unknown_1Eh { get; set; } + public byte Unknown_1Fh { get; set; } public byte[] Data { get; set; } public override void Read(ResourceDataReader reader, params object[] parameters) { // read structure data this.Unknown_00h = reader.ReadUInt32();//2965995365 2837183178 + this.Unknown_00hn = (MetaName)(uint)Unknown_00h; //this.Unknown_00h = reader.ReadByte(); //101 202 97 120 //this.Unknown_01h = reader.ReadByte(); //127 250 202 168 //this.Unknown_02h = reader.ReadByte(); //201 27 115 126 @@ -409,42 +412,51 @@ namespace CodeWalker.GameFiles this.Unknown_10h = reader.ReadUInt32();//314 174 1238 390 (=Length) this.Unknown_14h = reader.ReadUInt16();//0 0 0 0 this.Unknown_16h = reader.ReadUInt16();//221 (DD) 17 (11) 151 (97) 201 - this.Unknown_18h = reader.ReadUInt16();//0 4 4 0 type? + this.Unknown_18h = reader.ReadUInt16();//0 4 4 0 stride? this.Unknown_1Ah = reader.ReadUInt16();//0 0 106 0 this.Unknown_1Ch = reader.ReadUInt16();//0 17 0 0 bone? - this.Unknown_1Eh = reader.ReadUInt16();//64 255 255 64 + this.Unknown_1Eh = reader.ReadByte(); //64 255 255 64 + this.Unknown_1Fh = reader.ReadByte(); //0 0 0 0 - var pos = reader.Position; - this.Data = reader.ReadBytes((int)DataLength); - reader.Position = pos; - //float[] fvals = reader.ReadFloatsAt((ulong)pos, DataLength / 4); - //ushort[] svals = reader.ReadUshortsAt((ulong)pos, DataLength / 2); - //if (fvals != null) - //{ } - //reader.Position = pos; - //float f0 = reader.ReadSingle(); // 0 0 0 0 - //var v0 = reader.ReadStruct();// 0,0,0 1,1,1 0,0,0 0,0,0 - //float f1 = reader.ReadSingle(); // 0 0 0 0 - //uint u0 = reader.ReadUInt32(); // 0 17 0 0 - //short s1 = reader.ReadInt16(); // 0 112 0 0 - //short s2 = reader.ReadInt16(); // 0 14048 0 0 - ////float f2 = reader.ReadSingle(); // 0 6.675771E-06 0 - //float f3 = reader.ReadSingle(); // 0 -0.875 0 - //short u2 = reader.ReadInt16(); // 0 -1 - //short u3 = reader.ReadInt16(); // 0 1 - //short u4 = reader.ReadInt16(); // 0 -1 - //short u5 = reader.ReadInt16(); // 0 1 - //short u6 = reader.ReadInt16(); // 0 -18725 - //short u7 = reader.ReadInt16(); // 0 1 - //short u8 = reader.ReadInt16(); // 23 -18725 - //short u9 = reader.ReadInt16(); // 0 1 - //short uA = reader.ReadInt16(); // 2825 28086 - //short uB = reader.ReadInt16(); // 0 1 + switch (Unknown_18h) + { + case 0: + break; + case 4: + break; + case 12: + break; + default: + break; + } + + switch (Unknown_1Eh) + { + case 64: //0x40 + case 255: //0xFF + break; + default://no hits + break; + } + + switch (Unknown_1Fh) + { + case 0: + case 17: //0x11 + case 20: //0x14 + case 21: //0x15 + case 49: //0x31 + case 52: //0x34 + case 53: //0x35 + break; + default: //no hits + break; + } } diff --git a/WorldForm.cs b/WorldForm.cs index 3b82001..01baee6 100644 --- a/WorldForm.cs +++ b/WorldForm.cs @@ -135,6 +135,7 @@ namespace CodeWalker List BoundingBoxes = new List(); List BoundingSpheres = new List(); List HilightBoxes = new List(); + List SelectionBoxes = new List(); bool controllightdir = false; //if not, use timecycle @@ -223,6 +224,8 @@ namespace CodeWalker List SelectionLineVerts = new List(); List SelectionTriVerts = new List(); + YmapEntityDef SelectedCarGenEntity = new YmapEntityDef(); + TransformWidget Widget = new TransformWidget(); TransformWidget GrabbedWidget = null; @@ -562,6 +565,7 @@ namespace CodeWalker UpdateWidgets(); + SelectionBoxes.Clear(); HilightBoxes.Clear(); BoundingBoxes.Clear(); BoundingSpheres.Clear(); @@ -594,16 +598,16 @@ namespace CodeWalker RenderSingleItem(); } + RenderSelection(); + shaders.RenderQueued(context, camera, currentWindVec); RenderBounds(context); - RenderSelection(context); + RenderSelectionGeometry(context); RenderMoused(context); - RenderSelectionGeometry(context); - shaders.RenderFinalPass(context); RenderMarkers(context); @@ -2119,29 +2123,7 @@ namespace CodeWalker { var f = yft.Fragment; - RenderDrawable(f.Drawable, null, null, -camera.Position, hash); - - if (f.Unknown_F8h_Data != null) //cloth - { - RenderDrawable(f.Unknown_F8h_Data, null, null, -camera.Position, hash); - } - - //vehicle wheels... - if ((f.PhysicsLODGroup != null) && (f.PhysicsLODGroup.PhysicsLOD1 != null)) - { - var pl1 = f.PhysicsLODGroup.PhysicsLOD1; - if ((pl1.Children != null) && (pl1.Children.data_items != null)) - { - for (int i = 0; i < pl1.Children.data_items.Length; i++) - { - var pch = pl1.Children.data_items[i]; - if ((pch.Drawable1 != null) && (pch.Drawable1.AllModels.Length != 0)) - { - //RenderDrawable(pch.Drawable1, null, null, -camera.Position, hash); - } - } - } - } + RenderFragment(null, null, f, hash); seldrwbl = f.Drawable; } @@ -2511,6 +2493,38 @@ namespace CodeWalker + + private bool RenderFragment(Archetype arch, YmapEntityDef ent, FragType f, uint txdhash=0) + { + var pos = ent?.Position ?? Vector3.Zero; + + RenderDrawable(f.Drawable, arch, ent, pos-camera.Position, txdhash); + + if (f.Unknown_F8h_Data != null) //cloth + { + RenderDrawable(f.Unknown_F8h_Data, arch, ent, pos-camera.Position, txdhash); + } + + //vehicle wheels... + if ((f.PhysicsLODGroup != null) && (f.PhysicsLODGroup.PhysicsLOD1 != null)) + { + var pl1 = f.PhysicsLODGroup.PhysicsLOD1; + if ((pl1.Children != null) && (pl1.Children.data_items != null)) + { + for (int i = 0; i < pl1.Children.data_items.Length; i++) + { + var pch = pl1.Children.data_items[i]; + if ((pch.Drawable1 != null) && (pch.Drawable1.AllModels.Length != 0)) + { + //RenderDrawable(pch.Drawable1, arch, ent, -camera.Position, hash); + } + } + } + } + + return true; + } + private bool RenderArchetype(Archetype arche, YmapEntityDef entity, Renderable rndbl = null, bool cull = true) { //enqueue a single archetype for rendering. @@ -2875,10 +2889,8 @@ namespace CodeWalker if (mode == BoundsShaderMode.None) { return; } - Vector3 colour = new Vector3(0, 0, 1); - Vector3 colourhi = new Vector3(0, 1, 1); - colour *= globalLights.HdrIntensity; - colourhi *= globalLights.HdrIntensity; + Vector3 colour = new Vector3(0, 0, 1) * globalLights.HdrIntensity; + Vector3 colourhi = new Vector3(0, 1, 1) * globalLights.HdrIntensity; shaders.SetDepthStencilMode(context, clip ? DepthStencilMode.Enabled : DepthStencilMode.DisableAll); var shader = shaders.Bounds; @@ -2915,6 +2927,7 @@ namespace CodeWalker } } + shader.UnbindResources(context); } @@ -3060,22 +3073,22 @@ namespace CodeWalker } - private void RenderSelection(DeviceContext context) + private void RenderSelection() { if (SelectedItem.MultipleSelection) { for (int i = 0; i < SelectedItems.Count; i++) { var item = SelectedItems[i]; - RenderSelection(context, ref item); + RenderSelection(ref item); } } else { - RenderSelection(context, ref SelectedItem); + RenderSelection(ref SelectedItem); } } - private void RenderSelection(DeviceContext context, ref MapSelection selectionItem) + private void RenderSelection(ref MapSelection selectionItem) { //immediately render the bounding box of the current selection. also, arrows. @@ -3140,6 +3153,21 @@ namespace CodeWalker float arrowlen = cg._CCarGen.perpendicularLength; float arrowrad = arrowlen * 0.066f; RenderSelectionArrowOutline(cg.Position, Vector3.UnitX, Vector3.UnitY, ori, arrowlen, arrowrad, cgrn); + + Quaternion cgtrn = Quaternion.RotationAxis(Vector3.UnitZ, (float)Math.PI * -0.5f); //car fragments currently need to be rotated 90 deg right... + Quaternion cgori = Quaternion.Multiply(cg.Orientation, cgtrn); + + SelectedCarGenEntity.SetPosition(cg.Position); + SelectedCarGenEntity.SetOrientation(cgori); + + uint carhash = cg._CCarGen.carModel; + if (carhash == 0) carhash = 418536135; //"infernus" + + YftFile caryft = gameFileCache.GetYft(carhash); + if ((caryft != null) && (caryft.Loaded) && (caryft.Fragment != null)) + { + RenderFragment(null, SelectedCarGenEntity, caryft.Fragment, carhash); + } } if (selectionItem.PathNode != null) { @@ -3207,20 +3235,13 @@ namespace CodeWalker - shaders.SetDepthStencilMode(context, clip ? DepthStencilMode.Enabled : DepthStencilMode.DisableAll); - - //render selected object box... - var shader = shaders.Bounds; - shader.SetMode(BoundsShaderMode.Box); - shader.SetShader(context); - shader.SetInputLayout(context, VertexType.Default); - shader.SetSceneVars(context, camera, null, globalLights); - shader.SetColourVars(context, new Vector4(colour, 1)); - - shader.SetBoxVars(context, camrel, bbmin, bbmax, ori, scale); - shader.DrawBox(context); - - shader.UnbindResources(context); + MapBox box = new MapBox(); + box.CamRelPos = camrel; + box.BBMin = bbmin; + box.BBMax = bbmax; + box.Orientation = ori; + box.Scale = scale; + SelectionBoxes.Add(box); } @@ -3366,9 +3387,13 @@ namespace CodeWalker { bool clip = true; - if (SelectionMode == MapSelectionMode.NavMesh) + switch (SelectionMode) { - clip = false; + case MapSelectionMode.NavMesh: + case MapSelectionMode.WaterQuad: + case MapSelectionMode.MloInstance: + clip = false; + break; } @@ -3384,6 +3409,27 @@ namespace CodeWalker pshader.RenderLines(context, SelectionLineVerts, camera, shaders.GlobalLights); } + + + + if (SelectionBoxes.Count > 0) + { + Vector3 coloursel = new Vector3(0, 1, 0) * globalLights.HdrIntensity * 5.0f; + var shader = shaders.Bounds; + shader.SetMode(BoundsShaderMode.Box); + shader.SetShader(context); + shader.SetInputLayout(context, VertexType.Default); + shader.SetSceneVars(context, camera, null, globalLights); + shader.SetColourVars(context, new Vector4(coloursel, 1)); + for (int i = 0; i < SelectionBoxes.Count; i++) + { + MapBox mb = SelectionBoxes[i]; + shader.SetBoxVars(context, mb.CamRelPos, mb.BBMin, mb.BBMax, mb.Orientation, mb.Scale); + shader.DrawBox(context); + } + shader.UnbindResources(context); + } + } @@ -4330,6 +4376,10 @@ namespace CodeWalker CurMouseHit.AABB = bbox; } } + if (SelectedItem.CarGenerator != null) + { + } + } if ((SelectionMode == MapSelectionMode.MloInstance) && (ymap.MloEntities != null)) {