Coder Social home page Coder Social logo

il2cpp-1's Introduction

il2cpp测试框架

目录结构

  1. CSharp 热更dll工程
  2. output/CSharp C++工程目录
  3. output/GameAssembly-CSharp-x64 生成的可执行文件目录
  4. Tools/il2cpp il2cpp.exe源码

cmake

  1. output/CSharp/CMakeLists.txt CMakeLists文件,可以用clion或者vs打开,Toolchains选vs image

vs调试

  1. 使用vs打开output\CSharp,注意需要使用管理员权限打开vs,否则cmake构建会报错
  2. cp launch.vs.json output/CSharp/.vs/launch.vs.json
  3. 选择GameAssembly-CSharp-x64.dll image

需要修改huatuo的地方

  1. 增加il2cpp::vm::MetadataCache::LoadAssemblyFromFile函数
  2. 增加il2cpp_test导出函数
// ==={{ huatuo
#ifdef IL2CPP_TARGET_WINDOWS
#include <iostream>

// CSHARP_DLL_PATH=CSharp.dll
// rundll32.exe GameAssembly-CSharp-x64.dll,il2cpp_test
int il2cpp_test()
{
    il2cpp_set_config_dir("Data/etc");
    il2cpp_set_data_dir("Data");
    il2cpp_init("IL2CPP Root Domain");
    char *tmp = getenv("CSHARP_DLL_PATH");
    if (tmp != nullptr)
    {
        std::string csharp_dll_path(tmp);

        if (!csharp_dll_path.empty())
            il2cpp::vm::MetadataCache::LoadAssemblyFromFile(csharp_dll_path.c_str());
    }

    const Il2CppAssembly *assembly = il2cpp_domain_assembly_open(il2cpp_domain_get(), "CSharp.dll");
    const Il2CppImage *image = il2cpp_assembly_get_image(assembly);

    Il2CppClass *clazz = il2cpp_class_from_name(image, "CSharp", "Main");
    const MethodInfo *method = il2cpp_class_get_method_from_name(clazz, "Entry", 0);
    Il2CppException* exception = nullptr;

    il2cpp_runtime_invoke(method, nullptr, nullptr, &exception);

    if (exception != nullptr) {
        std::cout << il2cpp::utils::Exception::FormatException(exception) << std::endl;
        exit(1);
    }
    return 0;
}

#endif
// ===}} huatuo
  1. 优先热更dll
const Il2CppAssembly* il2cpp::vm::MetadataCache::GetOrLoadAssemblyByName(const char* assemblyNameOrPath, bool tryLoad)
{
    const char* assemblyName = huatuo::GetAssemblyNameFromPath(assemblyNameOrPath);

    il2cpp::utils::VmStringUtils::CaseInsensitiveComparer comparer;

    il2cpp::os::FastAutoLock lock(&il2cpp::vm::g_MetadataLock);

    for (auto assembly : s_cliAssemblies)
    {
        if (comparer(assembly->aname.name, assemblyName) || comparer(assembly->image->name, assemblyName))
            return assembly;
    }

    for (int i = 0; i < s_AssembliesCount; i++)
    {
        const Il2CppAssembly* assembly = s_AssembliesTable + i;

        if (comparer(assembly->aname.name, assemblyName) || comparer(assembly->image->name, assemblyName))
            return assembly;
    }

    if (tryLoad)
    {
        Il2CppAssembly* newAssembly = huatuo::metadata::Assembly::LoadFromFile(assemblyNameOrPath);
        if (newAssembly)
        {
            il2cpp::vm::Assembly::Register(newAssembly);
            s_cliAssemblies.push_back(newAssembly);
            return newAssembly;
        }
    }

    return nullptr;
}

搭建编译环境

git clone https://github.com/eelgame/il2cpp.git
cd il2cpp
cp -r $UNITY_PATH/2020.3.7f1/Editor/Data/il2cpp ./
热更dll路径:CSharp/CSharp/bin/Debug/CSharp.dll
run_test.sh #构建并运行。执行CSharp.Main.Entry方法
il2cpp_run_aot.sh #aot模式运行
il2cpp_run.sh #huatuo模式运行

注意事项

  1. CSharp是热更项目,build完成后CSharp.dll会自动拷贝到dll目录下,依赖dll请自行拷贝
  2. 热更dll同样会生成aot代码,所以不需要reftypes
  3. il2cpp_run_aot.sh/il2cpp_run.sh 可以在aot模式和huatuo模式下做对比测试

il2cpp-1's People

Contributors

copilot10080 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.