• 注入Unity mono游戏过程详解


    注入Unity mono游戏过程详解

    AppNinja

    (8条消息) 注入Unity mono游戏过程详解_AppNinja的博客-CSDN博客

    1、用 dnspy 查看 Assembly-CSharp.dll 使用的.net框架版本。

    如图为.NET4

    2、用 vs2010编译.net4的C# 类库工程,编译后生成 UnityPluginDemo.dll

    Cheat.cs代码如下:

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using System.IO;
    6. namespace UnityPluginDemo
    7. {
    8. public class Cheat
    9. {
    10. static void WriteLog(string content)
    11. {
    12. string path = "D:/unityplugin.txt";
    13. FileStream fs = null;
    14. if (File.Exists(path))
    15. {
    16. fs = new FileStream(path, FileMode.Append, FileAccess.Write);
    17. }
    18. else
    19. {
    20. fs = new FileStream(path, FileMode.Create, FileAccess.Write);
    21. }
    22. StreamWriter sw = new StreamWriter(fs);
    23. sw.WriteLine(content);
    24. sw.Close();
    25. fs.Close();
    26. }
    27. public static void Entry()
    28. {
    29. WriteLog("FirstUnityPlugin Enter!");
    30. }
    31. }
    32. }

    3、使用 SharpMonoInjector.Gui,输入类库信息,注入到目标。查看日志 D:/unityplugin.txt 。

    4、调用游戏逻辑类

    在UnityPluginDemo工程添加游戏的3个引用:Assembly-CSharp.dll、UnityEngine.CoreModule.dll、UnityEngine.dll。

    在Cheat.cs中引用头文件:using UnityEngine;

    添加获取游戏对象的代码,查看游戏自己的日志输出。

    1. public static void Entry()
    2. {
    3. WriteLog("FirstUnityPlugin Enter!");
    4. //GameObject player =
    5. PlayerManager.WriteLog("FirstUnityPlugin hook call PlayerManager");
    6. }

    5、使用 MelonLoader install和将UnityExplorer插件放入Mods文件夹查看GameObjects列表。

    工具:MelonLoader.Installer.exe、MelonLoader.x86.zip、UnityExplorer.MelonLoader.Mono

    6、枚举GameObjects,在GameObjectLabel,实现透视游戏对象。

    加载 UnityEngine.IMGUIModule,在OnGUI中实现代码:

    1. public void OnGUI()
    2. {
    3. GUI.Label(new Rect(0, 0, 200, 20), "Hello");
    4. GameObject[] Objs = GameObject.FindObjectsOfType();
    5. foreach (GameObject curObj in Objs)
    6. {
    7. // 3D坐标转变为屏幕坐标
    8. Vector3 pos = curObj.transform.position;
    9. Camera camera = Camera.main;
    10. // 获取屏幕坐标系
    11. Vector3 screenPos = camera.WorldToScreenPoint(pos);
    12. // z是负数,在摄像机的后面,就不需要画了。
    13. if (screenPos.z >= 0)
    14. {
    15. // UGUI坐标系[0,0]在左上角,屏幕坐标系[0,0]在左下角,所以Unity的Y,需要屏幕高-pos.Y
    16. GUI.Label(new Rect(screenPos.x, Screen.height - screenPos.y, 500, 500), curObj.name + ",ScreenH="+Screen.height.ToString() + ",Y=" + screenPos.y.ToString());
    17. }
    18. }
    19. }

    7、使用dnSpy调试游戏

    dnSpy/dnSpy-Unity-mono: Fork of Unity mono that's used to compile mono.dll with debugging support enabled (github.com)

  • 相关阅读:
    网络层五大核心知识点
    SpringBoot:ch03 yml 数据绑定示例
    <1> c++ 笔记 stl::map
    【音视频】AAC音频压缩格式
    python模块报错:‘No module named “Crypto“ ‘
    TOP K的时间复杂度分析
    AGI STK使用本地地形和地图
    记录一次排查视频转码失败原因的经历
    Android进行字符串替换
    LeetCode_排序_二分搜索_双指针_中等_658.找到 K 个最接近的元素
  • 原文地址:https://blog.csdn.net/a2831942318/article/details/126626335