kingkingyyk3
Visitor (Welcome to the Jungle, Baby!)
- Reaction score
- 216
I made this to enable those who have Warcraft 3 1.23 or lower patch to edit map made by 1.23b or higher patch world editor that containing the new handle - Hashtable by doing lowest changes to it.
Readme :
Library here :
Readme :
JASS:
Simulated Hashtable v1.2
by kingking
How is it useful?
If you are a mapper having 1.23 or older world editor and you wish to edit map
created by 1.23b world editor that containing hashtable functions, then you can
use this system to reduce the major changes.
PROS :
1) As an alternative for real hashtable
CONS :
1) Use turtle speed gamecache as storage.
Requires : Jass NewGen Pack 5c or later
List of functions provided :
function InitHashtable takes nothing returns hashtable
function GetHandleId takes handle h returns integer
function StringHash takes string s returns integer
function SaveInteger takes hashtable table, integer parentKey, integer childKey, integer value returns nothing
function SaveReal takes hashtable table, integer parentKey, integer childKey, real value returns nothing
function SaveBoolean takes hashtable table, integer parentKey, integer childKey, boolean value returns nothing
function SaveStr takes hashtable table, integer parentKey, integer childKey, string value returns boolean
function SavePlayerHandle takes hashtable table, integer parentKey, integer childKey, player whichPlayer returns boolean
function SaveWidgetHandle takes hashtable table, integer parentKey, integer childKey, widget whichWidget returns boolean
function SaveDestructableHandle takes hashtable table, integer parentKey, integer childKey, destructable whichDestructable returns boolean
function SaveItemHandle takes hashtable table, integer parentKey, integer childKey, item whichItem returns boolean
function SaveUnitHandle takes hashtable table, integer parentKey, integer childKey, unit whichUnit returns boolean
function SaveAbilityHandle takes hashtable table, integer parentKey, integer childKey, ability whichAbility returns boolean
function SaveTimerHandle takes hashtable table, integer parentKey, integer childKey, timer whichTimer returns boolean
function SaveTriggerHandle takes hashtable table, integer parentKey, integer childKey, trigger whichTrigger returns boolean
function SaveTriggerConditionHandle takes hashtable table, integer parentKey, integer childKey, triggercondition whichTriggercondition returns boolean
function SaveTriggerActionHandle takes hashtable table, integer parentKey, integer childKey, triggeraction whichTriggeraction returns boolean
function SaveTriggerEventHandle takes hashtable table, integer parentKey, integer childKey, event whichEvent returns boolean
function SaveForceHandle takes hashtable table, integer parentKey, integer childKey, force whichForce returns boolean
function SaveGroupHandle takes hashtable table, integer parentKey, integer childKey, group whichGroup returns boolean
function SaveLocationHandle takes hashtable table, integer parentKey, integer childKey, location whichLocation returns boolean
function SaveRectHandle takes hashtable table, integer parentKey, integer childKey, rect whichRect returns boolean
function SaveBooleanExprHandle takes hashtable table, integer parentKey, integer childKey, boolexpr whichBoolexpr returns boolean
function SaveSoundHandle takes hashtable table, integer parentKey, integer childKey, sound whichSound returns boolean
function SaveEffectHandle takes hashtable table, integer parentKey, integer childKey, effect whichEffect returns boolean
function SaveUnitPoolHandle takes hashtable table, integer parentKey, integer childKey, unitpool whichUnitpool returns boolean
function SaveItemPoolHandle takes hashtable table, integer parentKey, integer childKey, itempool whichItempool returns boolean
function SaveQuestHandle takes hashtable table, integer parentKey, integer childKey, quest whichQuest returns boolean
function SaveQuestItemHandle takes hashtable table, integer parentKey, integer childKey, questitem whichQuestitem returns boolean
function SaveDefeatConditionHandle takes hashtable table, integer parentKey, integer childKey, defeatcondition whichDefeatcondition returns boolean
function SaveTimerDialogHandle takes hashtable table, integer parentKey, integer childKey, timerdialog whichTimerdialog returns boolean
function SaveLeaderboardHandle takes hashtable table, integer parentKey, integer childKey, leaderboard whichLeaderboard returns boolean
function SaveMultiboardHandle takes hashtable table, integer parentKey, integer childKey, multiboard whichMultiboard returns boolean
function SaveMultiboardItemHandle takes hashtable table, integer parentKey, integer childKey, multiboarditem whichMultiboarditem returns boolean
function SaveTrackableHandle takes hashtable table, integer parentKey, integer childKey, trackable whichTrackable returns boolean
function SaveDialogHandle takes hashtable table, integer parentKey, integer childKey, dialog whichDialog returns boolean
function SaveButtonHandle takes hashtable table, integer parentKey, integer childKey, button whichButton returns boolean
function SaveTextTagHandle takes hashtable table, integer parentKey, integer childKey, texttag whichTexttag returns boolean
function SaveLightningHandle takes hashtable table, integer parentKey, integer childKey, lightning whichLightning returns boolean
function SaveImageHandle takes hashtable table, integer parentKey, integer childKey, image whichImage returns boolean
function SaveUbersplatHandle takes hashtable table, integer parentKey, integer childKey, ubersplat whichUbersplat returns boolean
function SaveRegionHandle takes hashtable table, integer parentKey, integer childKey, region whichRegion returns boolean
function SaveFogStateHandle takes hashtable table, integer parentKey, integer childKey, fogstate whichFogState returns boolean
function SaveFogModifierHandle takes hashtable table, integer parentKey, integer childKey, fogmodifier whichFogModifier returns boolean
function LoadInteger takes hashtable table, integer parentKey, integer childKey returns integer
function LoadReal takes hashtable table, integer parentKey, integer childKey returns real
function LoadBoolean takes hashtable table, integer parentKey, integer childKey returns boolean
function LoadStr takes hashtable table, integer parentKey, integer childKey returns string
function LoadPlayerHandle takes hashtable table, integer parentKey, integer childKey returns player
function LoadWidgetHandle takes hashtable table, integer parentKey, integer childKey returns widget
function LoadDestructableHandle takes hashtable table, integer parentKey, integer childKey returns destructable
function LoadItemHandle takes hashtable table, integer parentKey, integer childKey returns item
function LoadUnitHandle takes hashtable table, integer parentKey, integer childKey returns unit
function LoadAbilityHandle takes hashtable table, integer parentKey, integer childKey returns ability
function LoadTimerHandle takes hashtable table, integer parentKey, integer childKey returns timer
function LoadTriggerHandle takes hashtable table, integer parentKey, integer childKey returns trigger
function LoadTriggerConditionHandle takes hashtable table, integer parentKey, integer childKey returns triggercondition
function LoadTriggerActionHandle takes hashtable table, integer parentKey, integer childKey returns triggeraction
function LoadTriggerEventHandle takes hashtable table, integer parentKey, integer childKey returns event
function LoadForceHandle takes hashtable table, integer parentKey, integer childKey returns force
function LoadGroupHandle takes hashtable table, integer parentKey, integer childKey returns group
function LoadLocationHandle takes hashtable table, integer parentKey, integer childKey returns location
function LoadRectHandle takes hashtable table, integer parentKey, integer childKey returns rect
function LoadBooleanExprHandle takes hashtable table, integer parentKey, integer childKey returns boolexpr
function LoadSoundHandle takes hashtable table, integer parentKey, integer childKey returns sound
function LoadEffectHandle takes hashtable table, integer parentKey, integer childKey returns effect
function LoadUnitPoolHandle takes hashtable table, integer parentKey, integer childKey returns unitpool
function LoadItemPoolHandle takes hashtable table, integer parentKey, integer childKey returns itempool
function LoadQuestHandle takes hashtable table, integer parentKey, integer childKey returns quest
function LoadQuestItemHandle takes hashtable table, integer parentKey, integer childKey returns questitem
function LoadDefeatConditionHandle takes hashtable table, integer parentKey, integer childKey returns defeatcondition
function LoadTimerDialogHandle takes hashtable table, integer parentKey, integer childKey returns timerdialog
function LoadLeaderboardHandle takes hashtable table, integer parentKey, integer childKey returns leaderboard
function LoadMultiboardHandle takes hashtable table, integer parentKey, integer childKey returns multiboard
function LoadMultiboardItemHandle takes hashtable table, integer parentKey, integer childKey returns multiboarditem
function LoadTrackableHandle takes hashtable table, integer parentKey, integer childKey returns trackable
function LoadDialogHandle takes hashtable table, integer parentKey, integer childKey returns dialog
function LoadButtonHandle takes hashtable table, integer parentKey, integer childKey returns button
function LoadTextTagHandle takes hashtable table, integer parentKey, integer childKey returns texttag
function LoadLightningHandle takes hashtable table, integer parentKey, integer childKey returns lightning
function LoadImageHandle takes hashtable table, integer parentKey, integer childKey returns image
function LoadUbersplatHandle takes hashtable table, integer parentKey, integer childKey returns ubersplat
function LoadRegionHandle takes hashtable table, integer parentKey, integer childKey returns region
function LoadFogStateHandle takes hashtable table, integer parentKey, integer childKey returns fogstate
function LoadFogModifierHandle takes hashtable table, integer parentKey, integer childKey returns fogmodifier
function HaveSavedInteger takes hashtable table, integer parentKey, integer childKey returns boolean
function HaveSavedReal takes hashtable table, integer parentKey, integer childKey returns boolean
function HaveSavedBoolean takes hashtable table, integer parentKey, integer childKey returns boolean
function HaveSavedString takes hashtable table, integer parentKey, integer childKey returns boolean
function HaveSavedHandle takes hashtable table, integer parentKey, integer childKey returns boolean
function RemoveSavedInteger takes hashtable table, integer parentKey, integer childKey returns nothing
function RemoveSavedReal takes hashtable table, integer parentKey, integer childKey returns nothing
function RemoveSavedBoolean takes hashtable table, integer parentKey, integer childKey returns nothing
function RemoveSavedString takes hashtable table, integer parentKey, integer childKey returns nothing
function RemoveSavedHandle takes hashtable table, integer parentKey, integer childKey returns nothing
function FlushParentHashtable takes hashtable table returns nothing
function FlushChildHashtable takes hashtable table, integer parentKey returns nothing
Library here :
JASS:
library HASHTABLE initializer Init
globals
private gamecache TABLE
endglobals
//////////////Hashtable simulator//////////////////
struct hashtable
endstruct
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////
////Blizzard made this as H2I
function GetHandleId takes handle h returns integer
return h
return 0
endfunction
//////////////////////////////////////////////////
/////New native : StringHash//////////////////////
function StringHash takes string s returns integer
return s
return 0
endfunction
///////Init hashtable//////////
function InitHashtable takes nothing returns hashtable
return hashtable.create()
endfunction
////////////////////////////
/////Store integers/////////
function SaveInteger takes hashtable ht, integer parent, integer child, integer value returns nothing
call StoreInteger(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child),value)
endfunction
function LoadInteger takes hashtable ht, integer parent, integer child returns integer
return GetStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
function HaveSavedInteger takes hashtable ht, integer parent, integer child returns boolean
return HaveStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
function RemoveSavedInteger takes hashtable ht, integer parent, integer child returns nothing
call FlushStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
///////////////////////////////
//////Store Reals////////////////
function SaveReal takes hashtable ht, integer parent, integer child, real value returns nothing
call StoreReal(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child),value)
endfunction
function LoadReal takes hashtable ht, integer parent, integer child returns real
return GetStoredReal(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
function HaveSavedReal takes hashtable ht, integer parent, integer child returns boolean
return HaveStoredReal(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
function RemoveSavedReal takes hashtable ht, integer parent, integer child returns nothing
call FlushStoredReal(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
//////////////////////////////
////////////Store String//////
function SaveStr takes hashtable ht, integer parent, integer child, string value returns nothing
call StoreString(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child),value)
endfunction
function LoadStr takes hashtable ht, integer parent, integer child returns string
return GetStoredString(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
function HaveSavedString takes hashtable ht, integer parent, integer child returns boolean
return HaveStoredString(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
function RemoveSavedString takes hashtable ht, integer parent, integer child returns nothing
call FlushStoredString(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
/////////////////////////////
////////Store Boolean//////
function SaveBoolean takes hashtable ht, integer parent, integer child, boolean value returns nothing
call StoreBoolean(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child),value)
endfunction
function LoadBoolean takes hashtable ht, integer parent, integer child returns boolean
return GetStoredBoolean(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
function HaveSavedBoolean takes hashtable ht, integer parent, integer child returns boolean
return HaveStoredBoolean(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
function RemoveSavedBoolean takes hashtable ht, integer parent, integer child returns nothing
call FlushStoredBoolean(TABLE,I2S(ht)+"_"+I2S(parent),I2S(child))
endfunction
/////////////////////////////
private struct HandleData
handle h
endstruct
//! textmacro HASH_HANDLES takes Type, type
function Save$Type$Handle takes hashtable ht, integer parent, integer child, handle value returns boolean
local HandleData d = HandleData.create()
set d.h = value
call StoreInteger(TABLE,I2S(ht)+"_"+I2S(parent),"HandleData"+I2S(child),d)
if GetStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),"HandleData"+I2S(child)) == d then
return true
endif
return false
endfunction
function Load$Type$Handle takes hashtable ht, integer parent, integer child returns $type$
return HandleData(GetStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),"HandleData"+I2S(child))).h
endfunction
//! endtextmacro
//! runtextmacro HASH_HANDLES ("Widget","widget")
//! runtextmacro HASH_HANDLES ("Destructable","destructable")
//! runtextmacro HASH_HANDLES ("Unit","unit")
//! runtextmacro HASH_HANDLES ("Item","item")
//! runtextmacro HASH_HANDLES ("Ability","ability")
//! runtextmacro HASH_HANDLES ("Timer","timer")
//! runtextmacro HASH_HANDLES ("Trigger","trigger"")
//! runtextmacro HASH_HANDLES ("Force","force")
//! runtextmacro HASH_HANDLES ("Group","group")
//! runtextmacro HASH_HANDLES ("Location","location")
//! runtextmacro HASH_HANDLES ("Rect","rect")
//! runtextmacro HASH_HANDLES ("Region","region")
//! runtextmacro HASH_HANDLES ("Effect","effect")
//! runtextmacro HASH_HANDLES ("Sound","sound")
//! runtextmacro HASH_HANDLES ("Lightning","lightning")
//! runtextmacro HASH_HANDLES ("Player","player")
//! runtextmacro HASH_HANDLES ("TriggerCondition","triggercondition")
//! runtextmacro HASH_HANDLES ("TriggerAction","triggeraction")
//! runtextmacro HASH_HANDLES ("TriggerEvent","event")
//! runtextmacro HASH_HANDLES ("BooleanExpr","boolexpr")
//! runtextmacro HASH_HANDLES ("UnitPool","unitpool")
//! runtextmacro HASH_HANDLES ("ItemPool","itempool")
//! runtextmacro HASH_HANDLES ("Quest","quest")
//! runtextmacro HASH_HANDLES ("QuestItem","questitem")
//! runtextmacro HASH_HANDLES ("DefeatCondition","defeatcondition")
//! runtextmacro HASH_HANDLES ("TimerDialog","timerdialog")
//! runtextmacro HASH_HANDLES ("Leaderboard","leaderboard")
//! runtextmacro HASH_HANDLES ("Multiboard","multiboard")
//! runtextmacro HASH_HANDLES ("MultiboardItem","multiboarditem")
//! runtextmacro HASH_HANDLES ("Trackable","trackable")
//! runtextmacro HASH_HANDLES ("Dialog","dialog")
//! runtextmacro HASH_HANDLES ("Button","button")
//! runtextmacro HASH_HANDLES ("TextTag","texttag")
//! runtextmacro HASH_HANDLES ("Image","image")
//! runtextmacro HASH_HANDLES ("Ubersplat","ubersplat")
//! runtextmacro HASH_HANDLES ("FogState","fogstate")
//! runtextmacro HASH_HANDLES ("FogModifier","fogmodifier")
////////native for all handle storing////
function HaveSavedHandle takes hashtable ht, integer parent, integer child returns boolean
return HaveStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),"HandleData"+I2S(child))
endfunction
function RemoveSavedHandle takes hashtable ht, integer parent, integer child returns nothing
call HandleData(GetStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),"HandleData"+I2S(child))).destroy()
call FlushStoredInteger(TABLE,I2S(ht)+"_"+I2S(parent),"HandleData"+I2S(child))
endfunction
/////////////////////////////////////////
/////Cleaning functions///
function FlushParentHashtable takes hashtable ht returns nothing
call ht.destroy()
endfunction
function FlushChildHashtable takes hashtable ht, integer parent returns nothing
call FlushStoredMission(TABLE,I2S(ht)+"_"+I2S(parent))
endfunction
/////////////////////////
private function Init takes nothing returns nothing
call FlushGameCache(InitGameCache("SIMULATED_HASHTABLE"))
set TABLE = InitGameCache("SIMULATED_HASHTABLE")
endfunction
endlibrary
JASS:
v1.2 Changelog :
Fixed a bug for not clearing the handles039; data when using FlushChildHashtable.
Warcraft 3 1.23b stores handles as handle type in hashtable, the version will works similar.
Added missing natives, this system have full 1.23b natives now.