├── Data~ ├── ModifiedUnityAssemblies │ ├── 2019.4.40.meta │ └── 2019.4.40 │ │ ├── Unity.IL2CPP-Mac.dll │ │ └── Unity.IL2CPP-Win.dll ├── NetStandard │ ├── netstandard2.0.dll │ └── netstandard2.1.dll ├── Templates │ ├── AssemblyManifest.cpp.tpl │ ├── MethodBridge.cpp.tpl │ └── UnityVersion.h.tpl └── hybridclr_version.json ├── Editor.meta ├── Editor ├── 3rds.meta ├── 3rds │ ├── 7zip.meta │ ├── 7zip │ │ ├── Common.meta │ │ ├── Common │ │ │ ├── CRC.cs │ │ │ ├── CRC.cs.meta │ │ │ ├── CommandLineParser.cs │ │ │ ├── CommandLineParser.cs.meta │ │ │ ├── InBuffer.cs │ │ │ ├── InBuffer.cs.meta │ │ │ ├── OutBuffer.cs │ │ │ └── OutBuffer.cs.meta │ │ ├── Compress.meta │ │ ├── Compress │ │ │ ├── LZ.meta │ │ │ ├── LZ │ │ │ │ ├── IMatchFinder.cs │ │ │ │ ├── IMatchFinder.cs.meta │ │ │ │ ├── LzBinTree.cs │ │ │ │ ├── LzBinTree.cs.meta │ │ │ │ ├── LzInWindow.cs │ │ │ │ ├── LzInWindow.cs.meta │ │ │ │ ├── LzOutWindow.cs │ │ │ │ └── LzOutWindow.cs.meta │ │ │ ├── LZMA.meta │ │ │ ├── LZMA │ │ │ │ ├── LzmaBase.cs │ │ │ │ ├── LzmaBase.cs.meta │ │ │ │ ├── LzmaDecoder.cs │ │ │ │ ├── LzmaDecoder.cs.meta │ │ │ │ ├── LzmaEncoder.cs │ │ │ │ └── LzmaEncoder.cs.meta │ │ │ ├── RangeCoder.meta │ │ │ └── RangeCoder │ │ │ │ ├── RangeCoder.cs │ │ │ │ ├── RangeCoder.cs.meta │ │ │ │ ├── RangeCoderBit.cs │ │ │ │ ├── RangeCoderBit.cs.meta │ │ │ │ ├── RangeCoderBitTree.cs │ │ │ │ └── RangeCoderBitTree.cs.meta │ │ ├── ICoder.cs │ │ └── ICoder.cs.meta │ ├── UnityFS.meta │ ├── UnityFS │ │ ├── ArchiveFlags.cs │ │ ├── ArchiveFlags.cs.meta │ │ ├── BinaryReaderExtensions.cs │ │ ├── BinaryReaderExtensions.cs.meta │ │ ├── BinaryWriterExtensions.cs │ │ ├── BinaryWriterExtensions.cs.meta │ │ ├── BundleFileInfo.cs │ │ ├── BundleFileInfo.cs.meta │ │ ├── BundleFileReader.cs │ │ ├── BundleFileReader.cs.meta │ │ ├── BundleFileWriter.cs │ │ ├── BundleFileWriter.cs.meta │ │ ├── CompressionType.cs │ │ ├── CompressionType.cs.meta │ │ ├── EndianBinaryReader.cs │ │ ├── EndianBinaryReader.cs.meta │ │ ├── EndianBinaryWriter.cs │ │ ├── EndianBinaryWriter.cs.meta │ │ ├── EndianType.cs │ │ ├── EndianType.cs.meta │ │ ├── GlobalgamedatasPatcher.cs │ │ ├── GlobalgamedatasPatcher.cs.meta │ │ ├── Header.cs │ │ ├── Header.cs.meta │ │ ├── Node.cs │ │ ├── Node.cs.meta │ │ ├── ScriptingAssembliesJsonPatcher.cs │ │ ├── ScriptingAssembliesJsonPatcher.cs.meta │ │ ├── SevenZipHelper.cs │ │ ├── SevenZipHelper.cs.meta │ │ ├── StorageBlock.cs │ │ ├── StorageBlock.cs.meta │ │ ├── StorageBlockFlags.cs │ │ ├── StorageBlockFlags.cs.meta │ │ ├── StreamExtensions.cs │ │ ├── StreamExtensions.cs.meta │ │ ├── StreamFile.cs │ │ ├── StreamFile.cs.meta │ │ ├── UnityBinFile.cs │ │ ├── UnityBinFile.cs.meta │ │ ├── UnityBinFileDefines.cs │ │ ├── UnityBinFileDefines.cs.meta │ │ ├── UnityBinUtils.cs │ │ └── UnityBinUtils.cs.meta │ ├── UnityHook.meta │ └── UnityHook │ │ ├── CodePatcher.cs │ │ ├── CodePatcher.cs.meta │ │ ├── HookPool.cs │ │ ├── HookPool.cs.meta │ │ ├── HookUtils.cs │ │ ├── HookUtils.cs.meta │ │ ├── HookUtils_OSX.cs │ │ ├── HookUtils_OSX.cs.meta │ │ ├── HybridCLRHooks.meta │ │ ├── HybridCLRHooks │ │ ├── CopyStrippedAOTAssembliesHook.cs │ │ ├── CopyStrippedAOTAssembliesHook.cs.meta │ │ ├── GetIl2CppFolderHook.cs │ │ ├── GetIl2CppFolderHook.cs.meta │ │ ├── PatchScriptingAssembliesJsonHook.cs │ │ └── PatchScriptingAssembliesJsonHook.cs.meta │ │ ├── LDasm.cs │ │ ├── LDasm.cs.meta │ │ ├── MethodHook.cs │ │ ├── MethodHook.cs.meta │ │ ├── Plugins.meta │ │ └── Plugins │ │ ├── Utils.cpp │ │ ├── Utils.cpp.meta │ │ ├── build_libMonoHookUtils_OSX.dylib.sh │ │ ├── build_libMonoHookUtils_OSX.dylib.sh.meta │ │ ├── silicon.meta │ │ ├── silicon │ │ ├── libMonoHookUtils_OSX.dylib │ │ └── libMonoHookUtils_OSX.dylib.meta │ │ ├── x86_64.meta │ │ └── x86_64 │ │ ├── libMonoHookUtils_OSX.dylib │ │ └── libMonoHookUtils_OSX.dylib.meta ├── ABI.meta ├── ABI │ ├── ABIUtil.cs │ ├── ABIUtil.cs.meta │ ├── MethodDesc.cs │ ├── MethodDesc.cs.meta │ ├── ParamInfo.cs │ ├── ParamInfo.cs.meta │ ├── ParamOrReturnType.cs │ ├── ParamOrReturnType.cs.meta │ ├── PlatformABI.cs │ ├── PlatformABI.cs.meta │ ├── TypeCreator.cs │ ├── TypeCreator.cs.meta │ ├── TypeInfo.cs │ ├── TypeInfo.cs.meta │ ├── ValueTypeSizeAligmentCalculator.cs │ └── ValueTypeSizeAligmentCalculator.cs.meta ├── AOT.meta ├── AOT │ ├── AOTAssemblyMetadataStripper.cs │ ├── AOTAssemblyMetadataStripper.cs.meta │ ├── Analyzer.cs │ ├── Analyzer.cs.meta │ ├── ConstraintContext.cs │ ├── ConstraintContext.cs.meta │ ├── GenericReferenceWriter.cs │ └── GenericReferenceWriter.cs.meta ├── BuildProcessors.meta ├── BuildProcessors │ ├── AddLil2cppSourceCodeToXcodeproj2019.cs │ ├── AddLil2cppSourceCodeToXcodeproj2019.cs.meta │ ├── AddLil2cppSourceCodeToXcodeproj2020Or2021.cs │ ├── AddLil2cppSourceCodeToXcodeproj2020Or2021.cs.meta │ ├── AddLil2cppSourceCodeToXcodeproj2022OrNewer.cs │ ├── AddLil2cppSourceCodeToXcodeproj2022OrNewer.cs.meta │ ├── AddLil2cppSourceCodeToXcodeproj2023OrNewer.cs │ ├── AddLil2cppSourceCodeToXcodeproj2023OrNewer.cs.meta │ ├── BuildProcessorUtil.cs │ ├── BuildProcessorUtil.cs.meta │ ├── CheckSettings.cs │ ├── CheckSettings.cs.meta │ ├── CopyStrippedAOTAssemblies.cs │ ├── CopyStrippedAOTAssemblies.cs.meta │ ├── FilterHotFixAssemblies.cs │ ├── FilterHotFixAssemblies.cs.meta │ ├── MsvcStdextWorkaround.cs │ ├── MsvcStdextWorkaround.cs.meta │ ├── PatchScriptingAssemblyList.cs │ ├── PatchScriptingAssemblyList.cs.meta │ ├── ScriptingAssembliesJsonPatcher.cs │ └── ScriptingAssembliesJsonPatcher.cs.meta ├── Commands.meta ├── Commands │ ├── AOTReferenceGeneratorCommand.cs │ ├── AOTReferenceGeneratorCommand.cs.meta │ ├── CompileDllCommand.cs │ ├── CompileDllCommand.cs.meta │ ├── Il2CppDefGeneratorCommand.cs │ ├── Il2CppDefGeneratorCommand.cs.meta │ ├── LinkGeneratorCommand.cs │ ├── LinkGeneratorCommand.cs.meta │ ├── MethodBridgeGeneratorCommand.cs │ ├── MethodBridgeGeneratorCommand.cs.meta │ ├── PrebuildCommand.cs │ ├── PrebuildCommand.cs.meta │ ├── StripAOTDllCommand.cs │ └── StripAOTDllCommand.cs.meta ├── HashUtil.cs ├── HashUtil.cs.meta ├── HotUpdate.meta ├── HotUpdate │ ├── MissingMetadataChecker.cs │ └── MissingMetadataChecker.cs.meta ├── HybridCLR.Editor.asmdef ├── HybridCLR.Editor.asmdef.meta ├── Il2CppDef.meta ├── Il2CppDef │ ├── Il2CppDefGenerator.cs │ └── Il2CppDefGenerator.cs.meta ├── Installer.meta ├── Installer │ ├── BashUtil.cs │ ├── BashUtil.cs.meta │ ├── InstallerController.cs │ ├── InstallerController.cs.meta │ ├── InstallerWindow.cs │ └── InstallerWindow.cs.meta ├── Link.meta ├── Link │ ├── Analyzer.cs │ ├── Analyzer.cs.meta │ ├── LinkXmlWriter.cs │ └── LinkXmlWriter.cs.meta ├── Meta.meta ├── Meta │ ├── AssemblyCache.cs │ ├── AssemblyCache.cs.meta │ ├── AssemblyCacheBase.cs │ ├── AssemblyCacheBase.cs.meta │ ├── AssemblyReferenceDeepCollector.cs │ ├── AssemblyReferenceDeepCollector.cs.meta │ ├── AssemblyResolverBase.cs │ ├── AssemblyResolverBase.cs.meta │ ├── AssemblySorter.cs │ ├── AssemblySorter.cs.meta │ ├── CombinedAssemblyResolver.cs │ ├── CombinedAssemblyResolver.cs.meta │ ├── FixedSetAssemblyResolver.cs │ ├── FixedSetAssemblyResolver.cs.meta │ ├── GenericArgumentContext.cs │ ├── GenericArgumentContext.cs.meta │ ├── GenericClass.cs │ ├── GenericClass.cs.meta │ ├── GenericMethod.cs │ ├── GenericMethod.cs.meta │ ├── IAssemblyResolver.cs │ ├── IAssemblyResolver.cs.meta │ ├── MetaUtil.cs │ ├── MetaUtil.cs.meta │ ├── MethodReferenceAnalyzer.cs │ ├── MethodReferenceAnalyzer.cs.meta │ ├── PathAssemblyResolver.cs │ └── PathAssemblyResolver.cs.meta ├── MethodBridge.meta ├── MethodBridge │ ├── Analyzer.cs │ ├── Analyzer.cs.meta │ ├── CallNativeMethodSignatureInfo.cs │ ├── CallNativeMethodSignatureInfo.cs.meta │ ├── CalliAnalyzer.cs │ ├── CalliAnalyzer.cs.meta │ ├── Generator.cs │ ├── Generator.cs.meta │ ├── MonoPInvokeCallbackAnalyzer.cs │ ├── MonoPInvokeCallbackAnalyzer.cs.meta │ ├── PInvokeAnalyzer.cs │ └── PInvokeAnalyzer.cs.meta ├── ReversePInvokeWrap.meta ├── Settings.meta ├── Settings │ ├── HybridCLRSettingProvider.cs │ ├── HybridCLRSettingProvider.cs.meta │ ├── HybridCLRSettings.cs │ ├── HybridCLRSettings.cs.meta │ ├── MenuProvider.cs │ └── MenuProvider.cs.meta ├── SettingsUtil.cs ├── SettingsUtil.cs.meta ├── Template.meta └── Template │ ├── FileRegionReplace.cs │ └── FileRegionReplace.cs.meta ├── LICENSE ├── LICENSE.meta ├── Plugins.meta ├── Plugins ├── LZ4.dll ├── LZ4.dll.meta ├── dnlib.dll └── dnlib.dll.meta ├── README.md ├── README.md.meta ├── README_EN.md ├── README_EN.md.meta ├── RELEASELOG.md ├── RELEASELOG.md.meta ├── Runtime.meta ├── Runtime ├── HomologousImageMode.cs ├── HomologousImageMode.cs.meta ├── HybridCLR.Runtime.asmdef ├── HybridCLR.Runtime.asmdef.meta ├── LoadImageErrorCode.cs ├── LoadImageErrorCode.cs.meta ├── ReversePInvokeWrapperGenerationAttribute.cs ├── ReversePInvokeWrapperGenerationAttribute.cs.meta ├── RuntimeApi.cs ├── RuntimeApi.cs.meta ├── RuntimeOptionId.cs └── RuntimeOptionId.cs.meta ├── package.json └── package.json.meta /Data~/ModifiedUnityAssemblies/2019.4.40.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1cd43f2247d29084fa2b393c30648e64 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Data~/ModifiedUnityAssemblies/2019.4.40/Unity.IL2CPP-Mac.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/hybridclr_unity/fca130bbfaa58fab93b09a57ec83704c2aab4d4f/Data~/ModifiedUnityAssemblies/2019.4.40/Unity.IL2CPP-Mac.dll -------------------------------------------------------------------------------- /Data~/ModifiedUnityAssemblies/2019.4.40/Unity.IL2CPP-Win.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/hybridclr_unity/fca130bbfaa58fab93b09a57ec83704c2aab4d4f/Data~/ModifiedUnityAssemblies/2019.4.40/Unity.IL2CPP-Win.dll -------------------------------------------------------------------------------- /Data~/NetStandard/netstandard2.0.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/hybridclr_unity/fca130bbfaa58fab93b09a57ec83704c2aab4d4f/Data~/NetStandard/netstandard2.0.dll -------------------------------------------------------------------------------- /Data~/NetStandard/netstandard2.1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/hybridclr_unity/fca130bbfaa58fab93b09a57ec83704c2aab4d4f/Data~/NetStandard/netstandard2.1.dll -------------------------------------------------------------------------------- /Data~/Templates/AssemblyManifest.cpp.tpl: -------------------------------------------------------------------------------- 1 | #include "../Il2CppCompatibleDef.h" 2 | 3 | namespace hybridclr 4 | { 5 | const char* g_placeHolderAssemblies[] = 6 | { 7 | //!!!{{PLACE_HOLDER 8 | 9 | //!!!}}PLACE_HOLDER 10 | nullptr, 11 | }; 12 | } 13 | -------------------------------------------------------------------------------- /Data~/Templates/MethodBridge.cpp.tpl: -------------------------------------------------------------------------------- 1 | #include 2 | #if HYBRIDCLR_UNITY_2023_OR_NEW 3 | #include 4 | #elif HYBRIDCLR_UNITY_2022 5 | #include 6 | #elif HYBRIDCLR_UNITY_2020 || HYBRIDCLR_UNITY_2021 7 | #include 8 | #else 9 | #include 10 | #endif 11 | 12 | #include "vm/ClassInlines.h" 13 | #include "vm/Object.h" 14 | #include "vm/Class.h" 15 | #include "vm/ScopedThreadAttacher.h" 16 | 17 | #include "../metadata/MetadataUtil.h" 18 | 19 | 20 | #include "../interpreter/InterpreterModule.h" 21 | #include "../interpreter/MethodBridge.h" 22 | #include "../interpreter/Interpreter.h" 23 | #include "../interpreter/MemoryUtil.h" 24 | #include "../interpreter/InstrinctDef.h" 25 | 26 | using namespace hybridclr::interpreter; 27 | using namespace hybridclr::metadata; 28 | 29 | //!!!{{CODE 30 | 31 | 32 | //!!!}}CODE 33 | -------------------------------------------------------------------------------- /Data~/Templates/UnityVersion.h.tpl: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //!!!{{UNITY_VERSION 4 | 5 | 6 | //!!!}}UNITY_VERSION -------------------------------------------------------------------------------- /Data~/hybridclr_version.json: -------------------------------------------------------------------------------- 1 | { 2 | "versions": [ 3 | { 4 | "unity_version":"2019", 5 | "hybridclr" : { "branch":"v8.0.0"}, 6 | "il2cpp_plus": { "branch":"v2019-8.1.0"} 7 | }, 8 | { 9 | "unity_version":"2020", 10 | "hybridclr" : { "branch":"v8.0.0"}, 11 | "il2cpp_plus": { "branch":"v2020-8.1.0"} 12 | }, 13 | { 14 | "unity_version":"2021", 15 | "hybridclr" : { "branch":"v8.0.0"}, 16 | "il2cpp_plus": { "branch":"v2021-8.1.0"} 17 | }, 18 | { 19 | "unity_version":"2022", 20 | "hybridclr" : { "branch":"v8.0.0"}, 21 | "il2cpp_plus": { "branch":"v2022-8.1.0"} 22 | }, 23 | { 24 | "unity_version":"2022-tuanjie", 25 | "hybridclr" : { "branch":"v8.0.0"}, 26 | "il2cpp_plus": { "branch":"v2022-tuanjie-8.1.0"} 27 | }, 28 | { 29 | "unity_version":"2023", 30 | "hybridclr" : { "branch":"v8.0.0"}, 31 | "il2cpp_plus": { "branch":"v2023-8.1.0"} 32 | }, 33 | { 34 | "unity_version":"6000", 35 | "hybridclr" : { "branch":"v8.0.0"}, 36 | "il2cpp_plus": { "branch":"v6000-8.1.0"} 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c3fabc41cf17c444995fc01a76c5dbe6 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: daa1e09af240aae4da0741843cb2b3f3 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/7zip.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 08f44f6e8bfbc2c45afae7bdd2d7f21f 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Common.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5cedddbfa873eb94496b496e2a3ce8aa 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Common/CRC.cs: -------------------------------------------------------------------------------- 1 | // Common/CRC.cs 2 | 3 | namespace SevenZip 4 | { 5 | public class CRC 6 | { 7 | public static readonly uint[] Table; 8 | 9 | static CRC() 10 | { 11 | Table = new uint[256]; 12 | const uint kPoly = 0xEDB88320; 13 | for (uint i = 0; i < 256; i++) 14 | { 15 | uint r = i; 16 | for (int j = 0; j < 8; j++) 17 | if ((r & 1) != 0) 18 | r = (r >> 1) ^ kPoly; 19 | else 20 | r >>= 1; 21 | Table[i] = r; 22 | } 23 | } 24 | 25 | uint _value = 0xFFFFFFFF; 26 | 27 | public void Init() { _value = 0xFFFFFFFF; } 28 | 29 | public void UpdateByte(byte b) 30 | { 31 | _value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8); 32 | } 33 | 34 | public void Update(byte[] data, uint offset, uint size) 35 | { 36 | for (uint i = 0; i < size; i++) 37 | _value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8); 38 | } 39 | 40 | public uint GetDigest() { return _value ^ 0xFFFFFFFF; } 41 | 42 | static uint CalculateDigest(byte[] data, uint offset, uint size) 43 | { 44 | CRC crc = new CRC(); 45 | // crc.Init(); 46 | crc.Update(data, offset, size); 47 | return crc.GetDigest(); 48 | } 49 | 50 | static bool VerifyDigest(uint digest, byte[] data, uint offset, uint size) 51 | { 52 | return (CalculateDigest(data, offset, size) == digest); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Common/CRC.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d0bb58ecc915d9d47b8567adaa2d0ca6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Common/CommandLineParser.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dc0b3921c07ef224cb3656391f4317c3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Common/InBuffer.cs: -------------------------------------------------------------------------------- 1 | // InBuffer.cs 2 | 3 | namespace SevenZip.Buffer 4 | { 5 | public class InBuffer 6 | { 7 | byte[] m_Buffer; 8 | uint m_Pos; 9 | uint m_Limit; 10 | uint m_BufferSize; 11 | System.IO.Stream m_Stream; 12 | bool m_StreamWasExhausted; 13 | ulong m_ProcessedSize; 14 | 15 | public InBuffer(uint bufferSize) 16 | { 17 | m_Buffer = new byte[bufferSize]; 18 | m_BufferSize = bufferSize; 19 | } 20 | 21 | public void Init(System.IO.Stream stream) 22 | { 23 | m_Stream = stream; 24 | m_ProcessedSize = 0; 25 | m_Limit = 0; 26 | m_Pos = 0; 27 | m_StreamWasExhausted = false; 28 | } 29 | 30 | public bool ReadBlock() 31 | { 32 | if (m_StreamWasExhausted) 33 | return false; 34 | m_ProcessedSize += m_Pos; 35 | int aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize); 36 | m_Pos = 0; 37 | m_Limit = (uint)aNumProcessedBytes; 38 | m_StreamWasExhausted = (aNumProcessedBytes == 0); 39 | return (!m_StreamWasExhausted); 40 | } 41 | 42 | 43 | public void ReleaseStream() 44 | { 45 | // m_Stream.Close(); 46 | m_Stream = null; 47 | } 48 | 49 | public bool ReadByte(byte b) // check it 50 | { 51 | if (m_Pos >= m_Limit) 52 | if (!ReadBlock()) 53 | return false; 54 | b = m_Buffer[m_Pos++]; 55 | return true; 56 | } 57 | 58 | public byte ReadByte() 59 | { 60 | // return (byte)m_Stream.ReadByte(); 61 | if (m_Pos >= m_Limit) 62 | if (!ReadBlock()) 63 | return 0xFF; 64 | return m_Buffer[m_Pos++]; 65 | } 66 | 67 | public ulong GetProcessedSize() 68 | { 69 | return m_ProcessedSize + m_Pos; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Common/InBuffer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6ea025f5b275726479ba55e956574898 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Common/OutBuffer.cs: -------------------------------------------------------------------------------- 1 | // OutBuffer.cs 2 | 3 | namespace SevenZip.Buffer 4 | { 5 | public class OutBuffer 6 | { 7 | byte[] m_Buffer; 8 | uint m_Pos; 9 | uint m_BufferSize; 10 | System.IO.Stream m_Stream; 11 | ulong m_ProcessedSize; 12 | 13 | public OutBuffer(uint bufferSize) 14 | { 15 | m_Buffer = new byte[bufferSize]; 16 | m_BufferSize = bufferSize; 17 | } 18 | 19 | public void SetStream(System.IO.Stream stream) { m_Stream = stream; } 20 | public void FlushStream() { m_Stream.Flush(); } 21 | public void CloseStream() { m_Stream.Close(); } 22 | public void ReleaseStream() { m_Stream = null; } 23 | 24 | public void Init() 25 | { 26 | m_ProcessedSize = 0; 27 | m_Pos = 0; 28 | } 29 | 30 | public void WriteByte(byte b) 31 | { 32 | m_Buffer[m_Pos++] = b; 33 | if (m_Pos >= m_BufferSize) 34 | FlushData(); 35 | } 36 | 37 | public void FlushData() 38 | { 39 | if (m_Pos == 0) 40 | return; 41 | m_Stream.Write(m_Buffer, 0, (int)m_Pos); 42 | m_Pos = 0; 43 | } 44 | 45 | public ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Common/OutBuffer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5d61847c152e7384ab15aea89a942f54 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b6765bf0d03fd243b47d74c9b73c38b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/LZ.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a83572c42056f474db56e761a4f35e38 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/LZ/IMatchFinder.cs: -------------------------------------------------------------------------------- 1 | // IMatchFinder.cs 2 | 3 | using System; 4 | 5 | namespace SevenZip.Compression.LZ 6 | { 7 | interface IInWindowStream 8 | { 9 | void SetStream(System.IO.Stream inStream); 10 | void Init(); 11 | void ReleaseStream(); 12 | Byte GetIndexByte(Int32 index); 13 | UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit); 14 | UInt32 GetNumAvailableBytes(); 15 | } 16 | 17 | interface IMatchFinder : IInWindowStream 18 | { 19 | void Create(UInt32 historySize, UInt32 keepAddBufferBefore, 20 | UInt32 matchMaxLen, UInt32 keepAddBufferAfter); 21 | UInt32 GetMatches(UInt32[] distances); 22 | void Skip(UInt32 num); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/LZ/IMatchFinder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bfd1ee430d8108042a2607d92d7f58ad 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/LZ/LzBinTree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3ba8015d2d5df3a459615ffc06635e6d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/LZ/LzInWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 333112c3785a6ec4cbbfec8515081cac 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/LZ/LzOutWindow.cs: -------------------------------------------------------------------------------- 1 | // LzOutWindow.cs 2 | 3 | namespace SevenZip.Compression.LZ 4 | { 5 | public class OutWindow 6 | { 7 | byte[] _buffer = null; 8 | uint _pos; 9 | uint _windowSize = 0; 10 | uint _streamPos; 11 | System.IO.Stream _stream; 12 | 13 | public uint TrainSize = 0; 14 | 15 | public void Create(uint windowSize) 16 | { 17 | if (_windowSize != windowSize) 18 | { 19 | // System.GC.Collect(); 20 | _buffer = new byte[windowSize]; 21 | } 22 | _windowSize = windowSize; 23 | _pos = 0; 24 | _streamPos = 0; 25 | } 26 | 27 | public void Init(System.IO.Stream stream, bool solid) 28 | { 29 | ReleaseStream(); 30 | _stream = stream; 31 | if (!solid) 32 | { 33 | _streamPos = 0; 34 | _pos = 0; 35 | TrainSize = 0; 36 | } 37 | } 38 | 39 | public bool Train(System.IO.Stream stream) 40 | { 41 | long len = stream.Length; 42 | uint size = (len < _windowSize) ? (uint)len : _windowSize; 43 | TrainSize = size; 44 | stream.Position = len - size; 45 | _streamPos = _pos = 0; 46 | while (size > 0) 47 | { 48 | uint curSize = _windowSize - _pos; 49 | if (size < curSize) 50 | curSize = size; 51 | int numReadBytes = stream.Read(_buffer, (int)_pos, (int)curSize); 52 | if (numReadBytes == 0) 53 | return false; 54 | size -= (uint)numReadBytes; 55 | _pos += (uint)numReadBytes; 56 | _streamPos += (uint)numReadBytes; 57 | if (_pos == _windowSize) 58 | _streamPos = _pos = 0; 59 | } 60 | return true; 61 | } 62 | 63 | public void ReleaseStream() 64 | { 65 | Flush(); 66 | _stream = null; 67 | } 68 | 69 | public void Flush() 70 | { 71 | uint size = _pos - _streamPos; 72 | if (size == 0) 73 | return; 74 | _stream.Write(_buffer, (int)_streamPos, (int)size); 75 | if (_pos >= _windowSize) 76 | _pos = 0; 77 | _streamPos = _pos; 78 | } 79 | 80 | public void CopyBlock(uint distance, uint len) 81 | { 82 | uint pos = _pos - distance - 1; 83 | if (pos >= _windowSize) 84 | pos += _windowSize; 85 | for (; len > 0; len--) 86 | { 87 | if (pos >= _windowSize) 88 | pos = 0; 89 | _buffer[_pos++] = _buffer[pos++]; 90 | if (_pos >= _windowSize) 91 | Flush(); 92 | } 93 | } 94 | 95 | public void PutByte(byte b) 96 | { 97 | _buffer[_pos++] = b; 98 | if (_pos >= _windowSize) 99 | Flush(); 100 | } 101 | 102 | public byte GetByte(uint distance) 103 | { 104 | uint pos = _pos - distance - 1; 105 | if (pos >= _windowSize) 106 | pos += _windowSize; 107 | return _buffer[pos]; 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/LZ/LzOutWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb296a6e14ab7c44cb6388693d581a62 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/LZMA.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5fcd2f5c8b724164a8a01cee73896d1a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/LZMA/LzmaBase.cs: -------------------------------------------------------------------------------- 1 | // LzmaBase.cs 2 | 3 | namespace SevenZip.Compression.LZMA 4 | { 5 | internal abstract class Base 6 | { 7 | public const uint kNumRepDistances = 4; 8 | public const uint kNumStates = 12; 9 | 10 | // static byte []kLiteralNextStates = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5}; 11 | // static byte []kMatchNextStates = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10}; 12 | // static byte []kRepNextStates = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11}; 13 | // static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11}; 14 | 15 | public struct State 16 | { 17 | public uint Index; 18 | public void Init() { Index = 0; } 19 | public void UpdateChar() 20 | { 21 | if (Index < 4) Index = 0; 22 | else if (Index < 10) Index -= 3; 23 | else Index -= 6; 24 | } 25 | public void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); } 26 | public void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); } 27 | public void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); } 28 | public bool IsCharState() { return Index < 7; } 29 | } 30 | 31 | public const int kNumPosSlotBits = 6; 32 | public const int kDicLogSizeMin = 0; 33 | // public const int kDicLogSizeMax = 30; 34 | // public const uint kDistTableSizeMax = kDicLogSizeMax * 2; 35 | 36 | public const int kNumLenToPosStatesBits = 2; // it's for speed optimization 37 | public const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits; 38 | 39 | public const uint kMatchMinLen = 2; 40 | 41 | public static uint GetLenToPosState(uint len) 42 | { 43 | len -= kMatchMinLen; 44 | if (len < kNumLenToPosStates) 45 | return len; 46 | return (uint)(kNumLenToPosStates - 1); 47 | } 48 | 49 | public const int kNumAlignBits = 4; 50 | public const uint kAlignTableSize = 1 << kNumAlignBits; 51 | public const uint kAlignMask = (kAlignTableSize - 1); 52 | 53 | public const uint kStartPosModelIndex = 4; 54 | public const uint kEndPosModelIndex = 14; 55 | public const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex; 56 | 57 | public const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2); 58 | 59 | public const uint kNumLitPosStatesBitsEncodingMax = 4; 60 | public const uint kNumLitContextBitsMax = 8; 61 | 62 | public const int kNumPosStatesBitsMax = 4; 63 | public const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax); 64 | public const int kNumPosStatesBitsEncodingMax = 4; 65 | public const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax); 66 | 67 | public const int kNumLowLenBits = 3; 68 | public const int kNumMidLenBits = 3; 69 | public const int kNumHighLenBits = 8; 70 | public const uint kNumLowLenSymbols = 1 << kNumLowLenBits; 71 | public const uint kNumMidLenSymbols = 1 << kNumMidLenBits; 72 | public const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols + 73 | (1 << kNumHighLenBits); 74 | public const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/LZMA/LzmaBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 62f365191077342479f8227edadf57e3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/LZMA/LzmaDecoder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c60a9ce2c6df6774498e337ad69a356b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/LZMA/LzmaEncoder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 37dcefc9d952dc34f9fba085a160a968 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/RangeCoder.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 73c80167cede90a4a8fc4938bab053c8 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/RangeCoder/RangeCoder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a855cbfe314340a43b3d71672dcbb058 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/RangeCoder/RangeCoderBit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SevenZip.Compression.RangeCoder 4 | { 5 | struct BitEncoder 6 | { 7 | public const int kNumBitModelTotalBits = 11; 8 | public const uint kBitModelTotal = (1 << kNumBitModelTotalBits); 9 | const int kNumMoveBits = 5; 10 | const int kNumMoveReducingBits = 2; 11 | public const int kNumBitPriceShiftBits = 6; 12 | 13 | uint Prob; 14 | 15 | public void Init() { Prob = kBitModelTotal >> 1; } 16 | 17 | public void UpdateModel(uint symbol) 18 | { 19 | if (symbol == 0) 20 | Prob += (kBitModelTotal - Prob) >> kNumMoveBits; 21 | else 22 | Prob -= (Prob) >> kNumMoveBits; 23 | } 24 | 25 | public void Encode(Encoder encoder, uint symbol) 26 | { 27 | // encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol); 28 | // UpdateModel(symbol); 29 | uint newBound = (encoder.Range >> kNumBitModelTotalBits) * Prob; 30 | if (symbol == 0) 31 | { 32 | encoder.Range = newBound; 33 | Prob += (kBitModelTotal - Prob) >> kNumMoveBits; 34 | } 35 | else 36 | { 37 | encoder.Low += newBound; 38 | encoder.Range -= newBound; 39 | Prob -= (Prob) >> kNumMoveBits; 40 | } 41 | if (encoder.Range < Encoder.kTopValue) 42 | { 43 | encoder.Range <<= 8; 44 | encoder.ShiftLow(); 45 | } 46 | } 47 | 48 | private static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits]; 49 | 50 | static BitEncoder() 51 | { 52 | const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits); 53 | for (int i = kNumBits - 1; i >= 0; i--) 54 | { 55 | UInt32 start = (UInt32)1 << (kNumBits - i - 1); 56 | UInt32 end = (UInt32)1 << (kNumBits - i); 57 | for (UInt32 j = start; j < end; j++) 58 | ProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) + 59 | (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1)); 60 | } 61 | } 62 | 63 | public uint GetPrice(uint symbol) 64 | { 65 | return ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits]; 66 | } 67 | public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; } 68 | public uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; } 69 | } 70 | 71 | struct BitDecoder 72 | { 73 | public const int kNumBitModelTotalBits = 11; 74 | public const uint kBitModelTotal = (1 << kNumBitModelTotalBits); 75 | const int kNumMoveBits = 5; 76 | 77 | uint Prob; 78 | 79 | public void UpdateModel(int numMoveBits, uint symbol) 80 | { 81 | if (symbol == 0) 82 | Prob += (kBitModelTotal - Prob) >> numMoveBits; 83 | else 84 | Prob -= (Prob) >> numMoveBits; 85 | } 86 | 87 | public void Init() { Prob = kBitModelTotal >> 1; } 88 | 89 | public uint Decode(RangeCoder.Decoder rangeDecoder) 90 | { 91 | uint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob; 92 | if (rangeDecoder.Code < newBound) 93 | { 94 | rangeDecoder.Range = newBound; 95 | Prob += (kBitModelTotal - Prob) >> kNumMoveBits; 96 | if (rangeDecoder.Range < Decoder.kTopValue) 97 | { 98 | rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte(); 99 | rangeDecoder.Range <<= 8; 100 | } 101 | return 0; 102 | } 103 | else 104 | { 105 | rangeDecoder.Range -= newBound; 106 | rangeDecoder.Code -= newBound; 107 | Prob -= (Prob) >> kNumMoveBits; 108 | if (rangeDecoder.Range < Decoder.kTopValue) 109 | { 110 | rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte(); 111 | rangeDecoder.Range <<= 8; 112 | } 113 | return 1; 114 | } 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/RangeCoder/RangeCoderBit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f3fd3305ff6e02448a7b0470cfe65b77 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/RangeCoder/RangeCoderBitTree.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SevenZip.Compression.RangeCoder 4 | { 5 | struct BitTreeEncoder 6 | { 7 | BitEncoder[] Models; 8 | int NumBitLevels; 9 | 10 | public BitTreeEncoder(int numBitLevels) 11 | { 12 | NumBitLevels = numBitLevels; 13 | Models = new BitEncoder[1 << numBitLevels]; 14 | } 15 | 16 | public void Init() 17 | { 18 | for (uint i = 1; i < (1 << NumBitLevels); i++) 19 | Models[i].Init(); 20 | } 21 | 22 | public void Encode(Encoder rangeEncoder, UInt32 symbol) 23 | { 24 | UInt32 m = 1; 25 | for (int bitIndex = NumBitLevels; bitIndex > 0; ) 26 | { 27 | bitIndex--; 28 | UInt32 bit = (symbol >> bitIndex) & 1; 29 | Models[m].Encode(rangeEncoder, bit); 30 | m = (m << 1) | bit; 31 | } 32 | } 33 | 34 | public void ReverseEncode(Encoder rangeEncoder, UInt32 symbol) 35 | { 36 | UInt32 m = 1; 37 | for (UInt32 i = 0; i < NumBitLevels; i++) 38 | { 39 | UInt32 bit = symbol & 1; 40 | Models[m].Encode(rangeEncoder, bit); 41 | m = (m << 1) | bit; 42 | symbol >>= 1; 43 | } 44 | } 45 | 46 | public UInt32 GetPrice(UInt32 symbol) 47 | { 48 | UInt32 price = 0; 49 | UInt32 m = 1; 50 | for (int bitIndex = NumBitLevels; bitIndex > 0; ) 51 | { 52 | bitIndex--; 53 | UInt32 bit = (symbol >> bitIndex) & 1; 54 | price += Models[m].GetPrice(bit); 55 | m = (m << 1) + bit; 56 | } 57 | return price; 58 | } 59 | 60 | public UInt32 ReverseGetPrice(UInt32 symbol) 61 | { 62 | UInt32 price = 0; 63 | UInt32 m = 1; 64 | for (int i = NumBitLevels; i > 0; i--) 65 | { 66 | UInt32 bit = symbol & 1; 67 | symbol >>= 1; 68 | price += Models[m].GetPrice(bit); 69 | m = (m << 1) | bit; 70 | } 71 | return price; 72 | } 73 | 74 | public static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex, 75 | int NumBitLevels, UInt32 symbol) 76 | { 77 | UInt32 price = 0; 78 | UInt32 m = 1; 79 | for (int i = NumBitLevels; i > 0; i--) 80 | { 81 | UInt32 bit = symbol & 1; 82 | symbol >>= 1; 83 | price += Models[startIndex + m].GetPrice(bit); 84 | m = (m << 1) | bit; 85 | } 86 | return price; 87 | } 88 | 89 | public static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex, 90 | Encoder rangeEncoder, int NumBitLevels, UInt32 symbol) 91 | { 92 | UInt32 m = 1; 93 | for (int i = 0; i < NumBitLevels; i++) 94 | { 95 | UInt32 bit = symbol & 1; 96 | Models[startIndex + m].Encode(rangeEncoder, bit); 97 | m = (m << 1) | bit; 98 | symbol >>= 1; 99 | } 100 | } 101 | } 102 | 103 | struct BitTreeDecoder 104 | { 105 | BitDecoder[] Models; 106 | int NumBitLevels; 107 | 108 | public BitTreeDecoder(int numBitLevels) 109 | { 110 | NumBitLevels = numBitLevels; 111 | Models = new BitDecoder[1 << numBitLevels]; 112 | } 113 | 114 | public void Init() 115 | { 116 | for (uint i = 1; i < (1 << NumBitLevels); i++) 117 | Models[i].Init(); 118 | } 119 | 120 | public uint Decode(RangeCoder.Decoder rangeDecoder) 121 | { 122 | uint m = 1; 123 | for (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--) 124 | m = (m << 1) + Models[m].Decode(rangeDecoder); 125 | return m - ((uint)1 << NumBitLevels); 126 | } 127 | 128 | public uint ReverseDecode(RangeCoder.Decoder rangeDecoder) 129 | { 130 | uint m = 1; 131 | uint symbol = 0; 132 | for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++) 133 | { 134 | uint bit = Models[m].Decode(rangeDecoder); 135 | m <<= 1; 136 | m += bit; 137 | symbol |= (bit << bitIndex); 138 | } 139 | return symbol; 140 | } 141 | 142 | public static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex, 143 | RangeCoder.Decoder rangeDecoder, int NumBitLevels) 144 | { 145 | uint m = 1; 146 | uint symbol = 0; 147 | for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++) 148 | { 149 | uint bit = Models[startIndex + m].Decode(rangeDecoder); 150 | m <<= 1; 151 | m += bit; 152 | symbol |= (bit << bitIndex); 153 | } 154 | return symbol; 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/Compress/RangeCoder/RangeCoderBitTree.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ef79f786b772db344a4792a5cba382ff 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/7zip/ICoder.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9f4fba00efa28594ea18888f574d028a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 59ab7ccacd9a9944bb9456da235d6760 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/ArchiveFlags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace UnityFS 4 | { 5 | [Flags] 6 | public enum ArchiveFlags 7 | { 8 | CompressionTypeMask = 0x3f, 9 | BlocksAndDirectoryInfoCombined = 0x40, 10 | BlocksInfoAtTheEnd = 0x80, 11 | OldWebPluginCompatibility = 0x100, 12 | BlockInfoNeedPaddingAtStart = 0x200 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/ArchiveFlags.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 099de05eebdffaf4baeed3290dc98aaf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/BinaryReaderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace UnityFS 7 | { 8 | public static class BinaryReaderExtensions 9 | { 10 | 11 | public static void AlignStream(this BinaryReader reader, int alignment) 12 | { 13 | var pos = reader.BaseStream.Position; 14 | var mod = pos % alignment; 15 | if (mod != 0) 16 | { 17 | reader.BaseStream.Position += alignment - mod; 18 | } 19 | } 20 | 21 | public static string ReadAlignedString(this BinaryReader reader) 22 | { 23 | var length = reader.ReadInt32(); 24 | if (length > 0 && length <= reader.BaseStream.Length - reader.BaseStream.Position) 25 | { 26 | var stringData = reader.ReadBytes(length); 27 | var result = Encoding.UTF8.GetString(stringData); 28 | reader.AlignStream(4); 29 | return result; 30 | } 31 | return ""; 32 | } 33 | 34 | public static string ReadStringToNull(this BinaryReader reader, int maxLength = 32767) 35 | { 36 | var bytes = new List(); 37 | int count = 0; 38 | while (reader.BaseStream.Position != reader.BaseStream.Length && count < maxLength) 39 | { 40 | var b = reader.ReadByte(); 41 | if (b == 0) 42 | { 43 | break; 44 | } 45 | bytes.Add(b); 46 | count++; 47 | } 48 | return Encoding.UTF8.GetString(bytes.ToArray()); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/BinaryReaderExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a84e427dd05adde44b4345b3fd49007a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/BinaryWriterExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | 5 | namespace UnityFS 6 | { 7 | public static class BinaryWriterExtensions 8 | { 9 | public static void AlignStream(this BinaryWriter writer, int alignment) 10 | { 11 | var pos = writer.BaseStream.Position; 12 | var mod = pos % alignment; 13 | if (mod != 0) 14 | { 15 | writer.Write(new byte[alignment - mod]); 16 | } 17 | } 18 | 19 | public static void WriteAlignedString(this BinaryWriter writer, string str) 20 | { 21 | var bytes = Encoding.UTF8.GetBytes(str); 22 | writer.Write(bytes.Length); 23 | writer.Write(bytes); 24 | writer.AlignStream(4); 25 | } 26 | 27 | public static void WriteNullEndString(this BinaryWriter writer, string str) 28 | { 29 | writer.Write(Encoding.UTF8.GetBytes(str)); 30 | writer.Write((byte)0); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/BinaryWriterExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02eda21769c083346a5bd9b7dca49427 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/BundleFileInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UnityFS 8 | { 9 | public class BundleSubFile 10 | { 11 | public string file; 12 | public byte[] data; 13 | } 14 | 15 | public class BundleFileInfo 16 | { 17 | public string signature; 18 | public uint version; 19 | public string unityVersion; 20 | public string unityRevision; 21 | public ArchiveFlags flags; 22 | public List files; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/BundleFileInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a72550a949e322419b9c5d6e4fe495d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/BundleFileReader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f9b938458cc610e4d8a910c4499693cf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/BundleFileWriter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6705163b267de54a868f5e84f6c7024 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/CompressionType.cs: -------------------------------------------------------------------------------- 1 | namespace UnityFS 2 | { 3 | public enum CompressionType 4 | { 5 | None, 6 | Lzma, 7 | Lz4, 8 | Lz4HC, 9 | Lzham 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/CompressionType.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ddcd6644c83d2a94f9668d6e913bd80e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/EndianBinaryReader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace UnityFS 5 | { 6 | public class EndianBinaryReader : BinaryReader 7 | { 8 | private readonly byte[] buffer; 9 | 10 | public EndianType Endian; 11 | 12 | public EndianBinaryReader(Stream stream, EndianType endian = EndianType.BigEndian) : base(stream) 13 | { 14 | Endian = endian; 15 | buffer = new byte[8]; 16 | } 17 | 18 | public long Position 19 | { 20 | get => BaseStream.Position; 21 | set => BaseStream.Position = value; 22 | } 23 | 24 | private unsafe void ReadBufferBigEndian(byte* dst, byte[] src, int size) 25 | { 26 | System.Diagnostics.Debug.Assert(BitConverter.IsLittleEndian); 27 | for (int i = 0; i < size; i++) 28 | { 29 | dst[i] = src[size - i - 1]; 30 | } 31 | } 32 | 33 | public override short ReadInt16() 34 | { 35 | return (short)ReadUInt16(); 36 | } 37 | 38 | public unsafe override ushort ReadUInt16() 39 | { 40 | if (Endian == EndianType.BigEndian) 41 | { 42 | Read(buffer, 0, 2); 43 | ushort x = 0; 44 | ReadBufferBigEndian((byte*)&x, buffer, 2); 45 | return x; 46 | } 47 | return base.ReadUInt16(); 48 | } 49 | 50 | public override int ReadInt32() 51 | { 52 | return (int)ReadUInt32(); 53 | } 54 | 55 | public unsafe override uint ReadUInt32() 56 | { 57 | if (Endian == EndianType.BigEndian) 58 | { 59 | Read(buffer, 0, 4); 60 | uint x = 0; 61 | ReadBufferBigEndian((byte*)&x, buffer, 4); 62 | return x; 63 | } 64 | return base.ReadUInt32(); 65 | } 66 | 67 | public override long ReadInt64() 68 | { 69 | return (long)ReadUInt64(); 70 | } 71 | 72 | public unsafe override ulong ReadUInt64() 73 | { 74 | if (Endian == EndianType.BigEndian) 75 | { 76 | Read(buffer, 0, 8); 77 | 78 | ulong x = 0; 79 | ReadBufferBigEndian((byte*)&x, buffer, 8); 80 | return x; 81 | } 82 | return base.ReadUInt64(); 83 | } 84 | 85 | public override float ReadSingle() 86 | { 87 | if (Endian == EndianType.BigEndian) 88 | { 89 | Read(buffer, 0, 4); 90 | Array.Reverse(buffer, 0, 4); 91 | return BitConverter.ToSingle(buffer, 0); 92 | } 93 | return base.ReadSingle(); 94 | } 95 | 96 | public override double ReadDouble() 97 | { 98 | if (Endian == EndianType.BigEndian) 99 | { 100 | Read(buffer, 0, 8); 101 | Array.Reverse(buffer); 102 | return BitConverter.ToDouble(buffer, 0); 103 | } 104 | return base.ReadDouble(); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/EndianBinaryReader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9b02c037f0fa1014da65773804248d8d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/EndianBinaryWriter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace UnityFS 5 | { 6 | public class EndianBinaryWriter : BinaryWriter 7 | { 8 | private readonly byte[] buffer; 9 | 10 | public EndianType Endian; 11 | 12 | public EndianBinaryWriter(Stream stream, EndianType endian = EndianType.BigEndian) : base(stream) 13 | { 14 | Endian = endian; 15 | buffer = new byte[8]; 16 | } 17 | 18 | public long Position 19 | { 20 | get => BaseStream.Position; 21 | set => BaseStream.Position = value; 22 | } 23 | 24 | public long Length => BaseStream.Length; 25 | 26 | public override void Write(short x) 27 | { 28 | Write((ushort)x); 29 | } 30 | 31 | private unsafe void WriteBufferBigEndian(byte[] dst, byte* src, int size) 32 | { 33 | System.Diagnostics.Debug.Assert(BitConverter.IsLittleEndian); 34 | for(int i = 0; i < size; i++) 35 | { 36 | dst[i] = src[size - i - 1]; 37 | } 38 | } 39 | 40 | public unsafe override void Write(ushort x) 41 | { 42 | if (Endian == EndianType.BigEndian) 43 | { 44 | WriteBufferBigEndian(buffer, (byte*)&x, 2); 45 | Write(buffer, 0, 2); 46 | return; 47 | } 48 | base.Write(x); 49 | } 50 | 51 | public override void Write(int x) 52 | { 53 | Write((uint)x); 54 | } 55 | 56 | public unsafe override void Write(uint x) 57 | { 58 | if (Endian == EndianType.BigEndian) 59 | { 60 | WriteBufferBigEndian(buffer, (byte*)&x, 4); 61 | Write(buffer, 0, 4); 62 | return; 63 | } 64 | base.Write(x); 65 | } 66 | 67 | public override void Write(long x) 68 | { 69 | Write((ulong)x); 70 | } 71 | 72 | public unsafe override void Write(ulong x) 73 | { 74 | if (Endian == EndianType.BigEndian) 75 | { 76 | WriteBufferBigEndian(buffer, (byte*)&x, 8); 77 | Write(buffer, 0, 8); 78 | return; 79 | } 80 | base.Write(x); 81 | } 82 | 83 | public override void Write(float x) 84 | { 85 | if (Endian == EndianType.BigEndian) 86 | { 87 | var buf = BitConverter.GetBytes(x); 88 | Array.Reverse(buf, 0, 4); 89 | Write(buf, 0, 4); 90 | return; 91 | } 92 | base.Write(x); 93 | } 94 | 95 | public override void Write(double x) 96 | { 97 | if (Endian == EndianType.BigEndian) 98 | { 99 | var buf = BitConverter.GetBytes(x); 100 | Array.Reverse(buf, 0, 8); 101 | Write(buf, 0, 8); 102 | return; 103 | } 104 | base.Write(x); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/EndianBinaryWriter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4107364c7434b2042ad647b28e322513 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/EndianType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UnityFS 8 | { 9 | public enum EndianType 10 | { 11 | LittleEndian, 12 | BigEndian 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/EndianType.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2f6cbab4506c18248b410a164be891d2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/GlobalgamedatasPatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using UnityEngine; 8 | using UnityFS; 9 | 10 | namespace HybridCLR.Editor.UnityBinFileReader 11 | { 12 | public class Dataunity3dPatcher 13 | { 14 | 15 | public void ApplyPatch(string dataunity3dFile, List hotUpdateAssemblies) 16 | { 17 | var reader = new BundleFileReader(); 18 | using (var fs = new EndianBinaryReader(new MemoryStream(File.ReadAllBytes(dataunity3dFile)))) 19 | { 20 | reader.Load(fs); 21 | } 22 | 23 | var info = reader.CreateBundleFileInfo(); 24 | //Debug.Log($"name:{info.signature} version:{info.version} files:{info.files.Count}"); 25 | //foreach (var file in info.files) 26 | //{ 27 | // Debug.Log($"file:{file.file} size:{file.data.Length}"); 28 | //} 29 | 30 | var globalgamemanagersFile = info.files.Find(f => f.file == "globalgamemanagers"); 31 | //Debug.LogFormat("gobalgamemanagers origin size:{0}", globalgamemanagersFile.data.Length); 32 | 33 | var ggdBinFile = new UnityBinFile(); 34 | ggdBinFile.LoadFromStream(new MemoryStream(globalgamemanagersFile.data)); 35 | ggdBinFile.AddScriptingAssemblies(hotUpdateAssemblies); 36 | byte[] patchedGlobalgamedatasBytes = ggdBinFile.CreatePatchedBytes(); 37 | //Debug.LogFormat("gobalgamemanagers post patche size:{0}", patchedGlobalgamedatasBytes.Length); 38 | globalgamemanagersFile.data = patchedGlobalgamedatasBytes; 39 | 40 | var writer = new BundleFileWriter(info); 41 | var output = new MemoryStream(); 42 | writer.Write(new EndianBinaryWriter(output)); 43 | Debug.Log($"patch file:{dataunity3dFile} size:{output.Length}"); 44 | 45 | //string bakFile = dataunity3dFile + ".bak"; 46 | //if (!File.Exists(bakFile)) 47 | //{ 48 | // File.Copy(dataunity3dFile, bakFile); 49 | //} 50 | File.WriteAllBytes(dataunity3dFile, output.ToArray()); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/GlobalgamedatasPatcher.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 653a22d285c79f44a8113c5571b2d26b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/Header.cs: -------------------------------------------------------------------------------- 1 | namespace UnityFS 2 | { 3 | public class Header 4 | { 5 | public string signature; 6 | public uint version; 7 | public string unityVersion; 8 | public string unityRevision; 9 | public long size; 10 | public uint compressedBlocksInfoSize; 11 | public uint uncompressedBlocksInfoSize; 12 | public ArchiveFlags flags; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/Header.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f121e0520fa65c240884d43fd00b3c2a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/Node.cs: -------------------------------------------------------------------------------- 1 | namespace UnityFS 2 | { 3 | public class Node 4 | { 5 | public long offset; 6 | public long size; 7 | public uint flags; 8 | public string path; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/Node.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e3eea8a6a32b6ac4ba609b39715e25e2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/ScriptingAssembliesJsonPatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using UnityEngine; 8 | 9 | namespace UnityFS 10 | { 11 | public class ScriptingAssembliesJsonPatcher 12 | { 13 | [Serializable] 14 | private class ScriptingAssemblies 15 | { 16 | public List names; 17 | public List types; 18 | } 19 | 20 | private string _file; 21 | ScriptingAssemblies _scriptingAssemblies; 22 | 23 | public void Load(string file) 24 | { 25 | _file = file; 26 | string content = File.ReadAllText(file); 27 | _scriptingAssemblies = JsonUtility.FromJson(content); 28 | } 29 | 30 | public void AddScriptingAssemblies(List assemblies) 31 | { 32 | foreach (string name in assemblies) 33 | { 34 | if (!_scriptingAssemblies.names.Contains(name)) 35 | { 36 | _scriptingAssemblies.names.Add(name); 37 | _scriptingAssemblies.types.Add(16); // user dll type 38 | Debug.Log($"[PatchScriptAssembliesJson] add hotfix assembly:{name} to {_file}"); 39 | } 40 | } 41 | } 42 | 43 | public void Save(string jsonFile) 44 | { 45 | string content = JsonUtility.ToJson(_scriptingAssemblies); 46 | 47 | File.WriteAllText(jsonFile, content); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/ScriptingAssembliesJsonPatcher.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8f2dd29d56a640d4ebd1c2fd374b7638 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/SevenZipHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using SevenZip.Compression.LZMA; 4 | 5 | 6 | namespace UnityFS 7 | { 8 | public static class ComparessHelper 9 | { 10 | public static MemoryStream Decompress7Zip(MemoryStream inStream) 11 | { 12 | var decoder = new Decoder(); 13 | 14 | inStream.Seek(0, SeekOrigin.Begin); 15 | var newOutStream = new MemoryStream(); 16 | 17 | var properties = new byte[5]; 18 | if (inStream.Read(properties, 0, 5) != 5) 19 | throw new Exception("input .lzma is too short"); 20 | long outSize = 0; 21 | for (var i = 0; i < 8; i++) 22 | { 23 | var v = inStream.ReadByte(); 24 | if (v < 0) 25 | throw new Exception("Can't Read 1"); 26 | outSize |= ((long)(byte)v) << (8 * i); 27 | } 28 | decoder.SetDecoderProperties(properties); 29 | 30 | var compressedSize = inStream.Length - inStream.Position; 31 | decoder.Code(inStream, newOutStream, compressedSize, outSize, null); 32 | 33 | newOutStream.Position = 0; 34 | return newOutStream; 35 | } 36 | 37 | public static void Decompress7Zip(Stream compressedStream, Stream decompressedStream, long compressedSize, long decompressedSize) 38 | { 39 | var basePosition = compressedStream.Position; 40 | var decoder = new Decoder(); 41 | var properties = new byte[5]; 42 | if (compressedStream.Read(properties, 0, 5) != 5) 43 | throw new Exception("input .lzma is too short"); 44 | decoder.SetDecoderProperties(properties); 45 | decoder.Code(compressedStream, decompressedStream, compressedSize - 5, decompressedSize, null); 46 | compressedStream.Position = basePosition + compressedSize; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/SevenZipHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6606a654e10b3ba48b76b566b903b353 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/StorageBlock.cs: -------------------------------------------------------------------------------- 1 | namespace UnityFS 2 | { 3 | public class StorageBlock 4 | { 5 | public uint compressedSize; 6 | public uint uncompressedSize; 7 | public StorageBlockFlags flags; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/StorageBlock.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 40dc58bec5631f14c9c17c8a486496d4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/StorageBlockFlags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace UnityFS 4 | { 5 | [Flags] 6 | public enum StorageBlockFlags 7 | { 8 | CompressionTypeMask = 0x3f, 9 | Streamed = 0x40 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/StorageBlockFlags.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 79b9ed6799d3caf459cf2dfae5765a23 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/StreamExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace UnityFS 4 | { 5 | public static class StreamExtensions 6 | { 7 | private const int BufferSize = 81920; 8 | 9 | public static void CopyTo(this Stream source, Stream destination, long size) 10 | { 11 | var buffer = new byte[BufferSize]; 12 | for (var left = size; left > 0; left -= BufferSize) 13 | { 14 | int toRead = BufferSize < left ? BufferSize : (int)left; 15 | int read = source.Read(buffer, 0, toRead); 16 | destination.Write(buffer, 0, read); 17 | if (read != toRead) 18 | { 19 | return; 20 | } 21 | } 22 | } 23 | 24 | public static byte[] ReadAllBytes(this Stream source) 25 | { 26 | source.Position = 0; 27 | var bytes = new byte[source.Length]; 28 | source.Read(bytes, 0, bytes.Length); 29 | return bytes; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/StreamExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2262fbf5672028a48b0c63821d7ff0c0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/StreamFile.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace UnityFS 4 | { 5 | public class StreamFile 6 | { 7 | public string path; 8 | public string fileName; 9 | public Stream stream; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/StreamFile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fad7df04825c947489aad0d5d0c191a7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/UnityBinFile.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7f9902041e9a1ff4c9f2d65d6384530d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/UnityBinFileDefines.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 10655ce82e730324db6ae297f77df04b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/UnityBinUtils.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using UnityEngine; 5 | using System.Text; 6 | 7 | namespace UnityFS 8 | { 9 | public static class UnityBinUtils 10 | { 11 | public static void SwapUInt(ref uint val) 12 | { 13 | val = (val >> 24) | ((val >> 8) & 0x0000ff00) | ((val << 8) & 0x00ff0000) | (val << 24); 14 | } 15 | 16 | public static string ReadRawString(this BinaryReader br) 17 | { 18 | long startPos = br.BaseStream.Position; 19 | while (true) 20 | { 21 | byte val = br.ReadByte(); 22 | if(val == 0) 23 | break; 24 | } 25 | int size = (int)(br.BaseStream.Position - startPos); 26 | br.BaseStream.Position = startPos; 27 | 28 | byte[] buffer = br.ReadBytes(size); 29 | string ret = Encoding.UTF8.GetString(buffer, 0, size - 1); 30 | 31 | return ret; 32 | } 33 | 34 | public static void WriteRawString(this BinaryWriter bw, string str) 35 | { 36 | byte[] buffer = Encoding.UTF8.GetBytes(str); 37 | bw.Write(buffer, 0, buffer.Length); 38 | bw.Write((byte)0); 39 | } 40 | 41 | public static string ReadSizeString(this BinaryReader br) 42 | { 43 | int size = br.ReadInt32(); 44 | byte[] buff = br.ReadBytes(size); 45 | br.BaseStream.AlignOffset4(); 46 | 47 | string ret = Encoding.UTF8.GetString(buff); 48 | return ret; 49 | } 50 | 51 | public static void WriteSizeString(this BinaryWriter bw, string str) 52 | { 53 | byte[] buff = Encoding.UTF8.GetBytes(str); 54 | bw.Write(buff.Length); 55 | bw.Write(buff, 0, buff.Length); 56 | bw.BaseStream.AlignOffset4(); 57 | } 58 | 59 | public static void AlignOffset4(this Stream stream) 60 | { 61 | int offset = (((int)stream.Position + 3) >> 2) << 2; 62 | stream.Position = offset; 63 | } 64 | 65 | public static long AlignedReadInt64(this BinaryReader br) 66 | { 67 | br.BaseStream.AlignOffset4(); 68 | return br.ReadInt64(); 69 | } 70 | 71 | public static void AlignedWriteInt64(this BinaryWriter bw, long val) 72 | { 73 | bw.BaseStream.AlignOffset4(); 74 | bw.Write(val); 75 | } 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /Editor/3rds/UnityFS/UnityBinUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 12a24c30a3914be418be10cfebfa9649 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13fe0cab0b357464d889de45c8d98850 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/CodePatcher.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 97cc0d26f72fc4148b8370b2252d1585 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/HookPool.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using UnityEngine; 5 | using System.Linq; 6 | using System.IO; 7 | #if UNITY_EDITOR 8 | using UnityEditor; 9 | #endif 10 | 11 | namespace MonoHook 12 | { 13 | /// 14 | /// Hook 池,防止重复 Hook 15 | /// 16 | public static class HookPool 17 | { 18 | private static Dictionary _hooks = new Dictionary(); 19 | 20 | public static void AddHook(MethodBase method, MethodHook hook) 21 | { 22 | MethodHook preHook; 23 | if (_hooks.TryGetValue(method, out preHook)) 24 | { 25 | preHook.Uninstall(); 26 | _hooks[method] = hook; 27 | } 28 | else 29 | _hooks.Add(method, hook); 30 | } 31 | 32 | public static MethodHook GetHook(MethodBase method) 33 | { 34 | if (method == null) return null; 35 | 36 | MethodHook hook; 37 | if (_hooks.TryGetValue(method, out hook)) 38 | return hook; 39 | return null; 40 | } 41 | 42 | public static void RemoveHooker(MethodBase method) 43 | { 44 | if (method == null) return; 45 | 46 | _hooks.Remove(method); 47 | } 48 | 49 | public static void UninstallAll() 50 | { 51 | var list = _hooks.Values.ToList(); 52 | foreach (var hook in list) 53 | hook.Uninstall(); 54 | 55 | _hooks.Clear(); 56 | } 57 | 58 | public static void UninstallByTag(string tag) 59 | { 60 | var list = _hooks.Values.ToList(); 61 | foreach (var hook in list) 62 | { 63 | if(hook.tag == tag) 64 | hook.Uninstall(); 65 | } 66 | } 67 | 68 | public static List GetAllHooks() 69 | { 70 | return _hooks.Values.ToList(); 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/HookPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6b7421e47f0ae1e4ebb72bf18d1d7d48 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/HookUtils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e84139b42a6164e4c93ce4df1be6dcfb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/HookUtils_OSX.cs: -------------------------------------------------------------------------------- 1 | #if (UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX) 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using UnityEngine; 8 | 9 | namespace MonoHook 10 | { 11 | public static unsafe class HookUtils 12 | { 13 | static bool jit_write_protect_supported; 14 | private static readonly long _Pagesize; 15 | 16 | 17 | static HookUtils() 18 | { 19 | try 20 | { 21 | jit_write_protect_supported = pthread_jit_write_protect_supported_np() != 0; 22 | } 23 | catch { } 24 | 25 | PropertyInfo p_SystemPageSize = typeof(Environment).GetProperty("SystemPageSize"); 26 | if (p_SystemPageSize == null) 27 | throw new NotSupportedException("Unsupported runtime"); 28 | _Pagesize = (int)p_SystemPageSize.GetValue(null, new object[0]); 29 | } 30 | 31 | public static void MemCpy(void* pDst, void* pSrc, int len) 32 | { 33 | byte* pDst_ = (byte*)pDst; 34 | byte* pSrc_ = (byte*)pSrc; 35 | 36 | for (int i = 0; i < len; i++) 37 | *pDst_++ = *pSrc_++; 38 | } 39 | 40 | public static void MemCpy_Jit(void* pDst, byte[] src) 41 | { 42 | if (!jit_write_protect_supported) 43 | { 44 | fixed(void * pSrc = &src[0]) 45 | { 46 | MemCpy(pDst, pSrc, src.Length); 47 | } 48 | 49 | return; 50 | } 51 | 52 | fixed(void * p = &src[0]) 53 | { 54 | memcpy_jit(new IntPtr(pDst), new IntPtr(p), src.Length); 55 | } 56 | } 57 | 58 | /// 59 | /// set flags of address to `read write execute` 60 | /// 61 | public static void SetAddrFlagsToRWX(IntPtr ptr, int size) { } 62 | 63 | public static void FlushICache(void* code, int size) { } 64 | 65 | public static KeyValuePair GetPageAlignedAddr(long code, int size) 66 | { 67 | long pagesize = _Pagesize; 68 | long startPage = (code) & ~(pagesize - 1); 69 | long endPage = (code + size + pagesize - 1) & ~(pagesize - 1); 70 | return new KeyValuePair(startPage, endPage); 71 | } 72 | 73 | 74 | const int PRINT_SPLIT = 4; 75 | const int PRINT_COL_SIZE = PRINT_SPLIT * 4; 76 | public static string HexToString(void* ptr, int size, int offset = 0) 77 | { 78 | Func formatAddr = (IntPtr addr__) => IntPtr.Size == 4 ? $"0x{(uint)addr__:x}" : $"0x{(ulong)addr__:x}"; 79 | 80 | byte* addr = (byte*)ptr; 81 | 82 | StringBuilder sb = new StringBuilder(1024); 83 | sb.AppendLine($"addr:{formatAddr(new IntPtr(addr))}"); 84 | 85 | addr += offset; 86 | size += Math.Abs(offset); 87 | 88 | int count = 0; 89 | while (true) 90 | { 91 | sb.Append($"\r\n{formatAddr(new IntPtr(addr + count))}: "); 92 | for (int i = 1; i < PRINT_COL_SIZE + 1; i++) 93 | { 94 | if (count >= size) 95 | goto END; 96 | 97 | sb.Append($"{*(addr + count):x2}"); 98 | if (i % PRINT_SPLIT == 0) 99 | sb.Append(" "); 100 | 101 | count++; 102 | } 103 | } 104 | END:; 105 | return sb.ToString(); 106 | } 107 | 108 | [DllImport("pthread", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] 109 | private static extern int pthread_jit_write_protect_supported_np(); 110 | 111 | [DllImport("libMonoHookUtils_OSX", SetLastError = true, CallingConvention = CallingConvention.Cdecl)] 112 | private static extern IntPtr memcpy_jit(IntPtr dst, IntPtr src, int len); 113 | } 114 | } 115 | 116 | #endif -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/HookUtils_OSX.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: efda6e010e5c6594081c4a62861d469f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/HybridCLRHooks.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d796fc01daee1964586621890988a5ae 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/HybridCLRHooks/CopyStrippedAOTAssembliesHook.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Reflection; 6 | using UnityEngine; 7 | using UnityEditor; 8 | using System.Runtime.CompilerServices; 9 | using MonoHook; 10 | using HybridCLR.Editor.BuildProcessors; 11 | using System.IO; 12 | 13 | namespace HybridCLR.MonoHook 14 | { 15 | #if UNITY_2021_1_OR_NEWER && !UNITY_2023_1_OR_NEWER 16 | [InitializeOnLoad] 17 | public class CopyStrippedAOTAssembliesHook 18 | { 19 | private static MethodHook _hook; 20 | 21 | static CopyStrippedAOTAssembliesHook() 22 | { 23 | if (_hook == null) 24 | { 25 | Type type = typeof(UnityEditor.EditorApplication).Assembly.GetType("UnityEditorInternal.AssemblyStripper"); 26 | MethodInfo miTarget = type.GetMethod("StripAssembliesTo", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public); 27 | 28 | MethodInfo miReplacement = new StripAssembliesDel(OverrideStripAssembliesTo).Method; 29 | MethodInfo miProxy = new StripAssembliesDel(StripAssembliesToProxy).Method; 30 | 31 | _hook = new MethodHook(miTarget, miReplacement, miProxy); 32 | _hook.Install(); 33 | } 34 | } 35 | 36 | private delegate bool StripAssembliesDel(string outputFolder, out string output, out string error, IEnumerable linkXmlFiles, object runInformation); 37 | 38 | private static bool OverrideStripAssembliesTo(string outputFolder, out string output, out string error, IEnumerable linkXmlFiles, object runInformation) 39 | { 40 | bool result = StripAssembliesToProxy(outputFolder, out output, out error, linkXmlFiles, runInformation); 41 | if (!result) 42 | { 43 | return false; 44 | } 45 | UnityEngine.Debug.Log($"== StripAssembliesTo outputDir:{outputFolder}"); 46 | string outputStrippedDir = HybridCLR.Editor.SettingsUtil.GetAssembliesPostIl2CppStripDir(EditorUserBuildSettings.activeBuildTarget); 47 | Directory.CreateDirectory(outputStrippedDir); 48 | foreach (var aotDll in Directory.GetFiles(outputFolder, "*.dll")) 49 | { 50 | string dstFile = $"{outputStrippedDir}/{Path.GetFileName(aotDll)}"; 51 | Debug.Log($"[RunAssemblyStripper] copy aot dll {aotDll} -> {dstFile}"); 52 | File.Copy(aotDll, dstFile, true); 53 | } 54 | return result; 55 | } 56 | 57 | [MethodImpl(MethodImplOptions.NoOptimization)] 58 | private static bool StripAssembliesToProxy(string outputFolder, out string output, out string error, IEnumerable linkXmlFiles, object runInformation) 59 | { 60 | Debug.LogError("== StripAssembliesToProxy =="); 61 | output = ""; 62 | error = ""; 63 | return true; 64 | } 65 | } 66 | #endif 67 | } 68 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/HybridCLRHooks/CopyStrippedAOTAssembliesHook.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cf42c4f20b8a1b94baa04a1a5c6b8beb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/HybridCLRHooks/GetIl2CppFolderHook.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Reflection; 6 | using UnityEngine; 7 | using UnityEditor; 8 | using System.Runtime.CompilerServices; 9 | using MonoHook; 10 | using HybridCLR.Editor.BuildProcessors; 11 | using System.IO; 12 | 13 | namespace HybridCLR.MonoHook 14 | { 15 | #if UNITY_2022 || UNITY_2023_1_OR_NEWER 16 | [InitializeOnLoad] 17 | public class GetIl2CppFolderHook 18 | { 19 | private static MethodHook _hook; 20 | 21 | static GetIl2CppFolderHook() 22 | { 23 | if (_hook == null) 24 | { 25 | Type type = typeof(UnityEditor.EditorApplication).Assembly.GetType("UnityEditorInternal.IL2CPPUtils"); 26 | MethodInfo miTarget = type.GetMethod("GetIl2CppFolder", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, 27 | new Type[] { typeof(bool).MakeByRefType() }, null); 28 | 29 | MethodInfo miReplacement = new StripAssembliesDel(OverrideMethod).Method; 30 | MethodInfo miProxy = new StripAssembliesDel(PlaceHolderMethod).Method; 31 | 32 | _hook = new MethodHook(miTarget, miReplacement, miProxy); 33 | _hook.Install(); 34 | } 35 | } 36 | 37 | private delegate string StripAssembliesDel(out bool isDevelopmentLocation); 38 | 39 | private static string OverrideMethod(out bool isDevelopmentLocation) 40 | { 41 | //Debug.Log("[GetIl2CppFolderHook] OverrideMethod"); 42 | string result = PlaceHolderMethod(out isDevelopmentLocation); 43 | isDevelopmentLocation = false; 44 | return result; 45 | } 46 | 47 | [MethodImpl(MethodImplOptions.NoOptimization)] 48 | private static string PlaceHolderMethod(out bool isDevelopmentLocation) 49 | { 50 | Debug.LogError("[GetIl2CppFolderHook] PlaceHolderMethod"); 51 | isDevelopmentLocation = false; 52 | return null; 53 | } 54 | } 55 | #endif 56 | } 57 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/HybridCLRHooks/GetIl2CppFolderHook.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 96c2bc28db69e1644892219abef3d4b5 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/HybridCLRHooks/PatchScriptingAssembliesJsonHook.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Reflection; 6 | using UnityEngine; 7 | using UnityEditor; 8 | using System.Runtime.CompilerServices; 9 | using MonoHook; 10 | using HybridCLR.Editor.BuildProcessors; 11 | using System.IO; 12 | 13 | namespace HybridCLR.MonoHook 14 | { 15 | #if UNITY_2021_1_OR_NEWER && (UNITY_WEBGL || UNITY_WEIXINMINIGAME) 16 | [InitializeOnLoad] 17 | public class PatchScriptingAssembliesJsonHook 18 | { 19 | private static MethodHook _hook; 20 | 21 | static PatchScriptingAssembliesJsonHook() 22 | { 23 | if (_hook == null) 24 | { 25 | Type type = typeof(UnityEditor.EditorApplication); 26 | MethodInfo miTarget = type.GetMethod("BuildMainWindowTitle", BindingFlags.Static | BindingFlags.NonPublic); 27 | 28 | MethodInfo miReplacement = new Func(BuildMainWindowTitle).Method; 29 | MethodInfo miProxy = new Func(BuildMainWindowTitleProxy).Method; 30 | 31 | _hook = new MethodHook(miTarget, miReplacement, miProxy); 32 | _hook.Install(); 33 | } 34 | } 35 | 36 | private static string BuildMainWindowTitle() 37 | { 38 | var cacheDir = $"{Application.dataPath}/../Library/PlayerDataCache"; 39 | if (Directory.Exists(cacheDir)) 40 | { 41 | foreach (var tempJsonPath in Directory.GetDirectories(cacheDir, "*", SearchOption.TopDirectoryOnly)) 42 | { 43 | string dirName = Path.GetFileName(tempJsonPath); 44 | #if UNITY_WEIXINMINIGAME 45 | if (!dirName.Contains("WeixinMiniGame")) 46 | { 47 | continue; 48 | } 49 | #else 50 | if (!dirName.Contains("WebGL")) 51 | { 52 | continue; 53 | } 54 | #endif 55 | 56 | var patcher = new PatchScriptingAssemblyList(); 57 | patcher.PathScriptingAssembilesFile(tempJsonPath); 58 | } 59 | } 60 | 61 | string newTitle = BuildMainWindowTitleProxy(); 62 | return newTitle; 63 | } 64 | 65 | [MethodImpl(MethodImplOptions.NoOptimization)] 66 | private static string BuildMainWindowTitleProxy() 67 | { 68 | // 为满足MonoHook要求的最小代码长度而特地加入的无用填充代码, 69 | UnityEngine.Debug.Log(12345.ToString()); 70 | return string.Empty; 71 | } 72 | } 73 | #endif 74 | } 75 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/HybridCLRHooks/PatchScriptingAssembliesJsonHook.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cc89a9041ab48ac41975fbd1e00b9b98 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/LDasm.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c561c9729c367e4fbef63f4ec56f268 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/MethodHook.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bd0b8071cf434d6498160259e3829980 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 16b9dc031f67b4fe5ad79c230f75768c 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/Plugins/Utils.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Utils.cpp 3 | // MonoHookUtils_OSX 4 | // 5 | // Created by Misaka-Mikoto on 2022/8/31. 6 | // 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | extern "C"{ 14 | 15 | void* memcpy_jit(void* dst, void* src, int32_t size) 16 | { 17 | pthread_jit_write_protect_np(0); 18 | void* ret = memcpy(dst, src, size); 19 | pthread_jit_write_protect_np(1); 20 | sys_icache_invalidate (dst, size); 21 | return ret; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/Plugins/Utils.cpp.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 56b28b5583a184c669dcb968d175544c 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | : Any 16 | second: 17 | enabled: 0 18 | settings: 19 | Exclude Android: 1 20 | Exclude Editor: 0 21 | Exclude Linux64: 1 22 | Exclude OSXUniversal: 1 23 | Exclude WebGL: 1 24 | Exclude Win: 1 25 | Exclude Win64: 1 26 | Exclude iOS: 1 27 | - first: 28 | Android: Android 29 | second: 30 | enabled: 0 31 | settings: 32 | CPU: ARMv7 33 | - first: 34 | Any: 35 | second: 36 | enabled: 0 37 | settings: {} 38 | - first: 39 | Editor: Editor 40 | second: 41 | enabled: 1 42 | settings: 43 | CPU: AnyCPU 44 | DefaultValueInitialized: true 45 | OS: OSX 46 | - first: 47 | Standalone: Linux64 48 | second: 49 | enabled: 0 50 | settings: 51 | CPU: None 52 | - first: 53 | Standalone: OSXUniversal 54 | second: 55 | enabled: 0 56 | settings: 57 | CPU: ARM64 58 | - first: 59 | Standalone: Win 60 | second: 61 | enabled: 0 62 | settings: 63 | CPU: None 64 | - first: 65 | Standalone: Win64 66 | second: 67 | enabled: 0 68 | settings: 69 | CPU: None 70 | - first: 71 | iPhone: iOS 72 | second: 73 | enabled: 0 74 | settings: 75 | AddToEmbeddedBinaries: false 76 | CPU: AnyCPU 77 | CompileFlags: 78 | FrameworkDependencies: 79 | userData: 80 | assetBundleName: 81 | assetBundleVariant: 82 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/Plugins/build_libMonoHookUtils_OSX.dylib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | clang -shared -undefined dynamic_lookup -o libMonoHookUtils_OSX.dylib Utils.cpp 4 | 5 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/Plugins/build_libMonoHookUtils_OSX.dylib.sh.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69eeb734e262a0a4fbe0887249198f73 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/Plugins/silicon.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7adba4475cf0bdc4fa7995c0d748f480 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/Plugins/silicon/libMonoHookUtils_OSX.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/hybridclr_unity/fca130bbfaa58fab93b09a57ec83704c2aab4d4f/Editor/3rds/UnityHook/Plugins/silicon/libMonoHookUtils_OSX.dylib -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/Plugins/silicon/libMonoHookUtils_OSX.dylib.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e092a73910a69894daea44290d7292f6 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 1 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | : Any 16 | second: 17 | enabled: 0 18 | settings: 19 | Exclude Android: 1 20 | Exclude Editor: 0 21 | Exclude Linux64: 1 22 | Exclude OSXUniversal: 1 23 | Exclude WebGL: 1 24 | Exclude Win: 1 25 | Exclude Win64: 1 26 | Exclude iOS: 1 27 | - first: 28 | Android: Android 29 | second: 30 | enabled: 0 31 | settings: 32 | CPU: ARMv7 33 | - first: 34 | Any: 35 | second: 36 | enabled: 0 37 | settings: {} 38 | - first: 39 | Editor: Editor 40 | second: 41 | enabled: 1 42 | settings: 43 | CPU: ARM64 44 | DefaultValueInitialized: true 45 | OS: OSX 46 | - first: 47 | Standalone: Linux64 48 | second: 49 | enabled: 0 50 | settings: 51 | CPU: None 52 | - first: 53 | Standalone: OSXUniversal 54 | second: 55 | enabled: 0 56 | settings: 57 | CPU: None 58 | - first: 59 | Standalone: Win 60 | second: 61 | enabled: 0 62 | settings: 63 | CPU: x86 64 | - first: 65 | Standalone: Win64 66 | second: 67 | enabled: 0 68 | settings: 69 | CPU: x86_64 70 | - first: 71 | iPhone: iOS 72 | second: 73 | enabled: 0 74 | settings: 75 | AddToEmbeddedBinaries: false 76 | CPU: AnyCPU 77 | CompileFlags: 78 | FrameworkDependencies: 79 | userData: 80 | assetBundleName: 81 | assetBundleVariant: 82 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/Plugins/x86_64.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 31f6a810e38e66f4c832b135770a04bb 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/Plugins/x86_64/libMonoHookUtils_OSX.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/hybridclr_unity/fca130bbfaa58fab93b09a57ec83704c2aab4d4f/Editor/3rds/UnityHook/Plugins/x86_64/libMonoHookUtils_OSX.dylib -------------------------------------------------------------------------------- /Editor/3rds/UnityHook/Plugins/x86_64/libMonoHookUtils_OSX.dylib.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4adb23596911347faa69537b900c9f5e 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | : Any 16 | second: 17 | enabled: 0 18 | settings: 19 | Exclude Android: 1 20 | Exclude Editor: 0 21 | Exclude Linux64: 1 22 | Exclude OSXUniversal: 1 23 | Exclude WebGL: 1 24 | Exclude Win: 1 25 | Exclude Win64: 1 26 | Exclude iOS: 1 27 | - first: 28 | Android: Android 29 | second: 30 | enabled: 0 31 | settings: 32 | CPU: ARMv7 33 | - first: 34 | Any: 35 | second: 36 | enabled: 0 37 | settings: {} 38 | - first: 39 | Editor: Editor 40 | second: 41 | enabled: 1 42 | settings: 43 | CPU: x86_64 44 | DefaultValueInitialized: true 45 | OS: OSX 46 | - first: 47 | Standalone: Linux64 48 | second: 49 | enabled: 0 50 | settings: 51 | CPU: None 52 | - first: 53 | Standalone: OSXUniversal 54 | second: 55 | enabled: 0 56 | settings: 57 | CPU: AnyCPU 58 | - first: 59 | Standalone: Win 60 | second: 61 | enabled: 0 62 | settings: 63 | CPU: None 64 | - first: 65 | Standalone: Win64 66 | second: 67 | enabled: 0 68 | settings: 69 | CPU: None 70 | - first: 71 | iPhone: iOS 72 | second: 73 | enabled: 0 74 | settings: 75 | AddToEmbeddedBinaries: false 76 | CPU: AnyCPU 77 | CompileFlags: 78 | FrameworkDependencies: 79 | userData: 80 | assetBundleName: 81 | assetBundleVariant: 82 | -------------------------------------------------------------------------------- /Editor/ABI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d26c8b77c84f09442a05f2c67e5e09b8 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/ABI/ABIUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace HybridCLR.Editor.ABI 8 | { 9 | public static class ABIUtil 10 | { 11 | public static string GetHybridCLRPlatformMacro(PlatformABI abi) 12 | { 13 | switch(abi) 14 | { 15 | case PlatformABI.Arm64: return "HYBRIDCLR_ABI_ARM_64"; 16 | case PlatformABI.Universal64: return "HYBRIDCLR_ABI_UNIVERSAL_64"; 17 | case PlatformABI.Universal32: return "HYBRIDCLR_ABI_UNIVERSAL_32"; 18 | case PlatformABI.WebGL32: return "HYBRIDCLR_ABI_WEBGL32"; 19 | default: throw new NotSupportedException(); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Editor/ABI/ABIUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: edeb86f4b5b13ca4cb0fe9d87ce509bb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ABI/MethodDesc.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | using System.Threading.Tasks; 9 | 10 | namespace HybridCLR.Editor.ABI 11 | { 12 | public class MethodDesc : IEquatable 13 | { 14 | public string Sig { get; private set; } 15 | 16 | public MethodDef MethodDef { get; set; } 17 | 18 | public ReturnInfo ReturnInfo { get; set; } 19 | 20 | public List ParamInfos { get; set; } 21 | 22 | public void Init() 23 | { 24 | for(int i = 0; i < ParamInfos.Count; i++) 25 | { 26 | ParamInfos[i].Index = i; 27 | } 28 | Sig = CreateCallSigName(); 29 | } 30 | 31 | public void TransfromSigTypes(Func transformer) 32 | { 33 | ReturnInfo.Type = transformer(ReturnInfo.Type, true); 34 | foreach(var paramType in ParamInfos) 35 | { 36 | paramType.Type = transformer(paramType.Type, false); 37 | } 38 | } 39 | 40 | public string CreateCallSigName() 41 | { 42 | var n = new StringBuilder(); 43 | n.Append(ReturnInfo.Type.CreateSigName()); 44 | foreach(var param in ParamInfos) 45 | { 46 | n.Append(param.Type.CreateSigName()); 47 | } 48 | return n.ToString(); 49 | } 50 | 51 | public string CreateInvokeSigName() 52 | { 53 | var n = new StringBuilder(); 54 | n.Append(ReturnInfo.Type.CreateSigName()); 55 | foreach (var param in ParamInfos) 56 | { 57 | n.Append(param.Type.CreateSigName()); 58 | } 59 | return n.ToString(); 60 | } 61 | 62 | public override bool Equals(object obj) 63 | { 64 | return Equals((MethodDesc)obj); 65 | } 66 | 67 | public bool Equals(MethodDesc other) 68 | { 69 | return Sig == other.Sig; 70 | } 71 | 72 | public override int GetHashCode() 73 | { 74 | return Sig.GetHashCode(); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Editor/ABI/MethodDesc.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 28e06667d06f37b4990b16f54f903a35 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ABI/ParamInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace HybridCLR.Editor.ABI 9 | { 10 | 11 | public class ParamInfo 12 | { 13 | public TypeInfo Type { get; set; } 14 | 15 | public int Index { get; set; } 16 | 17 | } 18 | 19 | public class ReturnInfo 20 | { 21 | public TypeInfo Type { get; set; } 22 | 23 | public bool IsVoid => Type.PorType == ParamOrReturnType.VOID; 24 | 25 | public override string ToString() 26 | { 27 | return Type.GetTypeName(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Editor/ABI/ParamInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f2ba16cf4bf82374c814789b6ced3abd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ABI/ParamOrReturnType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace HybridCLR.Editor.ABI 8 | { 9 | public enum ParamOrReturnType 10 | { 11 | VOID, 12 | I1, 13 | U1, 14 | I2, 15 | U2, 16 | I4, 17 | U4, 18 | I8, 19 | U8, 20 | R4, 21 | R8, 22 | I, 23 | U, 24 | TYPEDBYREF, 25 | STRUCT, 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Editor/ABI/ParamOrReturnType.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 80682e47c38a2f04f8af94d356688cf0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ABI/PlatformABI.cs: -------------------------------------------------------------------------------- 1 | namespace HybridCLR.Editor.ABI 2 | { 3 | public enum PlatformABI 4 | { 5 | Universal32, 6 | Universal64, 7 | Arm64, 8 | WebGL32, 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Editor/ABI/PlatformABI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9f06ff0612105b4ea20e0309e759e24 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ABI/TypeCreator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0b1df5760b488fa43a68843c46fda63a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ABI/TypeInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ffafce7f1f0bf614d95b48ca39385377 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ABI/ValueTypeSizeAligmentCalculator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b7af32bdf1cf55c42bfc449820d401cb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/AOT.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4071bf66ac9c544487ae88b5ee9b20a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/AOT/AOTAssemblyMetadataStripper.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using dnlib.DotNet.Writer; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace HybridCLR.Editor.AOT 11 | { 12 | public class AOTAssemblyMetadataStripper 13 | { 14 | public static byte[] Strip(byte[] assemblyBytes) 15 | { 16 | var context = ModuleDef.CreateModuleContext(); 17 | var readerOption = new ModuleCreationOptions(context) 18 | { 19 | Runtime = CLRRuntimeReaderKind.Mono 20 | }; 21 | var mod = ModuleDefMD.Load(assemblyBytes, readerOption); 22 | // remove all resources 23 | mod.Resources.Clear(); 24 | foreach (var type in mod.GetTypes()) 25 | { 26 | if (type.HasGenericParameters) 27 | { 28 | continue; 29 | } 30 | foreach (var method in type.Methods) 31 | { 32 | if (!method.HasBody || method.HasGenericParameters) 33 | { 34 | continue; 35 | } 36 | method.Body = null; 37 | } 38 | } 39 | var writer = new System.IO.MemoryStream(); 40 | var options = new ModuleWriterOptions(mod); 41 | options.MetadataOptions.Flags |= MetadataFlags.PreserveRids; 42 | mod.Write(writer, options); 43 | writer.Flush(); 44 | return writer.ToArray(); 45 | } 46 | 47 | public static void Strip(string originalAssemblyPath, string strippedAssemblyPath) 48 | { 49 | byte[] originDllBytes = System.IO.File.ReadAllBytes(originalAssemblyPath); 50 | byte[] strippedDllBytes = Strip(originDllBytes); 51 | UnityEngine.Debug.Log($"aot dll:{originalAssemblyPath}, length: {originDllBytes.Length} -> {strippedDllBytes.Length}, stripping rate:{(originDllBytes.Length - strippedDllBytes.Length)/(double)originDllBytes.Length} "); 52 | Directory.CreateDirectory(System.IO.Path.GetDirectoryName(strippedAssemblyPath)); 53 | System.IO.File.WriteAllBytes(strippedAssemblyPath, strippedDllBytes); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Editor/AOT/AOTAssemblyMetadataStripper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7e9e6a048682dcb4fab806251411f29f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/AOT/Analyzer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 30bbf4a80a6cf3a43b3f489747d9dd6a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/AOT/ConstraintContext.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using HybridCLR.Editor.Meta; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace HybridCLR.Editor.AOT 10 | { 11 | 12 | public class ConstraintContext 13 | { 14 | public class ImplType 15 | { 16 | public TypeSig BaseType { get; } 17 | 18 | public List Interfaces { get; } 19 | 20 | public bool ValueType { get; } 21 | 22 | private readonly int _hash; 23 | 24 | public ImplType(TypeSig baseType, List interfaces, bool valueType) 25 | { 26 | BaseType = baseType; 27 | Interfaces = interfaces; 28 | ValueType = valueType; 29 | _hash = ComputHash(); 30 | } 31 | 32 | public override bool Equals(object obj) 33 | { 34 | ImplType o = (ImplType)obj; 35 | return MetaUtil.EqualsTypeSig(this.BaseType, o.BaseType) 36 | && MetaUtil.EqualsTypeSigArray(this.Interfaces, o.Interfaces) 37 | && this.ValueType == o.ValueType; 38 | } 39 | 40 | public override int GetHashCode() 41 | { 42 | return _hash; 43 | } 44 | 45 | private int ComputHash() 46 | { 47 | int hash = 0; 48 | if (BaseType != null) 49 | { 50 | hash = HashUtil.CombineHash(hash, TypeEqualityComparer.Instance.GetHashCode(BaseType)); 51 | } 52 | if (Interfaces.Count > 0) 53 | { 54 | hash = HashUtil.CombineHash(hash, HashUtil.ComputHash(Interfaces)); 55 | } 56 | 57 | return hash; 58 | } 59 | } 60 | 61 | public HashSet ImplTypes { get; } = new HashSet(); 62 | 63 | public GenericClass ApplyConstraints(GenericClass gc) 64 | { 65 | return gc; 66 | } 67 | 68 | public GenericMethod ApplyConstraints(GenericMethod gm) 69 | { 70 | return gm; 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Editor/AOT/ConstraintContext.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 812d81a75b690394bbe16ef5f0bcbc46 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/AOT/GenericReferenceWriter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d1243cf04685361478972f93b5ca868a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/BuildProcessors.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f80d2287f01c89642a74b0a60f7a3305 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2019.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2f62ca12f2eb4f2fba8e9cb51279421 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2020Or2021.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 61948fcb1bc40ba47b8c10b0ae801ebb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2022OrNewer.cs: -------------------------------------------------------------------------------- 1 | using HybridCLR.Editor.Installer; 2 | using HybridCLR.Editor.Settings; 3 | using System.IO; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using UnityEditor; 7 | using UnityEditor.Build; 8 | using UnityEditor.Callbacks; 9 | using UnityEngine; 10 | 11 | #if UNITY_2022 && (UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS) 12 | 13 | namespace HybridCLR.Editor.BuildProcessors 14 | { 15 | public static class AddLil2cppSourceCodeToXcodeproj2022OrNewer 16 | { 17 | 18 | [PostProcessBuild] 19 | public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) 20 | { 21 | if (!HybridCLRSettings.Instance.enable) 22 | return; 23 | string pbxprojFile = BuildProcessorUtil.GetXcodeProjectFile(pathToBuiltProject); 24 | RemoveExternalLibil2cppOption(pbxprojFile); 25 | CopyLibil2cppToXcodeProj(pathToBuiltProject); 26 | } 27 | 28 | private static string TryRemoveDunplicateShellScriptSegment(string pbxprojFile, string pbxprojContent) 29 | { 30 | // will appear duplicated Shell Script segment when append to existed xcode project. 31 | // This is unity bug. 32 | // we remove duplicated Shell Script to avoid build error. 33 | string copyFileComment = @"/\* CopyFiles \*/,\s+([A-Z0-9]{24}) /\* ShellScript \*/,\s+([A-Z0-9]{24}) /\* ShellScript \*/,"; 34 | var m = Regex.Match(pbxprojContent, copyFileComment, RegexOptions.Multiline); 35 | if (!m.Success) 36 | { 37 | return pbxprojContent; 38 | } 39 | 40 | if (m.Groups[1].Value != m.Groups[2].Value) 41 | { 42 | throw new BuildFailedException($"find invalid /* ShellScript */ segment"); 43 | } 44 | 45 | int startIndexOfDupShellScript = m.Groups[2].Index; 46 | int endIndexOfDupShellScript = pbxprojContent.IndexOf(",", startIndexOfDupShellScript); 47 | 48 | pbxprojContent = pbxprojContent.Remove(startIndexOfDupShellScript, endIndexOfDupShellScript + 1 - startIndexOfDupShellScript); 49 | Debug.LogWarning($"[AddLil2cppSourceCodeToXcodeproj] remove duplicated '/* ShellScript */' from file '{pbxprojFile}'"); 50 | return pbxprojContent; 51 | } 52 | 53 | private static void RemoveExternalLibil2cppOption(string pbxprojFile) 54 | { 55 | string pbxprojContent = File.ReadAllText(pbxprojFile, Encoding.UTF8); 56 | string removeBuildOption = @"--external-lib-il2-cpp=\""$PROJECT_DIR/Libraries/libil2cpp.a\"""; 57 | if (pbxprojContent.Contains(removeBuildOption)) 58 | { 59 | pbxprojContent = pbxprojContent.Replace(removeBuildOption, ""); 60 | Debug.Log($"[AddLil2cppSourceCodeToXcodeproj] remove il2cpp build option '{removeBuildOption}' from file '{pbxprojFile}'"); 61 | } 62 | else 63 | { 64 | Debug.LogWarning($"[AddLil2cppSourceCodeToXcodeproj] project.pbxproj remove building option:'{removeBuildOption}' fail. This may occur when 'Append' to existing xcode project in building"); 65 | } 66 | 67 | pbxprojContent = TryRemoveDunplicateShellScriptSegment(pbxprojFile, pbxprojContent); 68 | 69 | 70 | File.WriteAllText(pbxprojFile, pbxprojContent, Encoding.UTF8); 71 | } 72 | 73 | private static void CopyLibil2cppToXcodeProj(string pathToBuiltProject) 74 | { 75 | string srcLibil2cppDir = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp"; 76 | string destLibil2cppDir = $"{pathToBuiltProject}/Il2CppOutputProject/IL2CPP/libil2cpp"; 77 | BashUtil.RemoveDir(destLibil2cppDir); 78 | BashUtil.CopyDir(srcLibil2cppDir, destLibil2cppDir, true); 79 | } 80 | } 81 | } 82 | #endif -------------------------------------------------------------------------------- /Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2022OrNewer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a4ce072f7e4a17248a3d9ebfd011356b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2023OrNewer.cs: -------------------------------------------------------------------------------- 1 | using HybridCLR.Editor.Installer; 2 | using HybridCLR.Editor.Settings; 3 | using System.IO; 4 | using System.Text; 5 | using UnityEditor; 6 | using UnityEditor.Build; 7 | using UnityEditor.Callbacks; 8 | using UnityEngine; 9 | 10 | #if UNITY_2023_1_OR_NEWER && (UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS) 11 | 12 | namespace HybridCLR.Editor.BuildProcessors 13 | { 14 | public static class AddLil2cppSourceCodeToXcodeproj2022OrNewer 15 | { 16 | 17 | [PostProcessBuild] 18 | public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) 19 | { 20 | if (!HybridCLRSettings.Instance.enable) 21 | return; 22 | CopyLibil2cppToXcodeProj(pathToBuiltProject); 23 | } 24 | 25 | private static void CopyLibil2cppToXcodeProj(string pathToBuiltProject) 26 | { 27 | string srcLibil2cppDir = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp"; 28 | string destLibil2cppDir = $"{pathToBuiltProject}/Il2CppOutputProject/IL2CPP/libil2cpp"; 29 | BashUtil.RemoveDir(destLibil2cppDir); 30 | BashUtil.CopyDir(srcLibil2cppDir, destLibil2cppDir, true); 31 | } 32 | } 33 | } 34 | #endif -------------------------------------------------------------------------------- /Editor/BuildProcessors/AddLil2cppSourceCodeToXcodeproj2023OrNewer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2fa46135129b046a28014d58fdfd18ca -------------------------------------------------------------------------------- /Editor/BuildProcessors/BuildProcessorUtil.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using UnityEditor.Build; 4 | 5 | namespace HybridCLR.Editor.BuildProcessors 6 | { 7 | 8 | public static class BuildProcessorUtil 9 | { 10 | 11 | public static string GetXcodeProjectFile(string pathToBuiltProject) 12 | { 13 | foreach (string dir in Directory.GetDirectories(pathToBuiltProject, "*.xcodeproj", SearchOption.TopDirectoryOnly)) 14 | { 15 | string pbxprojFile = $"{dir}/project.pbxproj"; 16 | if (File.Exists(pbxprojFile)) 17 | { 18 | return pbxprojFile; 19 | } 20 | } 21 | throw new BuildFailedException($"can't find xxxx.xcodeproj/project.pbxproj in {pathToBuiltProject}"); 22 | } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/BuildProcessorUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c680e56f90f2745298a90803c04f6efc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/CheckSettings.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fb4ba063068b17247b2d0233420aa5f0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/CopyStrippedAOTAssemblies.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f7884710ec2f8e545b3fe9aa05def5a8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/FilterHotFixAssemblies.cs: -------------------------------------------------------------------------------- 1 | using HybridCLR.Editor.Meta; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using UnityEditor; 9 | using UnityEditor.Build; 10 | using UnityEngine; 11 | 12 | namespace HybridCLR.Editor.BuildProcessors 13 | { 14 | /// 15 | /// 将热更新dll从Build过程中过滤,防止打包到主工程中 16 | /// 17 | internal class FilterHotFixAssemblies : IFilterBuildAssemblies 18 | { 19 | public int callbackOrder => 0; 20 | 21 | public string[] OnFilterAssemblies(BuildOptions buildOptions, string[] assemblies) 22 | { 23 | if (!SettingsUtil.Enable) 24 | { 25 | Debug.Log($"[FilterHotFixAssemblies] disabled"); 26 | return assemblies; 27 | } 28 | List allHotUpdateDllNames = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved; 29 | 30 | // 检查是否重复填写 31 | var hotUpdateDllSet = new HashSet(); 32 | foreach(var hotUpdateDll in allHotUpdateDllNames) 33 | { 34 | if (string.IsNullOrWhiteSpace(hotUpdateDll)) 35 | { 36 | throw new BuildFailedException($"hot update assembly name cann't be empty"); 37 | } 38 | if (!hotUpdateDllSet.Add(hotUpdateDll)) 39 | { 40 | throw new BuildFailedException($"hot update assembly:{hotUpdateDll} is duplicated"); 41 | } 42 | } 43 | 44 | var assResolver = MetaUtil.CreateHotUpdateAssemblyResolver(EditorUserBuildSettings.activeBuildTarget, allHotUpdateDllNames); 45 | // 检查是否填写了正确的dll名称 46 | foreach (var hotUpdateDllName in allHotUpdateDllNames) 47 | { 48 | if (assemblies.Select(Path.GetFileNameWithoutExtension).All(ass => ass != hotUpdateDllName) 49 | && string.IsNullOrEmpty(assResolver.ResolveAssembly(hotUpdateDllName, false))) 50 | { 51 | throw new BuildFailedException($"hot update assembly:{hotUpdateDllName} doesn't exist"); 52 | } 53 | } 54 | 55 | // 将热更dll从打包列表中移除 56 | return assemblies.Where(ass => 57 | { 58 | string assName = Path.GetFileNameWithoutExtension(ass); 59 | bool reserved = allHotUpdateDllNames.All(dll => !assName.Equals(dll, StringComparison.Ordinal)); 60 | if (!reserved) 61 | { 62 | Debug.Log($"[FilterHotFixAssemblies] filter assembly:{assName}"); 63 | } 64 | return reserved; 65 | }).ToArray(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/FilterHotFixAssemblies.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9dec2922e3df5464aa047b636eb19e0d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/MsvcStdextWorkaround.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using System; 3 | using UnityEditor.Build; 4 | using UnityEditor.Build.Reporting; 5 | 6 | namespace HybridCLR.Editor.BuildProcessors 7 | { 8 | 9 | public class MsvcStdextWorkaround : IPreprocessBuildWithReport 10 | { 11 | const string kWorkaroundFlag = "/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS"; 12 | 13 | public int callbackOrder => 0; 14 | 15 | public void OnPreprocessBuild(BuildReport report) 16 | { 17 | var clEnv = Environment.GetEnvironmentVariable("_CL_"); 18 | 19 | if (string.IsNullOrEmpty(clEnv)) 20 | { 21 | Environment.SetEnvironmentVariable("_CL_", kWorkaroundFlag); 22 | } 23 | else if (!clEnv.Contains(kWorkaroundFlag)) 24 | { 25 | clEnv += " " + kWorkaroundFlag; 26 | Environment.SetEnvironmentVariable("_CL_", clEnv); 27 | } 28 | } 29 | } 30 | } 31 | 32 | #endif // UNITY_EDITOR 33 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/MsvcStdextWorkaround.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8bff6cadf0b8db54b87ba51b24d080f6 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/PatchScriptingAssemblyList.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9bb6e2908d8948648979c9ff6bb7937d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/ScriptingAssembliesJsonPatcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using UnityEngine; 8 | 9 | namespace HybridCLR.Editor.BuildProcessors 10 | { 11 | public class ScriptingAssembliesJsonPatcher 12 | { 13 | [Serializable] 14 | private class ScriptingAssemblies 15 | { 16 | public List names; 17 | public List types; 18 | } 19 | 20 | private string _file; 21 | ScriptingAssemblies _scriptingAssemblies; 22 | 23 | public void Load(string file) 24 | { 25 | _file = file; 26 | string content = File.ReadAllText(file); 27 | _scriptingAssemblies = JsonUtility.FromJson(content); 28 | } 29 | 30 | public void AddScriptingAssemblies(List assemblies) 31 | { 32 | foreach (string name in assemblies) 33 | { 34 | if (!_scriptingAssemblies.names.Contains(name)) 35 | { 36 | _scriptingAssemblies.names.Add(name); 37 | _scriptingAssemblies.types.Add(16); // user dll type 38 | Debug.Log($"[PatchScriptAssembliesJson] add hotfix assembly:{name} to {_file}"); 39 | } 40 | } 41 | } 42 | 43 | public void Save(string jsonFile) 44 | { 45 | string content = JsonUtility.ToJson(_scriptingAssemblies); 46 | 47 | File.WriteAllText(jsonFile, content); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Editor/BuildProcessors/ScriptingAssembliesJsonPatcher.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4455f7304f8678f408dd6cf21734f55e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Commands.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 92f51c069d2607447ae2f61de80540fb 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Commands/AOTReferenceGeneratorCommand.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2b464872c07f6ba4f9a4e4a02ca9a28c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Commands/CompileDllCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using UnityEditor; 8 | using UnityEditor.Build.Player; 9 | using UnityEngine; 10 | 11 | namespace HybridCLR.Editor.Commands 12 | { 13 | public class CompileDllCommand 14 | { 15 | public static void CompileDll(string buildDir, BuildTarget target, bool developmentBuild) 16 | { 17 | var group = BuildPipeline.GetBuildTargetGroup(target); 18 | 19 | ScriptCompilationSettings scriptCompilationSettings = new ScriptCompilationSettings(); 20 | scriptCompilationSettings.group = group; 21 | scriptCompilationSettings.target = target; 22 | scriptCompilationSettings.options = developmentBuild ? ScriptCompilationOptions.DevelopmentBuild : ScriptCompilationOptions.None; 23 | Directory.CreateDirectory(buildDir); 24 | ScriptCompilationResult scriptCompilationResult = PlayerBuildInterface.CompilePlayerScripts(scriptCompilationSettings, buildDir); 25 | #if UNITY_2022 26 | UnityEditor.EditorUtility.ClearProgressBar(); 27 | #endif 28 | Debug.Log($"compile finish!!! buildDir:{buildDir} target:{target} development:{developmentBuild}"); 29 | } 30 | 31 | public static void CompileDll(BuildTarget target) 32 | { 33 | CompileDll(target, EditorUserBuildSettings.development); 34 | } 35 | 36 | public static void CompileDll(BuildTarget target, bool developmentBuild) 37 | { 38 | CompileDll(SettingsUtil.GetHotUpdateDllsOutputDirByTarget(target), target, developmentBuild); 39 | } 40 | 41 | [MenuItem("HybridCLR/CompileDll/ActiveBuildTarget", priority = 100)] 42 | public static void CompileDllActiveBuildTarget() 43 | { 44 | CompileDll(EditorUserBuildSettings.activeBuildTarget, EditorUserBuildSettings.development); 45 | } 46 | 47 | [MenuItem("HybridCLR/CompileDll/ActiveBuildTarget_Release", priority = 102)] 48 | public static void CompileDllActiveBuildTargetRelease() 49 | { 50 | CompileDll(EditorUserBuildSettings.activeBuildTarget, false); 51 | } 52 | 53 | [MenuItem("HybridCLR/CompileDll/ActiveBuildTarget_Development", priority = 104)] 54 | public static void CompileDllActiveBuildTargetDevelopment() 55 | { 56 | CompileDll(EditorUserBuildSettings.activeBuildTarget, true); 57 | } 58 | 59 | [MenuItem("HybridCLR/CompileDll/Win32", priority = 200)] 60 | public static void CompileDllWin32() 61 | { 62 | CompileDll(BuildTarget.StandaloneWindows); 63 | } 64 | 65 | [MenuItem("HybridCLR/CompileDll/Win64", priority = 201)] 66 | public static void CompileDllWin64() 67 | { 68 | CompileDll(BuildTarget.StandaloneWindows64); 69 | } 70 | 71 | [MenuItem("HybridCLR/CompileDll/MacOS", priority = 202)] 72 | public static void CompileDllMacOS() 73 | { 74 | CompileDll(BuildTarget.StandaloneOSX); 75 | } 76 | 77 | [MenuItem("HybridCLR/CompileDll/Linux", priority = 203)] 78 | public static void CompileDllLinux() 79 | { 80 | CompileDll(BuildTarget.StandaloneLinux64); 81 | } 82 | 83 | [MenuItem("HybridCLR/CompileDll/Android", priority = 210)] 84 | public static void CompileDllAndroid() 85 | { 86 | CompileDll(BuildTarget.Android); 87 | } 88 | 89 | [MenuItem("HybridCLR/CompileDll/IOS", priority = 220)] 90 | public static void CompileDllIOS() 91 | { 92 | CompileDll(BuildTarget.iOS); 93 | } 94 | 95 | [MenuItem("HybridCLR/CompileDll/WebGL", priority = 230)] 96 | public static void CompileDllWebGL() 97 | { 98 | CompileDll(BuildTarget.WebGL); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Editor/Commands/CompileDllCommand.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf11b6c8bbc5afd4cb4a11921e5bd81e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Commands/Il2CppDefGeneratorCommand.cs: -------------------------------------------------------------------------------- 1 | using HybridCLR.Editor.Link; 2 | using HybridCLR.Editor.Settings; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Reflection; 7 | using UnityEditor; 8 | using UnityEngine; 9 | 10 | namespace HybridCLR.Editor.Commands 11 | { 12 | 13 | public static class Il2CppDefGeneratorCommand 14 | { 15 | 16 | [MenuItem("HybridCLR/Generate/Il2CppDef", priority = 104)] 17 | public static void GenerateIl2CppDef() 18 | { 19 | var options = new Il2CppDef.Il2CppDefGenerator.Options() 20 | { 21 | UnityVersion = Application.unityVersion, 22 | HotUpdateAssemblies = SettingsUtil.HotUpdateAssemblyNamesIncludePreserved, 23 | UnityVersionTemplateFile = $"{SettingsUtil.TemplatePathInPackage}/UnityVersion.h.tpl", 24 | UnityVersionOutputFile = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/generated/UnityVersion.h", 25 | AssemblyManifestTemplateFile = $"{SettingsUtil.TemplatePathInPackage}/AssemblyManifest.cpp.tpl", 26 | AssemblyManifestOutputFile = $"{SettingsUtil.LocalIl2CppDir}/libil2cpp/hybridclr/generated/AssemblyManifest.cpp", 27 | }; 28 | 29 | var g = new Il2CppDef.Il2CppDefGenerator(options); 30 | g.Generate(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Editor/Commands/Il2CppDefGeneratorCommand.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5165a065d05497c43a2fff885f31ed07 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Commands/LinkGeneratorCommand.cs: -------------------------------------------------------------------------------- 1 | using HybridCLR.Editor.Link; 2 | using HybridCLR.Editor.Meta; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Reflection; 6 | using UnityEditor; 7 | using UnityEngine; 8 | 9 | namespace HybridCLR.Editor.Commands 10 | { 11 | using Analyzer = HybridCLR.Editor.Link.Analyzer; 12 | 13 | public static class LinkGeneratorCommand 14 | { 15 | 16 | [MenuItem("HybridCLR/Generate/LinkXml", priority = 100)] 17 | public static void GenerateLinkXml() 18 | { 19 | BuildTarget target = EditorUserBuildSettings.activeBuildTarget; 20 | CompileDllCommand.CompileDll(target); 21 | GenerateLinkXml(target); 22 | } 23 | 24 | public static void GenerateLinkXml(BuildTarget target) 25 | { 26 | var ls = SettingsUtil.HybridCLRSettings; 27 | 28 | List hotfixAssemblies = SettingsUtil.HotUpdateAssemblyNamesExcludePreserved; 29 | 30 | var analyzer = new Analyzer(MetaUtil.CreateHotUpdateAndAOTAssemblyResolver(target, hotfixAssemblies)); 31 | var refTypes = analyzer.CollectRefs(hotfixAssemblies); 32 | 33 | Debug.Log($"[LinkGeneratorCommand] hotfix assembly count:{hotfixAssemblies.Count}, ref type count:{refTypes.Count} output:{Application.dataPath}/{ls.outputLinkFile}"); 34 | var linkXmlWriter = new LinkXmlWriter(); 35 | linkXmlWriter.Write($"{Application.dataPath}/{ls.outputLinkFile}", refTypes); 36 | AssetDatabase.Refresh(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Editor/Commands/LinkGeneratorCommand.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f5b96abdbc4c424eb1bc3bc34b3a1a4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Commands/MethodBridgeGeneratorCommand.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 46bc62d5236f5e941850776c435a9560 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Commands/PrebuildCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using UnityEditor; 7 | using UnityEditor.Build; 8 | 9 | namespace HybridCLR.Editor.Commands 10 | { 11 | public static class PrebuildCommand 12 | { 13 | /// 14 | /// 按照必要的顺序,执行所有生成操作,适合打包前操作 15 | /// 16 | [MenuItem("HybridCLR/Generate/All", priority = 200)] 17 | public static void GenerateAll() 18 | { 19 | var installer = new Installer.InstallerController(); 20 | if (!installer.HasInstalledHybridCLR()) 21 | { 22 | throw new BuildFailedException($"You have not initialized HybridCLR, please install it via menu 'HybridCLR/Installer'"); 23 | } 24 | BuildTarget target = EditorUserBuildSettings.activeBuildTarget; 25 | CompileDllCommand.CompileDll(target, EditorUserBuildSettings.development); 26 | Il2CppDefGeneratorCommand.GenerateIl2CppDef(); 27 | 28 | // 这几个生成依赖HotUpdateDlls 29 | LinkGeneratorCommand.GenerateLinkXml(target); 30 | 31 | // 生成裁剪后的aot dll 32 | StripAOTDllCommand.GenerateStripedAOTDlls(target); 33 | 34 | // 桥接函数生成依赖于AOT dll,必须保证已经build过,生成AOT dll 35 | MethodBridgeGeneratorCommand.GenerateMethodBridgeAndReversePInvokeWrapper(target); 36 | AOTReferenceGeneratorCommand.GenerateAOTGenericReference(target); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Editor/Commands/PrebuildCommand.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c20f09bfbe3f32143aae872d3813d9e9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Commands/StripAOTDllCommand.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 21fb0a02f23185141a4a3df67fe61789 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/HashUtil.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace HybridCLR.Editor 9 | { 10 | public static class HashUtil 11 | { 12 | public static int CombineHash(int hash1, int hash2) 13 | { 14 | return hash1 * 1566083941 + hash2; 15 | } 16 | 17 | public static int ComputHash(List sigs) 18 | { 19 | int hash = 135781321; 20 | TypeEqualityComparer tc = TypeEqualityComparer.Instance; 21 | foreach (var sig in sigs) 22 | { 23 | hash = hash * 1566083941 + tc.GetHashCode(sig); 24 | } 25 | return hash; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Editor/HashUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5d4ae4a5c0bba49469c525887d812717 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/HotUpdate.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e60a8b17b0e23a94a8ae875716208030 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/HotUpdate/MissingMetadataChecker.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bdd260aca2a6deb44b20210f01faa86b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/HybridCLR.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "HybridCLR.Editor", 3 | "rootNamespace": "", 4 | "references": [ 5 | "HybridCLR.Runtime" 6 | ], 7 | "includePlatforms": [ 8 | "Editor" 9 | ], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": true, 12 | "overrideReferences": false, 13 | "precompiledReferences": [], 14 | "autoReferenced": true, 15 | "defineConstraints": [], 16 | "versionDefines": [], 17 | "noEngineReferences": false 18 | } -------------------------------------------------------------------------------- /Editor/HybridCLR.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2373f786d14518f44b0f475db77ba4de 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/Il2CppDef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: da46bc9f1a4dece41a5c193166be9a30 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Il2CppDef/Il2CppDefGenerator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 590419ee7e82ac24cbac9b8a48891fe0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Installer.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a2c8f84b297371d4cbcd5ca655bf360d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Installer/BashUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 960a0257c3a17f64b810193308ce1558 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Installer/InstallerController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 44c8627d126b30d4e9560b1f738264ca 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Installer/InstallerWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 959fbf0bb06629542969354505189240 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Link.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5186a137e0258034cb3832bdf6b16a70 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Link/Analyzer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using dnlib.DotNet; 8 | using HybridCLR.Editor.Meta; 9 | using UnityEditor; 10 | using UnityEngine; 11 | using IAssemblyResolver = HybridCLR.Editor.Meta.IAssemblyResolver; 12 | 13 | namespace HybridCLR.Editor.Link 14 | { 15 | public class Analyzer 16 | { 17 | private readonly IAssemblyResolver _resolver; 18 | 19 | public Analyzer(IAssemblyResolver resolver) 20 | { 21 | _resolver = resolver; 22 | } 23 | 24 | public HashSet CollectRefs(List rootAssemblies) 25 | { 26 | var assCollector = new AssemblyCache(_resolver); 27 | var rootAssemblyNames = new HashSet(rootAssemblies); 28 | 29 | var typeRefs = new HashSet(TypeEqualityComparer.Instance); 30 | foreach (var rootAss in rootAssemblies) 31 | { 32 | var dnAss = assCollector.LoadModule(rootAss, false); 33 | foreach (var type in dnAss.GetTypeRefs()) 34 | { 35 | if (type.DefinitionAssembly == null) 36 | { 37 | Debug.LogWarning($"assembly:{dnAss.Name} TypeRef {type.FullName} has no DefinitionAssembly"); 38 | continue; 39 | } 40 | if (!rootAssemblyNames.Contains(type.DefinitionAssembly.Name.ToString())) 41 | { 42 | typeRefs.Add(type); 43 | } 44 | } 45 | } 46 | return typeRefs; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Editor/Link/Analyzer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fd3dd4871efd10e46947cb61c13797fd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Link/LinkXmlWriter.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace HybridCLR.Editor.Link 11 | { 12 | public class LinkXmlWriter 13 | { 14 | public void Write(string outputLinkXmlFile, HashSet refTypes) 15 | { 16 | string parentDir = Directory.GetParent(outputLinkXmlFile).FullName; 17 | Directory.CreateDirectory(parentDir); 18 | var writer = System.Xml.XmlWriter.Create(outputLinkXmlFile, 19 | new System.Xml.XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true}); 20 | 21 | writer.WriteStartDocument(); 22 | writer.WriteStartElement("linker"); 23 | 24 | var typesByAssembly = refTypes.GroupBy(t => t.DefinitionAssembly.Name.String).ToList(); 25 | typesByAssembly.Sort((a, b) => String.Compare(a.Key, b.Key, StringComparison.Ordinal)); 26 | 27 | foreach(var assembly in typesByAssembly) 28 | { 29 | writer.WriteStartElement("assembly"); 30 | writer.WriteAttributeString("fullname", assembly.Key); 31 | List assTypeNames = assembly.Select(t => t.FullName).ToList(); 32 | assTypeNames.Sort(string.CompareOrdinal); 33 | foreach(var typeName in assTypeNames) 34 | { 35 | #if UNITY_2023_1_OR_NEWER 36 | if (typeName == "UnityEngine.Debug") 37 | { 38 | continue; 39 | } 40 | #endif 41 | writer.WriteStartElement("type"); 42 | writer.WriteAttributeString("fullname", typeName); 43 | writer.WriteAttributeString("preserve", "all"); 44 | writer.WriteEndElement(); 45 | } 46 | writer.WriteEndElement(); 47 | } 48 | writer.WriteEndElement(); 49 | writer.WriteEndDocument(); 50 | writer.Close(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Editor/Link/LinkXmlWriter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d5cc4ae4adc319b4bb1e115567d7613e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3787c7d8b775c754aa4ae06bf78e96ea 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Meta/AssemblyCache.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using UnityEngine; 9 | 10 | namespace HybridCLR.Editor.Meta 11 | { 12 | public class AssemblyCache : AssemblyCacheBase 13 | { 14 | 15 | public AssemblyCache(IAssemblyResolver assemblyResolver) : base(assemblyResolver) 16 | { 17 | 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Editor/Meta/AssemblyCache.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa4650e79a52228488aa85e0690ca52c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/AssemblyCacheBase.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace HybridCLR.Editor.Meta 10 | { 11 | public abstract class AssemblyCacheBase 12 | { 13 | private readonly IAssemblyResolver _assemblyPathResolver; 14 | private readonly ModuleContext _modCtx; 15 | private readonly AssemblyResolver _asmResolver; 16 | private bool _loadedNetstandard; 17 | 18 | 19 | public ModuleContext ModCtx => _modCtx; 20 | 21 | public Dictionary LoadedModules { get; } = new Dictionary(); 22 | 23 | private readonly List _loadedModulesIncludeNetstandard = new List(); 24 | 25 | protected AssemblyCacheBase(IAssemblyResolver assemblyResolver) 26 | { 27 | _assemblyPathResolver = assemblyResolver; 28 | _modCtx = ModuleDef.CreateModuleContext(); 29 | _asmResolver = (AssemblyResolver)_modCtx.AssemblyResolver; 30 | _asmResolver.EnableTypeDefCache = true; 31 | _asmResolver.UseGAC = false; 32 | } 33 | 34 | 35 | public ModuleDefMD TryLoadModule(string moduleName, bool loadReferenceAssemblies = true) 36 | { 37 | string dllPath = _assemblyPathResolver.ResolveAssembly(moduleName, false); 38 | if (string.IsNullOrEmpty(dllPath)) 39 | { 40 | return null; 41 | } 42 | return LoadModule(moduleName, loadReferenceAssemblies); 43 | } 44 | 45 | public ModuleDefMD LoadModule(string moduleName, bool loadReferenceAssemblies = true) 46 | { 47 | // Debug.Log($"load module:{moduleName}"); 48 | if (LoadedModules.TryGetValue(moduleName, out var mod)) 49 | { 50 | return mod; 51 | } 52 | if (moduleName == "netstandard") 53 | { 54 | if (!_loadedNetstandard) 55 | { 56 | LoadNetStandard(); 57 | } 58 | return null; 59 | } 60 | mod = DoLoadModule(_assemblyPathResolver.ResolveAssembly(moduleName, true)); 61 | LoadedModules.Add(moduleName, mod); 62 | 63 | if (loadReferenceAssemblies) 64 | { 65 | foreach (var refAsm in mod.GetAssemblyRefs()) 66 | { 67 | LoadModule(refAsm.Name); 68 | } 69 | } 70 | 71 | return mod; 72 | } 73 | 74 | private void LoadNetStandard() 75 | { 76 | string netstandardDllPath = _assemblyPathResolver.ResolveAssembly("netstandard", false); 77 | if (!string.IsNullOrEmpty(netstandardDllPath)) 78 | { 79 | DoLoadModule(netstandardDllPath); 80 | } 81 | else 82 | { 83 | DoLoadModule(MetaUtil.ResolveNetStandardAssemblyPath("netstandard2.0")); 84 | DoLoadModule(MetaUtil.ResolveNetStandardAssemblyPath("netstandard2.1")); 85 | } 86 | _loadedNetstandard = true; 87 | } 88 | 89 | private ModuleDefMD DoLoadModule(string dllPath) 90 | { 91 | //Debug.Log($"do load module:{dllPath}"); 92 | ModuleDefMD mod = ModuleDefMD.Load(File.ReadAllBytes(dllPath), _modCtx); 93 | mod.EnableTypeDefFindCache = true; 94 | _asmResolver.AddToCache(mod); 95 | _loadedModulesIncludeNetstandard.Add(mod); 96 | return mod; 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Editor/Meta/AssemblyCacheBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3b01fa99119e72141bfee5628c0ffce1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/AssemblyReferenceDeepCollector.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using UnityEngine; 9 | 10 | namespace HybridCLR.Editor.Meta 11 | { 12 | public class AssemblyReferenceDeepCollector : AssemblyCacheBase 13 | { 14 | private readonly List _rootAssemblies; 15 | 16 | public IReadOnlyList GetRootAssemblyNames() 17 | { 18 | return _rootAssemblies; 19 | } 20 | 21 | public List GetLoadedModulesExcludeRootAssemblies() 22 | { 23 | return LoadedModules.Where(e => !_rootAssemblies.Contains(e.Key)).Select(e => e.Value).ToList(); 24 | } 25 | 26 | public List GetLoadedModules() 27 | { 28 | return LoadedModules.Select(e => e.Value).ToList(); 29 | } 30 | 31 | public List GetLoadedModulesOfRootAssemblies() 32 | { 33 | return _rootAssemblies.Select(ass => LoadedModules[ass]).ToList(); 34 | } 35 | 36 | public AssemblyReferenceDeepCollector(IAssemblyResolver assemblyResolver, List rootAssemblies) : base(assemblyResolver) 37 | { 38 | _rootAssemblies = rootAssemblies; 39 | LoadAllAssembiles(); 40 | } 41 | 42 | private void LoadAllAssembiles() 43 | { 44 | foreach (var asm in _rootAssemblies) 45 | { 46 | LoadModule(asm); 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Editor/Meta/AssemblyReferenceDeepCollector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0342c7d8575fdea49896260c77285286 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/AssemblyResolverBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace HybridCLR.Editor.Meta 8 | { 9 | public abstract class AssemblyResolverBase : IAssemblyResolver 10 | { 11 | public string ResolveAssembly(string assemblyName, bool throwExIfNotFind) 12 | { 13 | if (TryResolveAssembly(assemblyName, out string assemblyPath)) 14 | { 15 | return assemblyPath; 16 | } 17 | if (throwExIfNotFind) 18 | { 19 | if (SettingsUtil.HotUpdateAssemblyNamesIncludePreserved.Contains(assemblyName)) 20 | { 21 | throw new Exception($"resolve Hot update dll:{assemblyName} failed! Please make sure that this hot update dll exists or the search path is configured in the external hot update path."); 22 | } 23 | else 24 | { 25 | throw new Exception($"resolve AOT dll:{assemblyName} failed! Please make sure that the AOT project has referenced the dll and generated the trimmed AOT dll correctly."); 26 | } 27 | } 28 | return null; 29 | } 30 | 31 | protected abstract bool TryResolveAssembly(string assemblyName, out string assemblyPath); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Editor/Meta/AssemblyResolverBase.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f8d48774b790364cbd36f1f68fd6614 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/AssemblySorter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace HybridCLR.Editor.Meta 8 | { 9 | 10 | public class AssemblySorter 11 | { 12 | class Node 13 | { 14 | public string Name; 15 | public List Dependencies = new List(); 16 | 17 | public Node(string name) 18 | { 19 | Name = name; 20 | } 21 | } 22 | 23 | class TopologicalSorter 24 | { 25 | 26 | public static List Sort(List nodes) 27 | { 28 | List sorted = new List(); 29 | HashSet visited = new HashSet(); 30 | HashSet tempMarks = new HashSet(); 31 | 32 | foreach (var node in nodes) 33 | { 34 | if (!visited.Contains(node)) 35 | { 36 | Visit(node, visited, tempMarks, sorted); 37 | } 38 | } 39 | return sorted; 40 | } 41 | 42 | private static void Visit(Node node, HashSet visited, HashSet tempMarks, List sorted) 43 | { 44 | if (tempMarks.Contains(node)) 45 | { 46 | throw new Exception("Detected cyclic dependency!"); 47 | } 48 | 49 | if (!visited.Contains(node)) 50 | { 51 | tempMarks.Add(node); 52 | foreach (var dependency in node.Dependencies) 53 | { 54 | Visit(dependency, visited, tempMarks, sorted); 55 | } 56 | tempMarks.Remove(node); 57 | visited.Add(node); 58 | sorted.Add(node); 59 | } 60 | } 61 | } 62 | 63 | private static List SortAssemblyByReferenceOrder(IEnumerable assemblies, Dictionary> refs) 64 | { 65 | var nodes = new List(); 66 | var nodeMap = new Dictionary(); 67 | foreach (var assembly in assemblies) 68 | { 69 | var node = new Node(assembly); 70 | nodes.Add(node); 71 | nodeMap.Add(assembly, node); 72 | } 73 | foreach (var assembly in assemblies) 74 | { 75 | var node = nodeMap[assembly]; 76 | foreach (var refAssembly in refs[assembly]) 77 | { 78 | node.Dependencies.Add(nodeMap[refAssembly]); 79 | } 80 | } 81 | var sortedNodes = TopologicalSorter.Sort(nodes); 82 | return sortedNodes.Select(node => node.Name).ToList(); 83 | } 84 | 85 | public static List SortAssemblyByReferenceOrder(IEnumerable assemblies, IAssemblyResolver assemblyResolver) 86 | { 87 | var assCache = new AssemblyCache(assemblyResolver); 88 | var assRefAssemblies = new Dictionary>(); 89 | foreach (var assName in assemblies) 90 | { 91 | var refAssemblies = new HashSet(); 92 | var mod = assCache.LoadModule(assName, false); 93 | foreach (var refAss in mod.GetAssemblyRefs()) 94 | { 95 | if (assemblies.Contains(refAss.Name.ToString())) 96 | { 97 | refAssemblies.Add(refAss.Name.ToString()); 98 | } 99 | } 100 | assRefAssemblies.Add(assName, refAssemblies); 101 | } 102 | return SortAssemblyByReferenceOrder(assemblies, assRefAssemblies); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Editor/Meta/AssemblySorter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9b8eb45398fa344daa8c6e9b9fbf291 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/CombinedAssemblyResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace HybridCLR.Editor.Meta 8 | { 9 | public class CombinedAssemblyResolver : AssemblyResolverBase 10 | { 11 | private readonly IAssemblyResolver[] _resolvers; 12 | 13 | public CombinedAssemblyResolver(params IAssemblyResolver[] resolvers) 14 | { 15 | _resolvers = resolvers; 16 | } 17 | 18 | protected override bool TryResolveAssembly(string assemblyName, out string assemblyPath) 19 | { 20 | foreach(var resolver in _resolvers) 21 | { 22 | var assembly = resolver.ResolveAssembly(assemblyName, false); 23 | if (assembly != null) 24 | { 25 | assemblyPath = assembly; 26 | return true; 27 | } 28 | } 29 | assemblyPath = null; 30 | return false; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Editor/Meta/CombinedAssemblyResolver.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 89b83906438c52d4b9af4aaef055f177 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/FixedSetAssemblyResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using UnityEngine; 8 | 9 | namespace HybridCLR.Editor.Meta 10 | { 11 | public class FixedSetAssemblyResolver : AssemblyResolverBase 12 | { 13 | private readonly string _rootDir; 14 | private readonly HashSet _fileNames; 15 | 16 | public FixedSetAssemblyResolver(string rootDir, IEnumerable fileNameNotExts) 17 | { 18 | _rootDir = rootDir; 19 | _fileNames = new HashSet(fileNameNotExts); 20 | } 21 | 22 | protected override bool TryResolveAssembly(string assemblyName, out string assemblyPath) 23 | { 24 | if (_fileNames.Contains(assemblyName)) 25 | { 26 | assemblyPath = $"{_rootDir}/{assemblyName}.dll"; 27 | if (File.Exists(assemblyPath)) 28 | { 29 | Debug.Log($"[FixedSetAssemblyResolver] resolve:{assemblyName} path:{assemblyPath}"); 30 | return true; 31 | } 32 | assemblyPath = $"{_rootDir}/{assemblyName}.dll.bytes"; 33 | if (File.Exists(assemblyPath)) 34 | { 35 | Debug.Log($"[FixedSetAssemblyResolver] resolve:{assemblyName} path:{assemblyPath}"); 36 | return true; 37 | } 38 | } 39 | assemblyPath = null; 40 | return false; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Editor/Meta/FixedSetAssemblyResolver.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f135accd10f42c64b9735c3aa8cb1e77 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/GenericArgumentContext.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 07595a9b5b2f54c44a67022ae3e077d4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/GenericClass.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEngine; 5 | 6 | namespace HybridCLR.Editor.Meta 7 | { 8 | public class GenericClass 9 | { 10 | public TypeDef Type { get; } 11 | 12 | public List KlassInst { get; } 13 | 14 | private readonly int _hashCode; 15 | 16 | public GenericClass(TypeDef type, List classInst) 17 | { 18 | Type = type; 19 | KlassInst = classInst; 20 | _hashCode = ComputHashCode(); 21 | } 22 | 23 | public GenericClass ToGenericShare() 24 | { 25 | return new GenericClass(Type, MetaUtil.ToShareTypeSigs(Type.Module.CorLibTypes, KlassInst)); 26 | } 27 | 28 | public override bool Equals(object obj) 29 | { 30 | if (obj is GenericClass gc) 31 | { 32 | return Type == gc.Type && MetaUtil.EqualsTypeSigArray(KlassInst, gc.KlassInst); 33 | } 34 | return false; 35 | } 36 | 37 | public override int GetHashCode() 38 | { 39 | return _hashCode; 40 | } 41 | 42 | private int ComputHashCode() 43 | { 44 | int hash = TypeEqualityComparer.Instance.GetHashCode(Type); 45 | if (KlassInst != null) 46 | { 47 | hash = HashUtil.CombineHash(hash, HashUtil.ComputHash(KlassInst)); 48 | } 49 | return hash; 50 | } 51 | 52 | public TypeSig ToTypeSig() 53 | { 54 | return new GenericInstSig(this.Type.ToTypeSig().ToClassOrValueTypeSig(), this.KlassInst); 55 | } 56 | 57 | public static GenericClass ResolveClass(TypeSpec type, GenericArgumentContext ctx) 58 | { 59 | var sig = type.TypeSig.ToGenericInstSig(); 60 | if (sig == null) 61 | { 62 | return null; 63 | } 64 | TypeDef def = type.ResolveTypeDef(); 65 | if (def == null) 66 | { 67 | Debug.LogWarning($"type:{type} ResolveTypeDef() == null"); 68 | return null; 69 | } 70 | var klassInst = ctx != null ? sig.GenericArguments.Select(ga => MetaUtil.Inflate(ga, ctx)).ToList() : sig.GenericArguments.ToList(); 71 | return new GenericClass(def, klassInst); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Editor/Meta/GenericClass.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c95ff173013909548bd9e2008812f9ff 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/GenericMethod.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 88ecf3d52ec393b4cac142518944e487 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/IAssemblyResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace HybridCLR.Editor.Meta 8 | { 9 | public interface IAssemblyResolver 10 | { 11 | string ResolveAssembly(string assemblyName, bool throwExIfNotFind); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Editor/Meta/IAssemblyResolver.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f962a018018dbb945a19f82d2e098686 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/MetaUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f3dbfe2e8b6a92742b18e287c5d281dd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/MethodReferenceAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using HybridCLR.Editor.ABI; 3 | using System; 4 | using System.Collections.Concurrent; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace HybridCLR.Editor.Meta 11 | { 12 | public class MethodReferenceAnalyzer 13 | { 14 | private readonly Action, List, GenericMethod> _onNewMethod; 15 | 16 | private readonly ConcurrentDictionary> _methodEffectInsts = new ConcurrentDictionary>(); 17 | 18 | public MethodReferenceAnalyzer(Action, List, GenericMethod> onNewMethod) 19 | { 20 | _onNewMethod = onNewMethod; 21 | } 22 | 23 | public void WalkMethod(MethodDef method, List klassGenericInst, List methodGenericInst) 24 | { 25 | var ctx = new GenericArgumentContext(klassGenericInst, methodGenericInst); 26 | 27 | if (_methodEffectInsts.TryGetValue(method, out var effectInsts)) 28 | { 29 | foreach (var met in effectInsts) 30 | { 31 | var resolveMet = GenericMethod.ResolveMethod(met, ctx)?.ToGenericShare(); 32 | _onNewMethod(method, klassGenericInst, methodGenericInst, resolveMet); 33 | } 34 | return; 35 | } 36 | 37 | var body = method.Body; 38 | if (body == null || !body.HasInstructions) 39 | { 40 | return; 41 | } 42 | 43 | effectInsts = new List(); 44 | foreach (var inst in body.Instructions) 45 | { 46 | if (inst.Operand == null) 47 | { 48 | continue; 49 | } 50 | switch (inst.Operand) 51 | { 52 | case IMethod met: 53 | { 54 | if (!met.IsMethod) 55 | { 56 | continue; 57 | } 58 | var resolveMet = GenericMethod.ResolveMethod(met, ctx)?.ToGenericShare(); 59 | if (resolveMet == null) 60 | { 61 | continue; 62 | } 63 | effectInsts.Add(met); 64 | _onNewMethod(method, klassGenericInst, methodGenericInst, resolveMet); 65 | break; 66 | } 67 | case ITokenOperand token: 68 | { 69 | //GenericParamContext paramContext = method.HasGenericParameters || method.DeclaringType.HasGenericParameters ? 70 | // new GenericParamContext(method.DeclaringType, method) : default; 71 | //method.Module.ResolveToken(token.MDToken, paramContext); 72 | break; 73 | } 74 | } 75 | } 76 | _methodEffectInsts.TryAdd(method, effectInsts); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Editor/Meta/MethodReferenceAnalyzer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1c644b0c018fb87498d69c3202439d21 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Meta/PathAssemblyResolver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using UnityEngine; 8 | 9 | namespace HybridCLR.Editor.Meta 10 | { 11 | public class PathAssemblyResolver : AssemblyResolverBase 12 | { 13 | private readonly string[] _searchPaths; 14 | public PathAssemblyResolver(params string[] searchPaths) 15 | { 16 | _searchPaths = searchPaths; 17 | } 18 | 19 | protected override bool TryResolveAssembly(string assemblyName, out string assemblyPath) 20 | { 21 | foreach(var path in _searchPaths) 22 | { 23 | assemblyPath = Path.Combine(path, $"{assemblyName}.dll"); 24 | if (File.Exists(assemblyPath)) 25 | { 26 | Debug.Log($"resolve {assemblyName} at {assemblyPath}"); 27 | return true; 28 | } 29 | assemblyPath = Path.Combine(path, $"{assemblyName}.dll.bytes"); 30 | if (File.Exists(assemblyPath)) 31 | { 32 | Debug.Log($"resolve {assemblyName} at {assemblyPath}"); 33 | return true; 34 | } 35 | } 36 | assemblyPath = null; 37 | return false; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Editor/Meta/PathAssemblyResolver.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 121d574bf01969444aa6619a8f6dbb4c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/MethodBridge.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0c2444f09010bce41a52d951b7100c49 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/MethodBridge/Analyzer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ee1ec106190e514489c7ba32bc7bc2e7 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/MethodBridge/CallNativeMethodSignatureInfo.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | 3 | namespace HybridCLR.Editor.MethodBridge 4 | { 5 | public class CallNativeMethodSignatureInfo 6 | { 7 | public MethodSig MethodSig { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Editor/MethodBridge/CallNativeMethodSignatureInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2e4ca0a49975a84a8a72dbc70ec7795 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/MethodBridge/CalliAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using HybridCLR.Editor.Meta; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using UnityEngine; 9 | 10 | namespace HybridCLR.Editor.MethodBridge 11 | { 12 | 13 | public class CalliAnalyzer 14 | { 15 | private readonly List _rootModules = new List(); 16 | 17 | private readonly List _calliMethodSignatures = new List(); 18 | 19 | public List CalliMethodSignatures => _calliMethodSignatures; 20 | 21 | public CalliAnalyzer(AssemblyCache cache, List assemblyNames) 22 | { 23 | foreach (var assemblyName in assemblyNames) 24 | { 25 | _rootModules.Add(cache.LoadModule(assemblyName)); 26 | } 27 | } 28 | 29 | private void CollectCalli() 30 | { 31 | foreach (var mod in _rootModules) 32 | { 33 | Debug.Log($"ass:{mod.FullName} methodcount:{mod.Metadata.TablesStream.MethodTable.Rows}"); 34 | for (uint rid = 1, n = mod.Metadata.TablesStream.MethodTable.Rows; rid <= n; rid++) 35 | { 36 | var method = mod.ResolveMethod(rid); 37 | //Debug.Log($"method:{method}"); 38 | if (!method.HasBody) 39 | { 40 | continue; 41 | } 42 | 43 | foreach (var il in method.Body.Instructions) 44 | { 45 | if (il.OpCode.Code == dnlib.DotNet.Emit.Code.Calli) 46 | { 47 | MethodSig methodSig = (MethodSig)il.Operand; 48 | 49 | _calliMethodSignatures.Add(new CallNativeMethodSignatureInfo() 50 | { 51 | MethodSig = methodSig, 52 | }); 53 | Debug.Log($"method:{method} calli method signature:{methodSig}"); 54 | } 55 | } 56 | } 57 | } 58 | } 59 | 60 | public void Run() 61 | { 62 | CollectCalli(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Editor/MethodBridge/CalliAnalyzer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6ce33c8e48da5a649b261ba3a60fd3b9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/MethodBridge/Generator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e42a0f3bcbc5ddf438a85ae16c1b3116 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/MethodBridge/MonoPInvokeCallbackAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using HybridCLR.Editor.ABI; 3 | using HybridCLR.Editor.Meta; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using CallingConvention = System.Runtime.InteropServices.CallingConvention; 10 | using UnityEngine; 11 | 12 | namespace HybridCLR.Editor.MethodBridge 13 | { 14 | public class RawMonoPInvokeCallbackMethodInfo 15 | { 16 | public MethodDef Method { get; set; } 17 | 18 | public CustomAttribute GenerationAttribute { get; set; } 19 | } 20 | 21 | public class MonoPInvokeCallbackAnalyzer 22 | { 23 | 24 | private readonly List _rootModules = new List(); 25 | 26 | private readonly List _reversePInvokeMethods = new List(); 27 | 28 | public List ReversePInvokeMethods => _reversePInvokeMethods; 29 | 30 | public MonoPInvokeCallbackAnalyzer(AssemblyCache cache, List assemblyNames) 31 | { 32 | foreach (var assemblyName in assemblyNames) 33 | { 34 | _rootModules.Add(cache.LoadModule(assemblyName)); 35 | } 36 | } 37 | 38 | private void CollectReversePInvokeMethods() 39 | { 40 | foreach (var mod in _rootModules) 41 | { 42 | Debug.Log($"ass:{mod.FullName} method count:{mod.Metadata.TablesStream.MethodTable.Rows}"); 43 | for (uint rid = 1, n = mod.Metadata.TablesStream.MethodTable.Rows; rid <= n; rid++) 44 | { 45 | var method = mod.ResolveMethod(rid); 46 | //Debug.Log($"method:{method}"); 47 | if (!method.IsStatic || !method.HasCustomAttributes) 48 | { 49 | continue; 50 | } 51 | CustomAttribute wa = method.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.Name == "MonoPInvokeCallbackAttribute"); 52 | if (wa == null) 53 | { 54 | continue; 55 | } 56 | if (!MetaUtil.IsSupportedPInvokeMethodSignature(method.MethodSig)) 57 | { 58 | throw new Exception($"MonoPInvokeCallback method {method.FullName} has unsupported parameter or return type. Please check the method signature."); 59 | } 60 | //foreach (var ca in method.CustomAttributes) 61 | //{ 62 | // Debug.Log($"{ca.AttributeType.FullName} {ca.TypeFullName}"); 63 | //} 64 | _reversePInvokeMethods.Add(new RawMonoPInvokeCallbackMethodInfo() 65 | { 66 | Method = method, 67 | GenerationAttribute = method.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "HybridCLR.ReversePInvokeWrapperGenerationAttribute"), 68 | }); 69 | } 70 | } 71 | } 72 | 73 | public void Run() 74 | { 75 | CollectReversePInvokeMethods(); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Editor/MethodBridge/MonoPInvokeCallbackAnalyzer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c172068b408c0e349b2ceee4c4635085 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/MethodBridge/PInvokeAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using HybridCLR.Editor.Meta; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using UnityEngine; 9 | 10 | namespace HybridCLR.Editor.MethodBridge 11 | { 12 | 13 | public class PInvokeAnalyzer 14 | { 15 | private readonly List _rootModules = new List(); 16 | 17 | private readonly List _pinvokeMethodSignatures = new List(); 18 | 19 | public List PInvokeMethodSignatures => _pinvokeMethodSignatures; 20 | 21 | public PInvokeAnalyzer(AssemblyCache cache, List assemblyNames) 22 | { 23 | foreach (var assemblyName in assemblyNames) 24 | { 25 | _rootModules.Add(cache.LoadModule(assemblyName)); 26 | } 27 | } 28 | 29 | public void Run() 30 | { 31 | foreach (var mod in _rootModules) 32 | { 33 | foreach (TypeDef type in mod.GetTypes()) 34 | { 35 | foreach (MethodDef method in type.Methods) 36 | { 37 | if (method.IsPinvokeImpl) 38 | { 39 | if (!MetaUtil.IsSupportedPInvokeMethodSignature(method.MethodSig)) 40 | { 41 | throw new Exception($"PInvoke method {method.FullName} has unsupported parameter or return type. Please check the method signature."); 42 | } 43 | _pinvokeMethodSignatures.Add(new CallNativeMethodSignatureInfo { MethodSig = method.MethodSig }); 44 | } 45 | } 46 | } 47 | } 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Editor/MethodBridge/PInvokeAnalyzer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9923175c961b78849aeaf99708e294ce 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ReversePInvokeWrap.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 259c1cb7fe681f74eb435ab8f268890d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Settings.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3708ee1d4035cb14abaa4d64a8ec8148 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Settings/HybridCLRSettingProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2bd1694fedc8b54c88bb9f6c67907d3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Settings/HybridCLRSettings.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using UnityEditorInternal; 3 | using UnityEngine; 4 | 5 | namespace HybridCLR.Editor.Settings 6 | { 7 | 8 | public class HybridCLRSettings : ScriptableObject 9 | { 10 | [Tooltip("enable HybridCLR")] 11 | public bool enable = true; 12 | 13 | [Tooltip("use il2cpp in unity editor installation location")] 14 | public bool useGlobalIl2cpp; 15 | 16 | [Tooltip("hybridclr repo URL")] 17 | public string hybridclrRepoURL = "https://gitee.com/focus-creative-games/hybridclr"; 18 | 19 | [Tooltip("il2cpp_plus repo URL")] 20 | public string il2cppPlusRepoURL = "https://gitee.com/focus-creative-games/il2cpp_plus"; 21 | 22 | [Tooltip("hot update assembly definitions(asd)")] 23 | public AssemblyDefinitionAsset[] hotUpdateAssemblyDefinitions; 24 | 25 | [Tooltip("hot update assembly names(without .dll suffix)")] 26 | public string[] hotUpdateAssemblies; 27 | 28 | [Tooltip("preserved hot update assembly names(without .dll suffix)")] 29 | public string[] preserveHotUpdateAssemblies; 30 | 31 | [Tooltip("output directory of compiling hot update assemblies")] 32 | public string hotUpdateDllCompileOutputRootDir = "HybridCLRData/HotUpdateDlls"; 33 | 34 | [Tooltip("searching paths of external hot update assemblies")] 35 | public string[] externalHotUpdateAssembliyDirs; 36 | 37 | [Tooltip("output directory of stripped AOT assemblies")] 38 | public string strippedAOTDllOutputRootDir = "HybridCLRData/AssembliesPostIl2CppStrip"; 39 | 40 | [Tooltip("supplementary metadata assembly names(without .dll suffix)")] 41 | public string[] patchAOTAssemblies; 42 | 43 | [Tooltip("output file of automatic generated link.xml by scanning hot update assemblies")] 44 | public string outputLinkFile = "HybridCLRGenerate/link.xml"; 45 | 46 | [Tooltip("output file of automatic generated AOTGenericReferences.cs")] 47 | public string outputAOTGenericReferenceFile = "HybridCLRGenerate/AOTGenericReferences.cs"; 48 | 49 | [Tooltip("max iteration count of searching generic methods in hot update assemblies")] 50 | public int maxGenericReferenceIteration = 10; 51 | 52 | [Tooltip("max iteration count of searching method bridge generic methods in AOT assemblies")] 53 | public int maxMethodBridgeGenericIteration = 10; 54 | 55 | 56 | 57 | private static HybridCLRSettings s_Instance; 58 | 59 | public static HybridCLRSettings Instance 60 | { 61 | get 62 | { 63 | if (!s_Instance) 64 | { 65 | LoadOrCreate(); 66 | } 67 | return s_Instance; 68 | } 69 | } 70 | 71 | private static string GetFilePath() 72 | { 73 | return "ProjectSettings/HybridCLRSettings.asset"; 74 | } 75 | 76 | public static HybridCLRSettings LoadOrCreate() 77 | { 78 | string filePath = GetFilePath(); 79 | Object[] objs = InternalEditorUtility.LoadSerializedFileAndForget(filePath); 80 | s_Instance = objs.Length > 0 ? (HybridCLRSettings)objs[0] : (s_Instance ?? CreateInstance()); 81 | return s_Instance; 82 | } 83 | 84 | public static void Save() 85 | { 86 | if (!s_Instance) 87 | { 88 | return; 89 | } 90 | 91 | string filePath = GetFilePath(); 92 | string directoryName = Path.GetDirectoryName(filePath); 93 | Directory.CreateDirectory(directoryName); 94 | var obj = new Object[1] { s_Instance }; 95 | InternalEditorUtility.SaveToSerializedFileAndForget(obj, filePath, true); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Editor/Settings/HybridCLRSettings.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e189374413a3f00468e49d51d8b27a09 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Settings/MenuProvider.cs: -------------------------------------------------------------------------------- 1 | using HybridCLR.Editor.Installer; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace HybridCLR.Editor.Settings 6 | { 7 | public static class MenuProvider 8 | { 9 | 10 | [MenuItem("HybridCLR/About", priority = 0)] 11 | public static void OpenAbout() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/intro"); 12 | 13 | [MenuItem("HybridCLR/Installer...", priority = 60)] 14 | private static void Open() 15 | { 16 | InstallerWindow window = EditorWindow.GetWindow("HybridCLR Installer", true); 17 | window.minSize = new Vector2(800f, 500f); 18 | } 19 | 20 | [MenuItem("HybridCLR/Settings...", priority = 61)] 21 | public static void OpenSettings() => SettingsService.OpenProjectSettings("Project/HybridCLR Settings"); 22 | 23 | [MenuItem("HybridCLR/Documents/Quick Start")] 24 | public static void OpenQuickStart() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/beginner/quickstart"); 25 | 26 | [MenuItem("HybridCLR/Documents/Performance")] 27 | public static void OpenPerformance() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/basic/performance"); 28 | 29 | [MenuItem("HybridCLR/Documents/FAQ")] 30 | public static void OpenFAQ() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/help/faq"); 31 | 32 | [MenuItem("HybridCLR/Documents/Common Errors")] 33 | public static void OpenCommonErrors() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/help/commonerrors"); 34 | 35 | [MenuItem("HybridCLR/Documents/Bug Report")] 36 | public static void OpenBugReport() => Application.OpenURL("https://hybridclr.doc.code-philosophy.com/docs/help/issue"); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /Editor/Settings/MenuProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a475a5f281298b84da32373694704c68 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/SettingsUtil.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 381c08faeafbc004f97504eeba87380d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Template.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9af6345cc5ab1ae4a81262ab4b537911 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Template/FileRegionReplace.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace HybridCLR.Editor.Template 9 | { 10 | public class FileRegionReplace 11 | { 12 | private readonly string _tplCode; 13 | 14 | private readonly Dictionary _regionReplaceContents = new Dictionary(); 15 | 16 | public FileRegionReplace(string tplCode) 17 | { 18 | _tplCode = tplCode; 19 | } 20 | 21 | public void Replace(string regionName, string regionContent) 22 | { 23 | _regionReplaceContents.Add(regionName, regionContent); 24 | } 25 | 26 | public string GenFinalString() 27 | { 28 | string originContent = _tplCode; 29 | 30 | string resultContent = originContent; 31 | 32 | foreach (var c in _regionReplaceContents) 33 | { 34 | resultContent = ReplaceRegion(resultContent, c.Key, c.Value); 35 | } 36 | return resultContent; 37 | } 38 | 39 | public void Commit(string outputFile) 40 | { 41 | string dir = Path.GetDirectoryName(outputFile); 42 | Directory.CreateDirectory(dir); 43 | string resultContent = GenFinalString(); 44 | var utf8WithoutBOM = new System.Text.UTF8Encoding(false); 45 | File.WriteAllText(outputFile, resultContent, utf8WithoutBOM); 46 | } 47 | 48 | public static string ReplaceRegion(string resultText, string region, string replaceContent) 49 | { 50 | int startIndex = resultText.IndexOf("//!!!{{" + region); 51 | if (startIndex == -1) 52 | { 53 | throw new Exception($"region:{region} start not find"); 54 | } 55 | int endIndex = resultText.IndexOf("//!!!}}" + region); 56 | if (endIndex == -1) 57 | { 58 | throw new Exception($"region:{region} end not find"); 59 | } 60 | int replaceStart = resultText.IndexOf('\n', startIndex); 61 | int replaceEnd = resultText.LastIndexOf('\n', endIndex); 62 | if (replaceStart == -1 || replaceEnd == -1) 63 | { 64 | throw new Exception($"region:{region} not find"); 65 | } 66 | if (resultText.Substring(replaceStart, replaceEnd - replaceStart) == replaceContent) 67 | { 68 | return resultText; 69 | } 70 | resultText = resultText.Substring(0, replaceStart) + "\n" + replaceContent + "\n" + resultText.Substring(replaceEnd); 71 | return resultText; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Editor/Template/FileRegionReplace.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 15d4563ad83546c42bc65c99be9bd54a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Code Philosophy Technology Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f09e582706a5776448316f6c584e63a6 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a26873724919287449e2c9eec68ef1da 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Plugins/LZ4.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/hybridclr_unity/fca130bbfaa58fab93b09a57ec83704c2aab4d4f/Plugins/LZ4.dll -------------------------------------------------------------------------------- /Plugins/LZ4.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca69cf4ffd628394a9dd1ef1c56f7f20 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 1 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | : Any 16 | second: 17 | enabled: 0 18 | settings: 19 | Exclude Android: 1 20 | Exclude Editor: 0 21 | Exclude Linux64: 1 22 | Exclude OSXUniversal: 1 23 | Exclude WebGL: 1 24 | Exclude Win: 1 25 | Exclude Win64: 1 26 | Exclude iOS: 1 27 | - first: 28 | Android: Android 29 | second: 30 | enabled: 0 31 | settings: 32 | CPU: ARMv7 33 | - first: 34 | Any: 35 | second: 36 | enabled: 0 37 | settings: {} 38 | - first: 39 | Editor: Editor 40 | second: 41 | enabled: 1 42 | settings: 43 | CPU: AnyCPU 44 | DefaultValueInitialized: true 45 | OS: AnyOS 46 | - first: 47 | Standalone: Linux64 48 | second: 49 | enabled: 0 50 | settings: 51 | CPU: None 52 | - first: 53 | Standalone: OSXUniversal 54 | second: 55 | enabled: 0 56 | settings: 57 | CPU: None 58 | - first: 59 | Standalone: Win 60 | second: 61 | enabled: 0 62 | settings: 63 | CPU: None 64 | - first: 65 | Standalone: Win64 66 | second: 67 | enabled: 0 68 | settings: 69 | CPU: None 70 | - first: 71 | Windows Store Apps: WindowsStoreApps 72 | second: 73 | enabled: 0 74 | settings: 75 | CPU: AnyCPU 76 | - first: 77 | iPhone: iOS 78 | second: 79 | enabled: 0 80 | settings: 81 | AddToEmbeddedBinaries: false 82 | CPU: AnyCPU 83 | CompileFlags: 84 | FrameworkDependencies: 85 | userData: 86 | assetBundleName: 87 | assetBundleVariant: 88 | -------------------------------------------------------------------------------- /Plugins/dnlib.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/hybridclr_unity/fca130bbfaa58fab93b09a57ec83704c2aab4d4f/Plugins/dnlib.dll -------------------------------------------------------------------------------- /Plugins/dnlib.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b93c6604eb031674b80de14cd4458dc0 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | : Any 16 | second: 17 | enabled: 0 18 | settings: 19 | Exclude Android: 1 20 | Exclude Editor: 0 21 | Exclude Linux64: 1 22 | Exclude OSXUniversal: 1 23 | Exclude WebGL: 1 24 | Exclude Win: 1 25 | Exclude Win64: 1 26 | Exclude iOS: 1 27 | - first: 28 | Android: Android 29 | second: 30 | enabled: 0 31 | settings: 32 | CPU: ARMv7 33 | - first: 34 | Any: 35 | second: 36 | enabled: 0 37 | settings: {} 38 | - first: 39 | Editor: Editor 40 | second: 41 | enabled: 1 42 | settings: 43 | CPU: AnyCPU 44 | DefaultValueInitialized: true 45 | OS: AnyOS 46 | - first: 47 | Standalone: Linux64 48 | second: 49 | enabled: 0 50 | settings: 51 | CPU: None 52 | - first: 53 | Standalone: OSXUniversal 54 | second: 55 | enabled: 0 56 | settings: 57 | CPU: None 58 | - first: 59 | Standalone: Win 60 | second: 61 | enabled: 0 62 | settings: 63 | CPU: None 64 | - first: 65 | Standalone: Win64 66 | second: 67 | enabled: 0 68 | settings: 69 | CPU: None 70 | - first: 71 | Windows Store Apps: WindowsStoreApps 72 | second: 73 | enabled: 0 74 | settings: 75 | CPU: AnyCPU 76 | - first: 77 | iPhone: iOS 78 | second: 79 | enabled: 0 80 | settings: 81 | AddToEmbeddedBinaries: false 82 | CPU: AnyCPU 83 | CompileFlags: 84 | FrameworkDependencies: 85 | userData: 86 | assetBundleName: 87 | assetBundleVariant: 88 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | - [README 中文](./README.md) 2 | - [README English](./README_EN.md) 3 | 4 | # HybridCLR 5 | 6 | [![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/focus-creative-games/hybridclr/blob/main/LICENSE) 7 | 8 | ![logo](https://github.com/focus-creative-games/hybridclr/raw/main/docs/images/logo.jpg) 9 | 10 |
11 |
12 | 13 | HybridCLR是一个**特性完整、零成本、高性能、低内存**的**近乎完美**的Unity全平台原生c#热更新解决方案。 14 | 15 | HybridCLR扩充了il2cpp运行时代码,使它由纯[AOT](https://en.wikipedia.org/wiki/Ahead-of-time_compilation) runtime变成AOT+Interpreter 混合runtime,进而原生支持动态加载assembly,从底层彻底支持了热更新。使用HybridCLR技术的游戏不仅能在Android平台,也能在IOS、Consoles、WebGL等所有il2cpp支持的平台上高效运行。 16 | 17 | 由于HybridCLR对ECMA-335规范 的良好支持以及对Unity开发工作流的高度兼容,Unity项目在接入HybridCLR后,可以几乎无缝地获得C#代码热更新的能力,开发者不需要改变日常开发习惯和要求。HybridCLR首次实现了将Unity平台的全平台代码热更新方案的工程难度降到几乎为零的水平。 18 | 19 | 欢迎拥抱现代原生C#热更新技术 !!! 20 | 21 | ## 文档 22 | 23 | - [官方文档](https://hybridclr.doc.code-philosophy.com/docs/intro) 24 | - [快速上手](https://hybridclr.doc.code-philosophy.com/docs/beginner/quickstart) 25 | - [商业项目案例](https://hybridclr.doc.code-philosophy.com/docs/other/businesscase) 26 | 27 | 28 | ## 特性 29 | 30 | - 近乎完整实现了[ECMA-335规范](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/),只有极少量的[不支持的特性](https://hybridclr.doc.code-philosophy.com/docs/basic/notsupportedfeatures)。 31 | - 零学习和使用成本。对绝大多数开发者来说写代码近乎没有限制。 热更新代码与AOT代码无缝工作,可以随意写继承、**泛型**、**反射**之类的代码。不需要额外写任何特殊代码、没有代码生成 32 | - 完全支持多线程,包含但不限于 volatile、ThreadStatic、async Task等相关功能和特性。这是其他所有热更新方案都不支持的 33 | - 几乎完全兼容Unity的工作流。包括且不限于支持热更新**MonoBehaviour**、ScriptableObject、**DOTS**技术,资源上挂载的热更新脚本可以正确实例化,这是其他所有热更新方案都不支持的 34 | - 执行高效。实现了一个极其高效的寄存器解释器,所有指标都大幅优于其他热更新方案。[性能测试报告](https://hybridclr.doc.code-philosophy.com/docs/basic/performance) 35 | - 内存高效。 热更新脚本中定义的类跟普通c#类占用一样的内存空间,远优于其他热更新方案。[内存占用报告](https://hybridclr.doc.code-philosophy.com/docs/basic/memory) 36 | - 支持MonoPInvokeCallback,可以与native代码或者其他语言如lua、javascript、python良好交互 37 | - 支持一些il2cpp不支持的特性,如__makeref、 __reftype、__refvalue指令 38 | - 支持独创的 **Differential Hybrid Execution(DHE)** 差分混合执行技术,即可以对AOT dll任意增删改,会智能地让未改动的函数以AOT方式运行,变化或者新增的函数以interpreter模式运行,让热更新的游戏逻辑的运行性能基本达到原生AOT的水平 39 | - 支持 **热重载** 技术,可以100%卸载程序集 40 | - 支持现代的dll加密技术,有效保障代码安全 41 | 42 | ## 支持的版本与平台 43 | 44 | - 支持2019.4.x、2020.3.x、2021.3.x、2022.3.x、2023.2.x、6000.x.y全系列LTS版本 45 | - 支持所有il2cpp支持的平台 46 | - 支持团结引擎和鸿蒙平台 47 | 48 | ## 工作原理 49 | 50 | HybridCLR从mono的 [mixed mode execution](https://www.mono-project.com/news/2017/11/13/mono-interpreter/) 技术中得到启发,为unity的il2cpp之类的AOT runtime额外提供了interpreter模块,将它们由纯AOT运行时改造为"AOT + Interpreter"混合运行方式。 51 | 52 | ![icon](https://github.com/focus-creative-games/hybridclr/raw/main/docs/images/architecture.png) 53 | 54 | 更具体地说,HybridCLR做了以下几点工作: 55 | 56 | - 实现了一个高效的元数据(dll)解析库 57 | - 改造了元数据管理模块,实现了元数据的动态注册 58 | - 实现了一个IL指令集到自定义的寄存器指令集的compiler 59 | - 实现了一个高效的寄存器解释器 60 | - 额外提供大量的instinct函数,提升解释器性能 61 | 62 | ## 稳定性状况 63 | 64 | HybridCLR已经被广泛验证是非常高效、稳定的Unity热更新解决方案,良好满足大中型商业项目的稳定和性能要求。 65 | 66 | 目前已经有数千个商业游戏项目接入了HybridCLR,其中有超过千个已经在App Store和Google Player上线,仅仅iOS免费榜前500名中就有近百款使用了HybridCLR。上线的项目中包括MMORPG、重度卡牌、重度塔防之类的游戏。国内绝大多数**Top游戏公司**都已经在使用HybridCLR。 67 | 68 | 可查看我们已知的头部公司中使用HybridCLR并且已经上线的[项目列表](https://hybridclr.doc.code-philosophy.com/docs/other/businesscase)。 69 | 70 | ## 支持与联系 71 | 72 | - 官方1群(3000人):651188171(满) 73 | - 新手1群(3000人):428404198(满) 74 | - 新手2群(2000人):680274677(满) 75 | - 新手3群(2000人):**920714552(推荐)** 76 | - discord频道 https://discord.gg/BATfNfJnm2 77 | - 商业合作邮箱: business#code-philosophy.com 78 | - [商业化支持](https://hybridclr.doc.code-philosophy.com/docs/business/intro) 79 | 80 | ## 关于作者 81 | 82 | **walon** :**Code Philosophy(代码哲学)** 创始人 83 | 84 | 毕业于清华大学物理系,2006年CMO金牌,奥数国家集训队成员,保送清华基科班。专注于游戏技术,擅长开发架构和基础技术设施。 85 | 86 | ## license 87 | 88 | HybridCLR is licensed under the [MIT](https://github.com/focus-creative-games/hybridclr/blob/main/LICENSE) license 89 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4b6051e2483d664facc72a5102dcffc 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README_EN.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c9e34f237251ef44193538977db6b15f 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /RELEASELOG.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e53ce54bd8e88c4785c625555308dba 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a6d5e365e1b7d9742bee023ea54b31f2 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/HomologousImageMode.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace HybridCLR 3 | { 4 | public enum HomologousImageMode 5 | { 6 | Consistent, 7 | SuperSet, 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /Runtime/HomologousImageMode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f0351553ad90e74aa586746b5965ded 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/HybridCLR.Runtime.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "HybridCLR.Runtime", 3 | "rootNamespace": "", 4 | "references": [], 5 | "includePlatforms": [], 6 | "excludePlatforms": [], 7 | "allowUnsafeCode": true, 8 | "overrideReferences": false, 9 | "precompiledReferences": [], 10 | "autoReferenced": true, 11 | "defineConstraints": [], 12 | "versionDefines": [], 13 | "noEngineReferences": false 14 | } -------------------------------------------------------------------------------- /Runtime/HybridCLR.Runtime.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 13ba8ce62aa80c74598530029cb2d649 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/LoadImageErrorCode.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace HybridCLR 3 | { 4 | public enum LoadImageErrorCode 5 | { 6 | OK = 0, 7 | BAD_IMAGE, // invalid dll file 8 | NOT_IMPLEMENT, // not implement feature 9 | AOT_ASSEMBLY_NOT_FIND, // AOT assembly not found 10 | HOMOLOGOUS_ONLY_SUPPORT_AOT_ASSEMBLY, // can not load supplementary metadata assembly for non-AOT assembly 11 | HOMOLOGOUS_ASSEMBLY_HAS_LOADED, // can not load supplementary metadata assembly for the same assembly 12 | INVALID_HOMOLOGOUS_MODE, // invalid homologous image mode 13 | PDB_BAD_FILE, // invalid pdb file 14 | }; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Runtime/LoadImageErrorCode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2c7d5b71981fba643b4c21ed01bcb675 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/ReversePInvokeWrapperGenerationAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace HybridCLR 8 | { 9 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)] 10 | public class ReversePInvokeWrapperGenerationAttribute : Attribute 11 | { 12 | public int ReserveWrapperCount { get; } 13 | 14 | public ReversePInvokeWrapperGenerationAttribute(int reserveWrapperCount) 15 | { 16 | ReserveWrapperCount = reserveWrapperCount; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Runtime/ReversePInvokeWrapperGenerationAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f99dd22d9d81b2540b4663b3bcdf0a79 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/RuntimeApi.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0d58bdc22b6d6b54ab6791baf16a0a3d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/RuntimeOptionId.cs: -------------------------------------------------------------------------------- 1 | namespace HybridCLR 2 | { 3 | public enum RuntimeOptionId 4 | { 5 | InterpreterThreadObjectStackSize = 1, 6 | InterpreterThreadFrameStackSize = 2, 7 | ThreadExceptionFlowSize = 3, 8 | MaxMethodBodyCacheSize = 4, 9 | MaxMethodInlineDepth = 5, 10 | MaxInlineableMethodBodySize = 6, 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Runtime/RuntimeOptionId.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64be598b47302644a96013c74d945653 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.code-philosophy.hybridclr", 3 | "version": "8.1.0", 4 | "displayName": "HybridCLR", 5 | "description": "HybridCLR is a fully featured, zero-cost, high-performance, low-memory solution for Unity's all-platform native c# hotupdate.", 6 | "category": "Runtime", 7 | "documentationUrl": "https://hybridclr.doc.code-philosophy.com/#/", 8 | "changelogUrl": "https://hybridclr.doc.code-philosophy.com/#/other/changelog", 9 | "licensesUrl": "https://github.com/focus-creative-games/hybridclr_unity/blob/main/LICENSE", 10 | "keywords": [ 11 | "HybridCLR", 12 | "hotupdate", 13 | "hotfix", 14 | "focus-creative-games", 15 | "code-philosophy" 16 | ], 17 | "author": { 18 | "name": "Code Philosophy", 19 | "email": "hybridclr@code-philosophy.com", 20 | "url": "https://code-philosophy.com" 21 | } 22 | } -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8ea8eca3a387d9d4988a2fca1036f2e7 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------