[Script] [ACE] New Cash System - By ZIONS Games

KangKang Posts: 453Registered
[size=x-large][align=center]NEW CASH SYSTEM V 1.0 - BY ZIONS GAMES[/align][/size]

[chapter]Giới thiệu[/chapter]
Cung cấp một loại tiền tệ mới với mức độ bảo mật cao hơn, ngăn chặn tình trạng hack.

[chapter]Điều khoản sử dụng[/chapter]
1. Cho Script này: Để Credits: "ZIONS GAMES"
Miễn phí hoàn toàn cho cả dự án thương mại và phi thương mại.
2. Cho Script NRGSS: Liên hệ tác giả.

[chapter]Cài đặt[/chapter]
1. Chỉnh sửa trong "Module: Vocab" ở trong script
Chú ý: Gọi script sau 1 lần sau khi đã đặt dữ liệu tiền tệ vào biến [CashVar] để mã hoá dữ liệu và đảm bảo script chính hoạt động ổn định:
$game_variables[Vocab::CashVar] = $nrgss.encrypt_int($game_variables[Vocab::CashVar])


2. Đặt "@cash_window.close" sau "@gold_window.close" trong "Window_Message" (Line 181)
3. Đặt "@cash_window.y = y > 0 ? 0 : Graphics.height - ( 2 * @cash_window.height )"
sau "@gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height" trong "Window_Message" (Line 203)
4. Đặt:
"when 'CASH'
@cash_window.open"
sau "@gold_window.open" trong "Window_Message" (Line 351)
5. Đặt "@cash_window.dispose" sau "@gold_window.dispose" trong "Window_Message" (Line 135)
6. Đặt "@cash_window.update" sau "@gold_window.update" trong "Window_Message" (Line 157)
7. Đặt "create_cash_windows" sau "@gold_window.openness = 0" trong "Window_Message" (Line 93)
8. Đặt "create_cash_window" sau "create_gold_window" trong "Scene_Menu" (Line 14)

[chapter]Sử dụng[/chapter]
1. Để gọi cửa hàng riêng cho loại tiền tệ mới này, sử dụng script call bên dưới.
2. Để hiện cửa sổ Cash (giống như cửa sổ Gold), sử dụng: "\cash" (giống như dùng "\$")

Shop's Script Call:
#=======================================================#
g1 = [type 1, id 1, PO_flag(, price 1)]
g2 = [type 2, id 2, PO_flag(, price 2)]
...
gn = [type n, id n, PO_flag(, price n)]
cgoods = [g1,g2,...,gn]
buy_only = true
SceneManager.call(Scene_CShop)
SceneManager.scene.prepare(cgoods, buy_only))
#=======================================================#
| Type: 0 = Item | 1 = Weapon | 2 = Armor #
| ID: Item/Weapon/Armor ID in DataBase #
| PO_flag: 0 = Use default price | 1 = Use custom price #
| price: Custom price #
| buy_only = true or false #
#=======================================================#

[chapter]Script[/chapter]
Pastebin: http://pastebin.com/ptFWWZas
=begin
#==============================================================================#
#                    NEW CASH SYSTEM V 1.0 - BY ZIONS GAMES                    #
#==============================================================================#

 This Cash Script was contained NRGSS Script - by Narzew. Website: http://rpg-t.netii.net
 
 Description: Script provides a new currency with a higher level of security.
 
 Terms of Use:
    For this script:  Credits to "ZIONS GAMES".
                      It free for both non-commercial and commercial.
    For NRGSS Script: Contact the Author.
 
 Requirements: NRGSS Script by Narzew.
               This "New Cash Script" had been contained "NRGSS Script" by default.
               NRGSS Script place after Line 485.
 
 How to install:
 1. Edit data in "Module: Vocab" below
 
    CAUTION:
    Call script one-time after set Value in Variable[CashVar]:
		$game_variables[Vocab::CashVar] = $nrgss.encrypt_int($game_variables[Vocab::CashVar])
	  to Encrypt your Cash and Ensure script proper operation.
    
 2. Place "@cash_window.close" after "@gold_window.close" in "Window_Message" (Line 181)
 3. Place "@cash_window.y = y > 0 ? 0 : Graphics.height - ( 2 * @cash_window.height )"
    after "@gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height" in "Window_Message" (Line 203)
 4. Place "when 'CASH'
             @cash_window.open"
	  after "@gold_window.open" in "Window_Message" (Line 351)
 5. Place "@cash_window.dispose" after "@gold_window.dispose" in "Window_Message" (Line 135)
 6. Place "@cash_window.update" after "@gold_window.update" in "Window_Message" (Line 157)
 7. Place "create_cash_windows" after "@gold_window.openness = 0" in "Window_Message" (Line 93)
 8. Place "create_cash_window" after "create_gold_window" in "Scene_Menu" (Line 14)
 
 How to use:
 1. To call a shop, use "Shop's Script Call" below.
 2. To show Cash windows in Message popup, use: "\cash" (Use the same as "\$")
 
 Shop's Script Call:
	#=======================================================#
	 g1 = [type 1, id 1, PO_flag(, price 1)]
	 g2 = [type 2, id 2, PO_flag(, price 2)]
	 ...
	 gn = [type n, id n, PO_flag(, price n)]
	 cgoods = [g1,g2,...,gn]
	 buy_only = true
	 SceneManager.call(Scene_CShop)
	 SceneManager.scene.prepare(cgoods, buy_only))
	#=======================================================#
	| Type: 0 = Item | 1 = Weapon | 2 = Armor               #
	| ID: Item/Weapon/Armor ID in DataBase                  #
	| PO_flag: 0 = Use default price | 1 = Use custom price #
	| price: Custom price                                   #
	| buy_only = true or false                              #
	#=======================================================#

                         >>> Sorry my bad English! <<<
#==============================================================================#
=end

