Unity 4.3.1 source code compilation engine

introduction


Unity official from Unity 2017.1 release, the open source engine and editor of C # source code (Source Address: UnityCsReference), but the core of the C / C ++ source code was not part of open source.

 

Compiler Environment


There are two main online source versions of Unity 4.3.1f1 and Unity 4.7.1f1, but in fact the basic version is 4.3.1, and an example here to Unity 4.3 to compile the source code, but need to install some software before compilation tools:

  • Visual Studio 2010 (VS version can not be a high source compiler, or will be error)
  • Visual Studio 2010 SP1
  • Perl (download and install ActivePerl can)

 

Source Package


Unity4.7.1f1_source_3eo9sdfl01d_final.zip online There are many ways to get source packages, and these packages are basically versions of Unity 4.3.1f1, but the package name changed to 4.7 to cheat downloads it ~

 

Compilation step


The source packages on disk root directory, the path is too deep can cause an error when extracting (because the file name is too long due) appear, for example, here in my store directory F: \ Unity4.7.1f1_source;

Into the project directory, double-click jamCreateWorkspace.bat script, after the implementation will be more of a JamGenerated directory in the Projects directory; (if not this script can be used to generate in the current directory using the command line execution perl build.pl --prepare );

Then use VS Open Projects / JameGenerated / _workspace.vs2010_ / AllTarget.sln, select the Editor solution in Solution Explorer, right-generating;
image

After construction, the build results in the build / WindowsEditor directory, double-click Unity.exe starting the editor to start the editor.
image

 

Compile-time error to solve

  • No dependencies automatically extract:

    在 External 目录下有很多依赖库,有些是以压缩包的形式存在的,但编译的时候可能出现压缩包无法自动解压缩的情况,要么手动解压缩这些包,要么就使用自动化工具批量解压缩,显然后者要靠谱一些,可以避免遗漏。

    其实这些压缩包都是以 builds 命名的,后缀名为 .zip 、.7z 或这 .tar.gz 三种,这里我直接用 QQ 群友写的一个 python 脚本实现解压操作。但是需要安装 7z.exe 并将其配置到系统环境变量中(确保可以在任何目录下通过命令行调用),具体代码如下(例如取名为 unzipExtenalBuilds.py):

# -*- encoding: utf-8 -*-

import os

def unzip():
    for path, dirs, files in os.walk(r"External"):
        dir = os.path.join(path, "builds")
        if os.path.isdir(dir):
            continue
        for ext in [".7z", ".tar.gz", ".zip"]:
            fname = dir + ext
            if os.path.exists(fname):
                cmd = "7z.exe x " + fname + " -o" + dir
                print(cmd)
                os.system(cmd)

if __name__ == "__main__":
    unzip()
将此脚本放在工程根目录下,在命令行执行:

$ python unzipExtenalBuilds.py
解压完成后,再重头走一遍上面的编译步骤。

 

  • 中文系统导致的问题:

当如当前的系统是中文系统,然后在编译时出现很多如下报错:

C2220 警告被视为错误 - 没有生成 "obj" 文件
C4819 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
...
解决方案:

修改 Projects/Jam/Editor.jam 中第 360 行,插入 /wd4819 ,如下:

local vsflags = /WX /wd4251 ;           //修改前
local vsflags = /WX /wd4251 /wd4819 ;   //修改后
 

  • 未安装 VS 2010 SP1 补丁

编译时出现如下报错:

C3861 "_xgetbv" :找不到标识符
这是因为没有安装 Visual Studio 2010 SP1 ,在编译 CPUInfo.cpp 时因找不到 _xgetbv 方法而导致报错。

解决方案:

下载安装 VS10sp1-KB983509.exe 补丁,重新编译即可。

 

启动时报错


启动编译好的编辑器,弹出提示框:
image

Error loading page
SSL peer certificate or SSH remote key was not OK
这是因为许可管理导致的,因为在 Unity 启动时会联网校验许可信息。

解决方案:

  • 方案1:

可以用常用的方法进行破解,例如从 Unity 官网通过上传 Unity_v4.3.1f1.alf 再下载一个 Unity_v4.x.ulf 导入编辑器来激活,然后修改 LicenseManager.cpp 的 1709 行获取失效时间的代码:

std::string stopString = GetDate("StopDate", doc);  // 修改前
std::string stopString = "2112-01-27T08:00:00";     // 修改后
 

  • 方案2:

既然是要研究源码,最好是从源头上解决,打开 Editor/Src/LicenseInfo.cpp ,修改两个地方:

UInt64 LicenseInfo::GetRawFlags ()
{
    // 插入内容 start
    if (m_Tokens == 0)
    {
        m_Tokens = 12345678;
    }
    // 插入内容 end
    return m_Tokens;
}

void LicenseInfo::InitializeProtection()
{
    ...
    int state = m_LicenseManager->Initialize();
    // 插入一行代码代码
    state = kLicenseStatus_Valid;
}
打开 Editor/Src/Application.cpp ,修改方法:

the Application :: TickTimer void ()
{
    // shield at two lines of code
    // IF (m_IsInitialized)
    // :: the LicenseInfo the Get () -> the Tick ();
    ...
}
After modifying these three, recompiling .

 

other

  • Try vs2012 compile, compile failed
  • After (not installed VS2010 SP1) reported the other and this difference error in VS2010 compile and install VS2010 compile successfully

Ref: https://blog.csdn.net/linshuhe1/article/details/90295325

Guess you like

Origin www.cnblogs.com/open-coder/p/12079125.html