Skip to content

Instantly share code, notes, and snippets.

@farmboy0
Last active November 7, 2016 23:40
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 farmboy0/81a61c261cb1402c486707fed8418395 to your computer and use it in GitHub Desktop.
Save farmboy0/81a61c261cb1402c486707fed8418395 to your computer and use it in GitHub Desktop.
//--------------------------------------
//--- 010 Editor v6.0.2 Script File
//
// File:
// Author:
// Revision:
// Purpose:
//--------------------------------------
local string DATA_PATH = "/mnt/work/Xoreos/unpacked/";
local string template = "KoTOR1MDL.bt";
local int startcount = 0;
local int endcount = 100;
local string logfile = "010analyze.txt";
local uint test_root_tree = 1;
local uint test_anim_tree = 0;
uint testNode(node &n) {
if (n.header.content.has_unknown400 || n.header.content.has_unknown800) {
return 1;
}
return 0;
}
//------------------------------------------------------
//helper functions
local int count = 0;
void recurseDirectories(string dir) {
TFileList files = FindFiles(dir, "*.mdl");
int i;
string s;
for(i = 0; i < files.dircount; i++) {
s = dir + "/" + files.dir[i].dirname;
recurseDirectories(s);
}
if (files.filecount > 0 && count >= startcount && count < endcount) {
writeLine("Directory: " + dir);
}
for(i = 0; i < files.filecount; i++) {
count++;
if (count >= startcount && count < endcount) {
openFile(dir + "/" + files.file[i].filename);
}
}
}
void writeLine(string s) {
string clip = GetClipboardString();
if (s != "") {
clip = clip + GetCurrentDateTime("yyyy-MM-dd hh:mm:ss") + " " + s + "\n";
CopyStringToClipboard(clip);
}
OutputPaneClear();
Printf(clip);
}
void openFile(string file) {
int index = FileOpen(file, true);
FileSelect(index);
RunTemplate(template);
if (analyzeFile()) {
writeLine("File found: " + GetFileName());
} else {
writeLine("");
}
FileClose();
}
uint analyzeFile() {
if (hf.bin_mdl_id == 0) {
if (test_root_tree) {
if (analyzeNode(root)) {
return 1;
}
}
if (test_anim_tree) {
local int a;
for (a = 0; a < hm.animations.def.nr_used_entries; a++) {
if (analyzeNode(anim[a].animation_node)) {
return 1;
}
}
}
}
return 0;
}
uint analyzeNode(node &n) {
if (testNode(n)) {
writeLine("Node found: " + ReadNode(n));
return 1;
}
local int i;
for(i = 0; i < n.header.children.def.nr_used_entries; i++) {
if (analyzeNode(n.children[i])) {
return 1;
}
}
return 0;
}
//------------------------------------------------------
// Start of Script
local string error;
if (GetNumArgs() != 0 && GetNumArgs() != 3) {
SPrintf(error, "Wrong number of arguments, expected 0 or 3, got %i", GetNumArgs());
writeLine(error);
Exit(1);
}
if (GetNumArgs() == 3) {
template = GetArg(0);
if (Atoi(GetArg(1)) != 0 || GetArg(1) == "0") {
startcount = Atoi(GetArg(1));
} else {
SPrintf(error, "Expected integer as second argument, got %s", GetArg(1));
writeLine(error);
Exit(1);
}
if (Atoi(GetArg(2)) != 0) {
endcount = Atoi(GetArg(2));
} else {
SPrintf(error, "Expected integer as third argument, got %s", GetArg(2));
writeLine(error);
Exit(1);
}
}
int index = Strstr(template, "MDL.bt");
if (index == -1) {
SPrintf(error, "Template name not valid, got %s", template);
writeLine(error);
Exit(1);
}
local char game[] = SubStr(template, 0, index);
local int i;
for (i = 0; i < Strlen(game); i++) {
game[i] = ToLower(game[i]);
}
if (GetNumArgs() == 0) {
local string timestamp = GetCurrentDateTime("yyyy-MM-dd_hh.mm.ss");
logfile = "010analyze_" + game + "_" + timestamp + ".txt";
}
local string dir = DATA_PATH + game;
if (!FileExists(dir)) {
SPrintf(error, "Directory doesnt exist, got %s", dir);
writeLine(error);
Exit(1);
}
OutputPaneClear();
SetClipboardIndex(1);
ClearClipboard();
SPrintf(error, "Start (%i)", startcount);
writeLine(error);
recurseDirectories(dir);
SPrintf(error, "End (%i)", endcount);
writeLine(error);
ClearClipboard();
OutputPaneSave(DATA_PATH + logfile);
Exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment