diff --git a/File_Format_Library/FileFormats/Archives/RARC.cs b/File_Format_Library/FileFormats/Archives/RARC.cs index 1c39b4f0..cbc7fcfa 100644 --- a/File_Format_Library/FileFormats/Archives/RARC.cs +++ b/File_Format_Library/FileFormats/Archives/RARC.cs @@ -87,6 +87,8 @@ namespace FirstPlugin CanRenameFiles = true; CanReplaceFiles = true; + files.Clear(); + using (var reader = new FileReader(stream)) { _savedDirectories.Clear(); @@ -159,6 +161,7 @@ namespace FirstPlugin entry.FileData = reader.ReadBytes((int)entry.Size); } entry.FileName = entry.Name; + files.Add(entry); Directories[dir].AddNode(entry); } diff --git a/File_Format_Library/FileFormats/Layout/BxlytToGL.cs b/File_Format_Library/FileFormats/Layout/BxlytToGL.cs new file mode 100644 index 00000000..789896dd --- /dev/null +++ b/File_Format_Library/FileFormats/Layout/BxlytToGL.cs @@ -0,0 +1,290 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Drawing; +using System.Threading.Tasks; +using OpenTK.Graphics.OpenGL; +using Toolbox.Library; +using Toolbox.Library.IO; +using OpenTK; + +namespace LayoutBXLYT +{ + public class BxlytToGL + { + public static int ConvertTextureWrap(WrapMode wrapMode) + { + switch (wrapMode) + { + case WrapMode.Clamp: return (int)TextureWrapMode.Clamp; + case WrapMode.Mirror: return (int)TextureWrapMode.MirroredRepeat; + case WrapMode.Repeat: return (int)TextureWrapMode.Repeat; + default: return (int)TextureWrapMode.Clamp; + } + } + + public static int ConvertMagFilterMode(FilterMode filterMode) + { + switch (filterMode) + { + case FilterMode.Linear: return (int)TextureMagFilter.Linear; + case FilterMode.Near: return (int)TextureMagFilter.Nearest; + default: return (int)TextureMagFilter.Linear; + } + } + + public static int ConvertMinFilterMode(FilterMode filterMode) + { + switch (filterMode) + { + case FilterMode.Linear: return (int)TextureMinFilter.Linear; + case FilterMode.Near: return (int)TextureMinFilter.Nearest; + default: return (int)TextureMinFilter.Linear; + } + } + + public static void DrawPictureBox(BasePane pane, byte effectiveAlpha, Dictionary Textures) + { + Vector2[] TexCoords = new Vector2[] { + new Vector2(1,1), + new Vector2(0,1), + new Vector2(0,0), + new Vector2(1,0) + }; + + if (pane is Cafe.BFLYT.PIC1) + { + var pic1Pane = pane as Cafe.BFLYT.PIC1; + + Color[] Colors = new Color[] { + pic1Pane.ColorTopLeft.Color, + pic1Pane.ColorTopRight.Color, + pic1Pane.ColorBottomRight.Color, + pic1Pane.ColorBottomLeft.Color, + }; + + var mat = pic1Pane.Material; + if (mat.Shader == null) + { + mat.Shader = new BflytShader(mat); + mat.Shader.Compile(); + } + + mat.Shader.Enable(); + ((BflytShader)mat.Shader).SetMaterials(Textures); + + if (pic1Pane.TexCoords.Length > 0) + { + TexCoords = new Vector2[] { + pic1Pane.TexCoords[0].TopLeft.ToTKVector2(), + pic1Pane.TexCoords[0].TopRight.ToTKVector2(), + pic1Pane.TexCoords[0].BottomRight.ToTKVector2(), + pic1Pane.TexCoords[0].BottomLeft.ToTKVector2(), + }; + } + + DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); + + mat.Shader.Disable(); + + GL.BindTexture(TextureTarget.Texture2D, 0); + GL.PopAttrib(); + } + else if (pane is BCLYT.PIC1) + { + var pic1Pane = pane as BCLYT.PIC1; + + Color[] Colors = new Color[] { + pic1Pane.ColorTopLeft.Color, + pic1Pane.ColorTopRight.Color, + pic1Pane.ColorBottomRight.Color, + pic1Pane.ColorBottomLeft.Color, + }; + + var mat = pic1Pane.Material; + if (mat.Shader == null) + { + mat.Shader = new BclytShader(mat); + mat.Shader.Compile(); + } + + mat.Shader.Enable(); + ((BclytShader)mat.Shader).SetMaterials(Textures); + + if (pic1Pane.TexCoords.Length > 0) + { + TexCoords = new Vector2[] { + pic1Pane.TexCoords[0].TopLeft.ToTKVector2(), + pic1Pane.TexCoords[0].TopRight.ToTKVector2(), + pic1Pane.TexCoords[0].BottomRight.ToTKVector2(), + pic1Pane.TexCoords[0].BottomLeft.ToTKVector2(), + }; + } + + DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); + + mat.Shader.Disable(); + + GL.BindTexture(TextureTarget.Texture2D, 0); + GL.PopAttrib(); + } + else if (pane is BRLYT.PIC1) + { + var pic1Pane = pane as BRLYT.PIC1; + + Color[] Colors = new Color[] { + pic1Pane.ColorTopLeft.Color, + pic1Pane.ColorTopRight.Color, + pic1Pane.ColorBottomRight.Color, + pic1Pane.ColorBottomLeft.Color, + }; + + var mat = pic1Pane.Material; + if (mat.Shader == null) + { + mat.Shader = new BrlytShader(mat); + mat.Shader.Compile(); + } + + mat.Shader.Enable(); + ((BrlytShader)mat.Shader).SetMaterials(Textures); + + if (pic1Pane.TexCoords.Length > 0) + { + TexCoords = new Vector2[] { + pic1Pane.TexCoords[0].TopLeft.ToTKVector2(), + pic1Pane.TexCoords[0].TopRight.ToTKVector2(), + pic1Pane.TexCoords[0].BottomRight.ToTKVector2(), + pic1Pane.TexCoords[0].BottomLeft.ToTKVector2(), + }; + } + + DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); + + mat.Shader.Disable(); + + GL.BindTexture(TextureTarget.Texture2D, 0); + GL.PopAttrib(); + } + } + + public static void DrawBoundryPane(BasePane pane, byte effectiveAlpha, List SelectedPanes) + { + Vector2[] TexCoords = new Vector2[] { + new Vector2(1,1), + new Vector2(0,1), + new Vector2(0,0), + new Vector2(1,0) + }; + + Color color = Color.DarkGreen; + if (SelectedPanes.Contains(pane)) + color = Color.Red; + + color = Color.FromArgb(70, color); + + Color[] Colors = new Color[] { + color, + color, + color, + color, + }; + + BxlytToGL.DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); + } + + public static bool BindGLTexture(BxlytTextureRef tex, STGenericTexture texture) + { + if (texture.RenderableTex == null || !texture.RenderableTex.GLInitialized) + texture.LoadOpenGLTexture(); + + //If the texture is still not initialized then return + if (!texture.RenderableTex.GLInitialized) + return false; + + GL.BindTexture(TextureTarget.Texture2D, texture.RenderableTex.TexID); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, ConvertChannel(texture.RedChannel)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, ConvertChannel(texture.GreenChannel)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleB, ConvertChannel(texture.BlueChannel)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, ConvertChannel(texture.AlphaChannel)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, ConvertTextureWrap(tex.WrapModeU)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, ConvertTextureWrap(tex.WrapModeV)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, ConvertMagFilterMode(tex.MaxFilterMode)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, ConvertMinFilterMode(tex.MinFilterMode)); + + return true; + } + + private static int ConvertChannel(STChannelType type) + { + switch (type) + { + case STChannelType.Red: return (int)TextureSwizzle.Red; + case STChannelType.Green: return (int)TextureSwizzle.Green; + case STChannelType.Blue: return (int)TextureSwizzle.Blue; + case STChannelType.Alpha: return (int)TextureSwizzle.Alpha; + case STChannelType.Zero: return (int)TextureSwizzle.Zero; + case STChannelType.One: return (int)TextureSwizzle.One; + default: return 0; + } + } + + enum TextureSwizzle + { + Zero = All.Zero, + One = All.One, + Red = All.Red, + Green = All.Green, + Blue = All.Blue, + Alpha = All.Alpha, + } + + public static void DrawRectangle(CustomRectangle rect, Vector2[] texCoords, + Color[] colors, bool useLines = true, byte alpha = 255) + { + for (int i = 0; i < colors.Length; i++) + { + uint setalpha = (uint)((colors[i].A * alpha) / 255); + colors[i] = Color.FromArgb((int)setalpha, colors[i]); + } + + if (useLines) + { + GL.Begin(PrimitiveType.LineLoop); + GL.Color4(colors[0]); + GL.Vertex2(rect.LeftPoint, rect.BottomPoint); + GL.Vertex2(rect.RightPoint, rect.BottomPoint); + GL.Vertex2(rect.RightPoint, rect.TopPoint); + GL.Vertex2(rect.LeftPoint, rect.TopPoint); + GL.End(); + } + else + { + GL.Begin(PrimitiveType.Quads); + GL.Color4(colors[0]); + GL.MultiTexCoord2(TextureUnit.Texture0, texCoords[0].X, texCoords[0].Y); + GL.Vertex2(rect.LeftPoint, rect.BottomPoint); + GL.Color4(colors[1]); + GL.MultiTexCoord2(TextureUnit.Texture0, texCoords[1].X, texCoords[1].Y); + GL.Vertex2(rect.RightPoint, rect.BottomPoint); + GL.Color4(colors[2]); + GL.MultiTexCoord2(TextureUnit.Texture0, texCoords[2].X, texCoords[2].Y); + GL.Vertex2(rect.RightPoint, rect.TopPoint); + GL.Color4(colors[3]); + GL.MultiTexCoord2(TextureUnit.Texture0, texCoords[3].X, texCoords[3].Y); + GL.Vertex2(rect.LeftPoint, rect.TopPoint); + GL.End(); + + //Draw outline + GL.Begin(PrimitiveType.LineLoop); + GL.LineWidth(3); + GL.Color4(colors[0]); + GL.Vertex2(rect.LeftPoint, rect.BottomPoint); + GL.Vertex2(rect.RightPoint, rect.BottomPoint); + GL.Vertex2(rect.RightPoint, rect.TopPoint); + GL.Vertex2(rect.LeftPoint, rect.TopPoint); + GL.End(); + } + } + } +} diff --git a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs index fe1af11e..852b5c35 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/BFLYT.cs @@ -1181,6 +1181,8 @@ namespace LayoutBXLYT.Cafe { public override string Signature { get; } = "prt1"; + private bool hasSearchedParts = false; + public PRT1() : base() { @@ -1202,6 +1204,8 @@ namespace LayoutBXLYT.Cafe public BasePane GetExternalPane() { + if (hasSearchedParts) return null; + if (ExternalLayout == null) ExternalLayout = SearchExternalFile(); @@ -1214,6 +1218,8 @@ namespace LayoutBXLYT.Cafe //Get textures if possible from the external parts file public void UpdateTextureData(Dictionary textures) { + if (hasSearchedParts) return; + if (ExternalLayout == null) { ExternalLayout = SearchExternalFile(); @@ -1231,6 +1237,8 @@ namespace LayoutBXLYT.Cafe private BFLYT SearchExternalFile() { + hasSearchedParts = false; + var fileFormat = layoutFile.FileInfo; string path = FileManager.GetSourcePath(fileFormat); @@ -1240,13 +1248,12 @@ namespace LayoutBXLYT.Cafe string folder = Path.GetDirectoryName(path); foreach (var file in Directory.GetFiles(folder)) { - Console.WriteLine("checking " + file.Contains(LayoutFile)); if (file.Contains(LayoutFile)) { var openedFile = STFileLoader.OpenFileFormat(file); if (openedFile is IArchiveFile) { - var bflyt = new BFLYT(); + BFLYT bflyt = null; SearchArchive((IArchiveFile)openedFile, ref bflyt); if (bflyt != null) return bflyt; @@ -1280,15 +1287,21 @@ namespace LayoutBXLYT.Cafe foreach (var file in archiveFile.Files) { - if (file.FileName.Contains(LayoutFile)) + if (file.FileName.Contains(".lyarc")) + { + var openedFile = file.OpenFile(); + if (openedFile is IArchiveFile) + SearchArchive((IArchiveFile)openedFile, ref layoutFile); + } + else if (file.FileName.Contains(LayoutFile)) { - Console.WriteLine("Part found! " + file.FileName); - var openedFile = file.OpenFile(); if (openedFile is IArchiveFile) SearchArchive((IArchiveFile)openedFile, ref layoutFile); else if (openedFile is BFLYT) { + Console.WriteLine("Part found! " + file.FileName); + layoutFile = openedFile as BFLYT; layoutFile.IFileInfo = new IFileInfo(); layoutFile.IFileInfo.ArchiveParent = layoutFile.IFileInfo.ArchiveParent; diff --git a/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs b/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs index e223c6a1..f331c635 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/BflytShader.cs @@ -50,7 +50,7 @@ namespace LayoutBXLYT { GL.ActiveTexture(TextureUnit.Texture0); SetInt("textures0", 0); - bool isBinded = LayoutViewer.BindGLTexture(material.TextureMaps[0], textures[textureMap0]); + bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[0], textures[textureMap0]); if (isBinded) SetInt("hasTexture0", 1); } @@ -81,10 +81,10 @@ namespace LayoutBXLYT if (material.TextureMaps.Length > 0) { var tex = material.TextureMaps[0]; - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, ConvertTextureWrap(tex.WrapModeU)); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, ConvertTextureWrap(tex.WrapModeV)); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, ConvertMagFilterMode(tex.MaxFilterMode)); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, ConvertMinFilterMode(tex.MinFilterMode)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, BxlytToGL.ConvertTextureWrap(tex.WrapModeU)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, BxlytToGL.ConvertTextureWrap(tex.WrapModeV)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, BxlytToGL.ConvertMagFilterMode(tex.MaxFilterMode)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, BxlytToGL.ConvertMinFilterMode(tex.MinFilterMode)); } } @@ -105,36 +105,5 @@ namespace LayoutBXLYT return System.IO.File.ReadAllText(path); } } - - private static int ConvertTextureWrap(TextureRef.WrapMode wrapMode) - { - switch (wrapMode) - { - case TextureRef.WrapMode.Clamp: return (int)TextureWrapMode.Clamp; - case TextureRef.WrapMode.Mirror: return (int)TextureWrapMode.MirroredRepeat; - case TextureRef.WrapMode.Repeat: return (int)TextureWrapMode.Repeat; - default: return (int)TextureWrapMode.Clamp; - } - } - - private static int ConvertMagFilterMode(TextureRef.FilterMode filterMode) - { - switch (filterMode) - { - case TextureRef.FilterMode.Linear: return (int)TextureMagFilter.Linear; - case TextureRef.FilterMode.Near: return (int)TextureMagFilter.Nearest; - default: return (int)TextureRef.FilterMode.Linear; - } - } - - private static int ConvertMinFilterMode(TextureRef.FilterMode filterMode) - { - switch (filterMode) - { - case TextureRef.FilterMode.Linear: return (int)TextureMinFilter.Linear; - case TextureRef.FilterMode.Near: return (int)TextureMinFilter.Nearest; - default: return (int)TextureRef.FilterMode.Linear; - } - } } } diff --git a/File_Format_Library/FileFormats/Layout/CAFE/Materials/TextureRef.cs b/File_Format_Library/FileFormats/Layout/CAFE/Materials/TextureRef.cs index f8354b6b..4c825635 100644 --- a/File_Format_Library/FileFormats/Layout/CAFE/Materials/TextureRef.cs +++ b/File_Format_Library/FileFormats/Layout/CAFE/Materials/TextureRef.cs @@ -2,29 +2,28 @@ namespace LayoutBXLYT.Cafe { - public class TextureRef + public class TextureRef : BxlytTextureRef { - public string Name { get; set; } public short ID; byte flag1; byte flag2; - public WrapMode WrapModeU + public override WrapMode WrapModeU { get { return (WrapMode)(flag1 & 0x3); } } - public WrapMode WrapModeV + public override WrapMode WrapModeV { get { return (WrapMode)(flag2 & 0x3); } } - public FilterMode MinFilterMode + public override FilterMode MinFilterMode { get { return (FilterMode)((flag1 >> 2) & 0x3); } } - public FilterMode MaxFilterMode + public override FilterMode MaxFilterMode { get { return (FilterMode)((flag2 >> 2) & 0x3); } } @@ -47,18 +46,5 @@ namespace LayoutBXLYT.Cafe writer.Write(flag1); writer.Write(flag2); } - - public enum FilterMode - { - Near = 0, - Linear = 1 - } - - public enum WrapMode - { - Clamp = 0, - Repeat = 1, - Mirror = 2 - } } } diff --git a/File_Format_Library/FileFormats/Layout/CTR/BCLYT.cs b/File_Format_Library/FileFormats/Layout/CTR/BCLYT.cs index 92a7b41f..8a1603ac 100644 --- a/File_Format_Library/FileFormats/Layout/CTR/BCLYT.cs +++ b/File_Format_Library/FileFormats/Layout/CTR/BCLYT.cs @@ -736,7 +736,7 @@ namespace LayoutBXLYT } } - public bool InfluenceAlpha + public override bool InfluenceAlpha { get { return (_flags1 & 0x2) == 0x2; } set @@ -750,8 +750,6 @@ namespace LayoutBXLYT public byte Origin { get; set; } - public byte Alpha { get; set; } - public byte PartsScale { get; set; } public byte PaneMagFlags { get; set; } @@ -921,7 +919,7 @@ namespace LayoutBXLYT uint texCount = Convert.ToUInt32(flags & 3); uint mtxCount = Convert.ToUInt32(flags >> 2) & 3; for (int i = 0; i < texCount; i++) - TextureMaps.Add(new TextureRef(reader)); + TextureMaps.Add(new TextureRef(reader, header)); for (int i = 0; i < mtxCount; i++) TextureTransforms.Add(new TextureTransform(reader)); @@ -965,38 +963,41 @@ namespace LayoutBXLYT } } - public class TextureRef + public class TextureRef : BxlytTextureRef { public short ID; byte flag1; byte flag2; - public WrapMode WrapModeU + public override WrapMode WrapModeU { get { return (WrapMode)(flag1 & 0x3); } } - public WrapMode WrapModeV + public override WrapMode WrapModeV { get { return (WrapMode)(flag2 & 0x3); } } - public FilterMode MinFilterMode + public override FilterMode MinFilterMode { get { return (FilterMode)((flag1 >> 2) & 0x3); } } - public FilterMode MaxFilterMode + public override FilterMode MaxFilterMode { get { return (FilterMode)((flag2 >> 2) & 0x3); } } public TextureRef() {} - public TextureRef(FileReader reader) { + public TextureRef(FileReader reader, Header header) { ID = reader.ReadInt16(); flag1 = reader.ReadByte(); flag2 = reader.ReadByte(); + + if (header.Textures.Count > 0) + Name = header.Textures[ID]; } public void Write(FileWriter writer) @@ -1005,19 +1006,6 @@ namespace LayoutBXLYT writer.Write(flag1); writer.Write(flag2); } - - public enum FilterMode - { - Near = 0, - Linear = 1 - } - - public enum WrapMode - { - Clamp = 0, - Repeat = 1, - Mirror = 2 - } } public class FNL1 : SectionCommon diff --git a/File_Format_Library/FileFormats/Layout/CTR/BrlytShader.cs b/File_Format_Library/FileFormats/Layout/CTR/BrlytShader.cs new file mode 100644 index 00000000..5d5c445e --- /dev/null +++ b/File_Format_Library/FileFormats/Layout/CTR/BrlytShader.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Text; +using System.Threading.Tasks; +using OpenTK.Graphics.OpenGL; +using OpenTK; +using Toolbox.Library; + +namespace LayoutBXLYT +{ + public class BclytShader : BxlytShader + { + public BCLYT.Material material; + + public BclytShader(BCLYT.Material mat) : base() + { + material = mat; + LoadShaders(); + } + + public override void OnCompiled() + { + SetColor("whiteColor", Color.FromArgb(255,255,255,255)); + SetColor("blackColor", Color.FromArgb(0, 0, 0, 0)); + SetInt("debugShading", 0); + SetInt("hasTexture0", 0); + SetInt("numTextureMaps", 0); + + SetVec2("uvScale0", new Vector2(1,1)); + SetFloat("uvRotate0", 0); + SetVec2("uvTranslate0", new Vector2(0, 0)); + } + + public void SetMaterials(Dictionary textures) + { + SetColor("whiteColor", Color.FromArgb(255, 255, 255, 255)); + SetColor("blackColor", Color.FromArgb(0, 0, 0, 0)); + SetInt("debugShading", (int)Runtime.LayoutEditor.Shading); + SetInt("numTextureMaps", material.TextureMaps.Count); + + BindTextureUniforms(); + + string textureMap0 = ""; + if (material.TextureMaps.Count > 0) + textureMap0 = material.GetTexture(0); + + if (textures.ContainsKey(textureMap0)) + { + GL.ActiveTexture(TextureUnit.Texture0); + SetInt("textures0", 0); + bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[0], textures[textureMap0]); + if (isBinded) + SetInt("hasTexture0", 1); + } + + if (material.TextureTransforms.Count > 0) + { + var transform = material.TextureTransforms[0]; + float shiftX = 0; + float shiftY = 0; + if (transform.Scale.X < 0) + shiftX = 1; + if (transform.Scale.Y < 0) + shiftY = 1; + + SetVec2("uvScale0",new Vector2(transform.Scale.X, transform.Scale.Y)); + SetFloat("uvRotate0", transform.Rotate); + SetVec2("uvTranslate0",new Vector2(shiftX + transform.Translate.X, shiftY + transform.Translate.Y)); + } + } + + private void BindTextureUniforms() + { + //Do uv test pattern + GL.ActiveTexture(TextureUnit.Texture10); + GL.Uniform1(GL.GetUniformLocation(program, "uvTestPattern"), 10); + GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.RenderableTex.TexID); + + if (material.TextureMaps.Count > 0) + { + var tex = material.TextureMaps[0]; + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, BxlytToGL.ConvertTextureWrap(tex.WrapModeU)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, BxlytToGL.ConvertTextureWrap(tex.WrapModeV)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, BxlytToGL.ConvertMagFilterMode(tex.MaxFilterMode)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, BxlytToGL.ConvertMinFilterMode(tex.MinFilterMode)); + } + } + + public override string VertexShader + { + get + { + string path = System.IO.Path.Combine(Runtime.ExecutableDir, "Shader", "Layout", "Bflyt.vert"); + return System.IO.File.ReadAllText(path); + } + } + + public override string FragmentShader + { + get + { + string path = System.IO.Path.Combine(Runtime.ExecutableDir, "Shader", "Layout", "Bflyt.frag"); + return System.IO.File.ReadAllText(path); + } + } + } +} diff --git a/File_Format_Library/FileFormats/Layout/Common.cs b/File_Format_Library/FileFormats/Layout/Common.cs index 8162771a..5988585e 100644 --- a/File_Format_Library/FileFormats/Layout/Common.cs +++ b/File_Format_Library/FileFormats/Layout/Common.cs @@ -191,6 +191,19 @@ namespace LayoutBXLYT } } + public enum FilterMode + { + Near = 0, + Linear = 1 + } + + public enum WrapMode + { + Clamp = 0, + Repeat = 1, + Mirror = 2 + } + public enum OriginX : byte { Center = 0, @@ -210,6 +223,16 @@ namespace LayoutBXLYT UserData UserData { get; set; } } + public class BxlytTextureRef + { + public string Name { get; set; } + + public virtual WrapMode WrapModeU { get; set; } + public virtual WrapMode WrapModeV { get; set; } + public virtual FilterMode MinFilterMode { get; set; } + public virtual FilterMode MaxFilterMode { get; set; } + } + public class UserData : SectionCommon { public List Entries { get; set; } diff --git a/File_Format_Library/FileFormats/Layout/Rev/BRLYT.cs b/File_Format_Library/FileFormats/Layout/Rev/BRLYT.cs index a7a663d6..a06f521d 100644 --- a/File_Format_Library/FileFormats/Layout/Rev/BRLYT.cs +++ b/File_Format_Library/FileFormats/Layout/Rev/BRLYT.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Threading.Tasks; +using System.ComponentModel; using Toolbox; using System.Windows.Forms; using Toolbox.Library; @@ -12,6 +12,7 @@ using FirstPlugin.Forms; using Syroot.Maths; using SharpYaml.Serialization; using FirstPlugin; +using static Toolbox.Library.IO.Bit; namespace LayoutBXLYT { @@ -120,8 +121,9 @@ namespace LayoutBXLYT file.FileFormat = tpl; foreach (var tex in tpl.IconTextureList) { + //Only need the first texture if (!textures.ContainsKey(tex.Text)) - textures.Add(tex.Text, tex); + textures.Add(file.FileName, tex); } } } @@ -656,6 +658,12 @@ namespace LayoutBXLYT return ParentLayout.TextureList.Textures[mat.TextureMaps[index].ID]; } + [TypeConverter(typeof(ExpandableObjectConverter))] + public Material Material + { + get { return ParentLayout.MaterialList.Materials[MaterialIndex]; } + } + private BRLYT.Header ParentLayout; public PIC1() : base() { @@ -720,7 +728,7 @@ namespace LayoutBXLYT } } - public bool InfluenceAlpha + public override bool InfluenceAlpha { get { return (_flags1 & 0x2) == 0x2; } set @@ -739,8 +747,6 @@ namespace LayoutBXLYT public byte Origin { get; set; } - public byte Alpha { get; set; } - public byte PartsScale { get; set; } public byte PaneMagFlags { get; set; } @@ -869,10 +875,8 @@ namespace LayoutBXLYT public class Material : BxlytMaterial { - public string Name { get; set; } - - public STColor16 ForeColor { get; set; } - public STColor16 BackColor { get; set; } + public STColor16 WhiteColor { get; set; } + public STColor16 BlackColor { get; set; } public STColor16 ColorRegister3 { get; set; } public STColor8 TevColor1 { get; set; } @@ -884,7 +888,6 @@ namespace LayoutBXLYT public List TextureTransforms { get; set; } private uint flags; - private int unknown; private BRLYT.Header ParentLayout; public string GetTexture(int index) @@ -910,8 +913,8 @@ namespace LayoutBXLYT Name = reader.ReadString(0x14, true); - ForeColor = reader.ReadColor16RGBA(); - BackColor = reader.ReadColor16RGBA(); + WhiteColor = reader.ReadColor16RGBA(); + BlackColor = reader.ReadColor16RGBA(); ColorRegister3 = reader.ReadColor16RGBA(); TevColor1 = reader.ReadColor8RGBA(); TevColor2 = reader.ReadColor8RGBA(); @@ -919,10 +922,12 @@ namespace LayoutBXLYT TevColor4 = reader.ReadColor8RGBA(); flags = reader.ReadUInt32(); - uint texCount = Convert.ToUInt32(flags & 3); - uint mtxCount = Convert.ToUInt32(flags >> 2) & 3; + uint indSrtCount = ExtractBits(flags, 2, 17); + uint texCoordGenCount = ExtractBits(flags, 4, 20); + uint mtxCount = ExtractBits(flags, 4, 24); + uint texCount = ExtractBits(flags, 4, 28); for (int i = 0; i < texCount; i++) - TextureMaps.Add(new TextureRef(reader)); + TextureMaps.Add(new TextureRef(reader, header)); for (int i = 0; i < mtxCount; i++) TextureTransforms.Add(new TextureTransform(reader)); @@ -966,35 +971,38 @@ namespace LayoutBXLYT } } - public class TextureRef + public class TextureRef : BxlytTextureRef { public short ID; byte flag1; byte flag2; - public WrapMode WrapModeU + public override WrapMode WrapModeU { get { return (WrapMode)(flag1 & 0x3); } } - public WrapMode WrapModeV + public override WrapMode WrapModeV { get { return (WrapMode)(flag2 & 0x3); } } - public FilterMode MinFilterMode + public override FilterMode MinFilterMode { get { return (FilterMode)((flag1 >> 2) & 0x3); } } - public FilterMode MaxFilterMode + public override FilterMode MaxFilterMode { get { return (FilterMode)((flag2 >> 2) & 0x3); } } public TextureRef() {} - public TextureRef(FileReader reader) { + public TextureRef(FileReader reader, Header header) { + if (header.Textures.Count > 0) + Name = header.Textures[ID]; + ID = reader.ReadInt16(); flag1 = reader.ReadByte(); flag2 = reader.ReadByte(); @@ -1006,19 +1014,6 @@ namespace LayoutBXLYT writer.Write(flag1); writer.Write(flag2); } - - public enum FilterMode - { - Near = 0, - Linear = 1 - } - - public enum WrapMode - { - Clamp = 0, - Repeat = 1, - Mirror = 2 - } } public class FNL1 : SectionCommon @@ -1038,11 +1033,15 @@ namespace LayoutBXLYT reader.Seek(2); //padding long pos = reader.Position; - - uint[] offsets = reader.ReadUInt32s(numFonts); - for (int i = 0; i < offsets.Length; i++) + for (int i = 0; i < numFonts; i++) { - reader.SeekBegin(offsets[i] + pos); + uint offset = reader.ReadUInt32(); + reader.ReadUInt32();//padding + + using (reader.TemporarySeek(offset + pos, System.IO.SeekOrigin.Begin)) + { + Fonts.Add(reader.ReadZeroTerminatedString()); + } } } @@ -1051,14 +1050,14 @@ namespace LayoutBXLYT writer.Write((ushort)Fonts.Count); writer.Seek(2); - //Fill empty spaces for offsets later + //Fill empty spaces for offsets later and also add padding long pos = writer.Position; - writer.Write(new uint[Fonts.Count]); + writer.Write(new uint[Fonts.Count * 2]); //Save offsets and strings for (int i = 0; i < Fonts.Count; i++) { - writer.WriteUint32Offset(pos + (i * 4), pos); + writer.WriteUint32Offset(pos + (i * 8), pos); writer.WriteString(Fonts[i]); } } @@ -1081,12 +1080,14 @@ namespace LayoutBXLYT reader.Seek(2); //padding long pos = reader.Position; - - uint[] offsets = reader.ReadUInt32s(numTextures); - for (int i = 0; i < offsets.Length; i++) + for (int i = 0; i < numTextures; i++) { - reader.SeekBegin(offsets[i] + pos); - Textures.Add(reader.ReadZeroTerminatedString()); + uint offset = reader.ReadUInt32(); + reader.ReadUInt32();//padding + + using (reader.TemporarySeek(offset + pos, System.IO.SeekOrigin.Begin)) { + Textures.Add(reader.ReadZeroTerminatedString()); + } } } @@ -1095,14 +1096,14 @@ namespace LayoutBXLYT writer.Write((ushort)Textures.Count); writer.Seek(2); - //Fill empty spaces for offsets later + //Fill empty spaces for offsets later and also add another for padding long pos = writer.Position; - writer.Write(new uint[Textures.Count]); + writer.Write(new uint[Textures.Count * 2]); //Save offsets and strings for (int i = 0; i < Textures.Count; i++) { - writer.WriteUint32Offset(pos + (i * 4), pos); + writer.WriteUint32Offset(pos + (i * 8), pos); writer.WriteString(Textures[i]); } } diff --git a/File_Format_Library/FileFormats/Layout/Rev/BrlytShader.cs b/File_Format_Library/FileFormats/Layout/Rev/BrlytShader.cs new file mode 100644 index 00000000..747d1f12 --- /dev/null +++ b/File_Format_Library/FileFormats/Layout/Rev/BrlytShader.cs @@ -0,0 +1,108 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Text; +using System.Threading.Tasks; +using OpenTK.Graphics.OpenGL; +using OpenTK; +using Toolbox.Library; + +namespace LayoutBXLYT +{ + public class BrlytShader : BxlytShader + { + public BRLYT.Material material; + + public BrlytShader(BRLYT.Material mat) : base() + { + material = mat; + LoadShaders(); + } + + public override void OnCompiled() + { + SetColor("whiteColor", Color.FromArgb(255,255,255,255)); + SetColor("blackColor", Color.FromArgb(0, 0, 0, 0)); + SetInt("debugShading", 0); + SetInt("hasTexture0", 0); + SetInt("numTextureMaps", 0); + + SetVec2("uvScale0", new Vector2(1,1)); + SetFloat("uvRotate0", 0); + SetVec2("uvTranslate0", new Vector2(0, 0)); + } + + public void SetMaterials(Dictionary textures) + { + SetColor("whiteColor", Color.FromArgb(255, material.WhiteColor.Color)); + SetColor("blackColor", material.BlackColor.Color); + SetInt("debugShading", (int)Runtime.LayoutEditor.Shading); + SetInt("numTextureMaps", material.TextureMaps.Count); + + BindTextureUniforms(); + + string textureMap0 = ""; + if (material.TextureMaps.Count > 0) + textureMap0 = material.GetTexture(0); + + if (textures.ContainsKey(textureMap0)) + { + GL.ActiveTexture(TextureUnit.Texture0); + SetInt("textures0", 0); + bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[0], textures[textureMap0]); + if (isBinded) + SetInt("hasTexture0", 1); + } + + if (material.TextureTransforms.Count > 0) + { + var transform = material.TextureTransforms[0]; + float shiftX = 0; + float shiftY = 0; + if (transform.Scale.X < 0) + shiftX = 1; + if (transform.Scale.Y < 0) + shiftY = 1; + + SetVec2("uvScale0",new Vector2(transform.Scale.X, transform.Scale.Y)); + SetFloat("uvRotate0", transform.Rotate); + SetVec2("uvTranslate0",new Vector2(shiftX + transform.Translate.X, shiftY + transform.Translate.Y)); + } + } + + private void BindTextureUniforms() + { + //Do uv test pattern + GL.ActiveTexture(TextureUnit.Texture10); + GL.Uniform1(GL.GetUniformLocation(program, "uvTestPattern"), 10); + GL.BindTexture(TextureTarget.Texture2D, RenderTools.uvTestPattern.RenderableTex.TexID); + + if (material.TextureMaps.Count > 0) + { + var tex = material.TextureMaps[0]; + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, BxlytToGL.ConvertTextureWrap(tex.WrapModeU)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, BxlytToGL.ConvertTextureWrap(tex.WrapModeV)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, BxlytToGL.ConvertMagFilterMode(tex.MaxFilterMode)); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, BxlytToGL.ConvertMinFilterMode(tex.MinFilterMode)); + } + } + + public override string VertexShader + { + get + { + string path = System.IO.Path.Combine(Runtime.ExecutableDir, "Shader", "Layout", "Bflyt.vert"); + return System.IO.File.ReadAllText(path); + } + } + + public override string FragmentShader + { + get + { + string path = System.IO.Path.Combine(Runtime.ExecutableDir, "Shader", "Layout", "Bflyt.frag"); + return System.IO.File.ReadAllText(path); + } + } + } +} diff --git a/File_Format_Library/File_Format_Library.csproj b/File_Format_Library/File_Format_Library.csproj index a35a18b6..2275681e 100644 --- a/File_Format_Library/File_Format_Library.csproj +++ b/File_Format_Library/File_Format_Library.csproj @@ -295,6 +295,7 @@ + @@ -306,9 +307,11 @@ + + diff --git a/File_Format_Library/GUI/BFLYT/LayoutViewer.cs b/File_Format_Library/GUI/BFLYT/LayoutViewer.cs index 9be4d19b..d9669d1a 100644 --- a/File_Format_Library/GUI/BFLYT/LayoutViewer.cs +++ b/File_Format_Library/GUI/BFLYT/LayoutViewer.cs @@ -56,10 +56,7 @@ namespace LayoutBXLYT Textures = textures; if (bxlyt.Textures.Count > 0) { - if (bxlyt.FileInfo is BFLYT) - Textures = ((BFLYT)bxlyt.FileInfo).GetTextures(); - else if (bxlyt.FileInfo is BCLYT) - Textures = ((BCLYT)bxlyt.FileInfo).GetTextures(); + Textures = bxlyt.GetTextures; } } @@ -185,7 +182,7 @@ namespace LayoutBXLYT var rotate = partPane.Rotate + pane.Rotate; GL.Translate(translate.X + translate.X, translate.Y, 0); - GL.Rotate(rotate.X, 1,0,0); + GL.Rotate(rotate.X, 1, 0, 0); GL.Rotate(rotate.Y, 0, 1, 0); GL.Rotate(rotate.Z, 0, 0, 1); GL.Scale(scale.X, scale.Y, 1); @@ -207,24 +204,16 @@ namespace LayoutBXLYT if (!isRoot) { - if (pane is BFLYT.PIC1) - DrawPicturePane((BFLYT.PIC1)pane, effectiveAlpha, stage); - else if (pane is BCLYT.PIC1) - DrawPicturePane((BCLYT.PIC1)pane, effectiveAlpha); - else if (pane is BRLYT.PIC1) - DrawPicturePane((BRLYT.PIC1)pane, effectiveAlpha); + if (pane is BFLYT.PIC1 || pane is BCLYT.PIC1 || pane is BRLYT.PIC1) + BxlytToGL.DrawPictureBox(pane, effectiveAlpha, Textures); + else if (pane is BFLYT.BND1 || pane is BCLYT.BND1 || pane is BRLYT.BND1) + BxlytToGL.DrawBoundryPane(pane, effectiveAlpha, SelectedPanes); else if (pane is BFLYT.WND1) DrawWindowPane((BFLYT.WND1)pane, effectiveAlpha); - else if (pane is BFLYT.BND1) - DrawBoundryPane((BFLYT.BND1)pane, effectiveAlpha); else if (pane is BFLYT.PRT1) DrawPartsPane((BFLYT.PRT1)pane, effectiveAlpha, parentAlphaInfluence); - else if (pane is BFLYT.PAN1) - DrawDefaultPane((BFLYT.PAN1)pane); - else if (pane is BCLYT.PAN1) - DrawDefaultPane((BCLYT.PAN1)pane); - else if (pane is BRLYT.PAN1) - DrawDefaultPane((BRLYT.PAN1)pane); + else + DrawDefaultPane(pane); } else isRoot = false; @@ -265,31 +254,6 @@ namespace LayoutBXLYT GL.End(); } - private void DrawBoundryPane(BFLYT.BND1 pane, byte effectiveAlpha) - { - Vector2[] TexCoords = new Vector2[] { - new Vector2(1,1), - new Vector2(0,1), - new Vector2(0,0), - new Vector2(1,0) - }; - - Color color = Color.DarkGreen; - if (SelectedPanes.Contains(pane)) - color = Color.Red; - - color = Color.FromArgb(70, color); - - Color[] Colors = new Color[] { - color, - color, - color, - color, - }; - - DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); - } - private void DrawDefaultPane(BasePane pane) { Vector2[] TexCoords = new Vector2[] { @@ -310,7 +274,7 @@ namespace LayoutBXLYT color, }; - DrawRectangle(pane.Rectangle, TexCoords, Colors); + BxlytToGL.DrawRectangle(pane.Rectangle, TexCoords, Colors); } private void DrawPartsPane(BFLYT.PRT1 pane, byte effectiveAlpha, bool parentInfluenceAlpha) @@ -386,7 +350,7 @@ namespace LayoutBXLYT }; } - DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); + BxlytToGL.DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); mat.Shader.Disable(); @@ -428,7 +392,7 @@ namespace LayoutBXLYT }; } - DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); + BxlytToGL.DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); GL.BindTexture(TextureTarget.Texture2D, 0); } @@ -468,7 +432,7 @@ namespace LayoutBXLYT }; } - DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); + BxlytToGL.DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); GL.BindTexture(TextureTarget.Texture2D, 0); } @@ -509,7 +473,7 @@ namespace LayoutBXLYT }; } - DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); + BxlytToGL.DrawRectangle(pane.Rectangle, TexCoords, Colors, false, effectiveAlpha); mat.Shader.Disable(); @@ -576,131 +540,6 @@ namespace LayoutBXLYT } } - public void DrawRectangle(CustomRectangle rect, Vector2[] texCoords, - Color[] colors, bool useLines = true, byte alpha = 255) - { - for (int i = 0; i < colors.Length; i++) - { - uint setalpha = (uint)((colors[i].A * alpha) / 255); - colors[i] = Color.FromArgb((int)setalpha, colors[i]); - } - - if (useLines) - { - GL.Begin(PrimitiveType.LineLoop); - GL.Color4(colors[0]); - GL.Vertex2(rect.LeftPoint, rect.BottomPoint); - GL.Vertex2(rect.RightPoint, rect.BottomPoint); - GL.Vertex2(rect.RightPoint, rect.TopPoint); - GL.Vertex2(rect.LeftPoint, rect.TopPoint); - GL.End(); - } - else - { - GL.Begin(PrimitiveType.Quads); - GL.Color4(colors[0]); - GL.MultiTexCoord2(TextureUnit.Texture0, texCoords[0].X, texCoords[0].Y); - GL.Vertex2(rect.LeftPoint, rect.BottomPoint); - GL.Color4(colors[1]); - GL.MultiTexCoord2(TextureUnit.Texture0, texCoords[1].X, texCoords[1].Y); - GL.Vertex2(rect.RightPoint, rect.BottomPoint); - GL.Color4(colors[2]); - GL.MultiTexCoord2(TextureUnit.Texture0, texCoords[2].X, texCoords[2].Y); - GL.Vertex2(rect.RightPoint, rect.TopPoint); - GL.Color4(colors[3]); - GL.MultiTexCoord2(TextureUnit.Texture0, texCoords[3].X, texCoords[3].Y); - GL.Vertex2(rect.LeftPoint, rect.TopPoint); - GL.End(); - - //Draw outline - GL.Begin(PrimitiveType.LineLoop); - GL.LineWidth(3); - GL.Color4(colors[0]); - GL.Vertex2(rect.LeftPoint, rect.BottomPoint); - GL.Vertex2(rect.RightPoint, rect.BottomPoint); - GL.Vertex2(rect.RightPoint, rect.TopPoint); - GL.Vertex2(rect.LeftPoint, rect.TopPoint); - GL.End(); - } - } - - enum TextureSwizzle - { - Zero = All.Zero, - One = All.One, - Red = All.Red, - Green = All.Green, - Blue = All.Blue, - Alpha = All.Alpha, - } - - public static bool BindGLTexture(TextureRef tex, STGenericTexture texture) - { - if (texture.RenderableTex == null || !texture.RenderableTex.GLInitialized) - texture.LoadOpenGLTexture(); - - //If the texture is still not initialized then return - if (!texture.RenderableTex.GLInitialized) - return false; - - GL.BindTexture(TextureTarget.Texture2D, texture.RenderableTex.TexID); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleR, ConvertChannel(texture.RedChannel)); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleG, ConvertChannel(texture.GreenChannel)); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleB, ConvertChannel(texture.BlueChannel)); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureSwizzleA, ConvertChannel(texture.AlphaChannel)); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, ConvertTextureWrap(tex.WrapModeU)); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, ConvertTextureWrap(tex.WrapModeV)); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, ConvertMagFilterMode(tex.MaxFilterMode)); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, ConvertMinFilterMode(tex.MinFilterMode)); - - return true; - } - - private static int ConvertChannel(STChannelType type) - { - switch (type) - { - case STChannelType.Red: return (int)TextureSwizzle.Red; - case STChannelType.Green: return (int)TextureSwizzle.Green; - case STChannelType.Blue: return (int)TextureSwizzle.Blue; - case STChannelType.Alpha: return (int)TextureSwizzle.Alpha; - case STChannelType.Zero: return (int)TextureSwizzle.Zero; - case STChannelType.One: return (int)TextureSwizzle.One; - default: return 0; - } - } - - private static int ConvertTextureWrap(TextureRef.WrapMode wrapMode) - { - switch (wrapMode) - { - case TextureRef.WrapMode.Clamp: return (int)TextureWrapMode.Clamp; - case TextureRef.WrapMode.Mirror: return (int)TextureWrapMode.MirroredRepeat; - case TextureRef.WrapMode.Repeat: return (int)TextureWrapMode.Repeat; - default: return (int)TextureWrapMode.Clamp; - } - } - - private static int ConvertMagFilterMode(TextureRef.FilterMode filterMode) - { - switch (filterMode) - { - case TextureRef.FilterMode.Linear: return (int)TextureMagFilter.Linear; - case TextureRef.FilterMode.Near: return (int)TextureMagFilter.Nearest; - default: return (int)TextureRef.FilterMode.Linear; - } - } - - private static int ConvertMinFilterMode(TextureRef.FilterMode filterMode) - { - switch (filterMode) - { - case TextureRef.FilterMode.Linear: return (int)TextureMinFilter.Linear; - case TextureRef.FilterMode.Near: return (int)TextureMinFilter.Nearest; - default: return (int)TextureRef.FilterMode.Linear; - } - } - private void DrawBackground() { if (backgroundTex == null) diff --git a/Switch_Toolbox_Library/IO/Bits/Bit.cs b/Switch_Toolbox_Library/IO/Bits/Bit.cs index ef3c9b9d..ea8b9ca8 100644 --- a/Switch_Toolbox_Library/IO/Bits/Bit.cs +++ b/Switch_Toolbox_Library/IO/Bits/Bit.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Toolbox.Library.IO { - class Bit + public class Bit { //From https://github.com/shibbo/flyte/blob/337383c01c50dff155e4b4e170d248118db0c0aa/flyte/utils/Bit.cs public static uint ExtractBits(uint val, int numBits, int startBit)