diff --git a/test/agent/src/index.ts b/test/agent/src/index.ts index 3fa5c31..753cafd 100644 --- a/test/agent/src/index.ts +++ b/test/agent/src/index.ts @@ -82,8 +82,8 @@ Il2Cpp.perform(() => { }); test("Il2Cpp.Image::classCount", () => { - assert(Il2Cpp.domain.assembly("GameAssembly").image.classes.length).is(33); - assert(Il2Cpp.domain.assembly("GameAssembly").image.classCount).is(33); + assert(Il2Cpp.domain.assembly("GameAssembly").image.classes.length).is(36); + assert(Il2Cpp.domain.assembly("GameAssembly").image.classCount).is(36); }); test("Il2Cpp.Class::image", () => { @@ -619,4 +619,35 @@ Il2Cpp.perform(() => { "Cannot create nullable value type out of a reference type 'System.Object'" ); }); + // --- Struct return hook tests (Interceptor.replace via .implementation) --- + + test("Hooked method returning medium struct with passthrough result", () => { + const SRT = Il2Cpp.domain.assembly("GameAssembly").image.class("StructReturnTest"); + const method = SRT.method("GetMediumResult"); + + method.implementation = function (...args) { + return method.invoke(...args); + }; + + const result = method.invoke(3, 77); + assert(result.field("Code").value).is(3); + assert(result.field("Value").value).is(77); + SRT.method("GetMediumResult").revert(); + }); + + test("Hooked method returning large struct (sret) with passthrough result", () => { + const SRT = Il2Cpp.domain.assembly("GameAssembly").image.class("StructReturnTest"); + const method = SRT.method("GetLargeResult"); + const msg = Il2Cpp.string("passthrough"); + const entity = Il2Cpp.corlib.class("System.Object").new(); + + method.implementation = function (...args) { + return method.invoke(...args); + }; + + const result = method.invoke(5, msg, entity); + assert(result.field("Reason").value).is(5); + assert(result.field("Message").value.content).is("passthrough"); + SRT.method("GetLargeResult").revert(); + }); }).then(() => send({ action: "stop" })); diff --git a/test/src/GameAssembly.cs b/test/src/GameAssembly.cs index 4369200..84f2c83 100644 --- a/test/src/GameAssembly.cs +++ b/test/src/GameAssembly.cs @@ -355,3 +355,35 @@ static int CoalesceInt(int? a, int? b) return a ?? b ?? 777; } } + +public struct MediumStructResult +{ + public int Code; + public int Value; +} + +public struct LargeStructResult +{ + public int Reason; + public string Message; + public object Entity; +} + +public static class StructReturnTest +{ + public static MediumStructResult GetMediumResult(int code, int value) + { + return new MediumStructResult { Code = code, Value = value }; + } + + public static LargeStructResult GetLargeResult(int code, string message, object entity) + { + return new LargeStructResult + { + Reason = code, + Message = message, + Entity = entity + }; + } + +}