diff --git a/Building.md b/Building.md index 0d759952c..dd8ae347e 100644 --- a/Building.md +++ b/Building.md @@ -8,17 +8,17 @@ This file is a WIP set of instructions for building openBVE from source. #### When to use .NET Framework -- Visual Studio 2017 or later, x86 or x64 -- .NET Framework 4.7.2 or later, x86 or x64 +- Visual Studio 2017 or later +- .NET Framework 4.7.2 or later #### When to use Mono -- Mono 5.20.1 or later, x86 or x64 +- Mono 5.20.1 or later - NuGet client 2.16 or later ### Linux -- Mono 5.20.1 or later, x86 or x64 +- Mono 5.20.1 or later - NuGet client 2.16 or later - OpenAL - GNU Make @@ -50,6 +50,19 @@ echo -e '#!/bin/sh\nexec /usr/bin/mono /usr/local/lib/nuget.exe "$@"' | sudo tee sudo chmod 755 /usr/local/bin/nuget ``` +### Required Mono Components + +NOTE: Depending on the install type you select, Mono will not install all components by default. These are required: + +- mono-runtime +- libmono-corlib4.5-cil +- libmono-system-drawing4.0-cil +- libmono-system-windows-forms4.0-cil +- libmono-system4.0-cil +- libmono-system-xml-linq4.0-cil +- libmono-i18n4.0-all +- libmono-microsoft-csharp4.0-cil + #### Required Additional System Libraries - libusb-1.0 @@ -59,7 +72,7 @@ sudo chmod 755 /usr/local/bin/nuget ### Mac -- Mono 5.20.1 or later, x86 only +- Mono 5.20.1 or later - NuGet client 2.16 or later - OpenAL - GNU Make diff --git a/assets/Shaders/default.frag b/assets/Shaders/default.frag index eeb8cc2c7..f9a071321 100644 --- a/assets/Shaders/default.frag +++ b/assets/Shaders/default.frag @@ -19,7 +19,7 @@ out vec4 fragColor; void main(void) { - vec4 finalColor = vec4(oColor.rgb, 1.0) * texture(uTexture, oUv); + vec4 finalColor = vec4(oColor.rgb, 1.0) * texture(uTexture, oUv); // NOTE: only want the RGB of the color, A is passed in as part of opacity if((uMaterialFlags & 1) == 0 && (uMaterialFlags & 4) == 0) { diff --git a/source/AssimpParser/Wavefront/ObjFileMtlImporter.cs b/source/AssimpParser/Wavefront/ObjFileMtlImporter.cs index 45cc773ed..5400510a4 100644 --- a/source/AssimpParser/Wavefront/ObjFileMtlImporter.cs +++ b/source/AssimpParser/Wavefront/ObjFileMtlImporter.cs @@ -252,19 +252,15 @@ private void Load(string[] lines) // Loads a color definition private void GetColorRGBA(ref Color128 color) { - //Debug.Assert(color != null); - - float r = 0, g = 0, b = 0; - GetFloat(out r); - color.R = r; + GetFloat(out color.R); // we have to check if color is default 0 with only one token if (!IsLineEnd(DataIt)) { try { - GetFloat(out g); - GetFloat(out b); + GetFloat(out color.G); + GetFloat(out color.B); } catch { @@ -276,8 +272,6 @@ private void GetColorRGBA(ref Color128 color) */ } } - color.G = g; - color.B = b; } // Loads a single float value. @@ -291,60 +285,60 @@ private void GetFloatValue(out float result) // Gets a texture name from data. private void GetTexture() { - int clampIndex = -1; + int clampIndex; - if (String.Compare(Buffer, DataIt, DiffuseTexture, 0, DiffuseTexture.Length, StringComparison.OrdinalIgnoreCase) == 0) + if (string.Compare(Buffer, DataIt, DiffuseTexture, 0, DiffuseTexture.Length, StringComparison.OrdinalIgnoreCase) == 0) { // Diffuse texture clampIndex = (int)Material.TextureType.TextureDiffuseType; GetTextureOptionAndName(clampIndex, ref Model.CurrentMaterial.Texture); } - else if (String.Compare(Buffer, DataIt, AmbientTexture, 0, AmbientTexture.Length, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(Buffer, DataIt, AmbientTexture, 0, AmbientTexture.Length, StringComparison.OrdinalIgnoreCase) == 0) { // Ambient texture clampIndex = (int)Material.TextureType.TextureAmbientType; GetTextureOptionAndName(clampIndex, ref Model.CurrentMaterial.TextureAmbient); } - else if (String.Compare(Buffer, DataIt, SpecularTexture, 0, SpecularTexture.Length, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(Buffer, DataIt, SpecularTexture, 0, SpecularTexture.Length, StringComparison.OrdinalIgnoreCase) == 0) { // Specular texture clampIndex = (int)Material.TextureType.TextureSpecularType; GetTextureOptionAndName(clampIndex, ref Model.CurrentMaterial.TextureSpecular); } - else if (String.Compare(Buffer, DataIt, OpacityTexture, 0, OpacityTexture.Length, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(Buffer, DataIt, OpacityTexture, 0, OpacityTexture.Length, StringComparison.OrdinalIgnoreCase) == 0) { // Opacity texture clampIndex = (int)Material.TextureType.TextureOpacityType; GetTextureOptionAndName(clampIndex, ref Model.CurrentMaterial.TextureOpacity); } - else if (String.Compare(Buffer, DataIt, EmissiveTexture1, 0, EmissiveTexture1.Length, StringComparison.OrdinalIgnoreCase) == 0 - || String.Compare(Buffer, DataIt, EmissiveTexture2, 0, EmissiveTexture2.Length, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(Buffer, DataIt, EmissiveTexture1, 0, EmissiveTexture1.Length, StringComparison.OrdinalIgnoreCase) == 0 + || string.Compare(Buffer, DataIt, EmissiveTexture2, 0, EmissiveTexture2.Length, StringComparison.OrdinalIgnoreCase) == 0) { // Emissive texture clampIndex = (int)Material.TextureType.TextureEmissiveType; GetTextureOptionAndName(clampIndex, ref Model.CurrentMaterial.TextureEmissive); } - else if (String.Compare(Buffer, DataIt, BumpTexture1, 0, BumpTexture1.Length, StringComparison.OrdinalIgnoreCase) == 0 - || String.Compare(Buffer, DataIt, BumpTexture2, 0, BumpTexture2.Length, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(Buffer, DataIt, BumpTexture1, 0, BumpTexture1.Length, StringComparison.OrdinalIgnoreCase) == 0 + || string.Compare(Buffer, DataIt, BumpTexture2, 0, BumpTexture2.Length, StringComparison.OrdinalIgnoreCase) == 0) { // Bump texture clampIndex = (int)Material.TextureType.TextureBumpType; GetTextureOptionAndName(clampIndex, ref Model.CurrentMaterial.TextureBump); } - else if (String.Compare(Buffer, DataIt, NormalTexture, 0, NormalTexture.Length, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(Buffer, DataIt, NormalTexture, 0, NormalTexture.Length, StringComparison.OrdinalIgnoreCase) == 0) { // Normal map clampIndex = (int)Material.TextureType.TextureNormalType; GetTextureOptionAndName(clampIndex, ref Model.CurrentMaterial.TextureNormal); } - else if (String.Compare(Buffer, DataIt, ReflectionTexture, 0, ReflectionTexture.Length, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(Buffer, DataIt, ReflectionTexture, 0, ReflectionTexture.Length, StringComparison.OrdinalIgnoreCase) == 0) { // Reflection texture(s) // Do nothing here return; } - else if (String.Compare(Buffer, DataIt, DisplacementTexture1, 0, DisplacementTexture1.Length, StringComparison.OrdinalIgnoreCase) == 0 - || String.Compare(Buffer, DataIt, DisplacementTexture2, 0, DisplacementTexture2.Length, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(Buffer, DataIt, DisplacementTexture1, 0, DisplacementTexture1.Length, StringComparison.OrdinalIgnoreCase) == 0 + || string.Compare(Buffer, DataIt, DisplacementTexture2, 0, DisplacementTexture2.Length, StringComparison.OrdinalIgnoreCase) == 0) { // Displacement texture clampIndex = (int)Material.TextureType.TextureDispType; @@ -390,60 +384,60 @@ private void GetTextureOptionAndName(int clampIndex, ref string result) //skip option key and value int skipToken = 1; - if (String.Compare(Buffer, DataIt, ClampOption, 0, ClampOption.Length, StringComparison.OrdinalIgnoreCase) == 0) + if (string.Compare(Buffer, DataIt, ClampOption, 0, ClampOption.Length, StringComparison.OrdinalIgnoreCase) == 0) { DataIt = GetNextToken(DataIt, DataEnd); string tmp; CopyNextWord(out tmp); - if (String.Compare(tmp, 0, "on", 0, 2, StringComparison.OrdinalIgnoreCase) == 0) + if (string.Compare(tmp, 0, "on", 0, 2, StringComparison.OrdinalIgnoreCase) == 0) { clamp = true; } skipToken = 2; } - else if (String.Compare(Buffer, DataIt, TypeOption, 0, TypeOption.Length, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(Buffer, DataIt, TypeOption, 0, TypeOption.Length, StringComparison.OrdinalIgnoreCase) == 0) { DataIt = GetNextToken(DataIt, DataEnd); string tmp; CopyNextWord(out tmp); - if (String.Compare(tmp, 0, "cube_top", 0, 8, StringComparison.OrdinalIgnoreCase) == 0) + if (string.Compare(tmp, 0, "cube_top", 0, 8, StringComparison.OrdinalIgnoreCase) == 0) { clampIndex = (int)Material.TextureType.TextureReflectionCubeTopType; GetTextureName(ref Model.CurrentMaterial.TextureReflection[0]); already = true; } - else if (String.Compare(tmp, 0, "cube_bottom", 0, 11, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(tmp, 0, "cube_bottom", 0, 11, StringComparison.OrdinalIgnoreCase) == 0) { clampIndex = (int)Material.TextureType.TextureReflectionCubeBottomType; GetTextureName(ref Model.CurrentMaterial.TextureReflection[1]); already = true; } - else if (String.Compare(tmp, 0, "cube_front", 0, 10, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(tmp, 0, "cube_front", 0, 10, StringComparison.OrdinalIgnoreCase) == 0) { clampIndex = (int)Material.TextureType.TextureReflectionCubeFrontType; GetTextureName(ref Model.CurrentMaterial.TextureReflection[2]); already = true; } - else if (String.Compare(tmp, 0, "cube_back", 0, 9, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(tmp, 0, "cube_back", 0, 9, StringComparison.OrdinalIgnoreCase) == 0) { clampIndex = (int)Material.TextureType.TextureReflectionCubeBackType; GetTextureName(ref Model.CurrentMaterial.TextureReflection[3]); already = true; } - else if (String.Compare(tmp, 0, "cube_left", 0, 9, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(tmp, 0, "cube_left", 0, 9, StringComparison.OrdinalIgnoreCase) == 0) { clampIndex = (int)Material.TextureType.TextureReflectionCubeLeftType; GetTextureName(ref Model.CurrentMaterial.TextureReflection[4]); already = true; } - else if (String.Compare(tmp, 0, "cube_right", 0, 10, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(tmp, 0, "cube_right", 0, 10, StringComparison.OrdinalIgnoreCase) == 0) { clampIndex = (int)Material.TextureType.TextureReflectionCubeRightType; GetTextureName(ref Model.CurrentMaterial.TextureReflection[5]); already = true; } - else if (String.Compare(tmp, 0, "sphere", 0, 6, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(tmp, 0, "sphere", 0, 6, StringComparison.OrdinalIgnoreCase) == 0) { clampIndex = (int)Material.TextureType.TextureReflectionSphereType; GetTextureName(ref Model.CurrentMaterial.TextureReflection[0]); @@ -452,22 +446,22 @@ private void GetTextureOptionAndName(int clampIndex, ref string result) skipToken = 2; } - else if (String.Compare(Buffer, DataIt, BlendUOption, 0, BlendUOption.Length, StringComparison.OrdinalIgnoreCase) == 0 - || String.Compare(Buffer, DataIt, BlendVOption, 0, BlendVOption.Length, StringComparison.OrdinalIgnoreCase) == 0 - || String.Compare(Buffer, DataIt, BoostOption, 0, BoostOption.Length, StringComparison.OrdinalIgnoreCase) == 0 - || String.Compare(Buffer, DataIt, ResolutionOption, 0, ResolutionOption.Length, StringComparison.OrdinalIgnoreCase) == 0 - || String.Compare(Buffer, DataIt, BumpOption, 0, BumpOption.Length, StringComparison.OrdinalIgnoreCase) == 0 - || String.Compare(Buffer, DataIt, ChannelOption, 0, ChannelOption.Length, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(Buffer, DataIt, BlendUOption, 0, BlendUOption.Length, StringComparison.OrdinalIgnoreCase) == 0 + || string.Compare(Buffer, DataIt, BlendVOption, 0, BlendVOption.Length, StringComparison.OrdinalIgnoreCase) == 0 + || string.Compare(Buffer, DataIt, BoostOption, 0, BoostOption.Length, StringComparison.OrdinalIgnoreCase) == 0 + || string.Compare(Buffer, DataIt, ResolutionOption, 0, ResolutionOption.Length, StringComparison.OrdinalIgnoreCase) == 0 + || string.Compare(Buffer, DataIt, BumpOption, 0, BumpOption.Length, StringComparison.OrdinalIgnoreCase) == 0 + || string.Compare(Buffer, DataIt, ChannelOption, 0, ChannelOption.Length, StringComparison.OrdinalIgnoreCase) == 0) { skipToken = 2; } - else if (String.Compare(Buffer, DataIt, ModifyMapOption, 0, ModifyMapOption.Length, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(Buffer, DataIt, ModifyMapOption, 0, ModifyMapOption.Length, StringComparison.OrdinalIgnoreCase) == 0) { skipToken = 3; } - else if (String.Compare(Buffer, DataIt, OffsetOption, 0, OffsetOption.Length, StringComparison.OrdinalIgnoreCase) == 0 - || String.Compare(Buffer, DataIt, ScaleOption, 0, ScaleOption.Length, StringComparison.OrdinalIgnoreCase) == 0 - || String.Compare(Buffer, DataIt, TurbulenceOption, 0, TurbulenceOption.Length, StringComparison.OrdinalIgnoreCase) == 0) + else if (string.Compare(Buffer, DataIt, OffsetOption, 0, OffsetOption.Length, StringComparison.OrdinalIgnoreCase) == 0 + || string.Compare(Buffer, DataIt, ScaleOption, 0, ScaleOption.Length, StringComparison.OrdinalIgnoreCase) == 0 + || string.Compare(Buffer, DataIt, TurbulenceOption, 0, TurbulenceOption.Length, StringComparison.OrdinalIgnoreCase) == 0) { skipToken = 4; } diff --git a/source/AssimpParser/Wavefront/ObjFileParser.cs b/source/AssimpParser/Wavefront/ObjFileParser.cs index 228dd7758..21cc7e2aa 100644 --- a/source/AssimpParser/Wavefront/ObjFileParser.cs +++ b/source/AssimpParser/Wavefront/ObjFileParser.cs @@ -82,7 +82,6 @@ using System.Diagnostics; using System.Globalization; using System.IO; -using OpenBveApi.Interface; using OpenBveApi.Math; using OpenBveApi.Objects; @@ -530,14 +529,7 @@ protected void GetFace(PrimitiveType type) } // Set active material, if one set - if (Model.CurrentMaterial != null) - { - face.Material = Model.CurrentMaterial; - } - else - { - face.Material = Model.DefaultMaterial; - } + face.Material = Model.CurrentMaterial ?? Model.DefaultMaterial; // Create a default object, if nothing is there if (Model.Current == null) diff --git a/source/AssimpParser/X/XFileHelper.cs b/source/AssimpParser/X/XFileHelper.cs index c48280467..95fd40d52 100644 --- a/source/AssimpParser/X/XFileHelper.cs +++ b/source/AssimpParser/X/XFileHelper.cs @@ -109,7 +109,7 @@ public TexEntry(string name, bool isNormalMap = false) public class Material { public string Name; - public bool IsReference; // if true, mName holds a name by which the actual material can be found in the material list + public readonly bool IsReference; // if true, mName holds a name by which the actual material can be found in the material list public Color128 Diffuse; public float SpecularExponent; public Color128 Specular; @@ -117,21 +117,37 @@ public class Material public List Textures = new List(); public uint SceneIndex; // the index under which it was stored in the scene's material list + + public Material(bool isReference) + { + IsReference = isReference; + } } /** Helper structure to represent a bone weight */ public class BoneWeight { - public uint Vertex; + public readonly uint Vertex; public float Weight; + + public BoneWeight(uint vertex) + { + Vertex = vertex; + } + } /** Helper structure to represent a bone in a mesh */ public class Bone { - public string Name; + public readonly string Name; public List Weights = new List(); public Matrix4D OffsetMatrix; + + public Bone(string name) + { + Name = name; + } } /** Helper structure to represent an XFile mesh */ @@ -190,8 +206,13 @@ public class AnimBone /** Helper structure to represent an animation set in a XFile */ public class Animation { - public string Name; + public readonly string Name; public List Anims = new List(); + + public Animation(string name) + { + Name = name; + } } /** Helper structure analogue to aiScene */ diff --git a/source/AssimpParser/X/XFileParser.cs b/source/AssimpParser/X/XFileParser.cs index 5bb392ea8..f3207873e 100644 --- a/source/AssimpParser/X/XFileParser.cs +++ b/source/AssimpParser/X/XFileParser.cs @@ -231,7 +231,6 @@ public XFileParser(byte[] buffer) MemoryStream outputStream = new MemoryStream(); int currentBlock = 0; byte[] previousBlockBytes = new byte[(int)MSZIP_BLOCK]; - byte[] blockBytes; while (currentPosition + 3 < End) { #pragma warning disable CS0219 @@ -273,7 +272,7 @@ public XFileParser(byte[] buffer) inputStream.Position = currentPosition + 2; // Decompress the compressed block - blockBytes = new byte[compressedBlockSize]; + byte[] blockBytes = new byte[compressedBlockSize]; inputStream.Read(blockBytes, 0, compressedBlockSize); byte[] decompressedBytes = DeflateCompression.ZlibDecompressWithDictionary(blockBytes, currentBlock == 0 ? null : previousBlockBytes); @@ -614,8 +613,7 @@ protected void ParseDataObjectSkinWeights(ref Mesh mesh) string transformNodeName; GetNextTokenAsString(out transformNodeName); - Bone bone = new Bone(); - bone.Name = transformNodeName; + Bone bone = new Bone(transformNodeName); // read vertex weights uint numWeights = ReadInt(); @@ -623,8 +621,7 @@ protected void ParseDataObjectSkinWeights(ref Mesh mesh) for (int a = 0; a < (int)numWeights; a++) { - BoneWeight weight = new BoneWeight(); - weight.Vertex = ReadInt(); + BoneWeight weight = new BoneWeight(ReadInt()); bone.Weights.Add(weight); } @@ -846,8 +843,7 @@ protected void ParseDataObjectMeshMaterialList(ref Mesh mesh) { // template materials string matName = GetNextToken(); - Material material = new Material(); - material.IsReference = true; + Material material = new Material(true); //Use default BVE white color so this is visible if the global material is missing, otherwise will be overwritten material.Diffuse = Color128.White; material.Name = matName; @@ -875,7 +871,7 @@ protected void ParseDataObjectMeshMaterialList(ref Mesh mesh) protected void ParseDataObjectMaterial(out Material material) { - material = new Material(); + material = new Material(false); string matName; ReadHeadOfDataObject(out matName); @@ -884,7 +880,6 @@ protected void ParseDataObjectMaterial(out Material material) matName = "material" + LineNumber; } material.Name = matName; - material.IsReference = false; // read material values material.Diffuse = ReadRGBA(); @@ -938,8 +933,7 @@ protected void ParseDataObjectAnimationSet() string animName; ReadHeadOfDataObject(out animName); - Animation anim = new Animation(); - anim.Name = animName; + Animation anim = new Animation(animName); while (true) { @@ -1577,7 +1571,7 @@ protected uint ReadInt() protected float ReadFloat() { - float result = 0.0f; + float result; if (IsBinaryFormat) { @@ -1605,26 +1599,20 @@ protected float ReadFloat() currentPosition += 8; return result; } - else - { - currentPosition = End; - return 0.0f; - } + + currentPosition = End; + return 0.0f; } - else + + if (End - currentPosition >= 4) { - if (End - currentPosition >= 4) - { - result = BitConverter.ToSingle(Buffer, currentPosition); - currentPosition += 4; - return result; - } - else - { - currentPosition = End; - return 0.0f; - } + result = BitConverter.ToSingle(Buffer, currentPosition); + currentPosition += 4; + return result; } + + currentPosition = End; + return 0.0f; } // text version @@ -1704,10 +1692,7 @@ protected void ThrowException(string text) { throw new Exception(text); } - else - { - throw new Exception("Line " + LineNumber + ": " + text); - } + throw new Exception("Line " + LineNumber + ": " + text); } // Filters the imported hierarchy for some degenerated cases that some exporters produce. diff --git a/source/LibRender2/BaseRenderer.cs b/source/LibRender2/BaseRenderer.cs index c96ac6dbd..74a99329a 100644 --- a/source/LibRender2/BaseRenderer.cs +++ b/source/LibRender2/BaseRenderer.cs @@ -279,7 +279,7 @@ protected BaseRenderer(HostInterface CurrentHost, BaseOptions CurrentOptions, Fi projectionMatrixList = new List(); viewMatrixList = new List(); - Fonts = new Fonts(currentHost, fileSystem, currentOptions.Font); + Fonts = new Fonts(currentHost, currentOptions.Font); VisibilityThread = new Thread(vt); VisibilityThread.Start(); } @@ -735,7 +735,7 @@ private void UpdateQuadTreeVisibility() private void UpdateLegacyVisibility(double TrackPosition) { - if (ObjectsSortedByStart == null || ObjectsSortedByStart.Length == 0) + if (ObjectsSortedByStart == null || ObjectsSortedByStart.Length == 0 || StaticObjectStates.Count == 0) { return; } @@ -1278,6 +1278,7 @@ public void RenderFace(Shader Shader, ObjectState State, MeshFace Face, bool IsD // daytime polygon { // texture + // ReSharper disable once PossibleInvalidOperationException if (material.DaytimeTexture != null && currentHost.LoadTexture(ref material.DaytimeTexture, (OpenGlTextureWrapMode)material.WrapMode)) { if (LastBoundTexture != material.DaytimeTexture.OpenGlTextures[(int)material.WrapMode]) @@ -1508,6 +1509,7 @@ public void RenderFaceImmediateMode(ObjectState State, MeshFace Face, Matrix4D m // texture if (material.DaytimeTexture != null) { + // ReSharper disable once PossibleInvalidOperationException if (currentHost.LoadTexture(ref material.DaytimeTexture, (OpenGlTextureWrapMode)material.WrapMode)) { GL.Enable(EnableCap.Texture2D); @@ -1567,7 +1569,7 @@ public void RenderFaceImmediateMode(ObjectState State, MeshFace Face, Matrix4D m if (vertices[Face.Vertices[i].Index] is ColoredVertex) { ColoredVertex v = (ColoredVertex)vertices[Face.Vertices[i].Index]; - GL.Color3(v.Color.R, v.Color.G, v.Color.B); + GL.Color4(v.Color.R, v.Color.G, v.Color.B, v.Color.A); } GL.Vertex3(vertices[Face.Vertices[i].Index].Coordinates.X, vertices[Face.Vertices[i].Index].Coordinates.Y, -vertices[Face.Vertices[i].Index].Coordinates.Z); diff --git a/source/LibRender2/Camera/Camera.cs b/source/LibRender2/Camera/Camera.cs index 9fc7b7a8d..5723f86a6 100644 --- a/source/LibRender2/Camera/Camera.cs +++ b/source/LibRender2/Camera/Camera.cs @@ -1,6 +1,5 @@ using System; using LibRender2.Camera; -using LibRender2.Objects; using LibRender2.Viewports; using OpenBveApi.Graphics; using OpenBveApi.Math; diff --git a/source/LibRender2/Loading/Loading.cs b/source/LibRender2/Loading/Loading.cs index 3e6a6915d..efcf2ec02 100644 --- a/source/LibRender2/Loading/Loading.cs +++ b/source/LibRender2/Loading/Loading.cs @@ -72,12 +72,6 @@ public void CompleteLoading() } /// Sets the loading screen background to a custom image - public void SetLoadingBkg(string fileName) - { - renderer.TextureManager.RegisterTexture(fileName, out TextureLoadingBkg); - customLoadScreen = true; - } - public void SetLoadingBkg(Texture texture) { if (customLoadScreen || texture == null) @@ -125,7 +119,7 @@ public void DrawLoadingScreen(OpenGlFont Font, double RouteProgress, double Trai // (the route custom image is loaded in OldParsers/CsvRwRouteParser.cs) if (!customLoadScreen) { - if (renderer.ProgramLogo != null && renderer.LoadLogo()) + if (showLogo && renderer.ProgramLogo != null && renderer.LoadLogo()) { // place the centre of the logo at from the screen top int logoTop = (int)(renderer.Screen.Height * logoCentreYFactor - renderer.ProgramLogo.Height / 2.0); diff --git a/source/LibRender2/Objects/ObjectLibrary.cs b/source/LibRender2/Objects/ObjectLibrary.cs index 392ec67cc..7a858f945 100644 --- a/source/LibRender2/Objects/ObjectLibrary.cs +++ b/source/LibRender2/Objects/ObjectLibrary.cs @@ -153,7 +153,11 @@ public void ShowObject(ObjectState State, ObjectType Type) else { State.Prototype.Mesh.Materials[face.Material].DaytimeTexture.Origin.GetTexture(out daytimeTexture); - TextureManager.textureCache.Add(State.Prototype.Mesh.Materials[face.Material].DaytimeTexture.Origin, daytimeTexture); + if (!TextureManager.textureCache.ContainsKey(State.Prototype.Mesh.Materials[face.Material].DaytimeTexture.Origin)) // because getting the Origin may change the ref + { + TextureManager.textureCache.Add(State.Prototype.Mesh.Materials[face.Material].DaytimeTexture.Origin, daytimeTexture); + } + } TextureTransparencyType transparencyType = daytimeTexture.GetTransparencyType(); diff --git a/source/LibRender2/Text/Fonts.cs b/source/LibRender2/Text/Fonts.cs index d2384b957..120612333 100644 --- a/source/LibRender2/Text/Fonts.cs +++ b/source/LibRender2/Text/Fonts.cs @@ -1,7 +1,4 @@ - -using System.Drawing; -using System.Drawing.Text; -using OpenBveApi.FileSystem; +using System.Drawing; using OpenBveApi.Hosts; namespace LibRender2.Text @@ -71,7 +68,7 @@ public OpenGlFont NextLargestFont(OpenGlFont currentFont) } } - public Fonts(HostInterface host, FileSystem fileSystem, string fontName) + public Fonts(HostInterface host, string fontName) { currentHost = host; FontFamily uiFont = FontFamily.GenericSansSerif; diff --git a/source/ObjectViewer/FunctionScripts.cs b/source/ObjectViewer/FunctionScripts.cs index 0b25bc1b2..68471ff23 100644 --- a/source/ObjectViewer/FunctionScripts.cs +++ b/source/ObjectViewer/FunctionScripts.cs @@ -290,6 +290,13 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr Function.Stack[s] = 0.0; } s++; break; + case Instructions.TrainLength: + if (Train != null) { + Function.Stack[s] = Train.Length; + } else { + Function.Stack[s] = 0.0; + } + s++; break; case Instructions.TrainSpeed: if (Train != null) { Function.Stack[s] = Train.Cars[CarIndex].CurrentSpeed; diff --git a/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs b/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs index 0cf18026a..f41048f5a 100644 --- a/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs +++ b/source/OpenBVE/Game/ObjectManager/AnimatedObjects/FunctionScripts.cs @@ -288,6 +288,13 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainBase Tr Function.Stack[s] = 0.0; } s++; break; + case Instructions.TrainLength: + if (Train != null) { + Function.Stack[s] = Train.Length; + } else { + Function.Stack[s] = 0.0; + } + s++; break; case Instructions.TrainSpeed: if (Train != null) { Function.Stack[s] = Train.Cars[CarIndex].CurrentSpeed; diff --git a/source/OpenBVE/Graphics/HUD/HUD.Element.cs b/source/OpenBVE/Graphics/HUD/HUD.Element.cs index 6efaddfa7..e4b170f45 100644 --- a/source/OpenBVE/Graphics/HUD/HUD.Element.cs +++ b/source/OpenBVE/Graphics/HUD/HUD.Element.cs @@ -42,7 +42,7 @@ internal Element() this.OverlayColor = Color32.White; this.TextColor = Color32.White; this.TextPosition = new Vector2(); - this.TextAlignment = new Vector2(-1, 0); + this.TextAlignment = Vector2.Left; this.Font = Program.Renderer.Fonts.VerySmallFont; this.TextShadow = true; this.Text = null; diff --git a/source/OpenBVE/Graphics/HUD/HUD.cs b/source/OpenBVE/Graphics/HUD/HUD.cs index bf2589087..e01a569f9 100644 --- a/source/OpenBVE/Graphics/HUD/HUD.cs +++ b/source/OpenBVE/Graphics/HUD/HUD.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Windows.Forms; using OpenBveApi.Colors; +using OpenBveApi.Math; using OpenBveApi.Sounds; using SoundManager; @@ -83,26 +84,9 @@ internal static void LoadHUD() } break; case "position": - if (Arguments.Length == 2) + if (!Vector2.TryParse(Arguments, out CurrentHudElements[Length - 1].Position)) { - float x, y; - if (!float.TryParse(Arguments[0], NumberStyles.Float, Culture, out x)) - { - MessageBox.Show("X is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); - } - else if (!float.TryParse(Arguments[1], NumberStyles.Float, Culture, out y)) - { - MessageBox.Show("Y is invalid in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); - } - else - { - CurrentHudElements[Length - 1].Position.X = x; - CurrentHudElements[Length - 1].Position.Y = y; - } - } - else - { - MessageBox.Show("Incorrect number of arguments supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); + MessageBox.Show("Invalid Vector2 supplied in " + Command + " at line " + (i + 1).ToString(Culture) + " in " + File); } break; case "alignment": diff --git a/source/OpenBVE/Graphics/Renderers/Overlays.Debug.cs b/source/OpenBVE/Graphics/Renderers/Overlays.Debug.cs index 42ec02a7f..47826acba 100644 --- a/source/OpenBVE/Graphics/Renderers/Overlays.Debug.cs +++ b/source/OpenBVE/Graphics/Renderers/Overlays.Debug.cs @@ -232,7 +232,7 @@ private void RenderDebugOverlays() private void RenderATSDebugOverlay() { // debug - renderer.Rectangle.Draw(null, new Vector2(0.0f, 0.0f), new Vector2(renderer.Screen.Width, renderer.Screen.Height), Color128.SemiTransparentGrey); + renderer.Rectangle.Draw(null, Vector2.Null, new Vector2(renderer.Screen.Width, renderer.Screen.Height), Color128.SemiTransparentGrey); string[] Lines; if (TrainManager.PlayerTrain.Plugin.Panel.Length > 0) { diff --git a/source/OpenBVE/System/Host.cs b/source/OpenBVE/System/Host.cs index 20c6cb8ea..621c22a0e 100644 --- a/source/OpenBVE/System/Host.cs +++ b/source/OpenBVE/System/Host.cs @@ -565,7 +565,7 @@ public override void AddScore(int Score, string Message, MessageColor Color, dou { Value = Score, Color = Color, - RendererPosition = new Vector2(0, 0), + RendererPosition = Vector2.Null, RendererAlpha = 0.0, Text = Message, Timeout = Timeout diff --git a/source/OpenBVE/System/MainLoop.cs b/source/OpenBVE/System/MainLoop.cs index 7e62acae7..99c328e88 100644 --- a/source/OpenBVE/System/MainLoop.cs +++ b/source/OpenBVE/System/MainLoop.cs @@ -504,7 +504,7 @@ internal static void RestoreCameraSettings() { case CameraViewMode.Interior: case CameraViewMode.InteriorLookAhead: - Program.Renderer.Camera.Alignment = TrainManagerBase.PlayerTrain.Cars[TrainManagerBase.PlayerTrain.CameraCar].InteriorCamera; + Program.Renderer.Camera.Alignment = TrainManagerBase.PlayerTrain.Cars[TrainManagerBase.PlayerTrain.CameraCar].InteriorCamera ?? TrainManagerBase.PlayerTrain.Cars[TrainManagerBase.PlayerTrain.DriverCar].InteriorCamera; break; case CameraViewMode.Exterior: Program.Renderer.Camera.Alignment = Program.Renderer.Camera.SavedExterior; diff --git a/source/OpenBVE/UserInterface/formMain.Designer.cs b/source/OpenBVE/UserInterface/formMain.Designer.cs index 4f248b37d..e676437da 100644 --- a/source/OpenBVE/UserInterface/formMain.Designer.cs +++ b/source/OpenBVE/UserInterface/formMain.Designer.cs @@ -603,10 +603,9 @@ private void InitializeComponent() { this.buttonClose.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonClose.Location = new System.Drawing.Point(8, 599); this.buttonClose.Name = "buttonClose"; - this.buttonClose.Size = new System.Drawing.Size(144, 24); + this.buttonClose.Size = new System.Drawing.Size(144, 26); this.buttonClose.TabIndex = 5; this.buttonClose.Text = "Close"; - this.buttonClose.UseVisualStyleBackColor = true; this.buttonClose.Click += new System.EventHandler(this.buttonClose_Click); // // panelStart @@ -651,7 +650,7 @@ private void InitializeComponent() { this.labelMode.ForeColor = System.Drawing.Color.Black; this.labelMode.Location = new System.Drawing.Point(16, 601); this.labelMode.Name = "labelMode"; - this.labelMode.Size = new System.Drawing.Size(128, 16); + this.labelMode.Size = new System.Drawing.Size(128, 18); this.labelMode.TabIndex = 10; this.labelMode.Text = "Mode of driving:"; this.labelMode.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -907,7 +906,7 @@ private void InitializeComponent() { this.labelReverseConsist.ForeColor = System.Drawing.SystemColors.ControlText; this.labelReverseConsist.Location = new System.Drawing.Point(8, 59); this.labelReverseConsist.Name = "labelReverseConsist"; - this.labelReverseConsist.Size = new System.Drawing.Size(96, 16); + this.labelReverseConsist.Size = new System.Drawing.Size(96, 18); this.labelReverseConsist.TabIndex = 11; this.labelReverseConsist.Text = "Reverse Consist:"; this.labelReverseConsist.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -932,7 +931,7 @@ private void InitializeComponent() { this.labelTrainEncoding.ForeColor = System.Drawing.SystemColors.ControlText; this.labelTrainEncoding.Location = new System.Drawing.Point(0, 0); this.labelTrainEncoding.Name = "labelTrainEncoding"; - this.labelTrainEncoding.Size = new System.Drawing.Size(96, 16); + this.labelTrainEncoding.Size = new System.Drawing.Size(96, 18); this.labelTrainEncoding.TabIndex = 0; this.labelTrainEncoding.Text = "Encoding:"; this.labelTrainEncoding.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -943,7 +942,7 @@ private void InitializeComponent() { this.buttonTrainEncodingBig5.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonTrainEncodingBig5.Location = new System.Drawing.Point(212, 24); this.buttonTrainEncodingBig5.Name = "buttonTrainEncodingBig5"; - this.buttonTrainEncodingBig5.Size = new System.Drawing.Size(64, 24); + this.buttonTrainEncodingBig5.Size = new System.Drawing.Size(64, 26); this.buttonTrainEncodingBig5.TabIndex = 9; this.buttonTrainEncodingBig5.Text = "Big5"; this.buttonTrainEncodingBig5.UseVisualStyleBackColor = true; @@ -967,7 +966,7 @@ private void InitializeComponent() { this.buttonTrainEncodingShiftJis.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonTrainEncodingShiftJis.Location = new System.Drawing.Point(148, 24); this.buttonTrainEncodingShiftJis.Name = "buttonTrainEncodingShiftJis"; - this.buttonTrainEncodingShiftJis.Size = new System.Drawing.Size(64, 24); + this.buttonTrainEncodingShiftJis.Size = new System.Drawing.Size(64, 26); this.buttonTrainEncodingShiftJis.TabIndex = 3; this.buttonTrainEncodingShiftJis.Text = "Shift_JIS"; this.buttonTrainEncodingShiftJis.UseVisualStyleBackColor = true; @@ -979,7 +978,7 @@ private void InitializeComponent() { this.buttonTrainEncodingLatin1.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonTrainEncodingLatin1.Location = new System.Drawing.Point(84, 24); this.buttonTrainEncodingLatin1.Name = "buttonTrainEncodingLatin1"; - this.buttonTrainEncodingLatin1.Size = new System.Drawing.Size(64, 24); + this.buttonTrainEncodingLatin1.Size = new System.Drawing.Size(64, 26); this.buttonTrainEncodingLatin1.TabIndex = 2; this.buttonTrainEncodingLatin1.Text = "Latin-1"; this.buttonTrainEncodingLatin1.UseVisualStyleBackColor = true; @@ -991,7 +990,7 @@ private void InitializeComponent() { this.labelTrainEncodingPreview.ForeColor = System.Drawing.SystemColors.ControlText; this.labelTrainEncodingPreview.Location = new System.Drawing.Point(7, 80); this.labelTrainEncodingPreview.Name = "labelTrainEncodingPreview"; - this.labelTrainEncodingPreview.Size = new System.Drawing.Size(96, 16); + this.labelTrainEncodingPreview.Size = new System.Drawing.Size(96, 18); this.labelTrainEncodingPreview.TabIndex = 4; this.labelTrainEncodingPreview.Text = "Preview:"; this.labelTrainEncodingPreview.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -1018,7 +1017,7 @@ private void InitializeComponent() { this.buttonStart.Enabled = false; this.buttonStart.Location = new System.Drawing.Point(571, 599); this.buttonStart.Name = "buttonStart"; - this.buttonStart.Size = new System.Drawing.Size(120, 24); + this.buttonStart.Size = new System.Drawing.Size(120, 26); this.buttonStart.TabIndex = 12; this.buttonStart.Text = "Start"; this.buttonStart.UseVisualStyleBackColor = true; @@ -1034,7 +1033,7 @@ private void InitializeComponent() { this.labelStart.ForeColor = System.Drawing.Color.White; this.labelStart.Location = new System.Drawing.Point(7, 567); this.labelStart.Name = "labelStart"; - this.labelStart.Size = new System.Drawing.Size(684, 24); + this.labelStart.Size = new System.Drawing.Size(684, 26); this.labelStart.TabIndex = 9; this.labelStart.Text = "Start"; this.labelStart.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; @@ -1334,7 +1333,7 @@ private void InitializeComponent() { this.labelCompatibilitySignalSet.ForeColor = System.Drawing.SystemColors.ControlText; this.labelCompatibilitySignalSet.Location = new System.Drawing.Point(13, 6); this.labelCompatibilitySignalSet.Name = "labelCompatibilitySignalSet"; - this.labelCompatibilitySignalSet.Size = new System.Drawing.Size(96, 16); + this.labelCompatibilitySignalSet.Size = new System.Drawing.Size(96, 18); this.labelCompatibilitySignalSet.TabIndex = 8; this.labelCompatibilitySignalSet.Text = "Default Signals:"; this.labelCompatibilitySignalSet.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -1373,7 +1372,7 @@ private void InitializeComponent() { this.buttonRouteEncodingLatin1.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonRouteEncodingLatin1.Location = new System.Drawing.Point(84, 24); this.buttonRouteEncodingLatin1.Name = "buttonRouteEncodingLatin1"; - this.buttonRouteEncodingLatin1.Size = new System.Drawing.Size(64, 24); + this.buttonRouteEncodingLatin1.Size = new System.Drawing.Size(64, 26); this.buttonRouteEncodingLatin1.TabIndex = 2; this.buttonRouteEncodingLatin1.Text = "Latin-1"; this.buttonRouteEncodingLatin1.UseVisualStyleBackColor = true; @@ -1385,7 +1384,7 @@ private void InitializeComponent() { this.buttonRouteEncodingBig5.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonRouteEncodingBig5.Location = new System.Drawing.Point(212, 24); this.buttonRouteEncodingBig5.Name = "buttonRouteEncodingBig5"; - this.buttonRouteEncodingBig5.Size = new System.Drawing.Size(64, 24); + this.buttonRouteEncodingBig5.Size = new System.Drawing.Size(64, 26); this.buttonRouteEncodingBig5.TabIndex = 4; this.buttonRouteEncodingBig5.Text = "Big5"; this.buttonRouteEncodingBig5.UseVisualStyleBackColor = true; @@ -1397,7 +1396,7 @@ private void InitializeComponent() { this.labelRouteEncoding.ForeColor = System.Drawing.SystemColors.ControlText; this.labelRouteEncoding.Location = new System.Drawing.Point(0, 0); this.labelRouteEncoding.Name = "labelRouteEncoding"; - this.labelRouteEncoding.Size = new System.Drawing.Size(96, 16); + this.labelRouteEncoding.Size = new System.Drawing.Size(96, 18); this.labelRouteEncoding.TabIndex = 0; this.labelRouteEncoding.Text = "Encoding:"; this.labelRouteEncoding.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -1408,7 +1407,7 @@ private void InitializeComponent() { this.buttonRouteEncodingShiftJis.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonRouteEncodingShiftJis.Location = new System.Drawing.Point(148, 24); this.buttonRouteEncodingShiftJis.Name = "buttonRouteEncodingShiftJis"; - this.buttonRouteEncodingShiftJis.Size = new System.Drawing.Size(64, 24); + this.buttonRouteEncodingShiftJis.Size = new System.Drawing.Size(64, 26); this.buttonRouteEncodingShiftJis.TabIndex = 3; this.buttonRouteEncodingShiftJis.Text = "Shift_JIS"; this.buttonRouteEncodingShiftJis.UseVisualStyleBackColor = true; @@ -1433,7 +1432,7 @@ private void InitializeComponent() { this.labelRouteEncodingPreview.ForeColor = System.Drawing.SystemColors.ControlText; this.labelRouteEncodingPreview.Location = new System.Drawing.Point(12, 87); this.labelRouteEncodingPreview.Name = "labelRouteEncodingPreview"; - this.labelRouteEncodingPreview.Size = new System.Drawing.Size(96, 16); + this.labelRouteEncodingPreview.Size = new System.Drawing.Size(96, 18); this.labelRouteEncodingPreview.TabIndex = 5; this.labelRouteEncodingPreview.Text = "Preview:"; this.labelRouteEncodingPreview.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -1550,7 +1549,7 @@ private void InitializeComponent() { this.buttonOptionsPrevious.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonOptionsPrevious.Location = new System.Drawing.Point(484, 38); this.buttonOptionsPrevious.Name = "buttonOptionsPrevious"; - this.buttonOptionsPrevious.Size = new System.Drawing.Size(99, 23); + this.buttonOptionsPrevious.Size = new System.Drawing.Size(99, 26); this.buttonOptionsPrevious.TabIndex = 19; this.buttonOptionsPrevious.Text = "Previous Page..."; this.buttonOptionsPrevious.UseVisualStyleBackColor = true; @@ -1562,7 +1561,7 @@ private void InitializeComponent() { this.buttonOptionsNext.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonOptionsNext.Location = new System.Drawing.Point(589, 38); this.buttonOptionsNext.Name = "buttonOptionsNext"; - this.buttonOptionsNext.Size = new System.Drawing.Size(99, 23); + this.buttonOptionsNext.Size = new System.Drawing.Size(99, 26); this.buttonOptionsNext.TabIndex = 18; this.buttonOptionsNext.Text = "Next Page..."; this.buttonOptionsNext.UseVisualStyleBackColor = true; @@ -1689,7 +1688,7 @@ private void InitializeComponent() { this.labelVSync.AutoEllipsis = true; this.labelVSync.Location = new System.Drawing.Point(8, 72); this.labelVSync.Name = "labelVSync"; - this.labelVSync.Size = new System.Drawing.Size(148, 16); + this.labelVSync.Size = new System.Drawing.Size(148, 18); this.labelVSync.TabIndex = 2; this.labelVSync.Text = "Vertical syncronization:"; this.labelVSync.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -1798,7 +1797,7 @@ private void InitializeComponent() { this.labelWindowWidth.AutoEllipsis = true; this.labelWindowWidth.Location = new System.Drawing.Point(8, 26); this.labelWindowWidth.Name = "labelWindowWidth"; - this.labelWindowWidth.Size = new System.Drawing.Size(148, 16); + this.labelWindowWidth.Size = new System.Drawing.Size(148, 18); this.labelWindowWidth.TabIndex = 0; this.labelWindowWidth.Text = "Width:"; this.labelWindowWidth.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -1838,7 +1837,7 @@ private void InitializeComponent() { this.labelFullscreenBits.AutoEllipsis = true; this.labelFullscreenBits.Location = new System.Drawing.Point(8, 74); this.labelFullscreenBits.Name = "labelFullscreenBits"; - this.labelFullscreenBits.Size = new System.Drawing.Size(148, 16); + this.labelFullscreenBits.Size = new System.Drawing.Size(148, 18); this.labelFullscreenBits.TabIndex = 4; this.labelFullscreenBits.Text = "Bits per pixel:"; this.labelFullscreenBits.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -1908,7 +1907,7 @@ private void InitializeComponent() { this.labelFullscreenWidth.AutoEllipsis = true; this.labelFullscreenWidth.Location = new System.Drawing.Point(8, 26); this.labelFullscreenWidth.Name = "labelFullscreenWidth"; - this.labelFullscreenWidth.Size = new System.Drawing.Size(148, 16); + this.labelFullscreenWidth.Size = new System.Drawing.Size(148, 18); this.labelFullscreenWidth.TabIndex = 0; this.labelFullscreenWidth.Text = "Width:"; this.labelFullscreenWidth.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -1989,7 +1988,7 @@ private void InitializeComponent() { this.labelTransparency.AutoEllipsis = true; this.labelTransparency.Location = new System.Drawing.Point(8, 100); this.labelTransparency.Name = "labelTransparency"; - this.labelTransparency.Size = new System.Drawing.Size(148, 16); + this.labelTransparency.Size = new System.Drawing.Size(148, 18); this.labelTransparency.TabIndex = 6; this.labelTransparency.Text = "Transparency:"; this.labelTransparency.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -2039,7 +2038,7 @@ private void InitializeComponent() { this.labelInterpolation.AutoEllipsis = true; this.labelInterpolation.Location = new System.Drawing.Point(8, 18); this.labelInterpolation.Name = "labelInterpolation"; - this.labelInterpolation.Size = new System.Drawing.Size(148, 16); + this.labelInterpolation.Size = new System.Drawing.Size(148, 18); this.labelInterpolation.TabIndex = 0; this.labelInterpolation.Text = "Mode:"; this.labelInterpolation.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -2100,7 +2099,7 @@ private void InitializeComponent() { this.labelTimeTableDisplayMode.AutoEllipsis = true; this.labelTimeTableDisplayMode.Location = new System.Drawing.Point(3, 17); this.labelTimeTableDisplayMode.Name = "labelTimeTableDisplayMode"; - this.labelTimeTableDisplayMode.Size = new System.Drawing.Size(153, 16); + this.labelTimeTableDisplayMode.Size = new System.Drawing.Size(153, 18); this.labelTimeTableDisplayMode.TabIndex = 0; this.labelTimeTableDisplayMode.Text = "Timetable Display Mode:"; this.labelTimeTableDisplayMode.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -2132,11 +2131,11 @@ private void InitializeComponent() { // // buttonRailDriverCalibration // - this.buttonRailDriverCalibration.Location = new System.Drawing.Point(230, 45); + this.buttonRailDriverCalibration.Location = new System.Drawing.Point(230, 42); this.buttonRailDriverCalibration.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonRailDriverCalibration.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonRailDriverCalibration.Name = "buttonRailDriverCalibration"; - this.buttonRailDriverCalibration.Size = new System.Drawing.Size(75, 23); + this.buttonRailDriverCalibration.Size = new System.Drawing.Size(75, 26); this.buttonRailDriverCalibration.TabIndex = 4; this.buttonRailDriverCalibration.Text = "Launch..."; this.buttonRailDriverCalibration.UseVisualStyleBackColor = true; @@ -2199,7 +2198,7 @@ private void InitializeComponent() { this.labelMotionBlur.AutoEllipsis = true; this.labelMotionBlur.Location = new System.Drawing.Point(5, 51); this.labelMotionBlur.Name = "labelMotionBlur"; - this.labelMotionBlur.Size = new System.Drawing.Size(140, 16); + this.labelMotionBlur.Size = new System.Drawing.Size(140, 18); this.labelMotionBlur.TabIndex = 3; this.labelMotionBlur.Text = "Motion blur:"; this.labelMotionBlur.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -2210,7 +2209,7 @@ private void InitializeComponent() { this.labelDistanceUnit.AutoEllipsis = true; this.labelDistanceUnit.Location = new System.Drawing.Point(272, 24); this.labelDistanceUnit.Name = "labelDistanceUnit"; - this.labelDistanceUnit.Size = new System.Drawing.Size(24, 16); + this.labelDistanceUnit.Size = new System.Drawing.Size(24, 18); this.labelDistanceUnit.TabIndex = 2; this.labelDistanceUnit.Text = "m"; // @@ -2307,7 +2306,7 @@ private void InitializeComponent() { this.labelJoystickAxisThreshold.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; this.labelJoystickAxisThreshold.Location = new System.Drawing.Point(110, 10); this.labelJoystickAxisThreshold.Name = "labelJoystickAxisThreshold"; - this.labelJoystickAxisThreshold.Size = new System.Drawing.Size(180, 16); + this.labelJoystickAxisThreshold.Size = new System.Drawing.Size(180, 18); this.labelJoystickAxisThreshold.TabIndex = 1; this.labelJoystickAxisThreshold.Text = "Joystick threshold:"; this.labelJoystickAxisThreshold.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -2468,7 +2467,7 @@ private void InitializeComponent() { | System.Windows.Forms.AnchorStyles.Right))); this.labelSoundNumber.Location = new System.Drawing.Point(5, 18); this.labelSoundNumber.Name = "labelSoundNumber"; - this.labelSoundNumber.Size = new System.Drawing.Size(136, 16); + this.labelSoundNumber.Size = new System.Drawing.Size(136, 18); this.labelSoundNumber.TabIndex = 2; this.labelSoundNumber.Text = "Number of allowed sounds:"; this.labelSoundNumber.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -2883,9 +2882,9 @@ private void InitializeComponent() { this.buttonOtherDirectory.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonOtherDirectory.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonOtherDirectory.BackColor = System.Drawing.SystemColors.Control; - this.buttonOtherDirectory.Location = new System.Drawing.Point(594, 83); + this.buttonOtherDirectory.Location = new System.Drawing.Point(594, 81); this.buttonOtherDirectory.Name = "buttonOtherDirectory"; - this.buttonOtherDirectory.Size = new System.Drawing.Size(75, 23); + this.buttonOtherDirectory.Size = new System.Drawing.Size(75, 26); this.buttonOtherDirectory.TabIndex = 8; this.buttonOtherDirectory.Text = "Choose..."; this.buttonOtherDirectory.UseVisualStyleBackColor = true; @@ -2918,9 +2917,9 @@ private void InitializeComponent() { this.buttonTrainInstallationDirectory.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonTrainInstallationDirectory.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonTrainInstallationDirectory.BackColor = System.Drawing.SystemColors.ButtonFace; - this.buttonTrainInstallationDirectory.Location = new System.Drawing.Point(594, 51); + this.buttonTrainInstallationDirectory.Location = new System.Drawing.Point(594, 49); this.buttonTrainInstallationDirectory.Name = "buttonTrainInstallationDirectory"; - this.buttonTrainInstallationDirectory.Size = new System.Drawing.Size(75, 23); + this.buttonTrainInstallationDirectory.Size = new System.Drawing.Size(75, 26); this.buttonTrainInstallationDirectory.TabIndex = 5; this.buttonTrainInstallationDirectory.Text = "Choose..."; this.buttonTrainInstallationDirectory.UseVisualStyleBackColor = true; @@ -2952,9 +2951,9 @@ private void InitializeComponent() { this.buttonSetRouteDirectory.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonSetRouteDirectory.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonSetRouteDirectory.ForeColor = System.Drawing.SystemColors.ControlText; - this.buttonSetRouteDirectory.Location = new System.Drawing.Point(594, 20); + this.buttonSetRouteDirectory.Location = new System.Drawing.Point(594, 18); this.buttonSetRouteDirectory.Name = "buttonSetRouteDirectory"; - this.buttonSetRouteDirectory.Size = new System.Drawing.Size(75, 23); + this.buttonSetRouteDirectory.Size = new System.Drawing.Size(75, 26); this.buttonSetRouteDirectory.TabIndex = 2; this.buttonSetRouteDirectory.Text = "Choose..."; this.buttonSetRouteDirectory.UseVisualStyleBackColor = true; @@ -3181,7 +3180,7 @@ private void InitializeComponent() { this.labelBlackBoxFormat.ForeColor = System.Drawing.Color.Black; this.labelBlackBoxFormat.Location = new System.Drawing.Point(8, 602); this.labelBlackBoxFormat.Name = "labelBlackBoxFormat"; - this.labelBlackBoxFormat.Size = new System.Drawing.Size(96, 16); + this.labelBlackBoxFormat.Size = new System.Drawing.Size(96, 18); this.labelBlackBoxFormat.TabIndex = 11; this.labelBlackBoxFormat.Text = "Format:"; this.labelBlackBoxFormat.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -3207,7 +3206,7 @@ private void InitializeComponent() { this.labelReviewTimeValue.AutoEllipsis = true; this.labelReviewTimeValue.Location = new System.Drawing.Point(104, 32); this.labelReviewTimeValue.Name = "labelReviewTimeValue"; - this.labelReviewTimeValue.Size = new System.Drawing.Size(88, 16); + this.labelReviewTimeValue.Size = new System.Drawing.Size(88, 18); this.labelReviewTimeValue.TabIndex = 3; this.labelReviewTimeValue.Text = "?"; // @@ -3216,7 +3215,7 @@ private void InitializeComponent() { this.labelReviewTimeCaption.AutoEllipsis = true; this.labelReviewTimeCaption.Location = new System.Drawing.Point(8, 32); this.labelReviewTimeCaption.Name = "labelReviewTimeCaption"; - this.labelReviewTimeCaption.Size = new System.Drawing.Size(96, 16); + this.labelReviewTimeCaption.Size = new System.Drawing.Size(96, 18); this.labelReviewTimeCaption.TabIndex = 2; this.labelReviewTimeCaption.Text = "Time:"; this.labelReviewTimeCaption.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -3228,7 +3227,7 @@ private void InitializeComponent() { this.labelReviewDateValue.AutoEllipsis = true; this.labelReviewDateValue.Location = new System.Drawing.Point(104, 16); this.labelReviewDateValue.Name = "labelReviewDateValue"; - this.labelReviewDateValue.Size = new System.Drawing.Size(88, 16); + this.labelReviewDateValue.Size = new System.Drawing.Size(88, 18); this.labelReviewDateValue.TabIndex = 1; this.labelReviewDateValue.Text = "?"; // @@ -3237,7 +3236,7 @@ private void InitializeComponent() { this.labelReviewDateCaption.AutoEllipsis = true; this.labelReviewDateCaption.Location = new System.Drawing.Point(8, 16); this.labelReviewDateCaption.Name = "labelReviewDateCaption"; - this.labelReviewDateCaption.Size = new System.Drawing.Size(96, 16); + this.labelReviewDateCaption.Size = new System.Drawing.Size(96, 18); this.labelReviewDateCaption.TabIndex = 0; this.labelReviewDateCaption.Text = "Date:"; this.labelReviewDateCaption.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -3246,9 +3245,9 @@ private void InitializeComponent() { // this.buttonBlackBoxExport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonBlackBoxExport.BackColor = System.Drawing.SystemColors.ButtonFace; - this.buttonBlackBoxExport.Location = new System.Drawing.Point(256, 598); + this.buttonBlackBoxExport.Location = new System.Drawing.Point(256, 597); this.buttonBlackBoxExport.Name = "buttonBlackBoxExport"; - this.buttonBlackBoxExport.Size = new System.Drawing.Size(120, 24); + this.buttonBlackBoxExport.Size = new System.Drawing.Size(120, 26); this.buttonBlackBoxExport.TabIndex = 13; this.buttonBlackBoxExport.Text = "Export..."; this.buttonBlackBoxExport.UseVisualStyleBackColor = false; @@ -3302,9 +3301,9 @@ private void InitializeComponent() { this.buttonScoreExport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonScoreExport.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonScoreExport.BackColor = System.Drawing.SystemColors.ButtonFace; - this.buttonScoreExport.Location = new System.Drawing.Point(291, 351); + this.buttonScoreExport.Location = new System.Drawing.Point(291, 350); this.buttonScoreExport.Name = "buttonScoreExport"; - this.buttonScoreExport.Size = new System.Drawing.Size(120, 24); + this.buttonScoreExport.Size = new System.Drawing.Size(120, 26); this.buttonScoreExport.TabIndex = 2; this.buttonScoreExport.Text = "Export..."; this.buttonScoreExport.UseVisualStyleBackColor = false; @@ -3378,7 +3377,7 @@ private void InitializeComponent() { this.labelReviewTrainValue.AutoEllipsis = true; this.labelReviewTrainValue.Location = new System.Drawing.Point(8, 32); this.labelReviewTrainValue.Name = "labelReviewTrainValue"; - this.labelReviewTrainValue.Size = new System.Drawing.Size(192, 16); + this.labelReviewTrainValue.Size = new System.Drawing.Size(192, 18); this.labelReviewTrainValue.TabIndex = 1; this.labelReviewTrainValue.Text = "?"; // @@ -3387,7 +3386,7 @@ private void InitializeComponent() { this.labelReviewTrainCaption.AutoSize = true; this.labelReviewTrainCaption.Location = new System.Drawing.Point(8, 16); this.labelReviewTrainCaption.Name = "labelReviewTrainCaption"; - this.labelReviewTrainCaption.Size = new System.Drawing.Size(39, 13); + this.labelReviewTrainCaption.Size = new System.Drawing.Size(39, 18); this.labelReviewTrainCaption.TabIndex = 0; this.labelReviewTrainCaption.Text = "Folder:"; // @@ -3410,7 +3409,7 @@ private void InitializeComponent() { this.labelReviewRouteValue.AutoEllipsis = true; this.labelReviewRouteValue.Location = new System.Drawing.Point(8, 32); this.labelReviewRouteValue.Name = "labelReviewRouteValue"; - this.labelReviewRouteValue.Size = new System.Drawing.Size(192, 16); + this.labelReviewRouteValue.Size = new System.Drawing.Size(192, 18); this.labelReviewRouteValue.TabIndex = 1; this.labelReviewRouteValue.Text = "?"; // @@ -3419,7 +3418,7 @@ private void InitializeComponent() { this.labelReviewRouteCaption.AutoSize = true; this.labelReviewRouteCaption.Location = new System.Drawing.Point(8, 16); this.labelReviewRouteCaption.Name = "labelReviewRouteCaption"; - this.labelReviewRouteCaption.Size = new System.Drawing.Size(26, 13); + this.labelReviewRouteCaption.Size = new System.Drawing.Size(26, 18); this.labelReviewRouteCaption.TabIndex = 0; this.labelReviewRouteCaption.Text = "File:"; // @@ -3464,25 +3463,25 @@ private void InitializeComponent() { this.labelRatingRatioValue.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.labelRatingRatioValue.Location = new System.Drawing.Point(128, 104); this.labelRatingRatioValue.Name = "labelRatingRatioValue"; - this.labelRatingRatioValue.Size = new System.Drawing.Size(120, 16); + this.labelRatingRatioValue.Size = new System.Drawing.Size(120, 18); this.labelRatingRatioValue.TabIndex = 9; this.labelRatingRatioValue.Text = "?"; // // labelRatingModeValue // this.labelRatingModeValue.AutoEllipsis = true; - this.labelRatingModeValue.Location = new System.Drawing.Point(128, 24); + this.labelRatingModeValue.Location = new System.Drawing.Point(128, 22); this.labelRatingModeValue.Name = "labelRatingModeValue"; - this.labelRatingModeValue.Size = new System.Drawing.Size(120, 16); + this.labelRatingModeValue.Size = new System.Drawing.Size(120, 18); this.labelRatingModeValue.TabIndex = 1; this.labelRatingModeValue.Text = "?"; // // labelRatingModeCaption // this.labelRatingModeCaption.AutoEllipsis = true; - this.labelRatingModeCaption.Location = new System.Drawing.Point(8, 24); + this.labelRatingModeCaption.Location = new System.Drawing.Point(8, 22); this.labelRatingModeCaption.Name = "labelRatingModeCaption"; - this.labelRatingModeCaption.Size = new System.Drawing.Size(120, 16); + this.labelRatingModeCaption.Size = new System.Drawing.Size(120, 18); this.labelRatingModeCaption.TabIndex = 0; this.labelRatingModeCaption.Text = "Mode:"; this.labelRatingModeCaption.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -3493,7 +3492,7 @@ private void InitializeComponent() { this.labelRatingRatioCaption.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.labelRatingRatioCaption.Location = new System.Drawing.Point(8, 104); this.labelRatingRatioCaption.Name = "labelRatingRatioCaption"; - this.labelRatingRatioCaption.Size = new System.Drawing.Size(120, 16); + this.labelRatingRatioCaption.Size = new System.Drawing.Size(120, 18); this.labelRatingRatioCaption.TabIndex = 8; this.labelRatingRatioCaption.Text = "Ratio:"; this.labelRatingRatioCaption.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -3503,7 +3502,7 @@ private void InitializeComponent() { this.labelRatingMaximumValue.AutoEllipsis = true; this.labelRatingMaximumValue.Location = new System.Drawing.Point(128, 88); this.labelRatingMaximumValue.Name = "labelRatingMaximumValue"; - this.labelRatingMaximumValue.Size = new System.Drawing.Size(120, 16); + this.labelRatingMaximumValue.Size = new System.Drawing.Size(120, 18); this.labelRatingMaximumValue.TabIndex = 7; this.labelRatingMaximumValue.Text = "?"; // @@ -3512,7 +3511,7 @@ private void InitializeComponent() { this.labelRatingMaximumCaption.AutoEllipsis = true; this.labelRatingMaximumCaption.Location = new System.Drawing.Point(8, 88); this.labelRatingMaximumCaption.Name = "labelRatingMaximumCaption"; - this.labelRatingMaximumCaption.Size = new System.Drawing.Size(120, 16); + this.labelRatingMaximumCaption.Size = new System.Drawing.Size(120, 18); this.labelRatingMaximumCaption.TabIndex = 6; this.labelRatingMaximumCaption.Text = "Maximum:"; this.labelRatingMaximumCaption.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -3522,7 +3521,7 @@ private void InitializeComponent() { this.labelRatingAchievedValue.AutoEllipsis = true; this.labelRatingAchievedValue.Location = new System.Drawing.Point(128, 72); this.labelRatingAchievedValue.Name = "labelRatingAchievedValue"; - this.labelRatingAchievedValue.Size = new System.Drawing.Size(120, 16); + this.labelRatingAchievedValue.Size = new System.Drawing.Size(120, 18); this.labelRatingAchievedValue.TabIndex = 5; this.labelRatingAchievedValue.Text = "?"; // @@ -3531,7 +3530,7 @@ private void InitializeComponent() { this.labelRatingAchievedCaption.AutoEllipsis = true; this.labelRatingAchievedCaption.Location = new System.Drawing.Point(8, 72); this.labelRatingAchievedCaption.Name = "labelRatingAchievedCaption"; - this.labelRatingAchievedCaption.Size = new System.Drawing.Size(120, 16); + this.labelRatingAchievedCaption.Size = new System.Drawing.Size(120, 18); this.labelRatingAchievedCaption.TabIndex = 4; this.labelRatingAchievedCaption.Text = "Achieved:"; this.labelRatingAchievedCaption.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -3649,7 +3648,7 @@ private void InitializeComponent() { this.buttonControlReset.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonControlReset.Location = new System.Drawing.Point(8, 293); this.buttonControlReset.Name = "buttonControlReset"; - this.buttonControlReset.Size = new System.Drawing.Size(96, 24); + this.buttonControlReset.Size = new System.Drawing.Size(96, 26); this.buttonControlReset.TabIndex = 12; this.buttonControlReset.Text = "Reset to defaults"; this.buttonControlReset.UseVisualStyleBackColor = true; @@ -3659,9 +3658,9 @@ private void InitializeComponent() { // this.buttonControlsExport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonControlsExport.BackColor = System.Drawing.SystemColors.ButtonFace; - this.buttonControlsExport.Location = new System.Drawing.Point(320, 264); + this.buttonControlsExport.Location = new System.Drawing.Point(320, 262); this.buttonControlsExport.Name = "buttonControlsExport"; - this.buttonControlsExport.Size = new System.Drawing.Size(96, 24); + this.buttonControlsExport.Size = new System.Drawing.Size(96, 26); this.buttonControlsExport.TabIndex = 7; this.buttonControlsExport.Text = "Export..."; this.buttonControlsExport.UseVisualStyleBackColor = true; @@ -3671,9 +3670,9 @@ private void InitializeComponent() { // this.buttonControlsImport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonControlsImport.BackColor = System.Drawing.SystemColors.ButtonFace; - this.buttonControlsImport.Location = new System.Drawing.Point(216, 264); + this.buttonControlsImport.Location = new System.Drawing.Point(216, 262); this.buttonControlsImport.Name = "buttonControlsImport"; - this.buttonControlsImport.Size = new System.Drawing.Size(96, 24); + this.buttonControlsImport.Size = new System.Drawing.Size(96, 26); this.buttonControlsImport.TabIndex = 6; this.buttonControlsImport.Text = "Import..."; this.buttonControlsImport.UseVisualStyleBackColor = true; @@ -3683,9 +3682,9 @@ private void InitializeComponent() { // this.buttonControlDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonControlDown.BackColor = System.Drawing.SystemColors.ButtonFace; - this.buttonControlDown.Location = new System.Drawing.Point(595, 264); + this.buttonControlDown.Location = new System.Drawing.Point(595, 262); this.buttonControlDown.Name = "buttonControlDown"; - this.buttonControlDown.Size = new System.Drawing.Size(96, 24); + this.buttonControlDown.Size = new System.Drawing.Size(96, 26); this.buttonControlDown.TabIndex = 9; this.buttonControlDown.Text = "Move down"; this.buttonControlDown.UseVisualStyleBackColor = true; @@ -3695,9 +3694,9 @@ private void InitializeComponent() { // this.buttonControlUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonControlUp.BackColor = System.Drawing.SystemColors.ButtonFace; - this.buttonControlUp.Location = new System.Drawing.Point(491, 264); + this.buttonControlUp.Location = new System.Drawing.Point(491, 262); this.buttonControlUp.Name = "buttonControlUp"; - this.buttonControlUp.Size = new System.Drawing.Size(96, 24); + this.buttonControlUp.Size = new System.Drawing.Size(96, 26); this.buttonControlUp.TabIndex = 8; this.buttonControlUp.Text = "Move up"; this.buttonControlUp.UseVisualStyleBackColor = true; @@ -3707,9 +3706,9 @@ private void InitializeComponent() { // this.buttonControlRemove.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonControlRemove.BackColor = System.Drawing.SystemColors.ButtonFace; - this.buttonControlRemove.Location = new System.Drawing.Point(112, 264); + this.buttonControlRemove.Location = new System.Drawing.Point(112, 262); this.buttonControlRemove.Name = "buttonControlRemove"; - this.buttonControlRemove.Size = new System.Drawing.Size(96, 24); + this.buttonControlRemove.Size = new System.Drawing.Size(96, 26); this.buttonControlRemove.TabIndex = 5; this.buttonControlRemove.Text = "Remove"; this.buttonControlRemove.UseVisualStyleBackColor = true; @@ -3719,9 +3718,9 @@ private void InitializeComponent() { // this.buttonControlAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.buttonControlAdd.BackColor = System.Drawing.SystemColors.ButtonFace; - this.buttonControlAdd.Location = new System.Drawing.Point(8, 264); + this.buttonControlAdd.Location = new System.Drawing.Point(8, 262); this.buttonControlAdd.Name = "buttonControlAdd"; - this.buttonControlAdd.Size = new System.Drawing.Size(96, 24); + this.buttonControlAdd.Size = new System.Drawing.Size(96, 26); this.buttonControlAdd.TabIndex = 4; this.buttonControlAdd.Text = "Add"; this.buttonControlAdd.UseVisualStyleBackColor = true; @@ -3885,7 +3884,7 @@ private void InitializeComponent() { this.labelKeyboardKey.AutoEllipsis = true; this.labelKeyboardKey.Location = new System.Drawing.Point(0, 3); this.labelKeyboardKey.Name = "labelKeyboardKey"; - this.labelKeyboardKey.Size = new System.Drawing.Size(80, 16); + this.labelKeyboardKey.Size = new System.Drawing.Size(80, 18); this.labelKeyboardKey.TabIndex = 0; this.labelKeyboardKey.Text = "Key:"; this.labelKeyboardKey.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -3895,7 +3894,7 @@ private void InitializeComponent() { this.checkboxKeyboardAlt.AutoSize = true; this.checkboxKeyboardAlt.Location = new System.Drawing.Point(192, 26); this.checkboxKeyboardAlt.Name = "checkboxKeyboardAlt"; - this.checkboxKeyboardAlt.Size = new System.Drawing.Size(38, 17); + this.checkboxKeyboardAlt.Size = new System.Drawing.Size(38, 18); this.checkboxKeyboardAlt.TabIndex = 5; this.checkboxKeyboardAlt.Text = "Alt"; this.checkboxKeyboardAlt.UseVisualStyleBackColor = true; @@ -3906,7 +3905,7 @@ private void InitializeComponent() { this.checkboxKeyboardCtrl.AutoSize = true; this.checkboxKeyboardCtrl.Location = new System.Drawing.Point(136, 26); this.checkboxKeyboardCtrl.Name = "checkboxKeyboardCtrl"; - this.checkboxKeyboardCtrl.Size = new System.Drawing.Size(41, 17); + this.checkboxKeyboardCtrl.Size = new System.Drawing.Size(41, 18); this.checkboxKeyboardCtrl.TabIndex = 4; this.checkboxKeyboardCtrl.Text = "Ctrl"; this.checkboxKeyboardCtrl.UseVisualStyleBackColor = true; @@ -3917,7 +3916,7 @@ private void InitializeComponent() { this.checkboxKeyboardShift.AutoSize = true; this.checkboxKeyboardShift.Location = new System.Drawing.Point(80, 26); this.checkboxKeyboardShift.Name = "checkboxKeyboardShift"; - this.checkboxKeyboardShift.Size = new System.Drawing.Size(47, 17); + this.checkboxKeyboardShift.Size = new System.Drawing.Size(47, 18); this.checkboxKeyboardShift.TabIndex = 3; this.checkboxKeyboardShift.Text = "Shift"; this.checkboxKeyboardShift.UseVisualStyleBackColor = true; @@ -3928,7 +3927,7 @@ private void InitializeComponent() { this.labelKeyboardModifier.AutoEllipsis = true; this.labelKeyboardModifier.Location = new System.Drawing.Point(0, 26); this.labelKeyboardModifier.Name = "labelKeyboardModifier"; - this.labelKeyboardModifier.Size = new System.Drawing.Size(80, 16); + this.labelKeyboardModifier.Size = new System.Drawing.Size(80, 18); this.labelKeyboardModifier.TabIndex = 2; this.labelKeyboardModifier.Text = "Modifiers:"; this.labelKeyboardModifier.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -3958,7 +3957,7 @@ private void InitializeComponent() { this.labelCommandOption.AutoEllipsis = true; this.labelCommandOption.Location = new System.Drawing.Point(463, 51); this.labelCommandOption.Name = "labelCommandOption"; - this.labelCommandOption.Size = new System.Drawing.Size(120, 16); + this.labelCommandOption.Size = new System.Drawing.Size(120, 18); this.labelCommandOption.TabIndex = 7; this.labelCommandOption.Text = "CommandOption:"; this.labelCommandOption.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -3968,7 +3967,7 @@ private void InitializeComponent() { this.labelCommand.AutoEllipsis = true; this.labelCommand.Location = new System.Drawing.Point(8, 24); this.labelCommand.Name = "labelCommand"; - this.labelCommand.Size = new System.Drawing.Size(80, 16); + this.labelCommand.Size = new System.Drawing.Size(80, 18); this.labelCommand.TabIndex = 0; this.labelCommand.Text = "Command:"; this.labelCommand.TextAlign = System.Drawing.ContentAlignment.TopRight; @@ -4008,7 +4007,7 @@ private void InitializeComponent() { this.labelJoystickAssignmentCaption.AutoEllipsis = true; this.labelJoystickAssignmentCaption.Location = new System.Drawing.Point(0, 0); this.labelJoystickAssignmentCaption.Name = "labelJoystickAssignmentCaption"; - this.labelJoystickAssignmentCaption.Size = new System.Drawing.Size(192, 16); + this.labelJoystickAssignmentCaption.Size = new System.Drawing.Size(192, 18); this.labelJoystickAssignmentCaption.TabIndex = 0; this.labelJoystickAssignmentCaption.Text = "Assignment:"; // @@ -4026,7 +4025,7 @@ private void InitializeComponent() { this.radiobuttonJoystick.AutoSize = true; this.radiobuttonJoystick.Location = new System.Drawing.Point(272, 48); this.radiobuttonJoystick.Name = "radiobuttonJoystick"; - this.radiobuttonJoystick.Size = new System.Drawing.Size(66, 17); + this.radiobuttonJoystick.Size = new System.Drawing.Size(66, 18); this.radiobuttonJoystick.TabIndex = 3; this.radiobuttonJoystick.TabStop = true; this.radiobuttonJoystick.Text = "Joystick:"; @@ -4038,7 +4037,7 @@ private void InitializeComponent() { this.radiobuttonKeyboard.AutoSize = true; this.radiobuttonKeyboard.Location = new System.Drawing.Point(8, 48); this.radiobuttonKeyboard.Name = "radiobuttonKeyboard"; - this.radiobuttonKeyboard.Size = new System.Drawing.Size(73, 17); + this.radiobuttonKeyboard.Size = new System.Drawing.Size(73, 18); this.radiobuttonKeyboard.TabIndex = 2; this.radiobuttonKeyboard.TabStop = true; this.radiobuttonKeyboard.Text = "Keyboard:"; @@ -4070,7 +4069,7 @@ private void InitializeComponent() { this.linkLabelReportBug.LinkColor = System.Drawing.Color.Gold; this.linkLabelReportBug.Location = new System.Drawing.Point(8, 56); this.linkLabelReportBug.Name = "linkLabelReportBug"; - this.linkLabelReportBug.Size = new System.Drawing.Size(128, 16); + this.linkLabelReportBug.Size = new System.Drawing.Size(128, 18); this.linkLabelReportBug.TabIndex = 8; this.linkLabelReportBug.TabStop = true; this.linkLabelReportBug.Text = "Report Problem"; @@ -4087,7 +4086,7 @@ private void InitializeComponent() { this.linkLabelCheckUpdates.LinkColor = System.Drawing.Color.Gold; this.linkLabelCheckUpdates.Location = new System.Drawing.Point(8, 40); this.linkLabelCheckUpdates.Name = "linkLabelCheckUpdates"; - this.linkLabelCheckUpdates.Size = new System.Drawing.Size(128, 16); + this.linkLabelCheckUpdates.Size = new System.Drawing.Size(128, 18); this.linkLabelCheckUpdates.TabIndex = 7; this.linkLabelCheckUpdates.TabStop = true; this.linkLabelCheckUpdates.Text = "Check for updates"; @@ -4104,7 +4103,7 @@ private void InitializeComponent() { this.aboutLabel.LinkColor = System.Drawing.Color.Gold; this.aboutLabel.Location = new System.Drawing.Point(8, 72); this.aboutLabel.Name = "aboutLabel"; - this.aboutLabel.Size = new System.Drawing.Size(128, 16); + this.aboutLabel.Size = new System.Drawing.Size(128, 18); this.aboutLabel.TabIndex = 6; this.aboutLabel.TabStop = true; this.aboutLabel.Text = "About"; @@ -4121,7 +4120,7 @@ private void InitializeComponent() { this.linkHomepage.LinkColor = System.Drawing.Color.Gold; this.linkHomepage.Location = new System.Drawing.Point(8, 24); this.linkHomepage.Name = "linkHomepage"; - this.linkHomepage.Size = new System.Drawing.Size(128, 16); + this.linkHomepage.Size = new System.Drawing.Size(128, 18); this.linkHomepage.TabIndex = 3; this.linkHomepage.TabStop = true; this.linkHomepage.Text = "Visit homepage"; @@ -4138,7 +4137,7 @@ private void InitializeComponent() { this.labelVersion.ForeColor = System.Drawing.Color.White; this.labelVersion.Location = new System.Drawing.Point(8, 8); this.labelVersion.Name = "labelVersion"; - this.labelVersion.Size = new System.Drawing.Size(144, 16); + this.labelVersion.Size = new System.Drawing.Size(144, 18); this.labelVersion.TabIndex = 1; this.labelVersion.Text = "v0.0.0.0"; this.labelVersion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; @@ -4251,9 +4250,9 @@ private void InitializeComponent() { // this.buttonBack2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonBack2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.buttonBack2.Location = new System.Drawing.Point(445, 565); + this.buttonBack2.Location = new System.Drawing.Point(445, 561); this.buttonBack2.Name = "buttonBack2"; - this.buttonBack2.Size = new System.Drawing.Size(120, 24); + this.buttonBack2.Size = new System.Drawing.Size(120, 28); this.buttonBack2.TabIndex = 18; this.buttonBack2.Text = "< Back"; this.buttonBack2.UseVisualStyleBackColor = true; @@ -4264,9 +4263,9 @@ private void InitializeComponent() { this.buttonNext.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonNext.Enabled = false; this.buttonNext.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.buttonNext.Location = new System.Drawing.Point(571, 565); + this.buttonNext.Location = new System.Drawing.Point(571, 561); this.buttonNext.Name = "buttonNext"; - this.buttonNext.Size = new System.Drawing.Size(120, 24); + this.buttonNext.Size = new System.Drawing.Size(120, 28); this.buttonNext.TabIndex = 17; this.buttonNext.Text = "Next >"; this.buttonNext.UseVisualStyleBackColor = true; @@ -4280,7 +4279,7 @@ private void InitializeComponent() { this.labelInstallText.ForeColor = System.Drawing.Color.Black; this.labelInstallText.Location = new System.Drawing.Point(179, 16); this.labelInstallText.Name = "labelInstallText"; - this.labelInstallText.Size = new System.Drawing.Size(340, 16); + this.labelInstallText.Size = new System.Drawing.Size(340, 18); this.labelInstallText.TabIndex = 16; this.labelInstallText.Text = "Install a Package"; this.labelInstallText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -4313,7 +4312,7 @@ private void InitializeComponent() { this.labelPackageDescription.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.labelPackageDescription.Location = new System.Drawing.Point(8, 420); this.labelPackageDescription.Name = "labelPackageDescription"; - this.labelPackageDescription.Size = new System.Drawing.Size(120, 13); + this.labelPackageDescription.Size = new System.Drawing.Size(120, 16); this.labelPackageDescription.TabIndex = 12; this.labelPackageDescription.Text = "Package Description:"; this.labelPackageDescription.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4325,7 +4324,7 @@ private void InitializeComponent() { this.linkLabelPackageWebsite.AutoSize = true; this.linkLabelPackageWebsite.Location = new System.Drawing.Point(134, 397); this.linkLabelPackageWebsite.Name = "linkLabelPackageWebsite"; - this.linkLabelPackageWebsite.Size = new System.Drawing.Size(112, 13); + this.linkLabelPackageWebsite.Size = new System.Drawing.Size(112, 16); this.linkLabelPackageWebsite.TabIndex = 11; this.linkLabelPackageWebsite.TabStop = true; this.linkLabelPackageWebsite.Text = "No package selected."; @@ -4336,7 +4335,7 @@ private void InitializeComponent() { this.labelPackageWebsite.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.labelPackageWebsite.Location = new System.Drawing.Point(8, 397); this.labelPackageWebsite.Name = "labelPackageWebsite"; - this.labelPackageWebsite.Size = new System.Drawing.Size(120, 13); + this.labelPackageWebsite.Size = new System.Drawing.Size(120, 16); this.labelPackageWebsite.TabIndex = 10; this.labelPackageWebsite.Text = "Package Website:"; this.labelPackageWebsite.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4356,7 +4355,7 @@ private void InitializeComponent() { this.labelPackageVersion.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.labelPackageVersion.Location = new System.Drawing.Point(8, 372); this.labelPackageVersion.Name = "labelPackageVersion"; - this.labelPackageVersion.Size = new System.Drawing.Size(120, 13); + this.labelPackageVersion.Size = new System.Drawing.Size(120, 16); this.labelPackageVersion.TabIndex = 8; this.labelPackageVersion.Text = "Package Version:"; this.labelPackageVersion.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4376,7 +4375,7 @@ private void InitializeComponent() { this.labelPackageAuthor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.labelPackageAuthor.Location = new System.Drawing.Point(8, 348); this.labelPackageAuthor.Name = "labelPackageAuthor"; - this.labelPackageAuthor.Size = new System.Drawing.Size(120, 13); + this.labelPackageAuthor.Size = new System.Drawing.Size(120, 16); this.labelPackageAuthor.TabIndex = 6; this.labelPackageAuthor.Text = "Package Author:"; this.labelPackageAuthor.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4396,7 +4395,7 @@ private void InitializeComponent() { this.labelPackageName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.labelPackageName.Location = new System.Drawing.Point(8, 324); this.labelPackageName.Name = "labelPackageName"; - this.labelPackageName.Size = new System.Drawing.Size(120, 13); + this.labelPackageName.Size = new System.Drawing.Size(120, 18); this.labelPackageName.TabIndex = 4; this.labelPackageName.Text = "Package Name:"; this.labelPackageName.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -4549,7 +4548,7 @@ private void InitializeComponent() { this.labelInstallSuccess1.ForeColor = System.Drawing.Color.Black; this.labelInstallSuccess1.Location = new System.Drawing.Point(8, 54); this.labelInstallSuccess1.Name = "labelInstallSuccess1"; - this.labelInstallSuccess1.Size = new System.Drawing.Size(129, 13); + this.labelInstallSuccess1.Size = new System.Drawing.Size(129, 18); this.labelInstallSuccess1.TabIndex = 17; this.labelInstallSuccess1.Text = "Installation was sucessful."; // @@ -4561,7 +4560,7 @@ private void InitializeComponent() { this.labelInstallSuccess2.ForeColor = System.Drawing.Color.Black; this.labelInstallSuccess2.Location = new System.Drawing.Point(179, 16); this.labelInstallSuccess2.Name = "labelInstallSuccess2"; - this.labelInstallSuccess2.Size = new System.Drawing.Size(340, 16); + this.labelInstallSuccess2.Size = new System.Drawing.Size(340, 18); this.labelInstallSuccess2.TabIndex = 16; this.labelInstallSuccess2.Text = "Installation Successful"; this.labelInstallSuccess2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -4757,7 +4756,7 @@ private void InitializeComponent() { this.labelProgressFile.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.labelProgressFile.Location = new System.Drawing.Point(1, 431); this.labelProgressFile.Name = "labelProgressFile"; - this.labelProgressFile.Size = new System.Drawing.Size(697, 24); + this.labelProgressFile.Size = new System.Drawing.Size(697, 30); this.labelProgressFile.TabIndex = 7; this.labelProgressFile.Text = "Unknown File..."; this.labelProgressFile.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -4769,7 +4768,7 @@ private void InitializeComponent() { this.labelProgressPercent.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.labelProgressPercent.Location = new System.Drawing.Point(290, 401); this.labelProgressPercent.Name = "labelProgressPercent"; - this.labelProgressPercent.Size = new System.Drawing.Size(118, 24); + this.labelProgressPercent.Size = new System.Drawing.Size(118, 30); this.labelProgressPercent.TabIndex = 6; this.labelProgressPercent.Text = "0%"; this.labelProgressPercent.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -4781,7 +4780,7 @@ private void InitializeComponent() { this.labelPleaseWait.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.labelPleaseWait.Location = new System.Drawing.Point(1, 462); this.labelPleaseWait.Name = "labelPleaseWait"; - this.labelPleaseWait.Size = new System.Drawing.Size(697, 24); + this.labelPleaseWait.Size = new System.Drawing.Size(697, 30); this.labelPleaseWait.TabIndex = 5; this.labelPleaseWait.Text = "Processing, please wait..."; this.labelPleaseWait.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -4819,9 +4818,9 @@ private void InitializeComponent() { this.buttonBack.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonBack.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonBack.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.buttonBack.Location = new System.Drawing.Point(445, 565); + this.buttonBack.Location = new System.Drawing.Point(445, 561); this.buttonBack.Name = "buttonBack"; - this.buttonBack.Size = new System.Drawing.Size(120, 24); + this.buttonBack.Size = new System.Drawing.Size(120, 28); this.buttonBack.TabIndex = 28; this.buttonBack.Text = "< Back"; this.buttonBack.UseVisualStyleBackColor = true; @@ -4835,7 +4834,7 @@ private void InitializeComponent() { this.buttonRemove.Enabled = false; this.buttonRemove.Location = new System.Drawing.Point(8, 525); this.buttonRemove.Name = "buttonRemove"; - this.buttonRemove.Size = new System.Drawing.Size(166, 23); + this.buttonRemove.Size = new System.Drawing.Size(166, 26); this.buttonRemove.TabIndex = 25; this.buttonRemove.Text = "Remove"; this.buttonRemove.UseVisualStyleBackColor = true; @@ -4859,7 +4858,7 @@ private void InitializeComponent() { this.labelDependanciesHeader.ForeColor = System.Drawing.Color.Black; this.labelDependanciesHeader.Location = new System.Drawing.Point(179, 16); this.labelDependanciesHeader.Name = "labelDependanciesHeader"; - this.labelDependanciesHeader.Size = new System.Drawing.Size(340, 16); + this.labelDependanciesHeader.Size = new System.Drawing.Size(340, 20); this.labelDependanciesHeader.TabIndex = 16; this.labelDependanciesHeader.Text = "Select Dependancies"; this.labelDependanciesHeader.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -4880,9 +4879,9 @@ private void InitializeComponent() { this.buttonCreatePackage.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonCreatePackage.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonCreatePackage.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.buttonCreatePackage.Location = new System.Drawing.Point(571, 565); + this.buttonCreatePackage.Location = new System.Drawing.Point(571, 561); this.buttonCreatePackage.Name = "buttonCreatePackage"; - this.buttonCreatePackage.Size = new System.Drawing.Size(120, 24); + this.buttonCreatePackage.Size = new System.Drawing.Size(120, 28); this.buttonCreatePackage.TabIndex = 14; this.buttonCreatePackage.Text = "Create"; this.buttonCreatePackage.UseVisualStyleBackColor = true; @@ -5000,7 +4999,7 @@ private void InitializeComponent() { this.labelInstalledDependancies.ForeColor = System.Drawing.Color.White; this.labelInstalledDependancies.Location = new System.Drawing.Point(0, 0); this.labelInstalledDependancies.Name = "labelInstalledDependancies"; - this.labelInstalledDependancies.Size = new System.Drawing.Size(683, 24); + this.labelInstalledDependancies.Size = new System.Drawing.Size(683, 26); this.labelInstalledDependancies.TabIndex = 20; this.labelInstalledDependancies.Text = "Installed Packages"; this.labelInstalledDependancies.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; @@ -5075,9 +5074,9 @@ private void InitializeComponent() { this.buttonReccomends.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonReccomends.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonReccomends.Enabled = false; - this.buttonReccomends.Location = new System.Drawing.Point(517, 1); + this.buttonReccomends.Location = new System.Drawing.Point(517, 0); this.buttonReccomends.Name = "buttonReccomends"; - this.buttonReccomends.Size = new System.Drawing.Size(166, 23); + this.buttonReccomends.Size = new System.Drawing.Size(166, 26); this.buttonReccomends.TabIndex = 24; this.buttonReccomends.Text = "Add Reccomendation"; this.buttonReccomends.UseVisualStyleBackColor = true; @@ -5103,9 +5102,9 @@ private void InitializeComponent() { this.buttonDepends.Enabled = false; this.buttonDepends.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonDepends.ForeColor = System.Drawing.SystemColors.ControlText; - this.buttonDepends.Location = new System.Drawing.Point(0, 2); + this.buttonDepends.Location = new System.Drawing.Point(0, 0); this.buttonDepends.Name = "buttonDepends"; - this.buttonDepends.Size = new System.Drawing.Size(166, 23); + this.buttonDepends.Size = new System.Drawing.Size(166, 26); this.buttonDepends.TabIndex = 23; this.buttonDepends.Text = "Add Dependancy"; this.buttonDepends.UseVisualStyleBackColor = true; @@ -5159,7 +5158,7 @@ private void InitializeComponent() { this.createPackageButton.BackColor = System.Drawing.SystemColors.ButtonFace; this.createPackageButton.Location = new System.Drawing.Point(281, 549); this.createPackageButton.Name = "createPackageButton"; - this.createPackageButton.Size = new System.Drawing.Size(136, 23); + this.createPackageButton.Size = new System.Drawing.Size(136, 26); this.createPackageButton.TabIndex = 23; this.createPackageButton.Text = "Create Package"; this.createPackageButton.UseVisualStyleBackColor = true; @@ -5172,7 +5171,7 @@ private void InitializeComponent() { this.buttonUninstallPackage.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonUninstallPackage.Location = new System.Drawing.Point(555, 549); this.buttonUninstallPackage.Name = "buttonUninstallPackage"; - this.buttonUninstallPackage.Size = new System.Drawing.Size(136, 23); + this.buttonUninstallPackage.Size = new System.Drawing.Size(136, 26); this.buttonUninstallPackage.TabIndex = 21; this.buttonUninstallPackage.Text = "Uninstall Package"; this.buttonUninstallPackage.UseVisualStyleBackColor = true; @@ -5185,7 +5184,7 @@ private void InitializeComponent() { this.buttonInstallPackage.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonInstallPackage.Location = new System.Drawing.Point(8, 549); this.buttonInstallPackage.Name = "buttonInstallPackage"; - this.buttonInstallPackage.Size = new System.Drawing.Size(136, 23); + this.buttonInstallPackage.Size = new System.Drawing.Size(136, 26); this.buttonInstallPackage.TabIndex = 20; this.buttonInstallPackage.Text = "Install Package"; this.buttonInstallPackage.UseVisualStyleBackColor = true; @@ -5253,7 +5252,7 @@ private void InitializeComponent() { this.labelInstalledPackages.ForeColor = System.Drawing.Color.White; this.labelInstalledPackages.Location = new System.Drawing.Point(8, 6); this.labelInstalledPackages.Name = "labelInstalledPackages"; - this.labelInstalledPackages.Size = new System.Drawing.Size(683, 24); + this.labelInstalledPackages.Size = new System.Drawing.Size(683, 26); this.labelInstalledPackages.TabIndex = 17; this.labelInstalledPackages.Text = "Installed Packages"; this.labelInstalledPackages.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; @@ -5290,9 +5289,9 @@ private void InitializeComponent() { this.buttonBack2.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonBack2.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonBack2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.buttonBack2.Location = new System.Drawing.Point(445, 565); + this.buttonBack2.Location = new System.Drawing.Point(445, 561); this.buttonBack2.Name = "buttonBack2"; - this.buttonBack2.Size = new System.Drawing.Size(120, 24); + this.buttonBack2.Size = new System.Drawing.Size(120, 28); this.buttonBack2.TabIndex = 18; this.buttonBack2.Text = "< Back"; this.buttonBack2.UseVisualStyleBackColor = true; @@ -5305,9 +5304,9 @@ private void InitializeComponent() { this.buttonNext.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonNext.Enabled = false; this.buttonNext.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.buttonNext.Location = new System.Drawing.Point(571, 565); + this.buttonNext.Location = new System.Drawing.Point(571, 561); this.buttonNext.Name = "buttonNext"; - this.buttonNext.Size = new System.Drawing.Size(120, 24); + this.buttonNext.Size = new System.Drawing.Size(120, 28); this.buttonNext.TabIndex = 17; this.buttonNext.Text = "Next >"; this.buttonNext.UseVisualStyleBackColor = true; @@ -5345,7 +5344,7 @@ private void InitializeComponent() { this.buttonSelectPackage.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.buttonSelectPackage.Location = new System.Drawing.Point(134, 535); this.buttonSelectPackage.Name = "buttonSelectPackage"; - this.buttonSelectPackage.Size = new System.Drawing.Size(180, 24); + this.buttonSelectPackage.Size = new System.Drawing.Size(180, 28); this.buttonSelectPackage.TabIndex = 14; this.buttonSelectPackage.Text = "Select Package..."; this.buttonSelectPackage.UseVisualStyleBackColor = true; @@ -5372,19 +5371,18 @@ private void InitializeComponent() { this.labelPackageDescription.ForeColor = System.Drawing.Color.Black; this.labelPackageDescription.Location = new System.Drawing.Point(8, 420); this.labelPackageDescription.Name = "labelPackageDescription"; - this.labelPackageDescription.Size = new System.Drawing.Size(120, 13); + this.labelPackageDescription.Size = new System.Drawing.Size(120, 18); this.labelPackageDescription.TabIndex = 12; this.labelPackageDescription.Text = "Package Description:"; this.labelPackageDescription.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // linkLabelPackageWebsite // - this.linkLabelPackageWebsite.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); + this.linkLabelPackageWebsite.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)))); this.linkLabelPackageWebsite.AutoSize = true; this.linkLabelPackageWebsite.Location = new System.Drawing.Point(134, 397); this.linkLabelPackageWebsite.Name = "linkLabelPackageWebsite"; - this.linkLabelPackageWebsite.Size = new System.Drawing.Size(112, 13); + this.linkLabelPackageWebsite.Size = new System.Drawing.Size(112, 18); this.linkLabelPackageWebsite.TabIndex = 11; this.linkLabelPackageWebsite.TabStop = true; this.linkLabelPackageWebsite.Text = "No package selected."; @@ -5396,7 +5394,7 @@ private void InitializeComponent() { this.labelPackageWebsite.ForeColor = System.Drawing.Color.Black; this.labelPackageWebsite.Location = new System.Drawing.Point(8, 397); this.labelPackageWebsite.Name = "labelPackageWebsite"; - this.labelPackageWebsite.Size = new System.Drawing.Size(120, 13); + this.labelPackageWebsite.Size = new System.Drawing.Size(120, 18); this.labelPackageWebsite.TabIndex = 10; this.labelPackageWebsite.Text = "Package Website:"; this.labelPackageWebsite.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -5419,7 +5417,7 @@ private void InitializeComponent() { this.labelPackageVersion.ForeColor = System.Drawing.Color.Black; this.labelPackageVersion.Location = new System.Drawing.Point(8, 372); this.labelPackageVersion.Name = "labelPackageVersion"; - this.labelPackageVersion.Size = new System.Drawing.Size(120, 13); + this.labelPackageVersion.Size = new System.Drawing.Size(120, 18); this.labelPackageVersion.TabIndex = 8; this.labelPackageVersion.Text = "Package Version:"; this.labelPackageVersion.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -5442,7 +5440,7 @@ private void InitializeComponent() { this.labelPackageAuthor.ForeColor = System.Drawing.Color.Black; this.labelPackageAuthor.Location = new System.Drawing.Point(8, 348); this.labelPackageAuthor.Name = "labelPackageAuthor"; - this.labelPackageAuthor.Size = new System.Drawing.Size(120, 13); + this.labelPackageAuthor.Size = new System.Drawing.Size(120, 18); this.labelPackageAuthor.TabIndex = 6; this.labelPackageAuthor.Text = "Package Author:"; this.labelPackageAuthor.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -5465,7 +5463,7 @@ private void InitializeComponent() { this.labelPackageName.ForeColor = System.Drawing.Color.Black; this.labelPackageName.Location = new System.Drawing.Point(8, 324); this.labelPackageName.Name = "labelPackageName"; - this.labelPackageName.Size = new System.Drawing.Size(120, 13); + this.labelPackageName.Size = new System.Drawing.Size(120, 18); this.labelPackageName.TabIndex = 4; this.labelPackageName.Text = "Package Name:"; this.labelPackageName.TextAlign = System.Drawing.ContentAlignment.MiddleRight; @@ -5511,9 +5509,9 @@ private void InitializeComponent() { this.buttonCancel.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonCancel.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonCancel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.buttonCancel.Location = new System.Drawing.Point(445, 565); + this.buttonCancel.Location = new System.Drawing.Point(445, 561); this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(120, 24); + this.buttonCancel.Size = new System.Drawing.Size(120, 28); this.buttonCancel.TabIndex = 29; this.buttonCancel.Text = "Cancel"; this.buttonCancel.UseVisualStyleBackColor = true; @@ -5728,9 +5726,9 @@ private void InitializeComponent() { this.buttonCancel2.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonCancel2.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonCancel2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.buttonCancel2.Location = new System.Drawing.Point(445, 565); + this.buttonCancel2.Location = new System.Drawing.Point(445, 561); this.buttonCancel2.Name = "buttonCancel2"; - this.buttonCancel2.Size = new System.Drawing.Size(120, 24); + this.buttonCancel2.Size = new System.Drawing.Size(120, 28); this.buttonCancel2.TabIndex = 38; this.buttonCancel2.Text = "Cancel"; this.buttonCancel2.UseVisualStyleBackColor = true; @@ -5743,7 +5741,7 @@ private void InitializeComponent() { this.SaveFileNameButton.ForeColor = System.Drawing.SystemColors.ControlText; this.SaveFileNameButton.Location = new System.Drawing.Point(571, 510); this.SaveFileNameButton.Name = "SaveFileNameButton"; - this.SaveFileNameButton.Size = new System.Drawing.Size(120, 23); + this.SaveFileNameButton.Size = new System.Drawing.Size(120, 26); this.SaveFileNameButton.TabIndex = 37; this.SaveFileNameButton.Text = "Save As...."; this.SaveFileNameButton.UseVisualStyleBackColor = true; @@ -5786,9 +5784,9 @@ private void InitializeComponent() { this.buttonCreateProceed.BackColor = System.Drawing.SystemColors.ButtonFace; this.buttonCreateProceed.ForeColor = System.Drawing.SystemColors.ControlText; this.buttonCreateProceed.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.buttonCreateProceed.Location = new System.Drawing.Point(571, 565); + this.buttonCreateProceed.Location = new System.Drawing.Point(571, 561); this.buttonCreateProceed.Name = "buttonCreateProceed"; - this.buttonCreateProceed.Size = new System.Drawing.Size(120, 24); + this.buttonCreateProceed.Size = new System.Drawing.Size(120, 28); this.buttonCreateProceed.TabIndex = 22; this.buttonCreateProceed.Text = "Next >"; this.buttonCreateProceed.UseVisualStyleBackColor = true; @@ -5898,9 +5896,9 @@ private void InitializeComponent() { this.labelPackageCreationHeader.BackColor = System.Drawing.Color.Silver; this.labelPackageCreationHeader.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.labelPackageCreationHeader.ForeColor = System.Drawing.Color.Black; - this.labelPackageCreationHeader.Location = new System.Drawing.Point(179, 16); + this.labelPackageCreationHeader.Location = new System.Drawing.Point(179, 14); this.labelPackageCreationHeader.Name = "labelPackageCreationHeader"; - this.labelPackageCreationHeader.Size = new System.Drawing.Size(340, 16); + this.labelPackageCreationHeader.Size = new System.Drawing.Size(340, 20); this.labelPackageCreationHeader.TabIndex = 16; this.labelPackageCreationHeader.Text = "Create a Package"; this.labelPackageCreationHeader.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -5956,7 +5954,7 @@ private void InitializeComponent() { this.packageToReplaceLabel.AutoSize = true; this.packageToReplaceLabel.Location = new System.Drawing.Point(8, 4); this.packageToReplaceLabel.Name = "packageToReplaceLabel"; - this.packageToReplaceLabel.Size = new System.Drawing.Size(230, 13); + this.packageToReplaceLabel.Size = new System.Drawing.Size(230, 16); this.packageToReplaceLabel.TabIndex = 24; this.packageToReplaceLabel.Text = "Please select the package you wish to replace:"; // @@ -6040,7 +6038,7 @@ private void InitializeComponent() { this.newPackageClearSelectionButton.BackColor = System.Drawing.SystemColors.ButtonFace; this.newPackageClearSelectionButton.Location = new System.Drawing.Point(572, 326); this.newPackageClearSelectionButton.Name = "newPackageClearSelectionButton"; - this.newPackageClearSelectionButton.Size = new System.Drawing.Size(121, 23); + this.newPackageClearSelectionButton.Size = new System.Drawing.Size(121, 26); this.newPackageClearSelectionButton.TabIndex = 30; this.newPackageClearSelectionButton.Text = "Clear Selection"; this.newPackageClearSelectionButton.UseVisualStyleBackColor = true; @@ -6066,7 +6064,7 @@ private void InitializeComponent() { this.addPackageItemsButton.ForeColor = System.Drawing.SystemColors.ControlText; this.addPackageItemsButton.Location = new System.Drawing.Point(8, 326); this.addPackageItemsButton.Name = "addPackageItemsButton"; - this.addPackageItemsButton.Size = new System.Drawing.Size(121, 23); + this.addPackageItemsButton.Size = new System.Drawing.Size(121, 26); this.addPackageItemsButton.TabIndex = 28; this.addPackageItemsButton.Text = "Add Folder"; this.addPackageItemsButton.UseVisualStyleBackColor = true; diff --git a/source/OpenBVE/UserInterface/formMain.Packages.cs b/source/OpenBVE/UserInterface/formMain.Packages.cs index 7fa1e0f82..5ea90e631 100644 --- a/source/OpenBVE/UserInterface/formMain.Packages.cs +++ b/source/OpenBVE/UserInterface/formMain.Packages.cs @@ -1281,7 +1281,7 @@ private static DialogResult ShowInputDialog(ref string input) { DialogResult = DialogResult.OK, Name = "okButton", - Size = new Size(75, 23), + Size = new Size(75, 26), Text = Translations.GetInterfaceString("packages_button_ok"), Location = new Point(size.Width - 80 - 80, 39) }; @@ -1291,7 +1291,7 @@ private static DialogResult ShowInputDialog(ref string input) { DialogResult = DialogResult.Cancel, Name = "cancelButton", - Size = new Size(75, 23), + Size = new Size(75, 26), Text = Translations.GetInterfaceString("packages_button_cancel"), Location = new Point(size.Width - 80, 39) }; diff --git a/source/OpenBVE/UserInterface/formMain.cs b/source/OpenBVE/UserInterface/formMain.cs index 3f0e44702..3850402d3 100644 --- a/source/OpenBVE/UserInterface/formMain.cs +++ b/source/OpenBVE/UserInterface/formMain.cs @@ -586,7 +586,7 @@ private void comboBoxFont_SelectedIndexChanged(object sender, EventArgs e) { SetFont(Controls, font.Name); Interface.CurrentOptions.Font = font.Name; - Program.Renderer.Fonts = new Fonts(Program.CurrentHost, Program.FileSystem, font.Name); + Program.Renderer.Fonts = new Fonts(Program.CurrentHost, font.Name); } catch { @@ -594,7 +594,7 @@ private void comboBoxFont_SelectedIndexChanged(object sender, EventArgs e) MessageBox.Show(@"Failed to set font " + font.Name, Translations.GetInterfaceString("program_title"), MessageBoxButtons.OK, MessageBoxIcon.Warning); SetFont(Controls, oldFont); Interface.CurrentOptions.Font = oldFont; - Program.Renderer.Fonts = new Fonts(Program.CurrentHost, Program.FileSystem, oldFont); + Program.Renderer.Fonts = new Fonts(Program.CurrentHost, oldFont); } } diff --git a/source/OpenBveApi/FunctionScripts/FunctionScript.cs b/source/OpenBveApi/FunctionScripts/FunctionScript.cs index e533acc2c..9da148549 100644 --- a/source/OpenBveApi/FunctionScripts/FunctionScript.cs +++ b/source/OpenBveApi/FunctionScripts/FunctionScript.cs @@ -421,6 +421,10 @@ public FunctionScript(HostInterface Host, string Expression, bool Infix) if (n >= InstructionSet.Length) Array.Resize(ref InstructionSet, InstructionSet.Length << 1); InstructionSet[n] = Instructions.TrainDestination; n++; s++; if (s >= m) m = s; break; + case "length": + if (n >= InstructionSet.Length) Array.Resize(ref InstructionSet, InstructionSet.Length << 1); + InstructionSet[n] = Instructions.TrainLength; + n++; s++; if (s >= m) m = s; break; case "speed": if (n >= InstructionSet.Length) Array.Resize(ref InstructionSet, InstructionSet.Length << 1); InstructionSet[n] = Instructions.TrainSpeed; diff --git a/source/OpenBveApi/FunctionScripts/Instructions.cs b/source/OpenBveApi/FunctionScripts/Instructions.cs index 2f078b7f2..b4b1c57e3 100644 --- a/source/OpenBveApi/FunctionScripts/Instructions.cs +++ b/source/OpenBveApi/FunctionScripts/Instructions.cs @@ -17,7 +17,7 @@ public enum Instructions { StackCopy, StackSwap, MathRandom, MathRandomInt, TimeSecondsSinceMidnight, TimeHourDigit, TimeMinuteDigit, TimeSecondDigit, CameraDistance, CameraXDistance, CameraYDistance, CameraZDistance,CameraView, - TrainCars, TrainCarNumber, TrainDestination, PlayerTrain, + TrainCars, TrainCarNumber, TrainDestination, PlayerTrain, TrainLength, TrainSpeed, TrainSpeedometer, TrainAcceleration, TrainAccelerationMotor, TrainSpeedOfCar, TrainSpeedometerOfCar, TrainAccelerationOfCar, TrainAccelerationMotorOfCar, TrainDistance, TrainDistanceToCar, TrainTrackDistance, TrainTrackDistanceToCar, CurveRadius, CurveRadiusOfCar, FrontAxleCurveRadius, FrontAxleCurveRadiusOfCar, RearAxleCurveRadius, RearAxleCurveRadiusOfCar, CurveCant, CurveCantOfCar, Pitch, PitchOfCar, Odometer, OdometerOfCar, BrightnessOfCar, diff --git a/source/OpenBveApi/Math/Vectors/Vector2.cs b/source/OpenBveApi/Math/Vectors/Vector2.cs index eefd61427..9c12a88e7 100644 --- a/source/OpenBveApi/Math/Vectors/Vector2.cs +++ b/source/OpenBveApi/Math/Vectors/Vector2.cs @@ -32,6 +32,37 @@ public Vector2(Vector2 v) this.X = v.X; this.Y = v.Y; } + + /// Parses a Vector2 from a list of strings + /// The list of strings + /// The out Vector + /// True if parsing succeded with no errors, false otherwise + /// This will always return a Vector3. + /// If any part fails parsing, it will be set to zero + public static bool TryParse(string[] arguments, out Vector2 v) + { + bool success = arguments.Length == 2; + v.X = 0; v.Y = 0;; + for (int i = 0; i < arguments.Length; i++) + { + switch (i) + { + case 0: + if (!double.TryParse(arguments[i], out v.X)) + { + success = false; + } + break; + case 1: + if (!double.TryParse(arguments[i], out v.Y)) + { + success = false; + } + break; + } + } + return success; + } // --- arithmetic operators --- diff --git a/source/OpenBveApi/Math/Vectors/Vector3.cs b/source/OpenBveApi/Math/Vectors/Vector3.cs index fb070f76b..dfd1cc56d 100644 --- a/source/OpenBveApi/Math/Vectors/Vector3.cs +++ b/source/OpenBveApi/Math/Vectors/Vector3.cs @@ -82,6 +82,43 @@ public static bool TryParse(string stringToParse, char separator, out Vector3 v) return success; } + /// Parses a Vector3 from a list of strings + /// The list of strings + /// The out Vector + /// True if parsing succeded with no errors, false otherwise + /// This will always return a Vector3. + /// If any part fails parsing, it will be set to zero + public static bool TryParse(string[] arguments, out Vector3 v) + { + bool success = arguments.Length == 3; + v.X = 0; v.Y = 0; v.Z = 0; + for (int i = 0; i < arguments.Length; i++) + { + switch (i) + { + case 0: + if (!double.TryParse(arguments[i], out v.X)) + { + success = false; + } + break; + case 1: + if (!double.TryParse(arguments[i], out v.Y)) + { + success = false; + } + break; + case 2: + if (!double.TryParse(arguments[i], out v.Z)) + { + success = false; + } + break; + } + } + return success; + } + /// Interpolates between two Vector3 values using a simple Cosine algorithm /// The first vector /// The second vector diff --git a/source/OpenBveApi/Objects/Mesh.cs b/source/OpenBveApi/Objects/Mesh.cs index b754644cd..412ba69ca 100644 --- a/source/OpenBveApi/Objects/Mesh.cs +++ b/source/OpenBveApi/Objects/Mesh.cs @@ -116,7 +116,7 @@ private void CreateNormals(int FaceIndex) { if (Vector3.IsZero(Faces[FaceIndex].Vertices[j].Normal)) { - Faces[FaceIndex].Vertices[j].Normal = new Vector3(0.0f, 1.0f, 0.0f); + Faces[FaceIndex].Vertices[j].Normal = Vector3.Down; } } } diff --git a/source/OpenBveApi/Objects/MeshFace.cs b/source/OpenBveApi/Objects/MeshFace.cs index 6047de321..6fc71a0d9 100644 --- a/source/OpenBveApi/Objects/MeshFace.cs +++ b/source/OpenBveApi/Objects/MeshFace.cs @@ -39,8 +39,8 @@ public MeshFace(int[] Vertices, FaceFlags Type = FaceFlags.NotSet) this.Vertices[i] = new MeshFaceVertex(Vertices[i]); } - this.Material = 0; - this.Flags = 0; + Material = 0; + Flags = 0; IboStartIndex = 0; NormalsIboStartIndex = 0; if (Type != FaceFlags.NotSet) @@ -55,9 +55,20 @@ public MeshFace(int[] Vertices, FaceFlags Type = FaceFlags.NotSet) [CLSCompliant(false)] public MeshFace(MeshFaceVertex[] verticies, ushort material) { - this.Vertices = verticies; - this.Material = material; - this.Flags = 0; + Vertices = verticies; + Material = material; + Flags = 0; + IboStartIndex = 0; + NormalsIboStartIndex = 0; + } + + /// Creates a new MeshFace containing N vertices + /// The number of vertices in the face + public MeshFace(int numVertices) + { + Vertices = new MeshFaceVertex[numVertices]; + Material = 0; + Flags = 0; IboStartIndex = 0; NormalsIboStartIndex = 0; } @@ -67,21 +78,21 @@ public void Flip() { if (((FaceFlags)Flags & FaceFlags.FaceTypeMask) == FaceFlags.QuadStrip) { - for (int i = 0; i < this.Vertices.Length; i += 2) + for (int i = 0; i < Vertices.Length; i += 2) { - MeshFaceVertex x = this.Vertices[i]; - this.Vertices[i] = this.Vertices[i + 1]; - this.Vertices[i + 1] = x; + MeshFaceVertex x = Vertices[i]; + Vertices[i] = Vertices[i + 1]; + Vertices[i + 1] = x; } } else { - int n = this.Vertices.Length; + int n = Vertices.Length; for (int i = 0; i < (n >> 1); i++) { - MeshFaceVertex x = this.Vertices[i]; - this.Vertices[i] = this.Vertices[n - i - 1]; - this.Vertices[n - i - 1] = x; + MeshFaceVertex x = Vertices[i]; + Vertices[i] = Vertices[n - i - 1]; + Vertices[n - i - 1] = x; } } } diff --git a/source/OpenBveApi/Objects/MeshFaceVertex.cs b/source/OpenBveApi/Objects/MeshFaceVertex.cs index 5b919f0ef..596c8fd03 100644 --- a/source/OpenBveApi/Objects/MeshFaceVertex.cs +++ b/source/OpenBveApi/Objects/MeshFaceVertex.cs @@ -18,7 +18,7 @@ public struct MeshFaceVertex public MeshFaceVertex(int Index) { this.Index = (ushort) Index; - this.Normal = new Vector3(0.0f, 0.0f, 0.0f); + this.Normal = Vector3.Zero; } /// Creates a new MeshFaceVertex with the specified normal vector diff --git a/source/OpenBveApi/System/FileSystem.cs b/source/OpenBveApi/System/FileSystem.cs index efd7efe62..fdf736b21 100644 --- a/source/OpenBveApi/System/FileSystem.cs +++ b/source/OpenBveApi/System/FileSystem.cs @@ -3,6 +3,7 @@ using System.Reflection; using System.Text; using System.Windows.Forms; +using Microsoft.Win32; using OpenBveApi.Hosts; // ReSharper disable PossibleNullReferenceException @@ -22,11 +23,8 @@ public class FileSystem { /// The location of the application data, including, among others, Compatibility, Flags and Languages. public string DataFolder; - /// The locations of managed content. - internal string[] ManagedContentFolders; - /// Gets the package database folder - public string PackageDatabaseFolder => OpenBveApi.Path.CombineDirectory(SettingsFolder, "PackageDatabase"); + public string PackageDatabaseFolder => Path.CombineDirectory(SettingsFolder, "PackageDatabase"); /// The location where to save user settings, including settings.cfg and controls.cfg. public string SettingsFolder; @@ -55,6 +53,9 @@ public class FileSystem { /// The location to which Loksim3D packages will be installed public string LoksimPackageInstallationDirectory; + /// The Loksim3D data directory + public string LoksimDataDirectory; + /// Any lines loaded from the filesystem.cfg which were not understood internal string[] NotUnderstoodLines; @@ -62,6 +63,7 @@ public class FileSystem { internal int Version; /// The host application + // ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable private readonly HostInterface currentHost; @@ -74,7 +76,7 @@ internal FileSystem(HostInterface Host) string assemblyFile = Assembly.GetEntryAssembly().Location; string assemblyFolder = System.IO.Path.GetDirectoryName(assemblyFile); //This copy of openBVE is a special string, and should not be localised - string userDataFolder = OpenBveApi.Path.CombineDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OpenBve"); + string userDataFolder = Path.CombineDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OpenBve"); if (currentHost != null && currentHost.Platform != HostPlatform.MicrosoftWindows) { /* @@ -86,7 +88,7 @@ internal FileSystem(HostInterface Host) int i = 0; while (File.Exists(userDataFolder)) { - userDataFolder = OpenBveApi.Path.CombineDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OpenBve-" + i); + userDataFolder = Path.CombineDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OpenBve-" + i); i++; if (i == 10) { @@ -96,17 +98,32 @@ internal FileSystem(HostInterface Host) } } } - this.DataFolder = OpenBveApi.Path.CombineDirectory(assemblyFolder, "Data"); - this.ManagedContentFolders = new string[] { OpenBveApi.Path.CombineDirectory(userDataFolder, "ManagedContent") }; - this.SettingsFolder = OpenBveApi.Path.CombineDirectory(userDataFolder, "Settings"); - this.InitialRouteFolder = OpenBveApi.Path.CombineDirectory(OpenBveApi.Path.CombineDirectory(OpenBveApi.Path.CombineDirectory(userDataFolder, "LegacyContent"), "Railway"), "Route"); - this.RouteInstallationDirectory = OpenBveApi.Path.CombineDirectory(OpenBveApi.Path.CombineDirectory(userDataFolder, "LegacyContent"), "Railway"); - this.InitialTrainFolder = OpenBveApi.Path.CombineDirectory(OpenBveApi.Path.CombineDirectory(userDataFolder, "LegacyContent"), "Train"); - this.TrainInstallationDirectory = OpenBveApi.Path.CombineDirectory(OpenBveApi.Path.CombineDirectory(userDataFolder, "LegacyContent"), "Train"); - this.OtherInstallationDirectory = OpenBveApi.Path.CombineDirectory(OpenBveApi.Path.CombineDirectory(userDataFolder, "LegacyContent"), "Other"); - this.LoksimPackageInstallationDirectory = OpenBveApi.Path.CombineDirectory(OpenBveApi.Path.CombineDirectory(userDataFolder, "ManagedContent"), "Loksim3D"); - this.RestartProcess = assemblyFile; - this.RestartArguments = string.Empty; + DataFolder = Path.CombineDirectory(assemblyFolder, "Data"); + SettingsFolder = Path.CombineDirectory(userDataFolder, "Settings"); + InitialRouteFolder = Path.CombineDirectory(Path.CombineDirectory(Path.CombineDirectory(userDataFolder, "LegacyContent"), "Railway"), "Route"); + RouteInstallationDirectory = Path.CombineDirectory(Path.CombineDirectory(userDataFolder, "LegacyContent"), "Railway"); + InitialTrainFolder = Path.CombineDirectory(Path.CombineDirectory(userDataFolder, "LegacyContent"), "Train"); + TrainInstallationDirectory = Path.CombineDirectory(Path.CombineDirectory(userDataFolder, "LegacyContent"), "Train"); + OtherInstallationDirectory = Path.CombineDirectory(Path.CombineDirectory(userDataFolder, "LegacyContent"), "Other"); + LoksimPackageInstallationDirectory = Path.CombineDirectory(Path.CombineDirectory(userDataFolder, "ManagedContent"), "Loksim3D"); + if (currentHost.Platform == HostPlatform.MicrosoftWindows) + { + try + { + RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Loksim-Group\\Install"); + LoksimDataDirectory = key.GetValue("InstallDataDirPath").ToString(); + } + catch + { + LoksimDataDirectory = LoksimPackageInstallationDirectory; // minor fudge + } + } + else + { + LoksimDataDirectory = LoksimPackageInstallationDirectory; // FIXME: Should this be saved on non Win-32 platforms?? + } + RestartProcess = assemblyFile; + RestartArguments = string.Empty; } @@ -123,11 +140,11 @@ public static FileSystem FromCommandLineArgs(string[] args, HostInterface Host) } } string assemblyFolder = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); - string configFile = OpenBveApi.Path.CombineFile(OpenBveApi.Path.CombineDirectory(OpenBveApi.Path.CombineDirectory(assemblyFolder, "UserData"), "Settings"), "filesystem.cfg"); + string configFile = Path.CombineFile(Path.CombineDirectory(Path.CombineDirectory(assemblyFolder, "UserData"), "Settings"), "filesystem.cfg"); if (File.Exists(configFile)) { return FromConfigurationFile(configFile, Host); } - configFile = OpenBveApi.Path.CombineFile(OpenBveApi.Path.CombineDirectory(OpenBveApi.Path.CombineDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OpenBve"), "Settings"), "filesystem.cfg"); + configFile = Path.CombineFile(Path.CombineDirectory(Path.CombineDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "OpenBve"), "Settings"), "filesystem.cfg"); if (File.Exists(configFile)) { return FromConfigurationFile(configFile, Host); @@ -139,7 +156,7 @@ public static FileSystem FromCommandLineArgs(string[] args, HostInterface Host) /// Saves the current file system configuration to disk public void SaveCurrentFileSystemConfiguration() { - string file = OpenBveApi.Path.CombineFile(this.SettingsFolder, "FileSystem.cfg"); + string file = Path.CombineFile(SettingsFolder, "FileSystem.cfg"); StringBuilder newLines = new StringBuilder(); newLines.AppendLine("Version=1"); try @@ -174,46 +191,46 @@ public void SaveCurrentFileSystemConfiguration() { //Create a new filesystem.cfg file using the current filesystem setup as a base //Where does the Debian package point it's filesystem.cfg to?? - newLines.AppendLine("Data=" + this.DataFolder); - newLines.AppendLine("Settings=" + this.SettingsFolder); - newLines.AppendLine("InitialRoute=" + this.InitialRouteFolder); - newLines.AppendLine("InitialTrain=" + this.InitialTrainFolder); - newLines.AppendLine("RestartProcess=" + this.RestartProcess); - newLines.AppendLine("RestartArguments=" + this.RestartArguments); + newLines.AppendLine("Data=" + DataFolder); + newLines.AppendLine("Settings=" + SettingsFolder); + newLines.AppendLine("InitialRoute=" + InitialRouteFolder); + newLines.AppendLine("InitialTrain=" + InitialTrainFolder); + newLines.AppendLine("RestartProcess=" + RestartProcess); + newLines.AppendLine("RestartArguments=" + RestartArguments); } - if (this.RouteInstallationDirectory != null && - Directory.Exists(this.RouteInstallationDirectory)) + if (RouteInstallationDirectory != null && + Directory.Exists(RouteInstallationDirectory)) { - newLines.AppendLine("RoutePackageInstall=" + ReplacePath(this.RouteInstallationDirectory)); + newLines.AppendLine("RoutePackageInstall=" + ReplacePath(RouteInstallationDirectory)); } - if (this.TrainInstallationDirectory != null && - Directory.Exists(this.TrainInstallationDirectory)) + if (TrainInstallationDirectory != null && + Directory.Exists(TrainInstallationDirectory)) { - newLines.AppendLine("TrainPackageInstall=" + ReplacePath(this.TrainInstallationDirectory)); + newLines.AppendLine("TrainPackageInstall=" + ReplacePath(TrainInstallationDirectory)); } - if (this.OtherInstallationDirectory != null && - Directory.Exists(this.OtherInstallationDirectory)) + if (OtherInstallationDirectory != null && + Directory.Exists(OtherInstallationDirectory)) { - newLines.AppendLine("OtherPackageInstall=" + ReplacePath(this.OtherInstallationDirectory)); + newLines.AppendLine("OtherPackageInstall=" + ReplacePath(OtherInstallationDirectory)); } - if (this.LoksimPackageInstallationDirectory != null && - Directory.Exists(this.LoksimPackageInstallationDirectory)) + if (LoksimPackageInstallationDirectory != null && + Directory.Exists(LoksimPackageInstallationDirectory)) { - newLines.AppendLine("LoksimPackageInstall=" + ReplacePath(this.LoksimPackageInstallationDirectory)); + newLines.AppendLine("LoksimPackageInstall=" + ReplacePath(LoksimPackageInstallationDirectory)); } - if (this.NotUnderstoodLines != null && this.NotUnderstoodLines.Length != 0) + if (NotUnderstoodLines != null && NotUnderstoodLines.Length != 0) { - for (int i = 0; i < this.NotUnderstoodLines.Length; i++) + for (int i = 0; i < NotUnderstoodLines.Length; i++) { - newLines.Append(this.NotUnderstoodLines[i]); + newLines.Append(NotUnderstoodLines[i]); } } - System.IO.File.WriteAllText(file, newLines.ToString(), new System.Text.UTF8Encoding(true)); + File.WriteAllText(file, newLines.ToString(), new UTF8Encoding(true)); } catch { - + // ignored } } @@ -231,35 +248,58 @@ internal static string ReplacePath(string line) } catch { + // ignored } return line; } /// Creates all folders in the file system that can later be written to. public void CreateFileSystem() { - try { - Directory.CreateDirectory(this.SettingsFolder); - } catch { } - foreach (string folder in this.ManagedContentFolders) { - try { - Directory.CreateDirectory(folder); - } catch { } + try + { + if (!string.IsNullOrEmpty(SettingsFolder) && !Directory.Exists(SettingsFolder)) + { + Directory.CreateDirectory(SettingsFolder); + } + } + catch(Exception ex) + { + AppendToLogFile("Failed to create the Settings Folder with exception " + ex); + } + + try + { + if (!string.IsNullOrEmpty(InitialRouteFolder) && !Directory.Exists(InitialRouteFolder)) + { + Directory.CreateDirectory(InitialRouteFolder); + } + + } + catch(Exception ex) + { + AppendToLogFile("Failed to create the Initial Route Folder with exception " + ex); + } + + try + { + if (!string.IsNullOrEmpty(InitialTrainFolder) && !Directory.Exists(InitialTrainFolder)) + { + Directory.CreateDirectory(InitialTrainFolder); + } + } + catch(Exception ex) + { + AppendToLogFile("Failed to create the Initial Train Folder with exception " + ex); } - try { - Directory.CreateDirectory(this.InitialRouteFolder); - } catch { } - try { - Directory.CreateDirectory(this.InitialTrainFolder); - } catch { } } /// Gets the data folder or any specified subfolder thereof. /// The subfolders. /// The data folder or a subfolder thereof. public string GetDataFolder(params string[] subfolders) { - string folder = this.DataFolder; + string folder = DataFolder; foreach (string subfolder in subfolders) { - folder = OpenBveApi.Path.CombineDirectory(folder, subfolder); + folder = Path.CombineDirectory(folder, subfolder); } return folder; } @@ -292,23 +332,17 @@ private static FileSystem FromConfigurationFile(string file, HostInterface Host) system.DataFolder = GetAbsolutePath(value, true); if (!Directory.Exists(system.DataFolder)) { - system.DataFolder = OpenBveApi.Path.CombineDirectory(assemblyFolder, "Data"); + system.DataFolder = Path.CombineDirectory(assemblyFolder, "Data"); if (!Directory.Exists(system.DataFolder)) { //If we are still unable to find the default data folder, this is a critical error, as it contains all sorts of essential stuff..... - MessageBox.Show(@"Unable to find the OpenBVE Data folder." + Environment.NewLine + - "OpenBVE will now exit as the Data folder is required for normal operation." + Environment.NewLine + Environment.NewLine + - "Please consider reinstalling OpenBVE.", "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); + MessageBox.Show(@"Unable to find the OpenBVE Data folder." + Environment.NewLine + + @"OpenBVE will now exit as the Data folder is required for normal operation." + Environment.NewLine + Environment.NewLine + + @"Please consider reinstalling OpenBVE.", @"Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); Environment.Exit(0); } } - break; - case "managedcontent": - system.ManagedContentFolders = value.Split(','); - for (int i = 0; i < system.ManagedContentFolders.Length; i++) - { - system.ManagedContentFolders[i] = GetAbsolutePath(system.ManagedContentFolders[i].Trim(new char[] { }), true); - } + break; case "version": int v; @@ -316,17 +350,17 @@ private static FileSystem FromConfigurationFile(string file, HostInterface Host) { system.AppendToLogFile("WARNING: Invalid filesystem.cfg version detected."); } + if (v <= 1) { //Silently upgrade to the current config version system.Version = 1; break; } - if (v > 1) - { - system.AppendToLogFile("WARNING: A newer filesystem.cfg version " + v + " was detected. The current version is 1."); - system.Version = v; - } + + system.AppendToLogFile("WARNING: A newer filesystem.cfg version " + v + " was detected. The current version is 1."); + system.Version = v; + break; case "settings": string folder = GetAbsolutePath(value, true); @@ -345,7 +379,7 @@ private static FileSystem FromConfigurationFile(string file, HostInterface Host) } string settingsFile = Path.CombineFile(folder, "1.5.0\\options.cfg"); - using (FileStream fs = File.OpenWrite(settingsFile)) + using (FileStream unused = File.OpenWrite(settingsFile)) { //Write test } @@ -355,8 +389,9 @@ private static FileSystem FromConfigurationFile(string file, HostInterface Host) value = value.Replace("$[AssemblyFolder]", "$[ApplicationData]"); folder = GetAbsolutePath(value, true); } - + } + system.SettingsFolder = folder; break; case "initialroute": @@ -388,6 +423,7 @@ private static FileSystem FromConfigurationFile(string file, HostInterface Host) { system.NotUnderstoodLines = new string[0]; } + int l = system.NotUnderstoodLines.Length; Array.Resize(ref system.NotUnderstoodLines, system.NotUnderstoodLines.Length + 1); system.NotUnderstoodLines[l] = line; @@ -397,7 +433,10 @@ private static FileSystem FromConfigurationFile(string file, HostInterface Host) } } } - catch { } + catch + { + // ignored + } return system; } @@ -424,19 +463,29 @@ private static string GetAbsolutePath(string folder, bool checkIfRooted) { /// Clears the log file. public void ClearLogFile(string version) { - try { - string file = System.IO.Path.Combine(this.SettingsFolder, "log.txt"); - System.IO.File.WriteAllText(file, @"OpenBVE Log: " + DateTime.Now + Environment.NewLine + @"Program Version: " + version + Environment.NewLine + Environment.NewLine, new System.Text.UTF8Encoding(true)); - } catch { } + try + { + string file = System.IO.Path.Combine(SettingsFolder, "log.txt"); + File.WriteAllText(file, @"OpenBVE Log: " + DateTime.Now + Environment.NewLine + @"Program Version: " + version + Environment.NewLine + Environment.NewLine, new UTF8Encoding(true)); + } + catch + { + // ignored + } } /// Appends the specified text to the log file. /// The text. public void AppendToLogFile(string text) { - try { - string file = System.IO.Path.Combine(this.SettingsFolder, "log.txt"); - System.IO.File.AppendAllText(file, DateTime.Now.ToString("HH:mm:ss") + @" " + text + Environment.NewLine, new System.Text.UTF8Encoding(false)); - } catch { } + try + { + string file = System.IO.Path.Combine(SettingsFolder, "log.txt"); + File.AppendAllText(file, DateTime.Now.ToString("HH:mm:ss") + @" " + text + Environment.NewLine, new UTF8Encoding(false)); + } + catch + { + // ignored + } } } } diff --git a/source/OpenBveApi/System/Path.cs b/source/OpenBveApi/System/Path.cs index e97934acc..572c8e830 100644 --- a/source/OpenBveApi/System/Path.cs +++ b/source/OpenBveApi/System/Path.cs @@ -29,6 +29,14 @@ public static partial class Path { /// A platform-specific absolute path to the specified directory. /// Raised when combining the paths failed, for example due to malformed paths or due to unauthorized access. public static string CombineDirectory(string absolute, string relative, bool allowQueryStr) { + if (string.IsNullOrEmpty(absolute)) + { + throw new ArgumentException("The absolute path was empty."); + } + if (string.IsNullOrEmpty(relative)) + { + throw new ArgumentException("The relative path was empty."); + } int index = relative.IndexOf("??", StringComparison.Ordinal); if (index >= 0) { string directory = CombineDirectory(absolute, relative.Substring(0, index).TrimEnd()); @@ -126,6 +134,14 @@ public static string CombineDirectory(string absolute, string relative) { /// Whether the operation succeeded and the specified file was found. /// Raised when combining the paths failed, for example due to malformed paths or due to unauthorized access. public static string CombineFile(string absolute, string relative) { + if (string.IsNullOrEmpty(absolute)) + { + throw new ArgumentException("The absolute path was empty."); + } + if (string.IsNullOrEmpty(relative)) + { + throw new ArgumentException("The relative path was empty."); + } int index = relative.IndexOf("??", StringComparison.Ordinal); if (index >= 0) { string file = CombineFile(absolute, relative.Substring(0, index).TrimEnd()); diff --git a/source/OpenBveApi/Train/AbstractTrain.cs b/source/OpenBveApi/Train/AbstractTrain.cs index d519bdf6d..04afb2afe 100644 --- a/source/OpenBveApi/Train/AbstractTrain.cs +++ b/source/OpenBveApi/Train/AbstractTrain.cs @@ -46,23 +46,14 @@ public abstract class AbstractTrain public abstract double RearCarTrackPosition(); /// Returns true if this is the player driven train - public virtual bool IsPlayerTrain - { - get - { - //An abstract train in and of itself cannot be the player train - return false; - } - } + /// NOTE: An abstract train in and of itself cannot be the player train + public virtual bool IsPlayerTrain => false; /// Returns the number of cars in this train - public virtual int NumberOfCars - { - get - { - return 0; - } - } + public virtual int NumberOfCars => 0; + + /// Gets the length of the train + public virtual double Length => 0; /// Updates the train /// The time elapsed since the last call to update diff --git a/source/Plugins/Object.Animated/Plugin.Parser.cs b/source/Plugins/Object.Animated/Plugin.Parser.cs index 96ba982bb..b5780e2c6 100644 --- a/source/Plugins/Object.Animated/Plugin.Parser.cs +++ b/source/Plugins/Object.Animated/Plugin.Parser.cs @@ -201,8 +201,8 @@ private static AnimatedObjectCollection ReadObject(string FileName, System.Text. RotateXDirection = Vector3.Right, RotateYDirection = Vector3.Down, RotateZDirection = Vector3.Forward, - TextureShiftXDirection = new Vector2(1.0, 0.0), - TextureShiftYDirection = new Vector2(0.0, 1.0), + TextureShiftXDirection = Vector2.Right, + TextureShiftYDirection = Vector2.Down, RefreshRate = 0.0, }; Vector3 Position = Vector3.Zero; diff --git a/source/Plugins/Object.CsvB3d/Plugin.Parser.cs b/source/Plugins/Object.CsvB3d/Plugin.Parser.cs index 67cc06026..f2b5bdb0a 100644 --- a/source/Plugins/Object.CsvB3d/Plugin.Parser.cs +++ b/source/Plugins/Object.CsvB3d/Plugin.Parser.cs @@ -445,7 +445,7 @@ private static StaticObject ReadObject(string FileName, Encoding Encoding) { } } if (q) { - MeshFace f = new MeshFace {Vertices = new MeshFaceVertex[Arguments.Length]}; + MeshFace f = new MeshFace(Arguments.Length); for (int j = 0; j < Arguments.Length; j++) { f.Vertices[j].Index = (ushort)a[j]; if (j < Normals.Count) @@ -1352,14 +1352,12 @@ private static StaticObject ReadObject(string FileName, Encoding Encoding) { "TextPadding is not a supported command - did you mean SetTextPadding? - at line " + (i + 1).ToString(Culture) + " in file " + FileName); } - if (Arguments.Length > 2) + Vector2 Padding; + if(!Vector2.TryParse(Arguments, out Padding)) { - currentHost.AddMessage(MessageType.Warning, false, - "At most 2 arguments are expected in " + cmd + " at line " + (i + 1).ToString(Culture) + " in file " + FileName); + currentHost.AddMessage(MessageType.Warning, false, "Invalid TextPadding at line " + (i + 1).ToString(Culture) + " in file " + FileName); } - Vector2 Padding = new Vector2(0, 0); - double.TryParse(Arguments[0], out Padding.X); - double.TryParse(Arguments[1], out Padding.Y); + for (int j = 0; j < Builder.Materials.Length; j++) { Builder.Materials[j].TextPadding = Padding; diff --git a/source/Plugins/Object.DirectX/Object.DirectX.csproj b/source/Plugins/Object.DirectX/Object.DirectX.csproj index ccd2f6a49..c9ed8f302 100644 --- a/source/Plugins/Object.DirectX/Object.DirectX.csproj +++ b/source/Plugins/Object.DirectX/Object.DirectX.csproj @@ -52,7 +52,6 @@ - diff --git a/source/Plugins/Object.DirectX/Parsers/AssimpXParser.cs b/source/Plugins/Object.DirectX/Parsers/AssimpXParser.cs index 0a56b0901..6500f9ed1 100644 --- a/source/Plugins/Object.DirectX/Parsers/AssimpXParser.cs +++ b/source/Plugins/Object.DirectX/Parsers/AssimpXParser.cs @@ -23,6 +23,7 @@ //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. using System; +using System.IO; using System.Linq; using OpenBveApi.Colors; using OpenBveApi.Objects; @@ -48,7 +49,18 @@ internal static StaticObject ReadObject(string FileName) try { #endif - XFileParser parser = new XFileParser(System.IO.File.ReadAllBytes(FileName)); + byte[] buffer = System.IO.File.ReadAllBytes(FileName); + if (buffer.Length < 16 || buffer[0] != 120 | buffer[1] != 111 | buffer[2] != 102 | buffer[3] != 32) + { + // Object is actually a single line text file containing relative path to the 'real' X + // Found in BRSigs\Night + string relativePath = System.Text.Encoding.ASCII.GetString(buffer); + if (!OpenBveApi.Path.ContainsInvalidChars(relativePath)) + { + return ReadObject(OpenBveApi.Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), relativePath)); + } + } + XFileParser parser = new XFileParser(buffer); Scene scene = parser.GetImportedData(); StaticObject obj = new StaticObject(Plugin.currentHost); @@ -175,8 +187,7 @@ private static void MeshBuilder(ref StaticObject obj, ref MeshBuilder builder, { throw new Exception("fVerts must be greater than zero"); } - MeshFace f = new MeshFace(); - f.Vertices = new MeshFaceVertex[fVerts]; + MeshFace f = new MeshFace(fVerts); for (int j = 0; j < fVerts; j++) { f.Vertices[j].Index = (ushort)mesh.PosFaces[i].Indices[j]; diff --git a/source/Plugins/Object.DirectX/Parsers/NewXParser.cs b/source/Plugins/Object.DirectX/Parsers/NewXParser.cs index 75c7aea61..0e88742d7 100644 --- a/source/Plugins/Object.DirectX/Parsers/NewXParser.cs +++ b/source/Plugins/Object.DirectX/Parsers/NewXParser.cs @@ -40,10 +40,21 @@ class NewXParser internal static StaticObject ReadObject(string FileName, Encoding Encoding) { rootMatrix = Matrix4D.NoTransformation; - currentFolder = System.IO.Path.GetDirectoryName(FileName); + currentFolder = Path.GetDirectoryName(FileName); currentFile = FileName; - byte[] Data = System.IO.File.ReadAllBytes(FileName); + byte[] Data = File.ReadAllBytes(FileName); + if (Data.Length < 16 || Data[0] != 120 | Data[1] != 111 | Data[2] != 102 | Data[3] != 32) + { + // Object is actually a single line text file containing relative path to the 'real' X + // Found in BRSigs\Night + string relativePath = Encoding.ASCII.GetString(Data); + if (!OpenBveApi.Path.ContainsInvalidChars(relativePath)) + { + return ReadObject(OpenBveApi.Path.CombineFile(Path.GetDirectoryName(FileName), relativePath), Encoding); + } + } + // floating-point format int FloatingPointSize; if (Data[12] == 48 & Data[13] == 48 & Data[14] == 51 & Data[15] == 50) @@ -161,6 +172,7 @@ private static void ParseSubBlock(Block block, ref StaticObject obj, ref MeshBui default: return; case TemplateID.Template: + // ReSharper disable once UnusedVariable string GUID = block.ReadString(); /* * Valid Microsoft templates are listed here: @@ -173,7 +185,9 @@ private static void ParseSubBlock(Block block, ref StaticObject obj, ref MeshBui */ return; case TemplateID.Header: + // ReSharper disable once UnusedVariable int majorVersion = block.ReadUInt16(); + // ReSharper disable once UnusedVariable int minorVersion = block.ReadUInt16(); int flags = block.ReadUInt16(); switch (flags) @@ -299,12 +313,13 @@ private static void ParseSubBlock(Block block, ref StaticObject obj, ref MeshBui for (int i = 0; i < nFaces; i++) { int fVerts = block.ReadUInt16(); - if (nFaces == 0) + if (fVerts == 0) { - throw new Exception("fVerts must be greater than zero"); + // Assuming here that a face must contain vertices + Plugin.currentHost.AddMessage(MessageType.Warning, false, "fVerts was declared as zero"); + break; } - MeshFace f = new MeshFace(); - f.Vertices = new MeshFaceVertex[fVerts]; + MeshFace f = new MeshFace(fVerts); for (int j = 0; j < fVerts; j++) { f.Vertices[j].Index = block.ReadUInt16(); @@ -413,7 +428,7 @@ private static void ParseSubBlock(Block block, ref StaticObject obj, ref MeshBui material.DaytimeTexture = null; } - if (!System.IO.File.Exists(material.DaytimeTexture) && material.DaytimeTexture != null) + if (!File.Exists(material.DaytimeTexture) && material.DaytimeTexture != null) { Plugin.currentHost.AddMessage(MessageType.Error, true, "Texure " + material.DaytimeTexture + " was not found in file " + currentFile); material.DaytimeTexture = null; @@ -456,7 +471,24 @@ private static void ParseSubBlock(Block block, ref StaticObject obj, ref MeshBui int nVertexColors = block.ReadUInt16(); for (int i = 0; i < nVertexColors; i++) { - builder.Vertices[i] = new ColoredVertex((Vertex)builder.Vertices[i], new Color128(255 * block.ReadSingle(), 255 * block.ReadSingle(), 255 * block.ReadSingle())); + int idx = block.ReadUInt16(); + if (idx >= builder.Vertices.Count) + { + Plugin.currentHost.AddMessage(MessageType.Warning, false, "MeshVertexColors index " + idx + " should be less than nVertices in Mesh " + block.Label); + continue; + } + ColoredVertex c = builder.Vertices[idx] as ColoredVertex; + if (c != null) + { + c.Color.R = block.ReadSingle(); + c.Color.G = block.ReadSingle(); + c.Color.B = block.ReadSingle(); + c.Color.A = block.ReadSingle(); + } + else + { + builder.Vertices[idx] = new ColoredVertex((Vertex)builder.Vertices[idx], new Color128(block.ReadSingle(), block.ReadSingle(), block.ReadSingle(), block.ReadSingle())); + } } break; case TemplateID.MeshFaceWraps: diff --git a/source/Plugins/Object.DirectX/Parsers/XObjectParser.cs b/source/Plugins/Object.DirectX/Parsers/XObjectParser.cs deleted file mode 100644 index a69af4c18..000000000 --- a/source/Plugins/Object.DirectX/Parsers/XObjectParser.cs +++ /dev/null @@ -1,2269 +0,0 @@ -using System; -using OpenBveApi.Colors; -using OpenBveApi.Math; -using OpenBveApi.Objects; -using System.Linq; -using System.Text; -using OpenBve.Formats.DirectX; -using OpenBveApi; -using OpenBveApi.Textures; -using OpenBveApi.Interface; - -namespace Plugin { - internal static class XObjectParser { - - // read object - internal static StaticObject ReadObject(string FileName, Encoding Encoding) { - byte[] Data = System.IO.File.ReadAllBytes(FileName); - // floating-point format - int FloatingPointSize; - if (Data[12] == 48 & Data[13] == 48 & Data[14] == 51 & Data[15] == 50) { - FloatingPointSize = 32; - } else if (Data[12] == 48 & Data[13] == 48 & Data[14] == 54 & Data[15] == 52) { - FloatingPointSize = 64; - } else { - throw new NotSupportedException("Invalid floating point format"); - } - // supported floating point format - if (Data[8] == 116 & Data[9] == 120 & Data[10] == 116 & Data[11] == 32) { - // textual flavor - return LoadTextualX(FileName, System.IO.File.ReadAllText(FileName, Encoding)); - } - if (Data[8] == 98 & Data[9] == 105 & Data[10] == 110 & Data[11] == 32) { - // binary flavor - return LoadBinaryX(FileName, Data, 16, FloatingPointSize); - } - if (Data[8] == 116 & Data[9] == 122 & Data[10] == 105 & Data[11] == 112) { - // compressed textual flavor - try { - byte[] Uncompressed = MSZip.Decompress(Data); - string Text = Encoding.GetString(Uncompressed); - return LoadTextualX(FileName, Text); - } catch (Exception ex) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "An unexpected error occured (" + ex.Message + ") while attempting to decompress the binary X object file encountered in " + FileName); - return null; - } - } - if (Data[8] == 98 & Data[9] == 122 & Data[10] == 105 & Data[11] == 112) { - // compressed binary flavor - - try { - byte[] Uncompressed = MSZip.Decompress(Data); - return LoadBinaryX(FileName, Uncompressed, 0, FloatingPointSize); - } catch (Exception ex) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "An unexpected error occured (" + ex.Message + ") while attempting to decompress the binary X object file encountered in " + FileName); - return null; - } - } - // unsupported flavor - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unsupported X object file encountered in " + FileName); - return null; - } - - - - // ================================ - - // template - private class Template { - internal readonly string Name; - internal string[] Members; - internal readonly string Key; - internal Template(string Name, string[] Members) { - this.Name = Name; - this.Members = Members; - } - internal Template(string Name, string[] Members, string Key) - { - this.Name = Name; - this.Members = Members; - this.Key = Key; - } - } - private static readonly Template[] Templates = new Template[] { - new Template("Mesh", new[] { "DWORD", "Vector[0]", "DWORD", "MeshFace[2]", "[...]" }), - new Template("Vector", new[] { "float", "float", "float" }), - new Template("MeshFace", new[] { "DWORD", "DWORD[0]" }), - new Template("MeshMaterialList", new[] { "DWORD", "DWORD", "DWORD[1]", "[...]" }), - new Template("Material", new[] { "ColorRGBA", "float", "ColorRGB", "ColorRGB", "[...]" }), - new Template("ColorRGBA", new[] { "float", "float", "float", "float" }), - new Template("ColorRGB", new[] { "float", "float", "float" }), - new Template("TextureFilename", new[] { "string" }), - new Template("MeshTextureCoords", new[] { "DWORD", "Coords2d[0]" }), - new Template("Coords2d", new[] { "float", "float" }), - new Template("MeshVertexColors", new[] { "DWORD","VertexColor[0]"}), - new Template("MeshNormals", new[] { "DWORD", "Vector[0]", "DWORD", "MeshFace[2]" }), - // Index , ColorRGBA - new Template("VertexColor", new[] { "DWORD", "ColorRGBA" }), - //Root frame around the model itself - new Template("Frame Root", new[] { "[...]" }), - //Presumably appears around each Mesh (??), Blender exported models - new Template("Frame", new[] { "[...]" }), - //Transforms the mesh, UNSUPPORTED - new Template("FrameTransformMatrix", new[] { "[???]" }), - }; - - // data - private class Structure { - internal readonly string Name; - internal readonly string Key; - internal object[] Data; - internal Structure(string Name, object[] Data, string Key) - { - this.Name = Name; - this.Key = Key; - this.Data = Data; - } - } - - private static bool AlternateStructure; - private static Structure[] LoadedMaterials; - - // get template - private static Template GetTemplate(string Name) { - for (int i = 0; i < Templates.Length; i++) { - if (Templates[i].Name == Name) { - return Templates[i]; - } - } - if (Name.ToLowerInvariant().StartsWith("frame ")) - { - //Enclosing frame for the model - //Appears in Blender exported stuff - return Templates[13]; - } - - if (Name.ToLowerInvariant().StartsWith("mesh ")) - { - //Named material, just ignore the name for the minute - //Appears in Blender exported stuff - return Templates[0]; - } - //Not a default template, so now figure out if it's a named texture - string[] splitName = Name.Split(new char[] { }); - if (splitName[0].ToLowerInvariant() == "material") - { - AlternateStructure = true; - return new Template("Material", new[] { "ColorRGBA", "float", "ColorRGB", "ColorRGB", "[...]" }, splitName[1]); - } - if (splitName[0].ToLowerInvariant() == "mesh") - { - return new Template("Mesh", new[] { "DWORD", "Vector[0]", "DWORD", "MeshFace[2]", "[...]" }); - } - return new Template(Name, new[] { "[???]" }); - } - - // ================================ - - // load textual x - private static StaticObject LoadTextualX(string FileName, string Text) { - // load - string[] Lines = Text.Replace("\u000D\u000A", "\u2028").Split(new[] { '\u000A', '\u000C', '\u000D', '\u0085', '\u2028', '\u2029' }, StringSplitOptions.None); - AlternateStructure = false; - LoadedMaterials = new Structure[] {}; - // strip away comments - bool Quote = false; - for (int i = 0; i < Lines.Length; i++) { - for (int j = 0; j < Lines[i].Length; j++) { - if (Lines[i][j] == '"') Quote = !Quote; - if (!Quote) { - if (Lines[i][j] == '#' || j < Lines[i].Length - 1 && Lines[i].Substring(j, 2) == "//") { - Lines[i] = Lines[i].Substring(0, j); - break; - } - } - } - //Convert runs of whitespace to single - var list = Lines[i].Split(new char[] { }).Where(s => !string.IsNullOrWhiteSpace(s)); - Lines[i] = string.Join(" ", list); - } - - //Preprocess the string array to get the variants to something we understand.... - for (int i = 0; i < Lines.Length; i++) - { - string[] splitLine = Lines[i].Split(new[] { ',' }); - if (splitLine.Length == 2 && splitLine[1].Trim(new char[] { }).Length > 0) - { - if (!splitLine[1].EndsWith(";")) - { - splitLine[1] = splitLine[1] + ";"; - } - else - { - splitLine[1] = splitLine[1] + ","; - } - Lines[i] = splitLine[0] + ';' + splitLine[1]; - } - else if (((splitLine.Length >= 4 && Lines[i].EndsWith(",")) || (splitLine.Length >= 3 && Lines[i].EndsWith(";;") && !Lines[i - 1].EndsWith(";,")) || (splitLine.Length >= 3 && Lines[i].EndsWith(";") && Lines[i - 1].Length > 5 && Lines[i - 1].EndsWith(";"))) && !splitLine[splitLine.Length - 2].EndsWith(";") && Lines[i - 1].Length > 5 && !Lines[i - 1].EndsWith("{")) - { - Lines[i - 1] = Lines[i - 1].Substring(0, Lines[i - 1].Length - 1) + ";,"; - } - - if ((Lines[i].IndexOf('}') != -1 || Lines[i].IndexOf('{') != -1) && Lines[i - 1].EndsWith(";,")) - { - Lines[i - 1] = Lines[i - 1].Substring(0, Lines[i - 1].Length - 2) + ";;"; - } - } - - // strip away header - if (Lines.Length == 0 || Lines[0].Length < 16) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "The textual X object file is invalid at line 1 in " + FileName); - return null; - } - Lines[0] = Lines[0].Substring(16); - // join lines - StringBuilder Builder = new StringBuilder(); - for (int i = 0; i < Lines.Length; i++) { - Builder.Append(Lines[i]); - } - string Content = Builder.ToString(); - - // parse file - int Position = 0; - Structure Structure; - if (!ReadTextualTemplate(FileName, Content, ref Position, new Template("", new[] { "[...]" }), false, out Structure)) { - return null; - } - // process structure - StaticObject Object; - if (!ProcessStructure(FileName, Structure, out Object)) { - return null; - } - return Object; - } - - private static bool IsDefaultTemplate(string s) - { - //X files generated by the original BVE4 convertor don't have the default templates defined, but are hardcoded instead - //On the other hand, X files which conform to the specification specify all used templates at the start of the file - //This is a simple textual check, and does not handle unexpected variations..... - switch (s.ToLowerInvariant()) - { - case "template meshface": - case "template vector": - case "template mesh": - case "template colorrgba": - case "template colorrgb": - case "template material": - case "template meshmateriallist": - case "template coords2d": - case "template meshtexturecoords": - case "template meshnormals": - case "template texturefilename": - case "template meshvertexcolors": - case "frametransformmatrix": - return true; - } - - return false; - } - - private static bool IsTemplate(string s) - { - //X files generated by the original BVE4 convertor don't have the default templates defined, but are hardcoded instead - //On the other hand, X files which conform to the specification specify all used templates at the start of the file - //This is a simple textual check, and does not handle unexpected variations..... - switch (s.ToLowerInvariant()) - { - case "meshface": - case "vector": - case "mesh": - case "colorrgba": - case "colorrgb": - case "material": - case "meshmateriallist": - case "coords2d": - case "meshtexturecoords": - case "meshnormals": - case "meshvertexcolors": - case "texturefilename": - case "frametransformmatrix": - return true; - } - - return false; - } - - // read textual template - private static bool ReadTextualTemplate(string FileName, string Content, ref int Position, Template Template, bool Inline, out Structure Structure) { - if (Template.Name == "MeshMaterialList" && AlternateStructure) - { - Template = new Template("MeshMaterialList", new[] { "DWORD", "DWORD", "DWORD[1]", "string2", "[...]" }); - } - Structure = new Structure(Template.Name, new object[] { }, Template.Key); - int i = Position; bool q = false; - int m; for (m = 0; m < Template.Members.Length; m++) { - if (Position >= Content.Length) break; - if (Template.Members[m] == "[???]") { - // unknown data accepted - while (Position < Content.Length) { - if (q) { - if (Content[Position] == '"') q = false; - } else { - if (Content[Position] == '"') { - q = true; - } else if (Content[Position] == ',' | Content[Position] == ';') { - i = Position + 1; - } else if (Content[Position] == '{') { - string s = Content.Substring(i, Position - i).Trim(new char[] { }); - Structure o; - Position++; - if (!ReadTextualTemplate(FileName, Content, ref Position, GetTemplate(s), false, out o)) { - return false; - } Position--; - i = Position + 1; - } else if (Content[Position] == '}') { - Position++; - return true; - } - } Position++; - } m--; - } else if (Template.Members[m] == "[...]") { - // any template accepted - while (Position < Content.Length) { - if (q) { - if (Content[Position] == '"') q = false; - } else { - if (Content[Position] == '"') { - q = true; - } else if (Content[Position] == '{') { - string s = Content.Substring(i, Position - i).Trim(new char[] { }); - Structure o; - Position++; - if (!ReadTextualTemplate(FileName, Content, ref Position, GetTemplate(s), false, out o)) { - return false; - } Position--; - if (!IsDefaultTemplate(s)) - { - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = o; - } - i = Position + 1; - } else if (Content[Position] == '}') { - if (Inline) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected closing brace encountered in inlined template " + Template.Name + " in textual X object file " + FileName); - return false; - } else { - Position++; - return true; - } - } else if (Content[Position] == ',') { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected comma encountered in template " + Template.Name + " in textual X object file " + FileName); - return false; - } else if (Content[Position] == ';') { - if (Inline) { - Position++; - return true; - } else { - if (Template.Name == "MeshMaterialList") - { - //A MeshMaterialList can also end with two semi-colons - Position++; - i++; - continue; - } - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected semicolon encountered in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - } - } Position++; - } m--; - } else if (Template.Members[m].EndsWith("]", StringComparison.Ordinal)) { - // inlined array expected - string r = Template.Members[m].Substring(0, Template.Members[m].Length - 1); - int h = r.IndexOf('['); - if (h >= 0) { - string z = r.Substring(h + 1, r.Length - h - 1); - r = r.Substring(0, h); - if (!int.TryParse(z, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out h)) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "The internal format description for a template array is invalid in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - if (h < 0 || h >= Structure.Data.Length || !(Structure.Data[h] is int)) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "The internal format description for a template array is invalid in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - h = (int)Structure.Data[h]; - } else { - Plugin.currentHost.AddMessage(MessageType.Error, false, "The internal format description for a template array is invalid in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - if (r == "DWORD") { - // dword array - int[] o = new int[h]; - if (h == 0) { - // empty array - while (Position < Content.Length) { - if (Content[Position] == ';') { - Position++; - break; - } - - if (Position > 0 && Content[Position -1] == ';') { - // Array not terminated with two semi-colons - break; - } - - if (!char.IsWhiteSpace(Content, Position)) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing an array in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - - Position++; - } - } else { - // non-empty array - for (int k = 0; k < h; k++) { - while (Position < Content.Length) { - if (Content[Position] == '{' | Content[Position] == '}' | Content[Position] == '"') { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing a DWORD array in template " + Template.Name + " in textual X object file " + FileName); - return false; - } else if (Content[Position] == ',') { - if (k == h - 1) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing a DWORD array in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - break; - } else if (Content[Position] == ';') { - if (k != h - 1) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing a DWORD array in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - break; - } Position++; - } if (Position == Content.Length) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "DWORD array was not terminated at the end of the file in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - string s = Content.Substring(i, Position - i); - Position++; - i = Position; - if (!int.TryParse(s, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out o[k])) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "DWORD could not be parsed in array in template " + Template.Name + " in textual X object file " + FileName); - } - } - } - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = o; - } else if (r == "float") { - // float array - double[] o = new double[h]; - if (h == 0) { - // empty array - while (Position < Content.Length) { - if (Content[Position] == ';') { - Position++; - break; - } - - if (Position > 0 && Content[Position -1] == ';') { - // Array not terminated with two semi-colons - break; - } - - if (!char.IsWhiteSpace(Content, Position)) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing an array in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - - Position++; - } - } else { - // non-empty array - for (int k = 0; k < h; k++) { - while (Position < Content.Length) { - if (Content[Position] == '{' | Content[Position] == '}' | Content[Position] == '"') { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing a float array in template " + Template.Name + " in textual X object file " + FileName); - return false; - } else if (Content[Position] == ',') { - if (k == h - 1) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing a float array in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - break; - } else if (Content[Position] == ';') { - if (k != h - 1) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing a float array in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - break; - } Position++; - } if (Position == Content.Length) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "float array was not terminated at the end of the file in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - string s = Content.Substring(i, Position - i); - Position++; - i = Position; - if (!double.TryParse(s, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out o[k])) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "float could not be parsed in array in template " + Template.Name + " in textual X object file " + FileName); - } - } - } - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = o; - } else { - // non-primitive array - Template t = GetTemplate(r); - Structure[] o = new Structure[h]; - if (h == 0) { - // empty array - while (Position < Content.Length) { - if (Content[Position] == ';') { - Position++; - break; - } - - if (Position > 0 && Content[Position - 1] == ';') { - // Array not terminated with two semi-colons - break; - } - - if (Content[Position] == '}' && Position == Content.Length -1 && Template.Members[m].StartsWith("MeshFace")) { - // A mesh has been provided, but no faces etc. - // Usually found in null objects - break; - } - - if (!char.IsWhiteSpace(Content, Position)) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing an array in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - - Position++; - } - } else { - int k; - for (k = 0; k < h; k++) { - if (!ReadTextualTemplate(FileName, Content, ref Position, t, true, out o[k])) { - return false; - } - if (k < h - 1) { - // most elements - while (Position < Content.Length) { - if (Content[Position] == ',') { - Position++; - break; - } else if (!char.IsWhiteSpace(Content, Position)) { - if ((char.IsDigit(Content[Position]) || Content[Position] == '-') && t.Name == "Coords2d") - { - /* - * Handles objects with a Coords2d structure which omit the comma from the array - * e.g. Marumado - */ - Position++; - break; - } - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing an array in template " + Template.Name + " in textual X object file " + FileName); - return false; - } else { - Position++; - } - } if (Position == Content.Length) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Array was not continued at the end of the file in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - } else { - // last element - while (Position < Content.Length) { - if (Content[Position] == ';') { - Position++; - break; - } else if (!char.IsWhiteSpace(Content, Position)) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing an array in template " + Template.Name + " in textual X object file " + FileName); - return false; - } else { - Position++; - } - } if (Position == Content.Length) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Array was not terminated at the end of the file in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - } - } if (k < h) { - return false; - } - } - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = o; - } - i = Position; - } else { - // inlined template or primitive expected - switch (Template.Members[m]) { - case "DWORD": - while (Position < Content.Length) { - if (Content[Position] == '{' | Content[Position] == '}' | Content[Position] == ',' | Content[Position] == '"') { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing a DWORD in template " + Template.Name + " in textual X object file " + FileName); - return false; - } else if (Content[Position] == ';') { - string s = Content.Substring(i, Position - i).Trim(new char[] { }); - int a; if (!int.TryParse(s, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out a)) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "DWORD could not be parsed in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = a; - Position++; - i = Position; - break; - } Position++; - } break; - case "float": - while (Position < Content.Length) { - if (Content[Position] == '{' | Content[Position] == '}' | Content[Position] == '"') { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing a DWORD in template " + Template.Name + " in textual X object file " + FileName); - return false; - } else if (Content[Position] == ';' || Content[Position] == ',') { - string s = Content.Substring(i, Position - i).Trim(new char[] { }); - double a; if (!double.TryParse(s, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out a)) { - if (s != string.Empty) - { - //Handle omitted entries which are still in a valid format - //May break elsewhere, but if so we're no further back anyways - Plugin.currentHost.AddMessage(MessageType.Error, false, "float could not be parsed in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - else - { - a = 0.0; - } - } - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = a; - Position++; - i = Position; - break; - } Position++; - } break; - case "string": - while (Position < Content.Length) { - if (Content[Position] == '"') { - Position++; - break; - } else if (!char.IsWhiteSpace(Content, Position)) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing a string in template " + Template.Name + " in textual X object file " + FileName); - return false; - } else { - Position++; - } - } if (Position >= Content.Length) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected end of file encountered while processing a string in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - i = Position; - while (Position < Content.Length) { - if (Content[Position] == '"') { - Position++; - break; - } else { - Position++; - } - } if (Position >= Content.Length) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected end of file encountered while processing a string in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - string t = Content.Substring(i, Position - i - 1); - while (Position < Content.Length) { - if (Content[Position] == ';') { - Position++; - break; - } else if (!char.IsWhiteSpace(Content, Position)) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing a string in template " + Template.Name + " in textual X object file " + FileName); - return false; - } else { - Position++; - } - } if (Position >= Content.Length) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected end of file encountered while processing a string in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = t; - i = Position; - break; - case "string2": - int OldPosition = Position; - if (Position < Content.Length - 1) - { - Position++; - } - bool SF = false; - while (char.IsWhiteSpace(Content[Position]) || Content[Position] == '{' && Position < Content.Length) - { - Position++; - } - i = Position; - if (Position >= Content.Length) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected end of file encountered while processing a string in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - while (Position < Content.Length) - { - if (Content[Position] == ';') - { - SF = true; - break; - } - if (Content[Position] == '}') - { - SF = true; - break; - } - if (Content[Position] == ',') - { - break; - } - Position++; - } - if (Position >= Content.Length) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected end of file encountered while processing a string in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - if (SF) - { - - - t = Content.Substring(i, Position - i).Trim(new char[] { }); - if (IsTemplate(t.Split(new char[] { })[0]) || t.Length == 0) - { - //HACK: Check if the found string starts with a template name to determine whether we should discard it - SF = false; - Position = OldPosition; - } - else - { - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = t; - } - } - else - { - //String wasn't found - Position = OldPosition; - } - if (Position >= Content.Length) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected end of file encountered while processing a string in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - - /* - * There could potentially be any number of strings, so add another to the array - */ - if (SF) - { - Array.Resize(ref Template.Members, Template.Members.Length + 1); - for (int a = m; a < Template.Members.Length - 1; a++) - { - Template.Members[a + 1] = Template.Members[a]; - } - Template.Members[m] = "string2"; - } - break; - default: - { - Structure o; - if (!ReadTextualTemplate(FileName, Content, ref Position, GetTemplate(Template.Members[m]), true, out o)) { - return false; - } - while (Position < Content.Length) { - if (Content[Position] == ';') { - Position++; - break; - } else if (!char.IsWhiteSpace(Content, Position)) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered while processing an inlined template in template " + Template.Name + " in textual X object file " + FileName); - return false; - } else { - Position++; - } - } if (Position >= Content.Length) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected end of file encountered while processing an inlined template in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = o; - i = Position; - } break; - } - } - } - if (m >= Template.Members.Length) { - if (Inline) { - return true; - } else { - // closed non-inline template - while (Position < Content.Length) - { - if (Content[Position] == ';') - { - Position++; - } - else if (Content[Position] == '}') - { - Position++; - break; - } - else if (!char.IsWhiteSpace(Content, Position)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Invalid character encountered in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - else - { - Position++; - } - } if (Position >= Content.Length) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected end of file encountered in template " + Template.Name + " in textual X object file " + FileName); - return false; - } - return true; - } - } else { - if (q) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Quotation mark not closed at the end of the file in template " + Template.Name + " in textual X object file " + FileName); - return false; - } else if (Template.Name.Length != 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected end of file encountered in template " + Template.Name + " in textual X object file " + FileName); - return false; - } else { - return true; - } - } - } - - // ================================ - - // load binary x - private static StaticObject LoadBinaryX(string FileName, byte[] Data, int StartingPosition, int FloatingPointSize) { - // parse file - AlternateStructure = false; - LoadedMaterials = new Structure[] {}; - Structure Structure; - try { - bool Result; - using (System.IO.MemoryStream Stream = new System.IO.MemoryStream(Data)) { - using (System.IO.BinaryReader Reader = new System.IO.BinaryReader(Stream)) { - Stream.Position = StartingPosition; - BinaryCache Cache = new BinaryCache(); - Cache.IntegersRemaining = 0; - Cache.FloatsRemaining = 0; - Result = ReadBinaryTemplate(FileName, Reader, FloatingPointSize, new Template("", new[] { "[...]" }), false, ref Cache, out Structure); - Reader.Close(); - } - Stream.Close(); - } if (!Result) { - return null; - } - } catch (Exception ex) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unhandled error (" + ex.Message + ") encountered in binary X object file " + FileName); - return null; - } - // process structure - StaticObject Object; - if (!ProcessStructure(FileName, Structure, out Object)) { - return null; - } return Object; - } - - // read binary template - private struct BinaryCache { - internal int[] Integers; - internal int IntegersRemaining; - internal double[] Floats; - internal int FloatsRemaining; - } - private static bool ReadBinaryTemplate(string FileName, System.IO.BinaryReader Reader, int FloatingPointSize, Template Template, bool Inline, ref BinaryCache Cache, out Structure Structure) { - Structure = new Structure(Template.Name, new object[] { }, Template.Key); - System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; - ASCIIEncoding Ascii = new ASCIIEncoding(); - int m; for (m = 0; m < Template.Members.Length; m++) { - if (Template.Members[m] == "[???]") { - // unknown template - int Level = 0; - if (Cache.IntegersRemaining != 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "An integer list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - } else if (Cache.FloatsRemaining != 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "A float list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - } - TokenID Token = (TokenID)Reader.ReadInt16(); - switch (Token) { - case TokenID.NAME: - { - Level++; - int n = Reader.ReadInt32(); - if (n < 1) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "count is invalid in TOKEN_NAME at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - Reader.BaseStream.Position += n; - Token = (TokenID)Reader.ReadInt16(); - if (Token != TokenID.OBRACE) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "TOKEN_OBRACE expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - } break; - case TokenID.INT: - { - Reader.BaseStream.Position += 4; - } break; - case TokenID.INT_LIST: - { - int n = Reader.ReadInt32(); - if (n < 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "count is invalid in TOKEN_INTEGER_LIST at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - Reader.BaseStream.Position += 4 * n; - } break; - case TokenID.FLOAT_LIST: - { - int n = Reader.ReadInt32(); - if (n < 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "count is invalid in TOKEN_FLOAT_LIST at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - Reader.BaseStream.Position += (FloatingPointSize >> 3) * n; - } break; - case TokenID.STRING: - { - int n = Reader.ReadInt32(); - if (n < 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "count is invalid in TOKEN_STRING at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - Reader.BaseStream.Position += n; - Token = (TokenID)Reader.ReadInt16(); - if (Token != TokenID.COMMA & Token != TokenID.SEMICOLON) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "TOKEN_COMMA or TOKEN_SEMICOLON expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - } break; - case TokenID.OBRACE: - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected token TOKEN_OBRACE encountered at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - case TokenID.CBRACE: - if (Level == 0) return true; - Level--; - break; - default: - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unknown token encountered at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } m--; - } else if (Template.Members[m] == "[...]") { - // any template - if (Cache.IntegersRemaining != 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "An integer list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - } else if (Cache.FloatsRemaining != 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "A float list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - } - if (Template.Name.Length == 0 && Reader.BaseStream.Position == Reader.BaseStream.Length) { - // end of file - return true; - } - TokenID Token = (TokenID)Reader.ReadInt16(); - switch (Token) { - case TokenID.NAME: - int n = Reader.ReadInt32(); - if (n < 1) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "count is invalid in TOKEN_NAME at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - string Name = new string(Ascii.GetChars(Reader.ReadBytes(n))); - Token = (TokenID)Reader.ReadInt16(); - if (Token != TokenID.OBRACE) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "TOKEN_OBRACE expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - Structure o; - if (!ReadBinaryTemplate(FileName, Reader, FloatingPointSize, GetTemplate(Name), false, ref Cache, out o)) { - return false; - } - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = o; - break; - case TokenID.CBRACE: - if (Template.Name.Length == 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected TOKEN_CBRACE encountered at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - m++; - break; - default: - Plugin.currentHost.AddMessage(MessageType.Error, false, "TOKEN_NAME or TOKEN_CBRACE expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } m--; - } else if (Template.Members[m].EndsWith("]", StringComparison.Ordinal)) { - // inlined array expected - string r = Template.Members[m].Substring(0, Template.Members[m].Length - 1); - int h = r.IndexOf('['); - if (h >= 0) { - string z = r.Substring(h + 1, r.Length - h - 1); - r = r.Substring(0, h); - if (!int.TryParse(z, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out h)) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "The internal format description for a template array is invalid in template " + Template.Name + " in binary X object file " + FileName); - return false; - } - if (h < 0 || h >= Structure.Data.Length || !(Structure.Data[h] is int)) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "The internal format description for a template array is invalid in template " + Template.Name + " in binary X object file " + FileName); - return false; - } - h = (int)Structure.Data[h]; - } else { - Plugin.currentHost.AddMessage(MessageType.Error, false, "The internal format description for a template array is invalid in template " + Template.Name + " in binary X object file " + FileName); - return false; - } - if (r == "DWORD") { - // dword array - int[] o = new int[h]; - for (int i = 0; i < h; i++) { - if (Cache.IntegersRemaining != 0) { - // use cached integer - int a = Cache.Integers[Cache.IntegersRemaining - 1]; - Cache.IntegersRemaining--; - o[i] = a; - } else if (Cache.FloatsRemaining != 0) { - // cannot use cached float - Plugin.currentHost.AddMessage(MessageType.Error, false, "A float list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } else { - while (true) { - TokenID Token = (TokenID)Reader.ReadInt16(); - if (Token == TokenID.INT) { - int a = Reader.ReadInt32(); - o[i] = a; break; - } else if (Token == TokenID.INT_LIST) { - int n = Reader.ReadInt32(); - if (n < 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "count is invalid in TOKEN_INTEGER_LIST at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - if (n != 0) { - Cache.Integers = new int[n]; - for (int j = 0; j < n; j++) { - Cache.Integers[n - j - 1] = Reader.ReadInt32(); - } - Cache.IntegersRemaining = n - 1; - int a = Cache.Integers[Cache.IntegersRemaining]; - o[i] = a; - break; - } - } else { - Plugin.currentHost.AddMessage(MessageType.Error, false, "TOKEN_INTEGER or TOKEN_INTEGER_LIST expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - } - } - } - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = o; - } else if (r == "float") { - // float array - double[] o = new double[h]; - for (int i = 0; i < h; i++) { - if (Cache.IntegersRemaining != 0) { - // cannot use cached integer - Plugin.currentHost.AddMessage(MessageType.Error, false, "An integer list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } else if (Cache.FloatsRemaining != 0) { - // use cached float - double a = Cache.Floats[Cache.FloatsRemaining - 1]; - Cache.FloatsRemaining--; - o[i] = a; - } else { - while (true) { - TokenID Token = (TokenID)Reader.ReadInt16(); - if (Token == TokenID.FLOAT_LIST) { - int n = Reader.ReadInt32(); - if (n < 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "count is invalid in TOKEN_FLOAT_LIST at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - if (n != 0) { - Cache.Floats = new double[n]; - for (int j = 0; j < n; j++) { - if (FloatingPointSize == 32) { - Cache.Floats[n - j - 1] = Reader.ReadSingle(); - } else if (FloatingPointSize == 64) { - Cache.Floats[n - j - 1] = Reader.ReadDouble(); - } - } - Cache.FloatsRemaining = n - 1; - double a = Cache.Floats[Cache.FloatsRemaining]; - o[i] = a; - break; - } - } else { - Plugin.currentHost.AddMessage(MessageType.Error, false, "TOKEN_FLOAT_LIST expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - } - } - } - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = o; - } else { - // template array - Structure[] o = new Structure[h]; - for (int i = 0; i < h; i++) { - ReadBinaryTemplate(FileName, Reader, FloatingPointSize, GetTemplate(r), true, ref Cache, out o[i]); - } - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = o; - } - } else { - // inlined template or primitive expected - switch (Template.Members[m]) { - case "DWORD": - // dword expected - if (Cache.IntegersRemaining != 0) { - // use cached integer - int a = Cache.Integers[Cache.IntegersRemaining - 1]; - Cache.IntegersRemaining--; - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = a; - } else if (Cache.FloatsRemaining != 0) { - // cannot use cached float - Plugin.currentHost.AddMessage(MessageType.Error, false, "A float list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } else { - // read new data - while (true) { - TokenID Token = (TokenID)Reader.ReadInt16(); - if (Token == TokenID.INT) { - int a = Reader.ReadInt32(); - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = a; - break; - } else if (Token == TokenID.INT_LIST) { - int n = Reader.ReadInt32(); - if (n < 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "count is invalid in TOKEN_INTEGER_LIST at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - if (n != 0) { - Cache.Integers = new int[n]; - for (int i = 0; i < n; i++) { - Cache.Integers[n - i - 1] = Reader.ReadInt32(); - } - Cache.IntegersRemaining = n - 1; - int a = Cache.Integers[Cache.IntegersRemaining]; - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = a; - break; - } - } else { - Plugin.currentHost.AddMessage(MessageType.Error, false, "TOKEN_INTEGER or TOKEN_INTEGER_LIST expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - } - } break; - case "float": - // float expected - if (Cache.IntegersRemaining != 0) { - // cannot use cached integer - Plugin.currentHost.AddMessage(MessageType.Error, false, "An integer list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } else if (Cache.FloatsRemaining != 0) { - // use cached float - double a = Cache.Floats[Cache.FloatsRemaining - 1]; - Cache.FloatsRemaining--; - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = a; - } else { - // read new data - while (true) { - TokenID Token = (TokenID)Reader.ReadInt16(); - if (Token == TokenID.FLOAT_LIST) { - int n = Reader.ReadInt32(); - if (n < 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "count is invalid in TOKEN_FLOAT_LIST at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - if (n != 0) { - Cache.Floats = new double[n]; - for (int i = 0; i < n; i++) { - if (FloatingPointSize == 32) { - Cache.Floats[n - i - 1] = Reader.ReadSingle(); - } else if (FloatingPointSize == 64) { - Cache.Floats[n - i - 1] = Reader.ReadDouble(); - } - } - Cache.FloatsRemaining = n - 1; - double a = Cache.Floats[Cache.FloatsRemaining]; - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = a; - break; - } - } else { - Plugin.currentHost.AddMessage(MessageType.Error, false, "TOKEN_FLOAT_LIST expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - } - } break; - case "string": - { - // string expected - if (Cache.IntegersRemaining != 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "An integer list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - } else if (Cache.FloatsRemaining != 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "A float list was not depleted at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - } - TokenID Token = (TokenID)Reader.ReadInt16(); - if (Token == TokenID.STRING) { - int n = Reader.ReadInt32(); - if (n < 0) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "count is invalid in TOKEN_STRING at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - string s = new string(Ascii.GetChars(Reader.ReadBytes(n))); - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = s; - Token = (TokenID)Reader.ReadInt16(); - if (Token != TokenID.SEMICOLON) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "TOKEN_SEMICOLON expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - } else { - Plugin.currentHost.AddMessage(MessageType.Error, false, "TOKEN_STRING expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - } break; - default: - // inlined template expected - Structure o; - ReadBinaryTemplate(FileName, Reader, FloatingPointSize, GetTemplate(Template.Members[m]), true, ref Cache, out o); - Array.Resize(ref Structure.Data, Structure.Data.Length + 1); - Structure.Data[Structure.Data.Length - 1] = o; - break; - } - } - } - if (Inline) { - return true; - } else { - string s = Template.Members[Template.Members.Length - 1]; - if (s != "[???]" & s != "[...]") { - TokenID Token = (TokenID)Reader.ReadInt16(); - if (Token != TokenID.CBRACE) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "TOKEN_CBRACE expected at position 0x" + Reader.BaseStream.Position.ToString("X", Culture) + " in binary X object file " + FileName); - return false; - } - } - return true; - } - } - - // ================================ - - // structures - private struct Material { - internal Color32 faceColor; - internal Color24 specularColor; - internal Color24 emissiveColor; - internal string TextureFilename; - } - - // process structure - private static bool ProcessStructure(string FileName, Structure Structure, out StaticObject Object) { - System.Globalization.CultureInfo Culture = System.Globalization.CultureInfo.InvariantCulture; - Object = new StaticObject(Plugin.currentHost); - // file - for (int i = 0; i < Structure.Data.Length; i++) { - Structure f = Structure.Data[i] as Structure; - if (f == null) { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Top-level inlined arguments are invalid in x object file " + FileName); - return false; - } - switch (f.Name) { - case "Frame Root": - case "Frame": - //This is just a placeholder around the other templates - ProcessStructure(FileName, f, out Object); - break; - case "Mesh": - { - // mesh - if (f.Data.Length < 4) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Mesh is expected to have at least 4 arguments in x object file " + FileName); - return false; - } - else if (!(f.Data[0] is int)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nVertices is expected to be a DWORD in Mesh in x object file " + FileName); - return false; - } - else if (!(f.Data[1] is Structure[])) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "vertices[nVertices] is expected to be a Vector array in Mesh in x object file " + FileName); - return false; - } - else if (!(f.Data[2] is int)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaces is expected to be a DWORD in Mesh in x object file " + FileName); - return false; - } - else if (!(f.Data[3] is Structure[])) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faces[nFaces] is expected to be a MeshFace array in Mesh in x object file " + FileName); - return false; - } - int nVertices = (int)f.Data[0]; - if (nVertices < 0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nVertices is expected to be non-negative in Mesh in x object file " + FileName); - return false; - } - Structure[] vertices = (Structure[])f.Data[1]; - if (nVertices != vertices.Length) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nVertices does not match with the length of array vertices in Mesh in x object file " + FileName); - return false; - } - int nFaces = (int)f.Data[2]; - if (nFaces < 0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaces is expected to be non-negative in Mesh in x object file " + FileName); - return false; - } - Structure[] faces = (Structure[])f.Data[3]; - if (nFaces != faces.Length) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaces does not match with the length of array faces in Mesh in x object file " + FileName); - return false; - } - // collect vertices - VertexTemplate[] Vertices = new VertexTemplate[nVertices]; - for (int j = 0; j < nVertices; j++) - { - if (vertices[j].Name != "Vector") - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "vertices[" + j.ToString(Culture) + "] is expected to be of template Vertex in Mesh in x object file " + FileName); - return false; - } - else if (vertices[j].Data.Length != 3) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "vertices[" + j.ToString(Culture) + "] is expected to have 3 arguments in Mesh in x object file " + FileName); - return false; - } - else if (!(vertices[j].Data[0] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "x is expected to be a float in vertices[" + j.ToString(Culture) + "] in Mesh in x object file " + FileName); - return false; - } - else if (!(vertices[j].Data[1] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "y is expected to be a float in vertices[" + j.ToString(Culture) + "] in Mesh in x object file " + FileName); - return false; - } - else if (!(vertices[j].Data[2] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "z is expected to be a float in vertices[" + j.ToString(Culture) + "] in Mesh in x object file " + FileName); - return false; - } - double x = (double)vertices[j].Data[0]; - double y = (double)vertices[j].Data[1]; - double z = (double)vertices[j].Data[2]; - Vertices[j] = new Vertex(new Vector3(x,y,z)); - } - // collect faces - int[][] Faces = new int[nFaces][]; - Vector3[][] FaceNormals = new Vector3[nFaces][]; - int[] FaceMaterials = new int[nFaces]; - for (int j = 0; j < nFaces; j++) - { - FaceMaterials[j] = -1; - } - for (int j = 0; j < nFaces; j++) - { - if (faces[j].Name != "MeshFace") - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faces[" + j.ToString(Culture) + "] is expected to be of template MeshFace in Mesh in x object file " + FileName); - return false; - } - else if (faces[j].Data.Length != 2) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "face[" + j.ToString(Culture) + "] is expected to have 2 arguments in Mesh in x object file " + FileName); - return false; - } - else if (!(faces[j].Data[0] is int)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaceVertexIndices is expected to be a DWORD in face[" + j.ToString(Culture) + "] in Mesh in x object file " + FileName); - return false; - } - else if (!(faces[j].Data[1] is int[])) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faceVertexIndices[nFaceVertexIndices] is expected to be a DWORD array in face[" + j.ToString(Culture) + "] in Mesh in x object file " + FileName); - return false; - } - int nFaceVertexIndices = (int)faces[j].Data[0]; - if (nFaceVertexIndices < 0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaceVertexIndices is expected to be non-negative in MeshFace in Mesh in x object file " + FileName); - return false; - } - int[] faceVertexIndices = (int[])faces[j].Data[1]; - if (nFaceVertexIndices != faceVertexIndices.Length) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaceVertexIndices does not match with the length of array faceVertexIndices in face[" + j.ToString(Culture) + "] in Mesh in x object file " + FileName); - return false; - } - Faces[j] = new int[nFaceVertexIndices]; - FaceNormals[j] = new Vector3[nFaceVertexIndices]; - for (int k = 0; k < nFaceVertexIndices; k++) - { - if (faceVertexIndices[k] < 0 | faceVertexIndices[k] >= nVertices) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faceVertexIndices[" + k.ToString(Culture) + "] does not reference a valid vertex in face[" + j.ToString(Culture) + "] in Mesh in x object file " + FileName); - return false; - } - Faces[j][k] = faceVertexIndices[k]; - FaceNormals[j][k] = new Vector3(0.0f, 0.0f, 0.0f); - } - } - int ds = 4; - if (AlternateStructure) - { - ds = f.Data.Length - 1; - //If this file has the alternate structure, find the templates (if existing) after the mesh declaration - bool cf = false, cn = false; - for (int g = i + 1; g < Structure.Data.Length; g++) - { - int dl = f.Data.Length; - Structure h = Structure.Data[g] as Structure; - if (h == null) - { - continue; - } - if (cf && cn) - { - //A set of texture co-ords and normal co-ords has been found, so break the loop - break; - } - switch (h.Name) - { - case "MeshTextureCoords": - if (!cf) - { - cf = true; - //Insert into the structure array - Array.Resize(ref f.Data, dl + 1); - f.Data[dl] = h; - //Remove from the main array - for (int k = g + 1; k < Structure.Data.Length; k++) - { - Structure.Data[k - 1] = Structure.Data[k]; - } - Array.Resize(ref Structure.Data, Structure.Data.Length - 1); - g--; - } - break; - case "MeshNormals": - if (!cn) - { - cn = true; - //Insert into the structure array - Array.Resize(ref f.Data, dl + 1); - f.Data[dl] = h; - //Remove from the main array - for (int k = g + 1; k < Structure.Data.Length; k++) - { - Structure.Data[k - 1] = Structure.Data[k]; - } - Array.Resize(ref Structure.Data, Structure.Data.Length - 1); - g--; - } - break; - case "Mesh": - //If we've found a mesh, assume that the normals and co-ords have been declared or omitted for the previous mesh - cf = true; - cn = true; - break; - case "MeshVertexColors": - break; - default: - continue; - } - - } - } - // collect additional templates - Material[] Materials = new Material[] { }; - for (int j = ds; j < f.Data.Length; j++) - { - Structure g = f.Data[j] as Structure; - if (g == null) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected inlined argument encountered in Mesh in x object file " + FileName); - return false; - } - switch (g.Name) - { - case "MeshMaterialList": - { - // meshmateriallist - if (g.Data.Length < 3) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "MeshMaterialList is expected to have at least 3 arguments in Mesh in x object file " + FileName); - return false; - } - else if (!(g.Data[0] is int)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nMaterials is expected to be a DWORD in MeshMaterialList in Mesh in x object file " + FileName); - return false; - } - else if (!(g.Data[1] is int)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaceIndexes is expected to be a DWORD in MeshMaterialList in Mesh in x object file " + FileName); - return false; - } - else if (!(g.Data[2] is int[])) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faceIndexes[nFaceIndexes] is expected to be a DWORD array in MeshMaterialList in Mesh in x object file " + FileName); - return false; - } - int nMaterials = (int)g.Data[0]; - if (nMaterials < 0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nMaterials is expected to be non-negative in MeshMaterialList in Mesh in x object file " + FileName); - return false; - } - int nFaceIndexes = (int)g.Data[1]; - if (nFaceIndexes < 0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaceIndexes is expected to be non-negative in MeshMaterialList in Mesh in x object file " + FileName); - return false; - } - else if (nFaceIndexes > nFaces) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaceIndexes does not reference valid faces in MeshMaterialList in Mesh in x object file " + FileName); - return false; - } - int[] faceIndexes = (int[])g.Data[2]; - if (nFaceIndexes != faceIndexes.Length) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaceIndexes does not match with the length of array faceIndexes in face[" + j.ToString(Culture) + "] in Mesh in x object file " + FileName); - return false; - } - for (int k = 0; k < nFaceIndexes; k++) - { - if (faceIndexes[k] < 0 | faceIndexes[k] >= nMaterials) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faceIndexes[" + k.ToString(Culture) + "] does not reference a valid Material template in MeshMaterialList in Mesh in x object file " + FileName); - return false; - } - } - if (g.Data.Length >= 4 && g.Data[3] is String) - { - for (int m = 3; m < g.Data.Length; m++) - { - for (int n = 0; n < LoadedMaterials.Length; n++) - { - if ((string)g.Data[m] == LoadedMaterials[n].Key) - { - g.Data[m] = LoadedMaterials[n]; - break; - } - } - } - } - - { - // collect material templates - int mn = Materials.Length; - Array.Resize(ref Materials, mn + nMaterials); - for (int k = 0; k < nMaterials; k++) - { - Materials[mn + k].faceColor = Color32.White; - Materials[mn + k].specularColor = Color24.Black; - Materials[mn + k].emissiveColor = Color24.Black; - Materials[mn + k].TextureFilename = null; - } - int MaterialIndex = mn; - for (int k = 3; k < g.Data.Length; k++) - { - Structure h = g.Data[k] as Structure; - if (h == null) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected inlined argument encountered in MeshMaterialList in Mesh in x object file " + FileName); - return false; - } - else if (h.Name != "Material") - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Material template expected in MeshMaterialList in Mesh in x object file " + FileName); - return false; - } - else - { - // material - if (h.Data.Length < 4) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Material is expected to have at least 4 arguments in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(h.Data[0] is Structure)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faceColor is expected to be a ColorRGBA in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(h.Data[1] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "power is expected to be a float in Material in MeshMaterialList in Mesh in x object file " + FileName); - return false; - } - else if (!(h.Data[2] is Structure)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "specularColor is expected to be a ColorRGBA in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(h.Data[3] is Structure)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "emissiveColor is expected to be a ColorRGBA in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - Structure faceColor = (Structure)h.Data[0]; - Structure specularColor = (Structure)h.Data[2]; - Structure emissiveColor = (Structure)h.Data[3]; - double red, green, blue, alpha; - // collect face color - if (faceColor.Name != "ColorRGBA") - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faceColor is expected to be a ColorRGBA in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (faceColor.Data.Length != 4) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faceColor is expected to have 4 arguments in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(faceColor.Data[0] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "red is expected to be a float in faceColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(faceColor.Data[1] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "green is expected to be a float in faceColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(faceColor.Data[2] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "blue is expected to be a float in faceColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(faceColor.Data[3] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "alpha is expected to be a float in faceColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - red = (double)faceColor.Data[0]; - green = (double)faceColor.Data[1]; - blue = (double)faceColor.Data[2]; - alpha = (double)faceColor.Data[3]; - if (red < 0.0 | red > 1.0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "red is expected to be in the range from 0.0 to 1.0 in faceColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - red = red < 0.5 ? 0.0 : 1.0; - } - if (green < 0.0 | green > 1.0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "green is expected to be in the range from 0.0 to 1.0 in faceColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - green = green < 0.5 ? 0.0 : 1.0; - } - if (blue < 0.0 | blue > 1.0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "blue is expected to be in the range from 0.0 to 1.0 in faceColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - blue = blue < 0.5 ? 0.0 : 1.0; - } - if (alpha < 0.0 | alpha > 1.0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "alpha is expected to be in the range from 0.0 to 1.0 in faceColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - alpha = alpha < 0.5 ? 0.0 : 1.0; - } - Materials[MaterialIndex].faceColor = new Color32((byte)Math.Round(255.0 * red), - (byte)Math.Round(255.0 * green), (byte)Math.Round(255.0 * blue), (byte)Math.Round(255.0 * alpha)); - // collect specular color - if (specularColor.Name != "ColorRGB") - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "specularColor is expected to be a ColorRGB in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (specularColor.Data.Length != 3) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "specularColor is expected to have 3 arguments in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(specularColor.Data[0] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "red is expected to be a float in specularColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(specularColor.Data[1] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "green is expected to be a float in specularColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(specularColor.Data[2] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "blue is expected to be a float in specularColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - red = (double)specularColor.Data[0]; - green = (double)specularColor.Data[1]; - blue = (double)specularColor.Data[2]; - if (red < 0.0 | red > 1.0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "red is expected to be in the range from 0.0 to 1.0 in specularColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - red = red < 0.5 ? 0.0 : 1.0; - } - if (green < 0.0 | green > 1.0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "green is expected to be in the range from 0.0 to 1.0 in specularColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - green = green < 0.5 ? 0.0 : 1.0; - } - if (blue < 0.0 | blue > 1.0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "blue is expected to be in the range from 0.0 to 1.0 in specularColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - blue = blue < 0.5 ? 0.0 : 1.0; - } - Materials[MaterialIndex].specularColor = new Color24((byte)Math.Round(255.0 * red), - (byte)Math.Round(255.0 * green), (byte)Math.Round(255.0 * blue)); - // collect emissive color - if (emissiveColor.Name != "ColorRGB") - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "emissiveColor is expected to be a ColorRGBA in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (emissiveColor.Data.Length != 3) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "emissiveColor is expected to have 3 arguments in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(emissiveColor.Data[0] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "red is expected to be a float in emissiveColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(emissiveColor.Data[1] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "green is expected to be a float in emissiveColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(emissiveColor.Data[2] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "blue is expected to be a float in emissiveColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - red = (double)emissiveColor.Data[0]; - green = (double)emissiveColor.Data[1]; - blue = (double)emissiveColor.Data[2]; - if (red < 0.0 | red > 1.0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "red is expected to be in the range from 0.0 to 1.0 in emissiveColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - red = red < 0.5 ? 0.0 : 1.0; - } - if (green < 0.0 | green > 1.0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "green is expected to be in the range from 0.0 to 1.0 in emissiveColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - green = green < 0.5 ? 0.0 : 1.0; - } - if (blue < 0.0 | blue > 1.0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "blue is expected to be in the range from 0.0 to 1.0 in emissiveColor in Material in MeshMaterialList in Mesh in x object file " + - FileName); - blue = blue < 0.5 ? 0.0 : 1.0; - } - Materials[MaterialIndex].emissiveColor = new Color24((byte)Math.Round(255.0 * red), - (byte)Math.Round(255.0 * green), (byte)Math.Round(255.0 * blue)); - // collect additional templates - for (int l = 4; l < h.Data.Length; l++) - { - Structure e = h.Data[l] as Structure; - if (e == null) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "Unexpected inlined argument encountered in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - switch (e.Name) - { - case "TextureFilename": - { - // texturefilename - if (e.Data.Length != 1) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "filename is expected to have 1 argument in TextureFilename in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - else if (!(e.Data[0] is string)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "filename is expected to be a string in TextureFilename in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - string textureFileName = (string)e.Data[0]; - if (Path.ContainsInvalidChars(textureFileName)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "filename contains illegal characters in TextureFilename in Material in MeshMaterialList in Mesh in x object file " + - FileName); - } - else - { - string File = string.Empty; - if (Path.IsAbsolutePath(textureFileName)) - { - if (Plugin.EnabledHacks.BveTsHacks) - { - textureFileName = textureFileName.Split('/', '\\').Last(); - File = Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), textureFileName); - } - else - { - File = textureFileName; - } - } - else - { - if (!string.IsNullOrEmpty(textureFileName)) - { - File = Path.CombineFile(System.IO.Path.GetDirectoryName(FileName), textureFileName); - } - } - if (System.IO.File.Exists(File)) - { - Materials[MaterialIndex].TextureFilename = File; - } - else - { - if (!string.IsNullOrEmpty(textureFileName)) - { - Plugin.currentHost.AddMessage(MessageType.Error, true, "The texture file " + File + " could not be found in TextureFilename in Material in MeshMaterialList in Mesh in x object file " + - FileName); - } - else - { - Plugin.currentHost.AddMessage(MessageType.Information, false, $"An empty texture was specified in Material in MeshMaterialList in Mesh in x object file " + FileName); - } - } - } - } - break; - default: - // unknown - Plugin.currentHost.AddMessage(MessageType.Warning, false, "Unsupported template " + e.Name + " encountered in MeshMaterialList in Mesh in x object file " + - FileName); - break; - } - } - // finish - MaterialIndex++; - } - } - if (MaterialIndex != mn + nMaterials) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nMaterials does not match the number of Material templates encountered in Material in MeshMaterialList in Mesh in x object file " + - FileName); - return false; - } - } - // assign materials - for (int k = 0; k < nFaceIndexes; k++) - { - FaceMaterials[k] = faceIndexes[k]; - } - if (nMaterials != 0) - { - for (int k = 0; k < nFaces; k++) - { - if (FaceMaterials[k] == -1) - { - FaceMaterials[k] = 0; - } - } - } - } - break; - case "MeshTextureCoords": - { - // meshtexturecoords - if (g.Data.Length != 2) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "MeshTextureCoords is expected to have 2 arguments in Mesh in x object file " + FileName); - return false; - } - else if (!(g.Data[0] is int)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nTextureCoords is expected to be a DWORD in MeshTextureCoords in Mesh in x object file " + FileName); - return false; - } - else if (!(g.Data[1] is Structure[])) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "textureCoords[nTextureCoords] is expected to be a Coords2d array in MeshTextureCoords in Mesh in x object file " + FileName); - return false; - } - int nTextureCoords = (int)g.Data[0]; - Structure[] textureCoords = (Structure[])g.Data[1]; - if (nTextureCoords < 0 | nTextureCoords > nVertices) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nTextureCoords does not reference valid vertices in MeshTextureCoords in Mesh in x object file " + FileName); - return false; - } - for (int k = 0; k < nTextureCoords; k++) - { - if (textureCoords[k].Name != "Coords2d") - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "textureCoords[" + k.ToString(Culture) + "] is expected to be a Coords2d in MeshTextureCoords in Mesh in x object file " + FileName); - return false; - } - else if (textureCoords[k].Data.Length != 2) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "textureCoords[" + k.ToString(Culture) + "] is expected to have 2 arguments in MeshTextureCoords in Mesh in x object file " + FileName); - return false; - } - else if (!(textureCoords[k].Data[0] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "u is expected to be a float in textureCoords[" + k.ToString(Culture) + "] in MeshTextureCoords in Mesh in x object file " + FileName); - return false; - } - else if (!(textureCoords[k].Data[1] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "v is expected to be a float in textureCoords[" + k.ToString(Culture) + "] in MeshTextureCoords in Mesh in x object file " + FileName); - return false; - } - double u = (double)textureCoords[k].Data[0]; - double v = (double)textureCoords[k].Data[1]; - Vertices[k].TextureCoordinates = new Vector2((float)u, (float)v); - } - } - break; - case "MeshVertexColors": - if (g.Data.Length == 0) - { - continue; - } - if (g.Data.Length != 2) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "MeshVertexColors is expected to have 2 arguments in Mesh in x object file " + FileName); - return false; - } - else if (!(g.Data[0] is int)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nVertexColors is expected to be a DWORD in MeshTextureCoords in Mesh in x object file " + FileName); - return false; - } - else if (!(g.Data[1] is Structure[])) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "vertexColors[nVertexColors] is expected to be a Structure array in MeshVertexColors in Mesh in x object file " + FileName); - return false; - } - - Structure[] structures = g.Data[1] as Structure[]; - for (int k = 0; k < structures.Length; k++) - { - if (!(structures[k].Data[0] is int)) - { - //Message: Expected to be vertex index - continue; - } - int idx = (int)structures[k].Data[0]; - if (!(structures[k].Data[1] is Structure)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "vertexColors[" + idx + "] is expected to be a ColorRGBA array in MeshVertexColors in Mesh in x object file " + FileName); - continue; - } - - Structure colorStructure = structures[k].Data[1] as Structure; - if (colorStructure.Data.Length != 4) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "vertexColors[" + idx + "] is expected to have 4 arguments in MeshVertexColors in Mesh in x object file " + FileName); - continue; - } - if (!(colorStructure.Data[0] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "R is expected to be a float in MeshVertexColors[" + k.ToString(Culture) + "] in in Mesh in x object file " + FileName); - continue; - } - if (!(colorStructure.Data[1] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "G is expected to be a float in MeshVertexColors[" + k.ToString(Culture) + "] in in Mesh in x object file " + FileName); - continue; - } - if (!(colorStructure.Data[2] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "B is expected to be a float in MeshVertexColors[" + k.ToString(Culture) + "] in in Mesh in x object file " + FileName); - continue; - } - if (!(colorStructure.Data[3] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "A is expected to be a float in MeshVertexColors[" + k.ToString(Culture) + "] in in Mesh in x object file " + FileName); - continue; - } - - double red = (double)colorStructure.Data[0], green = (double)colorStructure.Data[1], blue = (double)colorStructure.Data[2], alpha = (double)colorStructure.Data[3]; - - Color128 c = new Color128((float)red, (float)green, (float)blue, (float)alpha); - Vertices[idx] = new ColoredVertex((Vertex)Vertices[idx], c); - } - break; - case "MeshNormals": - { - // meshnormals - if (g.Data.Length != 4) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "MeshNormals is expected to have 4 arguments in Mesh in x object file " + FileName); - return false; - } - else if (!(g.Data[0] is int)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nNormals is expected to be a DWORD in MeshNormals in Mesh in x object file " + FileName); - return false; - } - else if (!(g.Data[1] is Structure[])) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "normals is expected to be a Vector array in MeshNormals in Mesh in x object file " + FileName); - return false; - } - else if (!(g.Data[2] is int)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaceNormals is expected to be a DWORD in MeshNormals in Mesh in x object file " + FileName); - return false; - } - else if (!(g.Data[3] is Structure[])) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faceNormals is expected to be a MeshFace array in MeshNormals in Mesh in x object file " + FileName); - return false; - } - int nNormals = (int)g.Data[0]; - if (nNormals < 0) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nNormals is expected to be non-negative in MeshNormals in Mesh in x object file " + FileName); - return false; - } - Structure[] normals = (Structure[])g.Data[1]; - if (nNormals != normals.Length) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nNormals does not match with the length of array normals in MeshNormals in Mesh in x object file " + FileName); - return false; - } - int nFaceNormals = (int)g.Data[2]; - if (nFaceNormals < 0 | nFaceNormals > nFaces) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nNormals does not reference valid vertices in MeshNormals in Mesh in x object file " + FileName); - return false; - } - Structure[] faceNormals = (Structure[])g.Data[3]; - if (nFaceNormals != faceNormals.Length) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaceNormals does not match with the length of array faceNormals in MeshNormals in Mesh in x object file " + FileName); - return false; - } - // collect normals - Vector3[] Normals = new Vector3[nNormals]; - for (int k = 0; k < nNormals; k++) - { - if (normals[k].Name != "Vector") - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "normals[" + k.ToString(Culture) + "] is expected to be of template Vertex in MeshNormals in Mesh in x object file " + FileName); - return false; - } - else if (normals[k].Data.Length != 3) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "normals[" + k.ToString(Culture) + "] is expected to have 3 arguments in MeshNormals in Mesh in x object file " + FileName); - return false; - } - else if (!(normals[k].Data[0] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "x is expected to be a float in normals[" + k.ToString(Culture) + "] in MeshNormals in Mesh in x object file " + FileName); - return false; - } - else if (!(normals[k].Data[1] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "y is expected to be a float in normals[" + k.ToString(Culture) + " ]in MeshNormals in Mesh in x object file " + FileName); - return false; - } - else if (!(normals[k].Data[2] is double)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "z is expected to be a float in normals[" + k.ToString(Culture) + "] in MeshNormals in Mesh in x object file " + FileName); - return false; - } - double x = (double)normals[k].Data[0]; - double y = (double)normals[k].Data[1]; - double z = (double)normals[k].Data[2]; - Normals[k] = new Vector3((float)x, (float)y, (float)z); - Normals[k].Normalize(); - } - // collect faces - for (int k = 0; k < nFaceNormals; k++) - { - if (faceNormals[k].Name != "MeshFace") - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faceNormals[" + k.ToString(Culture) + "] is expected to be of template MeshFace in MeshNormals in Mesh in x object file " + FileName); - return false; - } - else if (faceNormals[k].Data.Length != 2) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faceNormals[" + k.ToString(Culture) + "] is expected to have 2 arguments in MeshNormals in Mesh in x object file " + FileName); - return false; - } - else if (!(faceNormals[k].Data[0] is int)) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaceVertexIndices is expected to be a DWORD in faceNormals[" + k.ToString(Culture) + "] in MeshNormals in Mesh in x object file " + FileName); - return false; - } - else if (!(faceNormals[k].Data[1] is int[])) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faceVertexIndices[nFaceVertexIndices] is expected to be a DWORD array in faceNormals[" + k.ToString(Culture) + "] in MeshNormals in Mesh in x object file " + FileName); - return false; - } - int nFaceVertexIndices = (int)faceNormals[k].Data[0]; - if (nFaceVertexIndices < 0 | nFaceVertexIndices > Faces[k].Length) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaceVertexIndices does not reference a valid vertex in MeshFace in MeshNormals in Mesh in x object file " + FileName); - return false; - } - int[] faceVertexIndices = (int[])faceNormals[k].Data[1]; - if (nFaceVertexIndices != faceVertexIndices.Length) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "nFaceVertexIndices does not match with the length of array faceVertexIndices in faceNormals[" + k.ToString(Culture) + "] in MeshFace in MeshNormals in Mesh in x object file " + FileName); - return false; - } - for (int l = 0; l < nFaceVertexIndices; l++) - { - if (faceVertexIndices[l] < 0 | faceVertexIndices[l] >= nNormals) - { - Plugin.currentHost.AddMessage(MessageType.Error, false, "faceVertexIndices[" + l.ToString(Culture) + "] does not reference a valid normal in faceNormals[" + k.ToString(Culture) + "] in MeshFace in MeshNormals in Mesh in x object file " + FileName); - return false; - } - FaceNormals[k][l] = Normals[faceVertexIndices[l]]; - } - } - } - break; - default: - // unknown - Plugin.currentHost.AddMessage(MessageType.Warning, false, "Unsupported template " + g.Name + " encountered in Mesh in x object file " + FileName); - break; - - } - } - // default material - if (Materials.Length == 0) - { - Materials = new Material[1]; - Materials[0].faceColor = Color32.White; - Materials[0].emissiveColor = Color24.Black; - Materials[0].specularColor = Color24.Black; - Materials[0].TextureFilename = null; - for (int j = 0; j < nFaces; j++) - { - FaceMaterials[j] = 0; - } - } - // create mesh - int mf = Object.Mesh.Faces.Length; - int mm = Object.Mesh.Materials.Length; - int mv = Object.Mesh.Vertices.Length; - Array.Resize(ref Object.Mesh.Faces, mf + nFaces); - Array.Resize(ref Object.Mesh.Materials, mm + Materials.Length); - Array.Resize(ref Object.Mesh.Vertices, mv + Vertices.Length); - for (int j = 0; j < Materials.Length; j++) - { - bool emissive = Materials[j].emissiveColor.R != 0 | Materials[j].emissiveColor.G != 0 | Materials[j].emissiveColor.B != 0; - bool transparent; - if (Materials[j].TextureFilename != null) - { - Plugin.currentHost.RegisterTexture(Materials[j].TextureFilename, new TextureParameters(null, Color24.Black), out Object.Mesh.Materials[mm + j].DaytimeTexture); - transparent = true; - } - else - { - Object.Mesh.Materials[mm + j].DaytimeTexture = null; - transparent = false; - } - - Object.Mesh.Materials[mm + j].Flags = new MaterialFlags(); - if (transparent) - { - Object.Mesh.Materials[mm + j].Flags |= MaterialFlags.TransparentColor; - } - if (emissive) - { - Object.Mesh.Materials[mm + j].Flags |= MaterialFlags.Emissive; - } - Object.Mesh.Materials[mm + j].Color = Materials[j].faceColor; - Object.Mesh.Materials[mm + j].TransparentColor = Color24.Black; - Object.Mesh.Materials[mm + j].EmissiveColor = Materials[j].emissiveColor; - Object.Mesh.Materials[mm + j].NighttimeTexture = null; - Object.Mesh.Materials[mm + j].BlendMode = MeshMaterialBlendMode.Normal; - Object.Mesh.Materials[mm + j].GlowAttenuationData = 0; - } - for (int j = 0; j < nFaces; j++) - { - Object.Mesh.Faces[mf + j].Material = (ushort)FaceMaterials[j]; - Object.Mesh.Faces[mf + j].Vertices = new MeshFaceVertex[Faces[j].Length]; - for (int k = 0; k < Faces[j].Length; k++) - { - Object.Mesh.Faces[mf + j].Vertices[k] = new MeshFaceVertex(mv + Faces[j][k], FaceNormals[j][k]); - } - } - for (int j = 0; j < Vertices.Length; j++) - { - Object.Mesh.Vertices[mv + j] = Vertices[j]; - } - break; - } - case "Header": - break; - default: - // unknown - if (f.Name == "Material" && f.Key != String.Empty) - { - Array.Resize(ref LoadedMaterials, LoadedMaterials.Length + 1); - LoadedMaterials[LoadedMaterials.Length - 1] = f; - break; - } - Plugin.currentHost.AddMessage(MessageType.Warning, false, "Unsupported template " + f.Name + " encountered in x object file " + FileName); - break; - } - } - // return - Object.Mesh.CreateNormals(); - return true; - } - - } -} diff --git a/source/Plugins/Object.DirectX/Plugin.cs b/source/Plugins/Object.DirectX/Plugin.cs index 78a595b99..9f9a466f9 100644 --- a/source/Plugins/Object.DirectX/Plugin.cs +++ b/source/Plugins/Object.DirectX/Plugin.cs @@ -1,4 +1,27 @@ -using System; +//Simplified BSD License (BSD-2-Clause) +// +//Copyright (c) 2020, Christopher Lees, The OpenBVE Project +// +//Redistribution and use in source and binary forms, with or without +//modification, are permitted provided that the following conditions are met: +// +//1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +//2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +//ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +//WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +//ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +//(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +//LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +//ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +//(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + using System.IO; using OpenBveApi.FileSystem; using OpenBveApi.Hosts; @@ -30,18 +53,31 @@ public override void SetObjectParser(object parserType) if (parserType is XParsers) { currentXParser = (XParsers) parserType; + if (currentXParser == XParsers.Original) + { + currentHost.AddMessage(MessageType.Error, false, "The original X Parser has been deprecated- Using the NewXParser"); + } } } + private int pathRecursions; + public override bool CanLoadObject(string path) { - if (string.IsNullOrEmpty(path) || !File.Exists(path)) + if (string.IsNullOrEmpty(path) || !File.Exists(path) || pathRecursions > 2) { + pathRecursions = 0; return false; } byte[] Data = File.ReadAllBytes(path); if (Data.Length < 16 || Data[0] != 120 | Data[1] != 111 | Data[2] != 102 | Data[3] != 32) { + string potentialPath = System.Text.Encoding.ASCII.GetString(Data); + if (!OpenBveApi.Path.ContainsInvalidChars(potentialPath)) + { + pathRecursions++; + return CanLoadObject(OpenBveApi.Path.CombineFile(Path.GetDirectoryName(path), potentialPath)); + } // not an x object return false; } @@ -49,6 +85,7 @@ public override bool CanLoadObject(string path) if (Data[4] != 48 | Data[5] != 51 | Data[6] != 48 | Data[7] != 50 & Data[7] != 51) { // unrecognized version + pathRecursions = 0; return false; } @@ -63,42 +100,42 @@ public override bool CanLoadObject(string path) } else { + pathRecursions = 0; return false; } + pathRecursions = 0; return true; } public override bool LoadObject(string path, System.Text.Encoding Encoding, out UnifiedObject unifiedObject) { - try - { - if (currentXParser != XParsers.Original) - { + switch (currentXParser) + { + case XParsers.Original: + case XParsers.NewXParser: try { - if (currentXParser == XParsers.NewXParser) - { - unifiedObject = NewXParser.ReadObject(path, Encoding); - return true; - } - unifiedObject = AssimpXParser.ReadObject(path); + unifiedObject = NewXParser.ReadObject(path, Encoding); return true; } - catch (Exception ex) + catch { - currentHost.AddMessage(MessageType.Error, false, "The new X parser raised the following exception: " + ex); - unifiedObject = XObjectParser.ReadObject(path, Encoding); + unifiedObject = null; + return false; + } + case XParsers.Assimp: + try + { + unifiedObject = AssimpXParser.ReadObject(path); return true; } - } - unifiedObject = XObjectParser.ReadObject(path, Encoding); - return true; - } - catch - { - unifiedObject = null; - currentHost.AddMessage(MessageType.Error, false, "An unexpected error occured whilst attempting to load the following object: " + path); + catch + { + unifiedObject = null; + return false; + } } + unifiedObject = null; return false; } } diff --git a/source/Plugins/Object.LokSim/ObjectParser.cs b/source/Plugins/Object.LokSim/ObjectParser.cs index da6935c2c..884125899 100644 --- a/source/Plugins/Object.LokSim/ObjectParser.cs +++ b/source/Plugins/Object.LokSim/ObjectParser.cs @@ -283,13 +283,11 @@ internal static StaticObject ReadObject(string FileName, Vector3 Rotation) { //Defines the verticies in this face //**NOTE**: A vertex may appear in multiple faces with different texture co-ordinates - if (childNode.Attributes["Points"] != null) + if (childNode.Attributes["Points"] != null && !string.IsNullOrEmpty(childNode.Attributes["Points"].Value)) { string[] Verticies = childNode.Attributes["Points"].Value.Split(';'); //Add 1 to the length of the face array - MeshFace f = new MeshFace(); - //Create the vertex array for the face - f.Vertices = new MeshFaceVertex[Verticies.Length]; + MeshFace f = new MeshFace(Verticies.Length); //Run through the vertices list and grab from the temp array int smallestX = TextureWidth; diff --git a/source/Plugins/Object.Wavefront/Parsers/AssimpObjParser.cs b/source/Plugins/Object.Wavefront/Parsers/AssimpObjParser.cs index 049b4c757..0476f948d 100644 --- a/source/Plugins/Object.Wavefront/Parsers/AssimpObjParser.cs +++ b/source/Plugins/Object.Wavefront/Parsers/AssimpObjParser.cs @@ -94,7 +94,7 @@ internal static StaticObject ReadObject(string FileName) for (int i = 0; i < nVerts; i++) { Vertex v = new Vertex(allVertices[(int)face.Vertices[i]]); - if (allTexCoords.Count > 0 && i <= allTexCoords.Count) + if (allTexCoords.Count > 0 && i <= allTexCoords.Count && face.TexturCoords.Count > 0 && i <= face.TexturCoords.Count) { v.TextureCoordinates = allTexCoords[(int)face.TexturCoords[i]]; } @@ -102,10 +102,7 @@ internal static StaticObject ReadObject(string FileName) } - MeshFace f = new MeshFace - { - Vertices = new MeshFaceVertex[nVerts] - }; + MeshFace f = new MeshFace(nVerts); for (int i = 0; i < nVerts; i++) { f.Vertices[i].Index = (ushort)i; diff --git a/source/Plugins/Route.CsvRw/CsvRwRouteParser.ApplyRouteData.cs b/source/Plugins/Route.CsvRw/CsvRwRouteParser.ApplyRouteData.cs index a4c569e83..fba6d35ed 100644 --- a/source/Plugins/Route.CsvRw/CsvRwRouteParser.ApplyRouteData.cs +++ b/source/Plugins/Route.CsvRw/CsvRwRouteParser.ApplyRouteData.cs @@ -152,7 +152,7 @@ private void ApplyRouteData(string FileName, ref RouteData Data, bool PreviewOnl } // create objects and track Vector3 Position = Vector3.Zero; - Vector2 Direction = new Vector2(0.0, 1.0); + Vector2 Direction = Vector2.Down; double CurrentSpeedLimit = double.PositiveInfinity; int CurrentRunIndex = 0; int CurrentFlangeIndex = 0; diff --git a/source/Plugins/Route.Mechanik/MechanikRouteParser.cs b/source/Plugins/Route.Mechanik/MechanikRouteParser.cs index 288a83f0f..c9e652b23 100644 --- a/source/Plugins/Route.Mechanik/MechanikRouteParser.cs +++ b/source/Plugins/Route.Mechanik/MechanikRouteParser.cs @@ -689,9 +689,9 @@ private static void ProcessRoute(bool PreviewOnly) } Vector3 worldPosition = new Vector3(); - Vector2 worldDirection = new Vector2(0.0, 1.0); - Vector3 trackPosition = new Vector3(0.0, 0.0, 0.0); - Vector2 trackDirection = new Vector2(0.0, 1.0); + Vector2 worldDirection = Vector2.Down; + Vector3 trackPosition = Vector3.Zero; + Vector2 trackDirection = Vector2.Down; Plugin.CurrentRoute.Tracks[0].Elements = new TrackElement[256]; int CurrentTrackLength = 0; diff --git a/source/Plugins/Sound.RiffWave/Plugin.Parser.cs b/source/Plugins/Sound.RiffWave/Plugin.Parser.cs index 8382d5192..b4e9e7f40 100644 --- a/source/Plugins/Sound.RiffWave/Plugin.Parser.cs +++ b/source/Plugins/Sound.RiffWave/Plugin.Parser.cs @@ -13,21 +13,30 @@ public partial class Plugin // --- structures and enumerations --- private abstract class WaveFormatEx { - internal ushort wFormatTag; + internal readonly ushort wFormatTag; internal ushort nChannels; internal uint nSamplesPerSec; internal uint nAvgBytesPerSec; internal ushort nBlockAlign; internal ushort wBitsPerSample; internal ushort cbSize; + + protected WaveFormatEx(ushort tag) + { + wFormatTag = tag; + } } private class WaveFormatPcm : WaveFormatEx { + public WaveFormatPcm(ushort tag) : base(tag) + { + } } private class WaveFormatAdPcm : WaveFormatEx { + internal struct CoefSet { internal short iCoef1; @@ -61,10 +70,24 @@ internal BlockData(int channels) 230, 230, 230, 230, 307, 409, 512, 614, 768, 614, 512, 409, 307, 230, 230, 230 }; + + public WaveFormatAdPcm(ushort tag) : base(tag) + { + } } private class WaveFormatMp3 : WaveFormatEx { + public WaveFormatMp3(ushort tag) : base(tag) + { + } + } + + private class WaveFormatExtensible : WaveFormatEx + { + public WaveFormatExtensible(ushort tag) : base(tag) + { + } } @@ -194,22 +217,25 @@ private static Sound WaveLoadFromStream(BinaryReader reader, BinaryReaderExtensi ushort wFormatTag = reader.ReadUInt16(endianness); - if (wFormatTag == 0x0001 || wFormatTag == 0x0003) - { - format = new WaveFormatPcm { wFormatTag = wFormatTag }; - } - else if (wFormatTag == 0x0002) - { - format = new WaveFormatAdPcm { wFormatTag = wFormatTag }; - } - else if (wFormatTag == 0x0050 || wFormatTag == 0x0055) - { - format = new WaveFormatMp3 { wFormatTag = wFormatTag }; - } - else + switch (wFormatTag) { - // unsupported format - throw new InvalidDataException("Unsupported wFormatTag"); + case 0x0001: + case 0x0003: + format = new WaveFormatPcm(wFormatTag); + break; + case 0x0002: + format = new WaveFormatAdPcm(wFormatTag); + break; + case 0x0050: + case 0x0055: + format = new WaveFormatMp3(wFormatTag); + break; + case 0xFFFE: + format = new WaveFormatExtensible(wFormatTag); + break; + default: + // unsupported format + throw new InvalidDataException("Unsupported wFormatTag"); } format.nChannels = reader.ReadUInt16(endianness); @@ -491,6 +517,7 @@ private static Sound ChangeBitDepth(ushort formatTag, int samplesPerSec, int byt switch (formatTag) { case 0x0001: + case 0xFFFE: switch (bytesPerSample) { case 3: diff --git a/source/RouteViewer/FunctionScripts.cs b/source/RouteViewer/FunctionScripts.cs index f94a30577..f3e46a3d7 100644 --- a/source/RouteViewer/FunctionScripts.cs +++ b/source/RouteViewer/FunctionScripts.cs @@ -288,6 +288,13 @@ internal static void ExecuteFunctionScript(FunctionScript Function, TrainManager Function.Stack[s] = 0.0; } s++; break; + case Instructions.TrainLength: + if (Train != null) { + Function.Stack[s] = Train.Length; + } else { + Function.Stack[s] = 0.0; + } + s++; break; case Instructions.TrainSpeed: if (Train != null) { Function.Stack[s] = Train.Cars[CarIndex].CurrentSpeed; diff --git a/source/TrainEditor/Program.cs b/source/TrainEditor/Program.cs index 697b87d27..7ef0b813a 100644 --- a/source/TrainEditor/Program.cs +++ b/source/TrainEditor/Program.cs @@ -12,6 +12,7 @@ internal static class Program { /// Information about the file system organization. internal static FileSystem FileSystem = null; + internal static HostInterface CurrentHost; // --- functions --- /// Is executed when the program starts. @@ -20,8 +21,9 @@ internal static class Program { private static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); + CurrentHost = new Host(); try { - FileSystem = FileSystem.FromCommandLineArgs(args, null); + FileSystem = FileSystem.FromCommandLineArgs(args, CurrentHost); FileSystem.CreateFileSystem(); } catch (Exception ex) { MessageBox.Show(Translations.GetInterfaceString("errors_filesystem_invalid") + Environment.NewLine + Environment.NewLine + ex.Message, "TrainEditor", MessageBoxButtons.OK, MessageBoxIcon.Hand); diff --git a/source/TrainEditor/System/Class1.cs b/source/TrainEditor/System/Class1.cs new file mode 100644 index 000000000..9bf4f7c52 --- /dev/null +++ b/source/TrainEditor/System/Class1.cs @@ -0,0 +1,17 @@ +using System; +using OpenBveApi.Hosts; +using OpenBveApi.Trains; + + +namespace TrainEditor +{ + /// Represents the host application. + internal class Host : HostInterface + { + public Host() : base(HostApplication.TrainEditor) { } + public override AbstractTrain ParseTrackFollowingObject(string objectPath, string tfoFile) + { + throw new NotImplementedException(); + } + } +} diff --git a/source/TrainEditor/TrainEditor.csproj b/source/TrainEditor/TrainEditor.csproj index 4a34b9b38..ad5eb6901 100644 --- a/source/TrainEditor/TrainEditor.csproj +++ b/source/TrainEditor/TrainEditor.csproj @@ -77,11 +77,13 @@ + + Form @@ -138,6 +140,7 @@ TrainManager + diff --git a/source/TrainEditor2/Program.cs b/source/TrainEditor2/Program.cs index 155115b36..bcbb861bf 100644 --- a/source/TrainEditor2/Program.cs +++ b/source/TrainEditor2/Program.cs @@ -40,7 +40,7 @@ private static void Main() try { - FileSystem = FileSystem.FromCommandLineArgs(new string[0], null); + FileSystem = FileSystem.FromCommandLineArgs(new string[0], CurrentHost); FileSystem.CreateFileSystem(); } catch (Exception ex) diff --git a/source/TrainManager/SafetySystems/Plugin/Plugin.cs b/source/TrainManager/SafetySystems/Plugin/Plugin.cs index bb6605c0f..fca2494c5 100644 --- a/source/TrainManager/SafetySystems/Plugin/Plugin.cs +++ b/source/TrainManager/SafetySystems/Plugin/Plugin.cs @@ -326,7 +326,7 @@ private void SetHandles(OpenBveApi.Runtime.Handles handles, bool virtualHandles) else { this.Train.Handles.EmergencyBrake.Release(); - Train.Handles.Brake.ApplyState(AirBrakeHandleState.Release); + Train.Handles.Brake.ApplyState(AirBrakeHandleState.Service); } } else if (handles.BrakeNotch == 3) diff --git a/source/TrainManager/Train/TrainBase.cs b/source/TrainManager/Train/TrainBase.cs index 0bd952819..4817a89e5 100644 --- a/source/TrainManager/Train/TrainBase.cs +++ b/source/TrainManager/Train/TrainBase.cs @@ -5,6 +5,7 @@ using OpenBveApi; using OpenBveApi.Colors; using OpenBveApi.Interface; +using OpenBveApi.Routes; using OpenBveApi.Runtime; using OpenBveApi.Trains; using RouteManager2.MessageManager; @@ -79,6 +80,20 @@ public double CargoRatio } } + public override double Length + { + get + { + double myLength = 0; + for (int i = 0; i < Cars.Length; i++) + { + myLength += Cars[i].Length; + } + + return myLength; + } + } + public TrainBase(TrainState state) { State = state;