speige / WC3MapDeprotector

Warcraft 3 Custom Map deprotector
https://www.youtube.com/@ai-gamer
MIT License
26 stars 3 forks source link

Fire Arena deprotection #35

Open alex-voronovich opened 4 months ago

alex-voronovich commented 4 months ago

Hi there. Thank you very much for what you are doing.

I have this map Fire Arena. It is quite old and any support is long gone. https://www.epicwar.com/maps/283244

Tried to use the deprotector, even completed a full playthrough during testing. However WC3 editor still fails to open it.

The screenshot contains the initial error before deprotection Screenshot 2024-07-17 143956

After deprotection it tries to load units: Screenshot 2024-07-17 155319

At this step the editor crashes completely

speige commented 4 months ago

You're right, this is definitely a bug in my app. Unfortunately, it doesn't deprotect all maps 100% successfully yet. I'm a bit busy with other projects right now, so I won't be able to fix this bug right away, however I can give you some hints if you want to fix it yourself.

The bug is related to not recovering this file correctly: war3mapUnits.doo This is what shows all the units on the screen in the editor (the actual units are created in-game by war3map.j) When the map is saved, a CreateAllUnits function is auto-generated from this war3mapUnits.doo file & inserted into war3map.j.

Here's a partial fix: Make a blank map with world editor & save it, extract the war3mapUnits.doo file, insert that file into "Fire Arena v4.2_deprotected.w3x" (replacing the corrupted one). It's a partial fix because it'll open in the editor, but the units won't render in the editor (they will still work in game), but if you save, the CreateAllUnits will be re-generated from a blank slate, which will remove all the units in-game.

Here's a permanent fix: Extract the war3map.j from "Fire Arena v4.2_deprotected.w3x" using MPQEditor (before you complete the partial fix above & open/save in the editor), name it war3map_before.j Perform the partial fix above & Open/Save in the World editor. Extract the war3map.j again, name it war3map_after.j Download & install a program called WinMerge, use it to compare the before/after versions of war3map.j You will see functions like these have been removed:

function CreateBuildingsForPlayer0 takes nothing returns nothing
local player p=Player(0)
local unit u
local integer unitID
local trigger t
local real life
set u=CreateUnit(p,0x68303031,576.0,-3840.0,270.000)
call SetUnitColor(u,ConvertPlayerColor(12))
endfunction

Your goal is to fix the war3mapunits.doo file so that it re-generates the war3map.j without deleting this function. You do this by manually finding the unit 0x68303031 in the unit palette, putting it on the screen at the correct coordinates, saving the map, extracting war3map_after.j & refreshing winmerge to see if it's generating correctly now. You'll need to do this for each unit that's being deleted when you save.

One hint about finding the unit. 0x68303031 is the unit type. The standard way this is written is 'h001' but the protection changed the format to make it harder to read. Search for an ASCII table online & look only at the HEX column (not decimal). Split the hex string into pairs of 2 numbers (68 30 30 31), look each of those up on the ASCII table & you get h001. Next, open Object Editor window in WC3 Editor, Click View/DisplayValuesAsRawData, you will now see the code for HumanPeasant is hpea, etc. Click Edit/Find, type h001, & it'll take you to the correct unit. Right-click, Select in Tool Palette. Now you can place it on the map & save.

Some units may be a bit more complicated that, for example a hero may be set to a certain level, have certain abilities upgraded already, or be holding certain items. You will see it in the JASS function, you will need to edit the properties of the unit after you place it on the map by selecting it & pressing enter (not the object editor which affects all units of that type, only the specific unit you placed on the map). If you get lucky, there won't be very many units to create & they won't have many extra settings, but I'm not familiar with this map, so I don't know.

If you don't understand JASS, copy the file to ChatGPT & ask it to explain to you everything that happens in the call stack starting from CreateAllUnits.

Let me know if you have any more questions.

Good luck!

alex-voronovich commented 4 months ago

Thanks! Will give it a try