- 注:本文仅分享逆向过程及思路,切勿用于非法用途!
- 教程适用范围:在Steam购买并下载基于Unity引擎的单机游戏
- 工具:dnSpy(反编译dll) 实验目标:免Steam启动游戏,或在没购买或没Steam的电脑上启动。
当你正在没有网络的机房上水课,如果你玩腻了赛博灯泡,或者是%0|%0(内存泄露程序),那就试试在U盘自带一些经典的单机小游戏吧!

我们知道,Steam上下载的游戏必须要通过Steam(且登陆了拥有此游戏的账号)才能打开,如果把整个游戏文件夹复制到另一台电脑上,会提示无法运行,或弹出Steam并显示您的账号未拥有此游戏。所以需要跟着下面的步骤,来达到实验目标吧!
一 . 判断Unity引擎

一般通过文件结构判断基于Unity引擎的游戏,当游戏目录下存在“游戏名”,以及“游戏名_Data”,那么这个游戏很大概率就是基于Unity引擎制作的。

二 . 逆向分析
根据查询资料得知Steam 里的Unity游戏的启动参数都存在于/"游戏名_Data"/Managed/Assembly-CSharp.dll里,所以我们需要反编译这个dll,尝试在里面删除有关检测Steam的代码。
以下将以“非常普通的鹿”为演示

1.打开dnSpy工具

2.导入文件
将Assembly-CSharp.dll拖入DnSpy中

拖入后,可以看到,dll的源码已经反编译出来了(这也说明这个dll没有被混淆或加密)

3.搜索
按下Ctrl+F,直接搜索与Steam相关的类

选择可疑的类,在源码中寻找与启动相关的代码。当然本文已经找出相关代码位于SteamManager类中。

查看类中的代码,找到Awake函数
三 . 分析代码
// 在游戏启动时执行 ...C#
protected virtual void Awake()
{
if (SteamManager.s_instance != null)
{
UnityEngine.Object.Destroy(base.gameObject);
return;
}
SteamManager.s_instance = this;
if (SteamManager.s_EverInitialized)
{
throw new Exception("Tried to Initialize the SteamAPI twice in one session!");
}
UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
if (!Packsize.Test())
{
Debug.LogError("[Steamworks.NET] Packsize Test returned false, the wrong version of Steamworks.NET is being run in this platform.", this);
}
if (!DllCheck.Test())
{
Debug.LogError("[Steamworks.NET] DllCheck Test returned false, One or more of the Steamworks binaries seems to be the wrong version.", this);
}
try
{
if (SteamAPI.RestartAppIfNecessary(AppId_t.Invalid))
{
Application.Quit();
return;
}
}
catch (DllNotFoundException ex)
{
string str = "[Steamworks.NET] Could not load [lib]steam_api.dll/so/dylib. It's likely not in the correct location. Refer to the README for more details.\n";
DllNotFoundException ex2 = ex;
Debug.LogError(str + ((ex2 != null) ? ex2.ToString() : null), this);
Application.Quit();
return;
}
this.m_bInitialized = SteamAPI.Init();
if (!this.m_bInitialized)
{
Debug.LogError("[Steamworks.NET] SteamAPI_Init() failed. Refer to Valve's documentation or the comment above this line for more information.", this);
return;
}
SteamManager.s_EverInitialized = true;
}
以上为打开游戏后,所运行的程序,我们需要关注的是try字段的代码
try
{
// 判断是否继续运行游戏
if (SteamAPI.RestartAppIfNecessary(AppId_t.Invalid))
{
Application.Quit();//退出程序
return;
}
}
catch (DllNotFoundException ex)
{
// 捕获动态链接库未找到异常,输出错误信息并退出应用程序
string errorMessage = "[Steamworks.NET] 无法加载 [lib]steam_api.dll/so/dylib。可能未放置在正确的位置。查阅 README 获取更多详细信息。\n";
Debug.LogError(errorMessage + ex.ToString(), this);
Application.Quit();//退出
return;
}
我们先分析if里面的SteamAPI.RestartAppIfNecessary,这个全局变量位于Steamapi中

此处的代码会检查当前平台是否支持 Steamworks(即是否正确安装Steam),如果有Steam,后面的代码大致意思就是判读你的账户里有没有这个游戏的ID(买了没有)。

分析完代码的含义后,我们只需要把Awake里会阻止我们继续运行的Application.Quit();删除即可。
四. 删除代码

DnSpy编辑此代码需要右键,选择编辑类,在里面删除即可

删除完成后点击右下角编译

然后在左上角文件中选择全部保存

五 . 验证
直接点击确定即可

在其他设备上测试,没有Steam或者没购买此游戏的设备也能正常运行游玩(不过不能连接到Steam云。
通过反编译游戏代码,删除与Steam账户和游戏ID检测相关的部分,实现在没有Steam或未购买的电脑上运行游戏。不过,在享受游戏的同时,还是应当支持正版并尊重开发者劳动成果。
Comments NOTHING