s2client-api
s2client-api copied to clipboard
Fetch the map hash
It'd be helpful to get the hash (or whatever unique id) of the current map in the gameinfo data. Of course, the map is loaded based on what I supply as an argument to the game/API, but it'd feel much less flimsy and be more future-proof to get the actual hash of the map that the game ended up loading.
In my case I'd want this for caching: I spend something like 10 seconds generating all kinds of stuff from the terrain and unit information on game start, which I'd like to cache for next sessions by the map ID. Especially important in realtime use, since that 10 seconds is subtracted from active play time.
I agree some type of uniqueId would be useful. May not be high on our priority list though.
Since you are specifying the map directly, you could try just loading the file from disk yourself and hashing it.
That is what I'm doing and it seems to work fairly well.
Hi @noorus
Was your issue solved? If yes, can you close this issue, please?
Hi @herodrigues I wouldn't call it solved. What I indeed ended up doing was hash the map file being loaded myself, but (depending on implementation and compiler settings) this actually takes a while and in turn causes my realtime bot to lag in startup, missing out on maybe a few seconds of precious early game time.
The process is:
- I give my bot a map name to load, the bot passes it to sc2
- SC2 resolves the name to what I hope is always the latest ladder version of said map
- As SC2 starts loading the game, my bot finally receives the full filename from the API and can do its own thing
- And here then my bot has to initialize everything before the game starts, or it will miss out on gameplay time.
So what I then did was to start taking the SHA256 directly from the map file name if it came from the bnet cache instead of calculating it myself, but this is a hack and not a real neat solution.
Of course I could also sidestep the issue by passing an absolute path to a map file to the launcher instead of a map name, but then I'd be missing out on what I see as a cool and useful feature (launching the latest ladder version of a map by name).
TL;DR I hacked my way around it so it's not a pressing issue, but I don't see why whatever internal identifiers battlenet uses for every single map cannot be passed to the bot by the API.
Unless I'm missing something, I don't really see what the PR where this was referenced has to do with this particular problem either.