-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
192 lines (187 loc) · 7.06 KB
/
Program.cs
File metadata and controls
192 lines (187 loc) · 7.06 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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
using ResourceModLoader.Module;
using ResourceModLoader.Tool;
using ResourceModLoader.Tool.Creator;
using ResourceModLoader.Tool.SpriteAnimTool;
using ResourceModLoader.Tool.WWiseTool;
using ResourceModLoader.Utils;
namespace ResourceModLoader
{
class Program
{
public static string VERSION = "0.1.22";
public static GameModder Modder;
public static bool isDevMode = false;
static void Main(string[] args)
{
Modder = new GameModder(DiscoverGameDir(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)));
if (!Modder.isValid)
{
Log.Wait();
return;
}
if (Modder.addressableMgr.Loaded() == 0)
{
Log.Warn("当前状态无法进行该操作,请先启动游戏下载资源");
Log.Wait();
return;
}
Modder.Install(args);
if (args.Length > 0)
{
if (args[0] == "tool")
{
Tool(args);
return;
}
else if (args[0] == "dev")
{
isDevMode = true;
}
else if (args[0] == "debug")
{
Modder.isDebugMode= true;
}
else if (args[0] == "u" || args[0] == "update")
{
var a = new AddressableUpdator(Modder);
a.startCollectUrl();
return;
}
else
{
Log.Warn("未识别的参数");
return;
}
}
TryCopy();
do
{
Modder.ProcessMods(isDevMode);
if(isDevMode)
Log.Info("继续运行将重新应用mod");
Log.Wait();
} while (isDevMode);
}
static void Tool(string[] args)
{
if (args.Length < 2)
{
PrintToolHelp();
return;
}
string toolName = args[1];
string[] remain = new string[Math.Max(args.Length - 2, 0)];
Array.Copy(args, 2, remain, 0, remain.Length);
if (toolName == "proto-export")
{
ProtoExportTool.Invoke(remain, Modder.addressableMgr, Modder.scan);
}
else if (toolName == "wwise-export")
{
WWiseExtractTool.Invoke(remain, Modder);
}
else if (toolName == "merge")
{
MergedExportTool.ExportRedirectedBundle(Modder);
}
else if (toolName == "create")
CreateTool.Invoke(Modder);
else if (toolName == "sprite-anim")
{
SpriteAnimTool.HandleSpriteAnimTool(remain);
}
else
{
Log.Warn($"未知的工具: {toolName}");
PrintToolHelp();
}
}
static void PrintToolHelp()
{
Log.Info("可用工具:");
Log.Info(" create - 模组包创建工具");
Log.Info(" proto-export - 导出Proto");
Log.Info(" wwise-export - 导出WWise SoundBnk");
Log.Info(" merge - 使用合并模式运行ModProcess,并将结果整理导出到exported");
Log.Info(" sprite-anim - AssetBundle动画导出/回填工具");
Log.Info("");
Log.Info("使用 'tool <toolName> help' 查看详细用法");
}
static string DiscoverGameDir(string user)
{
string currentPath = Directory.GetCurrentDirectory();
if (Path.Exists(Path.Combine(currentPath, "possible_names.txt")))
{
const string DETECT_STR = "[Subsystems] Discovering subsystems at path ";
var possibleNames = File.ReadAllText(Path.Combine(currentPath, "possible_names.txt")).Split("\n");
foreach (var possibleName in possibleNames)
{
var detectPath = Path.Combine(possibleName.Trim().Replace("{User}", user), "Player.log");
if (File.Exists(detectPath))
{
var unityLog = "";
try
{
unityLog = File.ReadAllText(detectPath);
}catch (Exception ex)
{
Log.Warn("无法打开" + possibleName + "的日志文件。如果对应的游戏正在运行,请关闭后重试");
continue;
}
var sp = unityLog.IndexOf(DETECT_STR);
if (sp >= 0)
{
sp += DETECT_STR.Length;
var ep = unityLog.IndexOf("\n", sp);
var path = unityLog.Substring(sp, ep - sp);
path = Path.GetDirectoryName(Path.GetDirectoryName(path));
return path;
}
}
}
}
return currentPath;
}
static void TryCopy()
{
string currentPath = Directory.GetCurrentDirectory();
if (Path.Exists(Path.Combine(currentPath, "copies.txt")))
{
string modsDirectory = Path.Combine(Modder.basePath, "mods");
var copyItems = File.ReadAllText(Path.Combine(currentPath, "copies.txt")).Split("\n");
foreach (var copyItem in copyItems)
{
string sourceItem = copyItem;
string targetItem = copyItem;
if (copyItem.Contains(":"))
{
var t = copyItem.Split(':');
sourceItem= t[0];
targetItem = t[1];
}
var p = Path.Combine(currentPath, sourceItem.Trim());
var target = Path.Combine(modsDirectory, targetItem.Trim());
var dir = Path.GetDirectoryName(target);
if(!Path.Exists(dir))
Directory.CreateDirectory(dir);
if (File.Exists(p))
{
File.Copy(p, target,true);
Log.SuccessAll($"已复制文件 {target}");
}
else if (Directory.Exists(p))
{
if(Directory.Exists(target))
Directory.Delete(target,true);
Util.CopyDirectory(p, target,true);
Log.SuccessAll($"已复制目录 {target}");
}
else
{
Log.Warn($"要拷贝的文件{p}不存在");
}
}
}
}
}
}