#==============================================================================#
#                              Module: Vocab                                   #
#==============================================================================#
module Vocab
  CashName        = "ż"               # Call: Vocab::CashName
  CashVar         =  2                # Call: Vocab::CashVar
  CShopBuy        = Vocab::ShopBuy    # Buy button name. Default: Same Shop
  CShopSell       = Vocab::ShopSell   # Sell button name. Default: Same Shop
  CShopCancel     = Vocab::ShopCancel # Cancel button name. Defautl: Same Shop
  SkipTitle       = true              # Skip Title in Test Mode?
end
#==============================================================================#
#                                Skip Title                                    #
#==============================================================================#
if $TEST and Vocab::SkipTitle
class Scene_Title < Scene_Base
  def start
    super
    SceneManager.clear
    Graphics.freeze
    command_new_game if !DataManager.save_file_exists?
    command_continue if DataManager.save_file_exists?
  end
  
  def command_new_game
    DataManager.setup_new_game
    $game_map.autoplay
    SceneManager.goto(Scene_Map)
  end
  
  def command_continue
    return command_new_game if @load_scene; @load_scene = true
    SceneManager.call(Scene_Load)
  end
  
  def terminate
    super
    SceneManager.snapshot_for_background
  end
end
end

#==============================================================================#
#                               Window: Cash                                   #
#==============================================================================#
class Window_Cash < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, window_width, fitting_height(1))
    refresh
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return 160
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    draw_currency_value(value, cash_unit, 4, 0, contents.width - 8)
  end
  #--------------------------------------------------------------------------
  # * Get Party Cash
  #--------------------------------------------------------------------------
  def value
    $value = $nrgss.decrypt_int($game_variables[Vocab::CashVar])
    $nrgss.encrypt_int($game_variables[Vocab::CashVar])
    return $value
  end
  #--------------------------------------------------------------------------
  # Get Cash Name
  #--------------------------------------------------------------------------
  def cash_unit
    Vocab::CashName
  end
  #--------------------------------------------------------------------------
  # * Open Window
  #--------------------------------------------------------------------------
  def open
    refresh
    super
  end
end

#==============================================================================#
#                              Window: Message                                 #
#==============================================================================#
class Window_Message < Window_Base
  #--------------------------------------------------------------------------
  # * Create All Windows
  #--------------------------------------------------------------------------
  def create_cash_windows
    @cash_window = Window_Cash.new
    @cash_window.x = Graphics.width - ( 2 * @cash_window.width )
    @cash_window.y = 0
    @cash_window.openness = 0
  end
end

#==============================================================================#
#                           Window: CShopCommand                               #
#==============================================================================#
class Window_CShopCommand < Window_HorzCommand
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(window_width, purchase_only)
    @window_width = window_width
    @purchase_only = purchase_only
    super(0, 0)
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    @window_width
  end
  #--------------------------------------------------------------------------
  # * Get Digit Count
  #--------------------------------------------------------------------------
  def col_max
    if !@purchase_only
      return 3
    else
      return 2
    end
  end
  #--------------------------------------------------------------------------
  # * Create Command List
  #--------------------------------------------------------------------------
  def make_command_list
    add_command(Vocab::CShopBuy,    :buy)
    
    if !@purchase_only
      add_command(Vocab::CShopSell, :sell)
    end

    add_command(Vocab::CShopCancel, :cancel)
  end
end

#==============================================================================#
#                               Scene: Menu                                    #
#==============================================================================#
class Scene_Menu < Scene_MenuBase
    def create_cash_window
    @cash_window = Window_Cash.new
    @cash_window.x = 0
    @cash_window.y = Graphics.height - ( 2 * @cash_window.height )
  end
end

#==============================================================================#
#                               Scene: Shop                                    #
#==============================================================================#
class Scene_CShop < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Prepare
  #--------------------------------------------------------------------------
  def prepare(cgoods, purchase_only)
    @cgoods = cgoods
    @purchase_only = purchase_only
  end
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super
    create_help_window
    create_cash_window
    create_command_window
    create_dummy_window
    create_number_window
    create_status_window
    create_buy_window
    create_category_window
    create_sell_window
  end
  #--------------------------------------------------------------------------
  # * Create cash Window
  #--------------------------------------------------------------------------
  def create_cash_window
    @cash_window = Window_Cash.new
    @cash_window.viewport = @viewport
    @cash_window.x = Graphics.width - @cash_window.width
    @cash_window.y = @help_window.height
  end
  #--------------------------------------------------------------------------
  # * Create Command Window
  #--------------------------------------------------------------------------
  def create_command_window
    @command_window = Window_CShopCommand.new(@cash_window.x, @purchase_only)
    @command_window.viewport = @viewport
    @command_window.y = @help_window.height
    @command_window.set_handler(:buy,    method(:command_buy))
    @command_window.set_handler(:sell,   method(:command_sell))
    @command_window.set_handler(:cancel, method(:return_scene))
  end
  #--------------------------------------------------------------------------
  # * Create Dummy Window
  #--------------------------------------------------------------------------
  def create_dummy_window
    wy = @command_window.y + @command_window.height
    wh = Graphics.height - wy
    @dummy_window = Window_Base.new(0, wy, Graphics.width, wh)
    @dummy_window.viewport = @viewport
  end
  #--------------------------------------------------------------------------
  # * Create Quantity Input Window
  #--------------------------------------------------------------------------
  def create_number_window
    wy = @dummy_window.y
    wh = @dummy_window.height
    @number_window = Window_ShopNumber.new(0, wy, wh)
    @number_window.viewport = @viewport
    @number_window.hide
    @number_window.set_handler(:ok,     method(:on_number_ok))
    @number_window.set_handler(:cancel, method(:on_number_cancel))
  end
  #--------------------------------------------------------------------------
  # * Create Status Window
  #--------------------------------------------------------------------------
  def create_status_window
    wx = @number_window.width
    wy = @dummy_window.y
    ww = Graphics.width - wx
    wh = @dummy_window.height
    @status_window = Window_ShopStatus.new(wx, wy, ww, wh)
    @status_window.viewport = @viewport
    @status_window.hide
  end
  #--------------------------------------------------------------------------
  # * Create Purchase Window
  #--------------------------------------------------------------------------
  def create_buy_window
    wy = @dummy_window.y
    wh = @dummy_window.height
    @buy_window = Window_ShopBuy.new(0, wy, wh, @cgoods)
    @buy_window.viewport = @viewport
    @buy_window.help_window = @help_window
    @buy_window.status_window = @status_window
    @buy_window.hide
    @buy_window.set_handler(:ok,     method(:on_buy_ok))
    @buy_window.set_handler(:cancel, method(:on_buy_cancel))
  end
  #--------------------------------------------------------------------------
  # * Create Category Window
  #--------------------------------------------------------------------------
  def create_category_window
    @category_window = Window_ItemCategory.new
    @category_window.viewport = @viewport
    @category_window.help_window = @help_window
    @category_window.y = @dummy_window.y
    @category_window.hide.deactivate
    @category_window.set_handler(:ok,     method(:on_category_ok))
    @category_window.set_handler(:cancel, method(:on_category_cancel))
  end
  #--------------------------------------------------------------------------
  # * Create Sell Window
  #--------------------------------------------------------------------------
  def create_sell_window
    wy = @category_window.y + @category_window.height
    wh = Graphics.height - wy
    @sell_window = Window_ShopSell.new(0, wy, Graphics.width, wh)
    @sell_window.viewport = @viewport
    @sell_window.help_window = @help_window
    @sell_window.hide
    @sell_window.set_handler(:ok,     method(:on_sell_ok))
    @sell_window.set_handler(:cancel, method(:on_sell_cancel))
    @category_window.item_window = @sell_window
  end
  #--------------------------------------------------------------------------
  # * Activate Purchase Window
  #--------------------------------------------------------------------------
  def activate_buy_window
    @buy_window.money = money
    @buy_window.show.activate
    @status_window.show
  end
  #--------------------------------------------------------------------------
  # * Activate Sell Window
  #--------------------------------------------------------------------------
  def activate_sell_window
    @category_window.show
    @sell_window.refresh
    @sell_window.show.activate
    @status_window.hide
  end
  #--------------------------------------------------------------------------
  # * [Buy] Command
  #--------------------------------------------------------------------------
  def command_buy
    @dummy_window.hide
    activate_buy_window
  end
  #--------------------------------------------------------------------------
  # * [Sell] Command
  #--------------------------------------------------------------------------
  def command_sell
    @dummy_window.hide
    @category_window.show.activate
    @sell_window.show
    @sell_window.unselect
    @sell_window.refresh
  end
  #--------------------------------------------------------------------------
  # * Buy [OK]
  #--------------------------------------------------------------------------
  def on_buy_ok
    @item = @buy_window.item
    @buy_window.hide
    @number_window.set(@item, max_buy, buying_price, cash_unit)
    @number_window.show.activate
  end
  #--------------------------------------------------------------------------
  # * Buy [Cancel]
  #--------------------------------------------------------------------------
  def on_buy_cancel
    @command_window.activate
    @dummy_window.show
    @buy_window.hide
    @status_window.hide
    @status_window.item = nil
    @help_window.clear
  end
  #--------------------------------------------------------------------------
  # * Category [OK]
  #--------------------------------------------------------------------------
  def on_category_ok
    activate_sell_window
    @sell_window.select(0)
  end
  #--------------------------------------------------------------------------
  # * Category [Cancel]
  #--------------------------------------------------------------------------
  def on_category_cancel
    @command_window.activate
    @dummy_window.show
    @category_window.hide
    @sell_window.hide
  end
  #--------------------------------------------------------------------------
  # * Sell [OK]
  #--------------------------------------------------------------------------
  def on_sell_ok
    @item = @sell_window.item
    @status_window.item = @item
    @category_window.hide
    @sell_window.hide
    @number_window.set(@item, max_sell, selling_price, cash_unit)
    @number_window.show.activate
    @status_window.show
  end
  #--------------------------------------------------------------------------
  # * Sell [Cancel]
  #--------------------------------------------------------------------------
  def on_sell_cancel
    @sell_window.unselect
    @category_window.activate
    @status_window.item = nil
    @help_window.clear
  end
  #--------------------------------------------------------------------------
  # * Quantity Input [OK]
  #--------------------------------------------------------------------------
  def on_number_ok
    Sound.play_shop
    case @command_window.current_symbol
    when :buy
      do_buy(@number_window.number)
    when :sell
      do_sell(@number_window.number)
    end
    end_number_input
    @cash_window.refresh
    @status_window.refresh
  end
  #--------------------------------------------------------------------------
  # * Quantity Input [Cancel]
  #--------------------------------------------------------------------------
  def on_number_cancel
    Sound.play_cancel
    end_number_input
  end
  #--------------------------------------------------------------------------
  # * Execute Purchase
  #--------------------------------------------------------------------------
  def do_buy(number)
    n = $game_variables[Vocab::CashVar]
    $game_variables[Vocab::CashVar] = $nrgss.encrypt_int( $nrgss.decrypt_int(n) - (number * buying_price) )
    $game_party.gain_item(@item, number)
  end
  #--------------------------------------------------------------------------
  # * Execute Sale
  #--------------------------------------------------------------------------
  def do_sell(number)
    $game_party.gain_gold(number * selling_price)
    $game_party.lose_item(@item, number)
  end
  #--------------------------------------------------------------------------
  # * Exit Quantity Input
  #--------------------------------------------------------------------------
  def end_number_input
    @number_window.hide
    case @command_window.current_symbol
    when :buy
      activate_buy_window
    when :sell
      activate_sell_window
    end
  end
  #--------------------------------------------------------------------------
  # * Get Maximum Quantity Buyable
  #--------------------------------------------------------------------------
  def max_buy
    max = $game_party.max_item_number(@item) - $game_party.item_number(@item)
    buying_price == 0 ? max : [max, money / buying_price].min
  end
  #--------------------------------------------------------------------------
  # * Get Maximum Quantity Sellable
  #--------------------------------------------------------------------------
  def max_sell
    $game_party.item_number(@item)
  end
  #--------------------------------------------------------------------------
  # * Get Party cash
  #--------------------------------------------------------------------------
  def money
    #@cash_window.value
    $money = $nrgss.decrypt_int($game_variables[Vocab::CashVar])
    $nrgss.encrypt_int($game_variables[Vocab::CashVar])
    return $money
  end
  #--------------------------------------------------------------------------
  # Get cash Unit
  #--------------------------------------------------------------------------
  def cash_unit
    @cash_window.cash_unit
  end
  #--------------------------------------------------------------------------
  # * Get Purchase Price
  #--------------------------------------------------------------------------
  def buying_price
    @buy_window.price(@item)
  end
  #--------------------------------------------------------------------------
  # * Get Sale Price
  #--------------------------------------------------------------------------
  def selling_price
    #@item.price / 2
    @item.price
  end
