Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

HBGames

Data Encrypter/Decrypter - Version: 1.0


Introduction

This is a script to overcome some of RMXP's limitations. It takes the decrypts the data files into an editable format, then encrypts them back into the data files.

Screenshots

Not necessary (It's just a command window on the title background)

Script
Code:
#=============================================================================

#  Data Encrypter/Decrypter

#  Version 1.0

#-----------------------------------------------------------------------------

#  Scripted by: Yeyinde

#  Help from: Trickster

#  December 2006

#-----------------------------------------------------------------------------

#  This script decrypts some of the data files in the Data folder, then can

#  remake that decrypted data into new data files.  Because this script will

#  modify the original data files, I suggest you make a backup.

#  Take note on how the data comes out.  That is how the data should look like

#  when, and if, you make changes.

#  Call with $scene = Scene_DataManager.new

#=============================================================================

 

class Scene_DataManager

  def main

    @command_window = Window_Command.new(160, ['Decrypt', 'Encrypt'])

    @command_window.back_opacity = 160

    @command_window.x = 320 - @command_window.width / 2

    @command_window.y = 288 

    @sprite = Sprite.new

    @sprite.bitmap = RPG::Cache.title($data_system.title_name) 

    Graphics.transition

    loop do

      Graphics.update

      Input.update

      update

      break if $scene != self

    end

    Graphics.freeze

    @command_window.dispose

    @sprite.dispose

  end

  def update

    @command_window.update

    @sprite.update

    if Input.trigger?(Input::B)

      $game_system.se_play($data_system.cancel_se)

      $scene = Scene_Map.new

      return

    end

    if Input.trigger?(Input::C)

      $game_system.se_play($data_system.decision_se)

      if @command_window.index == 0

        decrypt

      else

        if File.directory?('D_Data')

          encrypt

        else

          print 'Cannot encrypt nothing.  Decrypt data first.'

          return

        end

      end

      $scene = Scene_Map.new

      return

    end

  end

  # Main encrypt method

  def encrypt

    print 'Now encrypting data.'

    encrypt_data('Actors')

    encrypt_data('Classes')

    encrypt_data('Skills')

    encrypt_data('Items')

    encrypt_data('Weapons')

    encrypt_data('Armors')

    encrypt_data('Enemies')

    encrypt_data('States')

    encrypt_data('System', false)

    print 'Data encryption complete.  Now reseting data.'

    $data_actors        = load_data("Data/Actors.rxdata")

    $data_classes       = load_data("Data/Classes.rxdata")

    $data_skills        = load_data("Data/Skills.rxdata")

    $data_items         = load_data("Data/Items.rxdata")

    $data_weapons       = load_data("Data/Weapons.rxdata")

    $data_armors        = load_data("Data/Armors.rxdata")

    $data_enemies       = load_data("Data/Enemies.rxdata")

    $data_states        = load_data("Data/States.rxdata")

    $data_system        = load_data("Data/System.rxdata")

  end

  # Encrypt Data method

  def encrypt_data(data_file, array = true)

    file = File.new('D_Data/' + data_file + '.txt')

    lines = file.readlines

    file.close

    data = array ? [nil] : RPG::System.new

    element = case data_file

              when 'Actors'

                RPG::Actor.new

              when 'Classes'

                RPG::Class.new

              when 'Skills'

                RPG::Skill.new

              when 'Items'

                RPG::Item.new

              when 'Weapons'

                RPG::Weapon.new

              when 'Armors'

                RPG::Armor.new

              when 'Enemies'

                RPG::Enemy.new

              when 'States'

                RPG::State.new

              end

    lines.each_with_index do |line, index|

      name = line.split(' = ')

      if line.size == 1

        data << element if array

        element = case data_file

                  when 'Actors'

                    RPG::Actor.new

                  when 'Classes'

                    RPG::Class.new

                  when 'Skills'

                    RPG::Skill.new

                  when 'Items'

                    RPG::Item.new

                  when 'Weapons'

                    RPG::Weapon.new

                  when 'Armors'

                    RPG::Armor.new

                  when 'Enemies'

                    RPG::Enemy.new

                  when 'States'

                    RPG::State.new

                  end

        next

      end

      var_data = name[1].chomp

      var_data = remake_data(var_data)

      name = name[0]

      data.is_a?(RPG::System) ? data : element

      eval("(data.is_a?(RPG::System) ? data : element).#{name} = var_data")

    end

    save_data(data, 'Data/' + data_file + '.rxdata')

  end

  def remake_data(variable)

    if variable.include?('RPG::AudioFile.new(')

      variable.gsub!('RPG::AudioFile.new(', '')

      variable.gsub!(')', '')

      variable = variable.split(',')

      variable[0].gsub!(/\"/, '')

      variable = RPG::AudioFile.new(variable[0], variable[1].to_i, variable[2].to_i )

    elsif variable.include?('Words{')

      variable.gsub!('Words{', '')

      variable.gsub!('}', '')

      vars = variable.split(',')

      vars.each {|var| var.gsub!(/\"/, '')}

      variable = RPG::System::Words.new

      vars.each do |var|

        var = var.split(':')

        eval("variable.#{var[0]} = '#{var[1]}'")

      end

    elsif variable.include?('Table(')

      variable.gsub!('Table(', '')

      var_data = variable.split(')')

      var_data[0] = var_data[0].split(',')

      var_data[0][0] = var_data[0][0].to_i

      var_data[0][1] = var_data[0][1].to_i if var_data[0][1]

      variable = Table.new(*var_data[0])

      var_data[1].gsub!('[', '')

      var_data[1].gsub!(']', '')

      var_data[1] = var_data[1].split(':')

      for x in 0...var_data[0][0]

        if var_data[0][1]

          var_data[1][x] = var_data[1][x].split(',')

          var_data[1][x].each_with_index do |obj, y|

            variable[x, y] = obj.to_i

          end

        else

          variable[x - 1] = var_data[1][x - 1].to_i

        end

      end

    elsif variable.include?('[')

      variable.gsub!('[', '')

      variable.gsub!(']', '')

      vars = variable.split(',')

      variable = []

      vars.each {|new_variable| variable.push(remake_data(new_variable))}

    elsif variable.include?('Action{')

      variable.gsub!('Action{', '')

      variable.gsub!('}', '')

      vars = variable.split(';')

      vars.each {|var| var.gsub!(/\"/, '')}

      variable = RPG::Enemy::Action.new

      vars.each do |var|

        var = var.split(':')

        eval("variable.#{var[0]} = #{var[1]}.to_i")

      end

    elsif variable.include?('Learning(')

      variable.gsub!('Learning(', '')

      variable.gsub!(')', '')

      var = variable.split(':')

      variable = RPG::Class::Learning.new

      variable.level = var[0].to_i

      variable.skill_id = var[1].to_i

    elsif variable.include?('"')

      variable.gsub!(/\"/, '')

    elsif variable == 'false'

      variable = false

    elsif variable == 'true'

      variable = true

    elsif variable == 'nil'

      variable = nil

    else

      variable = variable.to_i

    end

    return variable

  end

  # Main decrypt method

  def decrypt

    # Check if 'D_Data' is not there, then make it

    unless File.directory?('D_Data')

      Dir.mkdir('D_Data')

    end

    print 'Now decrypting data.'

    decrypt_data('Actors')

    decrypt_data('Classes')

    decrypt_data('Skills')

    decrypt_data('Items')

    decrypt_data('Weapons')

    decrypt_data('Armors')

    decrypt_data('Enemies')

    decrypt_data('States')

    decrypt_data('System')

    print 'Data decryption complete.'

  end

  # Decrypt Data method

  def decrypt_data(data_file)

    data = load_data('Data/' + data_file + '.rxdata')

    file = File.open('D_Data/' + data_file + '.txt', 'w')

    if data.is_a?(Array)

      for i in 0..data.size

        next if data[i].nil?

        puts data_file + ' #' + i.to_s

        variables = data[i].instance_variables

        variables.each do |variable|

          varname = variable.delete('@')

          file.print(varname,' = ')

          object = eval("data[i].#{varname}")

          print_data(object, file)

        end

        file.print("\n")

      end

    else

      variables = data.instance_variables

      variables.each do |variable|

        varname = variable.delete('@')

        next if varname == '_'

        file.print(varname, ' = ')

        object = eval("data.#{varname}")

        print_data(object, file)

      end

    end

    file.close

  end

  def print_data(object, file, newline = true)

    case object

    when Array

      file.print('[')

      object.each_with_index do |element, index|

        print_data(element, file, false)

        file.print(',') unless index == object.size - 1

      end

      file.print(']')

    when Hash

      file.print('{')

      object.each {|k, v| file.print(k, ':', v, ',')}

      file.print('}')

    when Numeric

      file.print(object)

    when String

      file.print('"' + object + '"')

    when TrueClass

      file.print('true')

    when FalseClass

      file.print('false')

    when NilClass

      file.print('nil')

    when RPG::AudioFile

      file.print('RPG::AudioFile.new(')

      file.print('"', object.name, '",', object.volume, ',', object.pitch, ')')

    when Table

      file.print('Table(', object.xsize)

      if object.ysize > 1

        file.print(',', object.ysize)

      end

      file.print(')')

      file.print('[')

      object.xsize.times do |x|

        

        if object.ysize != 1

          object.ysize.times do |y|

            print_data(object[x, y], file, false)

            file.print(',') unless y == object.ysize - 1

          end

        else

          print_data(object[x], file, false)

        end

        file.print(':') unless x == object.xsize - 1

        

      end

      file.print(']')

    when RPG::System::Words

      file.print('Words{')

      file.print('"gold":"', object.gold, '",')

      file.print('"hp":"', object.hp, '",')

      file.print('"sp":"', object.sp, '",')

      file.print('"str":"', object.str, '",')

      file.print('"dex":"', object.dex, '",')

      file.print('"agi":"', object.agi, '",')

      file.print('"int":"', object.int, '",')

      file.print('"atk":"', object.atk, '",')

      file.print('"pdef":"', object.pdef, '",')

      file.print('"mdef":"', object.mdef, '",')

      file.print('"weapon":"', object.weapon, '",')

      file.print('"armor1":"', object.armor1, '",')

      file.print('"armor2":"', object.armor2, '",')

      file.print('"armor3":"', object.armor3, '",')

      file.print('"armor4":"', object.armor4, '",')

      file.print('"attack":"', object.attack, '",')

      file.print('"skill":"', object.skill, '",')

      file.print('"guard":"', object.guard, '",')

      file.print('"item":"', object.item, '",')

      file.print('"equip":"', object.equip, '"}')

    when RPG::Class::Learning

      file.print('Learning(', object.level.to_s, ':', object.skill_id.to_s, ')')

    when RPG::Enemy::Action

      file.print('Action{')

      file.print('"kind":', object.kind, ';')

      file.print('"basic":', object.basic, ';')

      file.print('"skill_id":', object.skill_id, ';')

      file.print('"condition_turn_a":', object.condition_turn_a, ';')

      file.print('"condition_turn_b":', object.condition_turn_b, ';')

      file.print('"condition_hp":', object.condition_hp, ';')

      file.print('"condition_level":', object.condition_level, ';')

      file.print('"condition_switch_id":', object.condition_switch_id, ';')

      file.print('"rating":', object.rating, '}')

    end

    file.print("\n") if newline

  end

end

Instructions

Place this script directly above Main. Call it with $scene = Scene_DataManager.new
If running in test play, this the encryption will not work. Run Game.exe if you want to encrypt the data. This script will only do Actors, Classes, Skills, Items, Weapons, Armor, Enemies, and the System data. Other data is either too complex or too difficult to write down to use.

FAQ



Credits and Thanks

Thanks to Trickster who help fix a few bugs.

Author's Notes

Because this script overwrites the original data files, I strongly recommend that you make a backup of them.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top