private static void EnsureLoaded() { if (OodleLZ_Handle != IntPtr.Zero) { return; } // Can't use DllImport if I want to support multiple DLL versions. Resolve the exports by hand. OodleLZ_Handle = LoadLibraryW("oo2core_7_win64.dll"); OodleLZ_Version = 7; if (OodleLZ_Handle == IntPtr.Zero) { OodleLZ_Handle = LoadLibraryW("oo2core_3_win64.dll"); OodleLZ_Version = 3; } var decompressorFunc = GetProcAddress(OodleLZ_Handle, "OodleLZ_Decompress"); var compressorFunc = GetProcAddress(OodleLZ_Handle, "OodleLZ_Compress"); if (decompressorFunc == IntPtr.Zero || compressorFunc == IntPtr.Zero) { throw new Exception("A valid oo2core DLL couldn't be found in the program directory (oo2core_3_win64.dll, oo2core_7_win64.dll)"); } OodleLZ_Decompress = Marshal.GetDelegateForFunctionPointer <OodleLZ_Decompress_Delegate>(decompressorFunc); OodleLZ_Compress = Marshal.GetDelegateForFunctionPointer <OodleLZ_Compress_Delegate>(compressorFunc); }
public static void LoadLibrary(string gamePath) { string libpath = Path.Combine(gamePath, "oo2ext_7_win64.dll"); Console.WriteLine("Loading compression library: " + libpath); LibraryHandle = KernLoadLibrary(@libpath); if (LibraryHandle == IntPtr.Zero) { throw new Exception("Failed to load oodle library"); } OodleLZ_Decompress_Ptr = KernGetProcAddress(LibraryHandle, "OodleLZ_Decompress"); OodleLZ_GetCompressedBufferSizeNeeded_Ptr = KernGetProcAddress(LibraryHandle, "OodleLZ_GetCompressedBufferSizeNeeded"); OodleLZ_Compress_Ptr = KernGetProcAddress(LibraryHandle, "OodleLZ_Compress"); if (OodleLZ_Decompress_Ptr == IntPtr.Zero || OodleLZ_GetCompressedBufferSizeNeeded_Ptr == IntPtr.Zero || OodleLZ_Compress_Ptr == IntPtr.Zero) { throw new Exception("Compression functions not found in oodle library"); } OodleLZ_Decompress = (OodleLZ_Decompress_Delegate)Marshal.GetDelegateForFunctionPointer(OodleLZ_Decompress_Ptr, typeof(OodleLZ_Decompress_Delegate)); }