IIYAMA

[src] Automatic mta compiler using mta services.

Recommended Posts

Automatic compile your whole resource. Do what you want with it, but keep the formal credits.

Don't forget that compiling isn't just for protection, it was also meant for optimization!

 

Version for universal resource compiler: (NEW)

resourceCompiler/meta.xml

<meta>
	<info author="IIYAMA" type="script" name="Resource compiler" version="1.3.0" />
	
	<script src="scripts/compiler_s.lua" />	
	<export function="compileResource" type="server"/>
	<aclrequest>
		<right name="function.fetchRemote" access="true" />
		<right name="general.ModifyOtherObjects" access="true" />
	</aclrequest>
</meta>

 


resourceCompiler/scripts/compiler_s.lua

 
------------------ 
-- by IIYAMA -- 

function compileResource (player, resourceName)
    if hasObjectPermissionTo ( player, "function.shutdown", false ) and getResourceFromName ( resourceName ) then 
		if not hasObjectPermissionTo ( getThisResource (), "function.fetchRemote", false ) then
			outputChatBox(" ", player)
			outputChatBox("Require fetchRemote to compiling this resource!", player, 255, 0, 0)
			outputChatBox(" ", player)
		else
			local meta = xmlLoadFile(":" .. resourceName .. "/meta.xml") 
			if meta then 
				local folderName =  "compiled/".. resourceName --.. "_compiled" 
				local newMeta = xmlCopyFile(meta, folderName .. "/meta.xml") 
				if newMeta then 
					local metaNotes = xmlNodeGetChildren(meta) 
					for i=1, #metaNotes do 
						local metaNote = metaNotes[i]
						local scriptName = xmlNodeGetAttribute(metaNote, "src") 
						if not scriptName or not string.match(scriptName, "compiler.lua") then
							if xmlNodeGetName(metaNote) == "script" then 
								
								if scriptName and scriptName ~= "" then 
									local FROM = ":" .. resourceName .. "/" .. scriptName 
									local TO = folderName .. "/" .. scriptName .. "c" 
									 
									local scriptFile = fileOpen(FROM) 
									 
									fetchRemote( "http://luac.mtasa.com/?compile=1&debug=0&obfuscate=2",  
									function(data)  
										local newscriptFile = fileCreate ( TO ) 
										if newscriptFile then 
											fileWrite(newscriptFile, data)  
											fileFlush(newscriptFile) 
											fileClose(newscriptFile) 
										end 
									end, fileRead(scriptFile, fileGetSize ( scriptFile )) , true )--fileLoad(FROM) 
									--https://luac.mtasa.com/api/ 
									 
								 
									fileClose(scriptFile) 
								end 
							else 
								local fileName = xmlNodeGetAttribute(metaNote, "src") 
								if fileName then 
									fileCopy (":" .. resourceName .. "/" .. fileName, folderName .. "/" .. fileName, true ) 
								end 
							end
						end
					end 
					local newMetaNotes = xmlNodeGetChildren(newMeta) 
					for i=1, #newMetaNotes do 
						local newMetaNote = newMetaNotes[i] 
						if xmlNodeGetName(newMetaNote) == "script" then 
							
							local scriptName = xmlNodeGetAttribute(newMetaNote, "src") 
							
							if not string.match(scriptName, "compiler.lua") then
								if scriptName and scriptName ~= "" then 
									xmlNodeSetAttribute ( newMetaNote, "src", scriptName .. "c" ) 
								end 
							else
								xmlDestroyNode(newMetaNote)
							end
						end 
					end 
					xmlSaveFile(newMeta) 
					xmlUnloadFile(newMeta) 
				end 
				xmlUnloadFile(meta) 
				outputChatBox("Compiling done!", player, 0, 200, 0) 
			end 
		end
    end 
	return true
end


addCommandHandler("compile", 
function (player, commandName, resourceName ) 
	compileResource (player, resourceName)
end)

 

 

Installation:

  • Put everything inside the folder resourceCompiler. (see file path for file name and sub folders)
  • Use the commando: /refresh
  • Give the resource the required rights(login as admin before you use this commando):
    /aclrequest allow resourceCompiler all
    This commando will give the resource all the rights that are defined in the meta.xml. (those are required to make the resource work)

Rights:

Spoiler



<right name="function.fetchRemote" access="true" />

This right for the function fetchRemote will make sure that you can send and receive your code. (to the mta compiler)


<right name="general.ModifyOtherObjects" access="true" />

This right will allow the resource to read and edit the files of other resources. (In this case it is for reading and copy files)


 

Usage:

  • /compile [resourceName]
  • There is an export function you can use.

 

Now you are ready to go! Don't forget to leave a like!

 


EXCLUDED (but can be included)

