Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

PHP script to Decode style

Custom Title Activated
Loyal Member
Joined
Feb 27, 2004
Messages
1,378
Reaction score
50
reason for this release is cause i wanna see if any of u find faults in it

PHP:
function decode_style($r) {

	  //get gender
    $gender_array = array('Male', 'Female', 'Male 2','Female 2','Male 3', 'Female 3');
    $style['Gender'] = $gender_array[round($r / hexdec(4000000))];
	//GET AURA
	$style['Aura'] = round(($r % hexdec(4000000)) / hexdec(200000));
    // hair 
    $style['Hair'] = round(($r % hexdec(4000000) % hexdec(200000) ) / hexdec(20000));
   
    //hair color
    $style['Hair_Color'] = round((($r % hexdec(4000000)) % hexdec(20000)) / hexdec(2000));
    
    // get face 
    $style['Face'] = round(((($r % hexdec(4000000)) % hexdec(20000)) % hexdec(2000)) / hexdec(100));
    
    // get rank
    $style['Class_Rank'] = round((((($r % hexdec(4000000)) % hexdec(20000)) % hexdec(2000)) % hexdec(100)) / 8 );
    
    // get class
    $class_array = array(4=>'Force Archer',5=>'Force Shielder',6=>'Force Blader',
    9=>'Warrior',10=>'Blader',11=>'Wizard',12=>'Force Archer',13=>'Force Shielder',14=>'Force Blader');

    $style['Class'] = (((($r % hexdec(4000000)) % hexdec(20000)) % hexdec(2000)) % hexdec(100)) -  (($style['Class_Rank'] -1) * 8) ;

    $style['Class_Name'] = $class_array[$style['Class']] ;
    return $style;
	
}

how to use decode_style(STYLE);
returns an array

something like this
PHP:
  [Gender] => Male
    [Hair] => 4
    [Hair_Color] => 6
    [Face] => 3
    [Class_Rank] => 1
    [Class] => 9
    [Class_Name] => Warrior

see it in action here:
 
Last edited:
Custom Title Activated
Loyal Member
Joined
Feb 27, 2004
Messages
1,378
Reaction score
50
updated:

added aura edit:

u can also reverse it to create new style codes.
warning: not all faces will work since most clients do not have some faces/hairs/colors... so better experiment 1st.

 
Newbie Spellweaver
Joined
Jul 2, 2005
Messages
96
Reaction score
0
Can you please explain what's going on in English, so i can apply this to other programming languages.

Thanks (I don't understand PHP very well Q_Q)
 
The Dinosaur
Loyal Member
Joined
Jun 29, 2008
Messages
5,028
Reaction score
999
It's just a set of mathematical formulas to extract specific values from the class. Just take each line one at a time and pull it apart. $r is the class.

$style['Gender'] = $gender_array[round($r / hexdec(4000000))];

hexdec(4000000) = 3D0900


So $r divided by 3D0900 (and then rounded) = your gender.

You can look up the other operators like modulus here.


You can tell no-one understands it as there are so few comments on what is one of the best posts here ;)
 
Newbie Spellweaver
Joined
Jul 2, 2005
Messages
96
Reaction score
0
It's just a set of mathematical formulas to extract specific values from the class. Just take each line one at a time and pull it apart. $r is the class.

$style['Gender'] = $gender_array[round($r / hexdec(4000000))];

hexdec(4000000) = 3D0900


So $r divided by 3D0900 (and then rounded) = your gender.

You can look up the other operators like modulus here.


You can tell no-one understands it as there are so few comments on what is one of the best posts here ;)

Thanks ALOT (again) LOL, ill try this right now :), only problem now T_T how do i get the remainder from windows calculator lol
 
Custom Title Activated
Loyal Member
Joined
Feb 27, 2004
Messages
1,378
Reaction score
50
Thanks ALOT (again) LOL, ill try this right now :), only problem now T_T how do i get the remainder from windows calculator lol

easy as pie

NUMBER1 DIVIDE NUMBER2 =

NUMBER3[/I].DECIMALS ...

SUBTRACT THE NUMBER3[/I] AND MULTIPLE BY NUMBER2

Sample:

23 / 8 = 2.875
2.875 - 2 = 0.875
0.875 * 8 = 7
 
Newbie Spellweaver
Joined
Jul 2, 2005
Messages
96
Reaction score
0
easy as pie

NUMBER1 DIVIDE NUMBER2 =

NUMBER3[/I].DECIMALS ...

SUBTRACT THE NUMBER3[/I] AND MULTIPLE BY NUMBER2

Sample:

23 / 8 = 2.875
2.875 - 2 = 0.875
0.875 * 8 = 7


okay so, can you give me an example of working out the whole of a style, because i want to make sure it's correct, so what would this give you? Just the first two or three (Like sex, aura) would be enough to make me understand really, sorry lol >_<
Style example: 213934124

As you can see it goes 100% wrong when i do it, although i did it all as decimals as you can only get whole numbers when using Hexadecimal numbers
Code:
213934124 / 4000000 => 53.483531 - 53 => .483531 * 4000000 => % 1934124 'Gender
1934124   / 200000  => 09.67062  - 09 => .67062  * 200000  => % 134124 'Aura
134124    / 20000   => 06.7062   - 06 => .7062   * 20000   => % 14124 'Hair
14124     / 2000    => 07.062    - 07 => .062    * 2000    => % 124 'Hair Color
124       / 100     => 01.24     - 01 => .24     * 100     => % 24 'Face
24        / 8       => 03.00     - 03 => .00     * 8       => % 0 'Rank
 
Custom Title Activated
Loyal Member
Joined
Feb 27, 2004
Messages
1,378
Reaction score
50
u totally ignored the fact that it the whole numbers there are HEX not decimals. i only put 4000000 cause i was too lazy to type up their decimal values


gender :
PHP:
   $style['Gender'] = $gender_array[round($r / hexdec(4000000))];
213934124 / 67108864 = 3.187866866588592529296875 = 3
- gender gets only the whole number ( ROUND IT )
- 3 would be female 2. ( array starts with 0 )

aura:
PHP:
  $style['Aura'] = round(($r % hexdec(4000000)) / hexdec(200000));
213934124 / 67108864 = 3.187866866588592529296875 - 3 = * 67108864 =
12607532 / 2097152 = 6.0117397308349609375
= 6

same goes for the rest. it is just a repeat process just adding new values.
notes:
% mean find remainder
/ means divide
round means to get the whole number
() means calculate priority. inner-most comes first ie. (3nd cal((1st / cal) * 2nd cal ))

anyway here is the output of 213934124
[Gender] => Female 2
[Aura] => 6
[Hair] => 0
[Hair_Color] => 3
[Face] => 0
[Class_Rank] => 6
[Class] => 4
[Class_Name] => Force Archer
 
Newbie Spellweaver
Joined
Jul 2, 2005
Messages
96
Reaction score
0
u totally ignored the fact that it the whole numbers there are HEX not decimals. i only put 4000000 cause i was too lazy to type up their decimal values


gender :
PHP:
   $style['Gender'] = $gender_array[round($r / hexdec(4000000))];
213934124 / 67108864 = 3.187866866588592529296875 = 3
- gender gets only the whole number ( ROUND IT )
- 3 would be female 2. ( array starts with 0 )

aura:
PHP:
  $style['Aura'] = round(($r % hexdec(4000000)) / hexdec(200000));
213934124 / 67108864 = 3.187866866588592529296875 - 3 = * 67108864 =
12607532 / 2097152 = 6.0117397308349609375
= 6

same goes for the rest. it is just a repeat process just adding new values.
notes:
% mean find remainder
/ means divide
round means to get the whole number
() means calculate priority. inner-most comes first ie. (3nd cal((1st / cal) * 2nd cal ))

anyway here is the output of 213934124
[Gender] => Female 2
[Aura] => 6
[Hair] => 0
[Hair_Color] => 3
[Face] => 0
[Class_Rank] => 6
[Class] => 4
[Class_Name] => Force Archer
Thanks ALOT i understand now :)

But im hitting a snag in my program, and i don't understand why o_O
Code:
            Style = DataReader.GetValue(12)
            Gender = Style / 67108864
            Aura = (((Gender - CInt(Gender)) * 67108864) / 2097152)
            Hair = (((Aura - CInt(Aura)) * 67108864) / 131072)
            Color = (((Hair - CInt(Hair)) * 67108864) / 8192)
            Face = (((Color - CInt(Color)) * 67108864) / 256)
            Rank = (((Face - CInt(Face)) * 67108864) / 8)
            txtRank.Text = CInt(Rank)
when it gets to my variable color, it ALWAYS ends up as a whole number. meaning everything else (face and rank) become just 0.

I notice you don't carry the aura down to the hair color, could this be the problem?

Can you spot a problem? :S
 
