Jump to content

Weird Binary Code Conversion?


Monkuar
Go to solution Solved by mac_gyver,

Recommended Posts

Been looking at the mysql patterns for this very old game that was made in 1999-2001 called "Return Of Warrior" (Downloaded some private server files and checked how they stored the equipments and items for players)

 

Looked into their mysql column for users equipment and it was a binary code: (0xB62600000000B7260000000000000000000000000000B5040000BF230000). And the user only had a 1h Sword with 2-5 damage on it, etc. (Weird?)  How is this data read and stored? Would i need the source code in c++ to read it out?

 

And for users inventory it looks like this:

 

nHWXGwX.png

 

hcN6yps.png

 

So i'm just wondering, what kind of storing method was this and wouldn't be terrible for scaling and pulling data? For my game, I have a simple user_equip_items and user_misc_items (for potions/scrolls/enhancments/etc) and equips for gear.  And then just calling them from the table....   How would all this work via the way the binarycode does above? (I've always wondered this) Btw, the game is coded in c I believe.

 

AND to make this Question PHP Relevant!....  How would we read and store this binary data in PHP? (Example, getting a 2-5 dmg 1h sword from that equip field data lol)

 

The real question is, were the developers very smart doing it this way? Or stupid?  (serious question btw)

Edited by Monkuar
Link to comment
Share on other sites

My guess would be they just stuff a struct value in there in binary format. Without the C/C++ code that interacts with the database, one can only guess really. You'll need to get that source and review it to know for sure what they are doing.

 

As far as reading such a value with PHP: unpack

 

 

Whether what they did is a good idea or not depends on what exactly needs to be done with the data. If they never need to search through it then something like that is fine. I've done similar with storing serialized/json_encoded arrays in a DB field when the data does not need to be searched in any way, just stored.

Link to comment
Share on other sites

  • Solution

the data is a hexadecimal value, apparently padded to the full length of all possible fields. you would need to know what the individual bits, hex characters, or groups of hex characters mean in order to store/retrieve/test specific information in the value. you can retrieve/test any hex character(4 bits) or group of hex characters using a SUBSTRING() function in the query. i've not used any of the mysql database bit instructions, but you can probably also use bit_and/or/xor statements to test or set/reset individual bits in the value.

 

this is basically packing multiple values into one database column, rather than normalizing the data and storing each piece of data as a row with a key/value in a table. i.e. saving some storage at the cost of more complicated/slower code/queries and requiring altering the code and data if any thing needs to be added, where as, for normalized data, to add any choice, you simply add a row of data.

Link to comment
Share on other sites

Looking at all that hexadecimal brings back painful memories of the assembly language course I took 10+ years ago.... :shudder:

 

 

Yeah, I could see why this game was developed/coded around 99 and 2001. Probably before that too, the origin of this game was "RYL" Risk Your Life, developed by a company called "GamaSoft".  Game is a very fast-paced game, so I always wondered how they stored their equipment and inventory stuff.   I guess they did it the worst way possible.  

 

Since Im creating my own rpg game. for my inventory system, it's very simple.

 

just grab all user's items by user_id = 4 (me) and have a position column, [ 1 - 36 ] would tell each slot the user dragged the item to.  Then just put those in a multi demi lovato array, and spit them out :D [ No pun Demi Lovato <3 ]

 

This is what I do with my game.  

 

My only issue is that, I am not using a websocket or socket.io bcz it's not working on windows so I cant really test with it. I'm simply doing onclick ajax calls via jquery. I might do some comet, long polling for PVP battles, but not sure. I need to finish all my serverside stuff done first.  now im working a Loot allocation system, which is weird because I don't want to waste queries by checking if a user owns a Health Potion already, to just increase the quantity of it, or just insert it into a new row, then update it when they go to their inventory page.

 

These decisions and looking into how these older games stored info, makes my experience very interesting while making my game, I'm glad I did not do it this binary way.  But maybe that was the Norm back then?

 

In any event, thanks all for the replies, I feel like I am at closure now, great info lol. I was always curious about how they stored their stuff.  Looks confusing as crap imo.  Unless we got source code of their C File to decode it all?  But still wouldn't really matter, Im never doing it this way, rather I just add a new row.. lol

 

Btw, I'll be looking into that pack function, seems pretty close to what they did within their c file. Ty Kicken! (Plus it makes me feel kinda cool to do it that way, but i bet optimizations as in-compared to other functions are terrible scaled)

 

Edit: 

mac_gyver You actually joined on my bday, ironically u got the best answer solved for this topic, lol ! Edited by Monkuar
Link to comment
Share on other sites

I guess they did it the worst way possible.

You've gotta keep in mind the times when these things were developed. Sometimes the best way from an organizational point of view is not the best way from a speed point of view, and speed may be of greater value than organization in some instances. I remember my first PC that I got back in '98 was 233mhz processor with 32MB of RAM and a 2gig HD. On systems like that, or with less specs, storing things in a perfectly normalized manner may have taken up too much memory or processing time compared to a serialized format.

 

Whether something is stored in a good way or a bad way is not a black-n-white line, one has to take into account how the data needs to be used, and what the requirements of the application are.

 

(edit: I think my pc may have actually been 16mb ram out of the box, and I upgraded it to 32 after a year or so).

Edited by kicken
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.