Download
(3 Kb)
Download
Updated: 05/06/14 07:38 AM
Compatibility:
Live (1.0)
Updated:05/06/14 07:38 AM
Created:05/02/14 09:15 AM
Monthly downloads:15
Total downloads:1,038
Favorites:4
MD5:
FunctionCapture
Version: 1.0.3
by: LilBudyWizer [More]
Another quick and dirty. This is for discovering functions. It has no interface, it just saves the data it captures to saved variables which you can view live using zgoo. It build a cross reference of functions, and captures calls to those function. Capturing calls might be a bit dangerous, but there doesn't seem a good reason not to include it. The general structure of that saved variable is:

Lua Code:
  1. FunctionCapture_DB =
  2. {
  3.     Dictionary = {},
  4.     FunctionNames = {},
  5.     FunctionAddrs = {},
  6.     FunctionTree = {},
  7.     Synonyms = {},
  8.     Fired = {},
  9. }

All entries are cross references for functions, there is no capture at this point. FunctionNames and FunctionAddrs is simply a list of functions indexed by name or address. Addresses are in the form "function: 0F9E9A28". Synonyms is a list of function pointing to the same address grouped by address. Fired is a capture of the parms and result of the first call to function after it's hooked.

Dictionary and FunctionTree breaks apart a name by words. A word for this purpose is simply a capital letter followed by 1 or more lowercase letters. Nothing is actually thrown out so "This&That" is three words. Underscores "_" are stripped out. A special case is a prefix for a function, i.e. "prefix_function". Whatever precedes the first underscore is the first word of the function.

The general structure of Fired is:
Lua Code:
  1. Fired =
  2. {
  3.     GetSmithingResearchLineInfo =
  4.     {
  5.         Parms =
  6.         {
  7.             "1",
  8.             "1",
  9.         },
  10.         Result =
  11.         {
  12.             "Dagger",
  13.             "/esoui/art/icons/gear_breton_dagger_a.dds",
  14.             "8",
  15.             "328320",
  16.         },
  17.     },
  18. }

where Parms is the parameters into the function and Result is the values returned by the function. These are only present if there are parms or return values. If there's just a single parm or return value it's collapsed into a single line rather than using a subtable.

The general structure of Dictionary is:

Lua Code:
  1. Dictionary =
  2. {
  3.     Drag =
  4.     {
  5.         Store =
  6.         {
  7.             ZO_Store_OnReceiveDrag = "function: 3601D638",
  8.         },
  9.         Receive =
  10.         {
  11.             ZO_Store_OnReceiveDrag           = "function: 3601D638",
  12.             ZO_Trade_OnReceiveDrag           = "function: 32786D78",
  13.             ZO_InventorySlot_OnReceiveDrag   = "function: 2AECFDB0",
  14.             ZO_AbilitySlot_OnReceiveDrag     = "function: 24E9FB60",
  15.             UnitFrame_HandleMouseReceiveDrag = "function: 49B718E0",
  16.         },
  17.     },
  18. }

It has two levels and it's all combinations of two words used in the function. It makes for a very big dictionary, but it gets leaves down to a reasonable size. If it has no words, i.e. all lowercase, then it appears under _nowords. Note it is without regard to underscors so "this_is_a_test" is no words. That particular one would be under _nowords.this because it has a prefix. The vast majority of the saved variables is the dictionary.

The tree uses the order of the words. A bit more useful than with events. The general structure of this entry is:

Lua Code:
  1. FunctionTree =
  2. {
  3.     MM =
  4.     {
  5.         MM_ZrMMShown = "function: 4D79EDF8",
  6.         Hide =
  7.         {
  8.             MM_HideCheck = "function: 5AFCCC38",
  9.             MM_Hide = "function: 433EE320",
  10.         },
  11.     },
  12. }

If the function name is in the form "prefix_function" then it appears in the root, otherwise it appears under "_noprefix". The tree is formed by the words used in the order they are used. The tree is collapsed so that the only single child nodes are the leaves.

This is a huge file, over 100k lines. Not an issue for space, just 5MB, but an issue for manually browsing the file. I would strongly urge you to use it live with zgoo. If you want to use it outside the client then I would suggest you use dofile to load the saved variables then utility functions of your own devise to retrieve what you want out of it. The two word dictionary is so you can easily browse it using zgoo. With your own function you could do the intersection of any number of words. You can use it to speed your own lookup. It cuts the number of intersections needed in half rounded up.

TODO: Some utility functions. That would be both slash commands in game and a lua script that loads the saved variables and lets you query it. Longer term an interface. I'm think that will be a separate addon, likely named CaptureViewer, that will use the variables from the addons if they are present. I provide a capture prior to that for selectively capturing function calls. I'm just real reluctant to do that across the board, i.e. every function. That would initially be through slash commands then through an gui.
1.0.0 Initial release

1.0.1 Flattened dictionary

All the single function entries in the dictionary were folded into _misc and all the duplicates were merged into a single "word1 - word2 - word 3". The changes reduced the size of the saved variables by about 45k lines. It makes it easier to use through zgoo though, perhaps, a bit more difficult to use from a script. If one prefers the old version one can comment out the call to CollapseDictionary.

1.0.2 Captures function calls

Added in capturing the first call to the function after it's hooked during the player activated event.

1.0.3 Better error handling

I found the act of hooking a function that calls protected/private functions causes those functions to fail. Since I unhooked after the call it, effectively, disabled the function. I now unhook before calling the function. I also catch errors in the function, record the error message under result and rethrow the error with "Hook funcname: " prepended to the message. So you'll still get an error message trying to activate a power, but it will not continue to fail as you continue to try to use a power.
Optional Files (0)


