Git Product home page Git Product logo

dearimguiinjection's People

Contributors

xiaoxiao921 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dearimguiinjection's Issues

Resize Render Issue

Hey, seems like DearImGuiInjection is interfering with graphics
Is there a fix withi this?
When you resize the game by dragging, the graphic does not resize with windows size. This only happens when DearImGuiInjection.dll is present
I guess it has to do with dx11 thing but I am not sure what you did with that class

Need help loading image

Hello,
I am trying to do ImGui.Image() with the texture I received from game, but I kept getting memory issue

Texture unit_texture = new();
IntPtr unit_texturePtr = IntPtr.Zero;
int width = 15;
int height = 15;
UnityMainThreadDispatcher.Enqueue(() =>
{
    unit_texture = Elements.UnitUtility.LoadUnitIconTexture(100101, 6, false);
    unit_texturePtr = unit_texture.GetNativeTexturePtr();
    width = unit_texture.width;
    height = unit_texture.height;
    ImGui.Image(unit_texturePtr, new System.Numerics.Vector2(width, height));
});
ImGui.End();
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
   at ImGuiNET.ImGuiNative.igImage(IntPtr, System.Numerics.Vector2, System.Numerics.Vector2, System.Numerics.Vector2, System.Numerics.Vector4, System.Numerics.Vector4)
--------------------------------
   at ImGuiNET.ImGui.Image(IntPtr, System.Numerics.Vector2)
   at PrincessStudio.Overlay.CharaEditor+<>c__DisplayClass4_0.<Show>b__0()
   at UnityMainThreadDispatcher+<ActionWrapper>d__8.MoveNext()
   at BepInEx.Unity.IL2CPP.Utils.Collections.Il2CppManagedEnumerator.MoveNext()
   at DynamicClass.Trampoline_ByteThisBepInEx.Unity.IL2CPP.Utils.Collections.Il2CppManagedEnumeratorMoveNext(IntPtr, Il2CppInterop.Runtime.Runtime.Il2CppMethodInfo*)
   at Il2CppInterop.Runtime.IL2CPP.il2cpp_runtime_invoke(IntPtr, IntPtr, Void**, IntPtr ByRef)
   at Il2CppInterop.Runtime.IL2CPP.il2cpp_runtime_invoke(IntPtr, IntPtr, Void**, IntPtr ByRef)
   at UnityEngine.MonoBehaviour.StartCoroutine(Il2CppSystem.Collections.IEnumerator)
   at UnityMainThreadDispatcher+<>c__DisplayClass6_0.<Enqueue>b__0()
   at UnityMainThreadDispatcher.Update()
   at DynamicClass.Trampoline_VoidThisUnityMainThreadDispatcherUpdate(IntPtr, Il2CppInterop.Runtime.Runtime.Il2CppMethodInfo*)
   at DynamicClass.Invoker_VoidThis(IntPtr, Il2CppInterop.Runtime.Runtime.Il2CppMethodInfo*, IntPtr, IntPtr*, IntPtr*)

If I were to move the ImGui.Begin and ImGui.End inside the dispatcher, I do not get any errors but nothing show up

Crash with Chained Echoes

Trying to use it on chained echoes, but have not been successfully yet, tested with my own plugin and with the one from "TestPlugin" in this project and both same behavior, the game open, the plugin load and it crashes.

The log file does not get written but I managed to capture a screen before it closes, here is the log:

image

No error is shown the game just closes.

Fix dependency madness

  • Ideally everything on nuget

  • find some way of putting some nice ready to use packages, figuring needed dlls for unity net 4.x mono backend is legit annoying

ClickEvent Pass through

General Issue:
Click events pass through and blockage

Observations:
https://github.com/xiaoxiao921/DearImGuiInjection/blob/af1e9534c67088d11779ad09d1aab2c19226e34a/DearImGuiInjection/BepInEx/DearImGuiInjectionBasePluginIL2CPP.cs#L59C4-L80C1
Seems like you are blocking Unity's EventSystem conditionally by IsCursorVisible boolean.

public static IntPtr WndProcHandler(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam)

However, ImGuiWin32Impl.WndProcHandler seems to be always capturing mouse event.

Observed Behaviors:
What this leads to are as followed

  1. Mouse events will always pass through ImGui windows.
  2. Unity's UI object will not capture mouse event because UnityEngine.EventSystems.EventSystem.Update is patched with false prefix when IsCursorVisible is true.

