• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

iGen

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
Preview: Hanky
Language: vJass
Requires: JassHelper (JassHelper 0.A.2.B)

Short Description:
This system is made to make the life easier for every map creator who needs save/load codes. In the map should be enough documentation how to use the system. If not ask questions per PM or visitor message.

Change Log said:
> 1.0 initial release
> 1.0a some bug fixes
> 1.0b added compressor
> 1.1 added documentation -> public release
> 1.1a added 2x protection and some more documentation
> 1.2 bug fix
improved compression
more possible options
improved name protection
improved crc function
functions are now easier
added some more documentation
> 1.2a bug fix
> 1.2b optimized compression
> 2.0 the whole script is rewritten and improved
> 2.0a added an option and changed some things that maybe could lead to an incorrect save/load code
> 2.0b just added the static if
> 2.0c improved the example for the system
> 2.1 fixed compression, save/load codes will be shorter from now on
> 2.1a fixed a bug found by acomc

JASS:
//				                          ,¦¦
//				                          ¦ ¦¦¦¦                                                                
//				                          ¦    ¦¦¦¦¦                          2010 still moving on...
//				                          ¦         ¦¦            ¦¦¦¦¦¦
//				                          ¦         ¦¦      ¦¦¦¦¦¦     ¦¦¦
//				                          ¦        ¦¦     ¦¦¦            ¦¦
//				                          ¦        ¦     ¦                ¦¦     ¦¦¦¦¦¦¦¦
//				                          ¦       ¦¦¦_   ¦                 ¦¦  ¦¦¦      ¯¦.
//				                          ¦       ¦  ¦¦¦¦¦        ____      ¦¦¦¦          ¯¦
//				                          ¦       ¦     ¦¦¦_     _¦¦¦¦______¦¦        __    ¦
//				                         ¦        ¦       ¦     _¦¦¦¦¦¦¦¦¦¦¦¦¦       _¦¦,   ¯¦
//				                         ¦    ,   ¦_      ¦     ¦¦¦¦¦¦¦¦¦¦¦¦¦       _¦¦¯     ¯¦
//				                         ¦    ¦    ¯     ¦¦     ¦¦¦¦¦¦¦¦¦¦¦¦¦       ¦¦¦¦_     ¦.
//				                        ,¦    ¦          ¦      ¦¦¦¦¦¯¯¯¯¯¦¦¦       ¦¦¦¦¦      ¦
//				                        ¦     ¦          ¦      ¯¦¦¦¦     ¯¦¦_      ¦¦¦¦¦      ¦
//				                       ¦¦     ¦_         ¦         ¯¦.     ¯¦¦      ¯¦¦¦¦      ¦
//				                       ¦       ¦         ¦                  ¦¦       ¯¯¯¯      ¦
//				                      ¦¦       ¦         ¦_        _        ¦¦¦                ¦
//				                     _¦        ¦          ¦        ¦        ¦¦¦¦              _¦
//                                   #----------------------------------------------------------#
//                                   |================!NgO is sappin' ma sentry!================|
//    				                 #----------------------------------------------------------#
//                       
//                                * NgO is fucking proud to present the release of the new iGen =) *
//
// ************************************************************************************************************************************
// *                                                       ~ Release ~                                                                *
// *                                                       +++++++++++                                                                *
// *                                                                                                                                  *
// *                                                   Name: iGen x2.1a                                                               *
// *                                                   Type: Code Generater                                                           *
// *                                               Language: vJass                                                                    *
// *                                                Made by: Hanky                                                                    *
// *                                                   Date: 10-04-2010                                                               *
// *                                                                                                                                  *
// *                                            Description: This system is there to make your life easier creating a MMORPG.         *
// *                                                         This system is able to create save/load codes. Also this system          *
// *                                                         is using an unique encryption method which is pretty secure.             *
// *                                                                                                                                  *
// *                                                         I can just say: Enjoy our release =)                                     *
// *                                                                                                                                  *
// ************************************************************************************************************************************
// 
// ************************************************************************************************************************************
// *                                                        ~ Notes ~                                                                 *
// *                                                        +++++++++                                                                 *
// *                                                                                                                                  *
// *                                                 If you want to contact me,                                                       *
// *                                                   then just contact me?                                                          *
// *                                                                                                                                  *
// ************************************************************************************************************************************

// ************************************************************************************************************************************
// *                                                  ~ Greetings fly out to ~                                                        *
// *                                                  ++++++++++++++++++++++++                                                        *
// *                                                                                                                                  *
// *                               Darkt3mpl3r, JonNny, WaRadius, xxdingoxx93, De.Facto, Toadcop, Paladon                             *
// *                                                Eccho, -BerzeKer-, Fireeye, Bodo                                                  *
// *                                                                                                                                  *
// *                                                         NgO & HIVE                                                               *
// *                                                                                                                                  *
// ************************************************************************************************************************************

// ************************************************************************************************************************************
// *                           One of the last releases NgO will release for Warcraft 3. But we'll never die.                         *
// *                                       So we will continue making mods for Starcraft 2.                                           *
// *                                                                                                                                  *
// *                          With this release I want advice you to take a look at our latest Project Chernobyl.                     *
// *                          It's a riddle map with much stuff you can explore. A playable version will be out                       *
// *                                                              soon.                                                               *
// *                                                                                                                                  *
// ************************************************************************************************************************************
// *_____________________________________________________nfo_design_by_Hanky__________________________________________________________*
// ************************************************************************************************************************************


library iGen
  globals
    public constant boolean keyEncryption =false        //Enable an extra keyEncryption (Important: The char library of every parameter will change to the key char library.)
    public constant integer mparameterSize=20           //This is the maximal size of parameters you can enter. You can change it to your needs.
    public constant integer delimiterInt  =5            //If you use delimiters you can set the interval here.
    public constant string delimiterSign  ="-"          //Remember that the delimiter sign should be never in a library. Otherwise it can't be recogenized correctly.
    
    public constant string colorcodeNum   ="|c000080FF" //For "0..1..2"
    public constant string colorcodeabc   ="|c00008000" //For "a..b..c"
    public constant string colorcodeABC   ="|c00FFFF00" //For "A..B..C"
    public constant string colorcodeXtr   ="|c00FF0000" //For everything else
    
    public constant string signLibrary1   ="0123456789" 		        //Set up the numeric characters
    public constant string signLibrary2   ="abcdefghijklmnopqrstuvwxyz" //Set up the normal characters
    public constant string signLibrary3   ="ABCDEFGHIJKLMNOPQRSTUVWXYZ" //Set up the capital characters
    public constant string signLibrary4   ="@$[_!?&%:}~*+=<>)(/-" 	    //Set up the extra signs/characters
  endglobals

  public struct parameterLibrary
     //==================================================
     //Vars

     //> Sign Library Vars
     string Library   //< Encryption/Decryption Library
     integer Size     //< The Size Of The Library
     integer maxHex   //< The Size Of The Last HexCode
     integer maxInt   //< The Size Of The Last Integer
     //*******************

     //> Parameter Value Vars
     string Encrypt   //< Encrypted         string
     integer Decrypt  //< Decrypted         integer
     integer Extent   //< Extent            integer
     integer Length   //< Length            integer
     integer CRC      //< Checksum          integer
     boolean Active   //< Active            boolean
     //*******************

     //==================================================
     //onStructEvent Methods
     static method create takes nothing returns thistype
       local thistype iCook=thistype.allocate()

       set iCook.Library=null
       set iCook.Size   =0x00
       
       set iCook.Encrypt=null
       set iCook.Decrypt=0x00
       set iCook.Extent =0x00
       set iCook.Length =0x00
       set iCook.CRC    =0x00
       set iCook.Active =false

       return iCook
     endmethod

     //==================================================
     //Convert Methods

     //> Int2Char
     //  > Convert an integer value to a char
     method Int2Char takes integer i returns string
       if i>=0x00 and i<=.Size then
         return SubString(.Library,i,i+0x01)
       debug else
       debug call BJDebugMsg("Error: Invalid parameter")
       endif
       return null
     endmethod

     //> Char2Int
     //  > Convert a char to an integer value
     method Char2Int takes string s returns integer
      local integer l=StringLength(s)
      local integer i=0x00
    
      if l==0x01 then
        loop
          exitwhen i==.Size
          
          if SubString(.Library,i,i+0x01)==s then
            return i
          endif
          
          set i=i+0x01
        endloop
      debug else
      debug call BJDebugMsg("ERROR: Just enter one char")
      endif
      
      debug call BJDebugMsg("ERROR: Invalid parameter")
      return -0x01
     endmethod

     //> Hex2Int
     //  > Convert the encrypt var to an integer value for the decrypt var
     method Hex2Int takes nothing returns nothing
       local integer l=StringLength(.Encrypt)
       local integer m=0x01
       local integer i=0x00
      
       if maxHex>=l then
         loop
           exitwhen 0x00==l
           set i=m*.Char2Int(SubString(.Encrypt,l-0x01,l))+i
           set m=m*.Size
           set l=l-0x01
         endloop
       debug else
       debug call BJDebugMsg("ERROR: Invalid parameter")
       endif
      
       set .Decrypt=i
     endmethod
     
     //> Hex2IntEx
     //  > Convert the encrypt var to an integer value for the decrypt var
     method Hex2IntEx takes string iEx returns integer
       local integer l=StringLength(iEx)
       local integer m=0x01
       local integer i=0x00
      
       if maxHex>=l then
         loop
           exitwhen 0x00==l
           set i=m*.Char2Int(SubString(iEx,l-0x01,l))+i
           set m=m*.Size
           set l=l-0x01
         endloop
       debug else
       debug call BJDebugMsg("ERROR: Invalid parameter")
       endif
      
       return i
     endmethod

     //> Int2Hex
     //  > Convert the decrypt var to a hex string for the encrypt var 
     method Int2Hex takes nothing returns nothing
       //! textmacro 2hex
       loop
         set q=i/.Size
         set s=.Int2Char(i-(q*.Size))+s
         set k=k-0x01
         set i=q
         exitwhen k==0x00
       endloop
       //! endtextmacro
       //========================================
       local integer i=.Decrypt
       local integer q=.Size
       local integer k=0x01
       local string s =null
      
       if 0x7FFFFFFF>=.Decrypt then
         loop
           exitwhen q>=.Decrypt
           set q=q*.Size
           set k=k+0x01
         endloop
         //! runtextmacro 2hex()
       elseif .maxInt>=i then
         //Debug Maximal Int Size
         set k=.maxHex
         //! runtextmacro 2hex()
       debug else
       debug call BJDebugMsg("ERROR: Invalid parameter")
       endif
      
       set .Encrypt=s
     endmethod
     
     //> Int2HexEx
     //  > Convert the decrypt var to a hex string for the encrypt var 
     method Int2HexEx takes integer iEx returns string
       local integer i=iEx
       local integer q=.Size
       local integer k=0x01
       local string s =null
      
       if 0x7FFFFFFF>=iEx then
         loop
           exitwhen q>=iEx
           set q=q*.Size
           set k=k+0x01
         endloop
         //! runtextmacro 2hex()
       elseif .maxInt>=i then
         //Debug Maximal Int Size
         set k=.maxHex
         //! runtextmacro 2hex()
       debug else
       debug call BJDebugMsg("ERROR: Invalid parameter")
       endif
      
       return s
     endmethod

     //==================================================
     //String Operators

     //> checkCharLibrary
     //  > Check if a char is in a library.
     static method IsCharInLibrary takes string ch,string lib returns boolean
       local integer l=StringLength(ch)
       local integer z=StringLength(lib)
      
       loop
         exitwhen z<l
         if ch==SubString(lib,z-l,z) then
           return true
         endif
         set z=z-0x01
       endloop
      
       return false
     endmethod
     
    //> Int2CharEx
     //  > Convert an integer value to a char
    method Int2CharEx takes integer i,string lib returns string
      if i>=0x00 and i<=.Size then
        return SubString(lib,i,i+0x01)
      debug else
      debug call BJDebugMsg("Error: Wrong char position")
      endif
      return null
    endmethod

     //> Char2IntEx
     //  > Convert an char to an integer value
    method Char2IntEx takes string s,string lib returns integer
      local integer l=StringLength(s)
      local integer i=0x00
    
      if l==1 then
        loop
          exitwhen i==.Size
          
          if SubString(lib,i,i+0x01)==s then
            return i
          endif
          
          set i=i+0x01
        endloop
      debug else
      debug call BJDebugMsg("ERROR: Just enter one char")
      endif
      
      debug call BJDebugMsg("ERROR: Invalid parameter")
      return -0x01
    endmethod

     //> setupCRC
     //  > Setup the CRC value. Remember to set before a decrypted value.
     method setupCRC takes nothing returns nothing
       local string s =I2S(.Decrypt)
       local integer l=StringLength(s)

       loop
         exitwhen l==0x00
         set .CRC=.CRC+.Char2Int(SubString(s,l-0x01,l))+R2I(Pow(0x02,l))
         set l=l-0x01
       endloop
     endmethod

     //> setupLength
     //  > Setup the length of a encrypted value. Remember to set before a decrypted value.
     method setupLength takes nothing returns nothing
       local integer i=.Extent
       local integer q=.Size
       local integer k=0x01
       local string s =null
      
       if 0x7FFFFFFF>=.Decrypt then
         loop
            exitwhen q>=.Extent
            set q=q*.Size
            set k=k+0x01
         endloop
         //! runtextmacro 2hex()
       elseif .maxInt>=i then
         //Debug Maximal Int Size
         set k=.maxHex
         //! runtextmacro 2hex()
       debug else
       debug call BJDebugMsg("ERROR: Invalid parameter")
       endif

       set .Length=StringLength(s)
     endmethod

     //> setupLibrary
     //  > This will setup the library which you'll need to decrypt/encrypt.
     method setupLibrary takes string s returns nothing
       local integer index=0x01
       local integer ltemp=0x00
       local integer temp =StringLength(s)-0x01

       set .Library=s
       set .Size   =temp

       loop
	     //0x7FFFFFFF == 2147483647
         exitwhen temp>0x7FFFFFFF or temp<ltemp

	     set ltemp=temp
	     set temp =temp*.Size
         set index=index+0x01
       endloop
	
       set .maxHex=index
       set .maxInt=ltemp
     endmethod
  endstruct

  public struct Generator
     parameterLibrary array parameter[mparameterSize]
     parameterLibrary key

     string codeString
     integer parameterSize

     integer inParameterCRC
     integer inKeyCRC
     integer outParameterCRC
     integer outKeyCRC

     //==================================================
     //onStructEvent Methods
     static method create takes nothing returns thistype
       local thistype iCook=thistype.allocate() 
       local integer i     =mparameterSize-0x01

       set iCook.codeString     =null
       set iCook.key            =parameterLibrary.create()
       set iCook.inParameterCRC =0x00
       set iCook.outParameterCRC=0x00
       set iCook.parameterSize  =0x00
       loop
         exitwhen i<0x00
         set iCook.parameter[i]=parameterLibrary.create()
         set i=i-0x01
       endloop

       return iCook
     endmethod

     method onDestory takes nothing returns nothing
       local integer i=mparameterSize-0x01

       call .key.destroy()
       loop
         exitwhen i<0x00
         call .parameter[i].destroy()
         set i=i-0x01
       endloop
     endmethod

     //==================================================
     //Standart Methods
     
     //> reset
     //  > This will reset your whole generator struct
     method reset takes nothing returns nothing
       local integer i=mparameterSize-0x01

       call .key.destroy()
       set .key=parameterLibrary.create()
       loop
         exitwhen i<0x00
         call .parameter[i].destroy()
         set .parameter[i]=parameterLibrary.create()
         set i=i-0x01
       endloop
     endmethod
     
     //> addDelemiters
     //  > Add some delimiters to your code (Hint: Just use this function after you have generated a codestring and before you added color to the string.)
     method addDelimiters takes nothing returns nothing
        local integer tl
        local integer ti
        local integer tp
        local string ts
     
        if .codeString!=null then
            set tl=StringLength(.codeString)
            set ti=0x00
            set tp=0x00
            set ts=null
            loop
                exitwhen ti==tl
                if tp==delimiterInt then
                    set ts=ts+delimiterSign
                    set tp=0x01
                else
                    set tp=tp+0x01
                endif
                set ts=ts+SubString(.codeString,ti,ti+0x01)
                set ti=ti+0x01
            endloop
            set .codeString=ts
        endif
     endmethod
     
     //> addDelemiters
     //  > Remove all delimiters from your code (Hint: Just use this function after you have generated a codestring and before you added some delimiters to the string.)
     method removeDelimiters takes nothing returns nothing
        local integer tl
        local integer ti
        local string tc
        local string ts
     
        if .codeString!=null then
            set tl=StringLength(.codeString)
            set ti=0x00
            set ts=null
            loop
                exitwhen ti==tl
                set tc=SubString(.codeString,ti,ti+0x01)
                if tc!=delimiterSign then
                    set ts=ts+tc
                endif
                set ti=ti+0x01
            endloop
            set .codeString=ts
        endif
     endmethod
    
     //> addColor
     //  > Add some color to your code (Hint: Just use this function after you have generated a codestring.)
     method addColor takes nothing returns nothing
        local integer m
        local string t
        local string d
      
        if .codeString!=null then
            set m=StringLength(.codeString)-0x01
            set t=null
            
            loop
              exitwhen m<0x00
        
              set d=SubString(.codeString,m,m+0x01)
              if .key.IsCharInLibrary(d,signLibrary1) then
                set d=colorcodeNum+d+"|r"
              elseif .key.IsCharInLibrary(d,signLibrary2) then
                set d=colorcodeabc+d+"|r"
              elseif .key.IsCharInLibrary(d,signLibrary3) then
                set d=colorcodeABC+d+"|r"
              elseif .key.IsCharInLibrary(d,signLibrary4) then
                set d=colorcodeXtr+d+"|r"
              endif
              set t=d+t
        
              set m=m-0x01
            endloop
       
            set .codeString=t
        endif
     endmethod

     //==================================================
     //Set Methods
     
     //> setParameter
     //  > Set the value of a parameter
     method setParameter takes integer i,integer max,string lib returns nothing
       if .parameterSize<mparameterSize then
         set .parameter[.parameterSize].Active =true
         set .parameter[.parameterSize].Decrypt=i
         set .parameter[.parameterSize].Extent =max
         call .parameter[.parameterSize].setupLibrary(lib)
         call .parameter[.parameterSize].setupLength()
         call .parameter[.parameterSize].setupCRC()
         set .parameterSize=.parameterSize+0x01
       debug else
       debug call BJDebugMsg("Error: Wrong size")
       endif
     endmethod
     
     //> setLoadParameter
     //  > Before you load a code you have to set the load parameter
     method setLoadParameter takes integer max,string lib returns nothing
        if .parameterSize<mparameterSize then
         set .parameter[.parameterSize].Active =true
         set .parameter[.parameterSize].Extent =max
         call .parameter[.parameterSize].setupLibrary(lib)
         call .parameter[.parameterSize].setupLength()
         set .parameterSize=.parameterSize+0x01
       debug else
       debug call BJDebugMsg("Error: Wrong size")
       endif
     endmethod

     //> setKey
     //  > Nearly for every function it's very important to have a key setted
     method setKey takes string s,string lib returns nothing
       local integer l=StringLength(s)
       local integer q=0x00
       local integer x

       call .key.setupLibrary(lib)

       loop
         exitwhen l==0
         set x=.key.Char2Int(SubString(s,l-0x01,l))
         if x!=-0x01 then
           set q=q+x
         endif
         set l=l-0x01
       endloop

       set .key.Decrypt=q
       call .key.setupCRC()
       set .outKeyCRC=.key.CRC
     endmethod
     
     //> setLoadCode
     //  > If you want to load a code you have to set the codeString first
     method setLoadCode takes string s returns nothing
        set .codeString=s
     endmethod

     //==================================================
     //Reset Methods
     
     //> resetLastParameter
     //  > If you want to reset you last setted parameter just use this function
     method resetLastParameter takes nothing returns nothing
       if .parameterSize>0x00 then
         set .parameter[.parameterSize].Encrypt=null
         set .parameter[.parameterSize].Library=null
         set .parameter[.parameterSize].Decrypt=0x00
         set .parameter[.parameterSize].Extent =0x00
         set .parameter[.parameterSize].CRC    =0x00
         set .parameterSize=.parameterSize-0x01
       debug else
       debug call BJDebugMsg("Error: Wrong Size")
       endif
     endmethod

     //==================================================
     //Get Methods
     
     //> getParameter
     //  > This function is there to get a decrypted parameter
     method getParameter takes integer pos returns integer
       return .parameter[pos].Decrypt
     endmethod
     
     //> getCode
     //  > After you have generated a code you can get with this function the code
     method getCode takes nothing returns string
        return .codeString
     endmethod

     //==================================================
     //Check Methods
     
     //> checkParameter
     //  > After you have decrypted a code you can check with this function if the checksum of the parameters is correct
     method checkParameter takes nothing returns boolean
       return .inParameterCRC==.outParameterCRC
     endmethod

     //> checkKey
     //  > After you have decrypted a code you can check with this function if the checksum of the key is correct
     method checkKey takes nothing returns boolean
       return .inKeyCRC==.outKeyCRC
     endmethod

     //==================================================
     //Generating Methods

     //> encrypt
     //  > After you have done all settings you can generate your own code
     method encrypt takes nothing returns nothing
        local integer index=.parameterSize-0x01
        local integer ti
        local integer te
        local integer tl
        local string pex
        local string tsg
        local string csg
        
        loop
            exitwhen index<0x00
            if .parameter[index].Active then
                set tsg=null
                call SetRandomSeed(index*.key.CRC)
                set .inParameterCRC=.inParameterCRC+(.parameter[index].CRC*(index+0x01))
                set .parameter[index].Decrypt=ModuloInteger(.parameter[index].Decrypt+GetRandomInt(index,R2I(Pow(index,.key.CRC))),.parameter[index].Extent)
                call .parameter[index].Int2Hex()
                set tl=StringLength(.parameter[index].Encrypt)
                if tl<.parameter[index].Length then
                    set tl =.parameter[index].Length-tl
                    set ti =0x00
                    loop
                        exitwhen ti==tl
                        call SetRandomSeed(R2I(Pow(ti,.key.CRC)))
                        set tsg=tsg+.parameter[index].Int2Char(ModuloInteger(GetRandomInt(0x00,.parameter[index].Size)-((ti+0x01)*index*(ti+0x01)),.parameter[index].Size))
                        set ti =ti+0x01
                    endloop
                else
                    set ti=0x00
                endif
                set csg=null
                set te =0x00
                loop
                    exitwhen ti==.parameter[index].Length
                    call SetRandomSeed(R2I(Pow(ti,.key.CRC)))
                    set csg=csg+.parameter[index].Int2Char(ModuloInteger(.parameter[index].Char2Int(SubString(.parameter[index].Encrypt,te,te+0x01))+GetRandomInt(0x00,.parameter[index].Size)-((ti+0x01)*index*(ti+0x01)),.parameter[index].Size))
                    set ti=ti+0x01
                    set te=te+0x01
                endloop
                set .parameter[index].Encrypt=tsg+csg
            endif
            set index=index-0x01
        endloop
        set pex  =.key.Int2HexEx(.inParameterCRC)
        set index=.parameterSize-0x01
        loop
            exitwhen index<0x00
            set .codeString=.parameter[index].Encrypt+.codeString
            set index=index-0x01
        endloop
        call .key.Int2Hex()
        
        set .codeString=.key.Encrypt+.codeString+pex
        static if keyEncryption then
            set index=StringLength(.codeString)
            set csg  =null
            loop
                exitwhen index==0x00
                call SetRandomSeed(.key.CRC*(index+0x01))
                set csg=.key.Int2Char(ModuloInteger(.key.Char2Int(SubString(.codeString,index-0x01,index))-GetRandomInt(0x00,.key.Size),.key.Size))+csg
                set index=index-0x01
            endloop
            set .codeString=csg
        endif
     endmethod

     //> decrypt
     //  > After you have done all settings you can decrypt an entered code
     method decrypt takes nothing returns nothing
        local parameterLibrary tk=parameterLibrary.create()
        local boolean filter
        local integer index
        local integer pos
        local integer te
        local integer tl
        local integer ti
        local string ts
        local string bs
        
        static if keyEncryption then
            set index=StringLength(.codeString)
            set ts   =null
            loop
                exitwhen index==0x00
                call SetRandomSeed(.key.CRC*(index+0x01))
                set ts=.key.Int2Char(ModuloInteger(.key.Char2Int(SubString(.codeString,index-0x01,index))+GetRandomInt(0x00,.key.Size),.key.Size))+ts
                set index=index-0x01
            endloop
            set .codeString=ts
        endif
        
        call .key.Int2Hex()
        call tk.setupLibrary(.key.Library)
        set tl=StringLength(.key.Encrypt)
        set tk.Encrypt=SubString(.codeString,0x00,tl)
        call tk.Hex2Int()
        call tk.setupCRC()
        set .inKeyCRC=tk.CRC
        set ts=SubString(.codeString,tl,StringLength(.codeString))
        
        if .checkKey() then
            set index=0x00
            set pos  =0x00
            loop
                exitwhen index==.parameterSize
                if .parameter[index].Active then
                    set .parameter[index].Encrypt=SubString(ts,pos,pos+.parameter[index].Length)
                    set filter=false
                    set bs=null
                    set ti=0x00
                    set te=StringLength(.parameter[index].Encrypt)
                    loop
                        exitwhen ti==te
                        call SetRandomSeed(R2I(Pow(ti,tk.CRC)))
                        set tl=ModuloInteger(.parameter[index].Char2Int(SubString(.parameter[index].Encrypt,ti,ti+0x01))-GetRandomInt(0x00,.parameter[index].Size)+((ti+0x01)*index*(ti+0x01)),.parameter[index].Size)
                        if filter or tl!=0x00 then
                            set bs    =bs+.parameter[index].Int2Char(tl)
                            set filter=true
                        endif
                        set ti=ti+0x01
                    endloop
                    if bs==null then
                        set bs=.parameter[index].Int2Char(0x00)
                    endif
                    set .parameter[index].Encrypt=bs
                    call .parameter[index].Hex2Int()
                    call SetRandomSeed(index*.key.CRC)
                    set .parameter[index].Decrypt=ModuloInteger(.parameter[index].Decrypt-GetRandomInt(index,R2I(Pow(index,.key.CRC))),.parameter[index].Extent)
                    call .parameter[index].setupCRC()
                    set .inParameterCRC=.inParameterCRC+(.parameter[index].CRC*(index+0x01))                
                    set pos=pos+.parameter[index].Length
                endif
                set index=index+0x01
            endloop
            set .outParameterCRC=tk.Hex2IntEx(SubString(ts,pos,StringLength(ts)))
        endif
        
    
        call tk.destroy()
     endmethod
  endstruct
endlibrary

And as always greeting my clan NgO and some certain people:
- Darkt3mpl3r (pure win)
- JonNny
- Paladon
- Eccho
- Toadcop
- Berzeker
- WaRadius (miss ya mate)
- xxdingo93xx

Any improvement ideas will be helpful.

Keywords:
codegen, thecakeisaspy, savenload, save, load, code, ngo, hanky, darkt3mpl3r, igen
Contents

iGen x2.1 (Map)

Reviews
8 Sep 2011 Bribe: Deprecated in favor of: http://www.hiveworkshop.com/forums/spells-569/save-load-snippets-v1-0-0-7-a-202714/ 20:54, 22nd Aug 2009 hvo-busterkomo: The coding looks good and could definitely be useful. Approved.
Level 14
Joined
Jan 15, 2007
Messages
349
Yes it took some time. But Im happy that I had the time to finally release it.

Hm, yeah. I didn't wanted that my codegen got the same name like the codegen from TriggerHappy. So I named it iGen, I also think the name is kinda funny. ;)
 
Level 14
Joined
Jan 15, 2007
Messages
349
@baasee
For sure soon i'll release iJass xD

@Etzer
If you mean by "CodeGen" the system TriggerHappy coded then I have to say that both systems are different. Im pretty sure that I use an other compression method than TriggerHappy etc.

Well I don't want to say "my sistem is teh 1337 shit!!!11". I think TriggerHappys system got some pros and my system got also some pros.

Just read the documentation (There's also a part which list all features.) and work abit with the system and Im sure you'll find your favorite yourself.
 
Level 1
Joined
Dec 20, 2009
Messages
5
well done, it saved me a lot of time

simple and useful examples, easy to be understood with explanations, as well as the flexibility for adjustments to my own settings

5/5 no doubt
 
Level 14
Joined
Jan 15, 2007
Messages
349
Thank you =)

New version is up. Enjoy.

Edit: New version is up. I fixed a bug which made is impossible for users to save some stuff. But now everything should be alright. Thanks to acomc for reporting me this bug.
 
Last edited:
Level 1
Joined
Jun 24, 2010
Messages
1
i got a problem: when i edit your code to save more items/otheritems, even if i add only 1 item, the normal editor crashed and the genpack found errors and stuck... i dont know what to do :/ any1 has a idea, how i can fix my problem?
 
Level 2
Joined
Jan 17, 2010
Messages
8
If you really got the latest JassHelper version which is 0.A.2.B then everything should work alright. At least it does for me. (You can get the latest Version here: http://www.wc3c.net/showthread.php?t=88142)

If it still won't work for you just remove the static prefix in that line.

Thanks I messed up. so i had to reinstall newgen then reinstall the latest jasshelper...

Edit: Can I use the SNL you made? For some reason when i type -save nothing happens
And I don't know Jass.
 
Last edited:
Level 14
Joined
Jan 15, 2007
Messages
349
@lmfaocj

Sure you can use the example script. SNL is a perfect help for guys who just know GUI.

@IronForge

Nope the JassHelper have to be updated manually.

Sure the iGen is able to save as many integers as you want. That means you just need to save in one parameter the id or array index of the unit. Look at the examples I made. Make a array with unittypes. There you add all your heroes you want. (Dont forget to have one empty herotype. It would be the best if "0" is the empty one.) After you have done that you need to add a loop to the save/load trigger which search the index number of the unittype. The index number can be easily saved in one of the parameters of the iGen.

Remember that you are able to increase the maximal parameter size of the iGen. (Remember that you have to set the maximal parameter size also in the constants of the system)

I hope that are enough information for you how to use this system. Remember that everything can be converted to an integer. And the iGen takes integer and compress/convert/encrypt them to a string.
 
Level 14
Joined
Jan 15, 2007
Messages
349
Depends if you just want to use this GUI interface or the real system. But since I guess you are using GUI you'll need this triggers:
iGen x2 (This is the main system code.)
SNL TestScript (This is for people who don't know GUI. It's made very simple how you can see.)
and the triggers which you have to modificate:
InitTypes (This trigger is there to set up those array.)
Save GUI (This trigger is there to save stuff. But this trigger will need the SNL Testscript trigger.)
Load GUI (This trigger is there to load stuff. But this trigger will need the SNL Testscript trigger.)

Normaly you just need to read the documentation and look at those examples. That's why I added them. I got no time to make a general tutorial how to save that and this. Since how I already said everything (like a/an unit/hero, ability etc.) can be converted to an integer.
 
Level 1
Joined
Jul 28, 2010
Messages
2
this save/load works all right in your map but when i go to test in my map it has like 1660 errors and thers like 10 for each line and wen i try to fix even more pop up any suggestions? or any thread on how to import/fix this problem

thx

tonton302 :D
 
Level 11
Joined
Sep 12, 2008
Messages
657
Thads odd.. i save the system, in jass new gen pack..
and i get syntax error at line 723,

"static if iGen_keyEncryption then"

didnt really look at it further, i redownloaded the system, did everything.. but sill, couldnt understend why.. any help?(really need this for my orpg.. tried to learn to do save/load system my self.. failed, with this, its really easy.. and i really need it.
Thanks in advance.
 
Level 14
Joined
Jan 15, 2007
Messages
349
Well how you maybe already read in this thread you need the last version of the JassHelper which is 0.A.2.B.

If it still won't work just remove the static prefix. So that there's "if iGen_keyEncryption then" instead of "static if iGen_keyEncryption then".
 
Level 2
Joined
Jan 17, 2010
Messages
8
I know I am being annoying but, when I type -save it gives me a code but the code doesn't work. Is it because I maybe messed up on the parameter or something? I changed most of the variables to ones that I already used it has nothing to do with that right?
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Yea, this kinda fails..

Tested this code
JASS:
struct tester extends array
    private static method onInit takes nothing returns nothing
        local iGen_Generator gen = iGen_Generator.create()
        local integer index      = 0
        local string lib = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        call gen.setParameter(1,1000001,lib)
        call gen.setParameter(1000,1001,lib)
        call gen.setParameter(100,101,lib)
        call gen.setParameter(300,301,lib)
        call gen.setParameter(1,2,lib)
        call gen.setParameter(0,2,lib)
        call gen.setParameter(7,17,lib)
        call gen.setParameter(10,11,lib)
        call gen.setKey("",lib)
        call gen.encrypt()
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, gen.getCode())
        call gen.destroy()
    endmethod
endstruct

The length of the code was 17 characters... that's just plain huge.. I encoded the exact same thing w/o encryption in 7. With encryption, I'd be adding a max of 4-5 chars (checksum*player hash sum, encoder id, +1 bit with salting), so that's 11-12 compared to 17 ;|.

This was the code with the above stuff
0QX6HPTOQNNNLRQ99

This was after I changed
call gen.setParameter(7,17,lib) -> call gen.setParameter(5,17,lib)
0QX6HPTOQNNNLPQ8U


If you can't encode all of the above data in 7 chars w/o security and read it back, then your code is already too big.
 
Last edited:
Level 14
Joined
Jan 15, 2007
Messages
349
Well it seems you dont get the system code. First of all if you set the range to "1000001" then the code will automaticly use the maximal size. That means "1000001" got 7 characters. 7/2 (if you use the right char library) = 3.5 -> 4 (something like this). And the code won't care if the value is just 1. Sure in some cases this is stupid... that is why I was working on a new version where this whole "set your max value" stuff isnt there anymore .

But by the way the char library you used in your example is kinda small... so don't expect a good compression at all.
 
Last edited:
Level 31
Joined
Jul 10, 2007
Messages
6,306
Ahem, I encoded the exact same thing in 7 chars with that exact same key.

I don't think you get that this system is pretty bad ;P. It's not about the key, it's just that the thing is plain bad and the encryption is failure. You do know that using placeholders is really dumb compared to just compacting the integers into one int If you compact, you maximize space, thus getting to that magical 7 char value. Until you can get to 7 chars w/o any security, your system will continue to be bad >.>. I can do encryption and get radical changes with 1 value at the cost of 0 bits btw.

My suggestion is to update this to use http://www.hiveworkshop.com/forums/jass-functions-413/system-bigint-188973/ as it'll cut the size of your save/load codes in half =). Not only that, it'll simplify your system and make things easier on yourself.

I disabled as much of the security in your system as I could, but your function was hard to read : (.

Notice that Pipedream's save/load system at wc3c does the stuff properly. It gets exact same output as the BigInt lib does =).

JASS:
//Is your save/load system any good? Is a save/load system on a forum any good?
//Save the following data with 0 security enabled and check the code length
//The data can be encoded with 7 characters with 0 security.
//iGen does it in 17 w/ security (prob 15-16 w/o)
//CodeGen does it in 16 w/o security
//PipeDream's Optimal Save System does it in 7 chars w/ 0 security, exact same output as BigInt

//Ensure that the key is 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
struct tester extends array
    private static method onInit takes nothing returns nothing
        local Base encryptKey = Base["0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
        local BigInt int = BigInt.create(encryptKey)
        local string s
        
        //1 out of 1000000 (1000000+1)
        //if it takes a parameter with a size, be sure to type in 1000000 or 1000000+1
        call int.add(1,0) //encode 1 (max doesn't matter as this,
                                    //is first, so put biggest value here)

        call int.multiply(1000+1)
        call int.add(1000,0) //encode 1000

        call int.multiply(100+1)
        call int.add(100,0) //encode 100
        
        call int.multiply(300+1)
        call int.add(300,0) //encode 300

        call int.multiply(1+1)
        call int.add(1,0) //encode 1

        call int.multiply(1+1)
        call int.add(0,0) //encode 0

        call int.multiply(16+1)
        call int.add(7,0) //encode 7

        call int.multiply(10+1)
        call int.add(10,0) //encode 10
        
        set s = int.toString()
        call int.destroy()

        //display the code ^_^
        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 60, s)
    endmethod
endstruct

Also here's a tutorial on salting and hashing-> http://www.hiveworkshop.com/forums/tutorial-submission-283/advanced-data-encryption-189120/

That'll give you much better encryption at a lower cost (if you are actually doing any encryption).
 
Last edited:
Level 14
Joined
Jan 15, 2007
Messages
349
Yea how I said the method Im using isn't the best one. But I got no free time to update the script... maybe in some weeks or months..

And to your last sentence. Sure it do encrypt/decrypt stuff... what else should it do?

Maybe I'll write a bigger reply to your post later... got no time now.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
So what should be done with this and the other save/load systems now...

people are still using them... it's easier to just get rid of them rather than to tell people not to use them at every turn.

Only 2 save/load systems are needed now, Encoder and an Encoder plain JASS version (no vjass), but I will prob never code #2 ;p. The rest should just be gotten rid of.
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
My argument is: why should something be approved that should never ever be used? : p

No, other save/load systems should be gotten rid of because they will just mislead people. You forget that beginners can't tell the difference between save/load systems, and optimal this and optimal that will just make them look for the easiest system possible rather than the best (because they think they're all around the same).

Approved is approved is a bad thing to uphold... if something is approved and something else comes along that's better, the first one should be graveyarded so that people don't accidentally use it. Why on earth would you want to lay traps on the site? It just makes it harder for map makers to find the good systems out of the thousands of bad systems and it makes it impossible for beginners to use anything that's any good.

I can see different systems that do the same things with pros and cons, but different systems that do the same thing where one is just plainly superior to another is just bad. I am speaking from experience here... back when I was a beginner, I ended up using AceHart's over Pipedream's because I couldn't tell the difference between them. This should have been graveyarded the day that Pipedream's came out (if it came out before his).

You shouldn't be proud of a system that nobody should ever use, rather you should be pushing this to be graveyarded as well. I know that I would push a system that I wrote to be graveyarded if another one came out that was better.

I honestly don't care what you think, i don't care who you are, I don't care about the rules, and I don't care about the mod's opinions. I care about the map makers who are looking through dozens of systems that all do around the same thing (only the vets end up knowing which ones are the best). Look at all of the save/load threads in World Editor Help Zone. People are still using iGen (some just starting in the last few days). They shouldn't be using this system, it is that simple >.<.

I don't play maps that use save/load systems other than Encoder now. I'm tired of typing in 50 char codes when they could just as easily be 25 characters. I find it stupid how stubborn so many people are being about this. I'm trying to put a stop to the 50 char codes, and you should be trying to put a stop to them as well. Supporting iGen is supporting 50 char codes over 25 char codes. I don't care about map makers complaining how hard a system is to use either, I primarily care about code length. It's the players that have to type in those codes.

Regardless, an approved system, if inferior to new ones, should be graveyarded as soon as possible so that people don't end up using it.

And you aren't a mod so yeah what did you say xD

Who cares, you should see all the fights I get into with mods all the time.

I fight for giving 0 credit for resources used in maps.
I fight for getting rid of systems for newer systems, not just keeping things approved because they were good enough to be approved in the first place.

One of the things I warned people about is that I would be fighting for every single resource having to do with save/load on every site to be graveyarded and replaced with Encoder when v2 of it was finished, and I am keeping my word.

= )
 
Level 15
Joined
Mar 31, 2009
Messages
1,397
I fight for giving 0 credit for resources used in maps.

No.

I fight for getting rid of systems for newer systems, not just keeping things approved because they were good enough to be approved in the first place.

Yes, but lazy.

One of the things I warned people about is that I would be fighting for every single resource having to do with save/load on every site to be graveyarded and replaced with Encoder when v2 of it was finished, and I am keeping my word

No. Instead the makers should be persuaded to switch.
 
Top