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 
 
TMI fix (new thread from game obj array)

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development
View previous topic :: View next topic  
Author Message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Thu Nov 27, 2008 6:43    Post subject: TMI fix (new thread from game obj array) Reply with quote

From- http://www.nwnx.org/phpBB2/viewtopic.php?t=1167

I think that TMI is happening here:

Code:

.text:005BD1A1                 inc     ecx
.text:005BD1A2                 mov     eax, ecx
.text:005BD1A4                 cmp     eax, 20000h
.text:005BD1A9                 mov     [esi+8], ecx
.text:005BD1AC                 jge     loc_5BF535


ecx, the counter, is incremented (it's counting instructions). It's moved into the accumulator (eax) and compared with 20,000 hex, or 131,072. This number is apparently the long sought after TMI limit. It records this value in the stack somewhere (mov [esi+8], ecx), and if the counter is greater than 131,072 it jumps 5BF535. I'm thinking the function at 5BF535 (not shown in post) is just setting an error number, and then jumping to some I/O function which will flush out the dreaded TOO MANY INSTRUCTIONS message.

I'm really excited by my findings. Now I just got to write the plugin. The plugin templates we've been given so far are handlers from SetLocalString function hooks.

Can the maintainer of the NWNX source tell me how to proceed from here? I could use the SetLocalString call to form a function for resetting TMI, but that would mean tracing where ecx is stored (obviously its a register, but I'm assuming there is a pointer equivalent lying around somewhere) and punching a hole in it. Since memory allocation can be a fairly dynamic thing, I'm not sure if I feel comfortable promenading thorugh memory with my NWNX plugin to find it. At least today I'm not Smile Who knows about tomorrow? Any thoughts on the *best* way to go about writing a TMI fix now?
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Thu Nov 27, 2008 7:19    Post subject: Reply with quote

That's right, this is the TMI limit.
You can just change this value in the code memory. It's what the original plugin does.
By the way, esi is "this", which in this case is a CVirtualMachine object.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Thu Nov 27, 2008 9:57    Post subject: Reply with quote

Thank you so much virusman. I had done some local tests and had modified my nwserver.exe already, and even sent this information to some friends at Arelith, but its nice hearing it from an experienced debugger.

I'll set about writing something for it right away. Unless you beat me there, but either way, its a victory for the community =). TMI has been a thorn in the side of men and women all over the NWN world for FAR too long. It will be really nice to have this killed off.

I'll post here again when it is done. Hopefully I'll do a nice enough job of it to get it included in the modules selection at nwnx.org.
Back to top
View user's profile Send private message
acaos



Joined: 08 May 2007
Posts: 153

PostPosted: Thu Nov 27, 2008 10:46    Post subject: Reply with quote

It already exists for Linux:

nwnx_system

There's also an older nwnx_tmi plugin which only modifies the TMI limit. You could probably use one of those two as a base for coding yours.

Acaos
Back to top
View user's profile Send private message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Fri Nov 28, 2008 9:20    Post subject: Reply with quote

I think I blew those plugins away with this rather elegant implementation I came up with today. This one is a real fire and forget, I love it!

I'm really excited, its a remarkably elegant. Just one call to WriteProcessMemory =-)

I'll be posting it soon (lol I sitll have my VS open minimized and my NWNServer running as just successfully completing my first test of it). I just had to dash to the forums to share my excitement, hahah.

On a more serious note, what steps would I have to take to get a download of it hosted at nwnx.org? Any particular packaging instructions for the source and DLL or peer review needed? I'm ready to jump through any hoops - I feel it wouldn't serve the community well if it were lost in that gargantuan NWVault; it really needs the official backing and stamping of nwnx.org Smile
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Fri Nov 28, 2008 10:48    Post subject: Reply with quote

addicted2rpg wrote:
Just one call to WriteProcessMemory
You can use memcpy instead. NWNX plugins are running in nwserver process space.
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Fri Nov 28, 2008 11:27    Post subject: Reply with quote

I think I'll shoot myself now, especially since its all workingn and ready to ship Smile

But...I'll go back and change it for memcpy. If a thing should be done, it should be done well.
Back to top
View user's profile Send private message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Fri Nov 28, 2008 11:36    Post subject: Reply with quote

Ok, memcpy segfaulted. hmmm.

WriteProcessMemory was working... hmmm.

maybe I just phucked the pointers, but I really don't think so. I'm usually very careful about that. I think WriteProcessMemory is affording me some extra priviledges with the windows kernel as far as to what address space I can write to. Even within a process, there are limitations with the ANSI C functions.

argh...

edit: You do know I'm writing in the instruction image area, right?

Code:

void CNWNXTMI::ModifyInstructionImage() {
   SIZE_T numBytes;
   unsigned char countoverwrite;
   HANDLE procHandle;


   procHandle = GetCurrentProcess();
      

   if(unlimited == 1) {
      tmiPatternStart = tmiPatternStart + 3;
      countoverwrite = 0xC3;

   }
   else {
      tmiPatternStart = tmiPatternStart + 7;
      countoverwrite = 0xFF & (unsigned char)instruction_cap;
            
   }

   if(TRUE != WriteProcessMemory(procHandle, tmiPatternStart, &countoverwrite, 1, &numBytes)) {
      Log("o Couldn't write to the nwnserver process.  Your TMI settings have not been applied.\n");
      return;
   }


   if(*tmiPatternStart == countoverwrite) {
      Log("o New instruction settings successfully applied.\n");
   }

   CloseHandle(procHandle);
}


Here is my final version, as far as 1.0 goes Smile

http://metafocus.net/~cs60/addicteds_TMI.zip

Runs like a dream, but maybe we can shorten it sometime later if I can get that memcpy to work.
Back to top
View user's profile Send private message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Sun Nov 30, 2008 7:37    Post subject: Reply with quote

I've simplified the code some more and have polished up the documentation (which means its very raw by normal standards, but there IS documentation). I believe the PW world of Arelith may start using this in the future, it is still going through their quality assurance processes which of course is very understandable considering the number of users they have and the sensitivity and care that comes with supporting such a massive PW.

In any case, I've put it on the vault.

http://nwvault.ign.com/View.php?view=other.detail&id=1364
Back to top
View user's profile Send private message
Fireboar



Joined: 17 Feb 2008
Posts: 323

PostPosted: Sun Nov 30, 2008 11:58    Post subject: Reply with quote

addicted2rpg wrote:
I believe the PW world of Arelith may start using this in the future


That's an understatement. The impression I got from Mithreas, the lead scripter there, is that he's positively dancing at the prospect of finally losing that awful arbitrary limit on number of instructions. Seems to work perfectly every time in testing too, so I guess they're going to go live with it pretty soon and see if anything breaks (2x75-player servers is very different to a single 2 player test server).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development 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