Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

*.db editor(C# code)

Junior Spellweaver
Joined
Jul 9, 2014
Messages
168
Reaction score
53
Hi, guys.
It's example of ROM binary database editor(C# code).
This one include editor and item struct example.

View attachment Classes.zip


Ok, let's speak about more details.

What is *.db in most cases(exlude string*.db and some other)?
This is binary representation of array of the struct, which are specific for every db. You can find it(and import to C# or write your own code on your favourite language) in server or client code, "ObjectStruct.h" file for structs and "ObjectStructEx.cpp" for reader example.

All *.db, that can be readed or edited via this editor, based on GameObjDbStruct.
It's combination of some fields, that's are equals for all structs(look on MainStruct interface in attach) and union, that contains *.db struct.

So, when you wanna read binary from *.db to struct, you just read 4 bytes from 132 offset for count and 4 from 136 for size. It would give you amount of items in current *.db and size of struct. Also, it would give you possibility to manually add unknown fields to struct, if *.db would be changed.

Ok, let's look for usage now(I have example code for .


Code:
//Some extension methods for better abstraction
public static class Extension
{
        public static T Clone<T>(this T source)
        {
            var dcs = new System.Runtime.Serialization
                .DataContractSerializer(typeof(T));
            using (var ms = new MemoryStream())
            {
                dcs.WriteObject(ms, source);
                ms.Seek(0, SeekOrigin.Begin);
                return (T)dcs.ReadObject(ms);
            }
        }


        public static T Row<T>(this List<T> source, int baseguid, int guid) where T : Structures.MainStruct
        {
            if (source.Any(x => x.GUID == guid))
                source.Remove(source.First(x => x.GUID == guid));

            var row = source.First(x => x.GUID == baseguid).Clone();
            row.GUID = guid;
            source.Add(row);
            return source.First(x=>x.Equals(row));
        }
}

        //here you would read "zoneobject.db" from ROOTFOLDER+@"db\zoneobject.db" and deserialize it to GameObjectZoneStruct
       var dbLocation = new DBEditor<Structures.GameObjectZoneStruct>("zoneobject"); 
       //Get List<GameObjectZoneStruct> - collection of readed "rows"
       var location = dbLocation.objects;
       //Create new item, based on existing. If you need fully new item, just use new GameObjectZoneStruct() and fill it.
       var newLocation = location.Row(750116, 750999);
       //now you can work with this item directly and change it. For ex., let's mark this zone as dungeon
       newLocation.IsPrivateZone = 4;

       //also, C# have really cool thing called Linq. With it you can do tricks like that:
       location.Where(x => x.PrivateZoneType == 4).ToList().ForEach(x => x.PrivateZoneType = 0);
       //voila, all dungeons are not dungeons now. Or smth like that.

 

       //Ok, seems it's time to save table back to binary!
       dbLocation.saveChanges();
       //You would have edited *.db file in "db_result" folder.


Thanks for your attention.
 

Attachments

You must be registered for see attachments list
Junior Spellweaver
Joined
Jul 9, 2014
Messages
168
Reaction score
53
No problem.
Also, if you got, how it work, you always can post examples.
 
Newbie Spellweaver
Joined
Dec 30, 2016
Messages
13
Reaction score
0
Hey Turmalin,

its very usefull information and adding something in this tool. But I didnt find out a reference. can you give me a link about these library or I will be glad if you can share.

Missing references;
- romdb_editor : I didnt find runedatabase class when I ran
 
Last edited:
Back
Top