end

#==============================================================================#
#                                  NRGSS                                       #
#==============================================================================#
# EX:
# $gold = 3000
# $game_variables[1] = $nrgss.encrypt_int($gold)
# $game_variables[2] = $nrgss.decrypt_int($game_variables[1]).to_i
# x = 10
# $game_variables[3] = $nrgss.encrypt_int($nrgss.decrypt_int($game_variables[1]).to_i - x)

class NRGSS
 
  #===========================================================
  #**initialize
  #**Defines a initialisation of class
  #===========================================================
 
  def initialize
    $nrgss_version = 2.6
  end
 
  #===========================================================
  #**version
  #**Defines a library Version
  #===========================================================
 
  def version
    return $nrgss_version
  end
 
  #===========================================================
  #**Variable definitions
  #===========================================================
 
  $error_section_num = (/^(?:Section)?{?(\d+)}?:/)
  $error_section = (/^(?:Section)?{?\d+}?:/)
  $double_crlf = (/\n\n/)
  $line = "\n"
  $doubleline = "\n\n"
 
  $messagebox = Win32API.new('user32', 'MessageBoxA', %w(p p p i), 'i')
  $msgbox = Win32API.new('user32', 'MessageBoxA', %w(p p p i), 'i')
  $getprivateprofilestring = Win32API.new('kernel32', 'GetPrivateProfileStringA',%w(p p p p l p),'l')
  $mcisendstring = Win32API.new('winmm', 'mciSendString', 'PPLL', 'L')
  $midioutsetvolume = Win32API.new('winmm', 'midiOutSetVolume', 'LL', 'L')
 
  $halfbyte = 0xF
  $byte = 0xFF
  $doublebyte = 0xFFFF
  $threebyte = 0xFFFFFF
  $long = 0xFFFFFF
  $doublelong = 0xFFFFFFFFFFFFFFFF
  $hex = $halfbyte
  $hex2 = $byte
  $hex4 = $doublebyte
  $hex6 = $threebyte
  $hex8 = $long
  $hex16 = $doublelong
  $hex32 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  $hex48 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  $hex64 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
  $hexes = [16**0,16**1,16**2,16**3,16**4,16**5,16**6,16**7,16**8,16**9,16**10,16**11,16**12,16**13,16**14,16**15,16**16]
 
  $registered_names = []
  $registered_authors = []
  $registered_scripts = {}
 
  #===========================================================
  #**register
  #**Registers a component
  #===========================================================
 
  def register(product, author, version)
    $registered_scripts[product] =  [author, version]
    $registered_authors << author
    $registered_names << product
  end
 
  #===========================================================
  #**registered?(product)
  #**Checks the component is registered
  #===========================================================
 
  def registered?(product, rd=false)
    if $registered_scripts.include?(product)
      if rd
        return $registered_scripts[product]
      else
        return true
      end
    else
      return false
    end
  end
 
  #===========================================================
  #**check_version(product, version)
  #**Checks the component is in valid version
  #===========================================================
 
  def check_version(product, version, raise=0)
    return false unless registered?(product)
    if $registered_scripts[product][1] >= version
      return true
    else
      raise("Bad version of product : #{product}.\nVersion : #{version} or later is required.") if raise == 1
      return false
    end
  end
 
  #===========================================================
  #**in_range?
  #**Checks the value is between x and y
  #===========================================================
 
  def in_range?( x, y, value)
    value = self if value ==  nil
    return true if value.to_i > x.to_i and value < y.to_i
  end
 
  #===========================================================
  #**round_range
  #**Rounds the value to range
  #===========================================================
 
  def round_range(min, max, value)
    value = self if value == nil
    if value > max
      value = max
    elsif value < min
      value = min
    end
    return value
  end
 
  #===========================================================
  #**unpack_byte
  #**Unpacks byte to letter
  #===========================================================
 
  def unpack_byte(byte)
    result  = []
    case byte
    when 0 then result << '$NULL$'
    when 1 then result << '$SOH$'
    when 2 then result << '$STX$'
    when 3 then result << '$ETX$'
    when 4 then result << '$EOT$'
    when 5 then result << '$ENQ$'
    when 6 then result << '$ACK$'
    when 7 then result << '$BEL$'
    when 8 then result << '$BS$'
    when 9 then result << '$TAB$'
    when 10 then result << '$LF$'
    when 11 then result << '$VT$'
    when 12 then result << '$FF$'
    when 13 then result << '$CR$'
    when 14 then result << '$SO$'
    when 15 then result << '$SI$'
    when 16 then result << '$DLE$'
    when 17 then result << '$DC1$'
    when 18 then result << '$DC2$'
    when 19 then result << '$DC3$'
    when 20 then result << '$DC4$'
    when 21 then result << '$NAK$'
    when 22 then result << '$SYN$'
    when 23 then result << '$ETB$'
    when 24 then result << '$CAN$'
    when 25 then result << '$EN$'
    when 26 then result << '$SUB$'
    when 27 then result << '$ESC$'
    when 28 then result << '$FS$'
    when 29 then result << '$GS$'
    when 30 then result << '$RS$'
    when 31 then result << '$US$'
    when 32 then result << ' '
    when 33 then result << '!'
    when 34 then result << '\"'
    when 35 then result << '#'
    when 36 then result << '$'
    when 37 then result << '%'
    when 38 then result << '&'
    when 39 then result << '\''
    when 40 then result << '('
    when 41 then result << ')'
    when 42 then result << '*'
    when 43 then result << '+'
    when 44 then result << ','
    when 45 then result << '-'
    when 46 then result << '.'
    when 47 then result << '/'
    when 48 then result << '0'
    when 49 then result << '1'
    when 50 then result << '2'
    when 51 then result << '3'
    when 52 then result << '4'
    when 53 then result << '5'
    when 54 then result << '6'
    when 55 then result << '7'
    when 56 then result << '8'
    when 57 then result << '9'
    when 58 then result << ':'
    when 59 then result << ';'
    when 60 then result << '<'
    when 61 then result << '='
    when 62 then result << '>'
    when 63 then result << '?'
    when 64 then result << '@'
    when 65 then result << 'A'
    when 66 then result << 'B'
    when 67 then result << 'C'
    when 68 then result << 'D'
    when 69 then result << 'E'
    when 70 then result << 'F'
    when 71 then result << 'G'
    when 72 then result << 'H'
    when 73 then result << 'I'
    when 74 then result << 'J'
    when 75 then result << 'K'
    when 76 then result << 'L'
    when 77 then result << 'M'
    when 78 then result << 'N'
    when 79 then result << 'O'
    when 80 then result << 'P'
    when 81 then result << 'Q'
    when 82 then result << 'R'
    when 83 then result << 'S'
    when 84 then result << 'T'
    when 85 then result << 'U'
    when 86 then result << 'V'
    when 87 then result << 'W'
    when 88 then result << 'X'
    when 89 then result << 'Y'
    when 90 then result << 'Z'
    when 91 then result << '['
    when 92 then result << '\\'
    when 93 then result << ']'
    when 94 then result << '^'
    when 95 then result << '_'
    when 96 then result << '`'
    when 97 then result << 'a'
    when 98 then result << 'b'
    when 99 then result << 'c'
    when 100 then result << 'd'
    when 101 then result << 'e'
    when 102 then result << 'f'
    when 103 then result << 'g'
    when 104 then result << 'h'
    when 105 then result << 'i'
    when 106 then result << 'j'
    when 107 then result << 'k'
    when 108 then result << 'l'
    when 109 then result << 'm'
    when 110 then result << 'n'
    when 111 then result << 'o'
    when 112 then result << 'p'
    when 113 then result << 'q'
    when 114 then result << 'r'
    when 115 then result << 's'
    when 116 then result << 't'
    when 117 then result << 'u'
    when 118 then result << 'v'
    when 119 then result << 'w'
    when 120 then result << 'x'
    when 121 then result << 'y'
    when 122 then result << 'z'
    when 123 then result << '{'
    when 124 then result << '|'
    when 125 then result << '}'
    when 126 then result << '~'
    when 127 then result << '$DEL$'
    else
      result << '$NOT$'
    end
    return result
  end
 
  #===========================================================
  #**unpack_clear_byte
  #**Unpacks clear (>32) byte
  #===========================================================
 
  def unpack_clear_byte(byte)
    if byte <= 31
      byte = 32
    end
    $nrgss.unpack_byte(byte)
  end
 
  #===========================================================
  #**unpack_text
  #**Unpacks byte packed text (array)
  #===========================================================
 
  def unpack_text(texttabl)
    result = []
    texttabl.each{|byte|
    result << $nrgss.unpack_byte(byte)
    }
    return result.to_s
  end
 
  #===========================================================
  #**pack_bytes
  #**Packs bytes to array from text
  #===========================================================
 
  def pack_bytes(text)
    result = []
    text.each_byte{|byte| result << byte }
    return result
  end
 
  #===========================================================
  #**pack_byte
  #**Packs one byte to array from text
  #===========================================================
 
  def pack_byte(letter)
    result = []
    letter.each_byte{|byte| result << letter }
    return result.at(0)
  end
 
  #===========================================================
  #**encrypt_int
  #**Encrypts an int
  #===========================================================
 
  def encrypt_int(int, key=17)
	srand(key * 7 + 3)
	return rand(9999) + int
  end
 
  #===========================================================
  #**decrypt_int
  #**Decrypts an int
  #===========================================================
 
  def decrypt_int(int, key=17)
	srand(key * 7 + 3)
	return int - rand(9999)
  end
 
  #===========================================================
  #**file_read
  #**Reads file
  #===========================================================
 
  def file_read(file2)
    file = File.open(file2, 'rb')
    return file.read
  end
 
  #===========================================================
  #**file_write
  #**Writes file
  #===========================================================
 
  def file_write(var, file2)
    file = File.open(file2, 'wb')
    file.write(var)
    file.close
  end
 
  #===========================================================
  #**file_dump
  #**Dumps to file
  #===========================================================
 
  def file_dump(var, file2)
    file = File.open(file2, 'wb')
    Marshal.dump(var, file)
    file.close
  end
 
  #===========================================================
  #**file_link
  #**Links two files
  #===========================================================
 
  def file_link(afile, bfile, cfile)
    file1 = File.open(afile, 'rb')
    file2 = File.open(bfile, 'rb')
    file3 = File.open(cfile, 'wb')
    file3.write(file1.read)
    file3.write(file2.read)
    file1.close
    file2.close
    file3.close
  end
 
  #===========================================================
  #**cbrt
  #**3rd root
  #===========================================================
 
  def cbrt(x)
    result = x**(1.0/3.0)
    return result
  end
 
  #===========================================================
  #**root
  #**Root
  #===========================================================
 
  def root(nr, st)
    result = nr**(1.0/st.to_f)
    return result
  end
 
  #===========================================================
  #**oppose
  #**Oppose
  #===========================================================
 
  def oppose(nr)
    result = nr - (nr*2)
    return result
  end
 
  #===========================================================
  #**randomize
  #**Randomize a int with range
  #===========================================================
 
  def randomize(min, max)
    return rand(max - min + 1)
  end
 
  #===========================================================
  #**save_script
  #**Saves a RGSS scripts to text
  #===========================================================
 
  def save_script(filename='script.txt', scriptfile='Data/Scripts.rxdata')
    file = File.open(filename, 'wb')
    script = load_data(scriptfile)
    script.each {|s|
    file.write(Zlib::Inflate.inflate(s.at(2)))
    file.write("\n\n\n")
    }
    file.close
  end
 
  #===========================================================
  #**Messagebox
  #**Messgebox
  #===========================================================
 
  def messagebox(message, title, type)
    $msgbox.call(0, message, title, type)
  end
 
  #===========================================================
  #**b64_encode
  #**Encodes string using Base64 algorithm
  #===========================================================
 
  def b64_encode(x)
    return [x].pack('m')
  end
 
  #===========================================================
  #**b64_decode
  #**Decodes string using Base64 algorithm
  #**Dekoduje ciąg używając algorytmu Base64
  #**Narzew
  #===========================================================
 
  def b64_decode(x)
    return x.unpack('m').first
  end
 
  #===========================================================
  #**uu_encode
  #**Encodes string using UU algorithm
  #**Koduje ciąg używając algorytmu UU
  #**Narzew
  #===========================================================
 
  def uu_encode(x)
    return [x].pack('u')
  end
 
  #===========================================================
  #**uu_decode
  #**Decodes string using UU algorithm
  #**Dekoduje ciąg używając algorytmu UU
  #**Narzew
  #===========================================================
 
  def uu_decode(x)
    return x.unpack('u')
  end
 
  #===========================================================
  #**b64_encode_file
  #**Encodes file using Base64 algorithm
  #**Koduje plik używając algorytmu Base64
  #**Narzew
  #===========================================================
 
  def b64_encode_file(file, result)
    readfile = File.open(file, 'rb')
    writefile = File.open(result, 'wb')
    data = readfile.read
    writefile.write($nrgss.b64_encode(data))
    readfile.close
    writefile.close
  end
 
  #===========================================================
  #**b64_decode_file
  #**Decodes file using Base64 algorithm
  #**Dekoduje plik używając algorytmu Base64
  #**Narzew
  #===========================================================
 
  def b64_decode_file(file, result)
    readfile = File.open(file, 'rb')
    writefile = File.open(result, 'wb')
    data = readfile.read
    writefile.write($nrgss.b64_decode(data))
    readfile.close
    writefile.close
  end
 
  #===========================================================
  #**uu_encode_file
  #**Encodes file using UU algorithm
  #**Koduje plik używając algorytmu UU
  #**Narzew
  #===========================================================
 
  def uu_encode_file(file, result)
    readfile = File.open(file, 'rb')
    writefile = File.open(result, 'wb')
    data = readfile.read
    writefile.write($nrgss.uu_encode(data))
    readfile.close
    writefile.close
  end
 
  #===========================================================
  #**uu_decode_file(file, result)
  #**Decodes file using UU algorithm
  #**Dekoduje plik używając algorytmu UU
  #**Narzew
  #===========================================================
 
  def uu_decode_file(file, result)
    readfile = File.open(file, 'rb')
    writefile = File.open(result, 'wb')
    data = readfile.read
    writefile.write($nrgss.uu_decode(data))
    readfile.close
    writefile.close
  end
 
  #===========================================================
  #**uri_download
  #**Downloads file using open-uri algorithm. Clear Ruby only.
  #**Pobiera plik używając algorytmu open-uri. Tylko czyste ruby.
  #**Narzew
  #===========================================================
 
  def uri_download(x, nam)
    require 'open-uri'
    open(x) {|f|
    file = File.open(nam, 'wb')
    file.write(f.read)
    file.close
    }
  end
 
  #===========================================================
  #**location_table
  #**Gets location file list from location array
  #**Zwraca wszystkie nazwy plików z lokacji określonych w tablicy
  #**Narzew
  #===========================================================
 
  def location_table(locations_ary)
    result = []
    locations_ary.each{|location|
    Dir.foreach(location){|x|
    if x != '.'
      if x != '..'
        result << "#{location}/#{x}"
      end
    end
    }
    }
    return result
  end
 
  #===========================================================
  #**xorify_crypt
  #**Encrypts script using xorify algorithm. Only TEXT are supported.
  #**Koduje skrypt używając algorytmu xorify. Tylko TEXT jest obsługiwany.
  #**Narzew
  #===========================================================
 
  def xorify_crypt(source, destination, key=0x0AEEF6)
    file = File.open(source, "rb")
    data = file.read
    file.close
    s = []
    xorval = key
    data.each_byte{|byte|
    r = byte.to_i ^ xorval
    s << r
    xorval = xorval * 2 + 113 & 0xFFFFFFFF
    }
    $data = s
    file = File.open(destination, 'wb')
    Marshal.dump($data, file)
    file.close
  end
 
  #===========================================================
  #**xorify_eval
  #**Evals a xorify encrypted script
  #**Wykonuje skrypt zakodowany algorytmem xorify
  #**Narzew
  #===========================================================
 
  def xorify_eval(packed, key=0x0AEEF6, raiseonfailure=0)
    file = File.open(packed, 'rb')
    $data = Marshal.load(file)
    s = []
    xorval = key
    $data.each{|x|
    r = x ^ xorval
    s << r
    xorval = xorval * 2 + 113 & 0xFFFFFFFF
    }
    a = []
    s.each{|x|
    a << $nrgss.unpack_byte_clear(x)
    }
    script = a.to_s
    begin
      eval(script)
    rescue
      raise("Failed to load script") if raiseonfailure == 1
      print("Failed to load script") if raiseonfailure == 0
    end
  end
 
  #===========================================================
  #**mci_eval
  #**Gets a command from MCI DLL
  #**Wykonuje komendę na bibliotece MCI
  #**ForeverZer0
  #===========================================================
 
  def mci_eval(command)
    data = "\0" * 256
    $mcisendstring.call(command, data, 256, 0)
    return data.delete("\0")
  end
 
  #===========================================================
  #**open_cd_drive
  #**Opens CD drive
  #**Otwiera napęd CD
  #**ForeverZer0
  #===========================================================
 
  def open_cd_drive
    $nrgss.mci_eval('set CDAudio door open')
  end
 
  #===========================================================
  #**close_cd_drive
  #**Closes CD drive
  #**Zamyka napęd CD
  #**ForeverZer0
  #===========================================================
 
  def close_cd_drive
    $nrgss.mci_eval('set CDAudio door closed')
  end
 
  #===========================================================
  #**string_int
  #**Converts string to integer
  #**Konwertuje ciąg na liczbę
  #**Narzew
  #===========================================================
 
  def string_int(string)
    return string.to_i(36)
  end
 
  #===========================================================
  #**int_string
  #**Converts int to string
  #**Konwertuje liczbę na ciąg
  #**Narzew
  #===========================================================
 
  def int_string(int)
    return int.to_s(36)
  end
 
  #===========================================================
  #**tea97_hash
  #**Hashs int using TEA97 hashing algorithm. Ruby 1.8 only
  #**Hashuje liczbę używając algorytmu TEA97. Tylko Ruby 1.8
  #**Narzew
  #===========================================================
 
  def tea97_hash(x,y=133,z=413,k=817)
    $k = k.to_i + 113
    $y = y.to_i + 103
    $z = z.to_i + 404
    $result = []
    x = x.crypt(($k * $z + $y).to_s)
    x.each_byte{|b|
    s = b.to_i
    a = s.to_i ^ y.to_i + 4
    b = a.to_i ^ y.to_i + 7
    c = b ^ y.to_i + $k.to_i
    d = c ^ (y.to_i + 2) * $k.to_i
    e = d ^ (z.to_i + 7) * $k.to_i
    f = e ^ (z.to_i + k.to_i) * 3
    g = f ^ (y.to_i + z.to_i + 330) * 3
    h = g ^ $k.to_i
    $result << (h.to_i ^ k.to_i + 7)
    $k = $k.to_i * 2 + 5 & 0xFFFFFF
    }
    $result = $result.to_s.to_i / ($k * 348 + $y + 329429378 + $z * 117 + $k * 1113244)
    $result = $result.to_s
    return $result
  end
 
  #===========================================================
  #**xt_unpack
  #**Depacks xt packed array
  #**Depakowuje tablicę zapakowaną xt
  #**Narzew
  #===========================================================
 
  def xt_unpack(table, key=0)
    $key = key
    $xt = []
    table.each{|x|
    $xt << ((x - $key).to_s(36))
    $key = $key * 2 + 6
    }
    return $xt
  end
 
  #===========================================================
  #**xt_pack
  #**Packs array using xt algorithm
  #**Pakuje tablicę używając algorytmu xt
  #**Narzew
  #===========================================================
 
  def xt_pack(table, key=0)
    $key = key
    $xt = []
    table.each{|x|
    $xt << (x.to_i(36) + $key)
    $key = $key * 2 + 6
    }
    return $xt
  end
 
  #===========================================================
  #**make_rbl
  #**Makes a rbl from data array
  #**Tworzy rbl z tablicy
  #**Narzew
  #===========================================================
 
  def make_rbl(archivedata, file2)
    $result = {}
    $archive = archivedata
    $archive.each{|x,y|
    $result[$nrgss.uu_encode(x)] = Zlib::Deflate.deflate(y)
    }
    file = File.open(file2, 'wb')
    Marshal.dump($result, file)
    file.close
  end
 
  #===========================================================
  #**execute_rbl
  #**Executes a rbl section
  #**Ładuje sekcję rbl
  #**Narzew
  #===========================================================
 
  def execute_rbl(archivesection, archive, args=[])
    $rbl_args = args
    file = File.open(archive, 'rb')
    $result = Marshal.load(file)
    file.close
    $data = {}
    $result.each{|x,y|
    $data[x] = Zlib::Inflate.inflate(y)
    }
    eval($data[$nrgss.uu_decode(x)])
  end
 
  #===========================================================
  #**eval_all_rbl
  #**Executes all rbl sections. Will crash if it's function-caller library.
  #**Ładuje wszystkie sekcje rbl. Zwróci błąd jeśli to function-caller.
  #**Narzew
  #===========================================================
 
  def eval_all_rbl(rbl)
    file = File.open(rbl, 'rb')
    $result = Marshal.load(file)
    file.close
    $data = {}
    $result.each{|x,y|
    $data[x] = Zlib::Inflate.inflate(y)
    }
    $data.each{|x,y|
    eval(y)
    }
  end
 
  #===========================================================
  #**encrypt_int2
  #**Encrypts an int (Method 2)
  #**Koduje liczbę (Metoda 2)
  #**Narzew
  #===========================================================
 
  def encrypt_int2(int, key)
    $int = int * 17 + 113
    $key = (key + (114 * 19 - 724) * key)
    srand(key) rescue srand(9200)
    $r = $int
    rand(2000).times{
    srand($key + 3)
    $r = $r ^ ($key + 7)
    $r = $r + rand(200 + $key)
    $key = $key + rand(3999)
    }
    return $r
  end
 
  #===========================================================
  #**fgetb
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def fgetb
    x=0
    ret=0
    each_byte do |i|
      ret=i || 0
      break
    end
    return ret
  end
 
  #===========================================================
  #**fgetw
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def fgetw
    x=0
    ret=0
    each_byte do |i|
      break if !i
      ret|=(i<<x)
      x+=8
      break if x==16
    end
    return ret
  end
 
  #===========================================================
  #**fgetdw
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def fgetdw
    x=0
    ret=0
    each_byte do |i|
      break if !i
      ret|=(i<<x)
      x+=8
      break if x==32
    end
    return ret
  end
 
  #===========================================================
  #**fgetsb
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def fgetsb
    ret=fgetb
    if (ret&0x80)!=0
      return ret-256
    else
      return ret
    end
  end
 
  #===========================================================
  #**xfgetb
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def xfgetb(offset)
    self.pos=offset
    return fgetb
  end
 
  #===========================================================
  #**xfgetw
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def xfgetw(offset)
    self.pos=offset
    return fgetw
  end
 
  #===========================================================
  #**xfgetdw
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def xfgetdw(offset)
    self.pos=offset
    return fgetdw
  end
 
  #===========================================================
  #**getoffset
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def getoffset(index)
    self.nil
    self.pos=0
    offset=fgetdw>>3
    return 0 if index>=offset
    self.pos=index*8
    return fgetdw
  end
 
  #===========================================================
  #**getlength
  #**???
  #**???
  #**PeterO.
  #===========================================================
 
  def getlength(index)
    self.nil
    self.pos=0
    offset=fgetdw>>3
    return 0 if index>=offset
    self.pos=index*8+4
    return fgetdw
  end
 
  #===========================================================
  #**readname
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def readname(index)
    self.nil
    self.pos=0
    offset=fgetdw>>3
    return "" if index>=offset
    self.pos=index<<3
    offset=fgetdw
    length=fgetdw
    return "" if length==0
    self.pos=offset
    return read(length)
  end
 
  #===========================================================
  #**fputb
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def fputb(b)
    b=b&0xFF
    write(b.chr)
  end
 
  #===========================================================
  #**fputw
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def fputw(w)
    2.times do
      b=w&0xFF
      write(b.chr)
      w>>=8
    end
  end
 
  #===========================================================
  #**fputdw
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def fputdw(w)
    4.times do
      b=w&0xFF
      write(b.chr)
      w>>=8
    end
  end
 
  #===========================================================
  #**pos=
  #**???
  #**???
  #**Peter O.
  #===========================================================
 
  def pos=(value)
    seek(value)
  end
 
  #===========================================================
  #**swap32
  #**Swaps bytes
  #**Zamienia bity
  #**Peter O.
  #===========================================================
 
  def swap32(x)
    return ((x>>24)&0x000000FF)|((x>>8)&0x0000FF00)|((x<<8)&0x00FF0000)|((x<<24)&0xFF000000)
  end
 
  #===========================================================
  #**gcd
  #**The greatest common divisor
  #**Największy wspólny dzielnik
  #**KGC
  #===========================================================
 
  def gcd(x)
    ary = x.find_all { |i| i.is_a?(Integer) && i != 0 }
    ary.sort! { |a, b| b - a }
    return 0 if ary.size < 2
    g = ary[0].abs
    (1...ary.size).each { |i|
      n = ary[i].abs
      g = gcd_r(g, n)
    }
    return g
  end
 
  #===========================================================
  #**gcd_r
  #**???
  #**???
  #**Required function.
  #**KGC
  #===========================================================
 
  def gcd_r(a, b)
    while b != 0
      c = a
      a = b
      b = c % b
    end
    return a
  end
 
  #===========================================================
  #**lcm
  #**The smallest common multiple
  #**Najmniejsza wspólna wielokrotność
  #**KGC
  #===========================================================
 
  def lcm(x)
    ary = x.find_all { |i| i.is_a?(Integer) && i != 0 }
    return 0 if ary.size < 2
    l = ary[0].abs
    (1...ary.size).each { |i|
      n = ary[i].abs
      l = l * n / [l, n].gcd
    }
    return l
  end
 
  #===========================================================
  #**average
  #**The average number from array
  #**Średnia z numerów tablicy
  #**KGC
  #===========================================================
 
  def average(value)
    n = 0.0
    value.each {|i| n += i}
    return n / value.size
  end
 
  #===========================================================
  #**devsq
  #**Sum of squared deviations
  #**Suma kwadratów odchyleń
  #**KGC
  #===========================================================
 
  def devsq(value)
    n, v = 0.0, average(value)
    value.each {|i| n += (i - v) ** 2}
    return n
  end
 
  #===========================================================
  #**gmt
  #**Geometric mean (synergistic)
  #**Średnia geometryczna (synergetsyczna)
  #**KGC
  #===========================================================
 
  def gmt(value)
    n = 1.0
    value.each {|i| n *= i}
    return n ** (1.0 / value.size)
  end
 
  #===========================================================
  #**stdevp
  #**Standard deviation
  #**Odchylenie standardowe
  #**KGC
  #===========================================================
 
  def stdevp(value)
    return sqrt(var(value))
  end
 
  #===========================================================
  #**var
  #**Unbiased variance
  #**Bezstronna wariancja
  #**KGC
  #===========================================================
 
  def var(value)
    return 0.0 if value.size < 2
    return devsq(value) / (value.size - 1)
  end
 
  #===========================================================
  #**Ends of NRGSS class
  #**Koniec klasy NRGSS
  #===========================================================
 
end
 
#===========================================================
#**NRGSS Class Definition
#**Definicja klas NRGSS
#===========================================================
 
$nrgss = NRGSS.new
 
#===========================================================
#**End of Library
#**Koniec biblioteki
#===========================================================

#==============================================================================#
#                            END NEW CASH SCRIPT                               #
#==============================================================================#

[chapter]Demo[/chapter]
Hướng Dẫn: Nói chuyện với thằng bên trái trước để nhận và mã hoá cash. Rồi nói chuyện với thằng phía dưới để vào CShop.
Download:
MF: http://www.mediafire.com/download/d55c4c83xtukvbq/New_Cash_-_Demo.zip
4S: http://www.4shared.com/zip/cR_lC1Aoba/New_Cash_-_Demo.html

Comments

Sign In or Register to comment.