JamesWilko / Payday-2-BLT

Payday 2 Better Lua injecTor
http://paydaymods.com/
MIT License
174 stars 36 forks source link

Linux Support #56

Closed karasuhebi closed 7 years ago

karasuhebi commented 8 years ago

Is this planned? :D

Ozymandias117 commented 8 years ago

Interesting. I'll check again, but when I'd tried hooking luaL_newstate I never hit the hooked function, which was why I'd changed to lua_newstate in the first place. I'll go back and verify it was hooking at the right address, and that the memory at that address was modified.

RomanHargrave commented 8 years ago

@SirWaddles That's interesting, especially given what @Ozymandias117 has to say about luaL_newstate on linux...

SirWaddles commented 8 years ago

Thinking about it, that sounds right. I'd say the function we called luaL_newstate wasn't actually luaL_newstate in PD2, and was a function in Payday's lua wrapper somewhere with some code copied from luaL_newstate.

If there was some code that was hanging around, but never really got called, we probably wouldn't have paid much attention to it (i.e. the actual luaL_newstate). We found that function by looking for things that actually called lua_newstate in the PD2 binary, and then just assumed that it was luaL_newstate, because like @RomanHargrave said, luaL_newstate calls lua_newstate.

Ozymandias117 commented 8 years ago

That makes a lot more sense, and also explains why you're hooking it like it's a class rather than a pure c function.

I just verified again and saw that luaL_newstate was hooked properly, but didn't get called. I guess we need to figure out what the wrapped function is.

Ozymandias117 commented 8 years ago

Here we go: `(gdb) bt

0 0x0000000000e0eed0 in lua_newstate ()

1 0x0000000000dad948 in dsl::LuaInterface::newstate(bool, bool, dsl::LuaInterface::Allocation) ()

2 0x0000000000daeafb in dsl::LuaInterpreter::LuaInterpreter(int, bool, bool, bool, dsl::LuaInterface::Allocation) ()

3 0x0000000000bdd0a9 in Application::Application() ()

4 0x0000000000e64e51 in app_run() ()

5 0x0000000000e65e65 in app_entry_filtered() ()

6 0x0000000000e64b74 in main ()

`

And from the disassembly: 0000000000dad920 <_ZN3dsl12LuaInterface8newstateEbbNS0_10AllocationE>

SirWaddles commented 8 years ago

dsl::LuaInterface::newstate sounds about right.

Ozymandias117 commented 8 years ago

Although that still isn't really (char, char, int)? I'm also still confused why your hooked function has an additional parameter that it's not passing on to the original function?

SirWaddles commented 8 years ago

Same again, all we had was the byte sizes. 1 byte we assumed was a character, 4 bytes an int etc.

The int edx param was as a result of using the thiscall and fastcall matched calling conventions.

Ozymandias117 commented 8 years ago

Awesome, thanks for the information! I can load payday and get to the update manager, so we probably have working mods. I'll clean up and push to my branch, then start looking at the CConsole stuff.

RomanHargrave commented 8 years ago

@Ozymandias117 interesting work.

I'd like to look at merging it with my project, though, if that's not too big of a deal. We've already got the traction, plus, there are a few things that I'd like to clean up.

Ozymandias117 commented 8 years ago

Yeah, I'm fine with that. Honestly, with as much as I changed here, we'll probably be able to get your hook working faster than I can figure out how to make both Windows and Linux build from the same tree...

I'll still try to get both working if possible. I was going to load up a handful of mods and try to play a few missions to see if I crash.

We'll also need to add support on paydaymods to be able to update both sides: Incoming HTTP Request/Request http://api.paydaymods.com/updates/retrieve/?mod[0]=payday2blt&mod[1]=payday2bltdll 806 Launching Async HTTP Thread [Updates] Attempting to remove temporary hook dll... [Warning] Could not remove hook dll: IPHLPAPI_temp.dll: No such file or directory [Updates] Received update data for 'payday2blt', server revision: 12 [Updates] Received update data for 'payday2bltdll', server revision: 5

RomanHargrave commented 8 years ago

@Ozymandias117 yeah, sounds like PDMods is going to need some work. WRT my hook, I'm nearing the point where the LUA gets mixed in. We've just been caught up re-implementing the BLT API.

In the mean time, @SirWaddles @JamesWilko you may be interested in knowing that the demangled form of dsl::LuaInterface::newstate takes the params (bool, bool, void*).

My guess would be that the returned int-width value is a pointer.

Ozymandias117 commented 8 years ago

Also, @JamesWilko, will you have an issue with this change to the CREATE_CALLABLE_SIGNATURE's?

name ## ptr name ## _orig = NULL; \

When I was keeping the original name, I was unable to build with gcc.

Looking back through, as long as you're okay with that, it might not be that bad to get both building.

SirWaddles commented 8 years ago

Hey, as long as it still works on Windows, I don't really care. Not sure why gcc stops working though, seems weird.

Also I should probably mention that Wilko wrote all of the APIs, the menu systems, the post and pre-script hooks and whatnot. Basically, he wrote all of the lua and I wrote all of the C/C++ (well, like 98% of it).

RomanHargrave commented 8 years ago

@Ozymandias117 I'm getting some strange stuff coming down the line for dsl::LuaInterface::newstate

Calling lua_gettop on the returned state structure is returning what I believe to be garbage data. Any thoughts?

Here are the parameter values for LuaInterface::newstate(..) as output by my debug code:

dsl_lua_newstate(this = 0x3de9810, 1, 0, 0x1)
stackSize = 663
dsl_lua_newstate(this = 0x3de98f0, 1, 1, 0)
stackSize = 1042594780
dsl_lua_newstate(this = 0xc0772c0, 1, 0, 0x1)
stackSize = -12637120

The this pointer appears relative consistent, and calling the original function with it works, the allocator portion is shaky, but appears to work too. What's getting me here are those bizarre

Ozymandias117 commented 8 years ago

I just ran a Cook Off with my branch to test. Here's what I got:

Working: Bodhi's War Repair Fast.Net Standalone Flashing Swan Song HUDListblt Lobby Player Info Side Jobs in Lobby SPL Sets

Didn't work: Enhanced Hitmarkers JackHUD PocoHud

RomanHargrave commented 8 years ago

@Ozymandias117 I can't even get your port working. The hooks are working, but nothing else. I'm trying to confirm some of my stuff with it.

SirWaddles commented 8 years ago

What happened with PocoHUD? I know a lot of people use that one.

RomanHargrave commented 8 years ago

My guess is that those mods are using plaform-specific file paths, without looking at them.

Ozymandias117 commented 8 years ago

@SirWaddles Here's the error output from Hitmarkers and Poco, although I doubt it's too relevant here specifically:

Edit: You can ignore the isDir x and In GetDirContents. Those are leftover from debugging. Enhanced Hitmarkers: [EH] Creating Enhanced Hitmarkers overrides folder... CURL INITD sh (27916) sh: 1: Syntax error: Unterminated quoted string assets/mod_overrides/Enhanced Hitmarkers/guis/textures/pd2/ In GetDirContents mods/Enhanced Hitmarkers/hitmarkers/ In GetDirContents loverkill.texture isDir 0 checkbox K.texture isDir 0 star.texture isDir 0 . isDir 1 pd2.texture isDir 0 almir.texture isDir 0 smiley.texture isDir 0 pirate H.texture isDir 0 aperture.texture isDir 0 nope.texture isDir 0 horny.texture isDir 0 pirate K.texture isDir 0 ovk.texture isDir 0 phatcross.texture isDir 0 tongue and lip.texture isDir 0 hotline miami.texture isDir 0 pooverkill.texture isDir 0 classic crit.texture isDir 0 Malo.texture isDir 0 checkbox H.texture isDir 0 classic hit.texture isDir 0 TdlQ.texture isDir 0 pattee.texture isDir 0 radioactive.texture isDir 0

PocoHud Err: Failed to load mods/PocoHud3/poco/../poco/3rdPartyLibrary.luacPoco:Init Err: Failed to load mods/PocoHud3/poco/../poco/Hud3_class.luacErr: Failed to load mods/PocoHud3/poco/../poco/Hud3_Options.luacLocale EN loaded Err: Failed to load mods/PocoHud3/poco/../poco/Hud3.luacIncoming

JackHUD mods/JackHUD/Lua/CrimeNetFiltersGui_ext.lua:7: attempt to call method 'save_persistent_settings' (a nil value)

@RomanHargrave Let me build again from fresh and make sure I didn't miss a file in the repo or anything. The two things I can think of to suggest are: 1. Did you copy the mods folder into the Payday 2 folder? 2. Currently I've only been able to get it working when running from the command line. If I add it to Steam's launch options, it didn't work.

RomanHargrave commented 8 years ago

@Ozymandias117 Got it working; not having issues with PocoHUD though.

Ozymandias117 commented 8 years ago

Hmm. I'll try downloading a fresh copy of Poco.

RomanHargrave commented 8 years ago

@Ozymandias117 btw, got my newstate hook working, was not expecting the supposed 'this' pointer to be a lua_state\ value

SirWaddles commented 8 years ago

Yea, the lua_state is just the first member of the class. So this points to the class, derefence it to get the first member, you've got a pointer to the lua state. It's technically not a lua_state**, but it's close enough.

Ozymandias117 commented 8 years ago

Even with a fresh Poco, I see it under Options -> Mod Options, but backspace doesn't work to open up the settings menu, and I'm getting those errors.

RomanHargrave commented 8 years ago

@SirWaddles I figured as much.

SirWaddles commented 8 years ago

I didn't realise Poco was luac files? Could that be the problem?

Ozymandias117 commented 8 years ago

GoonMod required me to rename req/options.lua to req/boptions.lua... it was loading updates.lua prior to options.lua for some reason... I'm not sure how that's working on Windows...?

Looking into JackHUD next Edit: JackHud was due to a prior issue that I missed in the logs: [Error] Could not open file 'mods/JackHUD/Lua/NetworkMatchmakingSteam_ext.lua'! Does it exist, is it readable?

It turns out it was named NetworkMatchmakingSTEAM_ext.lua in the folder.

@SirWaddles I'm not sure... the files in that folder aren't luac? I'm not sure why that's showing like that...

Ozymandias117 commented 8 years ago

@SirWaddles It looks like they search for the correct name, then if it doesn't exist, or dofile fails, they try with c appended. There's no output in the case that it finds the original file, but dofile fails. This is all in common.lua

ljrk0 commented 8 years ago

@SirWaddles Poco is distributed as binary luac buy lua code is available on GitHub too, so one could at least debug it.

BangL commented 8 years ago

@Ozymandias117 "It turns out it was named NetworkMatchmakingSTEAM_ext.lua in the folder."

..i've already changed that locally, but git on windows doesnt care. thanks for pointing it out though. i will take care of it.

BangL commented 8 years ago

btw.. this is awesome news. cant wait to get home. love you guys.

karolherbst commented 8 years ago

@Ozymandias117 awesome, your branch works for me (after I also copied the mods folder). But for me it wants to update the blt DLL, just curious if you also got the message.

Ozymandias117 commented 8 years ago

@karolherbst Yeah, that still needs to be fixed.

SirWaddles commented 8 years ago

Yea, if it can ask for a different mod ident instead of payday2bltdll like payday2bltdll_linux or something, I can add it to the website.

BangL commented 8 years ago

about pocohud:

the errors about luac files can be understood as warnings. as you can see in common.lua, line 18, pocohud tries to run luac files IF lua versions are not existant: return __req(name) or __req(name..'c')

the thing with the backspace key is a different story... for me its not working as well, but if i tap my X key two times, the options are coming up. (which is my binding for the detail view, i think it is the tilde-key by default)

karolherbst commented 8 years ago

well I tried pocohud and it seems working just fine, except I couldn't configure it.

BangL commented 8 years ago

