static unsafe void TrySetupLegacyBridge() { NlodSetup = Legacy.LegacyNativeWrapper.Setup; NlodRegisterTexture = Legacy.LegacyNativeWrapper.RegisterTexture; NlodRequestTextureLoad = Legacy.LegacyNativeWrapper.RequestTextureLoad; NlodCancelTextureLoad = Legacy.LegacyNativeWrapper.CancelTextureLoad; NlodRequestTextureUnload = Legacy.LegacyNativeWrapper.RequestTextureUnload; NlodRequestedUpdate = Legacy.LegacyNativeWrapper.RequestedUpdate; NlodStartSignalMessages = Legacy.LegacyNativeWrapper.StartSignalMessages; throw new NotImplementedException("DebugDumpTexture stil used? not implemented, at least!"); }
static void SetupNativeBridge() { try { ("Device: " + SystemInfo.graphicsDeviceVersion).Log(); if (!SystemInfo.graphicsDeviceVersion.StartsWith("Direct3D 9.0c")) { // Todo7: Support non-DX9 throw new PlatformNotSupportedException("This mod currently only supports Direct3D 9.0c."); } var lib = new UnmanagedLibrary(CopyEmbededNativeDllAndGetPath()).NotNull(); NlodSetup = lib.GetUnmanagedFunction <PInvokeDelegates.Setup>("NlodSetup").NotNull(); NlodRegisterTexture = lib.GetUnmanagedFunction <PInvokeDelegates.RegisterTexture>("NlodRegisterTexture").NotNull(); NlodRequestTextureLoad = lib.GetUnmanagedFunction <PInvokeDelegates.RequestTextureLoad>("NlodRequestTextureLoad").NotNull(); NlodCancelTextureLoad = lib.GetUnmanagedFunction <PInvokeDelegates.CancelTextureLoad>("NlodCancelTextureLoad").NotNull(); NlodRequestTextureUnload = lib.GetUnmanagedFunction <PInvokeDelegates.RequestTextureUnload>("NlodRequestTextureUnload").NotNull(); NlodRequestedUpdate = lib.GetUnmanagedFunction <PInvokeDelegates.RequestedUpdate>("NlodRequestedUpdate").NotNull(); NlodStartSignalMessages = lib.GetUnmanagedFunction <PInvokeDelegates.StartSignalMessages>("NlodStartSignalMessages").NotNull(); NlodDebug_DumpTexture = lib.GetUnmanagedFunction <PInvokeDelegates.DumpTexture>("NlodDebug_DumpTexture"); libraryRef = lib; DummyTexture = new Texture2D(2, 2, TextureFormat.RGB24, false); DummyTexture.Apply(true, true); } catch (Exception err) { try { throw new NotImplementedException("Legacy mode isn't even close to a working state!"); TrySetupLegacyBridge(); err.Log("Failed to set up native module, using LegacyWrapper instead (horrible perf!)"); Logic.ActivityGUI.SetText("Failed to set up native module, using LegacyWrapper instead (horrible perf!)"); } catch (Exception fallbackErr) { var bothErr = new AggregateException("Failed to create NativeBridge, even legacy mode!", new[] { err, fallbackErr }); Logic.ActivityGUI.SetError(bothErr); throw bothErr; } } }