77import java .nio .file .Path ;
88import java .nio .file .Paths ;
99import java .security .CodeSource ;
10- import java .util .ArrayList ;
11- import java .util .Collection ;
12- import java .util .Collections ;
13- import java .util .HashMap ;
14- import java .util .List ;
15- import java .util .Locale ;
16- import java .util .Map ;
10+ import java .util .*;
1711
1812import net .fabricmc .api .EnvType ;
1913import net .fabricmc .loader .api .ObjectShare ;
2923import net .fabricmc .loader .impl .game .minecraft .McVersionLookup ;
3024import net .fabricmc .loader .impl .game .patch .GameTransformer ;
3125import net .fabricmc .loader .impl .launch .FabricLauncher ;
26+ import net .fabricmc .loader .impl .launch .MappingConfiguration ;
3227import net .fabricmc .loader .impl .metadata .BuiltinModMetadata ;
3328import net .fabricmc .loader .impl .metadata .ContactInformationImpl ;
3429import net .fabricmc .loader .impl .metadata .ModDependencyImpl ;
4540import org .mcphackers .launchwrapper .util .ClassNodeSource ;
4641
4742public class LWGameProvider implements GameProvider {
43+ private static final Set <BuiltinTransform > TRANSFORM_WIDENALL_STRIPENV_CLASSTWEAKS = EnumSet .of (BuiltinTransform .WIDEN_ALL_PACKAGE_ACCESS , BuiltinTransform .STRIP_ENVIRONMENT , BuiltinTransform .CLASS_TWEAKS );
44+ private static final Set <BuiltinTransform > TRANSFORM_WIDENALL_CLASSTWEAKS = EnumSet .of (BuiltinTransform .WIDEN_ALL_PACKAGE_ACCESS , BuiltinTransform .CLASS_TWEAKS );
45+ private static final Set <BuiltinTransform > TRANSFORM_STRIPENV = EnumSet .of (BuiltinTransform .STRIP_ENVIRONMENT );
4846
4947 public LaunchConfig config = FabricBridge .getInstance ().config ;
5048 public MainLaunchTarget target = null ;
@@ -85,6 +83,11 @@ public void launch(ClassLoader loader) {
8583 }
8684 }
8785
86+ @ Override
87+ public boolean displayCrash (Throwable exception , String context ) {
88+ return GameProvider .super .displayCrash (exception , context );
89+ }
90+
8891 private Path getLaunchwrapperSource () {
8992 CodeSource source = Launch .class .getProtectionDomain ().getCodeSource ();
9093 if (source != null ) {
@@ -209,6 +212,7 @@ public Collection<BuiltinMod> getBuiltinMods() {
209212 .setEnvironment (ModEnvironment .CLIENT )
210213 .setDescription ("Launch wrapper for legacy Minecraft" )
211214 .addAuthor ("lassebq" , Collections .emptyMap ())
215+ .addContributor ("Zero_DSRS_VX" , Collections .emptyMap ())
212216 .addIcon (16 , "icon_16x16.png" )
213217 .addIcon (32 , "icon_32x32.png" )
214218 .addIcon (48 , "icon_48x48.png" )
@@ -244,13 +248,27 @@ public Path getGameJar() {
244248 }
245249
246250 @ Override
247- public boolean isObfuscated () {
248- return true ;
251+ public boolean requiresUrlClassLoader () {
252+ return hasModLoader ;
249253 }
250254
251255 @ Override
252- public boolean requiresUrlClassLoader () {
253- return hasModLoader ;
256+ public Set <BuiltinTransform > getBuiltinTransforms (String className ) {
257+ boolean isMinecraftClass = className .startsWith ("net.minecraft." ) // unobf classes in indev and later
258+ || className .startsWith ("com.mojang.minecraft." ) // unobf classes in classic
259+ || className .startsWith ("com.mojang.rubydung." ) // unobf classes in pre-classic
260+ || className .startsWith ("com.mojang.blaze3d." ) // unobf blaze3d classes
261+ || className .indexOf ('.' ) < 0 ; // obf classes
262+
263+ if (isMinecraftClass ) {
264+ if (FabricLoaderImpl .INSTANCE .isDevelopmentEnvironment ()) { // combined client+server jar, strip back down to production equivalent
265+ return TRANSFORM_WIDENALL_STRIPENV_CLASSTWEAKS ;
266+ } else { // environment specific jar, inherently env stripped
267+ return TRANSFORM_WIDENALL_CLASSTWEAKS ;
268+ }
269+ } else { // mod class TODO: exclude game libs
270+ return TRANSFORM_STRIPENV ;
271+ }
254272 }
255273
256274 @ Override
@@ -267,12 +285,28 @@ public boolean hasAwtSupport() {
267285 public void initialize (FabricLauncher launcher ) {
268286 launcher .setValidParentClassPath (validParentClassPath );
269287
270- if (isObfuscated ()) {
288+
289+ String gameNs = System .getProperty (SystemProperties .GAME_MAPPING_NAMESPACE );
290+
291+ if (gameNs == null ) {
292+ List <String > mappingNamespaces ;
293+
294+ if (launcher .isDevelopment ()) {
295+ gameNs = MappingConfiguration .NAMED_NAMESPACE ;
296+ } else if ((mappingNamespaces = launcher .getMappingConfiguration ().getNamespaces ()) == null
297+ || mappingNamespaces .contains (MappingConfiguration .OFFICIAL_NAMESPACE )) {
298+ gameNs = MappingConfiguration .OFFICIAL_NAMESPACE ;
299+ } else {
300+ gameNs = envType == EnvType .CLIENT ? MappingConfiguration .CLIENT_OFFICIAL_NAMESPACE : MappingConfiguration .SERVER_OFFICIAL_NAMESPACE ;
301+ }
302+ }
303+
304+ if (!gameNs .equals (launcher .getMappingConfiguration ().getRuntimeNamespace ())) { // game is obfuscated / in another namespace -> remap
271305 Map <String , Path > obfJars = new HashMap <>(1 );
272306 String clientSide = envType .name ().toLowerCase (Locale .ENGLISH );
273307 obfJars .put (clientSide , gameJar );
274308
275- obfJars = GameProviderHelper .deobfuscate (obfJars ,
309+ obfJars = GameProviderHelper .deobfuscate (obfJars , gameNs ,
276310 getGameId (), getNormalizedGameVersion (),
277311 getLaunchDirectory (),
278312 launcher );
@@ -302,6 +336,11 @@ public String[] getLaunchArguments(boolean sanitize) {
302336 return config .getArgs ();
303337 }
304338
339+ @ Override
340+ public String getRuntimeNamespace (String defaultNs ) {
341+ return GameProvider .super .getRuntimeNamespace (defaultNs );
342+ }
343+
305344 @ Override
306345 public boolean canOpenErrorGui () {
307346 return envType == EnvType .CLIENT ;
0 commit comments