|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Collections.Immutable; |
| 4 | +using System.Diagnostics; |
4 | 5 | using System.IO; |
5 | 6 | using System.Linq; |
6 | 7 | using System.Reflection; |
@@ -144,10 +145,49 @@ public static List<PortableExecutableReference> GenerateExhaustiveMetadataRefere |
144 | 145 | return referencesStr.Select(r => MetadataReference.CreateFromFile(r)).ToList(); |
145 | 146 | } |
146 | 147 |
|
| 148 | + private static readonly Dictionary<string, string> s_gameAliases = new(StringComparer.OrdinalIgnoreCase) |
| 149 | + { |
| 150 | + { "MonsterHunterWilds", "MHWILDS" }, |
| 151 | + { "DevilMayCry5", "DMC5" }, |
| 152 | + { "StreetFighter6", "SF6" }, |
| 153 | + { "DD2", "DD2" }, |
| 154 | + }; |
| 155 | + |
| 156 | + private static List<string> GetGamePreprocessorSymbols() |
| 157 | + { |
| 158 | + var symbols = new List<string> { "REFRAMEWORK" }; |
| 159 | + |
| 160 | + try |
| 161 | + { |
| 162 | + var exePath = Process.GetCurrentProcess().MainModule.FileName; |
| 163 | + var exeName = Path.GetFileNameWithoutExtension(exePath); |
| 164 | + |
| 165 | + // Always define the exe name (uppercased, non-alphanumeric stripped) |
| 166 | + var normalized = new string(exeName.Where(c => char.IsLetterOrDigit(c) || c == '_').ToArray()).ToUpperInvariant(); |
| 167 | + if (normalized.Length > 0 && !char.IsDigit(normalized[0])) |
| 168 | + symbols.Add(normalized); |
| 169 | + |
| 170 | + // Known short aliases |
| 171 | + if (s_gameAliases.TryGetValue(exeName, out var alias) && alias != normalized) |
| 172 | + symbols.Add(alias); |
| 173 | + |
| 174 | + Console.WriteLine($"[Compiler] Preprocessor symbols: {string.Join(", ", symbols)}"); |
| 175 | + } |
| 176 | + catch (Exception ex) |
| 177 | + { |
| 178 | + Console.WriteLine($"[Compiler] Failed to detect game for preprocessor symbols: {ex.Message}"); |
| 179 | + } |
| 180 | + |
| 181 | + return symbols; |
| 182 | + } |
| 183 | + |
147 | 184 | private static CSharpCompilation GenerateCode(string sourceCode, string filePath, Assembly executingAssembly, List<Assembly> deps) |
148 | 185 | { |
149 | 186 | var codeString = SourceText.From(sourceCode); |
150 | | - var options = CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp12); |
| 187 | + var symbols = GetGamePreprocessorSymbols(); |
| 188 | + var options = CSharpParseOptions.Default |
| 189 | + .WithLanguageVersion(LanguageVersion.CSharp12) |
| 190 | + .WithPreprocessorSymbols(symbols); |
151 | 191 | var parsedSyntaxTree = SyntaxFactory.ParseSyntaxTree(codeString, options); |
152 | 192 |
|
153 | 193 | var references = GenerateExhaustiveMetadataReferences(executingAssembly, deps); |
|
0 commit comments