File tree Expand file tree Collapse file tree 3 files changed +34
-23
lines changed Expand file tree Collapse file tree 3 files changed +34
-23
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,8 @@ namespace Il2Cpp {
4040 /**
4141 * Gets the version name of the current application, e.g. `4.12.8`.
4242 *
43- * **This information is not guaranteed to exist.**
43+ * In case the version cannot be retrieved, an hash of the IL2CPP
44+ * module is returned instead.
4445 *
4546 * ```ts
4647 * Il2Cpp.perform(() => {
@@ -49,8 +50,8 @@ namespace Il2Cpp {
4950 * });
5051 * ```
5152 */
52- get version ( ) : string | null {
53- return unityEngineCall ( "get_version" ) ;
53+ get version ( ) : string {
54+ return unityEngineCall ( "get_version" ) ?? exportsHash ( Il2Cpp . module ) . toString ( 16 ) ;
5455 }
5556 } ;
5657
Original file line number Diff line number Diff line change @@ -369,24 +369,4 @@ namespace Il2Cpp {
369369
370370 return new Il2Cpp . Tracer ( applier ( ) ) ;
371371 }
372-
373- /** https://stackoverflow.com/a/52171480/16885569 */
374- function cyrb53 ( str : string ) : number {
375- let h1 = 0xdeadbeef ;
376- let h2 = 0x41c6ce57 ;
377-
378- for ( let i = 0 , ch ; i < str . length ; i ++ ) {
379- ch = str . charCodeAt ( i ) ;
380- h1 = Math . imul ( h1 ^ ch , 2654435761 ) ;
381- h2 = Math . imul ( h2 ^ ch , 1597334677 ) ;
382- }
383-
384- h1 = Math . imul ( h1 ^ ( h1 >>> 16 ) , 2246822507 ) ;
385- h1 ^= Math . imul ( h2 ^ ( h2 >>> 13 ) , 3266489909 ) ;
386-
387- h2 = Math . imul ( h2 ^ ( h2 >>> 16 ) , 2246822507 ) ;
388- h2 ^= Math . imul ( h1 ^ ( h1 >>> 13 ) , 3266489909 ) ;
389-
390- return 4294967296 * ( 2097151 & h2 ) + ( h1 >>> 0 ) ;
391- }
392372}
Original file line number Diff line number Diff line change 1+ /** @internal https://stackoverflow.com/a/52171480/16885569 */
2+ function cyrb53 ( str : string ) : number {
3+ let h1 = 0xdeadbeef ;
4+ let h2 = 0x41c6ce57 ;
5+
6+ for ( let i = 0 , ch ; i < str . length ; i ++ ) {
7+ ch = str . charCodeAt ( i ) ;
8+ h1 = Math . imul ( h1 ^ ch , 2654435761 ) ;
9+ h2 = Math . imul ( h2 ^ ch , 1597334677 ) ;
10+ }
11+
12+ h1 = Math . imul ( h1 ^ ( h1 >>> 16 ) , 2246822507 ) ;
13+ h1 ^= Math . imul ( h2 ^ ( h2 >>> 13 ) , 3266489909 ) ;
14+
15+ h2 = Math . imul ( h2 ^ ( h2 >>> 16 ) , 2246822507 ) ;
16+ h2 ^= Math . imul ( h1 ^ ( h1 >>> 13 ) , 3266489909 ) ;
17+
18+ return 4294967296 * ( 2097151 & h2 ) + ( h1 >>> 0 ) ;
19+ }
20+
21+ /** @internal */
22+ function exportsHash ( module : Module ) : number {
23+ return cyrb53 (
24+ module
25+ . enumerateExports ( )
26+ . sort ( ( a , b ) => a . name . localeCompare ( b . name ) )
27+ . map ( _ => _ . name + _ . address . sub ( module . base ) )
28+ . join ( "" )
29+ ) ;
30+ }
You can’t perform that action at this time.
0 commit comments