Jump to content

Squishing XML sizes for quickbms (quality of life improvement for modding)


Recommended Posts

Hey guys,

 

Wanted to share the regex commands I use to squish XML sizes before I use the quickBMS re-importer (C# code, but you can just copy and use regex strings)

 

//"input" variable is the string containing the entire contents of the xml file
input = Regex.Replace(input, @"\t",                             " ", RegexOptions.Compiled);//turn tabs into spaces
input = Regex.Replace(input, @"\r\n",                           " ", RegexOptions.Compiled);//remove new lines
input = Regex.Replace(input, @" *= *",                          "=", RegexOptions.Compiled);//remove spaces between = signs
input = Regex.Replace(input, @" {2,}",                          " ", RegexOptions.Compiled);//remove double spaces
input = Regex.Replace(input, @"\<!--.+?--\>",                   "",  RegexOptions.Compiled);//remove comments

//decimal shortening
input = Regex.Replace(input, @"=\""(-?)0+([\d\.]+?)\""",       @"=""$1$2""", RegexOptions.Compiled);//remove leading 0s
input = Regex.Replace(input, @"=\""(-?)(\d*?\.\d*?)0+\""",     @"=""$1$2""", RegexOptions.Compiled);//remove trailing 0s
input = Regex.Replace(input, @"=\""(-?)(\d+)\.\""",            @"=""$1$2""", RegexOptions.Compiled);//remove trailing decimals (1. -> 1)
input = Regex.Replace(input, @"=\""-?[\.0]\""",                @"=""0""",    RegexOptions.Compiled);//turns '.', '-.', '-0' to 0

I've used this on a bunch of files so far and they all work great.

 

Using this will drastically reduce the xml sizes so that you have much more freedom to add/modify things (on the order of ~thousands of extra characters!). Only important thing is to make sure to pad the resulting file with spaces to make sure it is the same size as the base xml.

 

The way I use this is I have a "changes" directory where I use do my normal xml modifications and then I run a normalization script to do the squish/padding of all the changed files to a new directory which I use as the input argument for quickBMS.

 

If anyone is interested I can upload my entire script.

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...