mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
移除HubirdBuildProcessors
移除HubirdBuildProcessors
This commit is contained in:
@@ -10,7 +10,6 @@ namespace HybridCLR.Editor
|
||||
/// </summary>
|
||||
public static List<string> HotUpdateAssemblies { get; } = new List<string>
|
||||
{
|
||||
"TEngine.Runtime.dll",
|
||||
"HotFix.dll",
|
||||
};
|
||||
|
||||
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d7e4bb1668e0b341b9613b967e27f88
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,84 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEditor.Il2Cpp;
|
||||
using UnityEditor.UnityLinker;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
internal class BPCopyStrippedAOTAssemblies : IPostprocessBuildWithReport
|
||||
#if !UNITY_2021_1_OR_NEWER
|
||||
, IIl2CppProcessor
|
||||
#endif
|
||||
{
|
||||
|
||||
public int callbackOrder => 0;
|
||||
|
||||
#if UNITY_2021_1_OR_NEWER
|
||||
public static string GetStripAssembliesDir2021(BuildTarget target)
|
||||
{
|
||||
string projectDir = BuildConfig.ProjectDir;
|
||||
#if UNITY_STANDALONE_WIN
|
||||
return $"{projectDir}/Library/Bee/artifacts/WinPlayerBuildProgram/ManagedStripped";
|
||||
#elif UNITY_ANDROID
|
||||
return $"{projectDir}/Library/Bee/artifacts/Android/ManagedStripped";
|
||||
#elif UNITY_IOS
|
||||
return $"{projectDir}/Temp/StagingArea/Data/Managed/tempStrip";
|
||||
#elif UNITY_WEBGL
|
||||
return $"{projectDir}/Library/Bee/artifacts/WebGL/ManagedStripped";
|
||||
#elif UNITY_EDITOR_OSX
|
||||
return $"{projectDir}/Library/Bee/artifacts/MacStandalonePlayerBuildProgram/ManagedStripped";
|
||||
#else
|
||||
throw new NotSupportedException("GetOriginBuildStripAssembliesDir");
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
private string GetStripAssembliesDir2020(BuildTarget target)
|
||||
{
|
||||
string subPath = target == BuildTarget.Android ?
|
||||
"assets/bin/Data/Managed" :
|
||||
"Data/Managed/";
|
||||
return $"{BuildConfig.ProjectDir}/Temp/StagingArea/{subPath}";
|
||||
}
|
||||
|
||||
public void OnBeforeConvertRun(BuildReport report, Il2CppBuildPipelineData data)
|
||||
{
|
||||
// 此回调只在 2020中调用
|
||||
CopyStripDlls(GetStripAssembliesDir2020(data.target), data.target);
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void CopyStripDlls(string srcStripDllPath, BuildTarget target)
|
||||
{
|
||||
Debug.Log($"[BPCopyStrippedAOTAssemblies] CopyScripDlls. src:{srcStripDllPath} target:{target}");
|
||||
|
||||
var dstPath = BuildConfig.GetAssembliesPostIl2CppStripDir(target);
|
||||
|
||||
Directory.CreateDirectory(dstPath);
|
||||
|
||||
//string srcStripDllPath = BuildConfig.GetOriginBuildStripAssembliesDir(target);
|
||||
|
||||
foreach (var fileFullPath in Directory.GetFiles(srcStripDllPath, "*.dll"))
|
||||
{
|
||||
var file = Path.GetFileName(fileFullPath);
|
||||
Debug.Log($"[BPCopyStrippedAOTAssemblies] copy strip dll {fileFullPath} ==> {dstPath}/{file}");
|
||||
File.Copy($"{fileFullPath}", $"{dstPath}/{file}", true);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPostprocessBuild(BuildReport report)
|
||||
{
|
||||
#if UNITY_2021_1_OR_NEWER && !UNITY_IOS
|
||||
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
|
||||
CopyStripDlls(GetStripAssembliesDir2021(target), target);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7884710ec2f8e545b3fe9aa05def5a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,45 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
/// <summary>
|
||||
/// 将热更新dll从Build过程中过滤,防止打包到主工程中
|
||||
/// </summary>
|
||||
internal class BPFilterHotFixAssemblies : IFilterBuildAssemblies
|
||||
{
|
||||
public int callbackOrder => 0;
|
||||
|
||||
public string[] OnFilterAssemblies(BuildOptions buildOptions, string[] assemblies)
|
||||
{
|
||||
List<string> allHotUpdateDllNames = BuildConfig.HotUpdateAssemblies;
|
||||
|
||||
// 检查是否重复填写
|
||||
var hotUpdateDllSet = new HashSet<string>();
|
||||
foreach(var hotUpdateDll in allHotUpdateDllNames)
|
||||
{
|
||||
if (!hotUpdateDllSet.Add(hotUpdateDll))
|
||||
{
|
||||
throw new Exception($"热更新 assembly:{hotUpdateDll} 在列表中重复,请除去重复条目");
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否填写了正确的dll名称
|
||||
foreach (var hotUpdateDll in BuildConfig.HotUpdateAssemblies)
|
||||
{
|
||||
if (assemblies.All(ass => !ass.EndsWith(hotUpdateDll)))
|
||||
{
|
||||
throw new Exception($"热更新 assembly:{hotUpdateDll} 不存在,请检查拼写错误");
|
||||
}
|
||||
Debug.Log($"[BPFilterHotFixAssemblies] 过滤热更新assembly:{hotUpdateDll}");
|
||||
}
|
||||
|
||||
// 将热更dll从打包列表中移除
|
||||
return assemblies.Where(ass => BuildConfig.HotUpdateAssemblies.All(dll => !ass.EndsWith(dll, StringComparison.OrdinalIgnoreCase))).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9dec2922e3df5464aa047b636eb19e0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,148 +0,0 @@
|
||||
using HybridCLR.Editor.GlobalManagers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Android;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEditor.Il2Cpp;
|
||||
using UnityEditor.UnityLinker;
|
||||
using UnityEngine;
|
||||
|
||||
namespace HybridCLR.Editor.BuildProcessors
|
||||
{
|
||||
public class BPPatchScriptAssembliesJson : IPreprocessBuildWithReport,
|
||||
#if UNITY_ANDROID
|
||||
IPostGenerateGradleAndroidProject,
|
||||
#endif
|
||||
IPostprocessBuildWithReport
|
||||
{
|
||||
public int callbackOrder => 0;
|
||||
|
||||
|
||||
[Serializable]
|
||||
private class ScriptingAssemblies
|
||||
{
|
||||
public List<string> names;
|
||||
public List<int> types;
|
||||
}
|
||||
|
||||
public void OnPostGenerateGradleAndroidProject(string path)
|
||||
{
|
||||
// 如果直接打包apk,没有机会在PostprocessBuild中修改ScriptingAssemblies.json。
|
||||
// 因此需要在这个时机处理
|
||||
PathScriptingAssembilesFile(path);
|
||||
}
|
||||
|
||||
public void OnPostprocessBuild(BuildReport report)
|
||||
{
|
||||
// 如果target为Android,由于已经在OnPostGenerateGradelAndroidProject中处理过,
|
||||
// 这里不再重复处理
|
||||
#if !UNITY_ANDROID
|
||||
|
||||
PathScriptingAssembilesFile(report.summary.outputPath);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void PathScriptingAssembilesFile(string path)
|
||||
{
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
AddHotFixAssembliesToScriptingAssembliesJson(path);
|
||||
#else
|
||||
AddBackHotFixAssembliesToBinFile(path);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void AddHotFixAssembliesToScriptingAssembliesJson(string path)
|
||||
{
|
||||
Debug.Log($"AddBackHotFixAssembliesToJson. path:{path}");
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
path = Directory.GetParent(path).ToString();
|
||||
}
|
||||
/*
|
||||
* ScriptingAssemblies.json 文件中记录了所有的dll名称,此列表在游戏启动时自动加载,
|
||||
* 不在此列表中的dll在资源反序列化时无法被找到其类型
|
||||
* 因此 OnFilterAssemblies 中移除的条目需要再加回来
|
||||
*/
|
||||
string[] jsonFiles = Directory.GetFiles(path, BuildConfig.ScriptingAssembliesJsonFile, SearchOption.AllDirectories);
|
||||
|
||||
if (jsonFiles.Length == 0)
|
||||
{
|
||||
Debug.LogError($"can not find file {BuildConfig.ScriptingAssembliesJsonFile}");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string file in jsonFiles)
|
||||
{
|
||||
string content = File.ReadAllText(file);
|
||||
ScriptingAssemblies scriptingAssemblies = JsonUtility.FromJson<ScriptingAssemblies>(content);
|
||||
foreach (string name in BuildConfig.HotUpdateAssemblies)
|
||||
{
|
||||
if (!scriptingAssemblies.names.Contains(name))
|
||||
{
|
||||
scriptingAssemblies.names.Add(name);
|
||||
scriptingAssemblies.types.Add(16); // user dll type
|
||||
Debug.Log($"[PatchScriptAssembliesJson] add hotfix assembly:{name} to {file}");
|
||||
}
|
||||
}
|
||||
content = JsonUtility.ToJson(scriptingAssemblies);
|
||||
|
||||
File.WriteAllText(file, content);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddBackHotFixAssembliesToBinFile(string path)
|
||||
{
|
||||
/*
|
||||
* Unity2019 中 dll 加载列表存储在 globalgamemanagers 文件中,此列表在游戏启动时自动加载,
|
||||
* 不在此列表中的dll在资源反序列化时无法被找到其类型
|
||||
* 因此 OnFilterAssemblies 中移除的条目需要再加回来
|
||||
*/
|
||||
#if UNITY_ANDROID
|
||||
string[] binFiles = new string[] { "Temp/gradleOut/unityLibrary/src/main/assets/bin/Data/globalgamemanagers" }; // report.files 不包含 Temp/gradleOut 等目录
|
||||
#else
|
||||
// 直接出包和输出vs工程时路径不同,report.summary.outputPath 记录的是前者路径
|
||||
string[] binFiles = Directory.GetFiles(Path.GetDirectoryName(path), "globalgamemanagers", SearchOption.AllDirectories);
|
||||
#endif
|
||||
|
||||
if (binFiles.Length == 0)
|
||||
{
|
||||
Debug.LogError("can not find file ScriptingAssemblies.json");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string binPath in binFiles)
|
||||
{
|
||||
var binFile = new UnityBinFile();
|
||||
binFile.LoadFromFile(binPath);
|
||||
|
||||
ScriptsData scriptsData = binFile.scriptsData;
|
||||
foreach (string name in BuildConfig.HotUpdateAssemblies)
|
||||
{
|
||||
if (!scriptsData.dllNames.Contains(name))
|
||||
{
|
||||
scriptsData.dllNames.Add(name);
|
||||
scriptsData.dllTypes.Add(16); // user dll type
|
||||
}
|
||||
}
|
||||
binFile.scriptsData = scriptsData;
|
||||
|
||||
binFile.RebuildAndFlushToFile(binPath);
|
||||
}
|
||||
}
|
||||
|
||||
#region useless
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bb6e2908d8948648979c9ff6bb7937d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e52fb09e14efee949ae80ae8aa9f9d44
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,107 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace HybridCLR.Editor.GlobalManagers
|
||||
{
|
||||
/// <summary>
|
||||
/// Unity 生成的二进制文件(本代码不支持5.x之前的版本)
|
||||
/// </summary>
|
||||
public unsafe class UnityBinFile
|
||||
{
|
||||
/*
|
||||
* MonoManager: idx: 6;
|
||||
* type: metaData.types[objects[6].typeID]
|
||||
*/
|
||||
public const int kMonoManagerIdx = 6;
|
||||
|
||||
public string path { get; private set; }
|
||||
|
||||
public FileHeader header;
|
||||
public MetaData metaData;
|
||||
public ScriptsData scriptsData;
|
||||
|
||||
public void LoadFromFile(string path)
|
||||
{
|
||||
this.path = path;
|
||||
|
||||
var fs = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
var br = new BinaryReader(fs, Encoding.UTF8, true);
|
||||
|
||||
header.LoadFromStream(br);
|
||||
// 按理说 metaData 应该新开一个buffer来避免加载时的对齐逻辑问题,但由于 sizeof(Header) = 20,已经对齐到4了,所以可以连续读
|
||||
metaData.LoadFromStream(br, header.dataOffset);
|
||||
scriptsData = metaData.GetScriptData(br);
|
||||
|
||||
br.Close();
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
public void RebuildAndFlushToFile(string newPath)
|
||||
{
|
||||
var fsR = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
var brR = new BinaryReader(fsR, Encoding.UTF8, true);
|
||||
|
||||
var ms = new MemoryStream((int)(header.fileSize * 1.5f));
|
||||
var bw = new BinaryWriter(ms, Encoding.UTF8, true);
|
||||
|
||||
/*
|
||||
* 开始写入data
|
||||
* dll名称列表存储于 data 区段,修改其数据并不会影响 MetaData 大小,因此 dataOffset 不会改变
|
||||
*/
|
||||
ms.Position = header.dataOffset;
|
||||
|
||||
Dictionary<long, ObjectInfo> newObjInfos = new Dictionary<long, ObjectInfo>();
|
||||
foreach (var kv in metaData.objects)
|
||||
{
|
||||
long objID = kv.Key;
|
||||
ObjectInfo objInfo = kv.Value;
|
||||
|
||||
byte[] buff = new byte[objInfo.size];
|
||||
fsR.Position = objInfo.realPos;
|
||||
brR.Read(buff, 0, buff.Length);
|
||||
|
||||
|
||||
{// unity 的数据偏移貌似会对齐到 8
|
||||
int newPos = (((int)ms.Position + 7) >> 3) << 3;
|
||||
int gapSize = newPos - (int)ms.Position;
|
||||
|
||||
for (int i = 0; i < gapSize; i++)
|
||||
bw.Write((byte)0);
|
||||
|
||||
objInfo.dataPos = (uint)ms.Position - header.dataOffset; // 重定位数据偏移
|
||||
}
|
||||
|
||||
if (objID != kMonoManagerIdx)
|
||||
bw.Write(buff, 0, buff.Length);
|
||||
else
|
||||
objInfo.size = (uint)scriptsData.SaveToStream(bw);
|
||||
|
||||
newObjInfos.Add(objID, objInfo);
|
||||
}
|
||||
|
||||
metaData.objects = newObjInfos;
|
||||
header.fileSize = (uint)ms.Position;
|
||||
|
||||
ms.Position = 0;
|
||||
header.SaveToStream(bw);
|
||||
metaData.SaveToStream(bw);
|
||||
|
||||
brR.Close();
|
||||
fsR.Close();
|
||||
|
||||
// 写入新文件
|
||||
ms.Position = 0;
|
||||
File.WriteAllBytes(newPath, ms.ToArray());
|
||||
|
||||
bw.Close();
|
||||
ms.Close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae7ec6e3674077d46898fe821d24bf85
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,397 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using static HybridCLR.Editor.GlobalManagers.UnityBinUtils;
|
||||
|
||||
namespace HybridCLR.Editor.GlobalManagers
|
||||
{
|
||||
public struct FileHeader
|
||||
{
|
||||
public const int kSize = 20;
|
||||
|
||||
public uint dataSize => fileSize - metadataSize;
|
||||
|
||||
public uint metadataSize;
|
||||
public uint fileSize;
|
||||
public uint version;
|
||||
public uint dataOffset;
|
||||
public byte endianess;
|
||||
|
||||
public void LoadFromStream(BinaryReader br)
|
||||
{
|
||||
long startPos = br.BaseStream.Position;
|
||||
metadataSize = br.ReadUInt32();
|
||||
fileSize = br.ReadUInt32();
|
||||
version = br.ReadUInt32();
|
||||
dataOffset = br.ReadUInt32();
|
||||
endianess = br.ReadByte();
|
||||
br.BaseStream.Position = startPos + kSize;
|
||||
|
||||
SwapEndianess();
|
||||
}
|
||||
|
||||
public long SaveToStream(BinaryWriter bw)
|
||||
{
|
||||
SwapEndianess();
|
||||
|
||||
long startPos = bw.BaseStream.Position;
|
||||
bw.Write(metadataSize);
|
||||
bw.Write(fileSize);
|
||||
bw.Write(version);
|
||||
bw.Write(dataOffset);
|
||||
bw.Write(endianess);
|
||||
bw.BaseStream.Position = startPos + kSize;
|
||||
return kSize;
|
||||
}
|
||||
|
||||
void SwapEndianess()
|
||||
{
|
||||
SwapUInt(ref metadataSize);
|
||||
SwapUInt(ref fileSize);
|
||||
SwapUInt(ref version);
|
||||
SwapUInt(ref dataOffset);
|
||||
}
|
||||
}
|
||||
|
||||
public struct MetaData
|
||||
{
|
||||
public long dataStartPos;
|
||||
|
||||
public string version;
|
||||
public uint platform;
|
||||
public bool enableTypeTree;
|
||||
public int typeCount;
|
||||
public ObjectType[] types;
|
||||
public int objectCount;
|
||||
public Dictionary<long, ObjectInfo> objects;
|
||||
public int scriptTypeCount;
|
||||
public ScriptType[] scriptTypes;
|
||||
public int externalsCount;
|
||||
public ExternalInfo[] externals;
|
||||
|
||||
#if UNITY_2019_2_OR_NEWER
|
||||
public int refTypeCount;
|
||||
public ObjectType[] refTypes;
|
||||
#endif
|
||||
public string dummyStr;
|
||||
|
||||
public void LoadFromStream(BinaryReader br, uint dataOffset)
|
||||
{
|
||||
long startPos = br.BaseStream.Position;
|
||||
dataStartPos = startPos;
|
||||
|
||||
version = br.ReadRawString();
|
||||
platform = br.ReadUInt32();
|
||||
enableTypeTree = br.ReadBoolean();
|
||||
typeCount = br.ReadInt32();
|
||||
types = new ObjectType[typeCount];
|
||||
|
||||
for (int i = 0; i < typeCount; i++)
|
||||
{
|
||||
types[i].LoadFromStream(br);
|
||||
}
|
||||
|
||||
objectCount = br.ReadInt32();
|
||||
objects = new Dictionary<long, ObjectInfo>();
|
||||
for(int i = 0; i < objectCount; i++)
|
||||
{
|
||||
long id = br.AlignedReadInt64();
|
||||
ObjectInfo objInfo = new ObjectInfo();
|
||||
objInfo.LoadFromStream(br);
|
||||
objInfo.realPos = objInfo.dataPos + dataOffset;
|
||||
|
||||
objects.Add(id, objInfo);
|
||||
}
|
||||
|
||||
scriptTypeCount = br.ReadInt32();
|
||||
scriptTypes = new ScriptType[scriptTypeCount];
|
||||
for(int i = 0; i < scriptTypeCount; i++)
|
||||
{
|
||||
scriptTypes[i].LoadFromStream(br);
|
||||
}
|
||||
|
||||
externalsCount = br.ReadInt32();
|
||||
externals = new ExternalInfo[externalsCount];
|
||||
for(int i = 0; i < externalsCount; i++)
|
||||
{
|
||||
externals[i].LoadFromStream(br);
|
||||
}
|
||||
|
||||
#if UNITY_2019_2_OR_NEWER
|
||||
refTypeCount = br.ReadInt32();
|
||||
refTypes = new ObjectType[refTypeCount];
|
||||
for(int i = 0; i < refTypeCount; i++)
|
||||
{
|
||||
refTypes[i].LoadFromStream(br);
|
||||
}
|
||||
#endif
|
||||
dummyStr = br.ReadRawString();
|
||||
}
|
||||
|
||||
public long SaveToStream(BinaryWriter bw)
|
||||
{
|
||||
long startPos = bw.BaseStream.Position;
|
||||
bw.WriteRawString(version);
|
||||
bw.Write(platform);
|
||||
bw.Write(enableTypeTree);
|
||||
|
||||
bw.Write(typeCount);
|
||||
foreach(var type in types)
|
||||
type.SaveToStream(bw);
|
||||
|
||||
bw.Write(objectCount);
|
||||
foreach (var kv in objects)
|
||||
{
|
||||
bw.AlignedWriteInt64(kv.Key);
|
||||
kv.Value.SaveToStream(bw);
|
||||
}
|
||||
|
||||
bw.Write(scriptTypeCount);
|
||||
foreach(var st in scriptTypes)
|
||||
st.SaveToStream(bw);
|
||||
|
||||
bw.Write(externalsCount);
|
||||
foreach(var external in externals)
|
||||
external.SaveToStream(bw);
|
||||
|
||||
#if UNITY_2019_2_OR_NEWER
|
||||
bw.Write(refTypeCount);
|
||||
foreach(var refT in refTypes)
|
||||
refT.SaveToStream(bw);
|
||||
#endif
|
||||
|
||||
bw.WriteRawString(dummyStr);
|
||||
|
||||
return bw.BaseStream.Position - startPos;
|
||||
}
|
||||
|
||||
public ScriptsData GetScriptData(BinaryReader br)
|
||||
{
|
||||
ObjectInfo objInfo = objects[UnityBinFile.kMonoManagerIdx];
|
||||
br.BaseStream.Seek(objInfo.realPos, SeekOrigin.Begin);
|
||||
|
||||
ScriptsData data = new ScriptsData();
|
||||
data.LoadFromStream(br);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ObjectType
|
||||
{
|
||||
public int typeID;
|
||||
public bool isStriped;
|
||||
public short scriptTypeIndex;
|
||||
|
||||
public bool needReadScriptHash; // dont save
|
||||
|
||||
public Hash scriptSigHash;
|
||||
public Hash typeHash;
|
||||
|
||||
public void LoadFromStream(BinaryReader br)
|
||||
{
|
||||
typeID = br.ReadInt32();
|
||||
isStriped = br.ReadBoolean();
|
||||
scriptTypeIndex = br.ReadInt16();
|
||||
|
||||
needReadScriptHash = typeID == -1 || typeID == 0x72;
|
||||
if(needReadScriptHash)
|
||||
scriptSigHash.LoadFromStream(br);
|
||||
|
||||
typeHash.LoadFromStream(br);
|
||||
|
||||
// GlobalManagers does not has TypeTrees
|
||||
}
|
||||
|
||||
public long SaveToStream(BinaryWriter bw)
|
||||
{
|
||||
long startPos = bw.BaseStream.Position;
|
||||
bw.Write(typeID);
|
||||
bw.Write(isStriped);
|
||||
bw.Write(scriptTypeIndex);
|
||||
|
||||
if(needReadScriptHash)
|
||||
scriptSigHash.SaveToStream(bw);
|
||||
|
||||
typeHash.SaveToStream(bw);
|
||||
return bw.BaseStream.Position - startPos;
|
||||
}
|
||||
|
||||
public int Size()
|
||||
{
|
||||
int ret = 0;
|
||||
ret += sizeof(int);
|
||||
ret += sizeof(bool);
|
||||
ret += sizeof(short);
|
||||
|
||||
if (needReadScriptHash)
|
||||
ret += Hash.kSize;
|
||||
|
||||
ret += Hash.kSize;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ObjectInfo
|
||||
{
|
||||
public const int kSize = 12;
|
||||
|
||||
public uint dataPos;
|
||||
public uint size;
|
||||
public uint typeID;
|
||||
|
||||
public uint realPos; // dataPos + Header.dataOffset; // dont save
|
||||
|
||||
public void LoadFromStream(BinaryReader br)
|
||||
{
|
||||
dataPos = br.ReadUInt32();
|
||||
size = br.ReadUInt32();
|
||||
typeID = br.ReadUInt32();
|
||||
}
|
||||
|
||||
public long SaveToStream(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(dataPos);
|
||||
bw.Write(size);
|
||||
bw.Write(typeID);
|
||||
return kSize;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ScriptType
|
||||
{
|
||||
public int localFileIndex;
|
||||
public long localIdentifierOfBin;
|
||||
|
||||
public void LoadFromStream(BinaryReader br)
|
||||
{
|
||||
localFileIndex = br.ReadInt32();
|
||||
localIdentifierOfBin = br.AlignedReadInt64();
|
||||
}
|
||||
|
||||
public long SaveToStream(BinaryWriter bw)
|
||||
{
|
||||
long startPos = bw.BaseStream.Position;
|
||||
bw.Write(localFileIndex);
|
||||
bw.AlignedWriteInt64(localIdentifierOfBin);
|
||||
return bw.BaseStream.Position - startPos;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ExternalInfo
|
||||
{
|
||||
public string dummy;
|
||||
public Hash guid;
|
||||
public int type;
|
||||
public string name;
|
||||
|
||||
public void LoadFromStream(BinaryReader br)
|
||||
{
|
||||
dummy = br.ReadRawString();
|
||||
guid.LoadFromStream(br);
|
||||
type = br.ReadInt32();
|
||||
name = br.ReadRawString();
|
||||
}
|
||||
|
||||
public long SaveToStream(BinaryWriter bw)
|
||||
{
|
||||
long startPos = bw.BaseStream.Position;
|
||||
bw.WriteRawString(dummy);
|
||||
guid.SaveToStream(bw);
|
||||
bw.Write(type);
|
||||
bw.WriteRawString(name);
|
||||
return bw.BaseStream.Position - startPos;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ScriptsData
|
||||
{
|
||||
public ScriptID[] scriptIDs;
|
||||
public List<string> dllNames;
|
||||
public List<int> dllTypes; // 16 is user type
|
||||
|
||||
public void LoadFromStream(BinaryReader br)
|
||||
{
|
||||
{
|
||||
int count = br.ReadInt32();
|
||||
scriptIDs = new ScriptID[count];
|
||||
for(int i = 0; i < count; i++)
|
||||
scriptIDs[i].LoadFromStream(br);
|
||||
}
|
||||
{
|
||||
int count = br.ReadInt32();
|
||||
dllNames = new List<string>(count);
|
||||
for (var i = 0; i < count; i++)
|
||||
dllNames.Add(br.ReadSizeString());
|
||||
}
|
||||
{
|
||||
int count = br.ReadInt32();
|
||||
dllTypes = new List<int>(count);
|
||||
for(var i = 0; i < count; i++)
|
||||
dllTypes.Add(br.ReadInt32());
|
||||
}
|
||||
}
|
||||
|
||||
public long SaveToStream(BinaryWriter bw)
|
||||
{
|
||||
long startPos = bw.BaseStream.Position;
|
||||
bw.Write(scriptIDs.Length);
|
||||
for(int i = 0; i < scriptIDs.Length; i++)
|
||||
scriptIDs[i].SaveToStream(bw);
|
||||
|
||||
bw.Write(dllNames.Count);
|
||||
for(int i = 0, imax = dllNames.Count; i < imax; i++)
|
||||
bw.WriteSizeString(dllNames[i]);
|
||||
|
||||
bw.Write(dllTypes.Count);
|
||||
for(int i = 0, imax = dllTypes.Count; i < imax; i++)
|
||||
bw.Write(dllTypes[i]);
|
||||
|
||||
return bw.BaseStream.Position - startPos;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ScriptID
|
||||
{
|
||||
public int fileID;
|
||||
public long pathID; // localIdentifier
|
||||
|
||||
public void LoadFromStream(BinaryReader br)
|
||||
{
|
||||
fileID = br.ReadInt32();
|
||||
pathID = br.ReadInt64();
|
||||
}
|
||||
|
||||
public long SaveToStream(BinaryWriter bw)
|
||||
{
|
||||
bw.Write(fileID);
|
||||
bw.Write(pathID);
|
||||
return 4 + 8;
|
||||
}
|
||||
}
|
||||
|
||||
public struct Hash
|
||||
{
|
||||
public const int kSize = 16;
|
||||
|
||||
public int[] data;
|
||||
|
||||
public void LoadFromStream(BinaryReader br)
|
||||
{
|
||||
data = new int[4];
|
||||
for(int i = 0; i < data.Length; i++)
|
||||
{
|
||||
data[i] = br.ReadInt32();
|
||||
}
|
||||
}
|
||||
|
||||
public long SaveToStream(BinaryWriter bw)
|
||||
{
|
||||
for(int i = 0; i < data.Length; i++)
|
||||
{
|
||||
bw.Write(data[i]);
|
||||
}
|
||||
return kSize;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96788c7fe08d5d54d95a87cfbdcb643a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,78 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
|
||||
namespace HybridCLR.Editor.GlobalManagers
|
||||
{
|
||||
public static class UnityBinUtils
|
||||
{
|
||||
public static void SwapUInt(ref uint val)
|
||||
{
|
||||
val = (val >> 24) | ((val >> 8) & 0x0000ff00) | ((val << 8) & 0x00ff0000) | (val << 24);
|
||||
}
|
||||
|
||||
public static string ReadRawString(this BinaryReader br)
|
||||
{
|
||||
long startPos = br.BaseStream.Position;
|
||||
while (true)
|
||||
{
|
||||
byte val = br.ReadByte();
|
||||
if(val == 0)
|
||||
break;
|
||||
}
|
||||
int size = (int)(br.BaseStream.Position - startPos);
|
||||
br.BaseStream.Position = startPos;
|
||||
|
||||
byte[] buffer = br.ReadBytes(size);
|
||||
string ret = Encoding.UTF8.GetString(buffer, 0, size - 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void WriteRawString(this BinaryWriter bw, string str)
|
||||
{
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(str);
|
||||
bw.Write(buffer, 0, buffer.Length);
|
||||
bw.Write((byte)0);
|
||||
}
|
||||
|
||||
public static string ReadSizeString(this BinaryReader br)
|
||||
{
|
||||
int size = br.ReadInt32();
|
||||
byte[] buff = br.ReadBytes(size);
|
||||
br.BaseStream.AlignOffset4();
|
||||
|
||||
string ret = Encoding.UTF8.GetString(buff);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void WriteSizeString(this BinaryWriter bw, string str)
|
||||
{
|
||||
byte[] buff = Encoding.UTF8.GetBytes(str);
|
||||
bw.Write(buff.Length);
|
||||
bw.Write(buff, 0, buff.Length);
|
||||
bw.BaseStream.AlignOffset4();
|
||||
}
|
||||
|
||||
public static void AlignOffset4(this Stream stream)
|
||||
{
|
||||
int offset = (((int)stream.Position + 3) >> 2) << 2;
|
||||
stream.Position = offset;
|
||||
}
|
||||
|
||||
public static long AlignedReadInt64(this BinaryReader br)
|
||||
{
|
||||
br.BaseStream.AlignOffset4();
|
||||
return br.ReadInt64();
|
||||
}
|
||||
|
||||
public static void AlignedWriteInt64(this BinaryWriter bw, long val)
|
||||
{
|
||||
bw.BaseStream.AlignOffset4();
|
||||
bw.Write(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf7c4cf970660614fb54d838ec6e7eda
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user