mirror of
https://github.com/crskycode/GARbro.git
synced 2026-07-08 01:30:18 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -440,9 +440,22 @@ namespace GameRes
|
||||
{
|
||||
byte* s = m_mem + (offset - m_offset);
|
||||
uint string_length = 0;
|
||||
while (string_length < size && 0 != s[string_length])
|
||||
// enc.WindowsCodePage property might throw an exception for some encodings, while
|
||||
// CodePage is just a direct field access.
|
||||
if (enc.CodePage == 1200 || enc.CodePage == 1201) // for UTF-16 encodings stop marker is 2-bytes long
|
||||
{
|
||||
++string_length;
|
||||
ushort* u = (ushort*)s;
|
||||
while (string_length + 1 < size && 0 != u[string_length >> 1])
|
||||
{
|
||||
string_length += 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (string_length < size && 0 != s[string_length])
|
||||
{
|
||||
++string_length;
|
||||
}
|
||||
}
|
||||
return new string ((sbyte*)s, 0, (int)string_length, enc);
|
||||
}
|
||||
|
||||
@@ -263,7 +263,9 @@ namespace GameRes
|
||||
|
||||
public bool FileExists (string filename)
|
||||
{
|
||||
return m_dir.ContainsKey (CombinePath (CurrentDirectory, filename));
|
||||
return m_dir.ContainsKey (filename)
|
||||
|| !string.IsNullOrEmpty (CurrentDirectory)
|
||||
&& m_dir.ContainsKey (CombinePath (CurrentDirectory, filename));
|
||||
}
|
||||
|
||||
public Stream OpenStream (Entry entry)
|
||||
@@ -408,6 +410,8 @@ namespace GameRes
|
||||
Entry entry = null;
|
||||
if (m_dir.TryGetValue (filename, out entry))
|
||||
return entry;
|
||||
if (m_dir.TryGetValue (CombinePath (CurrentDirectory, filename), out entry))
|
||||
return entry;
|
||||
var dir_name = filename + PathDelimiter;
|
||||
if (m_dir.Keys.Any (n => n.StartsWith (dir_name)))
|
||||
return new SubDirEntry (filename);
|
||||
|
||||
@@ -220,6 +220,13 @@ namespace GameRes
|
||||
file.Read (pixels, dst, stride);
|
||||
for (int x = 3; !has_alpha && x < stride; x += 4)
|
||||
has_alpha = pixels[dst+x] != 0;
|
||||
/* // sometimes alpha channel is inverted
|
||||
for (int x = 3; x < stride; x += 4)
|
||||
{
|
||||
pixels[dst+x] ^= 0xFF;
|
||||
has_alpha = has_alpha || pixels[dst+x] != 0;
|
||||
}
|
||||
*/
|
||||
}
|
||||
PixelFormat format = has_alpha ? PixelFormats.Bgra32 : PixelFormats.Bgr32;
|
||||
return ImageData.Create (info, format, null, pixels, stride);
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace GameRes
|
||||
protected ImageData m_image;
|
||||
|
||||
public Stream Source { get { m_input.Position = 0; return m_input.AsStream; } }
|
||||
public ImageFormat SourceFormat { get { return null; } }
|
||||
public ImageFormat SourceFormat { get; protected set; }
|
||||
public ImageMetaData Info { get; protected set; }
|
||||
public ImageData Image { get { return m_image ?? (m_image = GetImageData()); } }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user