logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Trails and Troubles with NWNx4 & wine

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Technical support
View previous topic :: View next topic  
Author Message
kuscotopia



Joined: 10 Aug 2009
Posts: 11

PostPosted: Mon Aug 10, 2009 20:21    Post subject: Trails and Troubles with NWNx4 & wine Reply with quote

I am hoping that someone here will be able to speak to running NWNx4 + nwn2server within wine.

For starters I am wondering if this is even possible with the latest version of NWNx4. Does anyone know of any success stories with regards to hosting a PW via wine?

I have been working on this for the past couple days, and I am able to host built-in campaigns just fine. However when I go to load my custom module NWNx4 decides that nwn2server is taking too long to load and starts kicking up new server processes even though the original spawned server returns with the module loaded. Is there a parameter I can set within nwnx.ini that will cause it to wait longer?

I tried Skywing's branch in hopes that it would solve my problems but I only saw a bunch of the following messages displayed in the nwnx4_gui window:

Code:

Failed to wait for server message loop to begin
Couldn't receive response from server confirming message loop running


And, the following messages displayed from wine:

Code:

fixme:powrprof:DllMain (0x7e4c0000, 1, (nil)) not fully implemented
fixme:ntdll:NtPowerInformation Unimplemented NtPowerInformation action: 16
08:55:05: * IPC Server MyNWNXServer 32 started (DDE)
wine: Call from 0x7bc3a9b0 to unimplemented function ntdll.dll.NtContinue, aborting
err:seh:raise_exception Unhandled exception code 80000100 flags 1 addr 0x7bc3a9b0


Any advice is appreciated. Thanks!
Back to top
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Mon Aug 10, 2009 20:35    Post subject: Reply with quote

I have no first-hand experience with NWN2/NWNX4/wine, but my understanding is "it can be made to work, but you should really just use Windows or a Windows VM". Yorlik is the authority on that, IIRC, so maybe he'll chime in here.

As to your error, it looks to me like an issue with your wine setup -- it sounds like wine is supposed to provide NtContinue in ntdll.dll, but isn't for some reason, so it's exploding. Unless you're using a very old version of wine, I don't know why that would be.
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
kuscotopia



Joined: 10 Aug 2009
Posts: 11

PostPosted: Mon Aug 10, 2009 22:00    Post subject: Reply with quote

The version of wine I am using is 1.0. Not the latest, but the latest available for Ubuntu 8.04 LTS standard repositories Smile.
Back to top
View user's profile Send private message
Skywing



Joined: 03 Jan 2008
Posts: 321

PostPosted: Tue Aug 11, 2009 2:16    Post subject: Reply with quote

Sounds like the WINE folks haven't implemented things all the way.

It would be possible to rework the injector code I posted to not use NtContinue. The change I would make would be to write out into the jump trampoline mov instructions to set all of the registers, followed by a jmp rel32 to branch to the old eip value in lieu of calling NtContinue. (Standard longjmp semantics not used due to a need to preserve volatile registers.)

The current nwnx4 release uses Detours and I've no idea what the state of WINE compatibility of that is.
Back to top
View user's profile Send private message
kuscotopia



Joined: 10 Aug 2009
Posts: 11

PostPosted: Tue Aug 11, 2009 2:42    Post subject: Reply with quote

I will have to take your word for it Skywing. I am not much of a windows developer as I prefer to stay as close to gcc as possible. Wink

Detours SEEMED to work. I am only basing that on not seeing any error messages fly-by (or in log files) while the module was loaded. A good test would be to load the demo module, just to see if database access is possible.

I won't be able to fire up the demo module tonight, but I will post any findings as soon as I have them.
Back to top
View user's profile Send private message
kuscotopia



Joined: 10 Aug 2009
Posts: 11

PostPosted: Thu Aug 13, 2009 2:02    Post subject: Reply with quote

I have to rescind my previous statement. The detours version does not work at all Smile. For the run I cloned a known good nwnx4 configuration and ran the server within both a windows VM and wine.

The windows version gave a success message regarding plugins whereas the wine emulated version continued to display timeout errors and spawning new instances of nwn2server. Although I was able to connect to and login to both hostings the windows hosted demo module was the only one able to manipulate data within the DB.

I am guessing this means detours flavor is failing to inject the dlls properly.

Skywing would you have the time/motivation to make the changes you mentioned and give your branch a go at wine emulation?
Back to top
View user's profile Send private message
mckillroy



