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.

Imitating RPGXP Product Key Prompt [Not Fixed Yet]

Before we get started, I will tell you first hand that this is an early script in progress. A couple people have PMed me telling me this would get more attention in the submitted scripts section, although I personally don't think it belongs here yet. There are still many things being worked out, but this script will be updated regularly.

You can feel free to beta test it for me and tell me how to improve the work thus far, it does somewhat what its supposed to do, but its still 'beta' so don't expect anything great yet. If you make any fixes or anything, let me know so I can update the script.

-Going to fix the module and Game_System class.
-Need to re-write the random code gen method, because its not-so-random.
-Need to figure out how to translate from one code to another.
-Some other stuff to fix :P

-Writting methods that'll shut game down after user-defined time.
-Game authors will be able to disable use of certain items, skills and equipment for 'trial version' of their game.
-Re-writes default classes, I'll make compatibility patches for certain scripts upon request
-More attention to detail :P

Code:
#===============================================================================
# ~** Activate Product Code **~
#===============================================================================
# Written by  : Kain Nobel
# Version     : 0.06 (Beta)
# Last Update : 5/14/2008
# Date Created: 4/28/2008
#===============================================================================
# Activation_Debug
#   true : Enabled for Playtest
#   false: Disabled for Playtest
#------------------------------------------
# Activation_Required
#   true : Enabled for Game.exe
#   false: Disabled for Game.exe
#------------------------------------------
# Activation_TL_Hour
#   nil : Doesn't calculate hours
#   0..? : Calculates to set max hours
#------------------------------------------
# Activation_TL_Min
#   nil : Doesn't calculate minutes
#   0..59 : Calculates to set max minutes
#------------------------------------------
# Activation_TL_Sec
#   nil : Doesn't calculate seconds
#   0..59 : Calculates to set max seconds
#------------------------------------------
# Serial_Digits_Max
#   How many keys long is the Serial #?
#------------------------------------------
# Product_Digits_Max
#   How many keys long is the Product #?
#------------------------------------------
# Activation_Digits_Max (Don't touch)
#   Adds Product and Serial digits together
#------------------------------------------
# Activation_Menu_Disable
#   true  : disable menu in trial version
#   false : menu isn't disabled by script
#------------------------------------------
# Activation_Save_Disabled
#   true  : disable save in trial version
#   false : save isn't disabled by script
#------------------------------------------
# Activation_Load_Disabled
#   true  : disable load in trial version
#   false : load isn't disabled by script
#===============================================================================
# Activation File
Activation_File = "Activation"
# Script and Debug
Activation_Debug = true
Activation_Required = false
# Time Limit
Activation_TL_Hour = nil
Activation_TL_Min = nil
Activation_TL_Sec = nil
# Digits Max
Serial_Digits_Max = 25
Product_Digits_Max = 25
# Function Restrictions
New_Game_Disabled = false
Continue_Disabled = true
Activation_Menu_Disabled = false
Activation_Save_Disabled = false
Activation_Load_Disabled = false
# Do Not Touch Last Constant, script will malfunction
Activation_Digits_Max = Serial_Digits_Max + Product_Digits_Max
################################################################################
#===============================================================================
# ** Module RPG::Activation
#===============================================================================
module RPG
  class Serial_Number
    def initialize
      key = []
    end
  end
  class Product_Code
    def initialize
      key = []
    end
  end
end
################################################################################
#===============================================================================
# ** Game_System
#===============================================================================
class Game_System
  #[Attributes]-----------------------------------------------------------------
  attr_reader :serial_number
  attr_reader :product_code
  #-----------------------------------------------------------------------------
  alias_method :activation_game_system_initialize, :initialize
  #--------------------
  # * Initialize Method
  #--------------------
  def initialize
    serial_number = RPG::Serial_Number
    product_code = RPG::Product_Code
    register_codes
    activation_game_system_initialize
  end
  #-----------------
  # * Code Generator
  #-----------------
  def code_generator
    if @code_type.is_a?(RPG::Serial_Number)
      code = ['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', '1', '2',
      '3', '4', '5', '6', '7', '8', '9', '0']
      serial_number.key = code
    elsif @code_type.is_a?(RPG::Product_Code)
      code = ['0', '9',  '8', '7', '6', '5', '4', '3', '2', '1', 'Z', 'Y', 'X', 
      'W', 'V', 'U', 'T', 'S', 'R', 'Q', 'P', 'O', 'N', 'M', 'L', 'K', 'J', 'I',
      'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A']
      product_code.key = code
    end
  end
  #-----------------
  # * Register Codes
  #-----------------
  def register_codes
    if serial_number == nil
      @code_type = serial_number
      code_generator
    end
    if product_code == nil
      @code_type = product_code
      code_generator
    end
    # KN: Test-----------------
    if $DEBUG == true and Activation_Debug == true
      codes_valid?
      if codes_valid?
        print "Codes Valid!"
        record_numbers
      else
        print "Codes Invalid!"
        record_numbers
      end
    end
    # KN: Test-----------------
  end
  #---------------
  # * Codes Valid?
  #---------------
  def codes_valid?
    if serial_number != nil and product_code != nil
      if serial_number == product_code
        @valid = true
      else
        @valid = false
      end
    end
    return @valid
  end
  #-----------------
  # * Record Numbers
  #-----------------
  def record_numbers
    filename = "Data/" + Activation_File + ".rxdata"
    if FileTest.exist?(filename) == true
      code_generator
    end
    file = File.open(filename, "wb")
    Marshal.dump($game_system, file)
    file.close
  end
