• 🏆 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!

Sharpcraft for multiplayer

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
1. INTRO
Some times ago I asked about how to play sharpcraft (with new natives) in multiplayer (but I can't locate that post anymore) and someone (perhaps PurgeandFire) answered that we need to modify the common.j and inject the new natives in order to pass a quick checking before we enter a room. But I was too lazy to test this and chose to stop my project due to this problem, it was my fault seriously. But a moment ago, finally I got some motivations to actually do some researches how to play sharpcraft in multiplayer, and soon discovered that the method above works flawlessly. So here is the steps how I did it. Check it out!​

2. What is a Sharpcraft?
I'm not the best guy to explain sharpcraft so you can go here instead to read some informations about it. In short, it's an awesome tools that allows us to do many cool things like creating our own native functions, etc. (etc. because I don't know anything else :p). However, it requires some works to install it properly.​

3. How to play multiplayer map with Sharpcraft?
A. Why it can't work without these steps?
Before you enter a room, Warcraft will run some kind of quick check to validate your Warcraft 3 or perhaps the map. If the map has unidentified scripts (like new natives), then you just can't enter the room because it will assume that your Warcraft version is incompatible with the target room. Thus we need to modify the function library (common.j) and manually write the declaration of our new functions by ourselves.​

B. How to make it works?
The trick is to modify the common.j file without modifying war3.mpq:
  1. You need to have "Allow local files" enabled (tuts). Normally, one who has JNGP wouldn't have this problem since they can simply enable it under Extensions > Enable Local Files.
  2. Use a MPQ Extractor application (example). Open war3.mpq using that tool and go to Scripts > common.j then extract the file somewhere.
  3. Open the extracted common.j using notepad. Press CTRL+End (Windows) to go to the bottom part of the texts. Then you need to declare every new natives you use in your map. This is one example:
    Code:
    ......
    
    native NetworkConnect     takes string host, integer port returns nothing
    native IsNetworkConnected takes nothing returns boolean
    native NetworkUserCount   takes nothing returns integer
    native NetworkPing        takes nothing returns real
    native NetworkSyncUnit    takes unit u returns nothing*/
    
    native GetMouseX                    takes nothing returns real
    native GetMouseY                    takes nothing returns real
    native GetMouseTerrainX             takes nothing returns real
    native GetMouseTerrainY             takes nothing returns real
    native GetMouseUIX                  takes nothing returns real
    native GetMouseUIY                  takes nothing returns real
    native GetTriggerKey                takes nothing returns integer
    native GetTriggerWheelDelta         takes nothing returns integer
    native GetTriggerKeyString          takes nothing returns string
    native IsMouseOverUI                takes nothing returns boolean
    native IsKeyDown                    takes integer vkey returns boolean
    native TriggerRegisterAnyKeyEvent   takes trigger whichTrigger, integer state returns nothing
    native TriggerRegisterAnyMouseEvent takes trigger whichTrigger, integer state returns nothing
    native TriggerRegisterKeyEvent      takes trigger whichTrigger, integer vkey, integer state 
    
    returns nothing
    native TriggerRegisterMouseEvent    takes trigger whichTrigger, integer vkey, integer state 
    
    returns nothing
    native TriggerRegisterMouseWheelEvent takes trigger whichTrigger returns nothing
    
    native StopWatchCreate  takes nothing returns integer
    native StopWatchTicks   takes integer id returns integer
    native StopWatchMark    takes integer id returns integer
    native StopWatchDestroy takes integer id returns nothing
    
    native StringReplace takes string str, string old, string new returns string
    native StringReverse takes string str returns string
    native StringSplit   takes string str, string sub, integer index returns string
  4. Now that you have it modified, close the notepad and go to your Wacraft 3 directory. Create a folder named "Scripts" and move the modified common.j to that folder.
  5. (Untested) You need to do all these steps to all of PCs that want to play in the room that uses sharpcraft. I don't know does the server need to do these as well or not.
  6. It's done. But if you still can't enter the room, retry to enter it twice or so and it's going to work.
4. Known Bugs
Problem: Compile error when saving maps.
Solution: Rename the "Script" folder into something else. You just need to revert the name back to "Script" when you want to play a multiplayer map again using sharpcraft.​
5. Closing
Hope this can be helpful. I also attached the example of modified common.j below. If you spot any mistake above, please report it in this thread. Thanks!​
 

Attachments

  • common.j.zip
    16.5 KB · Views: 111
Last edited:
Level 6
Joined
Jan 4, 2014
Messages
227
Thanks for the tutorial :)

if you dont use Local Files, you cant import the modified common.j in your map and use custom path : Scripts/Common.j (113 Kb).
 
Level 6
Joined
Jan 4, 2014
Messages
227
i fixed the compile error : you must use the lastest common.j wich is found in Patch.mpq, and then add the natives there. you dont need to rename the folder.

but bro i have a question ... how do you get triggering player when triggering SharpCraft events ?!
 

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
i fixed the compile error : you must use the lastest common.j wich is found in Patch.mpq, and then add the natives there. you dont need to rename the folder.

but bro i have a question ... how do you get triggering player when triggering SharpCraft events ?!

Adding the natives to common.j won't have this issue indeed, but the tutorial is to do so without touching the common.j file.

but bro i have a question ... how do you get triggering player when triggering SharpCraft events ?!
GetLocalPlayer()
 
Level 6
Joined
Jan 4, 2014
Messages
227
1 - Go to Patch.mpq extract common.j from there, open common.j add the SharpCraft natives at the end, save the file and put it in warcraft3Directory/Scripts/common.j, this works perfect for me as long as local files are enabled.

2 - Can you pleas send me an exemple JASS script ?
 
Level 12
Joined
Mar 13, 2012
Messages
1,121
1. So does importing an altered common.j into the map work or not?

2. This is something like a lesser WarCom, right? But how does it work? Didn't the newest version of Sharpcraft revert to only plugin functionality, i.e. not having those natives? Where do they come from?
 
Level 6
Joined
Jan 4, 2014
Messages
227
1. As soon as i get a second computer at hand i will test it.

2. Its a lesser WarCom only if WarCom is released, but TriggerHappy did not come to the Hive for 7 months ...

2. "newest version of Sharpcraft revert to only plugin functionality" seems true from what i have read months ago, but when we tried SharpCraft 2.xx and 3.xx it did not work in any way, so we got back to SharpCraft 1.4 but it was not able to save maps correctly, and now we use SharpCraft 1.3
 

Kazeon

Hosted Project: EC
Level 33
Joined
Oct 12, 2011
Messages
3,449
1. So does importing an altered common.j into the map work or not?

2. This is something like a lesser WarCom, right? But how does it work? Didn't the newest version of Sharpcraft revert to only plugin functionality, i.e. not having those natives? Where do they come from?

1. Theoritically it doesn't work. The engine doesn't read other scripts available in your map other than war3map.j, I think. I'm not the one who understand how wc3 engine works, those are just speculations. Better to run a test about it.

2. WarCom is a plug in for Sharpcraft as far as I know. I'm not sure about the recent updates, but previously Sharpcraft allows you to create your own native functions. And if you ask where do they come from? I got them from here, they are made by TriggerHappy. Those scripts were called "plugin" as well, I don't know whether the newest version of Sharpcraft still support this custom script functionality or not.
 
Top