praydog / REFramework

Scripting platform, modding framework and VR support for all RE Engine games
https://cursey.github.io/reframework-book/
MIT License
2.68k stars 338 forks source link

DD2 - Returning sdk.create_managed_string(str) crashes the game. #1049

Closed ataraxyaffliction closed 2 months ago

ataraxyaffliction commented 2 months ago

Describe the bug Returning sdk.create_managed_string(str) instead of System.String in DD2 crashes the game.

Upload logs and any crash dumps reframework_crash.dmp

Identify the REFramework version Release v1.5.4 and Nightly 842.

To Reproduce Steps to reproduce the behavior:

  1. Open Pause Menu.
  2. Open History.
  3. Crash during loading NPC Logbook when the Guid in Likes matches.

Expected behavior I'm trying to replace System.String in Dragons Dogma 2 via sdk.hook using a specific Guid, but after returning sdk.create_managed_string(str) the game crashes.

Desktop and VR:

Additional context I only use this script, nothing else.

local current_message_guid

sdk.hook(sdk.find_type_definition("app.MessageManager"):get_method("getMessage"), 
    function(args) 
        local type = sdk.find_type_definition("System.Guid")
        current_message_guid = sdk.get_native_field(args[2], type, "mData1")
    end,
    function(retval)
        local msg = sdk.to_managed_object(retval):ToString()

        if current_message_guid == 3901721732 then
            return sdk.create_managed_string("X")
        end

        return retval
    end
)
ataraxyaffliction commented 2 months ago

Ok, I'm just stupid. It should be like this: return sdk.to_ptr(sdk.create_managed_string("X")).