end
################################################################################
#===============================================================================
# ** Window_Activation
#-------------------------------------------------------------------------------
# This Window is called at the title screen if the user's activation validation
# code hasn't been entered.
#===============================================================================
class Window_Activation < Window_Base
  #--------------------
  # * Initialize Method
  #--------------------
  def initialize
    super(160, 56, 320, 224)
    self.contents = Bitmap.new(width - 32, height - 32)
    @reg_serial = 0 # $game_system.serial_number #error
    @reg_product = 0 # $game_system.product_number #error
    @activation = []
    self.back_opacity = 160
    refresh
  end
  #-----------------
  # * Refresh Method
  #-----------------
  def refresh
    @reg_serial = $game_system.serial_number
    @reg_product = $game_system.product_code
    # Refresh Window
    self.contents.clear
    # Draw Code Names
    self.contents.font.color = system_color
    self.contents.draw_text(0, 0, 128, 32, "Serial Number")
    self.contents.draw_text(0, 64, 160, 32, "Product Number")
    self.contents.draw_text(0, 128, 160, 32, "Activation Code")
    # Draw Code Values
    self.contents.font.color = normal_color
    self.contents.draw_text(0, 32, 128, 32, @reg_serial.to_s, 2)
    self.contents.draw_text(0, 96, 128, 32, @reg_product.to_s, 2)
    self.contents.draw_text(0, 160, 128, 32, @reg_activ.to_s, 2)
  end
  #----------------
  # * Update Method
  #----------------
  def dispose
    super
  end
end
################################################################################
#===============================================================================
# ** Scene_Title (Aliased)
#-------------------------------------------------------------------------------
#   This scene is aliased to include the Activation scene when entering either
# command_new_game, or command_continue (provided a save file is present.)
#===============================================================================
class Scene_Title
  #-----------------------------------------------------------------------------
  # * Aliased Methods
  #-----------------------------------------------------------------------------
  alias_method :activation_scene_title_main, :main
  alias_method :activation_scene_title_new_game, :command_new_game
  alias_method :activation_scene_title_continue, :command_continue
  #------------------------
  # * Main Method (Aliased)
  #------------------------
  def main
    # Create Activation Window, make it invisible and inactive.
    serial_number = $game_system.serial_number
    product_code = $game_system.product_code
    if $activation == false
      @activ_window = Window_Activation.new
      @activ_window.visible = true
      @activ_window.active = true
    end
    # Alias method
    activation_scene_title_main
  end
  #---------------------
  # * New Game (Aliased)
  #---------------------
  def command_new_game
    # Open Activation window if purchase registration not completed
    if New_Game_Disabled == false
      # Alias method
      activation_scene_title_new_game
    elsif $activation == false and New_Game_Disabled == true
      # Goto: Enter Registration Method
      enter_registration
    end
  end
  #---------------------
  # * Continue (Aliased)
  #---------------------
  def command_continue
    if $activation #serial_number == product_code
      # Alias method
      activation_scene_title_continue
    elsif $activation == false and Continue_Disabled == true
      # Goto: Enter Registration method
      enter_registration
    end
  end
  #---------------------
  # * Enter Registration
  #---------------------
  def enter_registration
    # Coming soon...
    print("Coming Soon...")
  end
end
################################################################################
#===============================================================================
# ** Scene Save
#===============================================================================
class Scene_Save
  #--------------------------------
  # * Initialize Method (Overwrite)
  #--------------------------------
  def initialize
    @serial_number = $game_system.serial_number
    @product_code = $game_system.product_code
    # If you haven't entered product key...?
    if @serial_number == @product_code
      # Prints message, save disabled flag is true
      super("You cannot save without activation key.")
      @flag_save_disable = true
    else
      # Prints message, save disabled flag is false
      super("Which file would you like to save to?")
      @flag_save_disable = false
    end
    # Goto: Save Enabled? Method
    save_enabled?
  end
  #--------------
  # * On Decision
  #--------------
  def on_decision(filename)
    if save_enabled? == true # KN: false
      # Play Buzzer SE
      $game_system.se_play($data_system.buzzer_se)
      # Print Message
      print("Sorry, you must first enter a Product Code")
    else
      # Play save SE
      $game_system.se_play($data_system.save_se)
      # Write save data
      file = File.open(filename, "wb")
      write_save_data(file)
      file.close
      # If called from event
      if $game_temp.save_calling
        # Clear save call flag
        $game_temp.save_calling = false
        # Switch to map screen
        $scene = Scene_Map.new
        return
      end
      # Switch to menu screen
      $scene = Scene_Menu.new(4)
    end
  end
  #---------------
  # * Disable Save
  #---------------
  def save_enabled?
    if @flag_save_disabled == true
      $game_system.save_disabled = true
    else
      $game_system.save_disabled = false
    end
  end
end
################################################################################
 
from what i see in the script is suppose to pop a window up and make them put in a key to register the game. So be like a commercial game  and they pay for a product key like you do for the maker. but if you say it did nothing then it doesn't work.
 
Yikes, I thought I fixed most of the errors on the last update, but this one is worse... and thats not the right Game_System class, that is the main part of the script that is out-of-date >.<

I'll be working the errors out tonight, I appologize for any inconvenience, hopefully I'll have a more functional version by Wednesday... keep in mind this is still beta.

Any suggestions on better coding examples can be posted here, or the link in my sig will direct you to the support topic for this script. I'm replacing the array with the 'dummy' codes with some kinda gsub method, and hopefully I'll have randomly generated codes at startup on the next version. (Delete the Activation.rxdata in your game folder if it exists.)
 
so i was looking at comments and for the hours part. is it with so many hours played you have to submit the activation code? if so this will be great for commercial games instead of dimming down features but have a full flegded game but only for so many hours for free or if your kind to give out hte keys for free.
 
for the key why dont you use the Win32API.new('advapi32','CryptGenRandom',['i','l','l','i'],'i') feature so that it randomly creates a key depending on the computer (you could even integrate more features such as an IP tracker and such... and then you can use the save_data function to save the code permanently to the rgssad file... that way noone can change or hack it and you can make each computer have its own code... im currently working on somethign like this for my updater and own commercial code system so if you need any help with the API and such im here XD


#by the way the cryptgenrandom parameters may be wrong as i just used memory to type it... im at school ATM
 
I really need something like this for my own commercial project but as explained before this is way beyond my league!

Anyway sorry kain it doesn't work I'm afraid. Kind of like mine! :lol:
 
I'm very sorry I haven't updated it like I promised, working overtime lately, I will hopefully have a new update within the next couple days.

mechacrash, I would love any help you could give me, I haven't had time to work on anything and your knowledge would help push me in the right direction with this. Also, if you know how to create an actual 'Window' that you could prompt a keycode in (not a game window but an actual Window window), that'd be very cool and professional too for a commercial game XD

Everything else I'm sure I could figure out on my own, but if you wanna help me on that, feel free to do so I appreciate the help.
 
its easy to get the real window prompt... but you need to know C or ALOT of ruby (also the fact that you'd then neede to package a ruby system and ruby interpreter with your game would be nasty).

You create the window and its functions in C then save it as a .dll

then all you do is call the window handle and function from that .dll using Win32API.new and boom... your done...

sending the data from that window across may be harder, you could probably make it save a file then read the file and delete it within a millisecond so any coding platform would work there... of course to get a real code prompt you need something that stores the codes and such on the internet which is a problem of its own...

these things are all difficult overall but hey... its worth a try XD
 
I'm working on this script, its being more difficult than expected, and I've re-written the alithrogram for the code 1,000,000x's over.

If you would like to help me on it, I've got a seperate help topic where it belongs, here.

I'm sorry but I was hoping to get it out of beta stage sooner, I need some help and suggestions. For anything as far as ideas you can post them here, otherwise visit the help topic in order to assist me in my challenge of writting this.

Please leave this thread alone, until I fix the script.
 

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