Last edited:
Junior Spellweaver
Joined
Nov 10, 2005
Messages
101
Reaction score
0
Thanks jhon_d for this code. Very good.
02goswej seams you are trying to translate to vb or asp. If this is the case I have made a simple translation to asp:

<%
Function hexdec (sStyle)
hexdec=clng("&h" & sStyle)
End Function
%>
<%
Function decode_style (sStyle)
DIM gender_array(5)

'gender_array=Array(Male,Female,Male 2,Female 2,Male 3,Female 3)
gender_array (0) = "Male"
gender_array (1) = "Female"
gender_array (2) = "Male 2"
gender_array (3) = "Female 2"
gender_array (4) = "Male 3"
gender_array (5) = "Female 3"
'GET Gender
Gender= gender_array(round(sStyle / hexdec(4000000)))

'GET Aura
Aura = round((sStyle mod hexdec(4000000)) / hexdec(200000))
' hair
Hair = round((sStyle mod hexdec(4000000) mod hexdec(200000) ) / hexdec(20000))
'hair color
Hair_Color = round(((sStyle mod hexdec(4000000)) mod hexdec(20000)) / hexdec(2000))
' get face
Face = round((((sStyle mod hexdec(4000000)) mod hexdec(20000)) mod hexdec(2000)) / hexdec(100))
' get rank
Class_Rank = round(((((sStyle mod hexdec(4000000)) mod hexdec(20000)) mod hexdec(2000)) mod hexdec(100)) / 8 )
' get class
DIM class_array(14)
class_array (4) = "Force Archer"
class_array (5) = "Force Shielder"
class_array (6) = "Force Blader"
class_array (9) = "Warrior"
class_array (10) = "Blader"
class_array (11) = "Wizard"
class_array (12) = "Force Archer"
class_array (13) = "Force Shielder"
class_array (14) = "Force Blader"
sClass = (((( sStyle mod hexdec(4000000)) mod hexdec(20000)) mod hexdec(2000)) mod hexdec(100)) - ((Class_Rank -1) * 8)
Class_Name = class_array(sClass)
decode_style= "[Gender] => " & Gender & "<BR>" & "[Hair] => " & Hair & "<BR>" & "[Hair_Color] => " & Hair_Color & "<BR>" & "[Face] => " & Face & "<BR>" & "[Class_Rank] => " & Class_Rank & "<BR>" & "[Class] => " & sClass & "<BR>" & "[Class_Name] => " & Class_Name
End Function
%>

So you can test using:
<% response.write ( decode_style(12984740)) %>
and result is:
[Gender] => Male
[Hair] => 3
[Hair_Color] => 1
[Face] => 2
[Class_Rank] => 20
[Class] => 12
[Class_Name] => Force Archer
==============================
Or you can use sql analyzer to show rank 18 class:
use [SERVER01] -- or use [GAMEDB]
SELECT Name,Style from dbo.cabal_character_table WHERE
round(((((([Style] % (67108864)) % (131072)) % (8192)) % (256)) / 8 ),1)= 18

and even update class 18 to 20 :) :
update dbo.cabal_character_table
set [Style]=[Style]+16 where round(((((([Style] % (67108864)) % (131072)) % (8192)) % (256)) / 8 ),1)= 18
 
Newbie Spellweaver
Joined
Jul 2, 2005
Messages
96
Reaction score
0
Thanks for the help, just checked today but I fixed it a long time ago, adding more to it now, how would I rebuild the style after I have edited things like the rank/Hair etc
 
Newbie Spellweaver
Joined
Jul 2, 2005
Messages
96
Reaction score
0
All im finding on google with string "Reverse Modulus" is basically....Impossible ;P im retarded when in comes to complex maths :eek: (And i have been up since 5AM and just woken up now :p)
here is my VB Code for decoding the style:

Code:
            Style = DR.GetValue(12)
            Gender = Style / 67108864
            Aura = (Style Mod 67108864) / 2097152
            Hair = ((Style Mod 67108864) Mod 2097152) / 131072
            HColor = ((Style Mod 67108864) Mod 131072) / 8192
            Face = (((Style Mod 67108864) Mod 131072) Mod 8192) / 256
            Rank = ((((Style Mod 67108864) Mod 131072) Mod 8192) Mod 256) / 8
            PlayerClass = ((((Style Mod 67108864) Mod 131072) Mod 8192) Mod 256) - ((Rank - 1) * 8)
so in reverse would i be somthing like
Code:
Style = 2097152 * (Aura / 67108864) or would it be  (Aura Mod 67108864)

-02goswej

bump, Help please :S
 
Last edited by a moderator:
Back
Top