forked from yusefnapora/m1-multimc-hack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmcwrap.py
executable file
·82 lines (58 loc) · 2.26 KB
/
mcwrap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
import os
import sys
import subprocess
import glob
import pathlib
import logging
import shutil
LOG_FILE='/tmp/mcwrap.log'
logging.getLogger().addHandler(logging.FileHandler(LOG_FILE))
def this_dir():
return os.path.dirname(os.path.abspath(__file__))
def lwjgl_jar_path():
return os.path.join(this_dir(), 'lwjglfat.jar')
def openal_jar_path():
return os.path.join(this_dir(), 'openal.jar')
def lwjglutil_jar_path():
return os.path.join(this_dir(), 'lwjgl_util.jar')
def m1_native_libs_dir():
return os.path.join(this_dir(), 'lwjglnatives')
def copy_native_libs(dest_dir):
shutil.rmtree(dest_dir)
pathlib.Path(dest_dir).mkdir(parents=True, exist_ok=True)
logging.info('copying native libs from {} to {}'.format(m1_native_libs_dir(), dest_dir))
for f in glob.glob('{}/*.dylib'.format(m1_native_libs_dir())):
logging.info('copying {}'.format(os.path.basename(f)))
shutil.copy(f, dest_dir)
def rewrite_classpath(cp):
jars = [j for j in cp.split(':') if 'lwjgl' not in j]
jars.append(lwjgl_jar_path())
jars.append(openal_jar_path())
jars.append(lwjglutil_jar_path())
logging.info('rewritten classpath: {}'.format(jars))
return ':'.join(jars)
def rewrite_mc_args(mc_args):
out = []
for a in mc_args:
if 'lwjgl' in a:
a = rewrite_classpath(a)
logging.info('arg: {}'.format(a))
out.append(a)
return out
def launch_mc(mc_args):
logging.info('running minecraft with args: {}'.format(mc_args))
subprocess.run(mc_args)
def instance_dir():
return os.environ['INST_DIR']
def natives_dir():
return os.path.join(instance_dir(), 'natives')
def run():
mc_args = rewrite_mc_args(sys.argv[1:])
if not os.path.isdir(natives_dir()):
os.mkdir(natives_dir())
#edited line(s) above - what was happening was that when I closed the instance that I applied this script to, the folder containing the LWJGL natives was removed for some reason, hence this small modification checks if the folder exists (in edge cases it doesn't get removed, and we don't want to create a duplicate etc.), and if it has been, regenerates the folder.
copy_native_libs(natives_dir())
launch_mc(mc_args)
if __name__ == '__main__':
run()