Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

处理 nullable GetValueOrDefault #403

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
38 changes: 38 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/Source/UnityProj/Assets/IFix/Binding.meta
/Source/UnityProj/Assets/IFix/Binding
/Source/UnityProj/Library
/Source/UnityProj/AndroidBuild
/Source/UnityProj/obj
/Source/UnityProj/Logs
/Source/UnityProj/.idea
/Source/UnityProj/.vs
/Source/UnityProj/Assembly-CSharp-firstpass.csproj
/Source/UnityProj/Assembly-CSharp-firstpass.patch.bytes
/Source/UnityProj/UnityProj.sln
/Source/UnityProj/UnityProj.sln.DotSettings.user
/Source/UnityProj/Assembly-CSharp.csproj
/Source/UnityProj/Assembly-CSharp.dll
/Source/UnityProj/Assembly-CSharp.patch.bytes
/Source/UnityProj/Assembly-CSharp-Editor.csproj
/Source/UnityProj/ProjectSettings
/Source/UnityProj/buildexe
/Source/UnityProj/buildvs
/Source/UnityProj/buildvs2
/Source/VSProj/vs2013/.idea
/Source/VSProj/vs2013/obj
/Source/VSProj/vs2013/IFix.sln.DotSettings.user
/Source/UnityProj/Temp
/Source/VSProj/Lib
/Source/VSProj/Bin
/Source/VSProj/Data
/Source/UnityProj/UserSettings
/Source/UnityProj/Assets/Plugins/IFix.Core.pdb.meta
/Source/UnityProj/Assets/Plugins/IFix.Core.dll
/Source/UnityProj/Assets/Plugins/IFix.Core.pdb
/Source/UnityProj/IFixToolKit/IFix.exe.mdb
/Source/UnityProj/IFixToolKit/IFix.exe
/Source/UnityProj/Packages
/Source/UnityProj/Assets/Resources.meta
/Source/UnityProj/Assets/Resources
/Source/VSProj/Instruction.cs
/Source/VSProj/ShuffleInstruction.exe
119 changes: 100 additions & 19 deletions Source/UnityProj/Assets/Helloworld/Calc.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,116 @@
/*
* Tencent is pleased to support the open source community by making InjectFix available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* InjectFix is licensed under the MIT License, except for the third-party components listed in the file 'LICENSE' which may be subject to their corresponding license terms.
* InjectFix is licensed under the MIT License, except for the third-party components listed in the file 'LICENSE' which may be subject to their corresponding license terms.
* This file is subject to the terms and conditions defined in file 'LICENSE', which is part of this source code package.
*/

namespace IFix.Test

//HelloworldCfg.cs里配置了这个类型

using System;
using IFix;
using UnityEngine;

public enum TestEnumValue
{
t1 = 1,
t2 = 2,
}

public struct AllValueStruct
{
public int x;
}

public struct ChildClassStruct
{
public ClassStruct cs;
}

public struct ClassStruct
{
//HelloworldCfg.cs里配置了这个类型
public class Calculator
public GameObject go;
}

public class Calculator
{
private TestEnumValue thisEnum = TestEnumValue.t2;
private Vector3 v = Vector3.right;
private Vector3? nullableV1 = null;
private Vector3? nullableV2 = Vector3.left;

private static Vector3? nullableV3 = Vector3.left;

private AllValueStruct astruct = new AllValueStruct{x=1};

//修改成正确的逻辑后,打开如下注释,生成的补丁将修正该函数
public int Add(int a, int b)
{
//修改成正确的逻辑后,打开如下注释,生成的补丁将修正该函数
//[Patch]
public int Add(int a, int b)
{
return a * b;
}
return
TestAllValueStruct(default(AllValueStruct)) + TestAllValueStruct(default(AllValueStruct)) +
TestAllValueStruct(astruct) +
TestVector3(default(Vector3)) + TestVector3(default(Vector3)) + TestVector3(v) + TestVector3(Vector3.one) +
TestEnum(TestEnumValue.t2) + TestEnum(default(TestEnumValue)) + TestEnum(thisEnum) + TestEnum(TestEnumValue.t1) +
TestRefInt(ref a) + a +
TestNullable(null) + TestNullable(Vector3.left) + TestNullable(nullableV1) + TestNullable(nullableV2)
+ TestNullable(nullableV3);
//return DoAdd(a, b);
}

public int Sub(int a, int b)
public int TestNullable(ref Vector3? v)
{
if (v == null)
{
return a / b;
return 9 * 1000000;
}

public int Mult(int a, int b)
return (int)(v.Value.x + v.Value.y + v.Value.z) * 1000000;
}

public int TestNullable(Vector3? v)
{
if (v == null)
{
return a * b;
return 9 * 1000000;
}

public int Div(int a, int b)
{
return a / b;
}
return (int)(v.Value.x + v.Value.y + v.Value.z) * 1000000;
}
}

public int TestRefInt(ref int v)
{
v = 100000;
return v;
}

public int TestEnum(TestEnumValue v)
{
return (int)v * 1000;
}

public int TestAllValueStruct(AllValueStruct v)
{
return v.x * 10000;
}

public int TestVector3(Vector3 v)
{
return 10 * (int)(v.x + v.y + v.z);
}

public int Sub(int a, int b)
{
return a / b;
}

public int Mult(int a, int b)
{
return a * b;
}

public int Div(int a, int b)
{
return a / b;
}
}
6 changes: 3 additions & 3 deletions Source/UnityProj/Assets/Helloworld/Editor/HelloworldCfg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ static IEnumerable<Type> hotfix
return new List<Type>()
{
typeof(Helloworld),
typeof(IFix.Test.Calculator),
//AnotherClass在Pro Standard Assets下,会编译到Assembly-CSharp-firstpass.dll下,用来演示多dll的修复
typeof(AnotherClass),
typeof(Calculator),
// //AnotherClass在Pro Standard Assets下,会编译到Assembly-CSharp-firstpass.dll下,用来演示多dll的修复
// typeof(AnotherClass),
};
}
}
Expand Down
Loading