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 
 
Serialization of nwn objects

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



Joined: 02 Sep 2007
Posts: 830

PostPosted: Thu Jun 21, 2012 17:42    Post subject: Serialization of nwn objects Reply with quote

Hi All,
Quick question

When the hooked SCO/RCO are used, it retrieves the data from the database, which if I recall, is a format of blob? (binary)

I was just wondering.
If you were to do a manual select on this, and try to return the data.
(Assuming you had a string buffer that was large enough to contain the data)

Would it be possible to actually have a serialized string that contains the data of that object/item.

I kinda like the idea that you could sort of itemize objects, and save them off as files in the file system.

nwnx_system has this method

int NWNX_WriteStringToTextFile( string sFile, string sData, int nNextLine = TRUE );

Which I would love to be able to use, to parcel objects up, and save as files in a folder.

It would give the community the ability to save and trade objects/items/gear in a format that doesnt require importing of uti or erf files.

Instead you download the binary file for it, and have your nwnscript read the text, and import to database again, and then retrieve from database in game.


Sound feasible?
Back to top
View user's profile Send private message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Thu Jun 21, 2012 17:52    Post subject: Re: Serialization of nwn objects Reply with quote

Baaleos wrote:

Quick question
...
Would it be possible to actually have a serialized string that contains the data of that object/item.


According to the computation theories of Alan Turing, the answer is yes.

This isn't what you wanted to hear though, right?
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Thu Jun 21, 2012 17:55    Post subject: Reply with quote

actually, it is what I wanted to hear.

But was more interested in whether it would actually work.

eg Writing the binary information to a text file, and then re-reading it later, for re-importing.


I guess I was intrigued as to whether the blob data type can actually receive the data as a string.
I am gonna test it now with phpmyadmin
Back to top
View user's profile Send private message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Thu Jun 21, 2012 18:00    Post subject: Reply with quote

I recommend using 'unsigned char' for your string.

You can then think of each 0-255 value as a character.

Be sure to set your filewriter not to add new lines (i.e., binary write mode).
In C++, for example, fopen(f, path, "a+b")

Without this, the OS may corrupt your object by inserting unexpected newlines.

You can still add your own newlines (\n) and line feeds (\r), but you're in charge of them.
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Thu Jun 21, 2012 18:23    Post subject: Reply with quote

Actually,
I just found a way of doing it in native mySQL.


select VAL into outfile "C:/myFile.TXT" FIELDS TERMINATED BY '' ENCLOSED BY '' ESCAPED BY '' LINES TERMINATED BY '' STARTING BY '' from pwobjdata where id = 1;


This example exported the first stored object in pwobjdata to a text file on the server.

Importing would be a little more complex though. Need to ensure they go into the same format.
Best not to use TXT as a format, as it just encourages windows to treat it as a notepad file, allowing it to get modified in error.
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Thu Jun 21, 2012 18:32    Post subject: Reply with quote

Got the importing working

update pwobjdata set val = LOAD_FILE('C:/mydbdata.itp') where id = 10

This has imported the data from the file, to the database, into another row.


I've exported the table, and did a visual comparison on the string representation of the blob data
both the original, and the newly imported data match

Yay - I did it.
Back to top
View user's profile Send private message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Thu Jun 21, 2012 19:33    Post subject: Reply with quote

Grats dude Smile

Is this a solution step of your earlier problem of injecting things into the database contingent upon programatic events?
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Thu Jun 21, 2012 21:12    Post subject: Reply with quote

naw,
these were two separate things.

I've often toyed with the idea that ingame generate loot, could be stored online, in some way that would be tradeable, or even archiveable.

Todays test with the database exporting proves that its possible to export individual objects stored in the database, to a file system.


Imagine having a folder, containing subfolders with amulets, rings, armor, swords etc
Brings back memories of the Good ol days of Diablo 1.
Back to top
View user's profile Send private message
eeriegeek



Joined: 07 Jan 2008
Posts: 59

PostPosted: Thu Jun 21, 2012 22:33    Post subject: Reply with quote

Yes it's quite possible as you discovered. Smile

Read a little over here: http://nwnx.org/phpBB2/viewtopic.php?t=1900, (unfortunately Linux only, but you can browse the source code on GIT for ideas.) As part of an update/extention of the database interface I added a serialization interface to all of virusman's new serialization routines for placeables and such.

This does indeed allow full NWN object instances to be stored, transmitted, and recreated. By adding the hex encoding they can also be transmitted over non-binary-safe channels such as email.
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Fri Jun 22, 2012 11:21    Post subject: an idea Reply with quote

Most servers would have an area cleanup script of some sort.

What I have in mind, is that when an object/item is about to be cleared up, it actually gets archived via the above method.

eg - Transfered to a chest in another area for processing.

Then each item before being destroyed, is stored to database, and then exported to filesystem.

Then, I plan on having an online auction house type website setup, where my players can buy the items with virtual currency on the forum.

The items will have to have their item properties stored etc, but it will be fun to do.

This way, that fantastic piece of loot that the player forgot to lift, wont be lost forever, it will just go into the shop.

When the player buys the item, it is then re-loaded into the database from filesystem, and then Retrieved at a MailBox of sorts in game.

When retrieved successfully, the item is finally destroyed from the database/filesystem.
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Fri Jun 22, 2012 12:21    Post subject: Reply with quote

Why do you need to use filesystem for that at all? Store in the database, sell it, load back from database to the game. That's what SCO/RCO are made for.
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Fri Jun 22, 2012 12:57    Post subject: true Reply with quote

True - but I do like the idea of having a tangible file that I can see and interact with.

Not to mention, exported items from the database, I think can be opened in things like nwnexplorer.exe - at least characters exported in this manner, retain the BIC file structure.

Might even be possible to import/export to toolset too.
eg
Open temp0 folder
find the item you want
take the uti file
tell mySQL to import it to the database
go into game
Retrieve the object
Voila

Arguably - this can be done anyway with resman
Although the limitation of resman, is that it works with blueprints,

This however, would allow you to store a snapshot of the item, variables, properties and appearance and all.

The exported item would probably be re-usable by resman?

(Operating under the assumption that items would be exported in a UTI type format?/file structure)
Back to top
View user's profile Send private message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Fri Jun 22, 2012 18:05    Post subject: Re: true Reply with quote

Baaleos wrote:
True - but I do like the idea of having a tangible file that I can see and interact with.


Calling it now, Baaleos taking bribes to hex-edit player auctions!!!!!!
oh wait, the system hasn't been made yet Razz
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Fri Jun 22, 2012 18:10    Post subject: Reply with quote

Will admit,
I had my eyes set on a player auction house, but then I thought the logistics of it didnt seem right - the ingame loot is often so powerful, that it would be unaffordable my most, or inversely, that the ingame loot is so powerful, selling a single item could make you afford any other item.


So, I've actually decided to use this as part of an area cleanup system.

Cleanup Script finds unwanted items, adds to database/file system.
Captures the item properties and item description to a database/file.

The item is then listed on a webpage, and people in my PW can spend their forum currency to purchase the items.

I've done something like this before, where players could buy items on the forum, and receive them in-game,

This will be the first time though, that the system will capture items from ingame, and then advertise them on the forum, for collection in game.

It seems like a good way to ensure that good loot isnt missed, or goes to waste.

Eg - Some loot is spawned with alot of dynamic properties, which costs a little bit of processing power to generate.
Makes sense to not waste that item, after all the effort that went into generating it. Lol
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