Advanced JASS Tutorials?

General talk about editing, cheating, and deprotecting maps.

Moderator: Cheaters

storyyeller
Senior Member
Posts: 178
Joined: February 15th, 2009, 9:08 pm

Re: Advanced JASS Tutorials?

Post by storyyeller »

Ok I think I get it.
Is the ability to delay with the TriggerSleepAction the only difference between having everything in one thread and opening new threads?
Could multiple threads be used to reduce lag?

On another topic, what exactly are gamecaches? In what ways are they different from global variables? Can they be used for synchronization?
initialD
Some Honorary Title
Posts: 1713
Joined: June 8th, 2007, 5:08 am
Title: Angry Bird

Re: Advanced JASS Tutorials?

Post by initialD »

storyyeller wrote:But for natives, it only displays the prototype (I assume the actual logic of the natives is hardcoded into the game)

For example, when I look up ExecuteFunc, all I see is

Code: Select all

native ExecuteFunc          takes string funcName returns nothing
That doesn't really clarify whether code like this is acceptable or not. If foo is called, do the functions execute simulatenously or in sequence? Which one goes first? Or is there an error?

Code: Select all

globals
integer i
integer j
endglobals

function foo takes nothing returns nothing
set i=0
set j=0
call ExecuteFunc("bar")
loop
   exitwhen i==1
   set j=j+1
endloop
endfunction

function bar takes nothing returns nothing
//do stuff here
set i=1
endfunction
this doesn't work. You can't put function bar below of function foo.
and loop fails. It will loop for more then 12000 times and creates massive lags.
get some basic tutorials first. perhaps? good luck
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Advanced JASS Tutorials?

Post by Aero »

initialD wrote:this doesn't work. You can't put function bar below of function foo.
and loop fails. It will loop for more then 12000 times and creates massive lags.
get some basic tutorials first. perhaps? good luck
You're completely wrong actually.
Not only CAN you do that (ExecuteFunc can call functions that happen AFTER the function) but it wont loop forever at all.
function "bar" will execute and set 'i' to 1.

Then, the loop will begin and i will equal 1. Then the loop will exit. No infinite looping.

Also, in the event it did loop forever, it would hit the op limit and the thread would quit.
So, it would lag for about .5-1seconds then it would be fine.
initialD
Some Honorary Title
Posts: 1713
Joined: June 8th, 2007, 5:08 am
Title: Angry Bird

Re: Advanced JASS Tutorials?

Post by initialD »

opss, I have never do that before, executing a function which is below.
Last time I tried it on JASScraft it showed me some syntax errors. Probably I have been messing up with some other things.
Thanks for information.
storyyeller
Senior Member
Posts: 178
Joined: February 15th, 2009, 9:08 pm

Re: Advanced JASS Tutorials?

Post by storyyeller »

In fact, I actually sort of abused that feature in a map I worked on once

I just stuck a bunch of functions like this at the top of my code, so that I could call them from anywhere regardless of order. It is kind of annoying having to pass arguments through global variables though. Also, of course that only works for code that doesn't involve waits or recursion.

Code: Select all

function protoTowerSwap takes nothing returns nothing
    call ExecuteFunc("funcTowerSwap")
endfunction
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Advanced JASS Tutorials?

Post by Aero »

storyyeller wrote:In fact, I actually sort of abused that feature in a map I worked on once

I just stuck a bunch of functions like this at the top of my code, so that I could call them from anywhere regardless of order. It is kind of annoying having to pass arguments through global variables though. Also, of course that only works for code that doesn't involve waits or recursion.

Code: Select all

function protoTowerSwap takes nothing returns nothing
    call ExecuteFunc("funcTowerSwap")
endfunction
That's not abuse at all. That's just laziness. ExecuteFunc has much better uses...

For example.

1. It opens a new thread (avoid op limits)

2. You can ExecuteFunc a function that returns a value (Useful if you play it right), but not one that takes any.

3. If called in a function that has event responses, the event responses carry.

ex:

Code: Select all

function SomeFunc takes nothing returns integer
local unit u=GetTriggerUnit()
//YES THIS WORKS
set u=null
endfunction

function Some_Trigger_Action_Function takes nothing returns nothing
call ExecuteFunc("SomeFunc")
endfunction
4. You can call functions with ExecuteFunc by concatenating.

ex:

Code: Select all

function ForPlayer0 takes nothing returns nothing
//I WILL RUN
endfunction

function Some_Trigger_Action_Funtion takes nothing returns nothing
local player p=GetTriggerPlayer()
local integer id=GetPlayerId(p)
call ExecuteFunc("ForPlayer"+I2S(id))
set p=null
endfunction
If you use your brain a bit you can probably see that ExecuteFunc is quite useful.
storyyeller
Senior Member
Posts: 178
Joined: February 15th, 2009, 9:08 pm

Re: Advanced JASS Tutorials?

Post by storyyeller »

Obviously it has more uses, I just haven't used them
At the very least, it works wonders for code obfuscation

How to write unmaintainable code, JASS edition

Make sure every function is called with ExecuteFunc
Use global variables for everything
Make sure that the strings used for function execution are generated with a complex method which is virtually impossible to predict
Liberally sprinkle it with random side effects, handle counts, bizarre command flow, race conditions, etc. and even the most seasoned hacker will give up in disgust.

As a bonus, if they try to rename any of the functions to a meaningful non-obfuscated name, the code will instantly break.

Another bonus: You can "accidently" set it up so that it randomly crashes when people mess with stuff in the wrong ways or try adding/removing triggers. And they won't even be able to find out why it's crashing without insane amounts of work.
User avatar
Ozzapoo
The Flying Cow!
Posts: 2196
Joined: November 2nd, 2007, 10:34 pm
Location: Melbourne

Re: Advanced JASS Tutorials?

Post by Ozzapoo »

Isn't the point of using Jass over GUI to make it less leaky?
Visit Ozzapoo.net, my blog and the home of AutoCP and Cheatpack Detector!
AutoCP3 now available for free!
User avatar
Risen
Forum Staff
Posts: 811
Joined: January 1st, 2008, 12:58 am

Re: Advanced JASS Tutorials?

Post by Risen »

storyyeller wrote: How to write unmaintainable code, JASS edition

Make sure every function is called with ExecuteFunc
Use global variables for everything

As a bonus, if they try to rename any of the functions to a meaningful non-obfuscated name, the code will instantly break.
This 'Obfusciation' won't work for the majority, chances are, If they actually need to rename a function, They'll just use the JASSDo, Built into RMPQEx.

Oh, if you really wanna be smart, Name some random functions (That won't be called) and set their name as some of JJ's CP functions like... "WaitForString...", Etc.
Image
Wanna learn to hack maps? --> Guide
User avatar
Aero
Forum Staff
Posts: 829
Joined: January 28th, 2007, 8:10 pm
Title: JASS Programmer
Location: Canada

Re: Advanced JASS Tutorials?

Post by Aero »

Ozzapoo wrote:Isn't the point of using Jass over GUI to make it less leaky?
It's to overall improve efficiency, make it leak free and cleaner.

However, he's not discussing that. He's discussing the uses of ExecuteFunc and the difficulty of trying to break a map that's nested with it.