magic/rare DWORD decoding in Classic
#1
Hi all, this is my first post here. I usually hang out on the diabloii.net forums but I have a question that no-one has been able to answer so far :( I am writing a program to read the .d2s game files and I have a rather crude working Windows version for 1.07-1.09 here . However, in attempting an upgrade for Classic based on the info by Jamella, I found that I cannot decode the DWORD data for the magical mods on the items. I have searched high and low and was pointed here. On the old Lurker forums, I saw a post by Nuttzy99 about this same problem but the post had nothing i could work with. I tried looking for the PDF file that contained the source code to Jamella but the site is down and no-one seems to have it. It would appear that Jarulf has this info based on that post so i was wondering if he (or anyone else) could help. Thanks

--T
Reply
#2
On this same topic, does anyone have the Jamella or John Doe editor code I could look at?

--T
Reply
#3
There was a vaguely related post about this on dii.net ;)

http://forums.rpgforums.net/showthread.php...threadid=137287

However the discussion is about the seed for the various item generation.

There is no algorithm in the post but what was hinted at is that the function that maps the affixes into the item works with a hash (your DWORD I suppose).
Perhaps its a one-way hash and can't be decoded, I actually dont know this part (the game only needs forward hashing functionality to function). From memory Jamellas didn't let you stick any properties on a made-up rare item but instead had a 'generate a rare for item type X' button.

In any case if Ruvanal/Jarulf read this they should be able to shed more light on this.
Reply
#4
This is actually a different topic but somehow related I guess. I've read that thread before. I already asked Ruvanal but he doesn't seem to know so I'm waiting for a response from Jarulf. Thanks.

--T
Reply
#5
Hmm, I don't remember well (and certainly have not written it down) the old way of generating items. In much, the part about the magical properties is actually pretty much the same, although the current data tables differ some. Since the game only used to save the seeds (what you seem to call dword, but that is typically just a variable size) and the each game recreate the item, you actually need to have a built in feature to fully recreate (basically also thus create) an item, in the exact same way the game do (or did in this case since it is ild versions). That is the ONLY way.

From scetchy memory, there should be two seeds for items. One that is mainly used for non magical properties such as the exact DR in the range for an armor and ammount of items in stacked ones. The other is used for magical properties. THat seed is used first to actually determine the quality (yes despite that aspect being saved seperately). That step has a variable number of random numbers depending in quality. next it depends on the actual item type. For a magic item (blue), ther random rolls should be first to determine if it is a suffix or prefix, then it should be a random roll to pick one of the possible (for the specific item and case) affix, then agaon for the second one. Note if it was no prefix, it doesn't roll to pick one. And so on. For rare items it get more complicated but the process is more or less the same.

Finally note that you probably need to handle failed set and uniques as well.

This is in no way an exact help on how to do it though and you either need to go reread all the code for it (and I believe it might have differed slightly inbetween some versions, especially the save file and how it stored it, for example when it introduced the compact save) but I think item generation for the most was identical up until the expansion since any change would break existing items (morph them).

As for the save file. I have actually in the past week or so looked some at the current version (I have forgot ALL about older version I once looked at, think it was 1.04). If you want to exchange information about the save file, it would be fine. there are a few things I have not yet pinpointed.


Oh, and you might want to search the old news archieve at this site, espeically for the month of july to, say, september 2000 (or whatever the year the game was released). I posted several posts back then on various aspects of the game, including the item generation. Although not technical in nature, it should give a quite step by step procedure for how items are generated and you should be able to see in which order and what random decisions are made.
There are three types of people in the world. Those who can count and those who can't.
Reply
#6
I'd posted C code for the D2 RNG in this thread:

http://www.lurkerlounge.com/cgi-bin/forum/...&forum=Workshop

BTW, hakai_no_tenshi, thanks for posting, this is something I'm interested in as well



-- CH
Reply
#7
Cool, that's a first step in the right direction. :D I just wish someone would keep a repository of all these things in one place. It's sad when people like Jamella and John Doe keep their work secret and becomes lost knowledge. Do you think you got that comment from the source code that Jamella posted? I'd really like a copy of it if *anyone* has it.

Jarulf: I'll go hunt for the item generation posts. Thanks. I really hope to have Classi decoded. Unfortunately, there is only one seed in 1.03- and two seeds in 1.04+ ... I'm not quite sure how this works. Here is one post that had some info but nothing I could I could really work with :( I just wish I knew where to start. I'll send nutzzy99 an email and see what he says.

--T
Reply
#8
hakai_no_tenshi,Feb 28 2003, 07:03 AM Wrote:Cool, that's a first step in the right direction. :D I just wish someone would keep a repository of all these things in one place. It's sad when people like Jamella and John Doe keep their work secret and becomes lost knowledge. Do you think you got that comment from the source code that Jamella posted? I'd really like a copy of it if *anyone* has it.

Jarulf: I'll go hunt for the item generation posts. Thanks. I really hope to have Classi decoded. Unfortunately, there is only one seed in 1.03- and two seeds in 1.04+ ... I'm not quite sure how this works. Here is one post that had some info but nothing I could I could really work with :( I just wish I knew where to start. I'll send nutzzy99 an email and see what he says.

--T
I don't really keep things secret, I post things for people to understand the game though not posting what would basically be copies of the code.

The most important things to remember about item generation is that it is basically done by a stream of random values, of which the first is saved with the item (when there are two one is actually only used for a few things like ammount of items in stack, exact DR and so on, the other is used for ALL magical properties and quality determination, I supose in old versions it was simply just one used for all things).

So you really only need to figure out what random values are rolled for for an item.

First off (this is from memory), the game use the seed to determine the quality of the item (I think the quality is actually saved with the item, but it still goes through it to get to the correct seed used for the magical properties.

This is done more or less as today. You need to use the correct txt table to get the correct values for each quality of the specific game version you work with. Then calculate a number. This is more or less:

Number = Val - mlvl/divisor

I think for some qualities the divisor was not used though, not sure.

The game then do a Rnd[Number] and if the result was 0, that quality was picked, otherwise the game proceeded to the quality (rare was done before set in those old versions).

As soon as a quality was picked, the game proceeded to the actual code, specific for each quality (it is possible that for 1.03 and older that the game did the DR and suich inbetween here, no idea).

So you need seperate code for each quality.

For magic items the game was now to pick a prefix. First there is a random roll (with 50/50 chance that is a Rnd[2]) if it exists. Then the game build a list of all affixes possible and do a Rnd[number of possible affixes] to pick one. Then it do the same for suffix. Note, even if no prefix was picked and a suffix is needed, it still roll for it. It just discards the result if a suffix is needed. Then pick a suffix.

For rare items it is pretty much the same. First though, two random rolls are made to pick prefix and suffix NAMES. Again, you need to use the ingame data fileds to build the proper list of possible ones based on item types and pick on. Next it rolls for number of affixes.

The for EACH affix, it loops up to 250 times (I think) until an affix is actually chose in the loop then the loop stop. First it make another 50/50 roll to see if it is a prefix or suffix (remember, max three of each though, but I think it still rolled for it even if it then forced picked the other).
Next it picks a prefix or suffix in the exact same way as for a magical item. It DO roll the 50/50 chance but discards it since it is a forced pick when the item is rare. Build the list and pick one affix at random. Next it needs to check if the affix's group allready had an affix picked, if so it loop arround otherwise it pick that affix.

Uniques and sets are quite straight forward, pick one at random (for sets I believe I detelaied the procedure and how it made some sets more common in one post) but for uniques it is no need since it pick the first one not yet in existance in a game. Now, to recreate the item, you should allready find the exact set/unique number in the save file so no need to do anything I think.

Now if I recall correctly, each affix is added to the item AS IT IS PICKED. So you need to insert code that use a rnadom number to determine any possible random value of the affix's property. Some affixes has multiple properties by the way.

After all this the item should be almost done I think. But for some item types it pick the specific +spell properties. That is quite a compliacted thing that I really can't reember detailed enough to explain here. I think it as well is detailied very well in some post (a bit later in time, perhaps during fall 2000) and it should probably be enough to figure out how the seed is used, that is what random rolls are done.

Hope this helps soke. I guess you have to try a bit and see when you get it correctly.
There are three types of people in the world. Those who can count and those who can't.
Reply
#9
Wow, I'll give that a shot with the PRNG and a Classic data file I have. I'll post the code if/when I get it to work.

--T
Reply
#10
AHA! I just got my hands on the original jamella source code :D As Nuttzy99 said on the old forums, it's a lot of spaghetti code (with some meatballs and ragu sauce thrown in) so it's a bit hard to understand. I'll clean it up and post code snippets later.

--T
Reply
#11
Atma looks pretty cool--and it appears to decode all my mules and all their items correctly, something neither Jamella nor ShadowMaster can. Are you going to release source and/or a library for it?
Reply
#12
Hmm .. I hadn't thought about that yet. I'm still working on the new version which has full blown muling ability (drag-and-drop) and bunch of other neat features like multiple windows... basically a souped up Jamella/Shadowmaster. Once I get the item muling down, I'll probably start adding things like item editing. here are 3 screenshots of what it's looking like so far

# 1

# 2

# 3




--T
Reply
#13
I am so tired of half-functioning character/item editors for 1.09.

If you're feeling friendly, do me a favor and allow the program to handle modded txt files too. B)
Reply
#14
FoxBat,Mar 13 2003, 11:24 AM Wrote:I am so tired of half-functioning character/item editors for 1.09.

If you're feeling friendly, do me a favor and allow the program to handle modded txt files too.  B)
Unfortunately FoxBat, most of the data tables he is using are internal and are not referencing the *.txt files to drive the database. This would make it very difficult to allow it to work with a mod game unless he changes the way the coding is being done.

That is one of the things that I had liked about mjan's TC calculator. It would read the appropriate *.txt files to generate its results. This would allow you to substitute the modded files and still get an idea of who could drop what (and many of the other variations).
Reply
#15
Well, i have released a beta version of it on the Single Player Forums on diabloii.net . The release thread is here and the current discussion thread is here. Currently, i use internal tables that I ripped out of the MPQ files and reformatted for my own use. However, i am currently working on a new data engine that reads the .txt files directly so it will be compatible with MODS and 1.10 when it's finished.

--T
Reply
#16
Albeit a bit late, but I've recently been doing research into the same subject. I've found quite a tome of information at:
http://www.xmission.com/%7Etrevin/DiabloII...ile_Format.html

I've gotten pretty much everything in that document to work (using perl), and thus verified it. I'm currently running into a bug WRT SevenLances "normal" unique quest items that aren't seen in LoD like the Quill and Spleen and various other body parts.

Other than that, the spec looks very accurate if missing a few things such as the Iron Golem specification.
Reply
#17
yah, that is a good site and quite complete and accurate with only a few minor errors or problems. I think he is aware of the site though. As far as I could see, it is mostly about the current save file version though, not the old ones. There used to exist some web pages for old save files but they seem either gone or not up.

Anyway, if you have been looking into save files yourself and found anything new about them or additional info, feel free to join in on the thread over at Phrozen Keep. I have tried to collect information about the save file there from as many sources as possible (including checking myself for the most part). I have not had time to update it much lately and still have a whole bunch of things to add that I allready know, but still.

So if you know anything NOT present (or correction to) in that site, feel free to tell it if you want:

http://phrozenkeep.it-point.com/forum/view...opic.php?t=9011
There are three types of people in the world. Those who can count and those who can't.
Reply
#18
Well, I haven't found anything on his site that you haven't covered (and more). If you are looking for info on 1.07/1.08, I have discovered a few differences from 1.09.

--T
Reply
#19
hakai_no_tenshi,Mar 30 2003, 03:18 AM Wrote:Well, I haven't found anything on his site that you haven't covered (and more). If you are looking for info on 1.07/1.08, I have discovered a few differences from 1.09.

--T
Nah, I only look for 1.09 version, I skip older stuff. Will update it for 1.10 as soon as it is out, shouldn't be any major changes.

By the way, at the very end of item data but just before the stat data of it (that is, where it store the list of actual stat values), there seem to be a flag that is either 0 or 1 and if 1, there should be 2 32 bit values (it is right after all special info like personalization and such). Have you ever seen the value 1 here, and if so, do you know what the 2 32 bit values represent?
There are three types of people in the world. Those who can count and those who can't.
Reply
#20
Quick queston .. since I'm doing my programming on 32 bit Windows, does anyone have the PRNG function written for 32 bit systems? It uses 64 bit arithmetic so I'd have to do lots of bit shifting all over the place.

--T
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)