Skip to content

Commit

Permalink
Workaround for LiveSplit auto-updater bug: Embed hooks DLL in compone…
Browse files Browse the repository at this point in the history
…nt DLL.
  • Loading branch information
Fatalis committed Aug 14, 2014
1 parent 3ddfc6a commit 782c785
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 3 deletions.
3 changes: 3 additions & 0 deletions LiveSplit.MirrorsEdge.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 12.0.30110.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveSplit.MirrorsEdgeNoLoads", "LiveSplit.MirrorsEdge\LiveSplit.MirrorsEdgeNoLoads.csproj", "{6F40899A-6B45-4827-A3E7-1344DA09C4B8}"
ProjectSection(ProjectDependencies) = postProject
{0595D913-5F62-4D51-928C-8742CDE2F243} = {0595D913-5F62-4D51-928C-8742CDE2F243}
EndProjectSection
EndProject
Project("{002A2DE9-8BB6-484D-9802-7E4AD4084715}") = "menl_hooks", "menl_hooks\menl_hooks.visualdproj", "{0595D913-5F62-4D51-928C-8742CDE2F243}"
EndProject
Expand Down
2 changes: 1 addition & 1 deletion LiveSplit.MirrorsEdge/GameProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GameProcess

private Task _thread;
private CancellationTokenSource _cancelSource;
private const string GAMEDLL = "menl_hooks.dll";
public const string GAMEDLL = "menl_hooks.dll";
private const string PIPE_NAME = "LiveSplit.MirrorsEdge";
private bool _pipeConnected;

Expand Down
11 changes: 11 additions & 0 deletions LiveSplit.MirrorsEdge/LiveSplit.MirrorsEdgeNoLoads.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,19 @@
<Compile Include="MirrorsEdgeComponent.cs" />
<Compile Include="MirrorsEdgeFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="SafeNativeMethods.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
43 changes: 41 additions & 2 deletions LiveSplit.MirrorsEdge/MirrorsEdgeComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using LiveSplit.Model;
using System.IO;
using System.Security.Cryptography;
using LiveSplit.Model;
using LiveSplit.TimeFormatters;
using LiveSplit.UI.Components;
using LiveSplit.UI;
Expand Down Expand Up @@ -26,9 +28,11 @@ public string ComponentName

public MirrorsEdgeComponent(LiveSplitState state)
{
this.ExtractGameHooksDLL();

this.ContextMenuControls = new Dictionary<String, Action>();

this.InternalComponent = new InfoTimeComponent("Without Loads", null, new RegularTimeFormatter(TimeAccuracy.Hundredths));
this.InternalComponent = new InfoTimeComponent(null, null, new RegularTimeFormatter(TimeAccuracy.Hundredths));

_cache = new GraphicsCache();

Expand All @@ -46,6 +50,41 @@ public void Dispose()
_gameProcess.Stop();
}

public void ExtractGameHooksDLL()
{
// if an IO exception is thrown anywhere in here, the component will fail to load. this is intended.

string path = Path.Combine("Components", GameProcess.GAMEDLL);
if (!File.Exists(path))
{
File.WriteAllBytes(path, Properties.Resources.menl_hooks);
return;
}

byte[] installedVersion = File.ReadAllBytes(path);
using (var md5 = new MD5CryptoServiceProvider())
{
string installedVersionHash = Convert.ToBase64String(md5.ComputeHash(installedVersion));
string currentVersionHash = Convert.ToBase64String(md5.ComputeHash(Properties.Resources.menl_hooks));

if (installedVersionHash != currentVersionHash)
{
retry: // ?v=fiVr34QCF_c
try
{
File.WriteAllBytes(path, Properties.Resources.menl_hooks);
}
catch (IOException)
{
if (DialogResult.Retry ==
MessageBox.Show("Couldn't update " + GameProcess.GAMEDLL + "! Close the game and click Retry.", "Error",
MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning))
goto retry;
}
}
}
}

public void Update(IInvalidator invalidator, LiveSplitState state, float width, float height, LayoutMode mode)
{
this.InternalComponent.TimeValue =
Expand Down
73 changes: 73 additions & 0 deletions LiveSplit.MirrorsEdge/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions LiveSplit.MirrorsEdge/Properties/Resources.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="menl_hooks" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\..\bin\menl_hooks.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

0 comments on commit 782c785

Please sign in to comment.