From b5ad5116718edc74dbddc9390dc93b4cdabb881a Mon Sep 17 00:00:00 2001
From: Kevin Caccamo <kevin@ciinet.org>
Date: Mon, 2 Sep 2019 03:06:33 -0400
Subject: [PATCH] Enable DevIL on Linux

Remove NO_DEVIL defines, and add devil.dll -> libIL.so.1 DLL mapping to app.config
---
 Build/Builder.exe.config          | 45 ++++++++++++++++++++++++++++---
 Source/Core/BuilderMono.csproj    | 16 +++++------
 Source/Core/General/General.cs    |  5 +---
 Source/Core/IO/FileImageReader.cs | 39 ---------------------------
 Source/Core/app.config            |  1 +
 5 files changed, 51 insertions(+), 55 deletions(-)

diff --git a/Build/Builder.exe.config b/Build/Builder.exe.config
index d82da5de3..c902dd541 100755
--- a/Build/Builder.exe.config
+++ b/Build/Builder.exe.config
@@ -1,9 +1,46 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="utf-8"?>
 <configuration>
   <startup useLegacyV2RuntimeActivationPolicy="true">
-    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
+    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
   </startup>
   <runtime>
-    <loadFromRemoteSources enabled="true"/>
+    <loadFromRemoteSources enabled="true" />
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="mscorlib" publicKeyToken="b77a5c561934e089" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System" publicKeyToken="b77a5c561934e089" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Data" publicKeyToken="b77a5c561934e089" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Design" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Drawing" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="System.Windows.Forms" publicKeyToken="b77a5c561934e089" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
+      </dependentAssembly>
+    </assemblyBinding>
   </runtime>
-</configuration>
+  <dllmap dll="devil.dll" target="libIL.so.1" os="linux" />
+</configuration>
\ No newline at end of file
diff --git a/Source/Core/BuilderMono.csproj b/Source/Core/BuilderMono.csproj
index 386ed3352..da5183ad5 100644
--- a/Source/Core/BuilderMono.csproj
+++ b/Source/Core/BuilderMono.csproj
@@ -27,7 +27,7 @@
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     <DebugSymbols>true</DebugSymbols>
     <OutputPath>..\..\Build\</OutputPath>
-    <DefineConstants>TRACE;DEBUG;NO_SCINTILLA NO_FORMS_DESIGN NO_DEVIL NO_WIN32 NO_UPDATER</DefineConstants>
+    <DefineConstants>TRACE;DEBUG;NO_SCINTILLA NO_FORMS_DESIGN NO_WIN32 NO_UPDATER</DefineConstants>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <DebugType>full</DebugType>
     <PlatformTarget>x86</PlatformTarget>
@@ -48,7 +48,7 @@
     <ErrorReport>prompt</ErrorReport>
     <DocumentationFile>
     </DocumentationFile>
-    <DefineConstants>NO_SCINTILLA NO_FORMS_DESIGN NO_DEVIL NO_WIN32 NO_UPDATER</DefineConstants>
+    <DefineConstants>NO_SCINTILLA NO_FORMS_DESIGN NO_WIN32 NO_UPDATER</DefineConstants>
     <WarningLevel>4</WarningLevel>
     <DebugSymbols>true</DebugSymbols>
     <NoWarn>1591</NoWarn>
@@ -57,7 +57,7 @@
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug + Profiler|x86' ">
     <DebugSymbols>true</DebugSymbols>
     <OutputPath>..\..\Build\</OutputPath>
-    <DefineConstants>TRACE;DEBUG;PROFILE NO_SCINTILLA NO_FORMS_DESIGN NO_DEVIL NO_WIN32 NO_UPDATER</DefineConstants>
+    <DefineConstants>TRACE;DEBUG;PROFILE NO_SCINTILLA NO_FORMS_DESIGN NO_WIN32 NO_UPDATER</DefineConstants>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <DocumentationFile>
     </DocumentationFile>
@@ -79,7 +79,7 @@
     <PlatformTarget>x86</PlatformTarget>
     <UseVSHostingProcess>false</UseVSHostingProcess>
     <ErrorReport>prompt</ErrorReport>
-    <DefineConstants>TRACE;PROFILE NO_SCINTILLA NO_FORMS_DESIGN NO_DEVIL NO_WIN32 NO_UPDATER</DefineConstants>
+    <DefineConstants>TRACE;PROFILE NO_SCINTILLA NO_FORMS_DESIGN NO_WIN32 NO_UPDATER</DefineConstants>
     <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
@@ -89,7 +89,7 @@
     </DocumentationFile>
     <Prefer32Bit>false</Prefer32Bit>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-    <DefineConstants>TRACE;DEBUG;NO_SCINTILLA NO_FORMS_DESIGN NO_DEVIL NO_WIN32 NO_UPDATER</DefineConstants>
