Skip to content

Commit

Permalink
Fix crash with non english characters (fr this time)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnimatedSwine37 committed May 31, 2024
1 parent c13a5bf commit c395e01
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion UtocEmulator/UTOC.Stream.Emulator/RustApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static class RustApi

[DllImport("fileemu_utoc_stream_emulator")]
public static extern bool BuildTableOfContentsEx(
string basePath, uint version, ref nint tocData, ref nint tocLength,
nint basePath, nint basePathLength, uint version, ref nint tocData, ref nint tocLength,
ref nint blocks, ref nint blockCount, ref nint header, ref nint headerSize
);
}
Expand Down
6 changes: 4 additions & 2 deletions UtocEmulator/UTOC.Stream.Emulator/UtocEmulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,12 @@ public void MakeFilesOnInit() // from base Unreal Essentials path
nint blockCount = 0;
nint headerPtr = 0;
nint headerSize = 0;
var result = RustApi.BuildTableOfContentsEx(
ModTargetFilesDirectory, (uint)TocVersion, ref tocData, ref tocLength,
nint mod_path_unicode = Marshal.StringToHGlobalUni(ModTargetFilesDirectory);
var result = RustApi.BuildTableOfContentsEx(mod_path_unicode, ModTargetFilesDirectory.Length
, (uint)TocVersion, ref tocData, ref tocLength,
ref blockPtr, ref blockCount, ref headerPtr, ref headerSize
);
Marshal.FreeHGlobal(mod_path_unicode);
if (!result)
{
_logger.Info($"[UtocEmulator] An error occurred while making IO Store data");
Expand Down
6 changes: 4 additions & 2 deletions UtocEmulator/fileemu-utoc-stream-emulator/src/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub unsafe extern "C" fn AddFromFolders(modPath: *const u16, modPathLength: usiz
// haiiii Reloaded!!!! :3
pub unsafe extern "C" fn BuildTableOfContentsEx(
// UTOC
basePath: *const c_char,
basePath: *const u16,
basePathLength: usize,
version: u32,
tocData: *mut *const u8,
tocLength: *mut u64,
Expand All @@ -30,7 +31,8 @@ pub unsafe extern "C" fn BuildTableOfContentsEx(
header: *mut *const u8,
headerSize: *mut usize
) -> bool {
let base_path_owned = CStr::from_ptr(basePath).to_str().unwrap();
let mod_path_slice = std::slice::from_raw_parts(basePath, basePathLength);
let base_path_owned = &String::from_utf16(mod_path_slice).unwrap();
let toc_path = base_path_owned.to_owned() + "\\" + TARGET_TOC;
let cas_path = base_path_owned.to_owned() + "\\" + TARGET_CAS;
match toc_factory::build_table_of_contents(&toc_path, version) {
Expand Down

0 comments on commit c395e01

Please # to comment.