rbxts-flamework / core

Flamework is an extensible game framework. It requires typescript and offers many useful features.
MIT License
101 stars 8 forks source link

Hash improvements #49

Closed safazi closed 4 months ago

safazi commented 2 years ago

Love the idea of hash, let's make it better!

Fireboltofdeath commented 2 years ago

Hash an entire enum

Could you elaborate this? What do you mean by hashing an enum?

safazi commented 2 years ago

A way to hash many strings at once.

@Hash()
enum Keys {
    Test
}

const map = {
    [Keys.Test]: 1
}

could compile to

const map = {
    'asdasdasd-asdasdasdasd-asdasdasd-asdasd': 1
}

or something along those lines

Just any way to hash many things instead of calling hash a lot.

Fireboltofdeath commented 4 months ago

I'm perhaps a bit late on this but I feel like all of the bulletins included in the original post have mostly been solved by Flamework's modding API.

  1. Flamework.hash doesn't directly support this, but the Modding.Obfuscate metadata does if you write your own user macro.
  2. You can write your own user macro instead of Flamework.hash with however short of a name you want (minus the $ prefix)

The third one is a bit more nuanced but I don't think this is necessary with Flamework user macros and would probably be best implemented in a separate transformer like rbxts-transform-guid (although this one doesn't appear to preserve types which could cause issues with incremental compilation and typechecking errors)

With Flamework user macros, I think it'd be more idiomatic to automatically convert names into their hashed versions rather than having the user do so manually (like @flamework/networking does.) Although, it's not currently possible to obfuscate property accesses (without intrinsics) but I intend to support that eventually.

I'm going to close this issue for the above reasons, but feel free to reopen it if you disagree.