Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.46 KB | None | 0 0
  1. local sKey = "your_key_here"; -- Максимальная длина - 16 символов, можно больше, но смысла нет. Читаться будут только первые 16 символов.
  2. local iCountBytes = 1000;
  3.  
  4. -- CODING
  5. addEventHandler( "onResourceStart", resourceRoot,
  6.     function()
  7.         local XML = xmlLoadFile( "meta.xml" );
  8.         local Childrens = xmlNodeGetChildren( XML );
  9.         for Index, Child in ipairs( Childrens ) do
  10.             local Name = xmlNodeGetName( Child );
  11.             if Name == "file" then
  12.                 local Attributes = xmlNodeGetAttributes( Child );
  13.                 local FilePath = Attributes.src;
  14.  
  15.                 local pFile = fileOpen( FilePath )
  16.                 local FirstPart = fileRead( pFile, 65536 )
  17.                 fileSetPos( pFile, 65536 )
  18.                
  19.                 local SecondPart = fileRead( pFile, iCountBytes )
  20.                 local SecondPartConverted = ""
  21.                 local aTable = {}
  22.                 for i = 1, iCountBytes do
  23.                     local sString = string.sub( SecondPart, i )
  24.                     local iByte = string.byte( sString )
  25.                     SecondPartConverted = SecondPartConverted..teaEncode( iByte, sKey )
  26.                 end
  27.                 fileSetPos( pFile, 65536+iCountBytes )
  28.                
  29.                 local ThirdPart = fileRead( pFile, fileGetSize( pFile ) - (65536+iCountBytes) )
  30.                 local sResult = FirstPart..SecondPartConverted..ThirdPart
  31.                 fileClose( pFile )
  32.                
  33.                 local FileName = string.gsub( FilePath, "FILES_TO_ENCODE/", "" );  
  34.                 if fileExists( "ENCDODED_FILES/"..FileName ) then
  35.                     fileDelete( "ENCDODED_FILES/"..FileName )
  36.                 end
  37.                 pFile = fileCreate( "ENCDODED_FILES/"..FileName )
  38.                 fileWrite( pFile, sResult )
  39.                 fileClose( pFile )
  40.             end
  41.         end
  42.     end
  43. )
  44.  
  45. -- UNCODING
  46. local XML = xmlLoadFile( "meta.xml" );
  47. for Index, Table in ipairs( g_DffReplaces ) do
  48.     local pFile = fileOpen( Table[1] );
  49.     local FirstPart = fileRead( pFile, 65536 )
  50.     fileSetPos( pFile, 65536 )
  51.     local SecondPart = fileRead( pFile, iCountBytes * 12 );
  52.     local SecondPartConverted = ""
  53.     for i = 1, iCountBytes do
  54.         local iTo = i * 12
  55.         local iFrom = iTo - 11
  56.         local sConvertedString = string.sub( SecondPart, iFrom, iTo )
  57.         local iDecodedNumber = tonumber( teaDecode( sConvertedString, Key ) )
  58.         local sChar = string.char( iDecodedNumber )
  59.         SecondPartConverted = SecondPartConverted..sChar
  60.     end
  61.     fileSetPos( pFile, 65536+iCountBytes*12 )
  62.     local ThirdPart = fileRead( pFile, fileGetSize( pFile ) - (65536+iCountBytes*12) )
  63.     local sResult = FirstPart..SecondPartConverted..ThirdPart
  64.  
  65.     local DFF = engineLoadDFF( sResult );
  66.     engineReplaceModel( DFF, Table[2] );
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement