From 5cd29f999d3512cc18c8dd7670d55de30c2b5dec Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 26 Oct 2013 16:57:06 +1300 Subject: [PATCH 1/5] Palette header comes *after* the frame. Fixes #3728. --- OpenRA.FileFormats/Graphics/R8Reader.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/OpenRA.FileFormats/Graphics/R8Reader.cs b/OpenRA.FileFormats/Graphics/R8Reader.cs index 0ecd31c802..d737af6cee 100644 --- a/OpenRA.FileFormats/Graphics/R8Reader.cs +++ b/OpenRA.FileFormats/Graphics/R8Reader.cs @@ -53,15 +53,11 @@ namespace OpenRA.FileFormats // Skip alignment byte s.ReadUInt8(); - // Ignore palette header - if (type == 1 && paletteOffset != 0) - s.Seek(8, SeekOrigin.Current); - Image = s.ReadBytes(width*height); - // Ignore palette data + // Ignore palette if (type == 1 && paletteOffset != 0) - s.Seek(512, SeekOrigin.Current); + s.Seek(520, SeekOrigin.Current); } } From 84ffb0de053ccd876bb7b0ddcab18689e2740602 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 26 Oct 2013 17:39:44 +1300 Subject: [PATCH 2/5] Add Subtractive blend mode for d2k move-flash. --- OpenRA.FileFormats/Graphics/IGraphicsDevice.cs | 2 +- OpenRA.Renderer.SdlCommon/SdlGraphics.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs index 9be4681fc8..efd2bb6cfb 100755 --- a/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs +++ b/OpenRA.FileFormats/Graphics/IGraphicsDevice.cs @@ -32,7 +32,7 @@ namespace OpenRA.FileFormats.Graphics IGraphicsDevice Create( Size size, WindowMode windowMode ); } - public enum BlendMode { None, Alpha, Additive } + public enum BlendMode { None, Alpha, Additive, Subtractive } public interface IGraphicsDevice { diff --git a/OpenRA.Renderer.SdlCommon/SdlGraphics.cs b/OpenRA.Renderer.SdlCommon/SdlGraphics.cs index f8ab2ecde7..8c8de209e3 100644 --- a/OpenRA.Renderer.SdlCommon/SdlGraphics.cs +++ b/OpenRA.Renderer.SdlCommon/SdlGraphics.cs @@ -154,6 +154,9 @@ namespace OpenRA.Renderer.SdlCommon public void SetBlendMode(BlendMode mode) { + Gl.glBlendEquation(Gl.GL_FUNC_ADD); + ErrorHandler.CheckGlError(); + switch (mode) { case BlendMode.None: @@ -169,6 +172,13 @@ namespace OpenRA.Renderer.SdlCommon ErrorHandler.CheckGlError(); Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE); break; + case BlendMode.Subtractive: + Gl.glEnable(Gl.GL_BLEND); + ErrorHandler.CheckGlError(); + Gl.glBlendFunc(Gl.GL_ONE, Gl.GL_ONE); + ErrorHandler.CheckGlError(); + Gl.glBlendEquation(Gl.GL_FUNC_REVERSE_SUBTRACT); + break; } ErrorHandler.CheckGlError(); } From 3fe3b4d088fefdb55ec53e567afe3f9d1d057651 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 26 Oct 2013 17:40:02 +1300 Subject: [PATCH 3/5] Fieldloader support for longs. --- OpenRA.FileFormats/FieldLoader.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/OpenRA.FileFormats/FieldLoader.cs b/OpenRA.FileFormats/FieldLoader.cs index fc64c526f3..0dc062df43 100755 --- a/OpenRA.FileFormats/FieldLoader.cs +++ b/OpenRA.FileFormats/FieldLoader.cs @@ -127,6 +127,14 @@ namespace OpenRA.FileFormats return InvalidValueAction(value, fieldType, fieldName); } + if (fieldType == typeof(long)) + { + long res; + if (long.TryParse(value, out res)) + return res; + return InvalidValueAction(value, fieldType, fieldName); + } + else if (fieldType == typeof(float)) { float res; From ff21ec16051eac51a0d5dfa5542a3066ade2269e Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 26 Oct 2013 17:47:14 +1300 Subject: [PATCH 4/5] Add PaletteFromR8 for loading embedded palettes. The frames that define a custom palette are: Frame range -> offset (mem offset) 38 -> 12007 (22063136) 178 -> 159947 (21859680) 3494 - 3501 -> 2437846 (23366680) 3502 - 3509 -> 2443858 (23422744) 3510 - 3511 -> 2459105 (23363608) 3621 - 3625 -> 2572352 (23550488) 3739 - 3742 -> 2676956 (23534796) --- OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj | 1 + OpenRA.Mods.D2k/PaletteFromR8.cs | 53 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 OpenRA.Mods.D2k/PaletteFromR8.cs diff --git a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj index 01d307f517..f0c67781f0 100644 --- a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj +++ b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj @@ -79,6 +79,7 @@ + diff --git a/OpenRA.Mods.D2k/PaletteFromR8.cs b/OpenRA.Mods.D2k/PaletteFromR8.cs new file mode 100644 index 0000000000..697b31e67c --- /dev/null +++ b/OpenRA.Mods.D2k/PaletteFromR8.cs @@ -0,0 +1,53 @@ +#region Copyright & License Information +/* + * Copyright 2007-2012 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System.IO; +using OpenRA.FileFormats; +using OpenRA.Traits; +using OpenRA.Graphics; + +namespace OpenRA.Mods.RA +{ + class PaletteFromR8Info : ITraitInfo + { + [Desc("Internal palette name")] + public readonly string Name = null; + [Desc("Filename to load")] + public readonly string Filename = null; + [Desc("Palette byte offset")] + public readonly long Offset = 0; + public readonly bool AllowModifiers = true; + + public object Create(ActorInitializer init) { return new PaletteFromR8(this); } + } + + class PaletteFromR8 : IPalette + { + readonly PaletteFromR8Info info; + public PaletteFromR8(PaletteFromR8Info info) { this.info = info; } + + public void InitPalette(WorldRenderer wr) + { + var colors = new uint[256]; + using (var s = FileSystem.Open(info.Filename)) + { + s.Seek(info.Offset, SeekOrigin.Begin); + + for (var i = 0; i < 256; i++) + { + var packed = s.ReadUInt16(); + colors[i] = (uint)((255 << 24) | ((packed & 0xF800) << 8) | ((packed & 0x7E0) << 5) | ((packed & 0x1f) << 3)); + } + } + + wr.AddPalette(info.Name, new Palette(colors), info.AllowModifiers); + } + } +} From 536013f2d2f8f1653f821d95077966b4af2a7191 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 26 Oct 2013 19:15:05 +1300 Subject: [PATCH 5/5] Rescale the custom palette from 0-128. --- OpenRA.Mods.D2k/PaletteFromR8.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.D2k/PaletteFromR8.cs b/OpenRA.Mods.D2k/PaletteFromR8.cs index 697b31e67c..901fef682c 100644 --- a/OpenRA.Mods.D2k/PaletteFromR8.cs +++ b/OpenRA.Mods.D2k/PaletteFromR8.cs @@ -42,8 +42,10 @@ namespace OpenRA.Mods.RA for (var i = 0; i < 256; i++) { + // The custom palette is scaled into the range 0-128. + // This makes the move-flash match the original game, but may not be correct in other cases. var packed = s.ReadUInt16(); - colors[i] = (uint)((255 << 24) | ((packed & 0xF800) << 8) | ((packed & 0x7E0) << 5) | ((packed & 0x1f) << 3)); + colors[i] = (uint)((255 << 24) | ((packed & 0xF800) << 7) | ((packed & 0x7E0) << 4) | ((packed & 0x1f) << 2)); } }