Difference between revisions of "Reverse Engineering"
Ranger Fox (Talk | contribs) (Created page with "Whereigo cartridges are based on the [http://www.lua.org/ Lua scripting language]. Using facilities built into Lua, you can find out information about the properties and metho...") |
(No difference)
|
Latest revision as of 13:29, 22 April 2018
Whereigo cartridges are based on the Lua scripting language. Using facilities built into Lua, you can find out information about the properties and methods of the various objects which are part of the programming model.
Getting Started
To begin, create and publish a dummy cartridge to your local machine. Something created with the wizard will do nicely. Open the emulator and load your cartridge into it. Click Play. Now switch to the Lua Debug tab.
The Basic Script
Veeerrrrry carefully, type the following in the command box. Remember that Lua is case-sensitive. Better yet, copy and paste from here. The example examines the Player object. You can change the first line to examine any object instance which is accessible.
local o = Player;
print(o);
print(getmetatable(o));
for k,v in pairs(getmetatable(o)) do print(k,v) end;
print(getmetatable(o)._self);
for k,v in pairs(getmetatable(o)._self) do print(k,v) end;
Click the Execute Lua Command... button. Your results will appear in the result box. Counterintuitively, they appear in reverse order with the output of your last statement at the top of the result list. The result box lacks a vertical scroll bar. To see all of your results, you may need to click in the result box. Then use standard Windows text navigation keys (such as up- and down-arrow, page-up and page-down, etc.) to navigate.
What You Get
The above commands should show something like this:
GetVisibleObjects function: 036A5890
GetVisibleInventory function: 036A5918
PositionAccuracy Distance(1, 'm')
CurrentBearing false
Commands table: 0366B1F0
Name Builder
Icon false
GetContainer function: 0364A7E8
Cartridge a ZCartridge instance
ObjIndex -21555
Gender It
CommandsArray table: 0366B218
SetObjectLocation function: 0364A900
GetActiveVisibleZones function: 03685130
IsObjectVisible function: 036A58B0
RefreshLocation function: 03668400
Container false
CurrentDistance false
serialize function: 03660988
ProcessLocation function: 036683E0
InsideOfZones table: 03685108
Description
InsideOf function: 036A5938
Inventory table: 036472D8
OnEnterZone function: 0364A850
OnExitZone function: 0364A898
Id -1
LastLocationUpdate 1203287121
Type PC
OnSetInventory function: 0364A830
GetActiveVisibleTasks function: 036A5818
GetActiveTimers function: 036A58D0
CompletionCode builder
ObjectLocation ZonePoint(38.636607, -90.574608, Distance(0, 'm'))
Media false
Visible false
table: 036A4A98
newindex function: 0368AD70
tostring function: 0366D9A0
_self table: 036A4A98
index function: 0368AD90
table: 03647200
a ZCharacter instance
What It Means
Reading from the bottom up:
print(o) yields "a ZCharacter instance", which tells us the class of the the object Player. (Every instance exposes some information about itself when you simply print it. The amount and usefullness of the information varies according to the definition of the class.)
print(getmetatable(o)) yields "table: 03647200". This just tells us that the Player object has a metatable which describes itself.
for k,v in pairs(getmetatable(o))... yields the lines beginning with index and ending with __newindex. This is not useful information. I only left this step in so you can see where we get the reference to _self.
print(getmetatable(o)._self) yields "table: 036A4A98". Just tells us that ._self is also a table.
for k,v in pairs(getmetatable(o)._self)... yields all the remaining lines, which are the visible properties and methods on the Player object.
Of course, this doesn't really give us enough information to call methods. And I'm sure it exposes a number of things which we should not play with. On the other hand, several of the properties on the Player object (such as ObjectLocation and PositionAccuracy) have been discussed in the forums. So at least you have things about which you can ask specific questions.