need a very good jass'er to shed some info on how a system works :)

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Okay, this system is consists of 2 parts. Encoding and Decoding. It has it's working method and you also can create it by using your mathematical method! :D He used his mathematical method to calculate the code = Encode. Enter the code and the game load = Decode.
 

sithin

New Member
Reaction score
5
yeah i know all that, i even made a save/load system my self i just need to know how the mathimatical formula works.... any1 please help :)
 

Romek

Super Moderator
Reaction score
963
I merged your first 3 posts, Sithin, and deleted some other posts.
Simply because going through 6 posts to actually find out what you need isn't pleasant.

In the future, try to pup more detail than just "help me" in your first post. It'll let us helpers avoid having to ask what system, why you need help, etc. :)
 

sithin

New Member
Reaction score
5
ok here it is if any1 could shed some light, iv studied it and try hard but yeah
+rep till my eyes fall out if any1 could help

edit: oh and btw i need.. would like insite because my current save/load system i made is way to long, and want to add some form of compression
JASS:
function SaveLoad_InitialSetup takes nothing returns nothing
    local integer i = 0
    local integer j = 0

    loop
        set udg_SaveLoad_Compress[i + 48] = j
        set udg_SaveLoad_Uncompress<i> = i + 48
        set j = j + 1
        set i = i + 1
        exitwhen i &gt;= 10
    endloop
    set i = 0
    loop
        set udg_SaveLoad_Compress[i + 97] = j
        set udg_SaveLoad_Compress[i + 65] = j + 26
        set udg_SaveLoad_Uncompress[i + 10] = i + 97
        set udg_SaveLoad_Uncompress[i + 26 + 10] = i + 65
        set j = j + 1
        set i = i + 1
        exitwhen i &gt;= 26
    endloop
endfunction

function SaveLoad_Id2CId takes integer n returns integer
    local integer i = n / (256 * 256 * 256)
    local integer r
    set n = n - i * (256 * 256 * 256)
    set r = udg_SaveLoad_Compress<i>
    set i = n / (256 * 256)
    set n = n - i * (256 * 256)
    set r = r * 64 + udg_SaveLoad_Compress<i>
    set i = n / 256
    set r = r * 64 + udg_SaveLoad_Compress<i>
    return r * 64 + udg_SaveLoad_Compress[n - i * 256]
endfunction

function SaveLoad_CId2Id takes integer n returns integer
    local integer i = n / (64 * 64 * 64)
    local integer r
    set n = n - i * (64 * 64 * 64)
    set r = udg_SaveLoad_Uncompress<i>
    set i = n / (64 * 64)
    set n = n - i * (64 * 64)
    set r = r * 256 + udg_SaveLoad_Uncompress<i>
    set i = n / 64
    set r = r * 256 + udg_SaveLoad_Uncompress<i>
    return r * 256 + udg_SaveLoad_Uncompress[n - i * 64]
endfunction

function SaveLoad_Unit2Integer takes unit u returns integer
    local integer i = 0
    local integer n = GetUnitTypeId(u)
    if udg_SaveLoad_Initialized == false then
        set udg_SaveLoad_Initialized = true
        call SaveLoad_InitialSetup()
    endif
    loop
        set i = i + 1
        exitwhen i &gt; udg_SaveLoad_Heroes_LastIndex
        if udg_SaveLoad_Heroes<i> == n then
            return i
        endif
    endloop
    return SaveLoad_Id2CId(n)
endfunction
function SaveLoad_Integer2Unit takes integer i returns integer
    if udg_SaveLoad_Initialized == false then
        set udg_SaveLoad_Initialized = true
        call SaveLoad_InitialSetup()
    endif
    if i &lt;= udg_SaveLoad_Heroes_LastIndex then
        return udg_SaveLoad_Heroes<i>
    endif
    return SaveLoad_CId2Id(i)
endfunction

function SaveLoad_Item2Integer takes item t returns integer
    local integer i = 0
    local integer n = GetItemTypeId(t)
    if udg_SaveLoad_Initialized == false then
        set udg_SaveLoad_Initialized = true
        call SaveLoad_InitialSetup()
    endif
    loop
        set i = i + 1
        exitwhen i &gt; udg_SaveLoad_Items_LastIndex
        if udg_SaveLoad_Items<i> == n then
            return i
        endif
    endloop
    return SaveLoad_Id2CId(n)
endfunction
function SaveLoad_Integer2Item takes integer i returns integer
    if udg_SaveLoad_Initialized == false then
        set udg_SaveLoad_Initialized = true
        call SaveLoad_InitialSetup()
    endif
    if i &lt;= udg_SaveLoad_Items_LastIndex then
        return udg_SaveLoad_Items<i>
    endif
    return SaveLoad_CId2Id(i)
endfunction

function SaveLoad_Ability2Integer takes integer a returns integer
    local integer i = 0
    if udg_SaveLoad_Initialized == false then
        set udg_SaveLoad_Initialized = true
        call SaveLoad_InitialSetup()
    endif
    loop
        set i = i + 1
        exitwhen i &gt; udg_SaveLoad_Abilities_LastIndex
        if udg_SaveLoad_Abilities<i> == a then
            return i
        endif
    endloop
    return SaveLoad_Id2CId(a)
endfunction
function SaveLoad_Integer2Ability takes integer i returns integer
    if udg_SaveLoad_Initialized == false then
        set udg_SaveLoad_Initialized = true
        call SaveLoad_InitialSetup()
    endif
    if i &lt;= udg_SaveLoad_Abilities_LastIndex then
        return udg_SaveLoad_Abilities<i>
    endif
    return SaveLoad_CId2Id(i)
endfunction

function SaveLoad_Color takes string s returns string
    local integer i = StringLength(s)
    local string c
    local string r = &quot;&quot;

    loop
        set i = i - 1
        set c = SubString(s,i,i + 1)
        if c == &quot;0&quot; or c == &quot;1&quot; or c == &quot;2&quot; or c == &quot;3&quot; or c == &quot;4&quot; or c == &quot;5&quot; or c == &quot;6&quot; or c == &quot;7&quot; or c == &quot;8&quot; or c == &quot;9&quot; then
            set r = &quot;|cffffcc00&quot; + c + &quot;|r&quot; + r
        elseif c == &quot;-&quot; then
            set r = &quot;|cffdddddd-|r&quot; + r
        else
            set r = c + r
        endif
        exitwhen i &lt;= 0
    endloop
    return r
endfunction

function SaveLoad_EncodeChar takes string n returns integer
    local integer i = 0
    local string s1 = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;
    local string s2 = &quot;abcdefghijklmnopqrstuvwxyz&quot;
    local string s3 = &quot;0123456789&quot;

    loop
        if SubString(s1,i,i + 1) == n then
            return i
        endif
        if SubString(s2,i,i + 1) == n then
            return i
        endif
        set i = i + 1
        exitwhen i &gt;= 26
    endloop
    set i = 0
    loop
        if SubString(s3,i,i + 1) == n then
            return i
        endif
        set i = i + 1
        exitwhen i &gt;= 10
    endloop
    return 0
endfunction

function SaveLoad_EncodeVerify takes string buffer returns integer
    local integer i = 0
    local integer j = 0
    local string name = GetPlayerName(GetTriggerPlayer())
    if udg_SaveLoad_UsePlayername == true then
        loop
            set j = j + SaveLoad_EncodeChar(SubString(name,i,i + 1))
            set i = i + 1
            exitwhen i &gt;= StringLength(name)
        endloop
    endif
    set i = 0
    loop
        set j = j + SaveLoad_EncodeChar(SubString(buffer,i,i + 1))
        set i = i + 1
        exitwhen i &gt;= StringLength(buffer)
    endloop
    return j
endfunction

function SaveLoad_EncodeValues takes nothing returns string
    local integer i
    local integer j
    local integer k
    local integer l
    local integer m
    local integer CodeLength = StringLength(udg_SaveLoad_Alphabet)
    local integer array a
    local string buffer = &quot;&quot;
    local string c = &quot;&quot;
    local integer skip = 0
    local integer CONST = 1000000
    local string abc = &quot;0123456789&quot;

    set i = 0
    loop
        set i = i + 1
        exitwhen i &gt; udg_SaveCount
        set buffer = buffer + I2S(udg_Save<i>) + &quot;-&quot;
    endloop
    set buffer = buffer + I2S(SaveLoad_EncodeVerify(buffer))
    if udg_Save[1] == 0 then
        set buffer = &quot;-&quot; + buffer
    endif

    set i = 0
    loop
        set a<i> = 0
        set i = i + 1
        exitwhen i &gt;= 100
    endloop

    set m = 0
    set i = 0
    loop
        set j = 0
        loop
            set a[j] = a[j] * 11
            set j = j + 1
            exitwhen j &gt; m
        endloop

        set l = 0
        set c = SubString(buffer,i,i + 1)
        loop
            exitwhen SubString(abc,l,l + 1) == c
            set l = l + 1
            exitwhen l &gt; 9
        endloop
        set a[0] = a[0] + l

        set j = 0
        loop
            set k = a[j] / CONST
            set a[j] = a[j] - k * CONST
            set a[j + 1] = a[j + 1] + k
            set j = j + 1
            exitwhen j &gt; m
        endloop
        if k &gt; 0 then
            set m = m + 1
        endif
        set i = i + 1
        exitwhen i &gt;= StringLength(buffer)
    endloop

    set buffer = &quot;&quot;
    loop
        exitwhen m &lt; 0
        set j = m
        loop
            exitwhen j &lt;= 0
            set k = a[j] / CodeLength
            set a[j - 1] = a[j - 1] + (a[j] - k * CodeLength) * CONST
            set a[j] = k
            set j = j - 1
        endloop
        set k = a[j] / CodeLength
        set i = a[j] - k * CodeLength
        set buffer = buffer + SubString(udg_SaveLoad_Alphabet,i,i + 1)
        set a[j] = k
        if a[m] == 0 then
            set m = m - 1
        endif
    endloop

    set i = StringLength(buffer)
    set skip = 0
    set c = &quot;&quot;
    loop
        set i = i - 1
        set c = c + SubString(buffer,i,i + 1)
        set skip = skip + 1
        if skip == 4 and i &gt; 0 then
            set c = c + &quot;-&quot;
            set skip = 0
        endif
        exitwhen i &lt;= 0
    endloop
    return c
endfunction

function SaveLoad_DecodeValues takes string s returns boolean
    local integer i
    local integer j
    local integer k
    local integer l
    local integer SaveCode = 0
    local integer m
    local integer array a
    local string buffer = &quot;&quot;
    local integer CodeLength = StringLength(udg_SaveLoad_Alphabet)
    local integer skip = -1
    local integer CONST = 1000000
    local string abc = &quot;0123456789-&quot;
    local string c

    set i = 0
    loop
        set a<i> = 0
        set i = i + 1
        exitwhen i &gt;= 100
    endloop

    set m = 0

    set i = 0
    loop
        set j = 0
        loop
            set a[j] = a[j] * CodeLength
            set j = j + 1
            exitwhen j &gt; m
        endloop

        set skip = skip + 1
        if skip == 4 then
            set skip = 0
            set i = i + 1
        endif

        set l = CodeLength
        set c = SubString(s,i,i + 1)
        loop
            set l = l - 1
            exitwhen l &lt; 1
            exitwhen SubString(udg_SaveLoad_Alphabet,l,l + 1) == c
        endloop
        set a[0] = a[0] + l

        set j = 0
        loop
            set k = a[j] / CONST
            set a[j] = a[j] - k * CONST
            set a[j + 1] = a[j + 1] + k
            set j = j + 1
            exitwhen j &gt; m
        endloop
        if k &gt; 0 then
            set m = m + 1
        endif
        set i = i + 1
        exitwhen i &gt;= StringLength(s)
    endloop

    loop
        exitwhen m &lt; 0
        set j = m
        loop
            exitwhen j &lt;= 0
            set k = a[j] / 11
            set a[j - 1] = a[j - 1] + (a[j] - k * 11) * CONST
            set a[j] = k
            set j = j - 1
        endloop
        set k = a[j] / 11
        set i = a[j] - k * 11
        set buffer = SubString(abc,i,i + 1) + buffer
        set a[j] = k
        if a[m] == 0 then
            set m = m - 1
        endif
    endloop

    set i = 0
    set j = 0
    loop
        loop
            exitwhen i &gt;= StringLength(buffer)
            exitwhen i &gt; 0 and SubString(buffer,i,i + 1) == &quot;-&quot; and SubString(buffer,i - 1,i) != &quot;-&quot;
            set i = i + 1
        endloop
        if i &lt; StringLength(buffer) then
            set k = i
        endif
        set SaveCode = SaveCode + 1
        set udg_Save[SaveCode] = S2I(SubString(buffer,j,i))
        set j = i + 1
        set i = i + 1
        exitwhen i &gt;= StringLength(buffer)
    endloop

    set j = SaveLoad_EncodeVerify(SubString(buffer,0,k))
    set udg_SaveCount = SaveCode - 1
    if j == udg_Save[SaveCode] then
        return true
    endif
    return false
