[Release] Xiyue MapEditor - Akaras' mod updated by M2P

bansheemir.com

mir2pion

TL;DR
Dedicated Member
Feb 21, 2013
2,442
217
104
That data type would have to be something that would single out, be unique for the smTiles category and only ShandaMir2 at that.

The layer swap works for all other tiles, even the Tiles (bigTiles -> 4x4 smTiles from ShandaMir2) which normally you wouldn't place on front or middle layers but you can and the layer swapping works on them too if you do so. Somehow these particular tags are immune to being overwritten with new layer information.
 
Last edited:
MirWall Mir2 Server

Far

tsniffer
Developer
May 19, 2003
19,608
22
2,009
400
Shanda use have image heavy files, so will likely exceed ushort limit. Others like wemade probably don't, so you'll only see it on shanda if that's the case.
 

mir2pion

TL;DR
Dedicated Member
Feb 21, 2013
2,442
217
104
I noticed Akaras made appearance here last week, this would be something for him to chew on :D
It is not a big thing, just inconvenience if you run into it.

================================================================

I checked the layer swapping code and noticed SmTiles term does figure in it and likely that is where the glitch that prevents layer swapping is going to be.
I didn't write the code, just 'repurposed it' from other sections.

This line: if (!(str.IndexOf("SmTiles", StringComparison.Ordinal) > -1))

As much as I learned to read code, this line is not clear to me what it does.
The re-used code was taken from the 'swapping layers process' from Mir3 Layer Inversion, the "Save Invert Mir3 Layer"


C#:
        private void menu_InvertMiddleFrontLayersToggle_Click(object sender, EventArgs e)    //M2P
        {
            if (M2CellInfo != null)
            {
                //this should swap the points if point 2 is not a higher value
                if (p1.X > p2.X)
                {
                    p1.X += p2.X;
                    p2.X = p1.X - p2.X - 1;
                    p1.X -= p2.X;
                }

                if (p1.Y > p2.Y)
                {
                    p1.Y += p2.Y;
                    p2.Y = p1.Y - p2.Y - 1;
                    p1.Y -= p2.Y;
                }

                for (var x = p1.X; x <= p2.X; x++)
                {
                    for (var y = p1.Y; y <= p2.Y; y++)
                    {
                        string str;
                        if ((M2CellInfo[x, y].MiddleImage != 0) && ((M2CellInfo[x, y].FrontImage & 0x7FFF) == 0)) //M2P - Invert Middle to Front if Only MiddleImage Exists
                        {
                            str = GetLibName(M2CellInfo[x, y].MiddleIndex);
                            if (!(str.IndexOf("SmTiles", StringComparison.Ordinal) > -1))
                            {
                                if ((M2CellInfo[x, y].MiddleAnimationFrame != 0) &&
                                    (M2CellInfo[x, y].MiddleAnimationFrame != 255) &&
                                    (M2CellInfo[x, y].FrontAnimationFrame == 0))
                                {
                                    M2CellInfo[x, y].FrontAnimationFrame =
                                        (byte)(M2CellInfo[x, y].MiddleAnimationFrame & 0x0F);
                                    M2CellInfo[x, y].FrontAnimationTick = M2CellInfo[x, y].MiddleAnimationTick;
                                    M2CellInfo[x, y].MiddleAnimationFrame = 0;
                                    M2CellInfo[x, y].MiddleAnimationTick = 0;
                                }
                                M2CellInfo[x, y].FrontImage = M2CellInfo[x, y].MiddleImage;
                                M2CellInfo[x, y].FrontIndex = M2CellInfo[x, y].MiddleIndex;
                                M2CellInfo[x, y].MiddleImage = 0;
                                M2CellInfo[x, y].MiddleIndex = 0;
                            }
                        }
                        else if ((M2CellInfo[x, y].FrontImage != 0) && ((M2CellInfo[x, y].MiddleImage & 0x7FFF) == 0)) //M2P - Invert Front to Middle if Only Front Exists
                        {
                            str = GetLibName(M2CellInfo[x, y].FrontIndex);
                            if (!(str.IndexOf("SmTiles", StringComparison.Ordinal) > -1))
                            {
                                if ((M2CellInfo[x, y].FrontAnimationFrame != 0) &&
                                    (M2CellInfo[x, y].FrontAnimationFrame != 255) &&
                                    (M2CellInfo[x, y].MiddleAnimationFrame == 0))
                                {
                                    M2CellInfo[x, y].MiddleAnimationFrame =
                                        (byte)(M2CellInfo[x, y].FrontAnimationFrame & 0x0F);
                                    M2CellInfo[x, y].MiddleAnimationTick = M2CellInfo[x, y].FrontAnimationTick;
                                    M2CellInfo[x, y].FrontAnimationFrame = 0;
                                    M2CellInfo[x, y].FrontAnimationTick = 0;
                                }
                                M2CellInfo[x, y].MiddleImage = M2CellInfo[x, y].FrontImage;
                                M2CellInfo[x, y].MiddleIndex = M2CellInfo[x, y].FrontIndex;
                                M2CellInfo[x, y].FrontImage = 0;
                                M2CellInfo[x, y].FrontIndex = 0;
                            }
                        }
                        else if ((M2CellInfo[x, y].MiddleImage != 0) && ((M2CellInfo[x, y].FrontImage & 0x7FFF) != 0)) //M2P - Invert (Swap) Layers if Both FrontImage & MiddleImage Exist [Toggle]
                        {
                            str = GetLibName(M2CellInfo[x, y].MiddleIndex);
                            if (!(str.IndexOf("SmTiles", StringComparison.Ordinal) > -1))
                            {
                                if ((M2CellInfo[x, y].MiddleAnimationFrame == 255) ||
                                    (M2CellInfo[x, y].MiddleAnimationFrame == 0))
                                {
                                    if (M2CellInfo[x, y].FrontAnimationFrame == 0)
                                    {
                                        var temp = M2CellInfo[x, y].MiddleImage;
                                        M2CellInfo[x, y].MiddleImage =
                                            (short)(M2CellInfo[x, y].FrontImage & 0x7FFF);
                                        M2CellInfo[x, y].FrontImage = temp;
                                        temp = M2CellInfo[x, y].MiddleIndex;
                                        M2CellInfo[x, y].MiddleIndex = M2CellInfo[x, y].FrontIndex;
                                        M2CellInfo[x, y].FrontIndex = temp;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

WemadeM2 uses 'Smtiles' (lower case 't') while ShandaM2 libraries are SmTiles (capital 'T'). That means in the above code, the line

if (!(str.IndexOf("SmTiles", StringComparison.Ordinal) > -1))

'somehow' excludes the tiles that are from the library spelled SmTiles from having their tags re-written (which are the ShandaM2 libraries).

Now I could change SmTiles to Smtiles and then I suppose ShandaM2 SmTiles would allow layer swap and WemadeM2 Smtiles would be excluded from the swap.
Could I just remove that line or maybe it needs changing?
 
Last edited:

Far

tsniffer
Developer
May 19, 2003
19,608
22
2,009
400
Don't just remove random lines . It's probably there because smtiles should only be on the middle layer, but there's a bug with the casing so It doesn't work on all smtiles.

That line btw is just saying if the naming doesn't contain smtiles then do the code, otherwise ignore.

Ideally the check should use an ignore case.

I can't think off my head why smtiles would be compatible for middle layer only, but I expect there's a valid reason that code was added.
 
  • Like
Reactions: Jev

mir2pion

TL;DR
Dedicated Member
Feb 21, 2013
2,442
217
104
They (mir3) didn't want us (mir2) to have the goodies they have :p

After working on the code and with maps for some time, I became convinced that

a) Front & Middle layers are just copies (in code) of one another and only difference is in these two 'names'.

b) The functionality of these two layers is fully identical in Map Editor when working with maps. It is only mir2 client which is not included to use the middle layer to its full functionality (image strips on middle layer) which is done by a simple 'exclusion' in the client code. Actually not exclusion, just not inclusion.

There might have been a reason for it deep in the past, probably going back to when mir3 was split off mir2. For whatever reason they got the idea to build all mir3 maps primarily on middle layer and only use front one when tags would collide. Mir2 has maps built primarily on the other layer and uses the middle one only for basic tiles (48x32) to avoid collision with front layer object tags.

Mir2 client as I tested it, has the same capability on both layers to display 'tall' image strips that make up objects, except that for some reason that capability for middle layer is not 'unlocked'. Likely there was a historic reason at the time having to do with a need to make mir3 maps not compatible with mir2 or something like that and I can't see any technical reason for it. That need to make things different could simply be to prevent hackers use of mir3 maps on mir2. But now Crystal Client loads them anyway.

Another way to look at it - we can place tiles from SmTiles folders on either of the two layers but they can't be swapped btw the two layers. But Object libraries also contain many basic 48x32 pixels SmTiles (beside the strips of them) and those can be swapped btw layers and only thing different here is that the library has different name (Object vs SmTiles lib). Why then the same tiles shouldn't be able to be swapped between layers the same way it the only difference here is that they come from differently named libraries (SmTiles.Lib). There can be no technical reason for the exclusion of SmTiles from being placed on either layer and allow swapping between them.

Now I know coming from me, you'd be sceptic. It is time to fix client now that we can swap layers freely in the editor. I will send you mir2 client pull request with the fix for 'middle layer tile strips draw' tonight and you can judge for yourself. I have already tested it in the client.
 
Last edited:
  • Like
Reactions: FantasticTroll

mir2pion

TL;DR
Dedicated Member
Feb 21, 2013
2,442
217
104
Well, for one, you didn't need to quote my post. Second, this has nothing to do with this thread. This is meant for map editor release and related posts.

Third, I don't know anything about Zircon, atmospheric lighting on maps also is a matter for clients, not map editors. I only touched on client here to port into it changes that map editor needs to be there (for it to use middle layer with full functionality).

Why don't you move your post into Zircon section you might get answers there. Copy, delete here and paste into new post there. I might answer there with maybe a related finding I had when working with maps.
 

Jev

When I'm Gone
Staff member
Moderator
Jul 21, 2020
1,273
7
474
105
Worthing, West Sussex
Well, for one, you didn't need to quote my post. Second, this has nothing to do with this thread. This is meant for map editor release and related posts.

Third, I don't know anything about Zircon, atmospheric lighting on maps also is a matter for clients, not map editors. I only touched on client here to port into it changes that map editor needs to be there (for it to use middle layer with full functionality).

Why don't you move your post into Zircon section you might get answers there. Copy, delete here and paste into new post there. I might answer there with maybe a related finding I had when working with maps.
Post moved to Mir 3 Help Section
 
  • Like
Reactions: mir2pion