Joined: 16 May 2005
Posts: 40

PostPosted: Mon Aug 17, 2009 14:13    Post subject: Reply with quote

The Nwnx4/Detours version runs for me on wine for Solaris.
It ~should~ run on Linux, but I heared varying success/failure.
The problem is to get the hook dll loaded on runtime.
Usually this is done by nwnx4.
Since it doesn't work natively the workaround I use is to edit
the import table of the so called PE-header of the server executable.
The executable then "thinks" it needs the hook dll natively and thus the dll
gets loaded by the run-time linker of windows / wine and not by nwnx4.

You can use the CFF Explorer program to do this edit.

http://www.ntcore.com/exsuite.php

You must import the "dummy" function exported by the hook dll
==>by ordinal into the import table.

Once you have done this the nwn2server executable will require the hook dll in any case. So be sure to have a backup of the server exe.


Good luck !!
_________________
/McKillroy
a.k.a Yorlik
Back to top
View user's profile Send private message
kuscotopia



Joined: 10 Aug 2009
Posts: 11

PostPosted: Thu Aug 20, 2009 2:42    Post subject: Reply with quote

Well...maybe it is me...but importing NWNX4_Hook.dll into nwn2server.exe via CFF Explorer didn't change any of my results.

For a control, I have cloned my setup (with "improved" executable) in a windows VM and under wine.

Under windows, everything loads great. I see success messages NWNX4_GUI, nwnx4 log files are generated, and the demo module works just great.

Under wine though I see the same problem I have encountered previously. NWNX4_GUI comes up starts the server process and although the server loads the demo module, NWNX4 reports a failure to load the module and begins starting new server processes. No log files are created for nwnx4 or error messages reported. Connecting to the module succeeds but no database access. The only difference I see is a message when I shutdown nwn2server which reports, "NWNx4 shutting down."

Am I missing a dependency for NWNx4 that is preventing proper loading of nwn2server of the xp_* plugins?
Back to top
View user's profile Send private message
mckillroy



Joined: 16 May 2005
Posts: 40

PostPosted: Wed Aug 26, 2009 9:59    Post subject: Reply with quote

It is possible you need things not found in the native wine installation.
I suggest you look for the "winetricks" script to add some common stuff needed by many programs, like directX and such.
You should also try to run the hacked executable directly under your windows vm and see if it loads the hook dll even without nwnx4 (which should happen) and then check the demo module.

Good luck.
_________________
/McKillroy
a.k.a Yorlik
Back to top
View user's profile Send private message
kuscotopia



Joined: 10 Aug 2009
Posts: 11

PostPosted: Tue Mar 16, 2010 3:29    Post subject: Reply with quote

After a long break..I have returned Smile.

So, after a few months break..I have come around to trying again, sadly the same results as before.

To answer you previous post mckillroy, I have followed the standard install procedure for NWN2 as listed on WineHQ. Below are the winetricks I have installed:

vcrun2005, directx9, dotnet20

alternatively, I also tried this configuration:

vrun2005, directx9, mono-2.6.1

CFF Explore was a no-go for me, I can't even get the spliced server binary on widows to properly run the demo modules. Each time I log into the module I am met with warning messages about NWNX4 not being properly installed (unless of course I use NWNX4_GUI.exe).

*Sigh* So at this point I am still at a loss...mckillroy, what version of wine are your running? Could you perhaps share an install procedure using the latest NWNx4 1.09? Or perhaps, list which winetricks you used?

Thanks!
Back to top
View user's profile Send private message
Skywing



Joined: 03 Jan 2008
Posts: 321

PostPosted: Wed Mar 17, 2010 19:35    Post subject: Reply with quote

My branch and the current one release use completely different methods of injecting the nwnx hook module -- did you end up trying both on the latest wine? Maybe wine has enough implemented for one of the mechanisms to work now.
Back to top
View user's profile Send private message
kuscotopia



Joined: 10 Aug 2009
Posts: 11

PostPosted: Thu Mar 18, 2010 4:20    Post subject: Reply with quote

I have tried both Skywing...I just updated to the latest version of wine, 1.1.39.

I see the same output from NWNX4_GUI.exe from your branch as I did before:

