Skip to content

Instantly share code, notes, and snippets.

@FreeSlave
Created December 17, 2022 05:24
Show Gist options
  • Save FreeSlave/bb445196c2e6d2fc66b475505ffb01d4 to your computer and use it in GitHub Desktop.
Save FreeSlave/bb445196c2e6d2fc66b475505ffb01d4 to your computer and use it in GitHub Desktop.
Find 2048 spawnflag in .map file
import std.regex;
import std.stdio;
import std.file;
import std.conv;
void main(string[] args)
{
auto paramRegex = regex(`"(\w+)"\s+"(\w+)"`);
for (ulong i=1; i<args.length; ++i)
{
string fileName = args[i];
auto f = File(fileName, "r");
writefln("Map: %s\n", fileName);
auto byLine = f.byLineCopy;
while(!byLine.empty)
{
auto line = byLine.front;
bool shouldPop = true;
auto c = matchFirst(line, paramRegex);
if (!c.empty && c[1] == "classname")
{
auto className = c[2];
string targetName;
byLine.popFront();
while(!byLine.empty)
{
auto propLine = byLine.front;
auto prop = matchFirst(propLine, paramRegex);
if (!prop.empty)
{
auto propName = prop[1];
if (propName == "classname")
{
shouldPop = false;
break;
}
else if (propName == "targetname")
{
targetName = prop[2];
}
else if (propName == "spawnflags")
{
const spawnflags = to!uint(prop[2]);
if (spawnflags & 2048)
{
writefln("%s (%s): %s", className, targetName, spawnflags);
}
break;
}
}
byLine.popFront();
}
}
if (shouldPop && !byLine.empty)
byLine.popFront();
}
writeln();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment