InjectFix
Tencent open source Unity code logic hot fix
Unity code logic hot fix
A bug that can be used for Unity business Repair, support all Unity series and all platforms.
Few highlights
- Modify C directly on the Unity project to update
- Old projects can be used without modifying the original code
- One copy for each game Private patch format, more secure
Compile and install
- Open the Source\VSProj\build_for_unity.bat of the source package under Window, and modify the value of the UNITY_HOME variable to point to the unity of the unit Installation directory
- run build_for_unity.bat
copy
here corresponds to a Unity project directory
- IFixToolKit copied to the Unity project’s Assets 7 directory fc4d# at the same level
- Assets/IFix, Assets/Plugins copied to the Assets of the Unity project
Access example
If there is a patch, load the patch
var patchPath = "./Assets /IFix/Resources/Assembly-CSharp.ill.bytes";
if (File.Exists(patchPath))
{
PatchManager.Load(new FileStream(patchPath, FileMode.Open));
}
Configuration
The implementation of the hot patch depends on doing some static code insertion in advance, so it is necessary to configure which classes are preprocessed, and the configuration can be repaired. Generally speaking, as long as it is not a class with very demanding performance requirements, it can be added.
iFix supports dynamic and static lists. Because there are often more types, dynamic lists are more convenient. The following is an example to configure all types except anonymous classes in the XLua namespace.
[Configure]
public class InterpertConfig {
[IFix]
static IEnumerableToProcess
{
get
{
return (from type in Assembly.Load-CSharp" Assembly.Load(" ()
where type.Namespace == "XLua" && !type.Name.Contains("<")
select type);
}
}
}
Underline Important:
- Configure the configuration class with the Configure tag
- Configure the attributes with the IFix tag, and must be static type
In addition to not having to configure one by one, dynamic configuration may also have other additional benefits, such as the above configuration, and subsequent additions and deletions of classes in the name space do not need to change the configuration.
After configuration, the packaged mobile phone version will be automatically preprocessed. If you want to automate the packaging, you can also manually call the IFix.Editor.IFixEditor.InjectAllAssemblys function.
Patch making
Patch the function that needs to be patched
[Patch]
public int Add(int a, int b)
{
return a + b;
}
Execute the "InjectFix/Fix" menu.
After the patch is successfully created, it will be placed in the project directory. The file name is "{Dll Name}.patch.bytes" (for example: "Assembly-CSharp.patch.bytes"). Upload the patch to the phone and load it. See the effect.
Note: If there are conditional compilation macros in the function to be Patched, such as this code:
[Patch]
public void Job(int a)
{
if UNITY_EDITOR
Foo();
endif
if !UNITY_EDITOR
Bar();
endif
}
If the patch is generated directly under the editor, there will be more Foo calls than the mobile phone. Bar, this may cause various problems: the logic is wrong, the editor-specific function is called and the function to be called cannot be found, etc.
At this time, you can compile Assembly-CSharp.dll according to the compilation parameters of the corresponding platform, and then call IFix.Editor.IFixEditor.GenPatch to generate the patch.
Unity compilation is to create a new file in the Temp directory of the project, put the command line parameters in that file, and then execute similar commands (the directory depends on your unity installation) to compile:
"D :\Program Files\Unity201702\Editor\Data\MonoBleedingEdge\bin\mono.exe" "D:\Program Files\Unity201702\Editor\Data\MonoBleedingEdge\lib\mono\4.5\mcs.exe" @Temp/UnityTempFile-55a959adddae39f4aaa18507dd165989
You can try to package the mobile phone version under the editor once, and then copy the temporary file in the Temp directory under the project directory (it will be deleted automatically after compilation, so you have to be quick).
Most parts of this file will not change. The main change is the C file list, which can be dynamically generated: The C file list is generated according to the current project, and the others remain unchanged. Then use this file as input to compile.
github address:
https://github.com/tencent/injectfix
For more high-quality information, please pay attention to me, your support will encourage me to keep sharing More and better quality articles.