export-table-plugin-csharp 1.1.189

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/.vscode/launch.json +21 -0
  2. package/bin/Json2LiteDB.exe +0 -0
  3. package/bin/Json2LiteDB.pdb +0 -0
  4. package/bin/LiteDB.dll +0 -0
  5. package/bin/LiteDB.xml +7288 -0
  6. package/dist/CSParseTool.d.ts +36 -0
  7. package/dist/CSParseTool.d.ts.map +1 -0
  8. package/dist/CSParseTool.js +533 -0
  9. package/dist/CSProtoParser.d.ts +22 -0
  10. package/dist/CSProtoParser.d.ts.map +1 -0
  11. package/dist/CSProtoParser.js +171 -0
  12. package/dist/ExportCSPlugin.d.ts +9 -0
  13. package/dist/ExportCSPlugin.d.ts.map +1 -0
  14. package/dist/ExportCSPlugin.js +290 -0
  15. package/dist/ExportLiteDBCSPlugin.d.ts +8 -0
  16. package/dist/ExportLiteDBCSPlugin.d.ts.map +1 -0
  17. package/dist/ExportLiteDBCSPlugin.js +221 -0
  18. package/dist/ExportLiteDBUnityCSJsonPlugin.d.ts +11 -0
  19. package/dist/ExportLiteDBUnityCSJsonPlugin.d.ts.map +1 -0
  20. package/dist/ExportLiteDBUnityCSJsonPlugin.js +190 -0
  21. package/dist/ExportUnityCSJsonPlugin.d.ts +10 -0
  22. package/dist/ExportUnityCSJsonPlugin.d.ts.map +1 -0
  23. package/dist/ExportUnityCSJsonPlugin.js +265 -0
  24. package/dist/ExportUnityMMPPlugin.d.ts +8 -0
  25. package/dist/ExportUnityMMPPlugin.d.ts.map +1 -0
  26. package/dist/ExportUnityMMPPlugin.js +116 -0
  27. package/dist/index.d.ts +7 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +15 -0
  30. package/package.json +24 -0
  31. package/res/mmp-cs/BitUtils.cs +171 -0
  32. package/res/mmp-cs/BitUtils.cs.meta +11 -0
  33. package/res/mmp-cs/WritableValueTuple.cs +40 -0
  34. package/res/mmp-cs/WritableValueTuple.cs.meta +11 -0
  35. package/src/CSParseTool.ts +425 -0
  36. package/src/CSProtoParser.ts +137 -0
  37. package/src/ExportCSPlugin.ts +321 -0
  38. package/src/ExportLiteDBCSPlugin.ts +245 -0
  39. package/src/ExportLiteDBUnityCSJsonPlugin.ts +175 -0
  40. package/src/ExportUnityCSJsonPlugin.ts +297 -0
  41. package/src/ExportUnityMMPPlugin.ts +127 -0
  42. package/src/index.ts +14 -0
  43. package/test/testCS.bat +1 -0
  44. package/test/testCSWithProto.bat +1 -0
  45. package/test/testLiteDB.bat +2 -0
  46. package/test/testUJson.bat +2 -0
  47. package/tsconfig.json +101 -0
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExportUJsonPlugin = void 0;
4
+ exports.exportUJson = exportUJson;
5
+ exports.exportUJsonLoader = exportUJsonLoader;
6
+ const export_table_lib_1 = require("export-table-lib");
7
+ const CSParseTool_1 = require("./CSParseTool");
8
+ var isSkipIndexLoader0 = process.argv.findIndex(v => v == "--SkipIndexLoader") >= 0;
9
+ var isWrapObject = process.argv.findIndex(v => v == "--WrapObject") >= 0;
10
+ let firstLetterUpper = export_table_lib_1.makeFirstLetterUpper;
11
+ function exportUJson(paras) {
12
+ let { datas, fields, name, objects, table, } = paras;
13
+ var fullName = `${table.workbookName}-${name}`;
14
+ let jsonString = JSON.stringify(objects.map(obj => {
15
+ var newObj = Object.create(null);
16
+ for (let f of fields) {
17
+ let key = f.name;
18
+ var newKey = (0, CSParseTool_1.convMemberName)(key);
19
+ newObj[newKey] = obj[key];
20
+ let content = obj[key];
21
+ let result = (0, CSParseTool_1.genTupleArrayValue)(f, content);
22
+ if (result != null) {
23
+ let { isArray, objs } = result;
24
+ if (isArray) {
25
+ newObj[newKey + "Obj"] = objs;
26
+ }
27
+ else {
28
+ if (objs.length > 1) {
29
+ console.log(`配置错误,过多的条目数量: ${content}`);
30
+ }
31
+ newObj[newKey + "Obj"] = objs[0] ?? {};
32
+ }
33
+ }
34
+ }
35
+ // Object.keys(obj).forEach(key => {
36
+ // var newKey = convMemberName(key);
37
+ // newObj[newKey] = obj[key];
38
+ // })
39
+ return newObj;
40
+ }));
41
+ if (isWrapObject) {
42
+ jsonString = `{"A":${jsonString}}`;
43
+ }
44
+ return jsonString;
45
+ // // !!!必须开头没有空格
46
+ // let temp = `%YAML 1.1
47
+ // %TAG !u! tag:unity3d.com,2011:
48
+ // --- !u!114 &11400000
49
+ // MonoBehaviour:
50
+ // m_ObjectHideFlags: 0
51
+ // m_CorrespondingSourceObject: {fileID: 0}
52
+ // m_PrefabInstance: {fileID: 0}
53
+ // m_PrefabAsset: {fileID: 0}
54
+ // m_GameObject: {fileID: 0}
55
+ // m_Enabled: 1
56
+ // m_EditorHideFlags: 0
57
+ // m_Script: {fileID: 11500000, guid: 496f60086c072a8479a6e0b948efb5e8, type: 3}
58
+ // m_Name: ${fullName}
59
+ // m_EditorClassIdentifier:
60
+ // JsonText: ${JSON.stringify(jsonString)}
61
+ // `
62
+ // return temp
63
+ }
64
+ function exportUJsonLoader(paras) {
65
+ let { datas, fields, name, objects, table, exportNamespace, allTags, } = paras;
66
+ let useJsonToolNamesapce = (0, CSParseTool_1.GetUsingJsonToolNamespace)();
67
+ let RowClass = firstLetterUpper(name);
68
+ let fullName = `${table.workbookName}-${name}`;
69
+ let isMMP = CSParseTool_1.isEnableMMP || allTags.indexOf('csharp:mmp') != -1;
70
+ let fileExt = isMMP ? ".bytes" : ".json";
71
+ // !!!必须开头没有空格
72
+ let temp = `
73
+ using System.Collections.Generic;
74
+ using System.Threading.Tasks;
75
+ using UnityEngine;
76
+ ${useJsonToolNamesapce}
77
+
78
+ namespace ${exportNamespace}
79
+ {
80
+ public partial class ${RowClass}
81
+ {
82
+ #if UNITY_EDITOR && ENABLE_CONFIG_LOG
83
+ static ${RowClass}()
84
+ {
85
+ Debug.Log("ReferConfig-${RowClass}");
86
+ }
87
+ #endif
88
+ [System.Serializable]
89
+ private struct TempA
90
+ {
91
+ public List<${RowClass}> a;
92
+ }
93
+
94
+ public const string LoadUrl = "Assets/Bundles/GameConfigs/Auto/${fullName}${fileExt}";
95
+ public static int LoadState = 0;
96
+ public static bool IsLoadedSuccessfully => LoadState == 4;
97
+ public static bool IsComplete => LoadState != 0;
98
+
99
+ public static async Task Load()
100
+ {
101
+ if (LoadState <= 0)
102
+ {
103
+ LoadState = 1;
104
+ var loadUrl = LoadUrl;
105
+ var configLiteral = await ConfigAssetLoader.LoadAssetAsync(loadUrl);
106
+ if (configLiteral != null)
107
+ {
108
+ Debug.Log($"解析配表: {loadUrl}");
109
+ try
110
+ {
111
+ // JsonUtility.FromJsonOverwrite("{\"a\":"+configLiteral+"}", obj);
112
+ LoadState = 2;
113
+ ConfigAssetLoader.LoadConfigs(configLiteral, Configs);
114
+ LoadState = 4;
115
+ }
116
+ catch (System.Exception ex)
117
+ {
118
+ LoadState = -2;
119
+ Debug.LogError($"解析配表失败: {loadUrl}");
120
+ throw ex;
121
+ }
122
+ }
123
+ else
124
+ {
125
+ LoadState = -1;
126
+ Debug.LogError($"配表资源缺失: {loadUrl}");
127
+ }
128
+ }
129
+ }
130
+
131
+ #if UNITY_EDITOR
132
+ public static void LoadInEditor(bool force = false, System.Func<string, string> pathConverter = null)
133
+ {
134
+ if ((!force) && UnityEditor.EditorApplication.isPlaying)
135
+ {
136
+ var tip = $"cannot load ${RowClass}[] with LoadInEditor at runtime";
137
+ Debug.LogError(tip);
138
+ throw new System.Exception(tip);
139
+ }
140
+ var loadUrl = pathConverter == null ? LoadUrl : pathConverter(LoadUrl);
141
+ var configLiteral = System.IO.File.ReadAllText(loadUrl, System.Text.Encoding.UTF8);
142
+ if (configLiteral != null)
143
+ {
144
+ Configs.Clear();
145
+ try
146
+ {
147
+ ConfigAssetLoader.LoadConfigs(configLiteral, Configs);
148
+ }
149
+ catch(System.Exception ex)
150
+ {
151
+ Debug.LogError($"解析配表失败: {loadUrl}");
152
+ throw ex;
153
+ }
154
+ }
155
+ else
156
+ {
157
+ Debug.LogError($"配表资源缺失: {loadUrl}");
158
+ }
159
+ }
160
+
161
+ public static void SaveInEditor(bool force = false, System.Func<string, string> pathConverter = null)
162
+ {
163
+ if ((!force) && UnityEditor.EditorApplication.isPlaying)
164
+ {
165
+ var tip = $"cannot load ${RowClass}[] with LoadInEditor at runtime";
166
+ Debug.LogError(tip);
167
+ throw new System.Exception(tip);
168
+ }
169
+
170
+ var loadUrl = pathConverter == null ? LoadUrl : pathConverter(LoadUrl);
171
+ string configLiteral = null;
172
+ try
173
+ {
174
+ configLiteral = ConfigAssetLoader.ToLiteral(Configs);
175
+ }
176
+ catch (System.Exception exception)
177
+ {
178
+ Debug.LogError($"json序列化失败: {loadUrl}");
179
+ throw exception;
180
+ }
181
+
182
+ if (configLiteral != null)
183
+ {
184
+ try
185
+ {
186
+ var content0 = System.IO.File.ReadAllText(loadUrl, System.Text.Encoding.UTF8);
187
+ if (content0 != configLiteral)
188
+ {
189
+ System.IO.File.WriteAllText(loadUrl, configLiteral, System.Text.Encoding.UTF8);
190
+ }
191
+ }
192
+ catch (System.Exception exception)
193
+ {
194
+ Debug.LogError($"写配置文件失败: {loadUrl}");
195
+ throw exception;
196
+ }
197
+ }
198
+ }
199
+ #endif
200
+ }
201
+ }
202
+ `;
203
+ return temp;
204
+ }
205
+ class ExportUJsonPlugin extends export_table_lib_1.PluginBase {
206
+ name = "ujson";
207
+ tags = ["ujson"];
208
+ handleSheet(paras) {
209
+ var fullName = `${paras.table.workbookName}-${paras.name}`;
210
+ {
211
+ let content1 = exportUJsonLoader(paras);
212
+ if (content1 != null) {
213
+ let savePath = new export_table_lib_1.OutFilePath(paras.outPath, fullName, "Loader.cs").fullPath;
214
+ (0, CSParseTool_1.outputFileSync)(savePath, content1, "utf-8");
215
+ }
216
+ }
217
+ {
218
+ let content2 = exportUJson(paras);
219
+ if (content2 != null) {
220
+ let savePath = new export_table_lib_1.OutFilePath(paras.outPath, fullName, ".json").fullPath;
221
+ (0, CSParseTool_1.outputFileSync)(savePath, content2, "utf-8");
222
+ }
223
+ return content2;
224
+ }
225
+ }
226
+ handleBatch(paras) {
227
+ let { moreOptions, tables, exportNamespace, } = paras;
228
+ let isSkipIndexLoader = moreOptions?.SkipIndexLoader ?? false;
229
+ if (isSkipIndexLoader0) {
230
+ isSkipIndexLoader = true;
231
+ }
232
+ if (isSkipIndexLoader) {
233
+ return;
234
+ }
235
+ var temp = `
236
+ using System;
237
+ using System.Collections.Generic;
238
+ using System.Threading.Tasks;
239
+
240
+ namespace ${exportNamespace}
241
+ {
242
+ public static class DefaultConfigLoader{
243
+ public static IEnumerable<Func<Task>> Load(){
244
+ ${(0, export_table_lib_1.foreach)(tables.sort((ta, tb) => ta.name.localeCompare(tb.name)), (table) => `
245
+ yield return ${firstLetterUpper(table.name)}.Load;
246
+ `)}
247
+ yield break;
248
+ }
249
+
250
+ #if UNITY_EDITOR
251
+ public static IEnumerable<Action<bool, System.Func<string, string>>> LoadInEditor(){
252
+ ${(0, export_table_lib_1.foreach)(tables.sort((ta, tb) => ta.name.localeCompare(tb.name)), (table) => `
253
+ yield return ${firstLetterUpper(table.name)}.LoadInEditor;
254
+ `)}
255
+ yield break;
256
+ }
257
+ #endif
258
+ }
259
+ }
260
+ `;
261
+ let savePath = paras.outPath + "/DefaultConfigLoader.cs";
262
+ (0, CSParseTool_1.outputFileSync)(savePath, temp, "utf-8");
263
+ }
264
+ }
265
+ exports.ExportUJsonPlugin = ExportUJsonPlugin;
@@ -0,0 +1,8 @@
1
+ import { HandleSheetParams, PluginBase } from "export-table-lib";
2
+ export declare function exportMMP(paras: HandleSheetParams): string | null;
3
+ export declare class ExportUnityMMPPlugin extends PluginBase {
4
+ name: string;
5
+ tags: string[];
6
+ handleSheet(paras: HandleSheetParams): void;
7
+ }
8
+ //# sourceMappingURL=ExportUnityMMPPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExportUnityMMPPlugin.d.ts","sourceRoot":"","sources":["../src/ExportUnityMMPPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAO,iBAAiB,EAA+B,UAAU,EAA6D,MAAM,kBAAkB,CAAA;AAQ7J,wBAAgB,SAAS,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,GAAG,IAAI,CAqGjE;AAED,qBAAa,oBAAqB,SAAQ,UAAU;IACnD,IAAI,SAAQ;IACZ,IAAI,EAAE,MAAM,EAAE,CAAU;IAExB,WAAW,CAAC,KAAK,EAAE,iBAAiB;CAUpC"}
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExportUnityMMPPlugin = void 0;
4
+ exports.exportMMP = exportMMP;
5
+ const export_table_lib_1 = require("export-table-lib");
6
+ const CSParseTool_1 = require("./CSParseTool");
7
+ var isEnableMMPB = process.argv.findIndex(v => v == "--EnableMMPB") >= 0;
8
+ let firstLetterUpper = export_table_lib_1.makeFirstLetterUpper;
9
+ function exportMMP(paras) {
10
+ let { datas, fields, name, objects, table, exportNamespace, } = paras;
11
+ let RowClass = firstLetterUpper(name);
12
+ var fullName = `${table.workbookName}-${name}`;
13
+ var mmpMark = "[System.Runtime.InteropServices.StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]";
14
+ // TODO: 支持FK类型
15
+ let temp = `
16
+ using System;
17
+ using System.Collections.Generic;
18
+ using System.Runtime.InteropServices;
19
+ ${CSParseTool_1.useMMPNamespace}
20
+
21
+ namespace ${exportNamespace}
22
+ {
23
+ ${mmpMark}
24
+ public partial class ${RowClass} : IMMPSerializable
25
+ {
26
+ private static int _typeSize = -1;
27
+
28
+ public static int GetTypeSize()
29
+ {
30
+ if (_typeSize >= 0)
31
+ {
32
+ return _typeSize;
33
+ }
34
+
35
+ _typeSize = Marshal.SizeOf<${RowClass}>();
36
+ return _typeSize;
37
+ }
38
+
39
+ public void Serialize(ref SerializeParas paras)
40
+ {
41
+ ${(0, export_table_lib_1.foreach)(fields, f => `
42
+ ${(0, export_table_lib_1.iff)(f.type == "string[]", () => `
43
+ var ${(0, CSParseTool_1.convVarName)(f.name)} = this.${(0, CSParseTool_1.convMemberName)(f.name)}; this.${(0, CSParseTool_1.convMemberName)(f.name)} = null;
44
+ `)}
45
+ `)}
46
+ Marshal.StructureToPtr(this, paras.Ptr, false);
47
+ ${(0, export_table_lib_1.foreach)(fields, f => `
48
+ ${(0, export_table_lib_1.iff)(f.type == "string[]", () => `
49
+ this.${(0, CSParseTool_1.convMemberName)(f.name)} = ${(0, CSParseTool_1.convVarName)(f.name)};
50
+ `)}
51
+ `)}
52
+ paras.Offset += GetTypeSize();
53
+ ${(0, export_table_lib_1.foreach)(fields, f => `
54
+ ${(0, export_table_lib_1.iff)(f.type == "string", () => `
55
+ // ${f.name}
56
+ BitUtils.FromString(ref paras, this.${(0, CSParseTool_1.convMemberName)(f.name)});
57
+ ${(0, export_table_lib_1.iff)(f.rawType.startsWith("@") && f.rawType.endsWith("[]"), () => `
58
+ BitUtils.FromSArray(ref paras, this.${(0, CSParseTool_1.convMemberName)(f.name)}Obj);
59
+ `)}
60
+ `).elseif(f.type == "string[]", () => `
61
+ // ${f.name}
62
+ BitUtils.FromArray(ref paras, this.${(0, CSParseTool_1.convMemberName)(f.name)}, BitUtils.FromString);
63
+ `).elseif((0, CSParseTool_1.isTypeArray)(f), () => `
64
+ // ${f.name}
65
+ BitUtils.FromRawArray(ref paras, this.${(0, CSParseTool_1.convMemberName)(f.name)});
66
+ `).else(() => `
67
+ `)}
68
+ `, "\n")}
69
+ }
70
+
71
+ public void Deserialize(ref DeserializeParas paras)
72
+ {
73
+ Marshal.PtrToStructure(paras.Ptr, this);
74
+ paras.Offset += GetTypeSize();
75
+ ${(0, export_table_lib_1.foreach)(fields, f => `
76
+ ${(0, export_table_lib_1.iff)(f.type == "string", () => `
77
+ // ${f.name}
78
+ this.${(0, CSParseTool_1.convMemberName)(f.name)} = BitUtils.ToString(ref paras);
79
+ ${(0, export_table_lib_1.iff)(f.rawType.startsWith("@") && f.rawType.endsWith("[]"), () => `
80
+ BitUtils.ToSArray(ref paras, ref this.${(0, CSParseTool_1.convMemberName)(f.name)}Obj);
81
+ `)}
82
+ `).elseif(f.type == "string[]", () => `
83
+ // ${f.name}
84
+ this.${(0, CSParseTool_1.convMemberName)(f.name)} = BitUtils.ToArray(ref paras, BitUtils.ToString);
85
+ `).elseif((0, CSParseTool_1.isTypeArray)(f), () => `
86
+ // ${f.name}
87
+ this.${(0, CSParseTool_1.convMemberName)(f.name)} = BitUtils.ToRawArray<${(0, CSParseTool_1.getFieldElementType)(f)}>(ref paras);
88
+ `).else(() => `
89
+ `)}
90
+ `)}
91
+ }
92
+
93
+ public static IEnumerable<IMMPSerializable> AsSerializableEnumerable()
94
+ {
95
+ return Configs;
96
+ }
97
+ }
98
+ }
99
+ `;
100
+ return temp;
101
+ }
102
+ class ExportUnityMMPPlugin extends export_table_lib_1.PluginBase {
103
+ name = "mmp";
104
+ tags = ["mmp"];
105
+ handleSheet(paras) {
106
+ var fullName = `${paras.table.workbookName}-${paras.name}`;
107
+ {
108
+ let content1 = exportMMP(paras);
109
+ if (content1 != null) {
110
+ let savePath = new export_table_lib_1.OutFilePath(paras.outPath, fullName, "MMP.cs").fullPath;
111
+ (0, CSParseTool_1.outputFileSync)(savePath, content1, "utf-8");
112
+ }
113
+ }
114
+ }
115
+ }
116
+ exports.ExportUnityMMPPlugin = ExportUnityMMPPlugin;
@@ -0,0 +1,7 @@
1
+ import { ExportPlugin as ExportCSPlugin } from "./ExportCSPlugin";
2
+ import { ExportLiteDBCSPlugin } from "./ExportLiteDBCSPlugin";
3
+ import { ExportLiteDBUJsonPlugin } from "./ExportLiteDBUnityCSJsonPlugin";
4
+ import { ExportUJsonPlugin } from "./ExportUnityCSJsonPlugin";
5
+ import { ExportUnityMMPPlugin } from "./ExportUnityMMPPlugin";
6
+ export declare const ExportPlugins: (ExportCSPlugin | ExportLiteDBCSPlugin | ExportUJsonPlugin | ExportLiteDBUJsonPlugin | ExportUnityMMPPlugin)[];
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAA;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAE7D,eAAO,MAAM,aAAa,gHAMzB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExportPlugins = void 0;
4
+ const ExportCSPlugin_1 = require("./ExportCSPlugin");
5
+ const ExportLiteDBCSPlugin_1 = require("./ExportLiteDBCSPlugin");
6
+ const ExportLiteDBUnityCSJsonPlugin_1 = require("./ExportLiteDBUnityCSJsonPlugin");
7
+ const ExportUnityCSJsonPlugin_1 = require("./ExportUnityCSJsonPlugin");
8
+ const ExportUnityMMPPlugin_1 = require("./ExportUnityMMPPlugin");
9
+ exports.ExportPlugins = [
10
+ new ExportCSPlugin_1.ExportPlugin(),
11
+ new ExportUnityCSJsonPlugin_1.ExportUJsonPlugin(),
12
+ new ExportLiteDBCSPlugin_1.ExportLiteDBCSPlugin(),
13
+ new ExportLiteDBUnityCSJsonPlugin_1.ExportLiteDBUJsonPlugin(),
14
+ new ExportUnityMMPPlugin_1.ExportUnityMMPPlugin(),
15
+ ];
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "export-table-plugin-csharp",
3
+ "version": "1.1.189",
4
+ "description": "",
5
+ "main": "./dist/index.js",
6
+ "scripts": {},
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/windyuuy/export-table-plugin-csharp.git"
10
+ },
11
+ "author": "windyuuy",
12
+ "license": "ISC",
13
+ "dependencies": {
14
+ "@types/commander": "2.12.2",
15
+ "@types/node": "^17.0.18",
16
+ "export-table-lib": "^1.0.73",
17
+ "fs": "^0.0.1-security",
18
+ "fs-extra": "^10.0.0",
19
+ "fse": "^4.0.1"
20
+ },
21
+ "devDependencies": {
22
+ "@types/fs-extra": "^9.0.13"
23
+ }
24
+ }
@@ -0,0 +1,171 @@
1
+ using System;
2
+ using System.Runtime.InteropServices;
3
+ using System.Text;
4
+
5
+ namespace ExportedConfigs.MMPConvTool.Core
6
+ {
7
+ public delegate T DeserializeMethod<T>(ref DeserializeParas paras);
8
+
9
+ public delegate void SerializeMethod<T>(ref SerializeParas paras, T value);
10
+
11
+ public delegate void FromValue<T>(IntPtr ptr, T value);
12
+
13
+ public delegate T ToValue<T>(IntPtr ptr);
14
+
15
+ public struct DeserializeParas
16
+ {
17
+ public byte[] Bytes;
18
+ private IntPtr _ptr;
19
+ public IntPtr Ptr => _ptr + Offset;
20
+ public int Offset;
21
+
22
+ public DeserializeParas(byte[] bytes)
23
+ {
24
+ IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(bytes, 0);
25
+
26
+ Bytes = bytes;
27
+ _ptr = ptr;
28
+ Offset = 0;
29
+ }
30
+ }
31
+
32
+ public struct SerializeParas
33
+ {
34
+ public byte[] Bytes;
35
+ private IntPtr _ptr;
36
+ public IntPtr Ptr => _ptr + Offset;
37
+ public int Offset;
38
+
39
+ public SerializeParas(byte[] bytes)
40
+ {
41
+ IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(bytes, 0);
42
+
43
+ Bytes = bytes;
44
+ _ptr = ptr;
45
+ Offset = 0;
46
+ }
47
+ }
48
+
49
+ public static class BitUtils
50
+ {
51
+ public static T[] ToArray<T>(ref DeserializeParas paras, DeserializeMethod<T> func)
52
+ {
53
+ var count = BitUtils.ToValue(ref paras, Marshal.ReadInt32);
54
+
55
+ var arr = new T[count];
56
+ for (var i = 0; i < count; i++)
57
+ {
58
+ arr[i] = func(ref paras);
59
+ }
60
+
61
+ return arr;
62
+ }
63
+
64
+ public static void ToArrayInternal<T>(ref DeserializeParas paras, ref T[] arr) where T : IMMPSerializable, new()
65
+ {
66
+ var count = BitUtils.ToValue(ref paras, Marshal.ReadInt32);
67
+
68
+ arr = new T[count];
69
+ for (var i = 0; i < count; i++)
70
+ {
71
+ var obj = new T();
72
+ obj.Deserialize(ref paras);
73
+ arr[i] = obj;
74
+ }
75
+ }
76
+
77
+ public static void FromArrayInternal<T>(ref SerializeParas paras, T[] arr) where T : IMMPSerializable
78
+ {
79
+ BitUtils.FromValue(ref paras, Marshal.WriteInt32, arr.Length);
80
+ foreach (var obj in arr)
81
+ {
82
+ obj.Serialize(ref paras);
83
+ }
84
+ }
85
+
86
+ public static void FromArray<T>(ref SerializeParas paras, T[] arr, SerializeMethod<T> func)
87
+ {
88
+ BitUtils.FromValue(ref paras, Marshal.WriteInt32, arr.Length);
89
+ foreach (var obj in arr)
90
+ {
91
+ func(ref paras, obj);
92
+ }
93
+ }
94
+
95
+ public static T[] ToRawArray<T>(ref DeserializeParas paras) where T : unmanaged
96
+ {
97
+ var len = BitUtils.ToValue(ref paras, Marshal.ReadInt32);
98
+
99
+ var arr = new T[len];
100
+ var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0);
101
+ unsafe
102
+ {
103
+ var size = sizeof(T);
104
+ var byteLen = len * size;
105
+ Marshal.Copy(paras.Bytes, paras.Offset, ptr, byteLen);
106
+ paras.Offset += byteLen;
107
+ }
108
+
109
+ return arr;
110
+ }
111
+
112
+ public static void FromRawArray<T>(ref SerializeParas paras, T[] arr) where T : unmanaged
113
+ {
114
+ var arrLength = arr.Length;
115
+ BitUtils.FromValue(ref paras, Marshal.WriteInt32, arrLength);
116
+ var ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arr, 0);
117
+ unsafe
118
+ {
119
+ var size = sizeof(T);
120
+ var byteLength = arrLength * size;
121
+ Marshal.Copy(ptr, paras.Bytes, paras.Offset, byteLength);
122
+ paras.Offset += byteLength;
123
+ }
124
+ }
125
+
126
+ public static string ToString(ref DeserializeParas paras)
127
+ {
128
+ var len = BitUtils.ToValue(ref paras, Marshal.ReadInt32);
129
+ unsafe
130
+ {
131
+ var str = Marshal.PtrToStringUTF8(paras.Ptr, len);
132
+ paras.Offset += len;
133
+ return str;
134
+ }
135
+ }
136
+
137
+ public static void FromString(ref SerializeParas paras, string str)
138
+ {
139
+ var writeLen = Encoding.UTF8.GetBytes(str, 0, str.Length, paras.Bytes, paras.Offset + 4);
140
+ BitUtils.FromValue(ref paras, Marshal.WriteInt32, writeLen);
141
+
142
+ paras.Offset += writeLen;
143
+ }
144
+
145
+ public static T ToValue<T>(ref DeserializeParas paras, ToValue<T> conv) where T : unmanaged
146
+ {
147
+ var value = conv(paras.Ptr);
148
+ unsafe
149
+ {
150
+ paras.Offset += sizeof(T);
151
+ }
152
+
153
+ return value;
154
+ }
155
+
156
+ public static void FromValue<T>(ref SerializeParas paras, FromValue<T> conv, T value) where T : unmanaged
157
+ {
158
+ conv(paras.Ptr, value);
159
+ unsafe
160
+ {
161
+ paras.Offset += sizeof(T);
162
+ }
163
+ }
164
+ }
165
+
166
+ public interface IMMPSerializable
167
+ {
168
+ public void Serialize(ref SerializeParas paras);
169
+ public void Deserialize(ref DeserializeParas paras);
170
+ }
171
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: cfa73055f4e58f547a3c000a3a939613
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,40 @@
1
+ using System;
2
+ using System.Runtime.InteropServices;
3
+ using ExportedConfigs.MMPConvTool.Core;
4
+
5
+ #nullable disable
6
+ namespace FaBao.ExportedConfigs
7
+ {
8
+ [Serializable]
9
+ [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi)]
10
+ public struct WritableValueTuple<T1, T2> : IMMPSerializable
11
+ {
12
+ public T1 Item1;
13
+ public T2 Item2;
14
+
15
+ private static int _typeSize = -1;
16
+
17
+ public static int GetTypeSize()
18
+ {
19
+ if (_typeSize >= 0)
20
+ {
21
+ return _typeSize;
22
+ }
23
+
24
+ _typeSize = Marshal.SizeOf<WritableValueTuple<T1, T2>>();
25
+ return _typeSize;
26
+ }
27
+
28
+ public void Deserialize(ref DeserializeParas paras)
29
+ {
30
+ this = Marshal.PtrToStructure<WritableValueTuple<T1, T2>>(paras.Ptr);
31
+ paras.Offset += GetTypeSize();
32
+ }
33
+
34
+ public void Serialize(ref SerializeParas paras)
35
+ {
36
+ Marshal.StructureToPtr(this, paras.Ptr, false);
37
+ paras.Offset += GetTypeSize();
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 63fc6e80a69c70a459d0af723a616237
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant: