Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moradon Warp fix #206

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Moradon Warp fix #206

wants to merge 3 commits into from

Conversation

UTengine
Copy link
Contributor

Description

This is a draft pull request to review before PR/merging.
This fixes warpgates and warpentries and needs to be dealt with asap so I can publish loading of newer FX and zones.
I need every commit to be classed pristine reviewed and good to go, please give me a green light to continue.
I can make the client load tbl entries for warp and we can modify the server to only exchange object ID and warp entries without strings in a later stage, but for now I want this to be accessable to everyone to accelerate and have it simplified.
image

💔Thank you!

This fixes the warp from anywhere to Moradon, as long as there is no war going on.
This fixes Warpgate's from newer maps like Moradon Delos and various other ones.
This fixes newer maps, they have an extra "column" so when we add this to the struct size all warp entries are loaded perfectly.
@UTengine UTengine marked this pull request as ready for review July 26, 2023 08:14
Copy link
Contributor

@srmeier srmeier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few questions to better understand what you are trying to achieve

@@ -4173,7 +4173,7 @@ bool CGameProcMain::MsgSend_NPCEvent(short siIDTarget) {
int iOffset = 0;

CAPISocket::MP_AddByte(byBuff, iOffset, N3_WARP_LIST);
CAPISocket::MP_AddByte(byBuff, iOffset, WI.iID); // ���� ���̵� ������...
CAPISocket::MP_AddShort(byBuff, iOffset, WI.iID); // ���� ���̵� ������...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why which from byte to short here?

Copy link
Contributor Author

@UTengine UTengine Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -543,6 +543,7 @@ struct _WARP_INFO {
float fY;
float fZ;
float fR;
short sNation;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add this if it isn't being used anywhere?

Copy link
Contributor Author

@UTengine UTengine Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because without it loading any map will give screwed up warps.
Unless you want to stick with the oldest available maps elmorad and karus zone, they do work out of the box.
But before Moradon and KE was introduced this was added, it's a matter of preference I can either go with map.cpp load warplist readfile and do a skip size of short. Or we can just adjust the size of warp struct to fit newer SMD's.
See screenshot I included in the opening post. I remember twostars saying that the SMD's were horribly wrong/damaged/corrupted. Not even hinting out or sharing what was actually wrong.
Nobody ever took this much time as I dissected SMD's with hex editor.
I will publish the smd files along with this code once I'm done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to diagnose your own files, you can use my provided sample code this goes straight into map.cpp ebenezer:
Now you can export all warps to a text file, adjust struct of warpinfo with a snation and try without it, if you got mixed smd files you will see mixed results some zones proper warps and some with invalid numbers because of the missing short.

void C3DMap::LoadWarpList(HANDLE hFile) {
int WarpCount = 0;
DWORD dwNum;
_WARP_INFO * pWarp = NULL;

ReadFile(hFile, &WarpCount, 4, &dwNum, NULL);

for (int i = 0; i < WarpCount; i++) {
    pWarp = new _WARP_INFO;

    ReadFile(hFile, pWarp, sizeof(_WARP_INFO), &dwNum, NULL);

    if (!m_WarpArray.PutData(pWarp->sWarpID, pWarp)) {
        TRACE("Warp list PutData Fail - %d\n", pWarp->sWarpID);
        delete pWarp;
        pWarp = NULL;
    }
    UpdateWarpInfo(pWarp);
}

}

struct Warp {
short sWarpID;
char strWarpName[32];
char strAnnounce[256];
DWORD dwPay;
short sZone;
float fX;
float fY;
float fZ;
float fR;
short sNation;
};

void C3DMap::UpdateWarpInfo(_WARP_INFO * pWarp) {
if (!pWarp) {
return;
}
CStdioFile file;
CString line;
CArray lines;

if (file.Open(_T("warpinfo.txt"), CFile::modeReadWrite | CFile::typeText)) {
    while (file.ReadString(line)) {
        line.TrimRight(); // Remove trailing whitespace
        if (line.IsEmpty()) {
            continue; // Skip empty lines
        }

        Warp    warp;
        CString remaining;
        if (sscanf_s(line, "%hd\t%31[^\t]\t%255[^\t]\t%d\t%hd\t%f\t%f\t%f\t%f\t%d", &warp.sWarpID, warp.strWarpName,
                     32, warp.strAnnounce, 256, &warp.dwPay, &warp.sZone, &warp.fX, &warp.fY, &warp.fZ, &warp.fR,
                     &warp.sNation) == 10) {
            if (warp.sWarpID == pWarp->sWarpID) {
                // Load the data from the file
                strncpy_s(pWarp->strWarpName, warp.strWarpName, sizeof(pWarp->strWarpName));
                strncpy_s(pWarp->strAnnounce, warp.strAnnounce, sizeof(pWarp->strAnnounce));
                pWarp->dwPay = warp.dwPay;
                pWarp->sZone = warp.sZone;
                pWarp->fX = warp.fX;
                pWarp->fY = warp.fY;
                pWarp->fZ = warp.fZ;
                pWarp->fR = warp.fR;
                pWarp->sNation = warp.sNation;

                file.Close();
                return; // Found matching "warpid" in the file, loaded the data
            }
        }
        lines.Add(line); // Store the current line for rewriting
    }

    // Matching "warpid" not found, insert a new line with the provided pWarp data
    CString newLine;
    newLine.Format(_T("%hd\t%s\t%s\t%d\t%hd\t%f\t%f\t%f\t%f\t%d"), pWarp->sWarpID, pWarp->strWarpName,
                   pWarp->strAnnounce, pWarp->dwPay, pWarp->sZone, pWarp->fX, pWarp->fY, pWarp->fZ, pWarp->fR,
                   pWarp->sNation);
    lines.Add(newLine);

    // Rewrite the file with the updated lines
    file.SeekToBegin();
    file.SetLength(0); // Clear the file
    for (int i = 0; i < lines.GetSize(); i++) {
        file.WriteString(lines[i]);
        file.WriteString(_T("\n")); // Add a new line character
    }

    file.Close();
} else {
    // File does not exist, create it and insert the pWarp data
    if (file.Open(_T("warpinfo.txt"), CFile::modeCreate | CFile::modeWrite | CFile::typeText)) {
        CString newLine;
        newLine.Format(_T("%hd\t%s\t%s\t%d\t%hd\t%f\t%f\t%f\t%f\t%d"), pWarp->sWarpID, pWarp->strWarpName,
                       pWarp->strAnnounce, pWarp->dwPay, pWarp->sZone, pWarp->fX, pWarp->fY, pWarp->fZ, pWarp->fR,
                       pWarp->sNation);
        file.WriteString(newLine);
        file.WriteString(_T("\n")); // Add a new line character

        file.Close();
    } else {
        AfxMessageBox(_T("Failed to create warpinfo.txt file."));
    }
}

}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to add some context and another perspective, some gate objects are nation 0 which means for both, but that doesn't mean you will get Karus and Elmorad warp entries from the same object, that differs if you are invading Karus you are not allowed to teleport to Karus entries but you are allowed to use the object to warp back. (hypothesis) I'm not even going to confirm my suspicion or hypothesis, sooner or later this will have to be done and for now it saves me a lot of work. And if we go to KE SMD's they will have the extra short anyway >.>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine this would prevent our current maps from working, right? Could we update our old maps first by adding a short in the right place? This way we can still load our updated older maps.

Copy link
Contributor Author

@UTengine UTengine Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am already in the process doing that I just need green light and approval then I will upload them and hopefully merge.
<3

Copy link
Contributor Author

@UTengine UTengine Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine this would prevent our current maps from working, right? Could we update our old maps first by adding a short in the right place? This way we can still load our updated older maps.
image

Tested and they work fine so far.
We will need to add event zones for eslant tiles dbo.event is empty.
Also we need to adjust client zones.tbl and zones directory, the 1097 Colony Zone is just way too outdated......
Let's do the rest in different commits okay? (Loading 1264 maps (int version, int stringlength, readsizeofchar + add null termination to terrain loading and opd loading).
I don't want to clutter this Draft too much..

DB table zone_info:

12elmorad_1212.smd              163700418003850010
11karus_1212.smd                371201573003850010
1101battle_0810.smd               23700140003850030
1102battle_0810.smd               23700140003850030
1201freezone_1217.smd             10001000020
121moradon_1021.smd              3120040200010
111k_eslant.smd                  15000150001500000
112e_eslant.smd                  15000150001500000
130siege_1110.smd                10001000020
132abyssb_0925.smd               10001000020

servermaps.zip
servermapsv2.zip (Added Moradon to Piana warplist and adjusted Moradon to Piana warp around the object instead of the castle wall)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @srmeier here.

@stevewgr stevewgr marked this pull request as draft April 30, 2024 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants