Author Topic: Scripts to modify masses of .dbrs  (Read 6438 times)

0 Members and 2 Guests are viewing this topic.

Not Yet Rated!

Offline WNG

  • Forum Moderator
  • Full Member
  • *
  • Topic Author
  • Posts: 615
  • Country: ca
  • Karma: +10/-0
  • Gender: Male
    • View Profile
    • Awards
  • Time Zone: -4
Scripts to modify masses of .dbrs
« on: 13 February 2019, 00:51:36 »
Hi, I came up with a new idea for a mod, but accomplishing it will require to modify tons of .dbrs, and I figured it would be nice to have a "script" to run that would modify the the files I need and their parameters in the background, only I've never done it or know if it's even possible.

Anyone can enlighten me?

Not Yet Rated!

Offline soa

  • Modder
  • Full Member
  • *
  • Posts: 517
  • Country: fr
  • Karma: +21/-0
    • View Profile
    • Awards
  • Time Zone: +1
Re: Scripts to modify masses of .dbrs
« Reply #1 on: 13 February 2019, 11:42:13 »
It depends on what you need to change in the dbrs.

I know you can use scripts to open mass files, get their content into like an Excel file where you can cut the data in two colums : parameter name and value.
Then you can adjust values of a single parameter for many files : for instance, size of monsters : +20% (or use any formula you want). Then reimport these changes into the actual dbrs automatically.
But I don't know how to make these scripts. I only know that Mostal used this a lot for his Lilith mod (think his script was in PHP, but any language would do).

If what you need is a little simpler, I may help. I do a lot of search and replace in mass files for Soulvizier (with Notepad++). Only thing is I never need to adjust values automatically like +33% to health, -5 for armor, etc.

Soulvizier for AE, Ragnarok and Atlantis [released] :
https://titanquestfans.net/index.php?topic=1201.0  / Discord : https://discord.gg/qs9t6AA
Overhaul mod with many new monsters, skills, items, features, balance and bugfixes. Increased difficulty.

Not Yet Rated!

Offline WNG

  • Forum Moderator
  • Full Member
  • *
  • Topic Author
  • Posts: 615
  • Country: ca
  • Karma: +10/-0
  • Gender: Male
    • View Profile
    • Awards
  • Time Zone: -4
Re: Scripts to modify masses of .dbrs
« Reply #2 on: 13 February 2019, 14:47:19 »
Well, I would definetly appreciate some guidance, since right now I'm quite lost.

Tried to open .dbrs in Excel, I can split the field name and the value into two columns, though I only found how to edit one at a time still. Opening several at once puts them on different pages and since it doesn't recognize the .dbr extension gives a warning message everytime I try to open one, making the whole thing extra more tedious.

Then I tried a simple script in form of a .bat file that changes the extension of all my .dbr to .xlsx, a format that Excel is supposed to read. Now it won't recognize it at all -.-



Not Yet Rated!

Offline nargil66

  • Forum Moderator
  • Full Member
  • *
  • Posts: 2493
  • Country: bg
  • Karma: +67/-1
  • Gender: Male
  • Mesh-Texturing Beautifier :)
    • View Profile
    • Awards
  • Time Zone: ?
Re: Scripts to modify masses of .dbrs
« Reply #3 on: 13 February 2019, 15:59:46 »
Have you tried Text Crawler? It can search/replace in multiple files at once. Dont know if that's what you need.

Not Yet Rated!

Offline soa

  • Modder
  • Full Member
  • *
  • Posts: 517
  • Country: fr
  • Karma: +21/-0
    • View Profile
    • Awards
  • Time Zone: +1
Re: Scripts to modify masses of .dbrs
« Reply #4 on: 13 February 2019, 16:53:51 »
Text Crawler or Notepad++ can open multiple dbrs at once.
You can replace multiple values at the same time, and using regular expressions can help a lot.

If you intend to modify several files at once, I think Excel is useful only if you have a script that open all files in the same page and after modifications, puts data back to dbrs. Excel allows you to use formulas on values, which (I think) is not possible with text editors such as Notepad ++ or Text Crawler.

If you have an example of what you are trying to do, maybe we could see how to help.
Soulvizier for AE, Ragnarok and Atlantis [released] :
https://titanquestfans.net/index.php?topic=1201.0  / Discord : https://discord.gg/qs9t6AA
Overhaul mod with many new monsters, skills, items, features, balance and bugfixes. Increased difficulty.

Not Yet Rated!

Offline WNG

  • Forum Moderator
  • Full Member
  • *
  • Topic Author
  • Posts: 615
  • Country: ca
  • Karma: +10/-0
  • Gender: Male
    • View Profile
    • Awards
  • Time Zone: -4
Re: Scripts to modify masses of .dbrs
« Reply #5 on: 13 February 2019, 18:32:12 »
Well, I won't hide it. I'm trying to grab items and divide by 2 (or reduce by 50%) every single parameter, that includes Armor Rating, Base Damage, bonus stats, etc. That would exclude stuff like Level requirement, Item cost, Scaling and all booleans.

You can see why I had no intention to do all of this by hand >.>




Not Yet Rated!

Offline soa

  • Modder
  • Full Member
  • *
  • Posts: 517
  • Country: fr
  • Karma: +21/-0
    • View Profile
    • Awards
  • Time Zone: +1
Re: Scripts to modify masses of .dbrs
« Reply #6 on: 13 February 2019, 20:16:52 »
Ok, you clearly need a script then. I don't know how to do it exactly.
Here is some code I exhumed from Mostal, to give you a general idea of what the script could look like.
Steps :
0 - I think he has some code to go from a dbr to the next (not included here)
1 - He gets the content of a dbr file as a string
2 - He uses a pattern to detect which lines have to be changed ; essentially, you would change every line with a number other than 0, except some that you should list and declare manually
3 - He stores every match into an array (in this example he was only looking for 1 parameter named characterlife)
4 - He creates another array named tab, where he splits the previous array with ";" (but I believe the separator in dbrs is "," and not ";")
5- He calculates the new value with "$valeurclef" (in your case should be -50% I guess)
6- Here he searches in $contenu (the content of the whole .dbr file) for the old value to be replaced with the new value. This would need to be adapted as you don't change only one parameter.
7- Return to step 2 until every line has been treated.
8- (not in his example) : he has to replace the content of the dbr file with $new.

            $contenu = file_get_contents($rep.$dir); // Step 1

            // Step 2
            if (preg_match_all('#characterLife,(.*?),#', $contenu, $resultat))
            {   
               // Step 3
               for($i = 0; $i < sizeof($resultat[$i]); $i++)
               {   
                  // Step 4
                  $tab = split(';',$resultat[1][$i]);
                 
                  $chaine = "";
                  for ($j = 0; $j < count($tab); $j++)
                  {
                     // Step 5
                     $recalcul = intval($tab[$j] * $valeurclef / 100);
                     $newresult = $tab[$j] + $recalcul;
                     echo "<br>+$valeurclef % de vie : $newresult";
                     $chaine = $chaine.";".$newresult;
                  }
                  $chaine = substr($chaine, 1);
                 
                  // Step 6
                  $new = str_replace ( "characterLife,".$resultat[1][$i], "characterLife,".$chaine, $contenu);
 
Soulvizier for AE, Ragnarok and Atlantis [released] :
https://titanquestfans.net/index.php?topic=1201.0  / Discord : https://discord.gg/qs9t6AA
Overhaul mod with many new monsters, skills, items, features, balance and bugfixes. Increased difficulty.

Not Yet Rated!

Offline WNG

  • Forum Moderator
  • Full Member
  • *
  • Topic Author
  • Posts: 615
  • Country: ca
  • Karma: +10/-0
  • Gender: Male
    • View Profile
    • Awards
  • Time Zone: -4
Re: Scripts to modify masses of .dbrs
« Reply #7 on: 14 February 2019, 21:48:07 »
Will try to work around this in my already low free-time. The task is still very big but it might be worth the hassle ^^

Many thanks for the help :)

Not Yet Rated!

Offline treborx555

  • Beginner
  • *
  • Posts: 6
  • Country: mon
  • Karma: +0/-0
  • Gender: Male
    • View Profile
    • Awards
  • Time Zone: ?
Re: Scripts to modify masses of .dbrs
« Reply #8 on: 16 February 2019, 21:09:23 »
I actually made my mod 99% with scripts.

I used unity game engine to create the UI cus i already worked with it recently.

Spent most of the time optimizing file loading and editing so it doesn't take minutes. Though idk how efficient it is on weak pcs.

It's on my github. It's called grim dawn cus i first used it there. But then i went to play titan quest so i used it here too cus the .dbr files are the same.

It works by creating a "tool button"

Code: [Select]
namespace GrimDawnModdingTool
{
    public class ToolTQAdjustPotionCosts : ToolButton
    {
        public override string Name { get => "ToolTQAdjustPotionCosts"; }
        public override string Description { get; }

        protected override void Action()
        {
            float multi = float.Parse(Save.Instance.InputCommand);

            List<GrimObject> list = new List<GrimObject>(FileManager.GetObjectsFromAllFilesInPath(Path.Combine(Save.Instance.FilesToEditPath, "records"), true).Where(x => x.FilePath.Contains("oneshot") && x.Dict.ContainsKey("Class") && x.Dict["Class"].Contains("OneShot_Potion")));

            var newlist = new List<GrimObject>();

            foreach (GrimObject obj in list) {
                foreach (var key in obj.Dict.Keys.ToList()) {
                    if (key.Contains("itemCost")) {
                        obj.Dict["itemCost"] = (multi * float.Parse(obj.Dict["itemCost"])) + "";
                    }
                }

                newlist.Add(obj);
            }

            FileManager.WriteCopy(Save.Instance.OutputPath, newlist);
        }
    }
}

So key notes, derive your class from tool button because i search all the classes and any that derive from it will be in the UI as a button to click.

FileManager has methods to load dbr files into objects i called GrimObject. These objects have filepath and a dictionary of the text values.

It contains 2 most important methods, GetObjectsFromAllFilesInPath and WriteCopy.

The last thing is the Save class. The Save.instance variable contains stuff like the inputted command, game path, output path etc.

link to unity project  (you need to install unity and then import this project to use it for now)
https://github.com/RobertSkalko/Grim-Dawn-Modding-Tool

link to all the scripts i did to make my mods
https://github.com/RobertSkalko/Grim-Dawn-Modding-Tool/tree/master/Assets/Scripts/Tools

I didn't clean the code much. It's actually a fork of the tool i used to mod soldak games which used a different file format.

Hope it helps!

Not Yet Rated!

Offline WNG

  • Forum Moderator
  • Full Member
  • *
  • Topic Author
  • Posts: 615
  • Country: ca
  • Karma: +10/-0
  • Gender: Male
    • View Profile
    • Awards
  • Time Zone: -4
Re: Scripts to modify masses of .dbrs
« Reply #9 on: 17 February 2019, 01:58:34 »
Will definetly try this if the PHP code fails. Many thanks ^^

Not Yet Rated!

Offline Vio

  • aka Violos
  • TQ Titans
  • Hero Member
  • *
  • Posts: 69
  • Country: de
  • Karma: +1/-0
  • Gender: Male
    • View Profile
    • Awards
Re: Scripts to modify masses of .dbrs
« Reply #10 on: 24 February 2019, 17:04:41 »
I use Life Software's "Mass Search and Replace Tool" for mass changes that the AM doesn't support.
There are others like it... but this does what it should.

It basically lets you make such scripts on the fly using direct comparison, wildcards or regular expressions.

Just check whether the changes applied were really what you intended.
Because otherwise the AM may start deleting parts of your DBRs that do not fit its templates anymore.
« Last Edit: 24 February 2019, 17:13:11 by Vio »

Tags:
 


SimplePortal 2.3.7 © 2008-2024, SimplePortal