9
24
2010
3

C#:Ruby文件IO

目前功能尚不完全。仅作备份

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

namespace Marshal
{
    public partial class Marshal
    {
        static BinaryWriter w_stream;
        static Dictionary<rb_Symbol, int> w_symbols = new Dictionary<rb_Symbol, int> { };
        static Dictionary<object, int> w_objects = new Dictionary<object, int> { };
        static StringBuilder write_str;
        static public string rb_marshal_dump(object data, Stream s = null)
        {
            w_symbols.Clear();
            w_objects.Clear();
            write_str = new StringBuilder();
            dump(data);
            if (s != null && s.CanWrite)
            {
                w_stream = new BinaryWriter(s);
                foreach (byte i in write_str.ToString())
                {
                    s.WriteByte(i);
                }
            }
            return write_str.ToString();
        }
        static void dump(object ob, bool _pass = false)
        {
            if (!_pass)
            {
                write_str.Append((char)4);
                write_str.Append((char)8);
            }
            // 第一操作 请求Objects(Symbol判定已经排除)
            if (!(ob is int || ob is long || ob is rb_Nil || ob is bool || ob is rb_Symbol))
            {
                if (w_objects.ContainsKey(ob))
                {
                    write_str.Append((char)64);
                    writeint(w_objects[ob]);
                    return;
                }
            }
            // 第二操作 顺序输入存储 
            if (ob is long || ob is int)
            {
                write_str.Append((char)105);
                long i = Convert.ToInt64(ob);
                writeint(i);
            }
            else if (ob is string)
            {
                string s = (string)ob;
                write_str.Append((char)34);
                writestr(s);
            }
            else if (ob is rb_Symbol)
            {
                rb_Symbol sy = (rb_Symbol)ob;
                writesym(sy);
            }
            else if (ob is rb_Nil)
            {
                write_str.Append((char)48);
            }
            else if (ob is rb_Object)
            {
                writeobject((rb_Object)ob);
            }
            else if (ob is bool)
            {
                write_str.Append((char)((bool)ob ? 84 : 70));
            }

            else if (ob is rb_Table)
            {
                writeTable((rb_Table)ob);
            }
            else if (ob is object[])
            {
                writearray((object[])ob);
            }
            else if (ob is float || ob is double)
            {
                write_float((double)ob);
            }
            else
            {
                throw new Exception(ob.GetType().ToString());
            }
        }
        static List<rb_Symbol> r_symbols = new List<rb_Symbol> { };
        static List<object> r_objects = new List<object> { };
        static BinaryReader r_stream;
        static public object rb_marshal_load(Stream s)
        {
            if (!s.CanRead)
            { return null; }
            r_symbols.Clear();
            r_objects.Clear();
            r_stream = new BinaryReader(s);
            return read();
        }
        static object read(bool _pass = true)
        {
            if (_pass)
            {
                r_stream.Read();
                r_stream.Read();
            }
            object gotten;
            byte c = r_stream.ReadByte();
            long length = 0; int i = 0; object[] a;
            switch (c)
            {
                case 34:               // " 字符串
                    gotten = readstr(); break;
                case 48:               // 0 NIL
                    return new rb_Nil();
                case 47:               // '/' 正则表达式
                    string re = readstr();
                    int options = r_stream.ReadByte();
                    RegexOptions reg = RegexOptions.None;
                    if (options >= 4) { reg |= RegexOptions.Multiline; options -= 4; }
                    if (options >= 2) { reg |= RegexOptions.IgnorePatternWhitespace; options -= 2; }
                    if (options >= 1) { reg |= RegexOptions.IgnoreCase; options -= 1; }
                    gotten = new Regex(re, reg);
                    break;
                case 58:               // : 符号
                    return readsym();
                case 59:               // ; 符号引用
                    i = (int)readint();
                    return r_symbols[i];
                case 64:               // @ 物体引用
                    i = (int)readint();
                    return r_objects[i];
                case 70:               // F 伪值
                    return false;
                case 73:               // I 扩展自定义类
                    rb_expand_Object oba = new rb_expand_Object();
                    oba.real = read(false);
                    length = readint();
                    for (int j = 0; j < length; j++)
                    {
                        oba.variables[(rb_Symbol)read(false)] = read(false);
                    }
                    gotten = oba; break;
                case 84:               // T 真
                    return true;
                case 91:               // [ 数组
                    length = readint();
                    a = new object[length];
                    r_objects.Add(a);
                    for (int j = 0; j < length; j++)
                    {
                        a[j] = read(false);
                    }
                    return a;
                case 102:            // f 浮点
                    gotten = Convert.ToSingle(readstr()); break;
                case 105:              // i 整数
                    return readint();
                case 111:              // o 自定义类
                    rb_Object ob = new rb_Object();
                    r_objects.Add(ob);
                    ob.class_name = (rb_Symbol)read(false);
                    length = readint();
                    for (int j = 0; j < length; j++)
                    {
                        ob.variables[(rb_Symbol)read(false)] = read(false);
                    }
                    return ob;
                case 117:             // Table
                    string s = ((rb_Symbol)read(false)).getStr();
                    if (s == "Table")
                    {
                        long check1 = readint();
                        int d = readint4();
                        int x = readint4();
                        int y = readint4();
                        int z = readint4();
                        int check2 = readint4();
                        rb_Table array = new rb_Table(d, x, y, z);
                        for (int j = 0; j < z; j++)
                        {
                            for (int k = 0; k < y; k++)
                            {
                                for (int l = 0; l < x; l++)
                                {
                                    array.value[l, k, j] = readint4(2);
                                }
                            }
                        }
                        gotten = array;
                        break;
                    }
                    else
                    { throw new Exception("不支持的用户定义类型:" + s); }
                case 123:
                    Dictionary<Object, Object> dictionary = new Dictionary<object, object> { };
                    length = readint();
                    for (int j = 0; j < length; j++)
                    {
                        dictionary[read(false)] = read(false);
                    }
                    gotten = dictionary; break;
                default:
                    throw new Exception("不可预知的标识符:" + (char)c);
            }

            r_objects.Add(gotten);
            return gotten;
        }
    }
    public class rb_Symbol
    {
        string real;
        public rb_Symbol(string s)
        {
            real = s;
        }
        public override string ToString()
        {
            return ":" + real;
        }
        public string getStr()
        {
            return real;
        }
    }
    public class rb_Table
    {
        public readonly int size;
        public int[, ,] value;
        public rb_Table(int size, int x_size, int y_size = 1, int z_size = 1)
        {
            this.size = size;
            value = new int[x_size, y_size, z_size];
        }
        int get_Value(int x, int y, int z)
        {
            return value[x, y, z];
        }
        public override string ToString()
        {
            string s = "Ruby::Table{Size = ";
            s += size.ToString() + "} [";
            for (int i = 0; i < value.GetLength(2); i++)
            {
                s += "[";
                for (int j = 0; j < value.GetLength(1); j++)
                {
                    s += "[";
                    for (int k = 0; k < value.GetLength(0); k++)
                    {
                        s += value[k,j,i].ToString() + "  ";
                    }
                    s += "]";
                }
                s += "]";
            }
            s += "]";
            return s;
        }
    }
    public class rb_Object
    {
        public Dictionary<rb_Symbol, Object> variables = new Dictionary<rb_Symbol, object> { };
        public rb_Symbol class_name { get; set; }
        override public string ToString()
        {
            string s = "#<" + class_name + "> {";
            foreach (rb_Symbol i in variables.Keys)
            {
                s += (i + " = " + variables[i] + " ");
            }
            s += "}";
            return s;
        }
    }
    public class rb_expand_Object : rb_Object
    {
        public object real { get; set; }
        override public string ToString()
        {
            string s = "#<" + class_name + "> [" + real.ToString() + "]{";
            foreach (rb_Symbol i in variables.Keys)
            {
                s += (i + " = " + variables[i] + " , ");
            }
            s += "}";
            return s;
        }
    }
    public class rb_Nil : rb_Object
    {
        public override String ToString()
        { return "Ruby::Nil"; }
    }
}

第二代码

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Marshal
{
    public partial class Help
    {
        public class TrueStrLength
        {
            public TrueStrLength() { }
            static public int trueLength(string str)
            {
                int lenTotal = 0;
                int n = str.Length;
                string strWord = "";
                int asc;
                for (int i = 0; i < n; i++)
                {
                    strWord = str.Substring(i, 1);
                    asc = Convert.ToChar(strWord);
                    if (asc < 0 || asc > 127)
                        lenTotal = lenTotal + 3;
                    else
                        lenTotal = lenTotal + 1;
                }

                return lenTotal;
            }
            static public string cutTrueLength(string strOriginal, int maxTrueLength, char chrPad, bool blnCutTail)
            {
                string strNew = strOriginal;
                if (strOriginal == null || maxTrueLength <= 0)
                {
                    strNew = "";
                    return strNew;
                }

                int trueLen = trueLength(strOriginal);
                if (trueLen > maxTrueLength)
                {
                    if (blnCutTail)
                    {
                        for (int i = strOriginal.Length - 1; i > 0; i--)
                        {
                            strNew = strNew.Substring(0, i);
                            if (trueLength(strNew) == maxTrueLength)
                                break;
                            else if (trueLength(strNew) < maxTrueLength)
                            {
                                strNew += chrPad.ToString();
                                break;
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < maxTrueLength - trueLen; i++)
                    {
                        strNew += chrPad.ToString();
                    }
                }

                return strNew;
            }
        }
    }
    partial class Help
    {
        public static string Dictionary_String(Dictionary<Object, Object> d)
        {
            string s = "{";
            foreach (object i in d.Keys)
            {
                s += (i + " => " + d[i] + " , ");
            }
            s += "}";
            return s;
        }
        public static string Array_String(object[] ar)
        {
            string s = "[";
            foreach (object i in ar)
            {
                s += ((i.GetType() == ar.GetType()) ? Array_String((object[])i) : i.ToString()) + ",";
            }
            return s + "]";
        }
    }
}
namespace Marshal
{
    partial class Marshal
    {
        static void writeint(long i)
        {
            if (i > 122)
            {
                write_str.Append((char)Math.Ceiling(Math.Log(i, 256f)));
                while (i > 0)
                {
                    write_str.Append((char)(i & 0xff));
                    i = i >> 8;
                }
            }
            else if (i > 0)
            {
                write_str.Append((char)(i + 5));
            }
            else if (i == 0)
            {
                write_str.Append((char)0);
            }
            else if (i >= -123)
            {
                write_str.Append((char)(i - 5));
            }
            else
            {
                long t = ~i;
                write_str.Append((char)(sbyte)Math.Ceiling((Math.Log(t, 256))) * (-1));
                while (t > 0)
                {
                    write_str.Append((char)(t & 0xff));
                    t = t >> 8;
                }
            }
        }
        static void writestr(string s)
        {
            byte[] cs = Encoding.Unicode.GetBytes(s);
            byte[] bt = Encoding.Convert(Encoding.Unicode, Encoding.UTF8, cs);
            string st = Encoding.UTF8.GetString(bt);
            writeint(Help.TrueStrLength.trueLength(st));
            //System.Windows.Forms.MessageBox.Show(st + (st == s).ToString());
            //write_str.Append(st);
            foreach (byte i in bt)
            {
                write_str.Append((char)i);
            }
        }
        static void writearray(object[] ar)
        {
            write_str.Append((char)91);
            writeint(ar.Length);
            foreach (object i in ar)
            {
                dump(i, true);
            }
        }
        static void writeobject(rb_Object o)
        {
            write_str.Append((char)111);
            writesym(o.class_name);
            writeint(o.variables.Count);
            foreach (rb_Symbol i in o.variables.Keys)
            {
                writesym(i);
                dump(o.variables[i], true);
            }
        }
        static void writesym(rb_Symbol s)
        {
            // 符号序列检查
            if (w_symbols.ContainsKey(s))
            {
                int index = w_symbols[s];
                write_str.Append((char)59);
                writeint(index);
            }
            else
            {
                write_str.Append((char)58);
                writestr(s.getStr());
                w_symbols[s] = w_symbols.Count;
            }
        }
        static void writeTable(rb_Table t)
        {

            write_str.Append((char)117);
            writesym(new rb_Symbol("Table"));
            int x = t.value.GetLength(0);
            int y = t.value.GetLength(1);
            int z = t.value.GetLength(2);
            writeint(x * y * z * 2 + 20);
            write_str.Append(special_num(t.size));
            write_str.Append(special_num(x));
            write_str.Append(special_num(y));
            write_str.Append(special_num(z));
            write_str.Append(special_num(x * y * z));
            for (int i = 0; i < z; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    for (int k = 0; k < x; k++)
                    {
                        
                        write_str.Append(special_num(t.value[k, j, i],2));
                    }
                }
            }
        }
        static string special_num(int num,int length = 4)
        {
            string s = "";
            int count = 0;
            while (num != 0)
            {
                s = (char)(num % 256) + s;
                num = num >> 8;
                count += 1;
                if (count >= length) { break; }
            }
            for (int j = 0; j < length - count; j++)
            {
                s = (char)0 + s;
            }
            return s;
        }
        static void write_float(double f)
        {
            write_str.Append((char)102);
            writestr(string.Format("{0:g}", f));
        }
        static long readint()
        {
            sbyte c = r_stream.ReadSByte();
            if (c <= -5)
            { return c + 5; }
            else if (c < 0)
            {
                long g = 0;
                for (int i = 0; i < -c; i++)
                {
                    int t = 255 - r_stream.ReadByte();
                    g = g + (t << (8 * i));
                }
                return -g - 1;
            }
            else if (c == 0)
            { return 0; }
            else if (c <= 4)
            {
                long g = 0;
                for (int i = 0; i < c; i++)
                {
                    int t = r_stream.ReadByte();
                    g = g + (t << (8 * i));
                }
                return g;
            }
            else
            { return c - 5; }
        }
        static string readstr()
        {
            long l = readint();
            byte[] cs = new byte[l];
            for (int i = 0; i < l; i++)
            { cs[i] = r_stream.ReadByte(); }
            UnicodeEncoding uni = new UnicodeEncoding();
            UTF8Encoding utf = new UTF8Encoding();
            byte[] bt = Encoding.Convert(Encoding.UTF8, Encoding.Unicode, cs);
            return uni.GetString(bt);
        }
        static rb_Symbol readsym()
        {
            rb_Symbol s = new rb_Symbol(readstr());
            r_symbols.Add(s);
            return s;
        }
        static int readint4(int d = 4)
        {
            int g = 0;
            for (int i = 0; i < d; i++)
            {
                int t = r_stream.ReadByte();
                g = g + (t << (8 * i));
            }
            return g;
        }
    }
}
Category: RM | Tags: c# io ruby
9
23
2010
1

RM通用:搞瞎你的眼睛

是的,乃没看错,这个脚本是用来搞瞎你的眼睛的,加入任意工程执行即可。

 

def calc(x,y)
  a = 0
  a += 2 if 3 * x + 8 * y > 3600
  a += 1 if 3 * x - 2 * y > 600
  case a
  when 0
    return 7 if 3 * x - 8 * y > -1200
    return 4
  when 3
    return 6 if 3 * x - 8 * y > -1200
    return 3
  when 1
    return 9 if 3 * x + 2 * y > 1800
    return 8
  when 2
    return 2 if 3 * x + 2 * y > 1800
    return 1
  end
end

h = {
1 => Color.new(255,0,0),
2 => Color.new(0,255,0),
3 => Color.new(0,0,255),
4 => Color.new(255,255,0),
6 => Color.new(255,0,255),
7 => Color.new(255,255,255),
8 => Color.new(0,255,255),
9 => Color.new(0,0,0)
}
Graphics.frame_rate = 120
s = Sprite.new
s.bitmap = Bitmap.new(640,480)
for i in 0..640
  for j in 0..480
    c = h[calc(i,j)]
    c.alpha = 255 - (i - 400).abs * (j - 300).abs * 255 / (200 * 480)
    s.bitmap.set_pixel(i,j,c)
  end
    Graphics.update
end  
s.ox = s.x = 320
s.oy = s.y = 240
loop do
  for i in 0..20
    s.zoom_x += 0.1
    s.zoom_y += 0.02
    s.opacity -= 10
    Graphics.update
  end
  for i in 0..20
    s.zoom_x -= 0.1
    s.zoom_y -= 0.02
    s.opacity += 10
    Graphics.update
  end
end
exit
Category: RM | Tags: XP VX
9
23
2010
2

RM通用:鼠标定位脚本。

这个脚本用于随时按下Shift定位鼠标位置。

 

module Stop
  @@bitmap = Bitmap.new(640 * 2 + 1,480 * 2 + 1)
  @@bitmap.fill_rect(640,0,1,960,Color.new(255,0,0))
  @@bitmap.fill_rect(0,480,1280,1,Color.new(255,0,0))
  @@viewport = Viewport.new(0,0,640,480)
  @@viewport.z = 2000
  @@sprite = Sprite.new(@@viewport)
  @@sprite.bitmap = @@bitmap
  @@sprite.visible = false
  @@help_bitmap = Bitmap.new(200,48)
  @@help_bitmap.font.color = Color.new(255,255,0)
  @@help_sprite = Sprite.new(@@viewport)
  @@help_sprite.bitmap = @@help_bitmap
  @@help_sprite.visible = false
  def self.main
    @@sprite.visible = true
    @@help_sprite.visible = true
    @@sprite.x = -320
    @@sprite.y = -240
    begin
      Graphics.update
      Mouse.update
      a = Mouse.pixels
      @@sprite.x = a[0] - 640
      @@sprite.y = a[1] - 480
      @@help_bitmap.clear
      @@help_bitmap.draw_text(0,0,200,48,"[#{a[0].to_s},#{a[1].to_s}]")
    end until Mouse.press?(3) or Mouse.press?(2) or Mouse.press?(1)
    @@sprite.visible = false 
    @@help_sprite.visible = false
  end
end

class <<Input
  alias stop_update_add update unless method_defined?("stop_update_add")
  def update
    stop_update_add
    if Input.trigger?(Input::SHIFT)
      Stop.main
    end
  end
end

需要一个鼠标脚本。如下:

 

#==============================================================================
# ** 鼠标输入模块
#------------------------------------------------------------------------------
#   微调 by zh99998
#   版本 1.2a
#   06-30-2010
#   修复press判定
#   基于沉影的鼠标系统修改版alpha
#------------------------------------------------------------------------------
#   by DerVVulfman
#   版本 1.2
#   08-18-2007
#------------------------------------------------------------------------------
#   建立在鼠标输入模块...
#
#   by Near Fantastica
#------------------------------------------------------------------------------
#   Set_Pos feature by
#   Freakboy
#------------------------------------------------------------------------------
#
#   CALLS: 
#
#   Mouse.click?
#   判断鼠标是否真的按下(Ture/False).
#   这个值控制您按下的是左/右键,还是中键

#
#   Mouse.press?
#   判断鼠标是否真的按下/保持按下状态
#   这个值控制您按下的是左/右键,还是中键
#   Mouse.pixels
#   Mouse.pixels
#   这个值返回鼠标所在的坐标(640*480大小),如果鼠标超出游戏画面,这个值为空
#
#   Mouse.tiles
#   This returns  the mouse's screen  coordinates  in map tiles.   Based on the
#   system's 20x15 tile size,  this returns it in index values  (a 0-19 width & 
#   a 0-14 height).  This functions the same manner as Mouse.pixels.
#
#   Mouse.set_pos
#   This allows you  to forcefully position the mouse at an x/y position within
#   the game screen by pixel coordinates.  Given the game's normal screen width
#   of 640x480, adding:  Mouse.set_pos(320,240)  should position the mouse dead
#   center of the gaming window.
#
#   Mouse.update
#   Add this routine  into your update routines  to update  the mouse position.
#   It must be called otherwise you won't get valid mouse coordinates.
#
#==============================================================================

module Mouse
  #--------------------------------------------------------------------------
  # ## 常量
  #--------------------------------------------------------------------------
  GetAsyncKeyState = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
  GetKeyState = Win32API.new("user32","GetKeyState",['i'],'i')
  
  ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'lp', 'i')
  
  GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  GetClientRect = Win32API.new('user32', 'GetClientRect', 'lp', 'i')
  
  #--------------------------------------------------------------------------
  # * Mouse Click
  #     button      : button
  #--------------------------------------------------------------------------
  def Mouse.click?(button)
    return false if button == 1 and !$click_abled
    return true if @keys.include?(button)
    return false
  end  
  #--------------------------------------------------------------------------
  # * Mouse Pressed
  #     button      : button
  #--------------------------------------------------------------------------
  def Mouse.press?(button)
    return true if @press.include?(button)
    return false
  end
  #--------------------------------------------------------------------------
  # * Mouse Pressed
  #     button      : button
  #--------------------------------------------------------------------------
  def Mouse.area?(x, y, width=32, height=32)
    return false if @pos == nil
    return true if @pos[0] >= x and @pos[0] <= (x+width) and @pos[1] >= y and @pos[1] <= (y+height)
    return false
  end
  #--------------------------------------------------------------------------
  # * Mouse Pixel Position
  #--------------------------------------------------------------------------
  def Mouse.pixels
    return @pos == nil ? [0, 0] : @pos
  end
  #--------------------------------------------------------------------------
  # * Mouse Tile Position
  #--------------------------------------------------------------------------
  def Mouse.tiles
    return nil if @pos == nil
    x = @pos[0] / 32
    y = @pos[1] / 32
    return [x, y]
  end
  #--------------------------------------------------------------------------
  # * Set Mouse Position
  #-------------------------------------------------------------------------- 
  def Mouse.set_pos(x_pos=0, y_pos=0)
    width, height = Mouse.client_size
    if (x_pos.between?(0, width) && y_pos.between?(0, height))
      x = Mouse.client_pos[0] + x_pos; y = Mouse.client_pos[1] + y_pos
      Win32API.new('user32', 'SetCursorPos', 'NN', 'N').call(x, y)
    end
  end
  #--------------------------------------------------------------------------
  # * Mouse Update
  #--------------------------------------------------------------------------
  def Mouse.update
    @pos            = Mouse.pos
    @keys, @press   = [], []
    @keys.push(1)   if GetAsyncKeyState.call(1) & 0X01 == 1
    @keys.push(2)   if GetAsyncKeyState.call(2) & 0X01 == 1
    @keys.push(3)   if GetAsyncKeyState.call(4) & 0X01 == 1
    @press.push(1)  if GetKeyState.call(1) > 1
    @press.push(2)  if GetKeyState.call(2) > 1
    @press.push(3)  if GetKeyState.call(4) > 1
    ## 鼠标双击
    @wait ||= 0
    @wait += 1 if @key != nil
    (@key = nil; @wait = 0) if @wait > 30 # 双击时间
  end  
  #--------------------------------------------------------------------------
  # * Automatic functions below 
  #--------------------------------------------------------------------------
  #
  #--------------------------------------------------------------------------
  # * Obtain Mouse position in screen
  #--------------------------------------------------------------------------
  def Mouse.global_pos
    pos = [0, 0].pack('ll')
    if GetCursorPos.call(pos) != 0
      return pos.unpack('ll')
    else
      return nil
    end
  end
  #--------------------------------------------------------------------------
  # * Return Screen mouse position within game window
  #--------------------------------------------------------------------------
  def Mouse.pos
    x, y = Mouse.screen_to_client(*Mouse.global_pos)
    width, height = Mouse.client_size
    begin
      if (x >= 0 and y >= 0 and x < width and y < height)
        return x, y
      else
        return nil
      end
    rescue
      return nil
    end
  end
  #--------------------------------------------------------------------------
  #  * Pass Screen to Game System
  #--------------------------------------------------------------------------
  def Mouse.screen_to_client(x, y)
    return nil unless x and y
    pos = [x, y].pack('ll')
    if ScreenToClient.call(HWND, pos) != 0
      return pos.unpack('ll')
    else
      return nil
    end
  end
  #--------------------------------------------------------------------------
  # * Get Game Window Size
  #--------------------------------------------------------------------------
  def Mouse.client_size
    rect = [0, 0, 0, 0].pack('l4')
    GetClientRect.call(HWND, rect)
    right, bottom = rect.unpack('l4')[2..3]
    return right, bottom
  end
  #--------------------------------------------------------------------------
  # * Get Window Position
  #--------------------------------------------------------------------------
  def Mouse.client_pos
    rect = [0, 0, 0, 0].pack('l4')
    ## 用户区
    GetClientRect.call(HWND, rect)
    left, upper = rect.unpack('l4')[0..1]
    return left, upper
  end
  #--------------------------------------------------------------------------
  # ## 句柄
  #--------------------------------------------------------------------------
  def Mouse.get_hwnd
    game_name = "\0" * 256
    Win32API.new('kernel32', 'GetPrivateProfileStringA', 'pppplp', 'l').call('Game','Title','',game_name,255,".\\Game.ini")
    game_name.delete!("\0")
    return Win32API.new('user32', 'FindWindowA', 'pp', 'l').call('RGSS Player',game_name)
  end
  #--------------------------------------------------------------------------
  # ## 双击
  #--------------------------------------------------------------------------
  def self.double_click?(key)
    if @keys.include?(key)
      @key !=key ? (@key = key; return false) : (@key = nil; return true)
    end
  end
  ## 句柄常量
  HWND = Mouse.get_hwnd
  
  ###############
  GetMessage = Win32API.new('user32','GetMessage','plll','l')
  
  Point = Struct.new(:x, :y)
  Message = Struct.new(:message, :wparam, :lparam, :pt)
  Param = Struct.new(:x, :y, :scroll)
  
  def self.scroll
    msg = "\0"*32
    GetMessage.call(msg,0,0,0)
    r = wmcallback(unpack_msg(msg))
    return r unless r.nil?
  end
  
  def wmcallback(msg)
    return unless msg.message == Scroll
    param = Param.new
    param.x = word2signed_short(loword(msg.lparam))
    param.y = word2signed_short(hiword(msg.lparam))
    param.scroll = word2signed_short(hiword(msg.wparam))
    return [param.x,param.y,param.scroll]
  end
  
  def hiword(dword)
    ###return ((dword&0xffff0000)>>16)&0x0000ffff
    return (dword & 0xffff0000) / 0x10000
  end
  
  def loword(dword)
    return dword&0x0000ffff
  end
