I found this a long time ago, and never really publically shared it, even tho I told about this to Nestharus and he used this knowledge inside his Allocator, to print error of running instance.
I dont know if this works with Cohadar's version of Jass Helper, but it works with the newest version of Vexorian's Jass Helper.
Because of how the vJass processing works, all occurences of
But wait, this is very well known thing, why am I saying this?
The thing is that Vexorian never performed checks whether the keyword thistype is inside string or not, and if we put it inside the string, it will also get replaced with the structs name, even with the public/private modifiers.
2 most useful examples:
if we include the module in
Second good use would be textmacro:
which compiled looks like:
But wait, you can pass the name of the current struct even into textmacro!
Example:
Compiled:
Simple Alloc that uses this "exploit" to output debug messages when failed:
(Taken from http://www.hiveworkshop.com/forums/pastebin.php?id=7cpuvw).
This is not the fastest Alloc you can get, but it is example so you can rewrite it to your image if you want.
Hopefully someone will find this a bit usefull
I dont know if this works with Cohadar's version of Jass Helper, but it works with the newest version of Vexorian's Jass Helper.
Because of how the vJass processing works, all occurences of
thistype
will get replaced depending on where it is placed(because of the way that vJass is processed), but if you use it before member variable, it will be replaced with current struct's name, the same as with locals or return types.But wait, this is very well known thing, why am I saying this?
The thing is that Vexorian never performed checks whether the keyword thistype is inside string or not, and if we put it inside the string, it will also get replaced with the structs name, even with the public/private modifiers.
2 most useful examples:
JASS:
module myAwesomeModule
method myAwesomeMethod takes nothing returns nothing
call BJDebugMsg("We are inside myAwesomeModule, which expanded into struct thistype")
endmethod
endmodule
if we include the module in
struct MyAwesomeStruct
the output looks as following:
JASS:
//Implemented from module myAwesomeModule:
function s__MyAwesomeStruct_myAwesomeMethod takes integer this returns nothing
call BJDebugMsg("We are inside myAwesomeModule, which expanded into struct MyAwesomeStruct")
endfunction
Second good use would be textmacro:
JASS:
//! textmacro printSelf
call BJDebugMsg("thistype")
//! endtextmacro
struct MySecondAwesomeStruct
private method a takes nothing returns nothing
//! runtextmacro printSelf()
endmethod
endstruct
which compiled looks like:
JASS:
function s__MySecondAwesomeStruct_a takes integer this returns nothing
//textmacro instance: printSelf()
call BJDebugMsg("MySecondAwesomeStruct")
//end of: printSelf()
endfunction
But wait, you can pass the name of the current struct even into textmacro!
Example:
JASS:
//! textmacro print takes a
call BJDebugMsg("$a$")
//! endtextmacro
struct MyAwesomeStruct
private method myMethod takes nothing returns nothing
//! runtextmacro print("thistype")
endmethod
endstruct
Compiled:
JASS:
function s__MyAwesomeStruct_myMethod takes integer this returns nothing
//textmacro instance: print("thistype")
call BJDebugMsg("MyAwesomeStruct")
//end of: print("thistype")
endfunction
Simple Alloc that uses this "exploit" to output debug messages when failed:
JASS:
library AllocLib
/*
AllocLib library
version 1.1
by edo494
Alloc Example, includes debug messages with struct names that failed to load instance.
Double free protection is present in debug and in release mode, so is overflow.
However, messages are only print if debug mode is on.
*/
module Alloc
private static integer allocCount = 0
private static integer array allocList
static method allocate takes nothing returns thistype
local thistype this = allocList[0]
if this == 0 then
if allocCount >= 8190 then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10, "cannot allocate struct thistype(overflow)")
return 0
endif
set this = allocCount + 1
set allocCount = this
else
set allocList[0] = allocList[this]
endif
set allocList[this] = -1
return this
endmethod
method deallocate takes nothing returns nothing
if allocList[this] == -1 then
debug call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10, "cannot deallocate struct thistype(already deallocated)")
return
endif
set allocList[this] = allocList[0]
set allocList[0] = this
endmethod
endmodule
endlibrary
This is not the fastest Alloc you can get, but it is example so you can rewrite it to your image if you want.
Hopefully someone will find this a bit usefull
Last edited: