HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Warcraft's Internal String Table question

09-30-2008, 07:08 AM#1
chobibo
Did anyone, in the past, tried using warcraft's internal string table as a UnitId Table for array indeces? Something like this:
Collapse JASS:
library Table initializer Initialize
    
    globals
        private integer OFFSET=0
        private integer array UNIT_TABLE
    endglobals
    
    function GetUnitTypeData takes integer unitid returns integer
        return UNIT_TABLE[StringToInt(I2S(unitid))-OFFSET]
    endfunction
    
    private function Initialize takes nothing returns nothing
        set OFFSET=StringToInt(I2S('Hpal'))
        set UNIT_TABLE[OFFSET]=bj_HEROSTAT_STR
        set UNIT_TABLE[StringToInt(I2S('Hamg'))]=bj_HEROSTAT_INT
        set UNIT_TABLE[StringToInt(I2S('Hmkg'))]=bj_HEROSTAT_STR
        set UNIT_TABLE[StringToInt(I2S('Hblm'))]=bj_HEROSTAT_INT
    endfunction
endlibrary

would this work?
09-30-2008, 07:40 AM#2
Jazradel
Is StringToInt (by which I think you mean GetStringTableIndex) possible?
09-30-2008, 08:13 AM#3
Captain Griffen
It has issues with being reset, such as when you load a game, although you could take it hostage with a global variable I guess, the stuff you'd need to build in to make it secure would be slow and possibly unsure, making the speed advantage go away.
09-30-2008, 09:54 AM#4
Toadcop
i use something like that for constant storages. and renew them on load event... (you also should know how much stings are allocated before you init this) well imo it's usable only for constant storages like writing data on types (your example above) and etc.
10-01-2008, 12:28 AM#5
Ammorth
I would personally not use the string table as there may be side-effects to it that have yet to be discovered that may end up corrupting your data later down the road. I was thinking of using it for my PAS (store width via string table) but decided for the safer route of gamecache. Of course, this is just opinnion, but sometimes make robust code sacrafices some performance.
10-01-2008, 01:51 AM#6
grim001
Does anyone have evidence that this is an unsafe method of attachment for multiplayer games that don't involve saving or loading? Is any extra code needed to make it "safe" for some reason?
10-01-2008, 02:36 AM#7
Ammorth
Hard evidence, no. But does anyone have any evidence that it is completely safe under these conditions? no.

I did do some tests (a while back) that seemed to show as long as the game was not saved/loaded that the string table returned exprected values. I was unable to break the table with any means other than saving/loading.
10-01-2008, 03:14 AM#8
chobibo
Thanks for all the info guys,
@Jazradel: StringToInt is just a return bug like HandleToInt(H2I)
@ToadCop: I saw you using this in your 600 spheres post that's why I was wondering why other people haven't used it.

Another question, has anyone, or is it possible, to build off my own wts file and use it as a Look-up Table for constant data like values for items, primary attribute table, etc. I've been trying to edit a wts file using Jasscraft and it works, I just don't know if it's feasible to use it as data storage medium.
10-01-2008, 07:14 AM#9
DioD
RB over string is 100% safe, there is no way to break string table without async.
10-03-2008, 10:05 PM#10
Toadcop
Quote:
RB over string is 100% safe, there is no way to break string table without async.
+1
as i said if you use it for constant storages so it 100% safe (i use it in my TcX map)


Quote:
Another question, has anyone, or is it possible, to build off my own wts file and use it as a Look-up Table for constant data like values for items, primary attribute table, etc. I've been trying to edit a wts file using Jasscraft and it works, I just don't know if it's feasible to use it as data storage medium.
the wts lookup is "very slow" thats why optimization tools does inline strings from it... you can JassHelper for similar features (including code etc.) if you need.