Skip to content

Commit 4acffc9

Browse files
committed
📦 Set custom extraction path for natives
1 parent 0965862 commit 4acffc9

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

common/src/main/java/com/mrcrayfish/controllable/client/input/sdl2/SDL2ControllerManager.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import com.mrcrayfish.controllable.client.input.Controller;
88
import com.mrcrayfish.controllable.client.input.DeviceInfo;
99
import com.mrcrayfish.controllable.client.input.MultiController;
10+
import com.mrcrayfish.controllable.util.Utils;
1011
import com.mrcrayfish.controllable_sdl.api.gamecontroller.SdlGamecontroller;
12+
import com.mrcrayfish.controllable_sdl.jna.SdlNativeLibraryLoader;
1113
import com.sun.jna.Memory;
1214
import com.mrcrayfish.controllable_sdl.api.joystick.SDL_JoystickID;
1315
import com.mrcrayfish.controllable_sdl.api.rwops.SDL_RWops;
@@ -16,6 +18,8 @@
1618
import org.jetbrains.annotations.Nullable;
1719
import java.io.IOException;
1820
import java.io.InputStream;
21+
import java.nio.file.Files;
22+
import java.nio.file.Path;
1923
import java.util.ArrayList;
2024
import java.util.HashMap;
2125
import java.util.Iterator;
@@ -41,6 +45,32 @@
4145
*/
4246
public class SDL2ControllerManager extends AdaptiveControllerManager
4347
{
48+
static
49+
{
50+
try
51+
{
52+
Path natives = Utils.getGamePath().resolve("controllable_natives");
53+
Path sdl = natives.resolve("SDL");
54+
Files.createDirectories(sdl);
55+
SdlNativeLibraryLoader.setExtractionPath(sdl);
56+
57+
// Add a readme to the natives directory for users
58+
Path readMeFile = natives.resolve("README.txt");
59+
if(!Files.exists(readMeFile))
60+
{
61+
Files.writeString(readMeFile, """
62+
This directory holds the natives for Controllable, which are used to interface
63+
with game controllers and read their inputs. It is safe to delete, just make sure
64+
the game is closed as the natives may be loaded; preventing you from deleting them.
65+
If you are developing a modpack, make sure to exclude this directory.""");
66+
}
67+
}
68+
catch(IOException e)
69+
{
70+
throw new RuntimeException(e);
71+
}
72+
}
73+
4474
@Override
4575
public void init()
4676
{

common/src/main/java/com/mrcrayfish/controllable/util/Utils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public static ResourceLocation resource(String name)
1515
return ResourceLocation.fromNamespaceAndPath(Constants.MOD_ID, name);
1616
}
1717

18+
public static Path getGamePath()
19+
{
20+
return com.mrcrayfish.framework.platform.Services.CONFIG.getGamePath();
21+
}
22+
1823
public static Path getConfigDirectory()
1924
{
2025
return com.mrcrayfish.framework.platform.Services.CONFIG.getConfigPath();

0 commit comments

Comments
 (0)