|
| 1 | +// Package naming provides asset name mappings for EVR assets. |
| 2 | +package naming |
| 3 | + |
| 4 | +// AssetNameMapper maps file symbols to human-readable asset names. |
| 5 | +// This is populated with known assets and can be extended. |
| 6 | +type AssetNameMapper struct { |
| 7 | + symbolToName map[int64]string |
| 8 | + nameToSymbol map[string]int64 |
| 9 | +} |
| 10 | + |
| 11 | +// NewAssetNameMapper creates a new mapper with known assets. |
| 12 | +func NewAssetNameMapper() *AssetNameMapper { |
| 13 | + m := &AssetNameMapper{ |
| 14 | + symbolToName: make(map[int64]string), |
| 15 | + nameToSymbol: make(map[string]int64), |
| 16 | + } |
| 17 | + m.initializeKnownAssets() |
| 18 | + return m |
| 19 | +} |
| 20 | + |
| 21 | +// initializeKnownAssets populates the mapper with known asset names. |
| 22 | +// These are discovered from game analysis and documentation. |
| 23 | +func (m *AssetNameMapper) initializeKnownAssets() { |
| 24 | + // Level/Environment Assets (from game strings and analysis) |
| 25 | + // Store as uint64 then convert to int64 to handle the sign bit properly |
| 26 | + known := []struct { |
| 27 | + symbol uint64 |
| 28 | + name string |
| 29 | + }{ |
| 30 | + // Social/Lobby Level |
| 31 | + {0x43e2da7914642604, "social_2.0_arena"}, |
| 32 | + {0x43e2da7a0c623a19, "social_2.0_private"}, |
| 33 | + {0xd09afd15b1c75c04, "social_2.0_npe"}, |
| 34 | + |
| 35 | + // Common texture references |
| 36 | + {0xdf5ca7b7dfa383d4, "arena_environment"}, |
| 37 | + {0xcb9977f7fc2b4526, "lobby_environment"}, |
| 38 | + {0x576ed3f8428ebc4b, "courtyard_environment"}, |
| 39 | + {0x3f9915d3001dc28e, "environment_lighting"}, |
| 40 | + {0x3c8d74713ced8c3f, "environment_props"}, |
| 41 | + {0xac360e41e4ede056, "environment_decals"}, |
| 42 | + {0xe24c89df8235dd7a, "environment_particles"}, |
| 43 | + {0x4d82118c7c91b6bb, "environment_effects"}, |
| 44 | + |
| 45 | + // Note: Additional mappings can be added as they are discovered |
| 46 | + // through game binary analysis and community research |
| 47 | + } |
| 48 | + |
| 49 | + for _, item := range known { |
| 50 | + sym := int64(item.symbol) |
| 51 | + m.symbolToName[sym] = item.name |
| 52 | + m.nameToSymbol[item.name] = sym |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +// GetName returns the name for a file symbol, or a fallback if unknown. |
| 57 | +// If the symbol is unknown, returns a hex representation. |
| 58 | +func (m *AssetNameMapper) GetName(fileSymbol int64) string { |
| 59 | + if name, ok := m.symbolToName[fileSymbol]; ok { |
| 60 | + return name |
| 61 | + } |
| 62 | + // Fallback: return hex representation |
| 63 | + return formatHexSymbol(fileSymbol) |
| 64 | +} |
| 65 | + |
| 66 | +// HasName returns true if a name is known for the given symbol. |
| 67 | +func (m *AssetNameMapper) HasName(fileSymbol int64) bool { |
| 68 | + _, ok := m.symbolToName[fileSymbol] |
| 69 | + return ok |
| 70 | +} |
| 71 | + |
| 72 | +// GetSymbol returns the symbol for a known name, or 0 if not found. |
| 73 | +func (m *AssetNameMapper) GetSymbol(name string) int64 { |
| 74 | + if sym, ok := m.nameToSymbol[name]; ok { |
| 75 | + return sym |
| 76 | + } |
| 77 | + return 0 |
| 78 | +} |
| 79 | + |
| 80 | +// AddMapping adds or updates an asset name mapping. |
| 81 | +func (m *AssetNameMapper) AddMapping(fileSymbol int64, name string) { |
| 82 | + m.symbolToName[fileSymbol] = name |
| 83 | + m.nameToSymbol[name] = fileSymbol |
| 84 | +} |
| 85 | + |
| 86 | +// AddMappings adds multiple asset name mappings at once. |
| 87 | +func (m *AssetNameMapper) AddMappings(mappings map[int64]string) { |
| 88 | + for sym, name := range mappings { |
| 89 | + m.AddMapping(sym, name) |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +// KnownSymbolCount returns the number of known symbol mappings. |
| 94 | +func (m *AssetNameMapper) KnownSymbolCount() int { |
| 95 | + return len(m.symbolToName) |
| 96 | +} |
| 97 | + |
| 98 | +// formatHexSymbol returns a hex representation of a symbol. |
| 99 | +func formatHexSymbol(symbol int64) string { |
| 100 | + return formatHex(uint64(symbol)) |
| 101 | +} |
| 102 | + |
| 103 | +// formatHex returns a hex string representation of a uint64. |
| 104 | +// This is intentionally simple - returns the 16-digit hex value. |
| 105 | +func formatHex(value uint64) string { |
| 106 | + const hexChars = "0123456789abcdef" |
| 107 | + var result [16]byte |
| 108 | + |
| 109 | + for i := 15; i >= 0; i-- { |
| 110 | + result[i] = hexChars[value&0xf] |
| 111 | + value >>= 4 |
| 112 | + } |
| 113 | + |
| 114 | + return string(result[:]) |
| 115 | +} |
| 116 | + |
| 117 | +// GlobalAssetMapper is the default global mapper instance. |
| 118 | +var globalAssetMapper = NewAssetNameMapper() |
| 119 | + |
| 120 | +// GetAssetName returns the name for a file symbol using the global mapper. |
| 121 | +func GetAssetName(fileSymbol int64) string { |
| 122 | + return globalAssetMapper.GetName(fileSymbol) |
| 123 | +} |
| 124 | + |
| 125 | +// HasAssetName returns true if a name is known using the global mapper. |
| 126 | +func HasAssetName(fileSymbol int64) bool { |
| 127 | + return globalAssetMapper.HasName(fileSymbol) |
| 128 | +} |
| 129 | + |
| 130 | +// AddGlobalMapping adds a mapping to the global mapper. |
| 131 | +func AddGlobalMapping(fileSymbol int64, name string) { |
| 132 | + globalAssetMapper.AddMapping(fileSymbol, name) |
| 133 | +} |
| 134 | + |
| 135 | +// AddGlobalMappings adds multiple mappings to the global mapper. |
| 136 | +func AddGlobalMappings(mappings map[int64]string) { |
| 137 | + globalAssetMapper.AddMappings(mappings) |
| 138 | +} |
0 commit comments