• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Snippet] GetAgentHandle

Level 1
Joined
May 12, 2011
Messages
5
LoadAgentHandle can use to load agent value from hashtable

JASS:
library HashtableTool
    /*
        Function list:
        function LoadAgentHandle takes hashtable table, integer parentKey, integer childKey returns agent
        --------------------------------------------------------------------
        You can add agent support to Table by comment
        |    private struct agents extends array
        |        method operator []= takes integer key, agent value returns nothing
        |            call SaveAgentHandle(ht, this, key, value)
        |        endmethod
        |    endstruct
        and add uses HashtableTool and add this line
        |   //! runtextmacro NEW_ARRAY("Agent", "agent")
        --------------------------------------------------------------------
        Note: This disable SaveInteger if you use SaveXXXHandle
    */
	globals
		private agent array HandleIDData
	endglobals
	private function SaveHandleID takes hashtable table,integer parentKey,integer childKey,agent value returns nothing
		if (value==null) then
			call RemoveSavedHandle(table,parentKey,childKey)
		endif
		call SaveInteger(table,parentKey,childKey,GetHandleId(value))
		set HandleIDData[GetHandleId(value)-0x100000]=value
	endfunction
	function LoadAgentHandle takes hashtable table,integer parentKey,integer childKey returns agent
		local integer hid=LoadInteger(table,parentKey,childKey)
		return         HandleIDData[hid-0x100000]
	endfunction
    hook SaveAgentHandle SaveHandleID
	hook SavePlayerHandle SaveHandleID
	hook SaveWidgetHandle SaveHandleID
	hook SaveDestructableHandle SaveHandleID
	hook SaveItemHandle SaveHandleID
	hook SaveUnitHandle SaveHandleID
	hook SaveAbilityHandle SaveHandleID
	hook SaveTimerHandle SaveHandleID
	hook SaveTriggerHandle SaveHandleID
	hook SaveTriggerConditionHandle SaveHandleID
	hook SaveTriggerEventHandle SaveHandleID
	hook SaveForceHandle SaveHandleID
	hook SaveGroupHandle SaveHandleID
	hook SaveLocationHandle SaveHandleID
	hook SaveRectHandle SaveHandleID
	hook SaveBooleanExprHandle SaveHandleID
	hook SaveSoundHandle SaveHandleID
	hook SaveEffectHandle SaveHandleID
	hook SaveQuestHandle SaveHandleID
	hook SaveQuestItemHandle SaveHandleID
	hook SaveDefeatConditionHandle SaveHandleID
	hook SaveTimerDialogHandle SaveHandleID
	hook SaveLeaderboardHandle SaveHandleID
	hook SaveMultiboardHandle SaveHandleID
	hook SaveMultiboardItemHandle SaveHandleID
	hook SaveTrackableHandle SaveHandleID
	hook SaveDialogHandle SaveHandleID
	hook SaveButtonHandle SaveHandleID
	hook SaveRegionHandle SaveHandleID
	hook SaveFogModifierHandle SaveHandleID
	hook SaveHashtableHandle SaveHandleID
endlibrary

LoadHandle
JASS:
    function LoadHandle takes hashtable table, integer parentKey, integer childKey returns handle
        return LoadFogStateHandle(table, parentKey, childKey)
    endfunction
 
Last edited:
When I've used 2 hooks last time just to store conditions without forcing user to do so manually, mods suggested to go with custom type anyways.

Furthermore, I don't think using hook for every Save native is what you should go for. If someone uses for Table (what is common) this snippet slows every operation tremendously.
Mag ur eyes bleed ;o
I don't want to judge ur script without asking.. what is this for?
Isn't Table is all you need when playing with hashtables?
 
Last edited:
@Spinnaker: There is no LoadAgentHandle function. There is just a SaveAgentHandle function. A few people have requested this (although, there isn't really a good reason why).

I suppose this is okay, but IMO you only need to hook SaveAgentHandle. Unless I'm mistaken, you should be able to typecast the other types to agent just fine (assuming your code compiles/functions).

Also, 0x100000 should be a global constant. Some maps are large and pass 8191 handles relatively fast, in which case this code would crash/stop the thread (i don't remember which), because it would be greater than 0x101FFF and thereby reach the index limit for arrays.
 
I'm in favor of making a SaveAgentHandleEx function.
Hooking SaveAgentHandle could be used to print a message warning the user that he's still using the wrong function.

Then again, how often do people use SaveAgentHandle? ;o
The hook is not that bad in this case, but I'm not so sure about it.
We can avoid hooks by having a SaveAgentHandleEx function and using a hook only in debug mode to get rid of the remaining calls, but I'm ambivalent to this.
 
@Purge - haven't noticed it, lol. Blizzard api sucks even more than I thought it did.

And yes; using 0x100000 isn't a good idea if you are considering all the handles. Destructables can soak up 9000 indexes alone. You can make use of constant boolean to enable user to choose whether he wants quick array or hashtable.
 
Last edited:
Top