View previous topic :: View next topic |
Author |
Message |
Blacksting
Joined: 03 Jan 2005 Posts: 107
|
Posted: Thu Oct 19, 2006 1:10 Post subject: NWNX4 ... Looking Ahead |
|
|
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 |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Thu Oct 19, 2006 9:00 Post subject: Re: NWNX4 ... Looking Ahead |
|
|
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
Cheers
Gryphyn
Last edited by Gryphyn on Thu Oct 19, 2006 15:48; edited 1 time in total |
|
Back to top |
|
|
xaltos
Joined: 03 Jun 2006 Posts: 31 Location: Germany
|
Posted: Thu Oct 19, 2006 10:07 Post subject: |
|
|
oh , that is nice
That was exact the missing info
And I was wondering where the plugin writers found all the extra infos about the format. |
|
Back to top |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Thu Oct 19, 2006 15:45 Post subject: |
|
|
xaltos wrote: | oh , that is nice
That was exact the missing info
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 |
|
|
Blacksting
Joined: 03 Jan 2005 Posts: 107
|
Posted: Thu Oct 19, 2006 21:10 Post subject: |
|
|
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 |
|
|
Gryphyn
Joined: 20 Jan 2005 Posts: 431
|
Posted: Fri Oct 20, 2006 0:22 Post subject: |
|
|
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 |
|
|
xaltos
Joined: 03 Jun 2006 Posts: 31 Location: Germany
|
|
Back to top |
|
|
|