Specific Issues:

  1. UnityEngine.EventSystems.EventSystem.Update could be stripped when the game is shipped.
    This leads to everything clicked outside or within ImGui windows region when IsCursorVisible is true is always captured by Unity's UI objects, a.k.a pass through. Actually, I am not sure if is due to stripping. For the game priconner with Unity version 2021.3.20f1, I do see this class in interop dlls; however, it will always pass through.
  2. No inputs are allowed outside of ImGui windows region when IsCursorVisible is true. (not sure if you intended like this).
    It seems like a transparent canvas exist when IsCursorVisible is true.

Desired Behaviors:

  1. When IsCursorVisible is true, mouse events within ImGui windows region should not be captured by Unity's UI object, a.k.a no pass through.
  2. When IsCursorVisible is true, mouse events outside ImGui windows region should be captured by Unity's UI object., a.k.a GUI Overlay.

Changes
1.

public static IntPtr WndProcHandler(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam)

Change the return type of ImGuiWin32Impl.WndProcHandler to a boolean so that it will only return true when system message should be captured, false otherwise.
2.
private static unsafe IntPtr WndProcHandler(IntPtr windowHandle, WindowMessage message, IntPtr wParam, IntPtr lParam)

private static unsafe IntPtr WndProcHandler(IntPtr windowHandle, WindowMessage message, IntPtr wParam, IntPtr lParam)

For ImGuiDX11.WndProcHandler and ImGuiDX12.WndProcHandler, add a condition to return IntPtr.Zero when IsCursorVisible is true and when system message should be captured .

private static unsafe IntPtr WndProcHandler(IntPtr windowHandle, WindowMessage message, IntPtr wParam, IntPtr lParam)
{
    if (message == WindowMessage.WM_KEYUP && (VirtualKey)wParam == DearImGuiInjection.CursorVisibilityToggle.Get())
    {
        SaveOrRestoreCursorPosition();

        DearImGuiInjection.ToggleCursor();
    }

    if (DearImGuiInjection.IsCursorVisible && ImGuiWin32Impl.WndProcHandler(windowHandle, message, wParam, lParam))
        return IntPtr.Zero;

    return User32.CallWindowProc(_originalWindowProc, windowHandle, message, wParam, lParam);
}

public static bool IgnoreUIObjectsWhenImGuiCursorIsVisible()

Make it to return !false so that UnityEngine.EventSystems.EventSystem.Update is never patched. Honestly, I don't think SetupIgnoreUIObjectsWhenImGuiCursorIsVisible is needed anymore since we are now determining when to listen to mouse events through Window Message instead of Unity's EventSystem. Let me know if it is better to remove this.

Crash with Sons of the Forest, no error message from BepInEx (CoreClr Access Violation)

I am encountering an issue of the game completely closing while loading without any error output.
I am using .Net 6.
I made modifications to combine all references into one dll, but this error occurred before implementing this.
I've narrowed it down to this function in the RendererFinder.

