mirror of
https://github.com/0x7c13/Pal3.Unity.git
synced 2026-11-26 17:38:10 +08:00
Cover SCE command contracts, binary readers, resource layouts and full local CPK decompression for PAL3 and PAL3A. Fix CVD time rebasing, binary read bounds and short reads, and CPK/NAV validation. Standardize first-party copyright headers, preserve correct creation years, and update console source generation. Validate both variants in Unity and verify all live CPK entries.
51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
// ------------------------------------------------------------------------
|
|
// Copyright (c) 2021-2026, Jiaqi (0x7c13) Liu. All rights reserved.
|
|
// See LICENSE file in the project root for license information.
|
|
// ------------------------------------------------------------------------
|
|
|
|
namespace Engine.DataLoader
|
|
{
|
|
using System.Buffers;
|
|
using Core.Abstraction;
|
|
using Core.Implementation;
|
|
using Pal3.Core.DataReader.Bmp;
|
|
|
|
public sealed class BmpTextureLoader : ITextureLoader
|
|
{
|
|
public ITextureDataSource Load(byte[] data, out bool hasAlphaChannel)
|
|
{
|
|
hasAlphaChannel = false;
|
|
BmpFile image = new BmpFileReader().Read(data);
|
|
int width = image.Info.AbsWidth;
|
|
int height = image.Info.AbsHeight;
|
|
|
|
if (image.Info.Height < 0)
|
|
{
|
|
for (int y = 0; y < height / 2; y++)
|
|
{
|
|
for (int x = 0, o1 = y * width, o2 = (height - y - 1) * width; x < width; x++, o1++, o2++)
|
|
(image.ImageData[o1], image.ImageData[o2]) = (image.ImageData[o2], image.ImageData[o1]);
|
|
}
|
|
}
|
|
|
|
byte[] rgba = ArrayPool<byte>.Shared.Rent(checked(image.ImageData.Length * 4));
|
|
try
|
|
{
|
|
for (int i = 0; i < image.ImageData.Length; i++)
|
|
{
|
|
rgba[i * 4 + 0] = image.ImageData[i].B;
|
|
rgba[i * 4 + 1] = image.ImageData[i].G;
|
|
rgba[i * 4 + 2] = image.ImageData[i].R;
|
|
rgba[i * 4 + 3] = image.ImageData[i].A;
|
|
}
|
|
return Rgba32TextureDataSource.TakePooledBuffer(width, height, rgba, hasTransparency: false);
|
|
}
|
|
catch
|
|
{
|
|
ArrayPool<byte>.Shared.Return(rgba);
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|