rm-NoobInCoding / UnrealReZen

UnrealReZen is a modding tool for packing utoc and ucas files (Unreal Engine Zen Loader archive files)
GNU General Public License v3.0
106 stars 10 forks source link

new error "cannot create a file when that file already exists" #23

Closed Datura123 closed 1 month ago

Datura123 commented 1 year ago

Thank @rm-NoobInCoding for fix B03, but it appeared another error the new version B04

Untitled 5677- Copy

Datura123 commented 1 year ago

In the old version B03, this error is not encountered

rm-NoobInCoding commented 1 year ago

Please click on Details and send its text

Datura123 commented 1 year ago

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IO.IOException: Cannot create a file when that file already exists.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateCore(SafeFileHandle fileHandle, String mapName, HandleInheritability inheritability, MemoryMappedFileSecurity memoryMappedFileSecurity, MemoryMappedFileAccess access, MemoryMappedFileOptions options, Int64 capacity)
   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile(String path, FileMode mode, String mapName, Int64 capacity, MemoryMappedFileAccess access)
   at System.IO.MemoryMappedFiles.MemoryMappedFile.CreateFromFile(String path, FileMode mode, String mapName)
   at UEcastocLib.Packer.PackFilesToUcas(List`1 files, Manifest m, String dir, String outFilename, String compression) in C:\Users\PCMOD\source\repos\rm-NoobInCoding\UnrealUnZen\UnrealUnZen\UEcastocLib\Pack.cs:line 133
   at UEcastocLib.Packer.PackToCasToc(String dir, Manifest m, String outFilename, String compression, Byte[] aes) in C:\Users\PCMOD\source\repos\rm-NoobInCoding\UnrealUnZen\UnrealUnZen\UEcastocLib\Pack.cs:line 422
   at UEcastocLib.Packer.PackGameFiles(String dirPath, Manifest manifest, String outFile, String compressionMethod, String AESKey) in C:\Users\PCMOD\source\repos\rm-NoobInCoding\UnrealUnZen\UnrealUnZen\UEcastocLib\Pack.cs:line 48
   at UnrealUnZen.MainTool.RepackBTN_Click(Object sender, EventArgs e) in C:\Users\PCMOD\source\repos\rm-NoobInCoding\UnrealUnZen\UnrealUnZen\MainTool.cs:line 93
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Datura123 commented 1 year ago

I tried deleting the file with the same name and it worked

If there are 2 files with the same name in that common folder, it will encounter an error, for example: DroidSansMono.uasset

"Engine/Content/EngineFonts/Faces/DroidSansMono.uasset", "Engine/Content/EngineFonts/DroidSansMono.uasset"

KulaGGin commented 11 months ago

I tried deleting the file with the same name and it worked

If there are 2 files with the same name in that common folder, it will encounter an error, for example: DroidSansMono.uasset

"Engine/Content/EngineFonts/Faces/DroidSansMono.uasset", "Engine/Content/EngineFonts/DroidSansMono.uasset"

This is definitely a bug. It's totally possible to have a lot of files with the same name in the same package. For example: UnrealUnZen_SLQkDeMzxB

And there is no deleting the files for me. I just checked, I have 5980 duplicated files.

KulaGGin commented 11 months ago

This issue is happening because of the line:

MemoryMappedFile = MemoryMappedFile.CreateFromFile(pathToread, FileMode.Open, Path.GetFileNameWithoutExtension(pathToread));

In pack.cs#L133. This is happening is because you're calling MemoryMappedFile.CreateFromFile overload with mapName: you're creating a MemoryMappedFile and assigning it a mapName for a file. And so you can't have a file with the same mapName loaded twice in the memory. The quick fix is to use a different overload and just not pass the mapName to CreateFromFile function:

MemoryMappedFile = MemoryMappedFile.CreateFromFile(pathToread, FileMode.Open);

This fixes the bug: I packed 51000 files with 5980 files with duplicated names. But why are you even using MemoryMappedFile? MemoryMappedFile is made for big heavy files, so the file can be shared across running processes and wouldn't have to be loaded twice into each process. It's useless for this kind of a use case where you have one process just iterating over a bunch of files, reading them into memory, then archiving them and then forgetting about them, all without using them even twice around the program. In fact, it's using more memory than a simple Stream, because it's a much more complex type than a simple Stream. Just use File.Open.

KulaGGin commented 11 months ago

Created pull request with the fix. And before the official release is created, here's the zip of program with the fix: UnrealUnZen.zip

Datura123 commented 11 months ago

Created pull request with the fix. And before the official release is created, here's the zip of program with the fix: UnrealUnZen.zip

sorry but, it can't repack over 2GB file image

KulaGGin commented 11 months ago

sorry but, it can't repack over 2GB file

Right. That's why MemoryMappedFile was used. Try this one then: UnrealUnZen.zip

Datura123 commented 11 months ago

I tried this, it still doesn't work

sorry but, it can't repack over 2GB file

Right. That's why MemoryMappedFile was used. Try this one then: UnrealUnZen.zip

I tried this, it still doesn't work. can't repack over 2GB file

KulaGGin commented 11 months ago

I tried this, it still doesn't work. can't repack over 2GB file

I think I might have zipped this last version before I built the solution after going back one commit where there is no issue with over 2 GB files. That's my bad.

Try again: UnrealUnZen.zip

Yesterday I unpacked and then packed back two 11 GB packages after fixing this problem with "cannot create a file when that file already exists".

Datura123 commented 11 months ago

I think I might have zipped this last version before I built the solution after going back one commit where there is no issue with over 2 GB files. That's my bad.

Try again: UnrealUnZen.zip

Yesterday I unpacked and then packed back two 11 GB packages after fixing this problem with "cannot create a file when that file already exists".

Unfortunately, I tried many times, it still cannot repack over 2 GB file, I used oodle compression, maybe this compression method doesn't work?


Here Details:

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.IO.IOException: The file is too long. This operation is currently limited to supporting files less than 2 gigabytes in size.
   at System.IO.File.InternalReadAllBytes(String path, Boolean checkHost)
   at UEcastocLib.Packer.PackToCasToc(String dir, Manifest m, String outFilename, String compression, Byte[] aes) in D:\Projects\Reversing\UE4\UnrealUnZen\UnrealUnZen\UEcastocLib\Pack.cs:line 424
   at UEcastocLib.Packer.PackGameFiles(String dirPath, Manifest manifest, String outFile, String compressionMethod, String AESKey) in D:\Projects\Reversing\UE4\UnrealUnZen\UnrealUnZen\UEcastocLib\Pack.cs:line 48
   at UnrealUnZen.MainTool.RepackBTN_Click(Object sender, EventArgs e) in D:\Projects\Reversing\UE4\UnrealUnZen\UnrealUnZen\MainTool.cs:line 93
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
xjgames commented 11 months ago

我尝试了这个,仍然不起作用。无法重新打包超过 2GB 的文件

我想在返回一次提交(其中超过 2 GB 文件没有问题)之后构建解决方案之前,我可能已经压缩了最后一个版本。那是我的不好。

再试一次:UnrealUnZen.zip

昨天,在解决“当文件已存在时无法创建文件”的问题后,我解压并打包了两个 11 GB 的包。

cannot repack over 2 GB file

KulaGGin commented 11 months ago

Ok, I've now implemented some fixes for the problems with packing more than 2 GB files. The previous versions I posted only included the fix for "cannot create a file when that file already exists" error.

Try it out and let me know if it works: UnrealUnZen.zip

I've just now packed 2.5 GB .ucas with encryption enabled this time.

Datura123 commented 11 months ago

Ok, I've now implemented some fixes for the problems with packing more than 2 GB files. The previous versions I posted only included the fix for "cannot create a file when that file already exists" error.

Try it out and let me know if it works: UnrealUnZen.zip

I've just now packed 2.5 GB .ucas with encryption enabled this time.

thank you, it worked! image

xjgames commented 11 months ago

1701169522822 The packed utoc cannot be opened

rm-NoobInCoding commented 11 months ago

Did you define AES KEY in FModel?

xjgames commented 11 months ago

9683d4e51d17ba78699ad35897a48eb yes

xjgames commented 11 months ago

Game Name Dead Island 2 AES KEY =0x014AEC0148FBDEE9640633AAB67521AAB4E1083A98F76FF33DDCF78DAD05BE66

rm-NoobInCoding commented 11 months ago

Can you send repacked Toc file?

xjgames commented 11 months ago

toc.zip