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 
 
NWNX4 ... Looking Ahead

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



Joined: 03 Jan 2005
Posts: 107

PostPosted: Thu Oct 19, 2006 1:10    Post subject: NWNX4 ... Looking Ahead Reply with quote

I was quite surprised to find GFF editing routines buried in the exposed toolset dlls. Since I used GFF editing in combination with the Resource Plugin (how long before that one gets updated for x4?...) I was wondering if architecture can be readily built in to call C# dlls. The whole unmanaged, managed, COM solution gives me a headache but maybe someone out there has done this before and can whip it out quickly. Being able to get at the toolset GFF routines would be nice. Of course GFF is GFF and "finishing" a link between Leto Unicorn and NWNX could also be nice.
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Thu Oct 19, 2006 9:00    Post subject: Re: NWNX4 ... Looking Ahead Reply with quote

Blacksting wrote:
I was quite surprised to find GFF editing routines buried in the exposed toolset dlls. Since I used GFF editing in combination with the Resource Plugin (how long before that one gets updated for x4?...) I was wondering if architecture can be readily built in to call C# dlls. The whole unmanaged, managed, COM solution gives me a headache but maybe someone out there has done this before and can whip it out quickly. Being able to get at the toolset GFF routines would be nice. Of course GFF is GFF and "finishing" a link between Leto Unicorn and NWNX could also be nice.

Simple to do.... here's a little demo [it runs outside the toolset]

In C# - Add two references (Browse for them in your toolset folder)
NWN2Toolset.dll & OEIShared.dll

Code:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

//Add these 'includes'

using NWN2Toolset.NWN2.Data.Instances;
using OEIShared.IO.GFF;

namespace ItemSummary
{
  class Program
  {
    private const String _DataPath = @"D:\Neverwinter Nights 2\Presale-Toolset\Data\Templates";
    static void Main(string[] args)
    {
      DirectoryInfo Dir = new DirectoryInfo(_DataPath);
      FileInfo[] Files = Dir.GetFiles("*.UTI");
      foreach (FileInfo File in Files)
      {
        Console.WriteLine(File.Name);
        GFFFile gff = new GFFFile(File.FullName);
        GFFStructFieldDictionary dic = gff.TopLevelStruct.Fields;
        foreach (GFFField field in dic.Values)
        {
          if (!(field.IsComplex && field.IsComposite))
          {
            Console.WriteLine("{0} {1}", field.StringLabel, field.Value);
          }
        }
        break; 
      }
      Console.WriteLine();
      Console.WriteLine("Press any key to finish");
      Console.ReadKey();
    }
  }
}


Note: For this I've already unzipped the 'Templates.zip' - so this will find all the *.UTI files. (The break stops it after the first one)

The point is that it's really simple to access any of the file formats - in the Toolset (as a plugin) or outside it. The key is to add the References into your project.

No complaints, I just scratched this up as a proof-of-concept.
Hope this inspires a few out there with "Plugin-phobia".
**And some of this stuff will ALSO work with NWN1 files Wink

Cheers
Gryphyn


Last edited by Gryphyn on Thu Oct 19, 2006 15:48; edited 1 time in total
Back to top
View user's profile Send private message
xaltos



Joined: 03 Jun 2006
Posts: 31
Location: Germany

PostPosted: Thu Oct 19, 2006 10:07    Post subject: Reply with quote

oh , that is nice

That was exact the missing info Very Happy

And I was wondering where the plugin writers found all the extra infos about the format.
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Thu Oct 19, 2006 15:45    Post subject: Reply with quote

xaltos wrote:
oh , that is nice

That was exact the missing info Very Happy

And I was wondering where the plugin writers found all the extra infos about the format.


That's one of the nice things about .NET The Assemblies(dlls). There is a 'Reflection' aspect that allows you to 'describe' the contents of an Assembly, even to the level of 'generating' source code.

The early runner for doing this is Lutz Roeder's .NET Reflector.
With this tool you can 'inspect' the contents of an Assembly - and view 'Source' code {disassemble}

A magicians trick...
if you don't know how its done it seems like magic.

Cheers
Gryphyn
Back to top
View user's profile Send private message
Blacksting



Joined: 03 Jan 2005
Posts: 107

PostPosted: Thu Oct 19, 2006 21:10    Post subject: Reply with quote

The point of my question was not about writing C# applications to access the toolset dlls I am already doing this. The point of my post was how to access the toolset dlls from C++ (and thus NWNX4 directly.)
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Fri Oct 20, 2006 0:22    Post subject: Reply with quote

Blacksting wrote:
The point of my question was not about writing C# applications to access the toolset dlls I am already doing this. The point of my post was how to access the toolset dlls from C++ (and thus NWNX4 directly.)


Right Click on your Project
--> References...

[Add New Reference]
Browse for Assembly....

then in C++ code add the namespace.
eg
using namespace NWN2Toolset::Plugins;

and you're on your way.

Note:
Because regular C++ pointers (*) and references (&) cannot be tracked precisely, a handle-to object declarator is used.
Member selection through a handle (^) uses the pointer-to-member operator (->).
eg
MyClass ^ p_MyClass = gcnew MyClass;
p_MyClass->MyMethod();

Cheers
Gryphyn
Back to top
View user's profile Send private message
xaltos



Joined: 03 Jun 2006
Posts: 31
Location: Germany

PostPosted: Fri Oct 20, 2006 0:33    Post subject: Reply with quote

I haven't done it yet by myself, but this link could be helpful for you.

http://blogs.msdn.com/deeptanshuv/archive/2005/06/26/432870.aspx

It shows a way to use a managed DLL from a native Exe.
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