Files
ZuneModdingHelper/ZuneModCore/Mods/VideoSyncMod.cs
T

93 lines
3.4 KiB
C#
Raw Normal View History

using System;
2021-04-25 22:59:36 -05:00
using System.Collections.Generic;
using System.Diagnostics;
2021-04-25 22:59:36 -05:00
using System.IO;
using System.Threading.Tasks;
2024-05-20 21:53:52 -05:00
namespace ZuneModCore.Mods;
public class VideoSyncMod : Mod
2021-04-25 22:59:36 -05:00
{
2024-05-20 21:53:52 -05:00
private const int ZUNEENCENG_WMVCORA_OFFSET = 0x161E;
private const string Description =
2024-05-20 21:53:52 -05:00
"Resolves \"Error C00D11CD\" when attempting to sync video to a Zune device using Windows 10 1607 (Anniversary Update) or newer";
private const string Author = "sylvathemoth";
2024-05-20 21:53:52 -05:00
public override ModMetadata Metadata => new(nameof(VideoSyncMod), "Fix Video Sync", Description, Author);
2024-05-20 21:53:52 -05:00
public override async Task<string?> Apply()
2021-04-25 22:59:36 -05:00
{
2024-05-20 21:53:52 -05:00
// Verify that ZuneEncEng.dll exists
FileInfo zeeDllInfo = new(Path.Combine(ZuneInstallDir, "ZuneEncEng.dll"));
if (!zeeDllInfo.Exists)
return $"The file '{zeeDllInfo.FullName}' does not exist.";
2024-05-20 21:53:52 -05:00
// Make a backup if it doesn't already exist
FileInfo zeeDllBackupInfo = new(Path.Combine(StorageDirectory, "ZuneEncEng.original.dll"));
if (!zeeDllBackupInfo.Exists)
File.Copy(zeeDllInfo.FullName, zeeDllBackupInfo.FullName, true);
2021-04-25 22:59:36 -05:00
2024-05-20 21:53:52 -05:00
try
2021-04-25 22:59:36 -05:00
{
2024-05-20 21:53:52 -05:00
// Verify that the DLL is from v4.8 (other versions not tested)
var zeeDllVersion = FileVersionInfo.GetVersionInfo(zeeDllInfo.FullName);
if (zeeDllVersion is null || zeeDllVersion.FileMajorPart != 4 || zeeDllVersion.FileMinorPart != 8)
return "This mod has not been tested on versions earlier than 4.8.";
2021-05-26 11:32:53 -05:00
2024-05-20 21:53:52 -05:00
// Open the file
using (FileStream zeeDll = zeeDllInfo.Open(FileMode.Open))
using (BinaryWriter zeeDllWriter = new(zeeDll))
{
2024-05-20 21:53:52 -05:00
// Patch ZuneEncEng.dll to point to the local WMVCORE.DLL
zeeDllWriter.Seek(ZUNEENCENG_WMVCORA_OFFSET, SeekOrigin.Begin);
zeeDllWriter.Write((byte)'a');
2021-05-06 05:06:43 -05:00
2024-05-20 21:53:52 -05:00
zeeDllWriter.Flush();
}
2024-05-20 21:53:52 -05:00
// Get the working WMVCORE.dll
byte[] wmvDllAniv = ModResources.WMVCORE;
// Copy the WMVCore files to the Zune directory.
// Only ZuneEncEng.dll searches in System32 first; all other dependent
// DLLs will search the Zune folder.
await File.WriteAllBytesAsync(Path.Combine(ZuneInstallDir, "wmvcora.dll"), wmvDllAniv);
await File.WriteAllBytesAsync(Path.Combine(ZuneInstallDir, "wmvcore.dll"), wmvDllAniv);
return null;
2021-04-25 22:59:36 -05:00
}
2024-05-20 21:53:52 -05:00
catch (IOException)
2021-04-25 22:59:36 -05:00
{
2024-05-20 21:53:52 -05:00
return $"Unable to replace '{zeeDllInfo.FullName}'. Verify that the Zune software is not running and try again.";
}
catch (Exception ex)
{
return ex.Message;
2021-04-25 22:59:36 -05:00
}
}
2024-05-20 21:53:52 -05:00
public override Task<string?> Reset()
{
var zeeDllPath = Path.Combine(ZuneInstallDir, "ZuneEncEng.dll");
try
{
// Copy backup to application folder
File.Copy(Path.Combine(StorageDirectory, "ZuneEncEng.original.dll"), zeeDllPath, true);
// Delete WMVCore files
File.Delete(Path.Combine(ZuneInstallDir, "wmvcora.dll"));
File.Delete(Path.Combine(ZuneInstallDir, "wmvcore.dll"));
return Task.FromResult<string?>(null);
}
catch (Exception ex)
{
return Task.FromResult(ex.Message)!;
}
}
public override IReadOnlyList<Type>? DependentMods => null;
2021-04-25 22:59:36 -05:00
}