用C#编写游戏脚本
大学宿舍玩游戏的时候,为了简化重复的键鼠动作,有学习过按键精灵和TC脚本开发工具,并做了一些小脚本,基本达到了当时的需求。不知不觉,已经毕业了3年了,无聊之余又玩起了游戏,对于一些无趣的重复行为,于是又想写个脚本来处理下。比如跑任务,自动补血等,没想到现在的游戏对于按键精灵和TC基本上都是封杀。对于我这种小白,过游戏安全检测这种棘手的事,也许花费很多时间,都没有结果。经常测试,发现游戏不会对自己写的C#脚本进行检测,所以决定用C#来写。
研究了几天,突然间又不想玩游戏了,所以把这几天的研究成果分享给大家,希望对后来的人有启发。我玩的是一款QQ的游戏,我想要做的脚本就是 扫货脚本(当有人摆摊价格低于自己预设的价格时,自动购买下来,倒卖)。
经过分析,最难的步骤是怎么识别摊位上的价格,第一感觉,这不就是文字识别吗,于是找了一个.Net 唯一开源的Tesseract-ocr。经过测试,发现Tesseract-ocr只适合白底黑字的文字识别,于是对图片进行了以下处理
- 变灰度图
- 增加亮度100
- 增加对比度100
- 变黑白
- //反向 游戏文字是白色的
/// /// 反像/// /// /// public static Bitmap ApplyInvert(Bitmap source){//create a blank bitmap the same size as originalBitmap newBitmap = new Bitmap(source.Width, source.Height);//get a graphics object from the new imageGraphics g = Graphics.FromImage(newBitmap);// create the negative color matrixColorMatrix colorMatrix = new ColorMatrix(new float[][]{new float[] {-1, 0, 0, 0, 0},new float[] {0, -1, 0, 0, 0},new float[] {0, 0, -1, 0, 0},new float[] {0, 0, 0, 1, 0},new float[] {1, 1, 1, 0, 1}});// create some image attributesImageAttributes attributes = new ImageAttributes();attributes.SetColorMatrix(colorMatrix);g.DrawImage(source, new Rectangle(0, 0, source.Width, source.Height),0, 0, source.Width, source.Height, GraphicsUnit.Pixel, attributes);//dispose the Graphics objectg.Dispose();return newBitmap;}/// /// 图片变成灰度/// /// /// public static Bitmap ToGray(Bitmap b){for (int x = 0; x < b.Width; x++){for (int y = 0; y < b.Height; y++){Color c = b.GetPixel(x, y);int luma = (int)(c.R * 0.3 + c.G * 0.59 + c.B * 0.11);//转换灰度的算法b.SetPixel(x, y, Color.FromArgb(luma, luma, luma));}}return b;}/// /// 图像变成黑白/// /// //
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