endfunction

function SaveLoad_Encode takes nothing returns string
    if udg_SaveLoad_CaseSensitive == false then
        set udg_SaveLoad_Alphabet = StringCase(udg_SaveLoad_Alphabet,true)
    endif
    return SaveLoad_Color(SaveLoad_EncodeValues())
endfunction

function SaveLoad_Decode takes string s returns boolean
    if udg_SaveLoad_CaseSensitive == false then
        set udg_SaveLoad_Alphabet = StringCase(udg_SaveLoad_Alphabet,true)
        set s = StringCase(s,true)
    endif
    if SaveLoad_DecodeValues(s) then
        call DisplayTextToPlayer(GetTriggerPlayer(),0,0,&quot;Decoding sucessful&quot;)
        return true
    endif
    call DisplayTextToPlayer(GetTriggerPlayer(),0,0,&quot;Decoding failed&quot;)
    return false
endfunction
</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
 

No_exit

Regular User (What is Custom User Title?)
Reaction score
40
How Aceharts save/load system works is:

You have a bunch of numbers you want to save for example in an RPG:

Herotype: 2 (which is the ID for archer for example)
Herolevel: 9
Gold: 73
Wood: 5201

Now what he does is the following, he puts all the numbers behind eachother and puts a "minus sign" or "-" between them so you have:

2-9-73-5201 (this is the string he has in the variable buffer at one time)

He now basically converts every character into a number from 0 to 10.
1st character is 2 and is converted to 2
2nd character is - and is converted to 10
3rd character is 9 and is converted to 9
4th character is - and is converted to 10
5th character is 7 and is converted to 7
6th character is 3 and is converted to 3
7th character is - and is converted to 10
8th character is 5 and is converted to 5
9th character is 2 and is converted to 2
10th character is 0 and is converted to 0
11th character is 1 and is converted to 1

So you end up with
2 10 9 10 7 3 10 5 2 0 1 (This conversion is done character by character and once you have one character converted, it immediatly processes this converted number in the next step. So you never really see this sequence of numbers stored anywhere. I added this to hopefully make you better understand the maths behind it.)

Now that you have a bunch of numbers between 0 and 10 you put them all behind eachother again and act as if it is a big number in base 11 and convert it to a number in base 10 (Binary is a number in base 2 if that helps you know/remember what this "base" thing is).

To convert this number in base 11 to a number is base 10 you just do the following:
Start at the back and multiply the last number by 11^0, multiply the next number by 11^1, the next number by 11^2, ... and then sum these numbers all up and you got this:

2 * 11^10
+ 10 * 11^9
+ 9 * 11^8
+ 10 * 11^7
+ 7 * 11^6
+ 3 * 11^5
+ 10 * 11^4
+ 5 * 11^3
+ 2 * 11^2
+ 0 * 11^1
+ 1 * 11^0

Now you have a unique number
77591465139
The problem with this number is that the maximum number an integer can have is around
1 000 000 000
(Don't believe me? Try
JASS:
call BJDebugMsg(I2S(1000000*1000000))

and see what happens.)
this means that this number won't be able to get calculated and you will need to find another way to calculate this and AceHart chose to calculate the numbers in base 1000000 (since 11*1000000 < 1000000000 he won't have overflows problems).

Once he got got his big number 77591465139 into base 1000000 (which is basically 77591 465139; in the code it would mean that a[1] = 77591 and a[0] = 465139) and then he coverts it back to another base depending on the length of your alphabet, if your alphabet is for example "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" then you have 36 characters so you will convert to base 36 and for each number you have you will convert that number to the character that is at the same place (minus 1) in the string so the number 0 will be coverted to "A", the number 3 will be converted to "D", 10 will be converted to "K", 34 will be coverted to "8", ... .

And that is roughly how he goes from a bunch of numbers towards a save code (I prolly forgot some part like encode, player checksums, code checksums and others but I wanted to mainly cover the basic idea)
I know I rushed the explenation pretty fast at parts because I didn't want to go into detail into stuff you might already know but it is mainly about calculating in another base and a lot of coversions. If you still have troubles with it then I found this link http://en.wikipedia.org/wiki/Numeral_system that might help you. If it didn't then I guess you can always ask me.

GL.
 

sithin

New Member
Reaction score
5
i dont have time 2 read all of it b4 work but it looks freaking sound!!! thanks HEAPS!! ill read it all like 100 times uv helped me heaps thanks!!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top