well I tried pocohud and it seems working just fine, except I couldn't configure it.

thats what i tried to explain in my post before. the errors arent errors. and the configuring isnt possible because of messed up keybindings. - backspace isnt working as intended for some reason. but if you tap the "detail view" key two times, you can access the settings, which is the tilde-key by default. (atleast on english keyboard layouts)

EDIT: i think on other keyboard layouts, it might be completely unbound, to change it you could edit your mods/saves/hud3_config.json by hand.

as example: a config, which only changes the mentioned keybind would look like this:

{ "root": { "detailedModeKey": "x" } }

Ozymandias117 commented 8 years ago

Yeah, I'd posted earlier about the or in common.lua. My concern is why are we getting into that or case? It implies to me a bug in luaF_dofile. My guess is that it shouldn't be returning 0? On Apr 7, 2016 10:29 AM, Henno Rickowski notifications@github.com wrote: well I tried pocohud and it seems working just fine, except I couldn't configure it.

thats what i tried to explain in my post before. the errors arent errors. and the configuring isnt possible because of messed up keybindings. - backspace isnt working as intended for some reason. but if you tap the "detail view" key two times, you can access the settings, which is the tilde-key by default.

—You are receiving this because you were mentioned.Reply to this email directly or view it on GitHub

BangL commented 8 years ago

Yeah, I'd posted earlier about the or in common.lua. My concern is why are we getting into that or case?

indeed. you're absolutely right. i didn't even think about that so far.

It implies to me a bug in luaF_dofile. My guess is that it shouldn't be returning 0?

EDIT: the blt4win it's also returning 0. - so not sure. i see what you mean though.

BangL commented 8 years ago

@Ozymandias117 just debugged it.. actually dofile() isnt even returning 0, it should, but it is returning nil yet. - thats the point.

RomanHargrave commented 8 years ago

I just got my fresh implementation of BLT working. No issues so far, other than the current pocohud issue (and multiple poco components like damage and buff indicators are fine over here).

Ozymandias117 commented 8 years ago

Nice! I'm out of town until Monday - at that point I can try to finish merging this one back and help with any other bugs that have been found.

SirWaddles commented 8 years ago

This is largely my fault, but that might be an issue as the release branch at the moment is actually the crimefest branch.

RomanHargrave commented 8 years ago

@SirWaddles what exactly is different in the crimefest branch?

SteamD commented 8 years ago

awesome work folks. made a few notes while watching the thread, may or may not be useful at some point.

on ubuntu 14.04 you'll get an issue using gnutls, instead openssl is working fine. undefined symbol: CRYPTO_set_locking_call aptitude remove libcurl4-gnutls-dev; aptitude install libcurl4-openssl-dev

pocohud seems to be accessable via k too. modified L18 in common.lua regarding the loading of compiled scripts (luac) -- return __req(name) or __req(name..'c') return __req(name)

goonmod gets stuck on buying new inventory, modified mod.txt removed { "hook_id" : "lib/managers/menu/blackmarketgui", "script_path" : "goonbase.lua" }, { "hook_id" : "lib/managers/blackmarketmanager", "script_path" : "goonbase.lua" },

Ozymandias117 commented 8 years ago

@SteamD The PocoHud change is unnecessary, and may break PocoHud for some current users based off of @LeonardKoenig's statement that it's distributed as luac somewhere. The error output is erroneous. I don't believe anyone has solved the backspace keybinding issue yet.

BangL commented 8 years ago

I don't believe anyone has solved the backspace keybinding issue yet.

pocohud is using Idstring('backspace') to handle that binding so i bet it's a linux-related problem on overkills side (just a very wild guess)

drewofdoom commented 8 years ago

@Ozymandias117 @SteamD @LeonardKoenig The only reference to "luac" at all in the actual code is in a comment in Hud3.lua. Just went through and grepped all of the lua files for it.

The original, non-BLT version is compiled as luac, so that may be causing the confusion.

BangL commented 8 years ago

@drewofdoom it's this: __req(name..'c')