forked from hippolippo/Unity-Mod-Maker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModObjectBuilder.py
More file actions
107 lines (88 loc) · 3.68 KB
/
Copy pathModObjectBuilder.py
File metadata and controls
107 lines (88 loc) · 3.68 KB
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
from CodeManager import *
def end_block(newline=True):
return CodeLine("}\n ") if newline else CodeLine("}")
def create_headers():
code = [
CodeLine("using System;"),
CodeLine("using System.Collections;"),
CodeLine("using BepInEx;"),
CodeLine("using BepInEx.Logging;"),
CodeLine("using HarmonyLib;"),
CodeLine("using BepInEx.Configuration;"),
CodeLine("using UnityEngine;"),
CodeLine("using System.Reflection;\n "),
]
return CodeBlock(code_lines=code)
def create_namespace(mod_name, mod_name_no_space):
namespace_top = CodeBlock([
CodeLine("namespace"),
mod_name_no_space,
CodeLine("\n{")
],
delimiter=" "
)
namespace = CodeBlockWrapper(
prefix=namespace_top,
postfix=end_block(False)
)
return namespace
def create_namespace_contents(game):
namespace_contents = LargeCodeBlockWrapper()
bix_dependencies = CodeBlock()
bix_dependencies.add_line(code_line=CodeLine("[BepInPlugin(pluginGuid, pluginName, pluginVersion)]"))
bix_dependencies.add_line(code_line=CodeLine(
"[BepInProcess(\"" + game + "\")]"
))
bix_dependencies.add_line(code_line=CodeLine(
"[BepInDependency(ConfigurationManager.ConfigurationManager.GUID, BepInDependency.DependencyFlags.HardDependency)]"
))
namespace_contents.insert_block_before(bix_dependencies)
namespace_contents.insert_block_after(LargeCodeBlockWrapper())
return namespace_contents
def create_class(mod_name, mod_name_no_space):
output = CodeBlockWrapper(
prefix=CodeBlock(code_lines=[
CodeLine("public class"),
mod_name_no_space,
CodeLine("\n {")
], delimiter=" "),
contents=LargeCodeBlockWrapper(),
postfix=end_block(False)
)
output.prefix.add_line(CodeLine(": BaseUnityPlugin"), location=2)
return output
def create_constants(mod_name, mod_name_no_space, version):
output = LargeCodeBlockWrapper()
plugin_guid = LargeCodeBlockWrapper([CodeLine("public const string pluginGuid =")], delimiter=" ")
output.insert_block_after(plugin_guid)
plugin_guid.insert_block_after(CodeBlock([CodeLine("\"org.bepinex.plugins."),
mod_name_no_space, CodeLine("\";")], delimiter=""))
plugin_name = LargeCodeBlockWrapper([CodeLine("public const string pluginName =")], delimiter=" ")
output.insert_block_after(plugin_name)
plugin_name.insert_block_after(CodeBlock([CodeLine("\""), mod_name, CodeLine("\";")], delimiter=""))
plugin_version = LargeCodeBlockWrapper([CodeLine("public const string pluginVersion =")], delimiter=" ")
output.insert_block_after(plugin_version)
plugin_version.insert_block_after(CodeBlock([CodeLine("\""), version, CodeLine("\";")], delimiter=""))
return output
def create_function(head, contents=None):
if contents is None:
new_contents = LargeCodeBlockWrapper()
else:
new_contents = contents
head = CodeLine(head + "\n {")
function = CodeBlockWrapper(
prefix=head,
contents=new_contents,
postfix=end_block()
)
return function
def create_awake(mod_name, mod_name_no_space):
output = LargeCodeBlockWrapper()
output.insert_block_after(CodeBlock([CodeLine("Harmony.CreateAndPatchAll(typeof("), mod_name_no_space,
CodeLine("));")], delimiter=""))
output = create_function("void Awake()", contents=output)
return output
def create_update(mod_name, mod_name_no_space):
output = LargeCodeBlockWrapper()
output = create_function("void Update()", contents=output)
return output