Skip to content

Commit

Permalink
Merge pull request #11 from UlyssesWu/feature/tlg, Fix #9
Browse files Browse the repository at this point in the history
Add TLG encoding plugin, Fix #9
  • Loading branch information
UlyssesWu authored Jul 14, 2018
2 parents 14ef2b8 + 1d99564 commit 2887989
Show file tree
Hide file tree
Showing 21 changed files with 500 additions and 127 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,4 @@ paket-files/
/FreeMote.Tests/Res
/FreeMote.Tests/PurifyTest.cs

/MigrationBackup
53 changes: 53 additions & 0 deletions FreeMote.Plugins/FreeMote.Plugins.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F37472B9-6501-440E-8898-7774304F7FEC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FreeMote.Plugins</RootNamespace>
<AssemblyName>FreeMote.Plugins</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TlgPlugin.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dynamitey">
<Version>2.0.9.136</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions FreeMote.Plugins/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("FreeMote.Plugins")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Project AZUSA")]
[assembly: AssemblyProduct("FreeMote")]
[assembly: AssemblyCopyright("Copyright © Ulysses 2018")]
[assembly: AssemblyTrademark("[email protected]")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("f37472b9-6501-440e-8898-7774304f7fec")]

// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]
115 changes: 115 additions & 0 deletions FreeMote.Plugins/TlgPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using Dynamitey.DynamicObjects;

namespace FreeMote.Plugins
{
/// <summary>
/// FreeMote.Tlg
/// <para>Native TLG Plugin</para>
/// </summary>
public static class TlgPlugin
{
private static bool _isEnabled = true;

/// <summary>
/// Is plugin enabled
/// </summary>
public static bool IsEnabled
{
get => IsReady && _isEnabled;
set
{
if (IsReady)
{
_isEnabled = value;
}
}
}

/// <summary>
/// Is plugin loaded
/// </summary>
public static bool IsReady { get; private set; } = false;
private const string PluginPath = "TlgLib.dll";
private static dynamic TlgNative = null;
//private static dynamic TlgLoader = null;
static TlgPlugin()
{
IsReady = false;

if (Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix)
{
return;
}

var path = Path.GetFullPath(PluginPath);
if (!File.Exists(path))
{
try
{
path = Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ??
Environment.CurrentDirectory, PluginPath);
//Console.WriteLine(path);
}
catch (Exception)
{
// ignored
}

if (!File.Exists(path))
{
return;
}
}

try
{
var asm = Assembly.LoadFile(path);
TlgNative = new LateType(asm, "FreeMote.Tlg.TlgNative");
//TlgLoader = new LateType(asm, "FreeMote.Tlg.TlgLoader");
if (TlgNative.IsAvailable)
{
IsReady = true;
}
}
catch (Exception)
{
return;
}
}

/// <summary>
/// Save <see cref="Bitmap"/> as TLG
/// </summary>
/// <param name="bmp"></param>
/// <param name="tlg6">true: save as TLG6; false: save as TLG5</param>
/// <returns></returns>
public static byte[] SaveTlg(Bitmap bmp, bool tlg6 = false)
{
if (tlg6)
{
return TlgNative.ToTlg6(bmp);
}

return TlgNative.ToTlg5(bmp);
}

/// <summary>
/// Load TLG as <see cref="Bitmap"/>
/// </summary>
/// <param name="tlgBytes"></param>
/// <param name="version">get TLG version [5,6]</param>
/// <returns></returns>
public static Bitmap LoadTlg(byte[] tlgBytes, out int version)
{
//Impossible to call `TlgNative.ToBitmap(byte[], out int, bool = false)` because dynamic invoke can not call method with ref/out!
Tuple<Bitmap, int> tuple = TlgNative.ToBitmap(tlgBytes);
version = tuple.Item2;
return tuple.Item1;
}
}
}
9 changes: 7 additions & 2 deletions FreeMote.PsBuild/FreeMote.PsBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="TlgConverter.cs" />
<Compile Include="MmoCompiler.cs" />
<Compile Include="MmoGenerator.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -52,6 +53,10 @@
<Compile Include="Converters\Common2KrkrConverter.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FreeMote.Plugins\FreeMote.Plugins.csproj">
<Project>{F37472B9-6501-440E-8898-7774304F7FEC}</Project>
<Name>FreeMote.Plugins</Name>
</ProjectReference>
<ProjectReference Include="..\FreeMote.Psb\FreeMote.Psb.csproj">
<Project>{c0b2c2ff-d8f4-497e-8312-c2af1bb6e7f7}</Project>
<Name>FreeMote.Psb</Name>
Expand All @@ -63,10 +68,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>10.0.3</Version>
<Version>11.0.2</Version>
</PackageReference>
<PackageReference Include="System.ValueTuple">
<Version>4.4.0</Version>
<Version>4.5.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
4 changes: 2 additions & 2 deletions FreeMote.PsBuild/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
// 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.*")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.*")]
[assembly: AssemblyFileVersion("1.2.0.0")]
Loading

0 comments on commit 2887989

Please sign in to comment.