{"id":5010997,"url":"https://github.com/tuyoogame/huatuo","last_synced_at":"2025-05-15T10:00:40.481Z","repository":{"id":37345531,"uuid":"446669267","full_name":"tuyoogame/huatuo","owner":"tuyoogame","description":"huatuo是一个特性完整、零成本、高性能、低内存的近乎完美的Unity全平台原生c#热更方案。 Huatuo is a fully featured, zero-cost, high-performance, low-memory solution for Unity's all-platform native c# hotfix","archived":false,"fork":false,"pushed_at":"2023-02-16T03:17:00.000Z","size":5229,"stargazers_count":2333,"open_issues_count":4,"forks_count":381,"subscribers_count":66,"default_branch":"main","last_synced_at":"2025-04-14T15:56:52.541Z","etag":null,"topics":["csharp","hot-fix","hot-update","hotfix","hotupdate","il2cpp","ilruntime","injectfix","lua","puerts","slua","tolua","unity","unlua","unreal","update","xlua"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tuyoogame.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":["https://raw.githubusercontent.com/focus-creative-games/huatuo/main/docs/sponsor/weixin.JPG","https://raw.githubusercontent.com/focus-creative-games/huatuo/main/docs/sponsor/zhifubao.JPG"]}},"created_at":"2022-01-11T03:50:55.000Z","updated_at":"2025-04-09T10:37:44.000Z","dependencies_parsed_at":"2024-09-19T11:31:09.221Z","dependency_job_id":"b81e1081-acfb-4cd5-90b0-d8523285c1e7","html_url":"https://github.com/tuyoogame/huatuo","commit_stats":{"total_commits":137,"total_committers":9,"mean_commits":"15.222222222222221","dds":"0.13138686131386856","last_synced_commit":"04fea98e5929426519c3b85fba26397644661167"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuyoogame%2Fhuatuo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuyoogame%2Fhuatuo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuyoogame%2Fhuatuo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tuyoogame%2Fhuatuo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tuyoogame","download_url":"https://codeload.github.com/tuyoogame/huatuo/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254319715,"owners_count":22051072,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","hot-fix","hot-update","hotfix","hotupdate","il2cpp","ilruntime","injectfix","lua","puerts","slua","tolua","unity","unlua","unreal","update","xlua"],"created_at":"2024-02-24T00:17:42.178Z","updated_at":"2025-05-15T10:00:39.992Z","avatar_url":"https://github.com/tuyoogame.png","language":"C++","funding_links":["https://raw.githubusercontent.com/focus-creative-games/huatuo/main/docs/sponsor/weixin.JPG","https://raw.githubusercontent.com/focus-creative-games/huatuo/main/docs/sponsor/zhifubao.JPG"],"categories":["C++"],"sub_categories":[],"readme":"\n# huatuo\n\n[![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/focus-creative-games/huatuo/blob/main/LICENSE)\n\n\u003cbr/\u003e\n\n![icon](docs/images/logo.png)\n\n\u003cbr/\u003e\n\nhuatuo是一个**特性完整、零成本、高性能、低内存**的**近乎完美**的Unity全平台原生c#热更方案。\n\nhuatuo扩充了il2cpp的代码，使它由纯[AOT](https://en.wikipedia.org/wiki/Ahead-of-time_compilation) runtime变成‘AOT+Interpreter’ 混合runtime，进而原生支持动态加载assembly，使得基于il2cpp backend打包的游戏不仅能在Android平台，也能在IOS、Consoles等限制了JIT的平台上高效地以**AOT+interpreter**混合模式执行。从底层彻底支持了热更新。\n\nhuatuo**开创性地实现了 `differential hybrid dll` 技术**====。即可以对AOT dll任意增删改，huatuo会智能地让变化或者新增的类和函数以interpreter模式运行，但未改动的类和函数以AOT方式运行，让热更新的游戏逻辑的运行性能基本达到原生AOT的水平。\n\n## 特性\n\n- 特性完整。 近乎完整实现了[ECMA-335规范](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/)，除了 下文中\"限制和注意事项\" 之外的特性都支持。\n- 零学习和使用成本。 huatuo将纯AOT runtime增强为完整的runtime，使得热更新代码与AOT代码无缝工作。脚本类与AOT类在同一个运行时内，可以随意写继承、反射、多线程(volatile、ThreadStatic、Task、async)之类的代码。不需要额外写任何特殊代码、没有代码生成，也没有什么特殊限制。\n- 执行高效。实现了一个极其高效的寄存器解释器，所有指标都大幅优于其他热更新方案。[性能测试报告](https://xxx/huatuo/performance/benchmark/#性能测试报告)\n- 内存高效。 热更新脚本中定义的类跟普通c#类占用一样的内存空间，远优于其他热更新方案。[内存占用报告](https://xxx/huatuo/performance/benchmark/#内存占用报告)\n- 原生支持hotfix修复AOT部分代码。几乎不增加任何开发和运行开销。\n- **开创性地实现了 `differential hybrid dll` 技术**。即可以将某个热更新dll先AOT形式打包，后面可以对该dll任意增删改，huatuo会智能地让变化或者新增的类和函数以interpreter模式运行，但未改动的类和函数以AOT方式运行。这意味着热更新的游戏逻辑的运行性能将接近原生AOT的水平。\n\n## 工作原理\n\nhuatuo从mono的[hybrid mode execution](https://developpaper.com/new-net-interpreter-mono-has-arrived/)技术中得到启发，为unity的il2cpp之类的AOT runtime额外提供了interpreter模块，将它们由纯AOT运行时改造为\"AOT + Interpreter\"混合运行方式。\n\n![icon](docs/images/architecture.png)\n\n更具体地说，huatuo做了以下几点工作：\n\n- 实现了一个高效的元数据(dll)解析库\n- 改造了元数据管理模块，实现了元数据的动态注册\n- 实现了一个IL指令集到自定义的寄存器指令集的compiler\n- 实现了一个高效的寄存器解释器\n- 额外提供大量的instinct函数，提升解释器性能\n- 提供hotfix AOT的支持\n\n## 与其他流行的c#热更新方案的区别\n\n### 本质比较\n\nhuatuo是原生的c#热更新方案。通俗地说，il2cpp相当于mono的aot模块，huatuo相当于mono的interpreter模块，两者合一成为完整mono。huatuo使得il2cpp变成一个全功能的runtime，原生（即通过System.Reflection.Assembly.Load）支持动态加载dll，从而支持ios平台的热更新。\n\n正因为huatuo是原生runtime级别实现，热更新部分的类型与主工程AOT部分类型是完全等价并且无缝统一的。可以随意调用、继承、反射、多线程，不需要生成代码或者写适配器。\n\n其他热更新方案则是独立vm，与il2cpp的关系本质上相当于mono中嵌入lua的关系。因此类型系统不统一，为了让热更新类型能够继承AOT部分类型，需要写适配器，并且解释器中的类型不能为主工程的类型系统所识别。特性不完整、开发麻烦、运行效率低下。\n\n### 实际使用体验或者特性比较\n\n- huatuo学习和使用成本几乎为零。huatuo让il2cpp变成全功能的runtime，学习和使用成本几乎为零，几乎零侵入性。而其他方案则有大量的坑和需要规避的规则，学习和使用成本，需要对原项目作大量改造。\n- huatuo可以使用所有c#的特性。而其他方案往往有大量的限制。\n- huatuo中可以直接支持使用和继承主工程中的类型。其他方案要写适配器或者生成代码。\n- huatuo中热更新部分元数据与AOT元数据无缝统一。像反射代码能够正常工作的，AOT部分也可以通过标准Reflection接口创建出热更新对象。其他方案做不到。\n- huatuo对多线程支持良好。像多线程、ThreadStatic、async等等特性都是huatuo直接支持，其他方案除了async特性外均难以支持。\n- huatuo中Unity工作流与原生几乎完全相同。huatuo中热更新MonoBehaviour可以直接挂载在热更新资源上，并且正确工作。其他方案不行。\n- huatuo兼容性极高。各种第三方库只要在il2cpp下能工作，在huatuo下也能正常工作。其他方案往往要大量魔改源码。\n- huatuo内存效率极高。huatuo中热更新类型与主工程的AOT类型完全等价，占用一样多的空间。其他方案的同等类型则是假类型，不仅不能被runtime识别，还多占了数倍空间。\n- huatuo执行效率高。huatuo中热更新部分与主工程AOT部分交互属于il2cpp内部交互，效率极高。而其他方案则是独立虚拟机与il2cpp之间的效率，不仅交互麻烦还效率低下。\n\n## 文档\n\n- [文档站](https://xxx/)，**推荐使用**\n- [FAQ](https://xxx/huatuo/faq/)\n- [限制和注意事项](https://xxx/huatuo/performance/limit/)\n- [示例项目](https://github.com/focus-creative-games/huatuo_trial)\n- [==\u003e致谢名单\u003c==](https://xxx/huatuo/donate/)\n\n## 稳定性状况\n\n=== **庆祝于 2021.6.7 第一款使用huatuo的android和iOS双端休闲游戏正式上线** ===，7月份还有几款中重游戏上线或者对外测试。\n\n技术评估上目前稳定性处于Beta版本。由于huatuo技术原理的先进性，bug本质上不多，稳定得非常快。\n\n- 目前PC、Android、iOS 已跑通所有单元测试，可稳定体验使用。\n- 测试了游戏常用库和框架的兼容性，兼容性良好。只要能在il2cpp backend下工作的库都可以在huatuo下正常工作。甚至那些与il2cpp因为AOT问题不兼容的库，现在因为huatuo对il2cpp的能力扩充，反而可以正常运行了。具体参见 [兼容性报告](https://xxx/huatuo/performance/compatible/)\n- 已经有几十个大中型游戏项目较完整地接入huatuo，并且其中一些在紧锣密鼓作上线前测试。具体参见收集的一些 [完整接入的商业项目列表](https://xxx/huatuo/ref_project/)\n\n## RoadMap\n\nhuatuo虽然与il2cpp相关，但绝大多数核心代码独立于il2cpp，很容易移植（预计一个月）到其他不支持AOT+Interpreter的CLR平台。无论unity如何版本变迁，哪怕废弃了il2cpp改用.net 6+，huatuo会持续跟进，稳定地提供跨平台的CLR热更新服务，直至某天.net官方直接支持AOT+Interpreter，则huatuo完成其历史使命。\n\n- 支持Unity 2019、2020和2021系列版本 (2022.6 -)\n- 支持32位 (2022.6 - 2022.7)\n- 指令优化，编译后指令数减少到原来1/4-1/2，基础指令和大多数对象模型指令有100%-300%的性能提升。 (2022.7 -)\n- 支持增量式gc (2022.8 -)\n\n## license\n\nHuatuo is licensed under the [MIT](https://github.com/xxx/huatuo/blob/main/LICENSE) license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuyoogame%2Fhuatuo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftuyoogame%2Fhuatuo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftuyoogame%2Fhuatuo/lists"}