private static IntPtr SwapChainResizeBuffersHook(IntPtr swapchainPtr, uint bufferCount, uint width, uint height, Format newFormat, uint swapchainFlags)
{
var swapChain = new SwapChain(swapchainPtr);
if (_preResizeBuffers != null)
{
foreach (Action<SwapChain, uint, uint, uint, Format, uint> item in _preResizeBuffers.GetInvocationList())
{
try
{
item(swapChain, bufferCount, width, height, newFormat, swapchainFlags);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
var result = _swapChainResizeBuffersHook.OriginalFunction(swapchainPtr, bufferCount, width, height, newFormat, swapchainFlags);
if (_postResizeBuffers != null)
{
foreach (Action<SwapChain, uint, uint, uint, Format, uint> item in _postResizeBuffers.GetInvocationList())
{
try
{
item(swapChain, bufferCount, width, height, newFormat, swapchainFlags);
}
catch (Exception e)
{
Log.Error(e);
}
}
}
return result;
}

more specifically this line
var result = _swapChainResizeBuffersHook.OriginalFunction(swapchainPtr, bufferCount, width, height, newFormat, swapchainFlags);

an access violation..
Current workaround is either run from debugger, or run game as administrator.
image
below is the log from BepInEx

[Message: Preloader] BepInEx 6.0.0-be.667 - SonsOfTheForest
[Message: Preloader] Built from commit 6b500b35727716f8ba182dedae304a628dbbb608
[Info : BepInEx] System platform: Windows 10 64-bit
[Info : BepInEx] Process bitness: 64-bit (x64)
[Info : BepInEx] Running under Unity 2022.2.16f1
[Info : BepInEx] Runtime version: 6.0.7
[Info : BepInEx] Runtime information: .NET 6.0.7
[Info : Preloader] 0 patcher plugins loaded
[Info : Preloader] 0 assemblies discovered
[Message:AssemblyPatcher] Executing 0 patch(es)
[Message: BepInEx] Chainloader initialized
[Debug : Preloader] Runtime invoke pointer: 0x7FFAE3F54DD0
[Debug :DobbyDetour] Preparing detour from 0x7FFAE3F54DD0 to 0x7FFA839A3264
[Debug :DobbyDetour] Prepared detour; Trampoline: 0x7FFAA3F60000
[Debug :DobbyDetour] Original: 7FFAE3F54DD0, Trampoline: 7FFAA3F60000, diff: 3FFF4DD0
[Debug : Preloader] Runtime invoke patched
[Debug :Il2CppInterop] il2cpp_object_get_virtual_method: 0x7FFAE3F54CE0
[Debug :Il2CppInterop] Object::GetVirtualMethod: 0x7FFAE3EE45C0
[Debug :Il2CppInterop] GenericMethod::GetMethod: 0x7FFAE3F1A550
[Debug :DobbyDetour] Preparing detour from 0x7FFAE3F1A550 to 0x7FFA839A32A4
[Debug :DobbyDetour] Prepared detour; Trampoline: 0x7FFAA3F60020
[Debug :DobbyDetour] Original: 7FFAE3F1A550, Trampoline: 7FFAA3F60020, diff: 3FFBA530
[Debug :Il2CppInterop] il2cpp_image_get_class: 0x7FFAE3F556E0
[Debug :Il2CppInterop] Image::GetType: 0x7FFAE3F5E990
[Debug :Il2CppInterop] MetadataCache::GetTypeInfoFromTypeDefinitionIndex: 0x7FFAE3F5E990
[Debug :DobbyDetour] Preparing detour from 0x7FFAE3F5E990 to 0x7FFA839A32E4
[Debug :DobbyDetour] Prepared detour; Trampoline: 0x7FFAA3F60040
[Debug :DobbyDetour] Original: 7FFAE3F5E990, Trampoline: 7FFAA3F60040, diff: 3FFFE950
[Debug :Il2CppInterop] Couldn't fetch Class::GetDefaultFieldValue with signatures, using method traversal
[Debug :Il2CppInterop] il2cpp_field_static_get_value: 0x7FFAE3F542B0
[Debug :Il2CppInterop] Field::StaticGetValue: 0x7FFAE3F75950
[Debug :Il2CppInterop] Field::StaticGetValueInternal: 0x7FFAE3F759D0
[Debug :Il2CppInterop] Class::GetDefaultFieldValue: 0x7FFAE3F5EBD0
[Debug :DobbyDetour] Preparing detour from 0x7FFAE3F5EBD0 to 0x7FFA839A3324
[Debug :DobbyDetour] Prepared detour; Trampoline: 0x7FFAA3F60060
[Debug :DobbyDetour] Original: 7FFAE3F5EBD0, Trampoline: 7FFAA3F60060, diff: 3FFFEB70
[Warning:Il2CppInterop] Class::Init signatures have been exhausted, using a substitute!
[Debug :Il2CppInterop] Picked mono_class_instance_size as a Class::Init substitute
[Debug :Il2CppInterop] Class::Init: 0x7FFAE3F56040
[Debug :Il2CppInterop] il2cpp_class_from_il2cpp_type: 0x7FFAE3F53300
[Debug :Il2CppInterop] Class::FromIl2CppType: 0x7FFAE3F22890
[Debug :DobbyDetour] Preparing detour from 0x7FFAE3F22890 to 0x7FFA839A3364
[Debug :DobbyDetour] Prepared detour; Trampoline: 0x7FFAA3F60080
[Debug :DobbyDetour] Original: 7FFAE3F22890, Trampoline: 7FFAA3F60080, diff: 3FFC2810
[Debug :Il2CppInterop] il2cpp_class_from_name: 0x7FFAE3F53310
[Debug :Il2CppInterop] Class::FromName: 0x7FFAE3F6F470
[Debug :DobbyDetour] Preparing detour from 0x7FFAE3F6F470 to 0x7FFA839A33A4
[Debug :DobbyDetour] Prepared detour; Trampoline: 0x7FFAA3F70000
[Debug :DobbyDetour] Original: 7FFAE3F6F470, Trampoline: 7FFAA3F70000, diff: 3FFFF470
[Info :Il2CppInterop] Registered mono type Il2CppInterop.Runtime.DelegateSupport+Il2CppToMonoDelegateReference in il2cpp domain
[Debug : Unity] Test call after applying unity logging hook
[Debug : BepInEx] Examining 'D:\SteamLibrary\steamapps\common\Sons Of The Forest\BepInEx\plugins\DearImGuiInjection.dll'
[Info : BepInEx] 2 plugins to load
[Info : BepInEx] Loading [DearImGuiInjection 1.0.2]
[Info :DearImGuiInjection] Costura.Fody Init in DearImGuiInjectionBasePlugin
[Info : Console] [RendererFinder] Costura.Fody Init
[Info : Console] [RendererFinder] DX11Renderer.Init()
[Info : Console] [Reloaded.Assmebler] Executing Assembly Location: C:\Users\jacob\AppData\Local\Temp\Costura\AAD9B7C6C0E5EC1BD890F0C637C35ED0\reloaded.assembler.dll
[Info : Console] [Reloaded.Assmebler] Executing Assembly CodeBase: file:///C:/Users/jacob/AppData/Local/Temp/Costura/AAD9B7C6C0E5EC1BD890F0C637C35ED0/reloaded.assembler.dll
[Info : Console] [Reloaded.Assmebler] App Domain Location:
[Info : Console] [Reloaded.Assmebler] GetExecutingDLLDirectory Result: C:\Users\jacob\AppData\Local\Temp\Costura\AAD9B7C6C0E5EC1BD890F0C637C35ED0
[Debug :DobbyDetour] Preparing detour from 0x7FFAE85ACA60 to 0x7FFA839A3664
[Debug :DobbyDetour] Prepared detour; Trampoline: 0x7FFAA85B0000
[Debug :DobbyDetour] Original: 7FFAE85ACA60, Trampoline: 7FFAA85B0000, diff: 3FFFCA60
[Info :Il2CppInterop] Registered mono type UnityMainThreadDispatcher in il2cpp domain
[Info : BepInEx] Loading [TestPluginDearImGui 1.0.0]
[Info :Il2CppInterop] Registered mono type TestPlugin.TestPluginBehaviour in il2cpp domain
[Message: BepInEx] Chainloader startup complete
[Debug : Preloader] Runtime invoke unpatched
[Message: Unity] Releases.Initialize
[Message: Unity] Releases : 12/01/2023 01:00:00
[Message: Unity] Version.Initialize
[Message: Unity] Version : EarlyAccess.42457
[Error : Unity] Missing GameSettingsManager Instance!
[Message: Unity] Fps Limiter set to 0
[Message: Unity] FMOD Setting Voice Count 128
[Message: Unity] FMOD Setting maxVorbisCodecs 118
[Message: Unity] FMOD System output rate: 48000 speaker mode: STEREO
[Message: Unity] Screen.brightness : 1
[Message: Unity] [EnvironmentArgs] ...
{}
[Message: Unity] User data path: C:/Users/jacob/AppData/LocalLow/Endnight/SonsOfTheForest
[Message: Unity] Steam Started
[Message: Unity] CoopSteamManager Initialize
[Message: Unity] Initializing Steam Stats and Achievements.
[Error : Unity] Missing GameSettingsManager Instance!
[Message: Unity] Fps Limiter set to 30
[Error : Unity] Missing GameSettingsManager Instance!
[Error : Unity] Missing GameSettingsManager Instance!
[Info :DearImGuiInjection] ImGuiImplWin32Init, Window Handle: 2814EC
[Message: Unity] Couldn't find Volume Profile
[Message: Unity] Couldn't find Volume Profile
[Message: Unity] SaveGameManager Registered Serializer: GameSetup.
[Message: Unity] GameSetup mode = Normal
[Warning: Unity] Duplicate FpsLimiter "FpsLimiter", removing latest.
[Message: Unity] SaveGameManager Registered Serializer: GameState.
[Message: Unity] New resolution is 2560 x 1440 (16:9)
[Message: Unity] No backtrace command arg found, Backtrace disabled
[Warning: Unity] Already set to the same number of voices 128
[Message: Unity] Applying grass setting HIGH
[Message: Unity] Applying Terrain Parallax setting HIGH
[Message: Unity] Applying Billboard setting HIGH
[Message: Unity] SaveGameManager Started. (2 queued serializers)
[Error : Unity] Invalid fullscreen mode "Exclusive FullScreen"
[Message: Unity] vSync set to 1
[Message: Unity] Setting resolution to 2560 x 1440 (FullScreenWindow)
[Message: Unity] New resolution is 2560 x 1440 (16:9)
[Message: Unity] Fps Limiter set to 155
[Info :DearImGuiInjection] [DX11 ResizeBuffers] Window Handle 2814EC

Fetal error in GC: Collecting from unknown thread

image
Can you please provide some clue as of any design or implementation of DearImGuiInjection that deals with Garbage Collection or threading?
We are getting this issue after running the game for a while when ImGui interface is enabled.

Add mod to Lethal Company on Thunderstore

Hello! I want to create a mod that uses this for Lethal Company, however I cannot publish it on Thunderstore because you cannot depend on mods from another game. Could you please publish this library for Lethal Company?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.