Skip to content

Commit 15463b3

Browse files
committed
Fix RB3 UVs
1 parent fd60f46 commit 15463b3

2 files changed

Lines changed: 9 additions & 21 deletions

File tree

MiloLib/Utils/Endian/EndianReader.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,8 @@ public long ReadInt64()
167167

168168
public float ReadHalfFloat()
169169
{
170-
ushort raw = ReadUInt16();
171-
172-
// Swap if stream endianness != host endianness
173-
if (_bigEndian == BitConverter.IsLittleEndian)
174-
raw = (ushort)((raw << 8) | (raw >> 8));
175-
176-
return (float)BitConverter.UInt16BitsToHalf(raw);
170+
ushort bits = ReadUInt16();
171+
return (float)BitConverter.UInt16BitsToHalf(bits);
177172
}
178173

179174
/// <summary>

MiloLib/Utils/Endian/EndianWriter.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,16 @@ public void WriteInt64(long value)
200200
/// <exception cref="IOException">Thrown if there is an issue writing to the stream.</exception>
201201
public void WriteHalfFloat(float value)
202202
{
203-
ushort bits = BitConverter.HalfToUInt16Bits((Half)value);
204-
205-
// Swap if stream endianness != host endianness
206-
if (_bigEndian == BitConverter.IsLittleEndian)
207-
bits = (ushort)((bits << 8) | (bits >> 8));
208-
209-
// write the low and high bits
210-
byte lo = (byte)(bits & 0xFF);
211-
byte hi = (byte)(bits >> 8);
212-
try
203+
Half half = (Half)value;
204+
if (_bigEndian)
213205
{
214-
_stream.WriteByte(lo);
215-
_stream.WriteByte(hi);
206+
byte[] bytes = BitConverter.GetBytes(half);
207+
_stream.Write(bytes.Reverse().ToArray(), 0, bytes.Length);
216208
}
217-
catch (Exception e)
209+
else
218210
{
219-
throw new IOException("An IO exception occurred during write", e);
211+
byte[] bytes = BitConverter.GetBytes(half);
212+
_stream.Write(bytes, 0, bytes.Length);
220213
}
221214
}
222215

0 commit comments

Comments
 (0)