-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.py
143 lines (112 loc) · 4.36 KB
/
build.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# -------------------------------------------------------------------------------
# MIT License
#
# Copyright (c) 2023 Not Enough Photons & adamdev
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# -------------------------------------------------------------------------------
import os
import sys
import subprocess
import time
import math
bti_template = """// Generated by build.py!
//
// Contains unique build info (useful for tracking the version people are using!)
namespace NEP.MonoDirector
{
static partial class BuildInfo
{
###CONTENTS###
}
}"""
if not os.path.exists("Links"):
print("Links folder does not exist! Have you ran setup_build.py before running this script?")
exit(1)
debug_build = "--debug" in sys.argv
run_after = False
quest_run_after = False
quest_build = False
quest_uselogcat = False
if "clean" in sys.argv:
command = "dotnet clean"
if debug_build:
command += " -c Debug"
else:
command += " -c Release"
os.system(command)
exit(0)
if "run" in sys.argv:
print("[Build] Will run BONELAB after building...")
run_after = True
if "quest" in sys.argv:
print("[Build] Building for Quest... make sure the Quest is connected!")
quest_build = True
if "qrun" in sys.argv:
quest_run_after = True
if "logcat" in sys.argv:
quest_uselogcat = True
command = "dotnet build"
if debug_build:
print("[Build] Building Debug configuration...")
command += " -c Debug"
debug_build = True
else:
command += " -c Release"
# Before we build, update src/BuildInfo.gen.cs
with open("src/BuildInfo.gen.cs", "w") as out_file:
contents = ""
contents += f"\t\tpublic const int Epoch = {math.floor(time.time())};\n"
# https://stackoverflow.com/questions/14989858/get-the-current-git-hash-in-a-python-script
hash = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip()
contents += f"\t\tpublic const string GitCommit = \"{hash}\";"
final = bti_template.replace("###CONTENTS###", contents)
out_file.write(final)
# Then build
if os.system(command) != 0:
print("[Build] Failed with non-zero return code!")
exit(1)
# Copy the resulting output if we want to
out_path = "./Output/"
if debug_build:
out_path += "Debug/"
else:
out_path += "Release/"
out_path += "MonoDirector.dll"
print("[Build] Output is located at '" + out_path + "'")
if quest_build:
quest_game_path = "/sdcard/Android/data/com.StressLevelZero.BONELAB/files/Mods"
with open(out_path, "rb"):
os.system(f"C:/adb/adb push {out_path} {quest_game_path}")
print("[Build] Copied MonoDirector.dll to the Quest mods folder!")
if quest_run_after:
os.system("C:/adb/adb shell am start -n com.StressLevelZero.BONELAB/com.unity3d.player.UnityPlayerActivity")
if quest_uselogcat:
os.system("C:/adb/adb logcat MelonLoader:I *:S")
if run_after:
# Forces an overwrite of the existing file
with open(out_path, "rb") as out_file:
with open("./Links/Mods/MonoDirector.dll", "wb") as dst_file:
dst_file.write(out_file.read())
print("[Build] Copied MonoDirector.dll! Launching game...")
# Get the real exe name and real game path
game_path = os.readlink("./Links/Game").removeprefix("\\\\?\\")
real_exe = os.readlink("./Links/BONELAB.exe").removeprefix("\\\\?\\")
os.chdir(game_path)
os.startfile(real_exe)