Skip to content

Commit 9189b2e

Browse files
committed
Add hotfix for UTF-8 properties file.
1 parent 80a9f52 commit 9189b2e

File tree

3 files changed

+92
-2
lines changed

3 files changed

+92
-2
lines changed

loader/src/main/java/com/fox2code/foxloader/client/gui/GuiConfigProviderConfigObject.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2023-2025 Fox2Code
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
124
package com.fox2code.foxloader.client.gui;
225

326
import net.minecraft.client.gui.GuiScreen;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2023-2025 Fox2Code
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package com.fox2code.foxloader.internal;
25+
26+
import java.io.*;
27+
import java.nio.charset.StandardCharsets;
28+
import java.util.Properties;
29+
30+
public class InternalHotfixesHooks {
31+
public static void loadProperties(Properties properties, InputStream inputStream) throws IOException {
32+
properties.load(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
33+
}
34+
35+
public static void storeProperties(Properties properties, OutputStream outputStream, String comment) throws IOException {
36+
properties.store(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8), comment);
37+
}
38+
}

patching/src/main/java/com/fox2code/foxloader/patching/game/HotfixesPatch.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,50 @@
2323
*/
2424
package com.fox2code.foxloader.patching.game;
2525

26+
import org.objectweb.asm.Opcodes;
2627
import org.objectweb.asm.tree.*;
2728

2829
/**
2930
* Theses are just hotfixes for the game, dedicated to fixing ReIndev bugs and crashes.
3031
*/
3132
final class HotfixesPatch extends GamePatch {
32-
static final boolean USE_HOTFIXES = false;
33+
private static final String PropertyManager = "net/minecraft/server/util/PropertyManager";
34+
private static final String Properties = "java/util/Properties";
35+
private static final String InternalHotfixesHooks = "com/fox2code/foxloader/internal/InternalHotfixesHooks";
36+
static final boolean USE_HOTFIXES = true;
3337

3438
HotfixesPatch() {
35-
super(new String[]{});
39+
super(new String[]{PropertyManager});
3640
}
3741

3842
@Override
3943
public ClassNode transform(ClassNode classNode) {
44+
if (PropertyManager.equals(classNode.name)) {
45+
patchPropertyManager(classNode);
46+
}
4047
return classNode;
4148
}
4249

50+
private static void patchPropertyManager(ClassNode classNode) {
51+
for (MethodNode methodNode : classNode.methods) {
52+
for (AbstractInsnNode abstractInsnNode : methodNode.instructions) {
53+
if (abstractInsnNode.getOpcode() == Opcodes.INVOKEVIRTUAL) {
54+
MethodInsnNode methodInsnNode = (MethodInsnNode) abstractInsnNode;
55+
if (Properties.equals(methodInsnNode.owner)) {
56+
if ("load".equals(methodInsnNode.name) &&
57+
"(Ljava/io/InputStream;)V".equals(methodInsnNode.desc)) {
58+
methodNode.instructions.set(methodInsnNode, new MethodInsnNode(
59+
Opcodes.INVOKESTATIC, InternalHotfixesHooks, "loadProperties",
60+
"(L" + Properties + ";Ljava/io/InputStream;)V"));
61+
} else if ("store".equals(methodInsnNode.name) &&
62+
"(Ljava/io/OutputStream;Ljava/lang/String;)V".equals(methodInsnNode.desc)) {
63+
methodNode.instructions.set(methodInsnNode, new MethodInsnNode(
64+
Opcodes.INVOKESTATIC, InternalHotfixesHooks, "storeProperties",
65+
"(L" + Properties + ";Ljava/io/OutputStream;Ljava/lang/String;)V"));
66+
}
67+
}
68+
}
69+
}
70+
}
71+
}
4372
}

0 commit comments

Comments
 (0)