Archived Files (3)
File Name
Version
Size
Uploader
Date
1.0.2
3kB
LilBudyWizer
05/04/14 05:53 AM
1.0.1
3kB
LilBudyWizer
05/03/14 03:46 PM
1.0.0
2kB
05/02/14 09:15 AM


Post A Reply Comment Options
Unread 05/06/14, 10:30 AM  
SinusPi
AddOn Author - Click to view AddOns

Forum posts: 18
File comments: 5
Uploads: 3
A tiny step ahead of you. Maybe. Look in Zgoo's source for BUGIT, BUGIT2, BUGCALL and BUGTABLE. I used *some* of those to "bug" certain calls to the original API. They're not officially documented, but they're there.

In Zgoo,
/run BUGIT (SomeInternalFunction) -- and /zgoo BUGIT_LOG when you think the function was called. Uses setfenv for proxying internal calls.
/run BUGCALL (SomeInternalFunction, arg1, arg2) -- it does BUGIT and calls the function with the params and zgoos the results, all in one go
/run BUGIT2 (SomeInternalFunction) -- pretty much what BUGIT does, just replaces the function completely for more precise logging, but not all functions are successfully replaced, as some were local'ized already.
/run BUGTABLE (SomeInternalTable) -- bugs the table and logs calls into it. (Messes up metatables...)

Care to compare how the above calls perform, compared to your addon?
Report comment to moderator  
Reply With Quote
Unread 05/04/14, 12:55 PM  
LilBudyWizer
AddOn Author - Click to view AddOns

Forum posts: 32
File comments: 11
Uploads: 4
The Wiki here has a MyFirstAddon tutorial. If you're new to programming then the Getting Started guide for Lua would be the place to start. If you're running Windows the luaforwindows site has an executable you just run and it installs lua, a number of libraries and helpful utilities. That includes SciTE which is a programming editor. You can type code into the text editor, click run and see the output below.

If your interest is in becoming a programmer and you're thinking this is your starting point then I would recommend Safari Books Online. It costs a subscription fee, but gives you access to most books on programming, about 40K of them. A good source for development of ESO addons is actually the one for WoW, since they are much the same. The HOWTOs there will help you a lot with how to do the same thing here.

This particular addon is a bit of an advanced use. You can do a great deal without ever resorting to something like this. Particularly you can browse the source for any addon on this site. It's lua scripts so they are distributed as source. One of the easiest ways to learn is just change an existing addon. I wouldn't do that with Librarian or something that builds a database over time since you might lose your data, but with most addons there's no history except your settings. So if you screw up you just reinstall it and, perhaps, reconfigure it. You shouldn't redistribute something like that without permission from the author, but no one cares if you do it just for your own use. Cosmetic changes are the easiest, like changing text content, color or size.

You can also use the /script slash command in combination with the d() function which prints whatever you pass to it. So you can do something like /script d(GetTimeString()) which will print the time. You can actually manual execute a whole program that way. That's tedious and quickly highlights why you need to save it and execute as a block. That's makes for a good way to bootstrap programming. Just create an addon that creates a function you can call from the command line to execute a series of functions for you to save you typing. That's really the essence of programming. Start with the most basic of what you want to do and keep adding to it. I'm a big fan of iterative programming. You don't type for days then see if it runs, you run it constantly, every time you add code to it. It's much easier to debug the code added a few minutes ago than the code you added a couple of weeks ago.
Report comment to moderator  
Reply With Quote
Unread 05/04/14, 04:46 AM  
Saftsuse
 
Saftsuse's Avatar

Forum posts: 13
File comments: 149
Uploads: 0
Thank you for your answer, Im very interested in addons and how they work, but got no experience at all with programming. I have ideas, I would very much like to learn, but in the mean time im very curious and try to get information from everywhere I can, everything except actually learning how to do it

I will find time, I cant just learn 10 minutes here and there, so during the summer I hope to get enough to actually start making some
Report comment to moderator  
Reply With Quote
Unread 05/03/14, 06:17 AM  
LilBudyWizer
AddOn Author - Click to view AddOns

Forum posts: 32
File comments: 11
Uploads: 4
Because ZeniMax's support for mod development is the existence of a framework within the client that allows addons to work. What function does what? Well, we have to figure out that one for ourselves. If you don't do mod development you might not understand that, but if you develop mods you well understand the lack of documentation and guidance provided by ZeniMax. This site has a list of functions with their parameters and return values. That is, presumably, obtained by extracting the scripts from game0000.dat. That is either outdated or not all functions are actually defined in game0000.dat because a number of functions are missing from the list. They are reasonably categorized, but not all functions fall neatly into a single category. So it can turn into a game of guess the word.

That is not a complaint about this site. It's a Herculean and what they have done is invaluable when working on mods. It is a community effort though. Eventually, assuming the game survives, we'll have something like this. There will be actual documentation of functions, howto guides and snippets. We have to create all those. So the purpose of this and similar addons I have/will create is to aid developers that don't have the benefit of such things yet so they, hopefully, someday do create those things.
Report comment to moderator  
Reply With Quote
Unread 05/03/14, 01:47 AM  
Saftsuse
 
Saftsuse's Avatar

Forum posts: 13
File comments: 149
Uploads: 0
Im curious what this is for? Or why would I use it to discover functions? Why would anyone need this?
Last edited by Saftsuse : 05/03/14 at 01:49 AM.
Report comment to moderator  
Reply With Quote
Post A Reply



Category Jump: