Bolt-Scripts / MHR-InGame-ModMenu-API

A user-friendly IMGUI inspired API for drawing in-game settings menus for REF mods in MHRise
13 stars 4 forks source link

reliance on plugin? #11

Closed HookedBehemoth closed 2 years ago

HookedBehemoth commented 2 years ago

I'm trying to figure out why this requires a native plugin before installing it. I'd like to avoid running precompiled dll's if it's not strictly necessary. Could "PtrToGuidTest" not be expressed in lua? It seems you're able to set the value from lua. Is it too slow to do it like that?

Bolt-Scripts commented 2 years ago

As it is it simply isn't possible from my understanding to take the ptr and get the data from it within lua since GUID is a value type and not a managed object. At least that's what praydog said and I couldn't figure any weird workaround. Support for this could be added into the REF sdk itself, but I figured it'd be at the least more interesting to make a plugin for it, but also it meant people wouldn't have to update REF for it to work. But if at some point support for this is added then could transition away from the plugin. Still, I wonder why you want to avoid it so much

HookedBehemoth commented 2 years ago

Thanks for the explanation. I'd like to avoid running random binaries where I can't verify the code easily. As an individual modder, you don't have anything to loose from potentially shipping malware. Don't see this as an allegation, but in my background, mainly switch modding, this wasn't that uncommon.

Bolt-Scripts commented 2 years ago

Yeah I get you. The source is in the repo but it'd be kinda hard to verify I didn't modify any of the like sol or lua files and then youd have to build it to make sure the dll matches or something idk. But I assure you my c++ skills are not good enough to write malware lmao Just an unfortunate roadblock that I needed to be able to read the GUIDs passed from the pointer in the arguments of a method, which is the crux of being able to display custom text in the UI.

Strackeror commented 2 years ago

So, I was surprised this was actually impossible to do, and indeed you can't actually get a value type from a pointer right now in REFramework.

BUT

After some research into the lua layer source code, I found the REField:get_data() function can take a pointer as an argument, and so I managed to make the mod work with this piece of lua:

local GuidType = sdk.find_type_definition("System.Guid")
local suidArg;
local function PreMsg(args)
  suidArg = GuidType:get_field("mData1"):get_data(args[2]);
end
Bolt-Scripts commented 2 years ago

Woah, that is sneaky! I never would've thought to do that, but I wouldn't have had any reason to look for undocumented functionality I suppose. But thanks for hunting this down, next update I shall remove the custom plugin in favor of this. Might be good to also update the doc with the capability?

Strackeror commented 2 years ago

I'll see if I can make a pull request to the reframework book for that, if I can find a way to formulate that well. Though to be frank I don't think this way of doing it is ideal, and there should just be a sdk.to_value_type() in REFramework itself

Bolt-Scripts commented 2 years ago

True, and I agree. Still, this would've saved me a lot of headache earlier trying to get anything working 😅