From 18a5b27333fd220eb2cef176a02a8a3278b246e6 Mon Sep 17 00:00:00 2001 From: Jeremy Pritts <49847914+ds5678@users.noreply.github.com> Date: Wed, 2 Aug 2023 01:33:37 -0400 Subject: [PATCH] Fix bug in NumericConversion --- .../NumericConversionGenerator.cs | 4 +++- AssetRipper.TextureDecoder/Rgb/NumericConversion.g.cs | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/AssetRipper.TextureDecoder.ColorGenerator/NumericConversionGenerator.cs b/AssetRipper.TextureDecoder.ColorGenerator/NumericConversionGenerator.cs index 63a85cb..bfa00bb 100644 --- a/AssetRipper.TextureDecoder.ColorGenerator/NumericConversionGenerator.cs +++ b/AssetRipper.TextureDecoder.ColorGenerator/NumericConversionGenerator.cs @@ -13,6 +13,7 @@ internal static class NumericConversionGenerator public static void Run() { + Console.WriteLine(ClassName); using IndentedTextWriter writer = IndentedTextWriterFactory.Create(OutputDirectory, ClassName); Write(writer); } @@ -214,7 +215,8 @@ internal static class NumericConversionGenerator writer.WriteLine("unchecked"); using (new CurlyBrackets(writer)) { - writer.WriteLine($"{toName} converted = ({toName})(({conversionType})value >> {(fromSize / toSize - 1) * 8});"); + int offset = (fromSize / toSize - 1) * toSize * 8; + writer.WriteLine($"{toName} converted = ({toName})(({conversionType})value >> {offset});"); writer.WriteLine($"return Unsafe.As<{toName}, TTo>(ref converted);"); } } diff --git a/AssetRipper.TextureDecoder/Rgb/NumericConversion.g.cs b/AssetRipper.TextureDecoder/Rgb/NumericConversion.g.cs index 3790353..9a51e01 100644 --- a/AssetRipper.TextureDecoder/Rgb/NumericConversion.g.cs +++ b/AssetRipper.TextureDecoder/Rgb/NumericConversion.g.cs @@ -278,7 +278,7 @@ static partial class NumericConversion // There are more accurate ways to map uint onto ushort, but this is the simplest. unchecked { - ushort converted = (ushort)((uint)value >> 8); + ushort converted = (ushort)((uint)value >> 16); return Unsafe.As(ref converted); } } @@ -369,7 +369,7 @@ static partial class NumericConversion // There are more accurate ways to map ulong onto ushort, but this is the simplest. unchecked { - ushort converted = (ushort)((ulong)value >> 24); + ushort converted = (ushort)((ulong)value >> 48); return Unsafe.As(ref converted); } } @@ -384,7 +384,7 @@ static partial class NumericConversion // There are more accurate ways to map ulong onto uint, but this is the simplest. unchecked { - uint converted = (uint)((ulong)value >> 8); + uint converted = (uint)((ulong)value >> 32); return Unsafe.As(ref converted); } }