Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=============================================================================
- # *** AWorks Library(ALibrary)
- #=============================================================================
- # Created by AWorks
- # Version: 1.03
- # Last Modification: 26/01/2009 (day/month/year)
- # Compatible with RMXP & RMVX
- #=============================================================================
- #==== Description ====
- # This script is a compilation of useful tools created and designed for their
- # use in the AWorks scripts. However, some functions may be useful for other
- # purposes and scripts.
- #=============================================================================
- #==== Credits ====
- # * Ruby 1.8
- # - Win32::Registry class, base of AWorks::Registry
- # * Nishikawa, Yasuhiro
- # - APIs for AWorks::Clipboard
- #=============================================================================
- #==== Requeriments ====
- # * AWorks.dll (Place it on the game folder)
- # - Version: 1.00
- #=============================================================================
- #==== Features ====
- # * AWorks::Ini.get_string(id[, tag[, file]])
- # Gets the string of the id field from the tag section from a .ini file.
- #
- # * AWorks::Ini.set_string(string, id, [, tag[, file]])
- # Sets the string of the id field from the tag section from a .ini file.
- #
- # * AWorks::Clipboard.read
- # Gets the clipboard data.
- #
- # * AWorks::Clipboard.write(string)
- # Sets the string to the clipboard data.
- #
- # * AWorks::Clipboard.empty
- # Empties the clipboard data.
- #
- # * AWorks::Registry.read_value(key, entry)
- # Read a registry value entry under key.
- #
- # * AWorks::Registry.enum_keys(key)
- # Enums all subkeys under key.
- #
- # * AWorks::Registry.enum_values(key)
- # Enums all entries under key.
- #
- # * AWorks::Registry.create_key(key)
- # Creates the subkey key.
- #
- # * AWorks::Registry.set_value(key, value[, type])
- # Sets(or creates) the value.
- #
- # * AWorks::Registry.delete_key(key[, recursive])
- # Deletes a subkey.
- #
- # * AWorks::Registry.delete_value(key)
- # Deletes a value.
- #
- # * AWorks.get_fonts_names
- # Returns fonts names from the windows Fonts folder.
- #
- # * AWorks.get_hwnd
- # Returns the HWND index of the game player.
- #
- # * AWorks.get_rgssdll
- # Returns the RGSS dll name.
- #
- # * AWorks.get_rtp_path([id])
- # Returns the rtp id path.
- #
- # * AWorks.get_mouse_swap_buttons_flag
- # Returns the Swap Mouse Buttons Flag.
- #
- # * Array.recursive_clone
- # Clones the array and all its subelements.
- #
- # * Array.to_hash
- # Converts the array in a hash.
- #
- # * Array.rindexes(*values)
- # Gets the indexes of the values.
- #
- # * Array.deep
- # Gets the deep of an Array. Deep stands for the max amount of subcontainers
- # (Arrays and Hashs) inside the array in a row.
- #
- # * Array.recursive_flatten
- # Calls the flatten method to the Array and all its subelements.
- #
- # * Array.recursive_flatten!
- # Calls the flatten method to the Array and all its subelements.
- #
- # * Array.insert(i, obj)
- # Inserts the obj object in the i index.
- #
- # * Hash.recursive_clone
- # Clones the hash and all its subelements.
- #
- # * Hash.deep(deep = -1)
- # Gets the deep of an Hash. Deep stands for the max amount of subcontainers
- # (Arrays and Hashs) inside the hash in a row.
- #
- # * Hash.fusion
- # Makes an array combining each key and value.
- #
- # * NilClass.clone
- # Empty method for allowing the cloning of nil objects.
- #
- # * Math.radian2degree(r)
- # Converts a radian value to a degree value,
- #
- # * Math.degree2radian(g)
- # Converts a degree value to a radian value,
- #
- # * Math.quick_cos(i)
- # Calc the cosine value of an Integer. Faster than Math.cos.
- #
- # * Math.quick_sin(i)
- # Calc the sine value of an Integer. Faster than Math.sine.
- #
- # * String.pixel_width(font)
- # Gets the width of the string for the given font in pixels.
- #
- # * String.pixel_width(name, size, bold)
- # Gets the width of the string for the given font format in pixels.
- #
- # * String.pixel_height(font)
- # Gets the height of the string for the given font in pixels.
- #
- # * String.pixel_height(name, size, bold)
- # Gets the height of the string for the given font format in pixels.
- #
- # * String.width_slice(width, font)
- # Returns in an array the string sliced in pieces which fit in the given width
- # for the given font.
- #
- # * String.width_slice(width, name, size, bold)
- # Returns in an array the string sliced in pieces which fit in the given width
- # for the given font format.
- #
- # * String.font_size_width(width, font)
- # Gets the max font size for the string to fit in the given width with the
- # given font. Font size doesn't matter.
- #
- # * String.font_size_width(width, name, bold)
- # Gets the max font size for the string to fit in the given width with the
- # given font format.
- #
- # * String.font_size_height(height, font)
- # Gets the max font size for the string to fit in the given height with the
- # given font. Font size doesn't matter.
- #
- # * String.font_size_height(height, name, bold)
- # Gets the max font size for the string to fit in the given height with the
- # given font format.
- #
- # * String.font_size(width, height, font)
- # Gets the max font size for the string to fit in the given width and height
- # with the given font. Font size doesn't matter.
- #
- # * String.font_size(width, height, name, bold)
- # Gets the max font size for the string to fit in the given width and height
- # with the given font format.
- #
- # * Bitmap.adraw_text(*args)
- # Draws like Bitmap.draw_text, but with some special features.
- #
- # * Graphics.auto_update (Property)
- # An array. Updates the objects and methods contained each frame. For adding
- # an object for being autoupdated add a new Array to Graphics.auto_update
- # with the following format:
- # [Object, method, frames]
- # The object must be a class and the method a symbol. If frames is nil, the
- # auto update will run undefined frames(Can be removed with .delete method).
- # If it is an Integer, it will act as a backward counter for each frame, and
- # the auto update will end when it reachs 0.
- #=============================================================================
- #=============================================================================
- # ** Module AWorks
- #=============================================================================
- module AWorks
- module_function
- #===========================================================================
- # ** Module AWorks::API
- #===========================================================================
- module_function
- module API
- #-------------------------------------------------------------------------
- # * AWorks DLL API declaration
- #-------------------------------------------------------------------------
- Initialize = Win32API.new('AWorks', 'Initialize', 'L', '')
- InputIni = Win32API.new('AWorks', 'InputInitialize', 'LLLLLL', '')
- InputUpdate = Win32API.new('AWorks', 'InputUpdate', '', '')
- InputMouseIni = Win32API.new('AWorks', 'InputMouseInitialize', 'LLL', '')
- InputMouseConfig = Win32API.new('AWorks', 'InputMouseConfig', 'LLLL', '')
- BitmapRotate = Win32API.new('AWorks', 'BitmapRotate', 'LLL', '')
- #-------------------------------------------------------------------------
- # * API declaration
- #-------------------------------------------------------------------------
- BlockInput = Win32API.new('user32', 'BlockInput', 'L', 'L')
- ClientToScreen = Win32API.new('user32', 'ClientToScreen', 'LP', 'L')
- CloseClipboard = Win32API.new('user32', 'CloseClipboard', '', 'L')
- ClipCursor = Win32API.new('user32', 'ClipCursor', 'P', 'L')
- EmptyClipboard = Win32API.new('user32', 'EmptyClipboard', '', 'L')
- FindWindowA = Win32API.new('user32', 'FindWindowA', 'pp', 'l')
- GetActiveWindow = Win32API.new('user32', 'GetActiveWindow', '', 'L')
- GetAsyncKeyState = Win32API.new('user32', 'GetAsyncKeyState', 'L', 'L')
- GetClientRect = Win32API.new('user32', 'GetClientRect', 'LP', 'L')
- GetClipboardData = Win32API.new('user32', 'GetClipboardData', 'L', 'L')
- GetCursorPos = Win32API.new('user32', 'GetCursorPos', 'P', 'L')
- GetDoubleClickTime = Win32API.new('user32', 'GetDoubleClickTime', '', 'L')
- GetKeyboardLayout = Win32API.new('user32', 'GetKeyboardLayout','L', 'L')
- GetKeyboardLayoutName =Win32API.new('user32','GetKeyboardLayoutName','P','L')
- GetKeyboardState = Win32API.new('user32', 'GetKeyboardState', 'P', 'L')
- GetKeyState = Win32API.new('user32', 'GetKeyState', 'L', 'L')
- GetSystemMetrics = Win32API.new('user32', 'GetSystemMetrics', 'L', 'L')
- GetWindowPlacement = Win32API.new('user32', 'GetWindowPlacement', 'LP', 'L')
- Keybd_Event = Win32API.new('user32', 'keybd_event', 'LLLL', '')
- OpenClipboard = Win32API.new('user32', 'OpenClipboard', 'L', 'L')
- ScreenToClient = Win32API.new('user32', 'ScreenToClient', 'LP', 'L')
- SetClipboardData = Win32API.new('user32', 'SetClipboardData', 'LL', 'L')
- ShowCursor = Win32API.new('user32', 'ShowCursor', 'L', 'L')
- SwapMouseButton = Win32API.new('user32', 'SwapMouseButton', 'L', 'L')
- ToAsciiEx = Win32API.new('user32', 'ToAsciiEx', 'LLPPLL', 'L')
- GetCurrentProcessId = Win32API.new('kernel32','GetCurrentProcessId', '','L')
- GPPSA = Win32API.new('kernel32', 'GetPrivateProfileStringA', 'PPPPLP', 'L')
- WPPSA = Win32API.new('kernel32', 'WritePrivateProfileStringA', 'PPPP', 'L')
- GlobalAlloc = Win32API.new('kernel32', 'GlobalAlloc', 'LL', 'L')
- GlobalLock = Win32API.new('kernel32', 'GlobalLock', 'L', 'L')
- GlobalSize = Win32API.new('kernel32', 'GlobalSize', 'L', 'L')
- GlobalUnlock = Win32API.new('kernel32', 'GlobalUnlock', 'L', '')
- RegCloseKey = Win32API.new('advapi32', 'RegCloseKey', 'L', 'L')
- RegEnumKeyExA = Win32API.new('advapi32', 'RegEnumKeyExA', 'LLPPLLLP', 'L')
- RegEnumValueA = Win32API.new('advapi32', 'RegEnumValueA', 'LLPPPPPP', 'L')
- RegOpenKeyExA = Win32API.new('advapi32', 'RegOpenKeyExA', 'LPLLP', 'L')
- RegQueryValueExA = Win32API.new('advapi32', 'RegQueryValueExA','LPLPPP', 'L')
- RegDeleteValue = Win32API.new('advapi32', 'RegDeleteValue','LP', 'L')
- RegDeleteKey = Win32API.new('advapi32', 'RegDeleteKey','LP', 'L')
- begin
- Memcpy = Win32API.new('ntdll', 'memcpy', 'PPL', 'L')
- rescue
- Memcpy = Win32API.new('crtdll', 'memcpy', 'PPL', 'L')
- end
- dll = "\0" * 255
- GPPSA.call('Game', 'Library', '', dll, 255, '.\\Game.ini')
- dll.delete!("\0")
- RGSSGetRTPPath = Win32API.new(dll, 'RGSSGetRTPPath', 'L', 'L')
- RGSSGetPathWithRTP = Win32API.new(dll, 'RGSSGetPathWithRTP', 'L', 'P')
- end
- #===========================================================================
- # ** Module AWorks::Ini
- #===========================================================================
- module Ini
- module_function
- #-------------------------------------------------------------------------
- # * Get String from Ini File
- #-------------------------------------------------------------------------
- def get_string(id, tag = 'Game', file = '.\\Game.ini')
- buffer = "\0" * 255
- API::GPPSA.call(tag, id, '', buffer, 255, file)
- buffer.delete!("\0")
- end
- #-------------------------------------------------------------------------
- # * Write String to Ini File
- #-------------------------------------------------------------------------
- def set_string(string, id, tag = 'Game', file = '.\\Game.ini')
- API::WPPSA.call(tag, id, string, file)
- end
- end
- #===========================================================================
- # ** Module AWorks::Clipboard
- #===========================================================================
- module Clipboard
- module_function
- #-------------------------------------------------------------------------
- # * Read Clipboard Data
- #-------------------------------------------------------------------------
- def read
- API::OpenClipboard.call(0)
- data = API::GetClipboardData.call(7)
- API::CloseClipboard.call
- return '' if data == 0
- lp = API::GlobalLock.call(data)
- len = API::GlobalSize.call(data)
- data2 = ' ' * (len - 1)
- API::Memcpy.call(data2, lp, len)
- API::GlobalUnlock.call(data)
- data2
- end
- #-------------------------------------------------------------------------
- # * Write Data to Clipboard
- #-------------------------------------------------------------------------
- def write(data)
- API::OpenClipboard.call(0)
- API::EmptyClipboard.call
- set_data = API::GlobalAlloc.call(66, data.length + 1)
- len = [data.size + 1, API::GlobalSize.call(set_data)].min
- lp = API::GlobalLock.call(set_data)
- API::Memcpy.call(lp, "#{data}", len)
- API::GlobalUnlock.call(set_data)
- API::SetClipboardData.call(7, set_data)
- API::CloseClipboard.call
- end
- #-------------------------------------------------------------------------
- # * Clear Clipboard Data
- #-------------------------------------------------------------------------
- def empty
- API::EmptyClipboard.call
- end
- end
- #===========================================================================
- # ** Module AWorks::Registry
- #===========================================================================
- module Registry
- module_function
- T_AUTO = -1
- T_SZ = 1
- T_BINARY = 3
- T_DWORD = 4
- HKEYS = {'HKEY_CLASSES_ROOT' => 0x80000000,'HKEY_CURRENT_USER' =>0x80000001,
- 'HKEY_LOCAL_MACHINE' => 0x80000002, 'HKEY_USERS' => 0x80000003,
- 'HKEY_CURRENT_CONFIG' => 0x80000005}
- #-------------------------------------------------------------------------
- # * Read a Value
- #-------------------------------------------------------------------------
- def read_value(key, entry)
- key.sub!(/(.*?)\\/, '')
- if !HKEYS[$1].nil?
- hkey = HKEYS[$1]
- else
- return nil
- end
- opened, type, size = [0].pack('V'), [0].pack('V'), [0].pack('V')
- API::RegOpenKeyExA.call(hkey, key, 0, 131097, opened)
- opened = (opened + [0].pack('V')).unpack('V')[0]
- API::RegQueryValueExA.call(opened, entry, 0, type, 0, size)
- data = ' ' * (size + [0].pack('V')).unpack('V')[0]
- API::RegQueryValueExA.call(opened, entry, 0, type, data, size)
- API::RegCloseKey.call(opened)
- data = data[0, (size + [0].pack('V')).unpack('V')[0]]
- type = (type += [0].pack('V')).unpack('V')[0]
- case type
- when 1
- data.chop
- when 2
- data.chop.gsub(/%([^%]+)%/) { ENV[$1] || $& }
- when 3
- data
- when 4
- (data += [0].pack('V')).unpack('V')[0]
- when 5
- data.unpack('N')[0]
- when 7
- data.split(/\0/)
- when 11
- (data.unpack('VV')[1] << 32) | data[0]
- else
- nil
- end
- end
- #-------------------------------------------------------------------------
- # * Enum Keys
- #-------------------------------------------------------------------------
- def enum_keys(key)
- key.sub!(/(.*?)\\/, '')
- if !HKEYS[$1].nil?
- hkey = HKEYS[$1]
- else
- return nil
- end
- index, keys, opened = 0, [], [0].pack('V')
- API::RegOpenKeyExA.call(hkey, key, 0, 131097, opened)
- opened = (opened + [0].pack('V')).unpack('V')[0]
- loop do
- name = ' ' * 514
- size = [514].pack('V')
- result = API::RegEnumKeyExA.call(opened, index, name, size, 0, 0, 0, 0)
- if result == 0
- keys.push(name[0, (size += [0].pack('V')).unpack('V')[0]])
- index += 1
- else
- break
- end
- end
- API::RegCloseKey.call(opened)
- keys
- end
- #-------------------------------------------------------------------------
- # * Enum Values
- #-------------------------------------------------------------------------
- def enum_values(key)
- key.sub!(/(.*?)\\/, '')
- if !HKEYS[$1].nil?
- hkey = HKEYS[$1]
- else
- return nil
- end
- index, entries, opened = 0, [], [0].pack('V')
- API::RegOpenKeyExA.call(hkey, key, 0, 131097, opened)
- opened = (opened + [0].pack('V')).unpack('V')[0]
- loop do
- name = ' ' * 514
- size = [514].pack('V')
- result = API::RegEnumValueA.call(opened, index, name, size, 0, 0, 0, 0)
- if result == 0
- entries.push(name[0, (size += [0].pack('V')).unpack('V')[0]])
- index += 1
- else
- break
- end
- end
- API::RegCloseKey.call(opened)
- entries
- end
- #-------------------------------------------------------------------------
- # * Create Key
- #-------------------------------------------------------------------------
- def create_key(key)
- key.sub!(/(.*?)\\/, '')
- if !HKEYS[$1].nil?
- hkey = HKEYS[$1]
- else
- return nil
- end
- result = [0].pack('V')
- disp = [0].pack('V')
- API::RegCreateKeyExA.call(hkey, key, 0, 0, 0, 131135, 0, result, disp)
- if [disp + [0].pack('V')].unpack('V')[0] == 2
- API::RegCloseKey.call(result)
- end
- end
- #-------------------------------------------------------------------------
- # * Set Value
- #-------------------------------------------------------------------------
- def set_value(key, value, type = T_AUTO)
- key.sub!(/(.*?)\\/, '')
- if !HKEYS[$1].nil?
- hkey = HKEYS[$1]
- else
- return nil
- end
- if type == T_AUTO
- if value.is_a?(Numeric)
- type = T_DWORD
- else
- type = T_SZ
- value = value.to_s
- end
- end
- case type
- when 1, 2
- value = value.to_s + "\0"
- when 7
- value = value.to_a.join("\0") + "\0\0"
- when 3
- value = value.to_s
- when 4
- value = [value.to_i].pack('V')
- when 5
- value = [value.to_i].pack('N')
- when 11
- value = [value.to_i & 0xFFFFFFFF, value.to_i >> 32 ].pack('VV')
- end
- API::RegSetValueExA.call(hkey, key, 0, type, value, value.length)
- end
- #-------------------------------------------------------------------------
- # * Delete Key
- #-------------------------------------------------------------------------
- def delete_key(key, recursive = false)
- skey = key.sub(/(.*?)\\/, '')
- if !HKEYS[$1].nil?
- hkey = HKEYS[$1]
- else
- return nil
- end
- if recursive
- else
- API::RegDeleteKey.call(hkey, key)
- end
- end
- #-------------------------------------------------------------------------
- # * Delete Value
- #-------------------------------------------------------------------------
- def delete_value(key)
- key.sub!(/(.*?)\\/, '')
- if !HKEYS[$1].nil?
- hkey = HKEYS[$1]
- else
- return nil
- end
- API::RegDeleteValue.call(hkey, key)
- end
- end
- #---------------------------------------------------------------------------
- # * Variables Declaration
- #---------------------------------------------------------------------------
- ASCII_TABLE = {1=>'☺',2=>'☻',3=>'♥',4=>'♦',5=>'♣',6=>'♠',7=>'•',8=>'◘',9=>'○',
- 10=>'◙',11=>'♂',12=>'♀',13=>'♪',14=>'♫',15=>'¤',16=>'►',17=>'◄',18=>'↕',
- 19=>'‼',20=>'¶',21=>'§',22=>'▬',23=>'↨',24=>'↑',25=>'↓',26=>'→',27=>'←',
- 28=>'∟',29=>'↔',30=>'▲',31=>'▼',32=>' ',33=>'!',34=>'"',35=>'#',36=>'$',
- 37=>'%',38=>'&',39=>"'",40=>'(',41=>')',42=>'*',43=>'+',44=>',',45=>'-',
- 46=>'.',47=>'/',48=>'0',49=>'1',50=>'2',51=>'3',52=>'4',53=>'5',54=>'6',
- 55=>'7',56=>'8',57=>'9',58=>':',59=>';',60=>'<',61=>'=',62=>'>',63=>'?',
- 64=>'@',65=>'A',66=>'B',67=>'C',68=>'D',69=>'E',70=>'F',71=>'G',72=>'H',
- 73=>'I',74=>'J',75=>'K',76=>'L',77=>'M',78=>'N',79=>'O',80=>'P',81=>'Q',
- 82=>'R',83=>'S',84=>'T',85=>'U',86=>'V',87=>'W',88=>'X',89=>'Y',90=>'Z',
- 91=>'[',92=>'\\',93=>']',94=>'^',95=>'_',96=>'`',97=>'a',98=>'b',99=>'c',
- 100=>'d',101=>'e',102=>'f',103=>'g',104=>'h',105=>'i',106=>'j',107=>'k',
- 108=>'l',109=>'m',110=>'n',111=>'o',112=>'p',113=>'q',114=>'r',115=>'s',
- 116=>'t',117=>'u',118=>'v',119=>'w',120=>'x',121=>'y',122=>'z',123=>'{',
- 124=>'|',125=>'}',126=>'~',127=>'¦',128=>'Ç',129=>'ü',130=>'é',131=>'â',
- 132=>'ä',133=>'à',134=>'å',135=>'ç',136=>'ê',137=>'ë',138=>'è',139=>'ï',
- 140=>'î',141=>'ì',142=>'Ä',143=>'Å',144=>'É',145=>'æ',146=>'Æ',147=>'ô',
- 148=>'ö',149=>'ò',150=>'û',151=>'ù',152=>'ÿ',153=>'Ö',154=>'Ü',155=>'ø',
- 156=>'£',157=>'Ø',158=>'×',159=>'ƒ',160=>'á',161=>'í',162=>'ó',163=>'ú',
- 164=>'ñ',165=>'Ñ',166=>'ª',167=>'º',168=>'¿',169=>'®',170=>'¬',171=>'½',
- 172=>'¼',173=>'¡',174=>'«',175=>'»',176=>'¦',177=>'¦',178=>'¦',179=>'¦',
- 180=>'¦',181=>'Á',182=>'Â',183=>'À',184=>'©',185=>'¦',186=>'¦',187=>'+',
- 188=>'+',189=>'¢',190=>'¥',191=>'+',192=>'+',193=>'-',194=>'-',195=>'+',
- 196=>'-',197=>'+',198=>'ã',199=>'Ã',200=>'+',201=>'+',202=>'-',203=>'-',
- 204=>'¦',205=>'-',206=>'+',207=>'¤',208=>'ð',209=>'Ð',210=>'Ê',211=>'Ë',
- 212=>'È',213=>'i',214=>'Í',215=>'Î',216=>'Ï',217=>'+',218=>'+',219=>'¦',
- 220=>'_',221=>'¦',222=>'Ì',223=>'¯',224=>'Ó',225=>'ß',226=>'Ô',227=>'Ò',
- 228=>'õ',229=>'Õ',230=>'µ',231=>'þ',232=>'Þ',233=>'Ú',234=>'Û',235=>'Ù',
- 236=>'ý',237=>'Ý',238=>'¯',239=>'´',240=>'',241=>'±',242=>'=',243=>'¾',
- 244=>'¶',245=>'§',246=>'÷',247=>'¸',248=>'°',249=>'¨',250=>'·',251=>'¹',
- 252=>'³',253=>'²',254=>'¦',255=>' '}
- TRANSLATE_TABLE ={"\225"=>'•',"\244"=>'¤',"\266"=>'¶',"\247"=>'§',"\307"=>'Ç',
- "\374"=>'ü',"\351"=>'é',"\342"=>'â',"\344"=>'ä',"\340"=>'à',"\345"=>'å',
- "\347"=>'ç',"\352"=>'ê',"\353"=>'ë',"\350"=>'è',"\357"=>'ï',"\356"=>'î',
- "\354"=>'ì',"\304"=>'Ä',"\305"=>'Å',"\311"=>'É',"\346"=>'æ',"\306"=>'Æ',
- "\364"=>'ô',"\366"=>'ö',"\362"=>'ò',"\373"=>'û',"\371"=>'ù',"\377"=>'ÿ',
- "\326"=>'Ö',"\334"=>'Ü',"\370"=>'ø',"\243"=>'£',"\330"=>'Ø',"\327"=>'×',
- "\203"=>'ƒ',"\341"=>'á',"\355"=>'í',"\363"=>'ó',"\372"=>'ú',"\361"=>'ñ',
- "\321"=>'Ñ',"\252"=>'ª',"\272"=>'º',"\277"=>'¿',"\256"=>'®',"\254"=>'¬',
- "\275"=>'½',"\274"=>'¼',"\241"=>'¡',"\253"=>'«',"\273"=>'»',"\301"=>'Á',
- "\302"=>'Â',"\300"=>'À',"\251"=>'©',"\242"=>'¢',"\245"=>'¥',"\343"=>'ã',
- "\303"=>'Ã',"\244"=>'¤',"\360"=>'ð',"\320"=>'Ð',"\312"=>'Ê',"\313"=>'Ë',
- "\310"=>'È',"\315"=>'Í',"\316"=>'Î',"\317"=>'Ï',"\314"=>'Ì',"\257"=>'¯',
- "\323"=>'Ó',"\337"=>'ß',"\324"=>'Ô',"\322"=>'Ò',"\365"=>'õ',"\325"=>'Õ',
- "\265"=>'µ',"\376"=>'þ',"\336"=>'Þ',"\332"=>'Ú',"\333"=>'Û',"\331"=>'Ù',
- "\375"=>'ý',"\335"=>'Ý',"\257"=>'¯',"\264"=>'´',"\255"=>'',"\261"=>'±',
- "\276"=>'¾',"\266"=>'¶',"\247"=>'§',"\367"=>'÷',"\270"=>'¸',"\260"=>'°',
- "\250"=>'¨',"\267"=>'·',"\271"=>'¹',"\263"=>'³',"\262"=>'²',"\240"=>' ',
- "\t"=>' ',"\200"=>'€'}
- #---------------------------------------------------------------------------
- # * Get Fonts Names
- #---------------------------------------------------------------------------
- def get_fonts_names
- key = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\#{ENV['OS'].sub(/_/,' ')}\\"
- fonts = Registry.enum_values(key + 'CurrentVersion\\Fonts')
- fonts.each_index {|f|
- fonts[f].sub!(' (TrueType)', '')
- fonts[f] = nil if !Font.exist?(fonts[f])
- }.delete(nil)
- fonts
- end
- #---------------------------------------------------------------------------
- # * Get RGSS Player HWND index
- #---------------------------------------------------------------------------
- def get_hwnd
- if @hwnd.nil?
- @hwnd = API::FindWindowA.call('RGSS Player', Ini.get_string('Title'))
- else
- @hwnd
- end
- end
- #---------------------------------------------------------------------------
- # * Get RGSS DLL
- #---------------------------------------------------------------------------
- def get_rgssdll
- Ini.get_string('Library')
- end
- #-------------------------------------------------------------------------
- # * Get RTP Path
- #-------------------------------------------------------------------------
- def get_rtp_path(rtp = 0)
- API::RGSSGetPathWithRTP.call(API::RGSSGetRTPPath.cal(rtp))
- end
- #-------------------------------------------------------------------------
- # * Get Mouse Swap Buttons Flag
- #-------------------------------------------------------------------------
- def get_mouse_swap_buttons_flag
- result = API::SwapMouseButton.call(0)
- if result == 0
- API::SwapMouseButton.call(0)
- 0
- else
- API::SwapMouseButton.call(1)
- 1
- end
- end
- #---------------------------------------------------------------------------
- # * Initialize AWorks Library
- #---------------------------------------------------------------------------
- API::Initialize.call(self.get_hwnd)
- end
- #=============================================================================
- # ** Class Array
- #=============================================================================
- class Array
- #---------------------------------------------------------------------------
- # * Recursive Clone
- #---------------------------------------------------------------------------
- def recursive_clone
- clon = self.clone
- clon.each_index do |i|
- clon[i] = clon[i].recursive_clone rescue clon[i].clone rescue clon[i]
- end
- clon
- end
- alias_method(:rclone, :recursive_clone)
- #---------------------------------------------------------------------------
- # * To Hash
- #---------------------------------------------------------------------------
- def to_hash
- hash = Hash.new
- self.each_index {|i| hash[i] = self[i]}
- hash
- end
- #---------------------------------------------------------------------------
- # * Indexes Reversed
- #---------------------------------------------------------------------------
- def rindexes(*values)
- array = Array.new
- self.each_index {|i| array.push(i) if values.include?(self[i])}
- array
- end
- #---------------------------------------------------------------------------
- # * Deep
- #---------------------------------------------------------------------------
- def deep(deep = -1)
- tmp_deep = deep + 1
- deep = tmp_deep
- self.each do |i|
- deep = i.deep(tmp_deep) if deep < i.deep(tmp_deep) rescue nil
- end
- deep
- end
- #---------------------------------------------------------------------------
- # * Recursive Flatten
- #---------------------------------------------------------------------------
- def recursive_flatten
- array = self.recursive_clone
- array.each_index do |i|
- array[i] = array[i].to_a if array[i].is_a?(Hash)
- array[i] = array[i].recursive_flatten rescue array[i]
- end
- array.flatten!
- array
- end
- alias_method(:rflatten, :recursive_flatten)
- #---------------------------------------------------------------------------
- # * Destructive Recursive Flatten
- #---------------------------------------------------------------------------
- def recursive_flatten!
- self.each_index do |i|
- self[i] = self[i].to_a if self[i].is_a?(Hash)
- self[i] = self[i].recursive_flatten! rescue self[i]
- end
- self.flatten!
- self
- end
- alias_method(:rflatten!, :recursive_flatten!)
- #---------------------------------------------------------------------------
- # * Insert
- #---------------------------------------------------------------------------
- def insert(i, obj)
- if i == 0
- obj + self
- elsif i == self.size
- self + obj
- elsif self.size < i
- self + Array.new(i - self.size) + obj
- else
- self[0, i - 1] + obj + self[i, self.size]
- end
- end
- end
- #=============================================================================
- # ** Class Hash
- #=============================================================================
- class Hash
- #---------------------------------------------------------------------------
- # * Recursive Clone
- #---------------------------------------------------------------------------
- def recursive_clone
- clon = self.clone
- clon.each_key do |i|
- clon[i] = clon[i].recursive_clone rescue clon[i].clone rescue clon[i]
- end
- clon
- end
- alias_method(:rclone, :recursive_clone)
- #---------------------------------------------------------------------------
- # * Deep
- #---------------------------------------------------------------------------
- def deep(deep = -1)
- tmp_deep = deep + 1
- key_deep = tmp_deep
- value_deep = tmp_deep
- self.each do |k, v|
- key_deep = k.deep(tmp_deep) if key_deep < k.deep(tmp_deep) rescue nil
- value_deep = v.deep(tmp_deep) if value_deep < v.deep(tmp_deep) rescue nil
- end
- if key_deep > value_deep
- key_deep
- else
- value_deep
- end
- end
- #---------------------------------------------------------------------------
- # * To Array, combining Key and Value
- #---------------------------------------------------------------------------
- def fusion
- array = self.sort
- array.each_index do|i|
- array[i] = array[i][0] + array[i][1] rescue array[i]
- end
- array
- end
- end
- #=============================================================================
- # ** Nil Class
- #=============================================================================
- class NilClass
- def clone;end
- end
- #=============================================================================
- # ** Module Math
- #=============================================================================
- module Math
- #---------------------------------------------------------------------------
- # * Radians to degrees
- #---------------------------------------------------------------------------
- def Math.radian2degree(r)
- r * 180 / Math::PI
- end
- #---------------------------------------------------------------------------
- # * Degrees to radians
- #---------------------------------------------------------------------------
- def Math.degree2radian(g)
- g * Math::PI / 180
- end
- #---------------------------------------------------------------------------
- # * Quick Cosine and Sine
- #---------------------------------------------------------------------------
- @cos = {}
- @sin = {}
- for i in 0..360
- @cos[i] = Math.cos(Math.degree2radian(i - 90))
- @sin[i] = Math.sin(Math.degree2radian(i - 90))
- end
- def Math.quick_cos(i)
- @cos[i.round % 360]
- end
- def Math.quick_sin(i)
- @sin[i.round % 360]
- end
- end
- #=============================================================================
- # ** Class String
- #=============================================================================
- class String
- #---------------------------------------------------------------------------
- # * Pixel Width of String
- #---------------------------------------------------------------------------
- def pixel_width(*args)
- bitmap = Bitmap.new(1, 1)
- if args[0].is_a?(Font)
- bitmap.font.size = args[0].size
- bitmap.font.name = args[0].name
- bitmap.font.bold = args[0].bold
- else
- bitmap.font.size = args[0].nil? ? Font.default_size : args[0]
- bitmap.font.name = args[1].nil? ? Font.default_name : args[1]
- bitmap.font.bold = args[2].nil? ? Font.default_bold : args[2]
- end
- pix = bitmap.text_size(self).width
- bitmap.dispose
- pix
- end
- #---------------------------------------------------------------------------
- # * Pixel Height of String
- #---------------------------------------------------------------------------
- def pixel_height(*args)
- bitmap = Bitmap.new(1, 1)
- if args[0].is_a?(Font)
- bitmap.font.size = args[0].size
- bitmap.font.name = args[0].name
- bitmap.font.bold = args[0].bold
- else
- bitmap.font.size = args[0].nil? ? Font.default_size : args[0]
- bitmap.font.name = args[1].nil? ? Font.default_name : args[1]
- bitmap.font.bold = args[2].nil? ? Font.default_bold : args[2]
- end
- pix = bitmap.text_size(self).height
- bitmap.dispose
- pix
- end
- #---------------------------------------------------------------------------
- # * Cut String to Strings with less or equal size than Width
- #---------------------------------------------------------------------------
- def width_slice(width, *args)
- bitmap = Bitmap.new(1, 1)
- if args[0].is_a?(Font)
- bitmap.font.size = args[0].size
- bitmap.font.name = args[0].name
- bitmap.font.bold = args[0].bold
- else
- bitmap.font.size = args[0].nil? ? Font.default_size : args[0]
- bitmap.font.name = args[1].nil? ? Font.default_name : args[1]
- bitmap.font.bold = args[2].nil? ? Font.default_bold : args[2]
- end
- result = ['']
- txt = self.clone.scan(/./)
- txt.each_index do |i|
- if txt[i].is_a?(String)
- txt[i] = [txt[i], bitmap.text_size(txt[i]).width]
- if txt.include?(txt[i][0])
- txt.collect! do |e|
- e == txt[i][0] ? txt[i] : e
- end
- end
- end
- end
- bitmap.dispose
- act_width = 0
- loop do
- if txt.size > 0
- tmp_width = act_width + txt[0][1]
- tmp_width += txt[1][1] if txt.size > 1
- if width >= act_width + txt[0][1]
- result[result.size - 1] += txt[0][0]
- act_width += txt[0][1]
- txt.delete_at(0)
- else
- result.push('')
- act_width = 0
- end
- else
- break
- end
- end
- result
- end
- #---------------------------------------------------------------------------
- # * Max Font Size for Width
- #---------------------------------------------------------------------------
- def font_size_width(width, *args)
- bitmap = Bitmap.new(1, 1)
- if args[0].is_a?(Font)
- bitmap.font.name = args[0].name
- bitmap.font.bold = args[0].bold
- else
- bitmap.font.name = args[0].nil? ? Font.default_name : args[0]
- bitmap.font.bold = args[1].nil? ? Font.default_bold : args[1]
- end
- size = 6
- for i in 6..96
- bitmap.font.size = i
- size = i if bitmap.text_size(self).width <= width
- end
- bitmap.dispose
- size
- end
- #---------------------------------------------------------------------------
- # * Max Font Size for Height
- #---------------------------------------------------------------------------
- def font_size_height(height, *args)
- bitmap = Bitmap.new(1, 1)
- if args[0].is_a?(Font)
- bitmap.font.name = args[0].name
- bitmap.font.bold = args[0].bold
- else
- bitmap.font.name = args[0].nil? ? Font.default_name : args[0]
- bitmap.font.bold = args[1].nil? ? Font.default_bold : args[1]
- end
- size = 6
- for i in 6..96
- bitmap.font.size = i
- size = i if bitmap.text_size(self).height <= height
- end
- bitmap.dispose
- size
- end
- #---------------------------------------------------------------------------
- # * Max Font Size for Width & Height
- #---------------------------------------------------------------------------
- def font_size(width, height, *args)
- bitmap = Bitmap.new(1, 1)
- if args[0].is_a?(Font)
- bitmap.font.name = args[0].name
- bitmap.font.bold = args[0].bold
- else
- bitmap.font.name = args[0].nil? ? Font.default_name : args[0]
- bitmap.font.bold = args[1].nil? ? Font.default_bold : args[1]
- end
- size = 6
- for i in 6..96
- bitmap.font.size = i
- if bitmap.text_size(self).width <= width and
- bitmap.text_size(self).height <= height
- size = i
- end
- end
- bitmap.dispose
- size
- end
- #---------------------------------------------------------------------------
- # * Transform the undrawable Characters
- #---------------------------------------------------------------------------
- def trans_undrawable_chr(font = Font.new, chr = '?')
- bmp = Bitmap.new(1, 1)
- bmp.font = font
- txt = ''
- scan(/./).each {|c| txt += (bmp.text_size(c).width == 0) ? chr : c}
- txt
- end
- end
- #=============================================================================
- # ** Class Bitmap
- #=============================================================================
- class Bitmap
- #---------------------------------------------------------------------------
- # * Draw Text AWorks
- #---------------------------------------------------------------------------
- def adraw_text(*args)
- if args.size.between?(2,3)
- args[2] = 0 if args.size == 2
- args[4] = args[1]
- args[5] = args[2]
- args[1] = args[0].y
- args[2] = args[0].width
- args[3] = args[0].height
- args[0] = args[0].x
- elsif args.size == 5
- args[5] = 0
- end
- if args[4].is_a?(Array)
- args[4] = args[4].rflatten
- args[4].each do |t|
- t = t.nil? ? 'nil' : "#{t}"
- width = args[2].nil? ? self.text_size(t).width : args[2]
- height = args[3].nil? ? self.text_size('0').height : args[3]
- self.draw_text(args[0], args[1], width, height, t, args[5])
- args[1] += height
- end
- return
- elsif args[4].is_a?(Hash)
- args[4] = args[4].fusion
- args[4] = args[4].rflatten
- args[4].each do |t|
- t = t.nil? ? 'nil' : "#{t}"
- width = args[2].nil? ? self.text_size(t).width : args[2]
- height = args[3].nil? ? self.text_size('0').height : args[3]
- self.draw_text(args[0], args[1], width, height, t, args[5])
- args[1] += height
- end
- return
- elsif !args[4].is_a?(String)
- if args[4].to_s == ''
- args[4] = args[4].inspect
- else
- args[4] = args[4].to_s
- end
- end
- args[2] = args[2].nil? ? self.text_size(args[4]).width + 2 : args[2]
- args[3] = args[3].nil? ? self.text_size('0').height + 2 : args[3]
- draw_text(*args)
- end
- end
- #=============================================================================
- # ** Module Graphics
- #=============================================================================
- module Graphics
- @auto_update = []
- class << self
- #-------------------------------------------------------------------------
- # * Object method auto-call
- #-------------------------------------------------------------------------
- unless self.method_defined?(:alibrary_update)
- alias_method(:alibrary_update, :update)
- end
- attr_accessor(:auto_update)
- def update
- alibrary_update
- @auto_update.each do |k|
- k[0].method(k[1]).call
- if !k[2].nil?
- k[2] -= 1
- k = nil if k[2] <= 0
- end
- end
- @auto_update.delete_if {|x| if !x[2].nil? : x[2] <= 0 else false end}
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment