Author Topic: [Idea] NWNCX plugin for overlay  (Read 2218 times)

Legacy_Valgav

  • Full Member
  • ***
  • Posts: 118
  • Karma: +0/-0
[Idea] NWNCX plugin for overlay
« on: May 02, 2015, 06:11:31 pm »


               

It's 2015 we're looking for water on Mars but we're still not able to add custom buttons in NWN. 


So I've spent last few days looking for workaround and I'm sharing results of my research because I'm lame coder and I'm unable to do that: 


The easiest way to add functionality is by using dll injection (just like nwnx and nwncx do) to hook OpenGl display to display anything(some nice lib is here). Then we need to control mouse clicks and cursor position. 


Then we can run some external code to process this hooks and connect to nwnx database(just like bridge from nwnx_cool does) to get stuff normally not possible to display from standard gui like reputation, hunger, custom spells menu or anything you can imagine. 


Or.. 


we can use C# form borderless app to create overlay in 3 minutes but it needs windowed game(try to create borderless windowed nwn its really pain) and do the same thing but it's quite lame that you can't use fullscreen. 




Tl;dr 


Nwn community need some easy xfire style overlay framework for server builders.



               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
[Idea] NWNCX plugin for overlay
« Reply #1 on: May 05, 2015, 05:17:59 pm »


               

http://www.codeproje...ing-raphook-dll


 


This demo's opengl overlays in action.


In theory - button clicks on a 'button' are basically just button clicks within a region defined by x,y start positions and length and height to calculate a hit box.


 


That in mind - simple Win32 hooks could be used to apply functionality to any button clicks that occur in a particular region.


 


Eg:


 


Draw a button at 


 


3,4


Which extends by 1,1 in both length and height.


 


When a User clicks : the Win32 hook fires


We evaluate the position of the click:


Was it within the 3,4 and 4,5 start and end positions?


 


If yes: Display the button depressed image (update the overlay code to display new graphic)


           Return to normal display when mouse button is released.


           Execute whatever functionality the button was meant to do


If no: do nothing


 


Using this methodology - a framework could in theory be created.


I am a .Net developer, so I envision everything in .Net code.


I am imagining some sort of friendly API along the lines of


 


 
GUIOverlay gui = new GUIOverlay("nwmain");
GUIButton ActivateAbilityX = new GUIButton();
ActivateAbilityX.DefaultImage = Resources.GetButtonImage();
ActivateAbilityX.DepressedImage = Resources.GetButtonPressedImage();
ActivateAbilityX.OnClick += new AbilityXExecute();
ActivateAbilityX.Position = new Point(3,4);
ActivateAbilityX.Height = 1.00;
ActivateAbilityX.Length = 2.00;
 
gui.AddButtonToGui(ActivateAbilityX);
 
 

 


The code above - if wrote appropriately, could be made in such a way that it registers the X,Y / length and height as a hitbox.


When a click is done in that region - it will execute the AbilityX Method.


 


The only tricky part is getting the Overlay to update in relation to the users clicking.


You would need to have a bridge between the Overlay hook in nwn / OpenGL, and the Win32 hooks.


The Overlay is effectively 'drawing' the GUI , including your static elements rapidly in a loop


You need to alert that Overlay loop that your custom content in the overlay has been updated.


Eg: Remove previous image, and update with the new image.


When the mouse click is released - go back to the default image.


 


 


I think if it were made in such a way that the Overlay code was constantly checking the 'state' of the GUIOverlay class for that process, and then the WIn32 hooks for mouse and keyboard just altered the content within that GUIOverlay class instance - then it would be a step closer to artifical gui element creation. 



               
               

               
            

Legacy_leo_x

  • Sr. Member
  • ****
  • Posts: 403
  • Karma: +0/-0
[Idea] NWNCX plugin for overlay
« Reply #2 on: May 06, 2015, 07:47:11 am »


               

On Higher Ground someone made the 'Higher Ground Extender' that could do overlays... they might be willing to share, I doubt it but maybe. '<img'>


 


A long long time ago someone also injected CrazyEddie's GUI, AngelScript and RakNet into the client, setup a whole new protocol on the side for building GUIs with scripts sent from the server.  Not sure if anyone would want to try resurrecting that -- I don't know if anyone ever even used it -- but I think I still have the source code if it's disappeared from the web.


 


The only problem is that it might mess up other overlays like xfire overwolf or whatever, steam, GOG galaxy, etc.



               
               

               
            

Legacy_Valgav

  • Full Member
  • ***
  • Posts: 118
  • Karma: +0/-0
[Idea] NWNCX plugin for overlay
« Reply #3 on: May 07, 2015, 09:37:38 pm »


               

I can experiment with connection and server side but injection of hooks? It's totally out of my league. But if there's some skilled code master who can handle that part it would be great.


The main problem is with hooking swapBuffer in opengl to force paint our custom gui at top of rendered scene and hooking mouse/keyboard clicks relative to position of cursor on screen(I know the terms but really have no idea how to write working code). Everything else is piece of cake '<img'>


               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
[Idea] NWNCX plugin for overlay
« Reply #4 on: May 11, 2015, 09:28:44 am »


               

https://github.com/Baaleos/NWNDotNet


 


This is a very rough implementation of a .Net hook for MainLoop - on the server side


I create a TCPListener class which creates a new open port for the server to receive commands on - for my own custom functionality.


 


Doing the same thing on the client side is just as easy.



 public DllInjectionResult Inject(string sProcName, string sDllPath)
        {
            if (!File.Exists(sDllPath))
            {
                return DllInjectionResult.DllNotFound;
            }
 
            uint _procId = 0;
 
            Process[] _procs = Process.GetProcesses();
            for (int i = 0; i < _procs.Length; i++)
            {
                if (_procs[i].ProcessName == sProcName)
                {
                    _procId = (uint)_procs[i].Id;
                    break;
                }
            }
 
            if (_procId == 0)
            {
                return DllInjectionResult.GameProcessNotFound;
            }
 
            if (!bInject(_procId, sDllPath))
            {
                return DllInjectionResult.InjectionFailed;
            }
 
            return DllInjectionResult.Success;
        }


MEH - I had posted loads more  - but Bioforums truncated it - 


Cant be arsed posting it again