Do you want to compile resources it in your admin panel as well? That would be nice right? (This source code is only on request because I do not want to be responsible for releasing a version of admin panel. My credits isn't on it as well)

mta-screen_2017-06-08_17-23-582.png

 

Like this post + send me a PM to get a look at the adminpanel adjustments!
A PM with just: 'yes I want this!' is enough!

Installation:
 

Spoiler


  1. Remove the default admin resource. (pls make a backup)
  2. Add the new admin resource you will receive from me.
  3. Command: /refreshall
  4. Give the admin group the acl right: command.compile
    Else you wouldn't be able to press the 'compile' button.

<right name="command.compile" access="true"></right>


 

 

Usage:

Spoiler


  1. Make sure that the resources admin and resourceCompiler are running.
  2. Press your damn super super easy left mouse button on top of the 'compile' button in adminpanel.
  3. It will give feedback inside the adminpanel if the export is successfully.
  4. Take a look in > resourceCompiler\compiled < This is where all your compiled resources will show up.
    You can use this folder as an administration method for the resources you will upload to your server.

 

 

 

 


 

Version for compiling inside the same resource: (OLD, but still useful)

Spoiler

 

Serverside


  
------------------ 
-- by IIYAMA -- 
addCommandHandler("compileScripts", 
function (player) 
    if ( hasObjectPermissionTo ( player, "function.shutdown", false ) ) then 
        local meta = xmlLoadFile("meta.xml") 
        if meta then 
            local folderName = getResourceName (getThisResource ()) .. "_compiled" 
            local newMeta = xmlCopyFile(meta,folderName .. "/meta.xml") 
            if newMeta then 
                local metaNotes = xmlNodeGetChildren(meta) 
                for i=1, #metaNotes do 
                    local metaNote = metaNotes[i] 
                    if xmlNodeGetName(metaNote) == "script" then 
                        local scriptName = xmlNodeGetAttribute(metaNote, "src") 
                        if scriptName and scriptName ~= "" then 
                            local FROM = scriptName 
                            local TO = folderName .. "/" .. scriptName .. "c" 
                             
                            local scriptFile = fileOpen(FROM) 
                             
                            fetchRemote( "http://luac.mtasa.com/?compile=1&debug=0&obfuscate=2",  
                            function(data)  
                                local newscriptFile = fileCreate ( TO ) 
                                if newscriptFile then 
                                    fileWrite(newscriptFile, data)  
                                    fileFlush(newscriptFile) 
                                    fileClose(newscriptFile) 
                                end 
                            end, fileRead(scriptFile, fileGetSize ( scriptFile )) , true )--fileLoad(FROM) 
                            --https://luac.mtasa.com/api/ 
                             
                         
                            fileClose(scriptFile) 
                        end 
                    else 
                        local fileName = xmlNodeGetAttribute(metaNote, "src") 
                        if fileName then 
                            fileCopy ( fileName, folderName .. "/" .. fileName, true ) 
                        end 
                    end 
                end 
                local newMetaNotes = xmlNodeGetChildren(newMeta) 
                for i=1, #newMetaNotes do 
                    local newMetaNote = newMetaNotes[i] 
                    if xmlNodeGetName(newMetaNote) == "script" then 
                        local scriptName = xmlNodeGetAttribute(newMetaNote, "src") 
                        if scriptName and scriptName ~= "" then 
                            xmlNodeSetAttribute ( newMetaNote, "src", scriptName .. "c" ) 
                        end 
                    end 
                end 
                xmlSaveFile(newMeta) 
                xmlUnloadFile(newMeta) 
            end 
            xmlUnloadFile(meta) 
            outputChatBox("Compiling done!") 
        end 
    end 
end) 
 
  1. Add those line in your mta script. (serverside)
  2. Make sure your resource has admin rights to use the function fetchRemote.
  3. write: /compileScripts
  4. Check out the folder of your resource.
  5. A new folder will show up, with the name: _compiled

 

 

Edited by IIYAMA
  • Like 6
  • Thanks 1

Share this post


Link to post

(NOT little) * source code = update!

 

 

Edited by IIYAMA

Share this post


Link to post
On ٩‏/٦‏/٢٠١٧ at 19:35, IIYAMA said:

(NOT little) * source code = update!

 

am really like it it's so easy to understand and edit 

  • Thanks 1

Share this post


Link to post
9 hours ago, iMr.WiFi..! said:

there already compile system .-.
https://community.multitheftauto.com/index.php?p=resources&s=details&id=9219
check mods if you dont want to tradition, good luck .

True, yet this one is different.

  1. Fully automatic finding all the scripts.
  2. Copying other files to the new folder so you have 2 versions.

And most of all, this one you have to install yourself. Which might be an achievement for some people.

 

 

 

  • Like 1

Share this post


Link to post
On 28.08.2017 г. at 23:09, kikos500 said:

You can't decompile a script

Which is why i keep mine decompiled in folders. If security means so much pain in the ass if i wanna edit it then no thanks xD But awesome resource for those who need it :)

  • Thanks 1

Share this post


Link to post

Hmm, it is not that much of a pain if it only takes one button / command to make a compiled copy which ends up in 1 folder.

But indeed, it will takes some management work.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.