1- using OwlCore . AbstractUI . Models ;
2- using System ;
1+ using System ;
32using System . Collections . Generic ;
43using System . Diagnostics ;
54using System . IO ;
6- using System . Security . AccessControl ;
7- using System . Security . Principal ;
85using System . Threading . Tasks ;
9- using ZuneModCore . Win32 ;
106
117namespace ZuneModCore . Mods
128{
139 public class VideoSyncMod : Mod
1410 {
15- private readonly string WMVCORE_PATH = Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . System ) , "WMVCORE.dll" ) ;
11+ private const int ZUNEENCENG_WMVCORA_OFFSET = 0x161E ;
1612
1713 public override string Title => "Fix Video Sync" ;
1814
1915 public override string Description =>
2016 "Resolves \" Error C00D11CD\" when attempting to sync video to a Zune device using Windows 10 1607 (Anniversary Update) or newer" ;
2117
22- public override string Author => "ส็็็Codix#4833 " ;
18+ public override string Author => "sylvathemoth " ;
2319
2420 public override string Id => nameof ( VideoSyncMod ) ;
2521
2622 public override async Task < string ? > Apply ( )
2723 {
28- // Make a backup of the original file
29- FileVersionInfo wmvDllVersionInfo = FileVersionInfo . GetVersionInfo ( WMVCORE_PATH ) ;
30- if ( Version . Parse ( wmvDllVersionInfo . ProductVersion ! ) != new Version ( 12 , 0 , 10586 , 0 ) )
31- File . Copy ( WMVCORE_PATH , Path . Combine ( StorageDirectory , "WMVCORE.original.dll" ) , true ) ;
24+ // Verify that ZuneEncEng.dll exists
25+ FileInfo zeeDllInfo = new ( Path . Combine ( ZuneInstallDir , "ZuneEncEng.dll" ) ) ;
26+ if ( ! zeeDllInfo . Exists )
27+ return $ "The file ' { zeeDllInfo . FullName } ' does not exist." ;
3228
33- // Get the working WMVCORE.dll
34- byte [ ] wmvDllAniv = ModResources . WMVCORE ;
35-
36- // Get the original WMVCORE.dll
37- FileInfo wmvDllInfo = new ( WMVCORE_PATH ) ;
29+ // Make a backup if it doesn't already exist
30+ FileInfo zeeDllBackupInfo = new ( Path . Combine ( StorageDirectory , "ZuneEncEng.original.dll" ) ) ;
31+ if ( ! zeeDllBackupInfo . Exists )
32+ File . Copy ( zeeDllInfo . FullName , zeeDllBackupInfo . FullName , true ) ;
3833
3934 try
4035 {
41- // Take ownership of DLL
42- TokenManipulator . TakeOwnership ( wmvDllInfo ) ;
36+ // Verify that the DLL is from v4.8 (other versions not tested)
37+ var zeeDllVersion = FileVersionInfo . GetVersionInfo ( zeeDllInfo . FullName ) ;
38+ if ( zeeDllVersion is null || zeeDllVersion . FileMajorPart != 4 || zeeDllVersion . FileMinorPart != 8 )
39+ return "This mod has not been tested on versions earlier than 4.8." ;
40+
41+ // Open the file
42+ using ( FileStream zeeDll = zeeDllInfo . Open ( FileMode . Open ) )
43+ using ( BinaryWriter zeeDllWriter = new ( zeeDll ) )
44+ {
45+ // Patch ZuneEncEng.dll to point to the local WMVCORE.DLL
46+ zeeDllWriter . Seek ( ZUNEENCENG_WMVCORA_OFFSET , SeekOrigin . Begin ) ;
47+ zeeDllWriter . Write ( ( byte ) 'a' ) ;
48+
49+ zeeDllWriter . Flush ( ) ;
50+ }
4351
44- // Replace with pre-Anniversary Update WMVCORE.dll
45- await File . WriteAllBytesAsync ( wmvDllInfo . FullName , wmvDllAniv ) ;
52+ // Get the working WMVCORE.dll
53+ byte [ ] wmvDllAniv = ModResources . WMVCORE ;
54+
55+ // Copy the WMVCore files to the Zune directory.
56+ // Only ZuneEncEng.dll searches in System32 first; all other dependent
57+ // DLLs will search the Zune folder.
58+ await File . WriteAllBytesAsync ( Path . Combine ( ZuneInstallDir , "wmvcora.dll" ) , wmvDllAniv ) ;
59+ await File . WriteAllBytesAsync ( Path . Combine ( ZuneInstallDir , "wmvcore.dll" ) , wmvDllAniv ) ;
4660
4761 return null ;
4862 }
4963 catch ( IOException )
5064 {
51- return $ "Unable to replace '{ wmvDllInfo . FullName } '. Verify that Zune and Windows Media Player are not running and try again.";
65+ return $ "Unable to replace '{ zeeDllInfo . FullName } '. Verify that the Zune software is not running and try again.";
5266 }
5367 catch ( Exception ex )
5468 {
@@ -58,10 +72,15 @@ public class VideoSyncMod : Mod
5872
5973 public override Task < string ? > Reset ( )
6074 {
75+ var zeeDllPath = Path . Combine ( ZuneInstallDir , "ZuneEncEng.dll" ) ;
6176 try
6277 {
6378 // Copy backup to application folder
64- File . Copy ( Path . Combine ( StorageDirectory , "WMVCORE.original.dll" ) , WMVCORE_PATH , true ) ;
79+ File . Copy ( Path . Combine ( StorageDirectory , "ZuneEncEng.original.dll" ) , zeeDllPath , true ) ;
80+
81+ // Delete WMVCore files
82+ File . Delete ( Path . Combine ( ZuneInstallDir , "wmvcora.dll" ) ) ;
83+ File . Delete ( Path . Combine ( ZuneInstallDir , "wmvcore.dll" ) ) ;
6584
6685 return Task . FromResult < string ? > ( null ) ;
6786 }
0 commit comments