Author Topic: Finding Dynamic Fields on SimObject  (Read 1751 times)

Hello modders,

I'd like to retrieve all the "dynamic fields" from a SimObject, similar to how the GuiGroup -> InspectDlg -> InspectTitle -> InspectFields (class: GuiInspector) functions.
Now the functionality of the tree inspector is written in the C++ TGE source code and the functionality to retrieve fields appears exclusively accessible to the C++ interface.

The only solution I can think of is logging the console when doing a .dump() (bad-dum-ts), and then just use the data before you reach the Methods: line.

That solution seems a bit silly, it would work, but I'd like to know, if there might better solution. Has anyone encountered this problem before?

I'm curious as to what you're using this for. Checking for lines in the console is a bad idea. It would be much easier to .save() the object and read the file.

It could be saved and read, that's true. That's probably better, since I just realised the ConsoleLogger saves to path as well, so there's no point in using .dump() when I do not require information on methods.
« Last Edit: August 27, 2018, 06:28:40 PM by Quartz »

Tagged fields? Sorry, it's been forever since I've worked with these.

Code: [Select]
%index = 0;
while((%field = %object.getTaggedField(%index)) !$= "")
{
//do stuff here
%index ++;
}

Tagged fields? Sorry, it's been forever since I've worked with these.

Code: [Select]
%index = 0;
while((%field = %object.getTaggedField(%index)) !$= "")
{
//do stuff here
%index ++;
}
Thank you.

holy stuff so thats what tagged field does

torquescript now with reflection!

weird I could of swore that function was semi-broken

while you guys were thinking about the right way of doing this I was busy theorizing the absolute worst ways to go about this

Code: [Select]
function findStuffOnObject(%obj,%lenToCheck)
{
if(%lenToCheck $= "")
%lenToCheck = 4;
%master = new simObject()
{
allowed = "abcdefghijklmnopqrstuvwxyz_1234567890";
len = 0;
latch = %obj;
foundCnt = 0;
};
%master.allowedLen = strLen(%master.allowed);
for(%i=0;%i<%master.allowedLen;%i++)
{
%master.chr[%i] = getSubStr(%master.allowed,%i,1);
}
%time = getRealTime();
while(%master.len<%lenToCheck)
{
%master.len++;
STARTOBJECTATTACK(%master);
}
echo("Operation complete for length of " @ %lenToCheck @ " in " @ ((getRealTime()-%time)/1000) @ " seconds");
for(%i=0;%i<%master.foundCnt;%i++)
{
%found = %master.found[%i];
%key = getField(%found,0);
%len = getFieldCount(%found);
%val = "";
for(%a=1;%a<%len;%a++)
{
%val = %val @ (%a > 1 ? "\t" : "") @ getField(%found,%a);
}
echo("FOUND FIELD " @ %key @ " = " @ %val);
}
%master.delete();
}
function STARTOBJECTATTACK(%master)
{
%last = %master.len-1;
objectforget(0,%master,%last);
}
function genStrFromMaster(%master)
{
%str = "";
for(%i=0;%i<%master.len;%i++)
%str = %str @ %master.test[%i];
return %str;
}
function checkIfAnObjectContainsAVariableString(%obj,%str)
{
%chr = getSubStr(%str,0,1);
%str = getSubStr(%str,1,256);
switch$(%chr)
{
case "a": return %obj.a[%str];
case "b": return %obj.b[%str];
case "c": return %obj.c[%str];
case "d": return %obj.d[%str];
case "e": return %obj.e[%str];
case "f": return %obj.f[%str];
case "g": return %obj.g[%str];
case "h": return %obj.h[%str];
case "i": return %obj.i[%str];
case "j": return %obj.j[%str];
case "k": return %obj.k[%str];
case "l": return %obj.l[%str];
case "m": return %obj.m[%str];
case "n": return %obj.n[%str];
case "o": return %obj.o[%str];
case "p": return %obj.p[%str];
case "q": return %obj.q[%str];
case "r": return %obj.r[%str];
case "s": return %obj.s[%str];
case "t": return %obj.t[%str];
case "u": return %obj.u[%str];
case "v": return %obj.v[%str];
case "w": return %obj.w[%str];
case "x": return %obj.x[%str];
case "y": return %obj.y[%str];
case "z": return %obj.z[%str];
case "_": return %obj._[%str];
}
return "";
}
function objectforget(%curr,%master,%last)
{
%next = %curr+1;
%len = %master.allowedLen;
if(%curr == 0)
%len -= 10;
for(%i=0;%i<%len;%i++)
{
%master.test[%curr] = %master.chr[%i];
if(%curr < %last)
{
objectforget(%next,%master,%last);
}
else
{
%str = genStrFromMaster(%master);
%var = checkIfAnObjectContainsAVariableString(%master.latch,%str);
if(%var !$= "")
{
%master.found[%master.foundCnt] = %str @ "\t" @ %var;
%master.foundCnt++;
}
}
}
}

I present variable name brute forcing on an object

Initialize an object

search for 1-3 character length variables

search for 1-4 character length variables


benchmark for 5 character length variables would probably take a reasonable 20 minutes but I don't have the patience for that