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

Prefix Method Get Skips #59

Closed
krulci opened this issue Jan 10, 2023 · 1 comment
Closed

Prefix Method Get Skips #59

krulci opened this issue Jan 10, 2023 · 1 comment

Comments

@krulci
Copy link

krulci commented Jan 10, 2023

using Elements;
using Grpc.Core;
using HarmonyLib;
using LitJson;
using PrincessInjector;
using PrincessStudioDefinitions;
using System;
using System.Linq;
using System.Net;
using System.Net.Sockets;

namespace _Elements
{
    [HarmonyPatch]
    public class _BaseReceiveParam
    {
        private static string[] GetIps()
        {
            return Dns.GetHostAddresses(Dns.GetHostName()).Where(ip => ip.AddressFamily == AddressFamily.InterNetwork)
                .Select(ip => ip.ToString()).ToArray();
        }

        [HarmonyPatch(typeof(Elements.BaseReceiveParam), nameof(Elements.BaseReceiveParam.ParseBaseReceiveParam))]
        [HarmonyPrefix]

        public static bool ParseBaseReceiveParam(ref BaseReceiveParam __instance, ref JsonData _json)
        {
            Console.WriteLine("ParseBaseReceiveParam(ref BaseReceiveParam __instance, ref JsonData _json)");
            int stage = 0;
            try
            {
                if (_json.Count == 0)
                {
                    return false;
                }

                ++stage;
                if (_json.Keys.Contains("notification"))
                {
                    JsonData jsonData = _json["notification"];
                    if (jsonData != null)
                    {
                        Traverse.Create(__instance).Property("Notification").SetValue( new Notification(jsonData));
                    }
                }
                if (_json.Keys.Contains("update_bank_gold"))
                {
                    Traverse.Create(__instance).Property("UpdateBankGold").SetValue(_json["update_bank_gold"].ToLong());
                }

                ++stage; 
                Console.WriteLine("Before: if (RemoteProcedureCall.PrincessStudioServiceClient == null)");
                if (RemoteProcedureCall.PrincessStudioServiceClient == null)
                {
                    AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
                    Console.WriteLine("AppContext.SetSwitch(\"System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport\", true);");
                    var channel = new Channel(GetIps().First(), 1, ChannelCredentials.Insecure);
                    Console.WriteLine("var channel = new Channel(GetIps().First(), 1, ChannelCredentials.Insecure);");
                    try
                    {
                        Console.WriteLine("PrincessStudioServiceClient = MagicOnionClient.Create<IPrincessStudioService>(channel);");
                        var client = MagicOnion.Client.MagicOnionClient.Create<IPrincessStudioService>(channel);
                    }
                    catch (Exception e) { Console.WriteLine(e.ToString()); }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                throw;
            }
            return false;
        }
    }
}

When adding the line:

var client = MagicOnion.Client.MagicOnionClient.Create<IPrincessStudioService>

This prefix get skips, below is the output. The Error : Unity Log is due to other methods trying to access fields which failed to instantiate due to this prefix being skipped.

[Message:   BepInEx] BepInEx 5.4.21.0 - PrincessConnectReDive (12/28/2022 2:40:55 AM)
[Info   :   BepInEx] Running under Unity v2018.4.36.7132039
[Info   :   BepInEx] CLR runtime version: 4.0.30319.42000
[Info   :   BepInEx] Supports SRE: True
[Info   :   BepInEx] System platform: Bits64, Windows
[Message:   BepInEx] Preloader started
[Info   :   BepInEx] Loaded 1 patcher method from [BepInEx.Preloader 5.4.21.0]
[Info   :   BepInEx] 1 patcher plugin loaded
[Info   :   BepInEx] Patching [UnityEngine.CoreModule] with [BepInEx.Chainloader]
[Message:   BepInEx] Preloader finished
[Message:   BepInEx] Chainloader ready
[Message:   BepInEx] Chainloader started
[Debug  :   BepInEx] Skipping loading C:\Users\_\priconner\BepInEx\plugins\grpc_csharp_ext.dll because it's not a valid .NET assembly. Full error: Format of the executable (.exe) or library (.dll) is invalid.
[Info   :   BepInEx] 1 plugins to load
[Info   :   BepInEx] Loading [PrincessInjector by Azatoi.Ichigo 1.0.1.0]
[Message:   BepInEx] Chainloader startup complete
[Info   : Unity Log] Injected generated tally into coneshell
[Error  : Unity Log] NullReferenceException: Object reference not set to an instance of an object
Stack trace:
Elements.ViewTitle+<onClickAfterProcess>d__25.MoveNext () (at <3d3cfcf9b4344767bc3e3387ad42e91b>:0)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <2774ccc3e0de4aef8525f5fbd178bef1>:0)

When MagicOnionClient line is removed, below is the proper output:

[Message:   BepInEx] BepInEx 5.4.21.0 - PrincessConnectReDive (12/28/2022 2:40:55 AM)
[Info   :   BepInEx] Running under Unity v2018.4.36.7132039
[Info   :   BepInEx] CLR runtime version: 4.0.30319.42000
[Info   :   BepInEx] Supports SRE: True
[Info   :   BepInEx] System platform: Bits64, Windows
[Message:   BepInEx] Preloader started
[Info   :   BepInEx] Loaded 1 patcher method from [BepInEx.Preloader 5.4.21.0]
[Info   :   BepInEx] 1 patcher plugin loaded
[Info   :   BepInEx] Patching [UnityEngine.CoreModule] with [BepInEx.Chainloader]
[Message:   BepInEx] Preloader finished
[Message:   BepInEx] Chainloader ready
[Message:   BepInEx] Chainloader started
[Debug  :   BepInEx] Skipping loading C:\Users\_\priconner\BepInEx\plugins\grpc_csharp_ext.dll because it's not a valid .NET assembly. Full error: Format of the executable (.exe) or library (.dll) is invalid.
[Info   :   BepInEx] 1 plugins to load
[Info   :   BepInEx] Loading [PrincessInjector by Azatoi.Ichigo 1.0.1.0]
[Message:   BepInEx] Chainloader startup complete
[Info   : Unity Log] Injected generated tally into coneshell
[Info   :   Console] ParseBaseReceiveParam(ref BaseReceiveParam __instance, ref JsonData _json)
[Info   :   Console] Before: if (RemoteProcedureCall.PrincessStudioServiceClient == null)
[Info   :   Console] AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
[Info   :   Console] var channel = new Channel(GetIps().First(), 1, ChannelCredentials.Insecure);
[Info   :   Console] PrincessStudioServiceClient = MagicOnionClient.Create<IPrincessStudioService>(channel);
@ManlyMarco
Copy link
Member

Looks like your patch crashes or references missing types, it's very unlikely to be a problem with harmony.

@krulci krulci closed this as completed Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants