Skip to content

Instantly share code, notes, and snippets.

@oatmealine
Last active December 5, 2020 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oatmealine/879f1a2cf394eecb2a6a667d131f0f1b to your computer and use it in GitHub Desktop.
Save oatmealine/879f1a2cf394eecb2a6a667d131f0f1b to your computer and use it in GitHub Desktop.
notitg template analyzer script
[
{
"name": "unknown",
"checks": []
},
{
"name": "no template",
"checks": [
{
"type": "filecontent",
"filename": ".sm",
"main": "#FGCHANGES:;",
"priority": 3
}
]
},
{
"name": "manual (#MODS)",
"checks": [
{
"type": "filecontent",
"filename": ".sm",
"main": "#MODS:",
"priority": 1
},
{
"type": "filecontent",
"filename": ".sm",
"main": "#ATTACKS:",
"priority": 1
}
]
},
{
"name": "xgml",
"checks": [
{
"type": "filecontent",
"filename": ".xml",
"main": "XGML CONFIG",
"priority": 5
},
{
"type": "folder",
"main": "core",
"priority": 1
}
]
},
{
"name": "xero",
"checks": [
{
"type": "folder",
"main": "xero",
"priority": 1
},
{
"type": "filename",
"main": "mods.lua",
"priority": 1
},
{
"type": "filename",
"main": "ease.lua",
"priority": 1
},
{
"type": "filecontent",
"filename": ".xml",
"main": "xero.add_mod",
"priority": 1
},
{
"type": "filecontent",
"filename": ".xml",
"main": "xero.loadfile",
"priority": 1
},
{
"type": "filecontent",
"filename": ".lua",
"main": "ease.combine",
"priority": 3
},
{
"type": "filecontent",
"filename": ".xml",
"main": "Linear Mod Reader",
"priority": 3
},
{
"type": "filecontent",
"filename": ".xml",
"main": "Mod reader code originally coded by Taronuke, and then Xero happened",
"priority": 3
},
{
"type": "folder",
"main": "template",
"priority": 1
},
{
"type": "filename",
"main": "loader.xml",
"priority": 2
},
{
"type": "filename",
"main": "reader.xml",
"priority": 2
},
{
"type": "filename",
"main": "addons.xml",
"priority": 1
},
{
"type": "folder",
"main": "addons",
"priority": 1
}
]
},
{
"name": "mirin",
"checks": [
{
"type": "folder",
"main": "template",
"priority": 1
},
{
"type": "folder",
"main": "core",
"priority": 1
},
{
"type": "folder",
"main": "addons",
"priority": 1
},
{
"type": "filename",
"main": "sort.xml",
"priority": 2
},
{
"type": "folder",
"main": "plugins",
"priority": 1
},
{
"type": "filename",
"main": "plugins.xml",
"priority": 3
},
{
"type": "filename",
"main": "std.xml",
"priority": 2
},
{
"type": "filecontent",
"filename": ".xml",
"main": "_G.xero",
"priority": 3
}
]
},
{
"name": "brothermojo",
"checks": [
{
"type": "filecontent",
"filename": ".xml",
"main": "self:tween(9999, 'pf_update()')",
"priority": 2
},
{
"type": "filecontent",
"filename": ".xml",
"main": "function pf_update()",
"priority": 2
}
]
},
{
"name": "exsch",
"checks": [
{
"type": "filename",
"main": "easing.xml",
"priority": 1
},
{
"type": "filename",
"main": "modhelpers.xml",
"priority": 1
},
{
"type": "filecontent",
"filename": ".xml",
"main": "ease mod reader",
"priority": 5
},
{
"type": "filecontent",
"filename": ".xml",
"main": "Ease table (includes func_ease)",
"priority": 5
}
]
},
{
"name": "exschtarofork",
"checks": [
{
"type": "filename",
"main": "easing.xml",
"priority": 1
},
{
"type": "filecontent",
"filename": ".xml",
"main": "original code by exschwasion, bastardized by taro",
"priority": 5
}
]
},
{
"name": "cering",
"checks": [
{
"type": "filename",
"main": "eases.xml",
"priority": 1
},
{
"type": "filename",
"main": "helpers.xml",
"priority": 1
},
{
"type": "filecontent",
"filename": ".xml",
"main": "cering's wacky all-in-one concat reader",
"priority": 5
}
]
},
{
"name": "taro2",
"checks": [
{
"type": "filecontent",
"filename": ".xml",
"main": "re-stolen by TaroNuke",
"priority": 3
},
{
"type": "filecontent",
"filename": ".xml",
"main": "local ThingsToGrab",
"priority": 0.5
}
]
},
{
"name": "josevarela",
"checks": [
{
"type": "filecontent",
"filename": ".xml",
"main": "--This table here reads through the mod_actions table, and runs the corresponding function from the table",
"priority": 2
}
]
},
{
"name": "mawaru",
"checks": [
{
"type": "filecontent",
"filename": ".xml",
"main": "-- GOD INPUT",
"priority": 1
}
]
},
{
"name": "taro1",
"checks": [
{
"type": "filecontent",
"filename": ".xml",
"main": "custom mod reader (c) 2015",
"priority": 5
},
{
"type": "filecontent",
"filename": ".xml",
"main": "#taronuke #yolo #swag #swag #amazon.co.jp #teamproofofconcept #swag",
"priority": 3
},
{
"type": "filecontent",
"filename": ".xml",
"main": "ACTION RPGS AINT GOT SHIT ON THIS",
"priority": 2
},
{
"type": "filecontent",
"filename": ".xml",
"main": "Action table by SteveReen, modified by TaroNuke",
"priority": 3
},
{
"type": "filecontent",
"filename": ".xml",
"main": "curmod<=table.getn(mods) and GAMESTATE:GetSongBeat()>=mods[curmod][1]",
"priority": 1
},
{
"type": "filecontent",
"filename": ".xml",
"main": "curmessage<= table.getn(messages) and GAMESTATE:GetSongBeat()>=messages[curmessage][1]",
"priority": 1
}
]
},
{
"name": "nayoto",
"checks": [
{
"type": "filecontent",
"filename": ".xml",
"main": "-- Mods Reader",
"priority": 1
},
{
"type": "filecontent",
"filename": ".xml",
"main": "-- Message Reader",
"priority": 1
},
{
"type": "filecontent",
"filename": ".xml",
"main": "-- Message reader",
"priority": 1
},
{
"type": "filecontent",
"filename": ".xml",
"main": "if (val[2] == 0 and CurrentTime <= val[1]+val[3]) or (val[2] == 1 and CurrentTime <= val[3]) then",
"priority": 2
}
]
},
{
"name": "heysora",
"checks": [
{
"type": "filecontent",
"filename": ".xml",
"main": "This template has been made by HeySora",
"priority": 5
},
{
"type": "filename",
"main": "Config.lua",
"priority": 1
}
]
},
{
"name": "windeu",
"checks": [
{
"type": "filecontent",
"filename": ".xml",
"main": "Mod reader code originally coded by Taronuke, remade to support end times and lengths.",
"priority": 5
},
{
"type": "filecontent",
"filename": ".xml",
"main": "Mod Reader Original by TaroNuke. Edited by WinDEU.",
"priority": 5
},
{
"type": "filecontent",
"filename": ".xml",
"main": "Remade by WinDEU.",
"priority": 5
}
]
},
{
"name": "ky",
"checks": [
{
"type": "folder",
"main": "init",
"priority": 1
},
{
"type": "filename",
"main": "init.xml",
"priority": 1
},
{
"type": "filename",
"main": "init_specific.xml",
"priority": 2
},
{
"type": "filecontent",
"filename": ".xml",
"main": "mod {",
"priority": 1
},
{
"type": "filecontent",
"filename": ".xml",
"main": "_G.________init",
"priority": 4
}
]
},
{
"name": "automaton",
"checks": [
{
"type": "filename",
"main": "build.js",
"priority": 1
},
{
"type": "folder",
"main": "automaton",
"priority": 5
},
{
"type": "filename",
"main": "automaton.json",
"priority": 5
},
{
"type": "filename",
"main": "automaton.lua",
"priority": 5
}
]
},
{
"name": "modlib",
"checks": [
{
"type": "filename",
"main": "modlib.lua",
"priority": 3
}
]
},
{
"name": "fmscat",
"checks": [
{
"type": "filename",
"main": "build.js",
"priority": 2
},
{
"type": "filename",
"main": "CatEvent.xml",
"priority": 2
},
{
"type": "filename",
"main": "cat-event.xml",
"priority": 2
},
{
"type": "filename",
"main": "cat-updater.xml",
"priority": 2
},
{
"type": "filename",
"main": "proxyguy.xml",
"priority": 2
}
]
},
{
"name": "jaez",
"checks": [
{
"type": "folder",
"main": "addons",
"priority": 1
},
{
"type": "filename",
"main": "addon_loader.xml",
"priority": 2
},
{
"type": "filename",
"main": "init_settings.xml",
"priority": 3
},
{
"type": "filecontent",
"filename": ".xml",
"main": "config.minimum_build",
"priority": 2
},
{
"type": "filecontent",
"filename": ".xml",
"main": "_G.melody_init",
"priority": 3
}
]
},
{
"name": "red and blue",
"checks": [
{
"type": "filename",
"main": "BGAnimation.ini",
"priority": 0.01
}
]
}
]
const fs = require('fs');
const path = require('path');
const categories = require('./categories.json');
let filepath = path.resolve(process.cwd(), process.argv[2] || __dirname);
let force = process.argv.includes('-f');
// get all files recursively
function listDir(i, p, list) {
i = i || 1;
p = p || filepath;
list = list || [];
i++;
if (i > 1000) throw new Error('Too much recursion. symlink fuckery might be happening');
let files = fs.readdirSync(p);
for (let f of files) {
let file = p + '/' + f;
let isDir = fs.statSync(file).isDirectory();
if (isDir) {
if (f !== '.git' && f !== 'node_modules') list = listDir(i, file, list); // youd think both of those arent in modfiles, but ive seen both :meme2:
} else {
list.push(file.replace(filepath, '').slice(1));
}
}
return list;
}
let files = listDir();
// safety check
if (!force && files.filter(f => f.endsWith('.sm') || f.endsWith('.dwi')).length === 0) {
console.error(`This is not a modfile! If you're sure '${filepath}' is the directory of the modfile, run this script with '-f'`);
process.exit(1);
}
// template check
let scores = [];
let readcache = {};
function readFile(f) {
f = path.join(filepath, f);
if (!readcache[f]) readcache[f] = fs.readFileSync(f, 'utf8');
return readcache[f];
}
for (let cat of categories) {
// console.log(`checking for ${cat.name}...`);
let score = 0;
for (let check of cat.checks) {
let correct = false;
switch (check.type) {
case 'filename':
correct = correct || files.filter(f => f.split('/').pop() === check.main).length > 0;
break;
case 'folder':
correct = correct || files.filter(f => f.split('/').includes(check.main)).length > 0;
break;
case 'extension':
correct = correct || files.filter(f => f.endsWith(check.main)).length > 0;
break;
case 'filecontent':
let fileContents = files.filter(f => f.endsWith(check.filename)).map(f => readFile(f));
correct = correct || fileContents.filter(f => f.includes(check.main)).length > 0;
break;
default:
console.warn(`${check.type} is not a valid type`)
}
if (correct) score += check.priority;
}
// console.log(`${cat.name}: ${score}`);
scores.push(score)
}
let highests = 0;
let highestc = categories[0];
let highests2 = 0;
for (let i in scores) {
let s = scores[i];
if (s > highests) {
highests2 = highests;
highestc2 = highestc;
highests = s;
highestc = categories[i];
}
}
let prob = Math.min(Math.floor((highests - highests2) / 3 * 100), 100);
console.log(`${highestc.name}${prob !== 0 && prob !== 100 ? `, ${prob}% certainty` : ''}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment