#===============================================================================
# ~** 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
#===============================================================================
# Script and Debug
Activation_Debug = false
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
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
################################################################################
# What does it do?
#===============================================================================
#Â Â When you open the game and are brought to the Title screen, you are only
# allowed to access New Game, you are not allowed to continue. Also, you are
# not allowed to save a game in progress and have a specified time frame in
# which you're allowed to play the game, until you've activated the game.
#Â Â Upon accessing a New Game, or trying to Save in a game in progress, you
# will be re-directed to the "Enter Product Key" window, where you must
# enter your "Proof of Purchase" code. Once you've entered a "Proof of Purchase"
# code, it is to be permanently saved to the Game_System so you will be able
# to play the game with no limitations.
#Â Â NOTE: By default, the system allows for New Game, which will let players
# play for a limited time (hence the option to set the time limit.) This will
# automatically exit the game after its been on for a certain ammount of time.
################################################################################
# Who would Want this?!
#===============================================================================
#Â Â Somebody who plans on selling their game to the general public for a small
# profit, or somebody who would require money for a person to play their game,
# such as an MMORPG, to keep their server running, etc.
#Â Â I personally didn't write this for my own use, but hopefully somebody would
# find good use of it. For god's sake, I wouldn't use it for a project demo or
# anything without disabling/removing the script, but if you've got a FULL game
# you want to sell (that doesn't suck) go ahead and use the script, and be sure
# to not expose your personal code keys to the public (thats why they're blank.)
################################################################################
# How are the codes determined?
#===============================================================================
#Â Â They are randomized upon first startup, and saved into the system. Each code
# translates as being the same, but are 'cloaked' to be different. The actual
# 'values' MUST be set by you, every letter A to Z and number 0 to 9, so that it
# they're unique from somebody else's game. That is why, when you open the
# script, you notice it is defined like...
#
# key_a = ['A', '', '']
#
# Those blank '' you must write a letter/number in and make sure you don't use
# the same value twice in the same column, like so...
#
# key_a = ['', 'C', '']
# key_b = ['', 'C', '']
#
# Notice how the middle digits are both 'C' ? Refrain from using the same letter
# or number twice, because that'll defeat the purpose of the codes translating
# like they should, and you'll possibly lose customers. Nobody wants to purchase
# a game, just to rip their hair out when trying to enter their purchased
# product key.
################################################################################
# Whats the chances of the same codes working on another game?
#===============================================================================
#Â Â Highly unlikely, they're randomized. Letters A-Z is 26 + 0-9 is 10, so thats
# 36 x 36 = 1296 different codes possible to be generated, so it's not exactly
# easy to get duplicate codes on different games.
################################################################################
# How are the codes set up?
#===============================================================================
# serial = [@serial_a, @serial_b, @serial_c, @serial_d, @serial_e]
# product = [@product_a, @product_b, @product_c, @product_d, @product_e]
#
# These all translate into each other, so secretly @serial_a and @product_a are
# really the same code translated like XD3F9 <--> MF89C
#
# Then when we get to activation code, it secretly translates like
#
# activation[@serial_a, @product_a, @serial_b, @product_b, ...]
#
# Again, each 'key' translates like A = ['A', '0', 'C'], depending on what
# type of code we're talking about.
################################################################################
# How do I give a customer their activation code?
#===============================================================================
#Â Â Sorry, thats the only thing that's completely up to you to handle. Best bet
# would be to have them send their codes to some kinda website server that'll
# translate their activation code for them, which I know nothing about. As long
# as you know how my script works, you'll have to develop a keygen tool for your
# project yourself, with the same 3 values for each Key as you've defined in the
# script.
#Â Â If worse comes to worse, they'll have to E-mail their serial/product
# code to you, and you'll have to translate it for them by hand. You better be
# on it if you're selling your game, because I do not support ripping people
# off!
#
#Â Â Good luck and have fun with it!
#===============================================================================
################################################################################
#===============================================================================
# ** Module : RPG
#===============================================================================
module RPG
 #=============================================================================
 # * RPG::Registration
 #-----------------------------------------------------------------------------
 # On scene title, these values are automatically overwritten if the activation
 # code does not translate back to the digits in "serial" and "product".
 #=============================================================================
 class Registration
  #--------------------
  # * Initialize Method
  #--------------------
  def initialize
   # Registered Serial Number
   serial = [@serial_a, @serial_b, @serial_c, @serial_d, @serial_e]
   # Serial Digits
   @serial_a = 0
   @serial_b = 0
   @serial_c = 0
   @serial_d = 0
   @serial_e = 0
   # Registered Product Number
   product = [@product_a, @product_b, @product_c, @product_d, @product_e]
   # Product Digits
   @product_a = 0
   @product_b = 0
   @product_c = 0
   @product_d = 0
   @product_e = 0
   # Registered Activation Code
   activation = [@activ_a,@activ_b,@activ_c,@activ_d,@activ_e,
          @activ_f, @activ_g,@activ_h, @activ_i, @activ_j]
   # Activation Digits
   @activ_a = 0
   @avtiv_b = 0
   @activ_c = 0
   @activ_d = 0
   @activ_e = 0
   @activ_f = 0
   @activ_g = 0
   @activ_h = 0
   @activ_i = 0
   @activ_j = 0
  end
  # Registered Serial Number
  attr_accessor :serial
  # Serial Digits
  attr_accessor :serial_a
  attr_accessor :serial_b
  attr_accessor :serial_c
  attr_accessor :serial_d
  # Registered Product Number
  attr_accessor :product
  # Product Digits
  attr_accessor :product_a
  attr_accessor :product_b
  attr_accessor :product_c
  attr_accessor :product_d
  # Activation Code
  attr_accessor :activation
  # Activation Digits
  attr_accessor :activ_a
  attr_accessor :activ_b
  attr_accessor :activ_c
  attr_accessor :activ_d
  attr_accessor :activ_e
  attr_accessor :activ_f
  attr_accessor :activ_g
  attr_accessor :activ_h
 end
end
################################################################################
#===============================================================================
# ** Game_System
#-------------------------------------------------------------------------------
#Â This class is aliased to save serial and product number information.
#===============================================================================
class Game_System #<< RPG::Registration
 #[Attributes]-----------------------------------------------------------------
 attr_accessor :serial_number
 attr_accessor :product_number
 attr_accessor :activation_code
 #-----------------------------------------------------------------------------
 # * Alias Methods
 #-----------------------------------------------------------------------------
 alias_method :activation_game_scene_initialize, :initialize
 #--------------------
 # * Initialize Method
 #--------------------
 def initialize
  @serial_number = serial_number
  @product_number = product_number
  @activation_code = activation_code
  activation_game_scene_initialize
 end
 #----------------
 # * Serial Number
 #----------------
 def serial_number
  @s_valid = false
  if @serial_number != nil && @serial_number == $game_activate.serial
   @s_valid = true
   return @serial_number
  else
   @s_valid = false
   register_new_serial
  end
 end
 #-----------------
 # * Product Number
 #-----------------
 def product_number
  @p_valid = false
  if @product_number == $game_activate.product
   @p_valid = true
   return @product_number
  else
   @p_valid = false
   register_new_product
  end
 end
 #-----------------------------
 # * Register New Serial Number
 #-----------------------------
 def register_new_serial
  # Serial Number is sent to an instance variable
  @reg_serial = serial_number
  # Maximum digits in the serial number
  @digits_max = Activation_Digits_Max
  # If Serial Number doesn't exist...
  if @reg_serial == nil
   # Serial Number size is sent to an instance variable
   @digit = @reg_serial.size
   # For the information in Serial Number size...
   for i in @digit
    # A random key is sent to the serial digit
    @digit = random_key[i]
    # Add 1 to the serial number size determinate.
    @size += 1
    # Push the digit into the serial number
    serial_number.push(@digit)
    # Ends once the digits max
   end until size == @digits_max
  end
 end
 #----------------------------
 # * Register New Product Code
 #----------------------------
 def register_new_product
  @reg_product = $game_system.product_number
  if @reg_product == nil
   # The method...?
  end
 end
 #-----------------
 # * Activation Key
 #-----------------
 def activation_code
  @code = $game_activate.activation_code
  @serial = $game_activate.serial
  if @code == @serial
   @unlock_new_product = true
  else
   @unlock_new_product = false
  end
  return @unlock_new_product
 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(0, 0, 0, 0)
  @serial = $game_system.serial_number
  @product = $game_system.product_number
  @activation = []
  refresh
 end
 #-----------------
 # * Refresh Method
 #-----------------
 def refresh
  self.contents.clear
  # Draw Code Names
  self.contents.font = Default.font_type
  self.contents.font.color = system_color
  self.contents.draw_text(0, 0, 0, 0, "Serial :", 1)
  self.contents.draw_text(0, 64, 0, 0, "Product :", 1)
  self.contents.draw_text(0, 128, 0, 0, "Activation :", 1)
  # Draw Code Values
  self.contents.font = "Georgia"
  self.contents.font.color = Color.new(0, 0, 0, 255)
  self.contents.draw_text(0, 32, 0, 0, @reg_serial.to_s, 1)
  self.contents.draw_text(0, 96, 0, 0, @reg_product.to_s, 1)
  self.contents.draw_text(0, 160, 0, 0, @reg_activ.to_s, 1)
 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.
  @activ_window = Window_Activation.new
  @activ_window.visible = false
  @activ_window.active = false
  # Alias method
  activation_scene_title_main
 end
 #---------------------
 # * New Game (Aliased)
 #---------------------
 def command_new_game
  # Open Activation window if purchase registration not completed
  if $activation = true
   # Alias method
   activation_scene_title_new_game
  else
   # Goto: Enter Registration Method
   enter_registration
  end
 end
 #---------------------
 # * Continue (Aliased)
 #---------------------
 def command_continue
  if $activation = true
   # Alias method
   activation_scene_title_continue
  else
   # 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
  # If you haven't entered product key...?
  if $activation = false
   # 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
 #---------------
 # * Disable Save
 #---------------
 def save_enabled?
  if @flag_save_disabled == true
   $game_system.save_disabled = true
  else
   $game_system.save_disabled = false
  end
 end
end
################################################################################