+    <DefineConstants>TRACE;DEBUG;NO_SCINTILLA NO_FORMS_DESIGN NO_WIN32 NO_UPDATER</DefineConstants>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
     <PlatformTarget>x64</PlatformTarget>
@@ -97,14 +97,14 @@
     <Prefer32Bit>false</Prefer32Bit>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <Optimize>true</Optimize>
-    <DefineConstants>TRACE;NO_SCINTILLA NO_FORMS_DESIGN NO_DEVIL NO_WIN32 NO_UPDATER</DefineConstants>
+    <DefineConstants>TRACE;NO_SCINTILLA NO_FORMS_DESIGN NO_WIN32 NO_UPDATER</DefineConstants>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug + Profiler|x64'">
     <PlatformTarget>x64</PlatformTarget>
     <OutputPath>..\..\Build\</OutputPath>
     <Prefer32Bit>false</Prefer32Bit>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-    <DefineConstants>TRACE;DEBUG;PROFILE NO_SCINTILLA NO_FORMS_DESIGN NO_DEVIL NO_WIN32 NO_UPDATER</DefineConstants>
+    <DefineConstants>TRACE;DEBUG;PROFILE NO_SCINTILLA NO_FORMS_DESIGN NO_WIN32 NO_UPDATER</DefineConstants>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release + Profiler|x64'">
     <PlatformTarget>x64</PlatformTarget>
@@ -112,7 +112,7 @@
     <Prefer32Bit>false</Prefer32Bit>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <Optimize>true</Optimize>
-    <DefineConstants>PROFILE NO_SCINTILLA NO_FORMS_DESIGN NO_DEVIL NO_WIN32 NO_UPDATER</DefineConstants>
+    <DefineConstants>PROFILE NO_SCINTILLA NO_FORMS_DESIGN NO_WIN32 NO_UPDATER</DefineConstants>
   </PropertyGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
diff --git a/Source/Core/General/General.cs b/Source/Core/General/General.cs
index 7493e3510..41e7d20dd 100755
--- a/Source/Core/General/General.cs
+++ b/Source/Core/General/General.cs
@@ -49,10 +49,8 @@ namespace CodeImp.DoomBuilder
 	{
         #region ================== API Declarations
 
-#if !NO_DEVIL
         [DllImport("devil.dll")]
 		private static extern void ilInit();
-#endif
 
 #if NO_WIN32
 
@@ -628,9 +626,8 @@ namespace CodeImp.DoomBuilder
 
 				// Initialize static classes
 				MapSet.Initialize();
-#if !NO_DEVIL
+
 				ilInit();
-#endif
 
 				// Create main window
 				General.WriteLogLine("Loading main interface window...");
diff --git a/Source/Core/IO/FileImageReader.cs b/Source/Core/IO/FileImageReader.cs
index 9f8753329..2170c6957 100755
--- a/Source/Core/IO/FileImageReader.cs
+++ b/Source/Core/IO/FileImageReader.cs
@@ -43,43 +43,6 @@ namespace CodeImp.DoomBuilder.IO
 		internal const int IL_DDS = 0x0437;  //!< DirectDraw Surface - .dds extension
 	}
 
-#if NO_DEVIL
-
-    internal unsafe class FileImageReader : IImageReader
-    {
-		public FileImageReader()
-		{
-			//imagetype = DevilImageType.IL_TYPE_UNKNOWN;
-		}
-
-		public FileImageReader(uint devilImagetype) 
-		{
-		}
-
-        public FileImageReader(uint devilImagetype, int guesstype, Playpal guesspalette)
-        {
-        }
-
-        public Bitmap ReadAsBitmap(Stream stream)
-        {
-            int x, y;
-            return ReadAsBitmap(stream, out x, out y);
-        }
-
-        public Bitmap ReadAsBitmap(Stream stream, out int offsetx, out int offsety)
-        {
-            offsetx = 0;
-            offsety = 0;
-            return new Bitmap(64, 64, PixelFormat.Format32bppArgb);
-        }
-
-        public void DrawToPixelData(Stream stream, PixelColor* target, int targetwidth, int targetheight, int x, int y)
-        {
-        }
-    }
-
-#else
-
     // [ZZ]
     internal enum DevilError
     {
@@ -722,6 +685,4 @@ namespace CodeImp.DoomBuilder.IO
 		
 #endregion
 	}
-
-#endif
 }
diff --git a/Source/Core/app.config b/Source/Core/app.config
index d82da5de3..de20aa9a9 100644
--- a/Source/Core/app.config
+++ b/Source/Core/app.config
@@ -6,4 +6,5 @@
   <runtime>
     <loadFromRemoteSources enabled="true"/>
   </runtime>
+  <dllmap dll="devil.dll" target="libIL.so.1" os="linux" />
 </configuration>
-- 
GitLab