public CmpFile(IntermediateNode rootnode, ILibFile additionalLibrary) { this.additionalLibrary = additionalLibrary; Models = new Dictionary <string, ModelFile>(); Cameras = new Dictionary <string, CmpCameraInfo>(); Constructs = new ConstructCollection(); Parts = new List <Part>(); List <string> modelNames = new List <string>(); foreach (Node node in rootnode) { switch (node.Name.ToLowerInvariant()) { case "exporter version": break; case "vmeshlibrary": IntermediateNode vMeshLibraryNode = node as IntermediateNode; if (VMeshLibrary == null) { VMeshLibrary = new VmsFile(vMeshLibraryNode, this); } else { throw new Exception("Multiple vmeshlibrary nodes in cmp root"); } break; case "animation": IntermediateNode animationNode = node as IntermediateNode; if (Animation == null) { Animation = new AnmFile(animationNode, Constructs); } else { throw new Exception("Multiple animation nodes in cmp root"); } break; case "material library": IntermediateNode materialLibraryNode = node as IntermediateNode; if (MaterialLibrary == null) { MaterialLibrary = new MatFile(materialLibraryNode, this); } else { throw new Exception("Multiple material library nodes in cmp root"); } break; case "texture library": IntermediateNode textureLibraryNode = node as IntermediateNode; if (TextureLibrary == null) { TextureLibrary = new TxmFile(textureLibraryNode); } else { throw new Exception("Multiple texture library nodes in cmp root"); } break; case "cmpnd": IntermediateNode cmpndNode = node as IntermediateNode; foreach (Node SubNode in cmpndNode) { if (SubNode is LeafNode) { continue; } var cmpndSubNode = (IntermediateNode)SubNode; if (cmpndSubNode.Name.Equals("cons", StringComparison.OrdinalIgnoreCase)) { Constructs.AddNode(cmpndSubNode); } else if ( cmpndSubNode.Name.StartsWith("part_", StringComparison.OrdinalIgnoreCase) || cmpndSubNode.Name.Equals("root", StringComparison.OrdinalIgnoreCase) ) { string objectName = string.Empty, fileName = string.Empty; foreach (LeafNode partNode in cmpndSubNode) { switch (partNode.Name.ToLowerInvariant()) { case "object name": objectName = partNode.StringData; break; case "file name": fileName = partNode.StringData; break; case "index": break; default: FLLog.Error("Cmp", "Invalid node in " + cmpndSubNode.Name + ": " + partNode.Name); break; } } Parts.Add(new Part(objectName, fileName, Models, Cameras, Constructs)); } else { throw new Exception("Invalid node in " + cmpndNode.Name + ": " + cmpndSubNode.Name); } } break; case "materialanim": MaterialAnim = new MaterialAnimCollection((IntermediateNode)node); break; default: if (node is IntermediateNode) { var im = (IntermediateNode)node; if (im.Any(x => x.Name.Equals("vmeshpart", StringComparison.OrdinalIgnoreCase) || x.Name.Equals("multilevel", StringComparison.OrdinalIgnoreCase))) { ModelFile m = new ModelFile(im, this); m.Path = node.Name; Models.Add(node.Name, m); modelNames.Add(node.Name); break; } else if (im.Any(x => x.Name.Equals("camera", StringComparison.OrdinalIgnoreCase))) { var cam = new CmpCameraInfo(im); Cameras.Add(im.Name, cam); break; } } FLLog.Error("Cmp", Path ?? "Utf" + ": Invalid Node in cmp root: " + node.Name); break; } } //FL handles cmpnd nodes that point to non-existant models: fix up here List <Part> broken = new List <Part>(); for (int i = 0; i < Parts.Count; i++) { if (Parts[i].IsBroken()) { broken.Add(Parts[i]); } } foreach (var b in broken) { Parts.Remove(b); } }
static void OnError(IntPtr t) { FLLog.Error("LancerDecode", Marshal.PtrToStringAnsi(t)); }
public override void Draw() { ImGui.Columns(2, "cols", true); ImGui.Text("Type"); ImGui.NextColumn(); ImGui.Text("Reference"); ImGui.Separator(); ImGui.NextColumn(); var tcolor = ImGui.GetStyle().Colors[(int)ImGuiCol.Text]; foreach (var t in res.TextureDictionary) { var col = new Vector4(0.6f, 0.6f, 0.6f, 1f); foreach (var tex in referencedTex) { if (t.Key.Equals(tex, StringComparison.InvariantCultureIgnoreCase)) { col = tcolor; break; } } ImGui.TextColored(col, "Texture"); ImGui.NextColumn(); SelectableColored(col, ImGuiExt.IDSafe(t.Key)); ContextView(t.Key, () => { if (t.Value is Texture2D) { var title = string.Format("{0} (Texture)", t.Key); win.AddTab(new TextureViewer(title, (Texture2D)t.Value, null, false)); } else { FLLog.Error("Texture", "Tried to view non-2D texture"); } }); ImGui.NextColumn(); } foreach (var m in res.MaterialDictionary) { var col = referencedMats.Contains(m.Key) ? tcolor : new Vector4(0.6f, 0.6f, 0.6f, 1f); ImGui.TextColored(col, "Material"); ImGui.NextColumn(); ImGui.TextColored(col, ImGuiExt.IDSafe(string.Format("{0} (0x{1:X})", m.Value.Name, m.Key))); ImGui.NextColumn(); } foreach (var m in res.AnimationDictionary) { var col = referencedTex.Contains(m.Key) ? tcolor : new Vector4(0.6f, 0.6f, 0.6f, 1f); ImGui.TextColored(col, "Animated Texture"); ImGui.NextColumn(); SelectableColored(col, ImGuiExt.IDSafe(m.Key)); ContextView(m.Key, () => { var title = string.Format("{0} (Animation)", m.Key); win.AddTab(new TextureViewer(title, (Texture2D)res.FindTexture(m.Key + "_0"), m.Value, false)); }); ImGui.NextColumn(); } foreach (var ln in missing) { ImGui.TextColored(Color4.Red, "Missing"); ImGui.NextColumn(); ImGui.TextColored(Color4.Red, string.Format("{0} (Ref {1})", ln.Missing, ln.Reference)); ImGui.NextColumn(); } ImGui.Columns(1, null, false); }
public Base(Section section, FreelancerData data) : base(data) { if (section == null) { throw new ArgumentNullException("section"); } string file = null; foreach (Entry e in section) { switch (e.Name.ToLowerInvariant()) { case "nickname": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Nickname != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Nickname = e[0].ToString(); break; case "system": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (System != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } System = e[0].ToString(); break; case "strid_name": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (IdsName != 0) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } IdsName = e[0].ToInt32(); break; case "file": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (file != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } file = e[0].ToString(); break; case "bgcs_base_run_by": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (BGCSBaseRunBy != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } BGCSBaseRunBy = e[0].ToString(); break; case "terrain_tiny": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (TerrainTiny != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } TerrainTiny = e[0].ToString(); break; case "terrain_sml": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (TerrainSml != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } TerrainSml = e[0].ToString(); break; case "terrain_mdm": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (TerrainMdm != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } TerrainMdm = e[0].ToString(); break; case "terrain_lrg": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (TerrainLrg != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } TerrainLrg = e[0].ToString(); break; case "terrain_dyna_01": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (TerrainDyna1 != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } TerrainDyna1 = e[0].ToString(); break; case "terrain_dyna_02": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (TerrainDyna2 != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } TerrainDyna2 = e[0].ToString(); break; case "autosave_forbidden": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (AutosaveForbidden != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } AutosaveForbidden = e[0].ToBoolean(); break; default: throw new Exception("Invalid Entry in " + section.Name + ": " + e.Name); } } Rooms = new List <Room>(); if (data.VFS.FileExists(data.Freelancer.DataPath + file)) { foreach (Section s in ParseFile(data.Freelancer.DataPath + file, data.VFS)) { switch (s.Name.ToLowerInvariant()) { case "baseinfo": foreach (Entry e in s) { switch (e.Name.ToLowerInvariant()) { case "nickname": if (e.Count != 1) { throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count); } if (Name != null) { FLLog.Warning("Base", "Duplicate " + e.Name + " Entry in " + s.Name); } Name = e[0].ToString(); break; case "start_room": if (e.Count != 1) { throw new Exception("Invalid number of values in " + s.Name + " Entry " + e.Name + ": " + e.Count); } if (StartRoom != null) { FLLog.Warning("Base", "Duplicate " + e.Name + " Entry in " + s.Name); } StartRoom = e[0].ToString(); break; case "price_variance": FLLog.Error("Base", "Unimplemented: price_variance"); break; default: throw new Exception("Invalid Entry in " + s.Name + ": " + e.Name); } } break; case "room": Rooms.Add(new Room(s, data)); break; default: throw new Exception("Invalid Section in " + file + ": " + s.Name); } } } else { FLLog.Error("Ini", "Base ini could not find file " + file); } }
public CmpFile(IntermediateNode rootnode, ILibFile additionalLibrary) { this.additionalLibrary = additionalLibrary; Models = new Dictionary <string, ModelFile>(); Constructs = new ConstructCollection(); Parts = new Dictionary <int, Part>(); foreach (Node node in rootnode) { switch (node.Name.ToLowerInvariant()) { case "exporter version": break; case "vmeshlibrary": IntermediateNode vMeshLibraryNode = node as IntermediateNode; if (VMeshLibrary == null) { VMeshLibrary = new VmsFile(vMeshLibraryNode, this); } else { throw new Exception("Multiple vmeshlibrary nodes in cmp root"); } break; case "animation": IntermediateNode animationNode = node as IntermediateNode; if (Animation == null) { Animation = new AnmFile(animationNode, Constructs); } else { throw new Exception("Multiple animation nodes in cmp root"); } break; case "material library": IntermediateNode materialLibraryNode = node as IntermediateNode; if (MaterialLibrary == null) { MaterialLibrary = new MatFile(materialLibraryNode, this); } else { throw new Exception("Multiple material library nodes in cmp root"); } break; case "texture library": IntermediateNode textureLibraryNode = node as IntermediateNode; if (TextureLibrary == null) { TextureLibrary = new TxmFile(textureLibraryNode); } else { throw new Exception("Multiple texture library nodes in cmp root"); } break; case "cmpnd": IntermediateNode cmpndNode = node as IntermediateNode; int maxIndices = int.MaxValue; foreach (Node SubNode in cmpndNode) { if (SubNode is LeafNode) { continue; } var cmpndSubNode = (IntermediateNode)SubNode; if (cmpndSubNode.Name.Equals("cons", StringComparison.OrdinalIgnoreCase)) { Constructs.AddNode(cmpndSubNode); } else if ( cmpndSubNode.Name.StartsWith("part_", StringComparison.OrdinalIgnoreCase) || cmpndSubNode.Name.Equals("root", StringComparison.OrdinalIgnoreCase) ) { string objectName = string.Empty, fileName = string.Empty; int index = -1; foreach (LeafNode partNode in cmpndSubNode) { switch (partNode.Name.ToLowerInvariant()) { case "object name": objectName = partNode.StringData; break; case "file name": fileName = partNode.StringData; break; case "index": if (partNode.Int32Data != null) { index = partNode.Int32Data.Value; } else { index = partNode.Int32ArrayData [0]; } break; default: throw new Exception("Invalid node in " + cmpndSubNode.Name + ": " + partNode.Name); } } if (Parts.ContainsKey(index)) { FLLog.Error("Cmp", "Duplicate index"); Parts.Add(maxIndices--, new Part(objectName, fileName, Models, Constructs)); } else { Parts.Add(index, new Part(objectName, fileName, Models, Constructs)); } } else { throw new Exception("Invalid node in " + cmpndNode.Name + ": " + cmpndSubNode.Name); } } break; case "materialanim": MaterialAnim = new MaterialAnimCollection((IntermediateNode)node); break; default: if (node.Name.EndsWith(".3db", StringComparison.OrdinalIgnoreCase)) { ModelFile m = new ModelFile(node as IntermediateNode, this); m.Path = node.Name; Models.Add(node.Name, m); } else { FLLog.Error("Cmp", Path ?? "Utf" + ": Invalid Node in cmp root: " + node.Name); } break; } } }
private void setTextures(IntermediateNode textureLibraryNode) { foreach (IntermediateNode textureNode in textureLibraryNode) { LeafNode child = null; bool isTexture = true; bool isTgaMips = false; if (textureNode.Count == 1) { child = textureNode[0] as LeafNode; } else { //TODO: Mipmapping foreach (var node in textureNode) { var n = node.Name.ToLowerInvariant().Trim(); if (n == "mip0") { child = node as LeafNode; isTgaMips = true; } if (n == "mips") { child = node as LeafNode; isTgaMips = false; break; } if (n == "fps") { isTexture = false; break; } } } if (isTexture) { if (child == null) { throw new Exception("Invalid texture library"); } TextureData data = new TextureData(child, textureNode.Name, isTgaMips); if (isTgaMips) { foreach (var node in textureNode) { data.SetLevel(node); } } if (data == null) { throw new Exception("Invalid texture library"); } string key = textureNode.Name; if (Textures.ContainsKey(key)) { FLLog.Error("Txm", "Duplicate texture " + key + " in texture library"); } else { Textures.Add(key, data); } } else { Animations.Add(textureNode.Name, new TexFrameAnimation(textureNode)); } } }
public Light(Section section, FreelancerData gdata) : base(section) { foreach (Entry e in section) { if (!parentEntry(e)) { switch (e.Name.ToLowerInvariant()) { case "inherit": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Inherit != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Inherit = gdata.Equipment.FindEquipment(e[0].ToString()) as Light; break; case "always_on": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (alwaysOn != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } alwaysOn = e[0].ToBoolean(); break; case "docking_light": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (dockingLight != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } dockingLight = e[0].ToBoolean(); break; case "bulb_size": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (bulbSize != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } bulbSize = e[0].ToSingle(); break; case "glow_size": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (glowSize != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } glowSize = e[0].ToSingle(); break; case "glow_color": if (e.Count != 3) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (glowColor != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } glowColor = new Color3f(e[0].ToInt32() / 255f, e[1].ToInt32() / 255f, e[2].ToInt32() / 255f); break; case "color": if (e.Count != 3) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (color != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } color = new Color3f(e[0].ToInt32() / 255f, e[1].ToInt32() / 255f, e[2].ToInt32() / 255f); break; case "flare_cone": if (e.Count != 2) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (flareCone != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } flareCone = new Vector2(e[0].ToInt32(), e[1].ToInt32()); break; case "intensity": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (intensity != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } intensity = e[0].ToInt32(); break; case "lightsource_cone": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (lightsourceCone != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } lightsourceCone = e[0].ToInt32(); break; case "min_color": if (e.Count != 3) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (minColor != null) { FLLog.Warning("Light", "Duplicate " + e.Name + " Entry in " + section.Name); } minColor = new Color3f(e[0].ToInt32() / 255f, e[1].ToInt32() / 255f, e[2].ToInt32() / 255f); break; case "avg_delay": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (avgDelay != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } avgDelay = e[0].ToSingle(); break; case "blink_duration": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (blinkDuration != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } blinkDuration = e[0].ToSingle(); break; case "shape": FLLog.Error("Light", "custom shape not implemented"); break; default: FLLog.Error("Equipment", "Invalid Entry in " + section.Name + ": " + e.Name); break; } } } }
public ParticleLibrary(ResourceManager res, AleFile ale) { Resources = res; foreach (var effect in ale.FxLib.Effects) { var fx = new ParticleEffect(this); fx.CRC = effect.CRC; fx.Name = effect.Name; Dictionary <uint, NodeReference> nodesByIndex = new Dictionary <uint, NodeReference>(); foreach (var noderef in effect.Fx) { FxNode node = null; if (!noderef.IsAttachmentNode) { var nd = ale.NodeLib.Nodes.FirstOrDefault((arg) => arg.CRC == noderef.CRC); if (nd == null) { node = new FxNode("error node", "error node"); FLLog.Error("Fx", fx.Name + " bad node CRC 0x" + noderef.CRC.ToString("x")); } else { node = NodeFromAle(ale.NodeLib.Nodes.Where((arg) => arg.CRC == noderef.CRC).First()); } } var reference = new NodeReference(); reference.Node = node; reference.IsAttachmentNode = noderef.IsAttachmentNode; nodesByIndex.Add(noderef.Index, reference); } foreach (var noderef in effect.Fx) { var nd = nodesByIndex[noderef.Index]; if (noderef.Parent != 32768) { var parent = nodesByIndex[noderef.Parent]; parent.Children.Add(nd); nd.Parent = parent; } } foreach (var pair in effect.Pairs) { var n1 = nodesByIndex[pair.Item1]; var n2 = nodesByIndex[pair.Item2]; n1.Paired.Add(n2); } int emitterIndex = 0; int beamIndex = 0; fx.References = new List <NodeReference>(nodesByIndex.Values); for (int i = 0; i < fx.References.Count; i++) { fx.References[i].Index = i; fx.References[i].EmitterIndex = emitterIndex; fx.References[i].BeamIndex = beamIndex; if (fx.References[i].Node is FxEmitter) { emitterIndex++; } if (fx.References[i].Node is FLBeamAppearance) { beamIndex++; } } fx.EmitterCount = emitterIndex; fx.BeamCount = beamIndex; Effects.Add(fx); } }
public override void PlayFile(string filename) { //Load the file MediaSource mediaSource; { var resolver = new SourceResolver(); ObjectType otype; var source = new ComObject(resolver.CreateObjectFromURL(filename, SourceResolverFlags.MediaSource, null, out otype)); try { // Sometimes throws HRESULT: [0x80004002], Module: [General], ApiCode: [E_NOINTERFACE/No such interface supported], Message: No such interface supported. Bug? mediaSource = source.QueryInterface <MediaSource>(); } catch (SharpDXException) { mediaSource = null; FLLog.Error("VideoPlayerWMF", "QueryInterface failed on Media Foundation"); } resolver.Dispose(); source.Dispose(); } if (mediaSource is null) { return; } PresentationDescriptor presDesc; mediaSource.CreatePresentationDescriptor(out presDesc); for (int i = 0; i < presDesc.StreamDescriptorCount; i++) { SharpDX.Mathematics.Interop.RawBool selected; StreamDescriptor desc; presDesc.GetStreamDescriptorByIndex(i, out selected, out desc); if (selected) { TopologyNode sourceNode; MediaFactory.CreateTopologyNode(TopologyType.SourceStreamNode, out sourceNode); sourceNode.Set(TopologyNodeAttributeKeys.Source, mediaSource); sourceNode.Set(TopologyNodeAttributeKeys.PresentationDescriptor, presDesc); sourceNode.Set(TopologyNodeAttributeKeys.StreamDescriptor, desc); TopologyNode outputNode; MediaFactory.CreateTopologyNode(TopologyType.OutputNode, out outputNode); var majorType = desc.MediaTypeHandler.MajorType; if (majorType == MediaTypeGuids.Video) { Activate activate; videoSampler = new MFSamples(); //retrieve size of video long sz = desc.MediaTypeHandler.CurrentMediaType.Get <long>(new Guid("{1652c33d-d6b2-4012-b834-72030849a37d}")); int height = (int)(sz & uint.MaxValue), width = (int)(sz >> 32); _texture = new Texture2D(width, height, false, SurfaceFormat.Color); mt = new MediaType(); mt.Set(MediaTypeAttributeKeys.MajorType, MediaTypeGuids.Video); // Specify that we want the data to come in as RGB32. mt.Set(MediaTypeAttributeKeys.Subtype, new Guid("00000016-0000-0010-8000-00AA00389B71")); GetMethods(); MFCreateSampleGrabberSinkActivate(mt, videoSampler, out activate); outputNode.Object = activate; } if (majorType == MediaTypeGuids.Audio) { Activate activate; MediaFactory.CreateAudioRendererActivate(out activate); outputNode.Object = activate; } topology.AddNode(sourceNode); topology.AddNode(outputNode); sourceNode.ConnectOutput(0, outputNode, 0); sourceNode.Dispose(); outputNode.Dispose(); } desc.Dispose(); } presDesc.Dispose(); mediaSource.Dispose(); //Play the file cb = new MFCallback(this, session); session.BeginGetEvent(cb, null); session.SetTopology(SessionSetTopologyFlags.Immediate, topology); // Get the clock clock = session.Clock.QueryInterface <PresentationClock>(); // Start playing. Playing = true; }
public Loadout(Section section, FreelancerData freelancerIni) { if (section == null) { throw new ArgumentNullException("section"); } //Equip = new List<Equip>(); Equip = new Dictionary <string, AbstractEquipment>(); int emptyHp = 1; foreach (Entry e in section) { switch (e.Name.ToLowerInvariant()) { case "nickname": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Nickname != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Nickname = e[0].ToString(); break; case "archetype": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Archetype != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Archetype = freelancerIni.Solar.FindSolar(e[0].ToString()); break; case "equip": //if (e.Count < 1 || e.Count > 2) throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); //TODO: Reverse-engineer this properly //HACK: Come up with a proper way of handling this string key = e.Count == 2 ? e[1].ToString() : "__noHardpoint" + (emptyHp++).ToString("d2"); if (e.Count == 2 && e[1].ToString().Trim() == "") { key = "__noHardpoint" + (emptyHp++).ToString("d2"); } if (!Equip.ContainsKey(key)) { Equip.Add(key, freelancerIni.Equipment.FindEquipment(e[0].ToString())); } break; case "cargo": // TODO: Loadout cargo break; case "hull": // TODO: Loadout hull? break; case "addon": // TODO: Loadout addon? break; case "hull_damage": //TODO: Is this real or a disco bug? break; default: FLLog.Error("Loadout", "Invalid Entry in " + section.Name + ": " + e.Name); break; } } }
public override void Run(ThnScriptInstance instance) { ThnObject objA; ThnObject objB; if (!instance.Objects.TryGetValue(Targets[0], out objA)) { FLLog.Error("Thn", "Object doesn't exist " + Targets[0]); return; } if (!instance.Objects.TryGetValue(Targets[1], out objB)) { FLLog.Error("Thn", "Object doesn't exist " + Targets[1]); return; } //Attach GameObjects to eachother GameObject part = null; string tgt_part; if (TargetType == TargetTypes.Hardpoint && !string.IsNullOrEmpty(TargetPart)) { if (objB.Object == null) { FLLog.Error("Thn", "Could not get hardpoints on " + objB.Name); } else { part = new GameObject(); part.Parent = objB.Object; part.Attachment = objB.Object.GetHardpoint(TargetPart); } } if (TargetType == TargetTypes.Part && !string.IsNullOrEmpty(TargetPart)) { if (objB.Object == null || objB.Object.RigidModel == null || objB.Object.RigidModel.Parts == null) { FLLog.Error("Thn", "Could not get parts on " + objB.Name); } else { if (objB.Object.RigidModel.Parts.TryGetValue(TargetPart, out var tgtpart)) { var hp = new Hardpoint(null, tgtpart); part = new GameObject(); part.Parent = objB.Object; part.Attachment = hp; } } } Quaternion lastRotate = Quaternion.Identity; if ((Flags & AttachFlags.Orientation) == AttachFlags.Orientation && (Flags & AttachFlags.OrientationRelative) == AttachFlags.OrientationRelative) { if (part != null) { lastRotate = part.WorldTransform.ExtractRotation(); } else { lastRotate = objB.Rotate.ExtractRotation(); } } instance.AddProcessor(new AttachEntityProcessor() { Duration = Duration, Child = objA, Parent = objB, Part = part, Position = ((Flags & AttachFlags.Position) == AttachFlags.Position), Orientation = ((Flags & AttachFlags.Orientation) == AttachFlags.Orientation), OrientationRelative = ((Flags & AttachFlags.OrientationRelative) == AttachFlags.OrientationRelative), EntityRelative = ((Flags & AttachFlags.EntityRelative) == AttachFlags.EntityRelative), LookAt = ((Flags & AttachFlags.LookAt) == AttachFlags.LookAt), LastRotate = lastRotate, Offset = Offset }); }
public Zone(Section section, FreelancerData data) : base(section, data) { if (section == null) { throw new ArgumentNullException("section"); } MissionType = new List <List <string> >(); FactionWeight = new Dictionary <string, int>(); DensityRestriction = new Dictionary <string, int>(); Encounters = new List <Encounter>(); foreach (Entry e in section) { if (!parentEntry(e)) { switch (e.Name.ToLowerInvariant()) { case "shape": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Shape != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } switch (e[0].ToString().ToLowerInvariant()) { case "sphere": Shape = ZoneShape.SPHERE; break; case "ellipsoid": Shape = ZoneShape.ELLIPSOID; break; case "box": Shape = ZoneShape.BOX; break; case "cylinder": Shape = ZoneShape.CYLINDER; break; case "ring": Shape = ZoneShape.RING; break; } break; case "attack_ids": if (AttackIds != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } AttackIds = new List <IValue>(); foreach (IValue i in e) { AttackIds.Add(i); } break; case "tradelane_attack": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (TradelaneAttack != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } TradelaneAttack = e[0].ToInt32(); break; case "property_flags": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (PropertyFlags != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } PropertyFlags = e[0].ToInt32(); break; case "property_fog_color": if (e.Count != 3) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (PropertyFogColor != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } PropertyFogColor = new Color4(e[0].ToInt32() / 255f, e[1].ToInt32() / 255f, e[2].ToInt32() / 255f, 1f); break; case "music": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Music != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Music = e[0].ToString(); break; case "edge_fraction": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (EdgeFraction != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } EdgeFraction = e[0].ToSingle(); break; case "spacedust": case "pacedust": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Spacedust != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Spacedust = e[0].ToString(); break; case "spacedust_maxparticles": case "spacedusr_maxparticles": case "spacedust_masparticles": case "spacedust _maxparticles": case "spacedust_maxdust": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (SpacedustMaxparticles != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } SpacedustMaxparticles = e[0].ToInt32(); break; case "interference": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Interference != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Interference = e[0].ToSingle(); break; case "power_modifier": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (PowerModifier != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } PowerModifier = e[0].ToSingle(); break; case "drag_modifier": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (DragModifier != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } DragModifier = e[0].ToSingle(); break; case "comment": if (Comment != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Comment = new List <string>(); foreach (IValue i in e) { Comment.Add(i.ToString()); } break; case "lane_id": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (LaneId != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } LaneId = e[0].ToInt32(); break; case "tradelane_down": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (TradelaneDown != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } TradelaneDown = e[0].ToInt32(); break; case "damage": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Damage != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Damage = e[0].ToSingle(); break; case "mission_type": MissionType.Add(new List <string>()); foreach (IValue i in e) { MissionType[MissionType.Count - 1].Add(i.ToString()); } break; case "sort": if (e.Count != 1) { FLLog.Warning("Ini", "Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Sort != null) { FLLog.Warning("Zone", "Duplicate " + e.Name + " Entry in " + section.Name); } Sort = e[0].ToSingle(); break; case "vignette_type": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (VignetteType != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } VignetteType = e[0].ToString(); break; case "toughness": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Toughness != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Toughness = e[0].ToInt32(); break; case "density": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Density != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Density = e[0].ToInt32(); break; case "population_additive": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (PopulationAdditive != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } PopulationAdditive = e[0].ToBoolean(); break; case "zone_creation_distance": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (ZoneCreationDistance != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } ZoneCreationDistance = e[0]; break; case "repop_time": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (RepopTime != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } RepopTime = e[0].ToInt32();; break; case "max_battle_size": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (MaxBattleSize != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } MaxBattleSize = e[0].ToInt32(); break; case "pop_type": if (PopType != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } PopType = new List <string>(); foreach (IValue i in e) { PopType.Add(i.ToString()); } break; case "relief_time": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (ReliefTime != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } ReliefTime = e[0].ToInt32(); break; case "path_label": if (PathLabel != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } PathLabel = e.ToList <IValue>(); break; case "usage": if (Usage != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Usage = new List <string>(); foreach (IValue i in e) { Usage.Add(i.ToString()); } break; case "mission_eligible": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (MissionEligible != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } MissionEligible = e[0].ToBoolean(); break; case "faction_weight": if (e.Count != 2) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (FactionWeight.ContainsKey(e[0].ToString())) { FLLog.Error("Ini", string.Format("Duplicate faction_weight for {0} in {1}, ignoring.", e[0], Nickname ?? "[undefined]")); } else { FactionWeight.Add(e[0].ToString(), e[1].ToInt32()); } break; case "density_restriction": if (e.Count != 2) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (DensityRestriction.ContainsKey(e[1].ToString())) { FLLog.Error("Ini", string.Format("Duplicate density_restriction for {0} in {1}, ignoring.", e[1], Nickname ?? "[undefined]")); } else { DensityRestriction.Add(e[1].ToString(), e[0].ToInt32()); } break; case "encounter": //if (e.Count != 3) throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); //Encounters.Add(new Encounter(e[0].ToString(), e[1].ToInt32(), e[2].ToSingle())); break; case "faction": //TODO: Re-enable encounter parsing //if (Encounters.Count == 0) throw new Exception(e.Name + " before encounter"); //if (e.Count == 1) { //Encounters[Encounters.Count - 1].Factions.Add(e[0].ToString(), 100); //} //else if (e.Count != 2) throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); //else Encounters[Encounters.Count - 1].Factions.Add(e[0].ToString(), e[1].ToSingle()); break; default: //throw new Exception("Invalid Entry in " + section.Name + ": " + e.Name); FLLog.Warning("Zone", "Invalid Entry in " + section.Name + ": " + e.Name); break; } } } }
private void load(IntermediateNode root, ILibFile additionalLibrary) { this.additionalLibrary = additionalLibrary; ready = false; Hardpoints = new List <HardpointDefinition>(); var lvls = new Dictionary <int, VMeshRef>(); foreach (Node node in root) { switch (node.Name.ToLowerInvariant()) { case "exporter version": break; case "vmeshlibrary": IntermediateNode vMeshLibraryNode = node as IntermediateNode; if (VMeshLibrary == null) { VMeshLibrary = new VmsFile(vMeshLibraryNode, this); } else { throw new Exception("Multiple vmeshlibrary nodes in 3db root"); } break; case "material library": IntermediateNode materialLibraryNode = node as IntermediateNode; if (MaterialLibrary == null) { MaterialLibrary = new MatFile(materialLibraryNode, this); } else { throw new Exception("Multiple material library nodes in 3db root"); } break; case "texture library": IntermediateNode textureLibraryNode = node as IntermediateNode; if (TextureLibrary == null) { TextureLibrary = new TxmFile(textureLibraryNode); } else { throw new Exception("Multiple texture library nodes in 3db root"); } break; case "hardpoints": IntermediateNode hardpointsNode = node as IntermediateNode; foreach (Node hpn in hardpointsNode) { if (hpn is LeafNode) { continue; //No nodes here } var hardpointTypeNode = (IntermediateNode)hpn; switch (hardpointTypeNode.Name.ToLowerInvariant()) { case "fixed": foreach (IntermediateNode fixedNode in hardpointTypeNode) { Hardpoints.Add(new FixedHardpointDefinition(fixedNode)); } break; case "revolute": foreach (IntermediateNode revoluteNode in hardpointTypeNode) { Hardpoints.Add(new RevoluteHardpointDefinition(revoluteNode)); } break; default: Hardpoints.Add(new FixedHardpointDefinition(hardpointTypeNode)); break; } } break; case "vmeshpart": { IntermediateNode vMeshPartNode = node as IntermediateNode; if (vMeshPartNode.Count == 1) { LeafNode vMeshRefNode = vMeshPartNode[0] as LeafNode; lvls.Add(0, new VMeshRef(vMeshRefNode.DataSegment, this)); } else { throw new Exception("Invalid VMeshPart: More than one child or zero elements"); } } break; case "multilevel": IntermediateNode multiLevelNode = node as IntermediateNode; foreach (Node multiLevelSubNode in multiLevelNode) { if (multiLevelSubNode.Name.StartsWith("level", StringComparison.OrdinalIgnoreCase)) { if (multiLevelSubNode is LeafNode) { continue; } IntermediateNode levelNode = multiLevelSubNode as IntermediateNode; if (levelNode.Count == 1) { int level = 0; if (!int.TryParse(levelNode.Name.Substring(5), out level)) { throw new Exception("Invalid Level: Missing index"); } IntermediateNode vMeshPartNode = levelNode[0] as IntermediateNode; if (vMeshPartNode.Count == 1) { LeafNode vMeshRefNode = vMeshPartNode[0] as LeafNode; if (vMeshRefNode != null && vMeshRefNode.Name.Equals("vmeshref", StringComparison.OrdinalIgnoreCase)) { lvls.Add(level, new VMeshRef(vMeshRefNode.DataSegment, this)); } } else { throw new Exception("Invalid VMeshPart: More than one child or zero elements"); } } //else throw new Exception("Invalid Level: More than one child or zero elements"); } else if (multiLevelSubNode.Name.Equals("switch2", StringComparison.OrdinalIgnoreCase)) { LeafNode switch2Node = multiLevelSubNode as LeafNode; Switch2 = switch2Node.SingleArrayData; } else { throw new Exception("Invalid node in " + multiLevelNode.Name + ": " + multiLevelSubNode.Name); } } break; case "vmeshwire": VMeshWire = new VMeshWire(node as IntermediateNode, this); break; case "mass properties": // TODO 3db Mass Properties break; case "extent tree": // TODO 3db Extent Tree break; case "materialanim": MaterialAnim = new MaterialAnimCollection((IntermediateNode)node); break; default: FLLog.Error("3db", (Path ?? "") + ": Invalid node: " + node.Name); break; } } //Sort levels in order var lvl2 = new List <VMeshRef>(); for (int i = 0; i < 100; i++) { if (lvls.ContainsKey(i)) { lvl2.Add(lvls[i]); } else { break; } } Levels = lvl2.ToArray(); }
static object GetFromSection(Section s, ReflectionInfo type) { var obj = Activator.CreateInstance(type.Type); ulong bitmask = 0; ulong requiredBits = type.RequiredFields; foreach (var e in s) { //Find entry int idx = -1; for (int i = 0; i < type.Fields.Count; i++) { if (type.Fields[i].Attr.Name.Equals(e.Name, StringComparison.InvariantCultureIgnoreCase)) { idx = i; break; } } //Special Handling if (idx == -1) { bool handled = false; if (type.HandleEntry != null) { handled = (bool)type.HandleEntry.Invoke(obj, new object[] { e }); } if (!handled) { FLLog.Warning("Ini", "Unknown entry " + e.Name + FormatLine(e.File, e.Line, s.Name)); } continue; } var field = type.Fields[idx]; //Warning for duplicates if (!field.Attr.Multiline) { if ((bitmask & (1ul << idx)) != 0) { FLLog.Warning("Ini", "Duplicate of " + field.Attr.Name + FormatLine(e.File, e.Line, s.Name)); } bitmask |= 1ul << idx; } requiredBits &= ~(1ul << idx); var ftype = field.Field.FieldType; Type nType; if ((nType = Nullable.GetUnderlyingType(ftype)) != null) { ftype = nType; } //Fill if (ftype == typeof(string)) { if (ComponentCheck(1, s, e)) { field.Field.SetValue(obj, e[0].ToString()); } } else if (ftype == typeof(float)) { if (ComponentCheck(1, s, e)) { field.Field.SetValue(obj, e[0].ToSingle()); } } else if (ftype == typeof(int)) { if (ComponentCheck(1, s, e)) { field.Field.SetValue(obj, e[0].ToInt32()); } } else if (ftype == typeof(long)) { if (ComponentCheck(1, s, e)) { field.Field.SetValue(obj, e[0].ToInt64()); } } else if (ftype == typeof(bool)) { if (field.Attr.Presence) { field.Field.SetValue(obj, true); } else if (ComponentCheck(1, s, e)) { field.Field.SetValue(obj, e[0].ToBoolean()); } } else if (ftype == typeof(Vector3)) { if (ComponentCheck(3, s, e)) { field.Field.SetValue(obj, new Vector3(e[0].ToSingle(), e[1].ToSingle(), e[2].ToSingle())); } } else if (ftype == typeof(Quaternion)) { if (ComponentCheck(4, s, e)) { field.Field.SetValue(obj, new Quaternion(e[1].ToSingle(), e[2].ToSingle(), e[3].ToSingle(), e[0].ToSingle())); } } else if (ftype == typeof(Vector2)) { if (e.Count == 1 && field.Attr.MinMax) { field.Field.SetValue(obj, new Vector2(-1, e[0].ToSingle())); } else if (ComponentCheck(2, s, e)) { field.Field.SetValue(obj, new Vector2(e[0].ToSingle(), e[1].ToSingle())); } } else if (ftype == typeof(Color4)) { if (ComponentCheck(4, s, e, 3)) { Color4 col; if (e.Count == 3) { col = new Color4(e[0].ToInt32() / 255f, e[1].ToInt32() / 255f, e[2].ToInt32() / 255f, 1f); } else { col = new Color4(e[0].ToInt32() / 255f, e[1].ToInt32() / 255f, e[2].ToInt32() / 255f, e[3].ToInt32() / 255f); } field.Field.SetValue(obj, col); } } else if (ftype == typeof(Color3f)) { if (ComponentCheck(3, s, e)) { field.Field.SetValue(obj, new Color3f(e[0].ToSingle(), e[1].ToSingle(), e[2].ToSingle())); } } else if (ftype == typeof(List <string>)) { if (field.Attr.Multiline) { bitmask &= ~(1ul << idx); //Avoid duplicate warnings if (ComponentCheck(1, s, e)) { var v = (List <string>)field.Field.GetValue(obj); v.Add(e[0].ToString()); } } else if (ComponentCheck(int.MaxValue, s, e, 1)) { field.Field.SetValue(obj, e.Select((x) => x.ToString()).ToList()); } } else if (ftype == typeof(float[])) { if (ComponentCheck(int.MaxValue, s, e, 1)) { var floats = new float[e.Count]; for (int i = 0; i < e.Count; i++) { floats[i] = e[i].ToSingle(); } field.Field.SetValue(obj, floats); } } else if (ftype == typeof(string[])) { if (ComponentCheck(int.MaxValue, s, e, 1)) { var strings = new string[e.Count]; for (int i = 0; i < e.Count; i++) { strings[i] = e[i].ToString(); } field.Field.SetValue(obj, strings); } } else if (ftype.IsEnum) { if (ComponentCheck(1, s, e)) { //TryParse requires generics, wrap in exception handler try { field.Field.SetValue(obj, Enum.Parse(field.Field.FieldType, e[0].ToString(), true)); } catch (Exception) { FLLog.Error("Ini", "Invalid value for enum " + e[0].ToString() + FormatLine(e.File, e.Line, s.Name)); } } } } if (requiredBits != 0) { //These sections crash the game if they don't have required fields //So don't let them be added to lists for (int i = 0; i < 64; i++) { if ((requiredBits & (1ul << i)) != 0) { FLLog.Error("Ini", string.Format("Missing required field {0}{1}", type.Fields[i].Attr.Name, FormatLine(s.File, s.Line, s.Name))); } } return(null); } else { return(obj); } }
public Room(Section section, FreelancerData data) { GameData = data; if (section == null) { throw new ArgumentNullException("section"); } string file = null; SceneScripts = new List <string>(); Hotspots = new List <RoomHotspot>(); ForShipSalePlacements = new List <string>(); foreach (Entry e in section) { switch (e.Name.ToLowerInvariant()) { case "nickname": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (Nickname != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } Nickname = e[0].ToString(); break; case "file": if (e.Count != 1) { throw new Exception("Invalid number of values in " + section.Name + " Entry " + e.Name + ": " + e.Count); } if (file != null) { throw new Exception("Duplicate " + e.Name + " Entry in " + section.Name); } file = e[0].ToString(); break; default: throw new Exception("Invalid Entry in " + section.Name + ": " + e.Name); } } if (VFS.FileExists(data.Freelancer.DataPath + file)) { foreach (Section s in ParseFile(data.Freelancer.DataPath + file)) { switch (s.Name.ToLowerInvariant()) { case "room_info": foreach (Entry e in s) { if (e.Name.ToLowerInvariant() == "set_script") { SceneScripts.Add(e[0].ToString()); } if (e.Name.ToLowerInvariant() == "goodscart_script") { GoodscartScript = e[0].ToString(); } if (e.Name.ToLowerInvariant() == "scene") { if (e.Count == 3 || e.Count == 4) { SceneScripts.Add(e[2].ToString()); } else { SceneScripts.Add(e[1].ToString()); } } } break; case "room_sound": foreach (Entry e in s) { if (e.Name.ToLowerInvariant() == "music") { Music = e[0].ToString(); } } break; case "camera": // TODO Room camera foreach (Entry e in s) { if (e.Name.ToLowerInvariant() == "name") { Camera = e[0].ToString(); } } break; case "spiels": // TODO Room spiels break; case "playershipplacement": foreach (Entry e in s) { switch (e.Name.ToLowerInvariant()) { case "name": PlayerShipPlacement = e[0].ToString(); break; case "launching_script": LaunchingScript = e[0].ToString(); break; case "landing_script": LandingScript = e[0].ToString(); break; } } break; case "characterplacement": foreach (Entry e in s) { switch (e.Name.ToLowerInvariant()) { case "start_script": StartScript = e[0].ToString(); break; } } break; case "forsaleshipplacement": foreach (Entry e in s) { if (e.Name.Equals("name", StringComparison.OrdinalIgnoreCase)) { ForShipSalePlacements.Add(e[0].ToString()); } } break; case "hotspot": // TODO Room hotspot var hotspot = new RoomHotspot(); foreach (Entry e in s) { switch (e.Name.ToLowerInvariant()) { case "name": hotspot.Name = e[0].ToString(); break; case "behavior": hotspot.Behavior = e[0].ToString(); break; case "room_switch": hotspot.RoomSwitch = e[0].ToString(); break; case "set_virtual_room": hotspot.VirtualRoom = e[0].ToString(); break; } } Hotspots.Add(hotspot); break; case "flashlightset": // TODO Room flashlightset break; case "flashlightline": // TODO Room flashlightline break; default: throw new Exception("Invalid Section in " + file + ": " + s.Name); } } } else { FLLog.Error("Ini", "Room file not found " + file); } }