end
Category: RM | Tags: VX XP
9
23
2010
1

VX存档自动缩进脚本

这个脚本用于在VX上动态显示存档窗体。

MINUS = 32
STEPS = 2
class Scene_File
  alias fxxx_create create_savefile_windows
  def create_savefile_windows
    fxxx_create
    @savefile_windows[1].height -= MINUS
    @savefile_windows[2].height -= MINUS
    @savefile_windows[3].height -= MINUS
    @savefile_windows[1].y -= MINUS * 0
    @savefile_windows[2].y -= MINUS * 1
    @savefile_windows[3].y -= MINUS * 2
    @savefile_windows[1].follow = @savefile_windows[0]
    @savefile_windows[2].follow = @savefile_windows[1]
    @savefile_windows[3].follow = @savefile_windows[2]
  end
  def cursor_down(wrap)
    last = @savefile_windows[@index]
    if @index < @item_max - 1 or wrap
      @index = (@index + 1) % @item_max
    end
    now = @savefile_windows[@index]
    for i in 0..MINUS / STEPS
      last.height -= STEPS
      now.height  += STEPS
      @savefile_windows[1].update
      @savefile_windows[2].update
      @savefile_windows[3].update
      Graphics.update
    end
  end
  def cursor_up(wrap)
    last = @savefile_windows[@index]
    if @index > 0 or wrap
      @index = (@index - 1 + @item_max) % @item_max
    end
    now = @savefile_windows[@index]
    for i in 0..MINUS / STEPS
      last.height -= STEPS
      now.height  += STEPS
      @savefile_windows[1].update
      @savefile_windows[2].update
      @savefile_windows[3].update
      Graphics.update
    end
  end
end

class Window_SaveFile
  attr_accessor :follow
  alias fxxx_update update
  def update
    fxxx_update
    if @follow != nil
      self.y = @follow.y + @follow.height
    end
  end
end
Category: RM | Tags: VX
6
26
2010
67

RMXP:地图链接重置

这个脚本用于自动重建RMXP地图链表。

 

data = load_data("Data/MapInfos.rxdata")
files = Dir["Data/Map???.r?data"]
names = []
for i in data.keys
  names.push sprintf("Data/Map%03d.rxdata",i)
end
files -= names
for i in files
  i.gsub!(/Data\/Map(.+?).rxdata/) { "" }
  id = $1.to_i
  data[id] = RPG::MapInfo.new
  data[id].name = sprintf("地图 %03d",id)
end
save_data(data,"Data/MapInfos.rxdata")
Category: RM | Tags: XP

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com