I have tried to load a DLL and failed.
Steps I took:
First, disable DEP to be able to load our dll. If you cannot disable DEP, you will run into errors like I did (and still do).
You will need to disable software and hardware DEP. Software DEP is disabled like this:
Code: Select all
bcdedit.exe /set {current} nx AlwaysOff
Hardware DEP is disabled by turning it off in BIOS, look for 'execution bit' or something like that. Some BIOSes (like mine) don't have that option, so you are probably out of luck - DEP will prevent dll from loading, mgsvtpp.exe will crash with BEX64/StackHash error. Reboot after turning them off.
Second, you need to get a 64 bit compilator - game uses 64-bit version of lua and doesn't like 32 bit dlls (this is just a guess, not 100% confirmed). I used gcc from
http://winbuilds.org/. Download the installer, install everything, veryfy that it is working by typing 'gcc' in console. If it is not working - check your PATH or invoke it directly from the installation directory.
Third, write your dll. This is the hardest part, so I chose to get the source from the internet.
test.tar
Fourth, compile it.
Code: Select all
gcc -O2 -c -o test.o test.cpp
gcc -O -static -o test.dll test.o
Note: we are compiling it as a static library.
You can also try to build a shared library. To do so, get Lua 5.1.5 windows x64 build -
https://sourceforge.net/projects/luabin ... p/download . Put lua5.1.dll along with test.cpp, compile:
Code: Select all
gcc -O2 -c -o test.o test.c
gcc -O -shared -o test.dll test.o -L . -llua5.1
Now we have a compiled DLL and ready to load it in the game. Put it along with mgsvtpp.exe to avoid path issues. If you have built shared library, copy lua5.1.dll there as well. You can put require code into init.lua or load it on button press - whatever you like.
or
Code: Select all
var add1 = package.loadlib('test','add1')
add1(2)
And here are the problems:
If you have shared library, game loads your dll AND lua5.1.dll, which results in soft hang - game is running, but the screen is frozen, inputs are not working. I see 2 possible problems with is:
- Internal lua engine conflicts with lua5.1.dll;
- dll is missing something.
No idea how to solve any of them.
If you have a static library, game tries to load your dll, but DEP is preventing it to load, crashing with BEX64/StackHash errors. I was unable to disable hardware part of DEP - my BIOS is missing settings. I have also tried disabling antivirus, turning on compability settings, running as admin - same error. This bug needs to be reproduced on another machine, maybe the problem is in my pc. There is also a possibility that I don't fully understand the mechanism of loading shared/static libraries and static lib is worthless.
I have also tried to load the dll using Fox module methods by calling them one by one with 'test' as parameter. Unfortunately it didn't work and I haven't seen any low-level C modules in the game that had functions with ability to load stuff (aside from Script.LoadLibrary, which loads luas only).
Edit: I have also tried to build a proxy dll as described here:
http://lua-users.org/wiki/LuaProxyDll. All 4 methods failed (or maybe it's just me). Hope that will help anyone trying to do the same.