Code:
2:10:45 AM: Running in GUI mode.
2:10:45 AM: Worker thread started.
2:10:45 AM: Starting the NWN Server.
2:10:51 AM: * Couldn't receive response from server confirming message loop running (5).
2:10:51 AM: * Failed to wait for server message loop to begin.
2:10:56 AM: * Couldn't receive response from server confirming message loop running (5).
2:10:57 AM: * Failed to wait for server message loop to begin.


The server process actually starts, but the communication path between your version of NWNX4 and the server is missing...I see the following from wine:

Code:
fixme:advapi:SetEntriesInAclA 1 0x33f74c (nil) 0x33f784
fixme:advapi:SetSecurityInfo stub
fixme:advapi:SetEntriesInAclA 1 0x33f738 (nil) 0x33f780
fixme:advapi:SetSecurityInfo stub
fixme:advapi:SetEntriesInAclA 1 0x33f758 (nil) 0x33f7a0
fixme:advapi:SetSecurityInfo stub
fixme:system:SetProcessDPIAware stub!
fixme:dwmapi:DwmIsCompositionEnabled 0x33e8a8
fixme:iphlpapi:NotifyAddrChange (Handle 0xd4e928, overlapped 0xd4e930): stub
fixme:iphlpapi:GetAdaptersAddresses no support for IPv6 addresses
02:16:47: * IPC Server MyNWNXServer 42 started (DDE)
wine: Call from 0x7bc3e90f to unimplemented function ntdll.dll.NtContinue, aborting
err:seh:raise_exception Unhandled exception code 80000100 flags 1 addr 0x7bc3e90f
02:16:52: * IPC Server MyNWNXServer 44 started (DDE)
wine: Call from 0x7bc3e90f to unimplemented function ntdll.dll.NtContinue, aborting
err:seh:raise_exception Unhandled exception code 80000100 flags 1 addr 0x7bc3e90f


So...here we are, same story. Is there any chance we can remove the dependency on ntcontinue? As the server process is actually starting, does this mean the dlls are being loaded properly?
Back to top
View user's profile Send private message
Skywing



Joined: 03 Jan 2008
Posts: 321

PostPosted: Fri Mar 19, 2010 0:06    Post subject: Reply with quote

Yes, you could change the injected code to emit some machine code to restore the register context manually as immediate operands.

NtContinue is just used as essentially a longjmp to restore the original thread context here. It's probably best to replace the dependency on the undocumented API anyway, but I already had this code laying around and it works on (full) Windows.

For example, you could write out a series of instructions in the injected blob like so:

mov eax, 0x<oldeax>
mov ebx, 0x<oldebx>
mov esp, 0x<oldesp>
...
jmp <relative-32 delta to oldeip>
Back to top
View user's profile Send private message
kuscotopia



Joined: 10 Aug 2009
Posts: 11

PostPosted: Fri Mar 19, 2010 14:59    Post subject: Reply with quote

I have very little experience with long-jumps and windows development, so I am sure the next few weeks of hackery should prove interesting. Skywing if you are feeling ambitious and would be willing to help me with the assembly generation, I certainly need the help in that department

I have checked out the source code and managed to find a copy of Visual Studio 2005 Express. The plan is to poke around the code a bit, just to see if I can get passed the timeout.

In the main-line code, the detours dll injection is not failing which makes me wonder why the IPC is borked. It looks to just be a shared memory structure, so I wonder if I am hitting the injected code at all. The lack of log files during execution certainly supports this theory...

I don't know at which step the plugins initialize themselves, but perhaps it is after the initialized boolean gets set to true? I think my first test will be to break the IPC and force a manual sleep. Perhaps everything is working properly and we just need to blow passed the handshake...
Back to top
View user's profile Send private message
Skywing



Joined: 03 Jan 2008
Posts: 321

PostPosted: Sat Mar 20, 2010 2:13    Post subject: Reply with quote

The general sequence of events at a high level is:

- nwnx controller (service or gui) launches nwn2server.exe (and arranges for the nwnx4_hook.dll module to be injected into nwn2server.exe).
- nwnx controller now waits for nwnx4_hook to signal that initialization is complete
- nwn2server.exe process is initialized and the injected nwnx4_hook.dll initializes (in nwn2server.exe address space)
- nwnx4_hook.dll loads all plugin modules, performs various other initial setup tasks, then indicates to the nwnx controller that hook initialization has completed
- control within nwn2server.exe transfers to nwn2server's main program entry point
- nwnx controller receives notification that the hook dll has successfully spun up, and all is well
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Technical support All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group