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.

Code Generating

Some of you already know that I'm making a Game Serial prompt, but I have a problem... the half working version of Game_System (modified) that goes into the script has been overwritten, but I had to re-code it anyways... theres still an older version on this topic if you need to look at anything for reference.

So here is the way I am doing the 'semi-random code' stuff, it handles it through arrays 'n all that fun stuff... arrays and text.gsub! methods are new to me, and I'm not even sure if this is coded right. Please tell me anything that you might know or how to better code the method if I'm doing something wrong.

Code:
Key_A = '9'
Key_B = '8'
Key_C = '7'
Key_D = '6'
Key_E = '5'
Key_F = '4'
Key_G = '3'
Key_H = '2'
Key_I = '1'
Key_J = '0'
Key_K = 'Z'
Key_L = 'Y'
Key_M = 'X'
Key_N = 'W'
Key_O = 'V'
Key_P = 'U'
Key_Q = 'T'
Key_R = 'S'
Key_S = 'R'
Key_T = 'Q'
Key_U = 'P'
Key_V = 'O'
Key_W = 'N'
Key_X = 'M'
Key_Y = 'L'
Key_Z = 'K'
Key_1 = 'J'
Key_2 = 'I'
Key_3 = 'H'
Key_4 = 'G'
Key_5 = 'F'
Key_6 = 'E'
Key_7 = 'D'
Key_8 = 'C'
Key_9 = 'B'
Key_0 = 'A'
class Game_System
  #[Attributes]-----------------------------------------------------------------
  attr_accessor :serial_number
  attr_accessor :product_number
  #[Alias Methods]
  alias_method :kn_activation_game_system_initialize, :initialize
  #--------------------
  # * Initialize Method
  #--------------------
  def initialize
    kn_activation_game_system_initialize
    @serial = nil
    @product = nil
    @key_codes = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
                  'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
                  'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    codes_validated
  end
  #---------------------------
  # * Check if Codes Validated
  #---------------------------
  def codes_validated
    if FileTest.exist?(filename) == true
      $data_activation = Activation_File + .new
      @serial = $data_activation.serial_number
      @product = $data_activation.product_number
      if @serial != nil or @product != nil
        serial_number
      end
    end
  end
  #------------------
  # * Generate Serial
  #------------------
  def serial_number(digits_max)
    @serial = serial_number
    @digits_max = Activation_DigitsMax
    for i in 0..@serial.digits_max
      until @digits_max == 0
        @serial.push(rand[@key_codes])
        @digits_max -= 1
      end
      return @serial
      product_number
    end
  end
  #-------------------
  # * Generate Product
  #-------------------
  def product_number(digits_max)
    @digits_max = Activation_DigitsMax
    @product = serial_number
    for i in 0..@product.digits_max
      until @digits_max == 0
        @product.sub_code_text
        @digits_max -= 1
      end
      return @product
      codes_validated = true
    end
  end
  #-------------------
  # * Sub Code Text
  #-------------------
  def sub_code_text
    @text.gsub!(/[1]/) do Key_1 end
    @text.gsub!(/[2]/) do Key_2 end
    @text.gsub!(/[3]/) do Key_3 end
    @text.gsub!(/[4]/) do Key_4 end
    @text.gsub!(/[5]/) do Key_5 end
    @text.gsub!(/[6]/) do Key_6 end
    @text.gsub!(/[7]/) do Key_7 end
    @text.gsub!(/[8]/) do Key_8 end
    @text.gsub!(/[9]/) do Key_9 end
    @text.gsub!(/[0]/) do Key_0 end
    @text.gsub!(/[Aa]/) do Key_A end
    @text.gsub!(/[Bb]/) do Key_B end
    @text.gsub!(/[Cc]/) do Key_C end
    @text.gsub!(/[Dd]/) do Key_D end
    @text.gsub!(/[Ee]/) do Key_E end
    @text.gsub!(/[Ff]/) do Key_F end
    @text.gsub!(/[Gg]/) do Key_G end
    @text.gsub!(/[Hh]/) do Key_H end
    @text.gsub!(/[Ii]/) do Key_I end
    @text.gsub!(/[Jj]/) do Key_J end
    @text.gsub!(/[Kk]/) do Key_K end
    @text.gsub!(/[Ll]/) do Key_L end
    @text.gsub!(/[Mm]/) do Key_M end
    @text.gsub!(/[Nn]/) do Key_N end
    @text.gsub!(/[Oo]/) do Key_O end
    @text.gsub!(/[Pp]/) do Key_P end
    @text.gsub!(/[Qq]/) do Key_Q end
    @text.gsub!(/[Rr]/) do Key_R end
    @text.gsub!(/[Ss]/) do Key_S end
    @text.gsub!(/[Tt]/) do Key_T end
    @text.gsub!(/[Uu]/) do Key_U end
    @text.gsub!(/[Vv]/) do Key_V end
    @text.gsub!(/[Ww]/) do Key_W end
    @text.gsub!(/[Xx]/) do Key_X end
    @text.gsub!(/[Yy]/) do Key_Y end
    @text.gsub!(/[Zz]/) do Key_Z end
  end
end

mechacrash mentioned using WinAPI and writting it to the registry 'n stuff, however I ponder that this might be better handled from within the encrypted game itself, just writting it to Activation.rxdata within the Data/ folder of an encrypted project. However, I wrote a line similiar to this one...

Code:
Activation_File = 'Activation'
#...
filename = Activation_File + .new
File.open(filename, "rb") { |f|
  obj = Marshal.load(f)
}

Which supposedly can handle encrypted file data, according to the help file, and it errors. Any ideas on what I have to do to get that to work? (I've only tested it in an un-encrypted project).

Also, critique on the new Game_System code generating functions would be helpful too, I haven't had time to test it. I'm off to work, thanks ahead of time to anybody who can help me (again).

Also, handle using WinAPI and writting to registry, or just handling it within the game files themselves... what you think would be better? (I have no knowledge of RGSS + WinAPI so that would involve some extra help.)
 
Okay, I've re-wrote this for the millionth time, I keep getting an error when trying to read data from the file though. It pops this error

Load Error":3vvick6s said:
Script 'RPGXP Serial Acitvation' line 72: TypeError Occured

incompatible marshal file format (can't be read)
format version 4.8 required; 68.97 given

One version of the file it can read, is written like this...

ࠄ㩯äœ
 
Okay, so I re-wrote it like this
Code:
if FileTest.exist?(@filename) == true
      file = File.open(@filename, "wb")
      $data_activation = Marshal.load(@filename)
      @activ_serial = $data_activation.id_serial
      @activ_product = $data_activation.id_product
      @activ_keycode = $data_activation.keycode
      file.close
    else

But its still giving me that error.

Code:
  #-----------------
  # * Write To File
  #-----------------
  def write_to_file
    file = File.open(@filename, "wb")
    Marshal.dump($data_activation, file)
    file.close
  end

I had it write me a brand new file and it won't read that one either, even with dummy data in it. Even with the file open its still popping the error. I tried copying and resaving the data in the .rxdata in unicode and UTF-8, I don't know what else it needs.
 
I tried changing "wb" to "rb", then searched through the help file because I wasn't sure if there's something else. I changed it to

file = File.open(@filename, "rb")
$data_activation = Marshal.load(@filename) #<--Still pops error at this line.

Its the same error, even with the newly created file (I pasted the old file's contents into the new file though, because the data is blank for now.)

I donno, I'm going in circles with this, perhaps I'll figure it out.
 
File.open(@filename,'rb'){|f|
$data_activation = Marshal.load(f)}

thast should work... i dnt use VX so i dont know if they changed it but in XP you had to use the load_data function to access files within encrypted archives... if this hasnt changed (which i doubt it has) then that'll also be a problem, you wont be able to load the file from an encrypted game, you'll have to use this call:

$data_activation = load_data("Data/" + @filename)

i think... i'll pose back once ive looked at VX for a bit


*EDIT*
yep i checked the help file for VX, if you want the file to be saved within the encrypted archive you'll need to use the save_data function and load_data function to load it... its the same as marshaling a file but RGSS reads it differently and runs a different code built into RGSS, this allows the file to be added to the Zlib compressed file... im working on how to do this myself (as i can already decrypt files within it XD)
 

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