• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

handlevars (return casting) converter

Status
Not open for further replies.
Level 5
Joined
Jun 16, 2004
Messages
108
A certain patch in the past broke a lot of maps. In those days it was common to use a typecasting exploit to convert handles to integers and vice versa. This type of typecasting allowed for easily writing things that otherwise would have been a pain.

The patch broke that particular method of typecasting, but it also gave us some new natives to get back some of the functionality that would have otherwise gone missing. However, maps that used the old typecasting method became unplayable.

Usually someone experienced with the matter could modify the out of date map and fix its script, but this process is tedious to do. Ideally the map author was present at the time and updated their map(s) in response to the patch.

Anyway, I wrote something that tries to do that kind of update automatically.

This tool tries to convert very simple patterns of that typecasting into something the current game tolerates. There are only a few patterns it can deal with, so if the map did anything outside of that scope, the tool would be unable to update it properly.

That being said, there is a slight chance using this tool would mean being able to easily play an ancient map again. Perhaps give it a try if you have a map in mind.

This tool is provided mostly as a curiosity, as I have no strong feelings to update it for maps it fails to work on. If it works for you, then great. If not, you are probably better off trying to fix the map manually if you really want to play it.

Instructions:
- download and extract the archive
- copy your common.j and Blizzard.j into the /core directory
- drag maps you want to try converting onto the saddays.cmd file
- the converted map should appear as [map name]_append.w3x in the same directory as saddays.cmd
- try to play the generated map

Edit: I actually forgot to mention that you need to copy common.j and Blizzard.j into the /core directory originally.

Added a zipped archive with the same contents.
 

Attachments

  • omlafatig.7z
    699.7 KB · Views: 115
  • omlafatig.zip
    1.1 MB · Views: 154
Last edited:
Level 5
Joined
Jun 16, 2004
Messages
108
This is not meant to take advantage of any bugs. I wrote up some simple code to run the tool on just to give an idea of what the tool tries to do. I actually noticed some cases I meant to handle that are not being handled while writing this up, maybe someday I will fix them.

Original code:
JASS:
globals
    gamecache udg_localvars
    handle downcast
endglobals

function H2I takes handle h returns integer
    return h
    return 0
endfunction

function T2I takes timer t returns integer
    return t
    return 0
endfunction

function I2H takes integer i returns handle
    return i
    return null
endfunction

function Real2Int takes real r returns integer
    return r
    return 0
endfunction

function I2Timer takes integer i returns timer
    return i
    return null
endfunction

function LocalVars takes nothing returns gamecache
    return udg_localvars
endfunction

function SetHandleHandle takes handle subject, string name, handle value returns nothing
    if value==null then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(), I2S(H2I(subject)), name, H2I(value))
    endif
endfunction

function SetHandleInt takes handle subject, string name, integer value returns nothing
    if value==0 then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleBoolean takes handle subject, string name, boolean value returns nothing
    if value==false then
        call FlushStoredBoolean(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreBoolean(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleReal takes handle subject, string name, real value returns nothing
    if value==0 then
        call FlushStoredReal(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreReal(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleString takes handle subject, string name, string value returns nothing
    if value==null then
        call FlushStoredString(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreString(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function GetHandleHandle takes handle subject, string name returns handle
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

function GetHandleInt takes handle subject, string name returns integer
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
endfunction

function GetHandleBoolean takes handle subject, string name returns boolean
    return GetStoredBoolean(LocalVars(), I2S(H2I(subject)), name)
endfunction

function GetHandleReal takes handle subject, string name returns real
    return GetStoredReal(LocalVars(), I2S(H2I(subject)), name)
endfunction

function GetHandleString takes handle subject, string name returns string
    return GetStoredString(LocalVars(), I2S(H2I(subject)), name)
endfunction

function GetHandleUnit takes handle subject, string name returns unit
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

function GetHandleTimer takes handle subject, string name returns timer
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(), I2S(H2I(subject)) )
endfunction
// ===========================

function storeunitontimer takes timer t, unit u returns nothing
    call SetHandleHandle(t, "theunit", u)
endfunction

function getunitontimer takes timer t returns unit
    call GetHandleUnit(t, "theunit")
endfunction

function sneakydowncast takes nothing returns camerasetup
    set downcast = CreateCameraSetup() // todo (?) breaks with unit
    return downcast
endfunction

function sillytimer takes nothing returns nothing
    local integer timer_int = 0 // todo (?) breaks when assigned directly in the declaration
    local timer whywouldyoudothis = null
    set timer_int = H2I(CreateTimer())
    set whywouldyoudothis = I2H(timer_int)
endfunction

function preventoptimizations takes nothing returns nothing
    call sneakydowncast()
endfunction

function main takes nothing returns nothing
    // does stuff
endfunction

Converted code:
JASS:
globals
    gamecache udg_localvars
    camerasetup downcast
    hashtable jthtable
endglobals
function ILAR_timer takes integer p returns timer
    return LoadTimerHandle(jthtable,0,p)
endfunction
function SAR_unit takes unit p returns unit
    call SaveUnitHandle(jthtable,0,GetHandleId(p),p)
    return p
endfunction
function SAR_timer takes timer p returns timer
    call SaveTimerHandle(jthtable,0,GetHandleId(p),p)
    return p
endfunction
function H2I takes handle h returns integer
    return GetHandleId(h)
endfunction
function LocalVars takes nothing returns gamecache
    return udg_localvars
endfunction
function SetHandleHandle takes handle subject,string name,handle value returns nothing
    if value == null then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(),I2S(H2I(subject)),name,H2I(value))
    endif
endfunction
function SetHandleInt takes handle subject,string name,integer value returns nothing
    if value == 0 then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(),I2S(H2I(subject)),name,value)
    endif
endfunction
function SetHandleBoolean takes handle subject,string name,boolean value returns nothing
    if value == false then
        call FlushStoredBoolean(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreBoolean(LocalVars(),I2S(H2I(subject)),name,value)
    endif
endfunction
function SetHandleReal takes handle subject,string name,real value returns nothing
    if value == 0 then
        call FlushStoredReal(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreReal(LocalVars(),I2S(H2I(subject)),name,value)
    endif
endfunction
function SetHandleString takes handle subject,string name,string value returns nothing
    if value == null then
        call FlushStoredString(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreString(LocalVars(),I2S(H2I(subject)),name,value)
    endif
endfunction
function GetHandleInt takes handle subject,string name returns integer
    return GetStoredInteger(LocalVars(),I2S(H2I(subject)),name)
endfunction
function GetHandleBoolean takes handle subject,string name returns boolean
    return GetStoredBoolean(LocalVars(),I2S(H2I(subject)),name)
endfunction
function GetHandleReal takes handle subject,string name returns real
    return GetStoredReal(LocalVars(),I2S(H2I(subject)),name)
endfunction
function GetHandleString takes handle subject,string name returns string
    return GetStoredString(LocalVars(),I2S(H2I(subject)),name)
endfunction
function GetHandleUnit takes handle subject,string name returns unit
    return LoadUnitHandle(jthtable,0,GetStoredInteger(LocalVars(),I2S(H2I(subject)),name))
endfunction
function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(),I2S(H2I(subject)))
endfunction
function storeunitontimer takes timer t,unit u returns nothing
    call SetHandleHandle(SAR_timer(t),"theunit",SAR_unit(u))
endfunction
function getunitontimer takes timer t returns unit
    call GetHandleUnit(SAR_timer(t),"theunit")
endfunction
function sneakydowncast takes nothing returns camerasetup
    set downcast = CreateCameraSetup()
    return downcast
endfunction
function sillytimer takes nothing returns nothing
    local integer timer_int = 0
    local timer whywouldyoudothis = null
    set timer_int = H2I(SAR_timer(CreateTimer()))
    set whywouldyoudothis = ILAR_timer(timer_int)
endfunction
function preventoptimizations takes nothing returns nothing
    call sneakydowncast()
endfunction
function main takes nothing returns nothing
    set jthtable = InitHashtable()
endfunction
 
Level 1
Joined
Nov 9, 2018
Messages
1
GENTLEMEN,


I will ask you to help me this day. I am not an english speaker i must say, but two years ago I ask if a good soul could help me fix this map. I will ask again: PLEASE, fix this map for me, it is already open, but I don't know how to fix. This map stopped to work in 1.24+ version, and since that time I can't play this map. It is an awsome map, so please.

THE PROBLEM IS:

Since 1.24 version this map can not be create anymore. It just doesn't work. I can't create the map to play it.


with sincerily,


Thank you

Doido II, the best x hero 3.45 player of all.
 

Attachments

  • Open VampBR 0.8b.w3x
    2 MB · Views: 64
Status
Not open for further replies.
Top