Skip to content

Commit

Permalink
Add flag to config for main clone support (default: off). Updated PEL…
Browse files Browse the repository at this point in the history
…oaderLib to support main clone EGFs
  • Loading branch information
ethanmoffat committed Mar 7, 2022
1 parent 8734c3a commit 4e0b1f2
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 9 deletions.
2 changes: 2 additions & 0 deletions EOLib.Config/ConfigFileLoadActions.cs
Expand Up @@ -60,6 +60,8 @@ public void LoadConfigFile()
_configRepository.Interaction = !configFile.GetValue(ConfigStrings.Chat, ConfigStrings.Interaction, out tempBool) || tempBool;
_configRepository.LogChatToFile = configFile.GetValue(ConfigStrings.Chat, ConfigStrings.LogChat, out tempBool) && tempBool;

_configRepository.MainCloneCompat = configFile.GetValue(ConfigStrings.Custom, ConfigStrings.MainCloneCompat, out tempBool) && tempBool;

string host;
_configRepository.Host = configFile.GetValue(ConfigStrings.Connection, ConfigStrings.Host, out host) ? host : ConfigDefaults.Host;
_configRepository.Port = configFile.GetValue(ConfigStrings.Connection, ConfigStrings.Port, out tempInt) ? tempInt : ConfigDefaults.Port;
Expand Down
1 change: 1 addition & 0 deletions EOLib.Config/ConfigStrings.cs
Expand Up @@ -27,6 +27,7 @@ public static class ConfigStrings
public const string Custom = "CUSTOM";
public const string NPCDropProtectTime = "NPCDropProtectTime";
public const string PlayerDropProtectTime = "PlayerDropProtectTime";
public const string MainCloneCompat = nameof(MainCloneCompat);

public const string LANGUAGE = "LANGUAGE";
public const string Language = "Language";
Expand Down
6 changes: 6 additions & 0 deletions EOLib.Config/IConfigurationRepository.cs
Expand Up @@ -29,6 +29,8 @@ public interface IConfigurationRepository
bool Interaction { get; set; }
bool LogChatToFile { get; set; }

bool MainCloneCompat { get; set; }

bool EnableLog { get; set; }
}

Expand Down Expand Up @@ -59,6 +61,8 @@ public interface IConfigurationProvider
bool Interaction { get; }
bool LogChatToFile { get; }

bool MainCloneCompat { get; }

bool EnableLog { get; }
}

Expand Down Expand Up @@ -91,6 +95,8 @@ public class ConfigurationRepository : IConfigurationRepository, IConfigurationP
public bool Interaction { get; set; }
public bool LogChatToFile { get; set; }

public bool MainCloneCompat { get; set; }

public bool EnableLog { get; set; }
}
}
13 changes: 8 additions & 5 deletions EOLib.Graphics.Test/NativeGraphicsLoaderTest.cs
Expand Up @@ -6,6 +6,7 @@
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Formats.Bmp;
using EOLib.Config;

namespace EOLib.Graphics.Test
{
Expand All @@ -15,12 +16,14 @@ public class NativeGraphicsLoaderTest
private IPEFileCollection _modules;
private INativeGraphicsLoader _nativeGraphicsLoader;

private const int ExpectedCulture = 0;
private const BitmapVersion ExpectedBitmapVersion = BitmapVersion.BitmapInfoHeader;

[SetUp]
public void SetUp()
{
_modules = Mock.Of<IPEFileCollection>();

_nativeGraphicsLoader = new NativeGraphicsLoader(_modules);
_nativeGraphicsLoader = new NativeGraphicsLoader(_modules, Mock.Of<IConfigurationProvider>(x => x.MainCloneCompat == false));
}

[Test]
Expand All @@ -31,7 +34,7 @@ public void WhenLoadGFX_CallsPEFile_GetEmbeddedBitmapResourceByID()
using (var bmp = _nativeGraphicsLoader.LoadGFX(GFXTypes.PreLoginUI, 1))
bmp.Dispose(); //hide warning for empty using statement

peFileMock.Verify(x => x.GetEmbeddedBitmapResourceByID(It.IsAny<int>(), It.IsAny<int>()), Times.Once());
peFileMock.Verify(x => x.GetEmbeddedBitmapResourceByID(It.IsAny<int>(), ExpectedBitmapVersion, ExpectedCulture), Times.Once());
}

[Test]
Expand All @@ -45,7 +48,7 @@ public void WhenLoadGFX_CallsPEFile_WithResourceValueIncreasedBy100()
using (var bmp = _nativeGraphicsLoader.LoadGFX(GFXTypes.PreLoginUI, requestedResourceID))
bmp.Dispose(); //hide warning for empty using statement

peFileMock.Verify(x => x.GetEmbeddedBitmapResourceByID(expectedResourceID, It.IsAny<int>()));
peFileMock.Verify(x => x.GetEmbeddedBitmapResourceByID(expectedResourceID, ExpectedBitmapVersion, ExpectedCulture));
}

[Test]
Expand Down Expand Up @@ -78,7 +81,7 @@ private Mock<IPEFile> SetupPEFileForGFXType(GFXTypes type, byte[] array)
var peFile = new Mock<IPEFile>();
collectionMock.Setup(x => x[type]).Returns(peFile.Object);

peFile.Setup(x => x.GetEmbeddedBitmapResourceByID(It.IsAny<int>(), It.IsAny<int>()))
peFile.Setup(x => x.GetEmbeddedBitmapResourceByID(It.IsAny<int>(), ExpectedBitmapVersion, ExpectedCulture))
.Returns(array);

return peFile;
Expand Down
5 changes: 4 additions & 1 deletion EOLib.Graphics/EOLib.Graphics.csproj
Expand Up @@ -13,9 +13,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutomaticTypeMapper" Version="1.4.1" />
<PackageReference Include="PELoaderLib" Version="1.1.1" />
<PackageReference Include="PELoaderLib" Version="1.2.0" />
<PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.0.0" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta14" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EOLib.Config\EOLib.Config.csproj" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion EOLib.Graphics/INativeGraphicsLoader.cs
@@ -1,4 +1,5 @@
using SixLabors.ImageSharp;
using PELoaderLib;
using SixLabors.ImageSharp;

namespace EOLib.Graphics
{
Expand Down
13 changes: 11 additions & 2 deletions EOLib.Graphics/NativeGraphicsLoader.cs
@@ -1,21 +1,30 @@
using AutomaticTypeMapper;
using EOLib.Config;
using PELoaderLib;
using SixLabors.ImageSharp;

namespace EOLib.Graphics
{
[MappedType(BaseType = typeof(INativeGraphicsLoader), IsSingleton = true)]
public class NativeGraphicsLoader : INativeGraphicsLoader
{
private const int CULTURE_EN_US = 1033;

private readonly IPEFileCollection _modules;
private readonly IConfigurationProvider _configurationProvider;

public NativeGraphicsLoader(IPEFileCollection modules)
public NativeGraphicsLoader(IPEFileCollection modules,
IConfigurationProvider configurationProvider)
{
_modules = modules;
_configurationProvider = configurationProvider;
}

public IImage LoadGFX(GFXTypes file, int resourceValue)
{
var fileBytes = _modules[file].GetEmbeddedBitmapResourceByID(resourceValue + 100);
var version = _configurationProvider.MainCloneCompat ? BitmapVersion.BitmapV3InfoHeader : BitmapVersion.BitmapInfoHeader;
var culture = _configurationProvider.MainCloneCompat ? CULTURE_EN_US : 0;
var fileBytes = _modules[file].GetEmbeddedBitmapResourceByID(resourceValue + 100, version, culture);

if (fileBytes.Length == 0)
throw new GFXLoadException(resourceValue, file);
Expand Down
5 changes: 5 additions & 0 deletions EndlessClient/GameExecution/GameRunnerBase.cs
Expand Up @@ -75,6 +75,11 @@ public virtual bool SetupDependencies()

i++;
}
else if(string.Equals(arg, "--clonecompat"))
{
_registry.Resolve<IConfigurationRepository>()
.MainCloneCompat = true;
}
else
{
Debug.WriteLine($"Unrecognized argument: {arg}. Will be ignored.");
Expand Down

0 comments on commit 4e0b1f2

Please sign in to comment.