Skip to content

Commit

Permalink
Fixed mission code offsets info in error messages. (#130)
Browse files Browse the repository at this point in the history
* Fixed mission code offsets info in error messages.

* fixup! Fixed mission code offsets info in error messages.
  • Loading branch information
MiranDMC authored Apr 26, 2024
1 parent fce8a8f commit 42dcc5f
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CLEO5.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\CTheScripts.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="cleo_sdk\CLEO.h" />
Expand Down
3 changes: 3 additions & 0 deletions CLEO5.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@
<ClCompile Include="source\OpcodeInfoDatabase.cpp">
<Filter>source\utils</Filter>
</ClCompile>
<ClCompile Include="$(PLUGIN_SDK_DIR)\plugin_sa\game_sa\CTheScripts.cpp">
<Filter>plugin_sdk</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="source\stdafx.h">
Expand Down
9 changes: 9 additions & 0 deletions source/CCustomOpcodeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace CLEO


OpcodeResult __stdcall opcode_0051(CRunningScript * thread); // GOSUB return
OpcodeResult __stdcall opcode_0417(CRunningScript* thread); // load_and_launch_mission_internal

OpcodeResult __stdcall opcode_0A92(CRunningScript* thread); // stream_custom_script
OpcodeResult __stdcall opcode_0A93(CRunningScript* thread); // terminate_this_custom_script
Expand Down Expand Up @@ -219,6 +220,7 @@ namespace CLEO
TRACE("Initializing CLEO core opcodes...");

CLEO_RegisterOpcode(0x0051, opcode_0051);
CLEO_RegisterOpcode(0x0417, opcode_0417);
CLEO_RegisterOpcode(0x0A92, opcode_0A92);
CLEO_RegisterOpcode(0x0A93, opcode_0A93);
CLEO_RegisterOpcode(0x0A94, opcode_0A94);
Expand Down Expand Up @@ -842,6 +844,13 @@ namespace CLEO
return originalOpcodeHandlers[tableIdx](thread, 0x0051); // call game's original
}

OpcodeResult __stdcall CCustomOpcodeSystem::opcode_0417(CRunningScript* thread) // load_and_launch_mission_internal
{
MissionIndex = CLEO_PeekIntOpcodeParam(thread);
size_t tableIdx = 0x0417 / 100; // 100 opcodes peer handler table
return originalOpcodeHandlers[tableIdx](thread, 0x0417); // call game's original
}

//0A92=-1,create_custom_thread %1d%
OpcodeResult __stdcall opcode_0A92(CRunningScript *thread)
{
Expand Down
1 change: 1 addition & 0 deletions source/CCustomOpcodeSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace CLEO
static OpcodeResult CleoReturnGeneric(WORD opcode, CRunningScript* thread, bool returnArgs = false, DWORD returnArgCount = 0, bool strictArgCount = true);

static OpcodeResult __stdcall opcode_0051(CRunningScript* thread); // GOSUB's return
static OpcodeResult __stdcall opcode_0417(CRunningScript* thread); // load_and_launch_mission_internal

private:
typedef OpcodeResult(__thiscall* _OpcodeHandler)(CRunningScript* thread, WORD opcode);
Expand Down
28 changes: 23 additions & 5 deletions source/CScriptEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "CleoBase.h"
#include "CFileMgr.h"
#include "CGame.h"
#include <CTheScripts.h>

#include <sstream>

Expand Down Expand Up @@ -298,6 +299,7 @@ namespace CLEO
BYTE *scmBlock;
BYTE *MissionLoaded;
BYTE *missionBlock;
int MissionIndex;
BOOL *onMissionFlag;
CTexture *scriptSprites;
BYTE *scriptDraws;
Expand Down Expand Up @@ -783,12 +785,27 @@ namespace CLEO
}
else
{
auto address = (DWORD)BaseIP;
if (address == 0) address = GetInstance().VersionManager.TranslateMemoryAddress(MA_SCM_BLOCK);
//address = (DWORD)CurrentIP - address; // processed position
address = (DWORD)CCustomOpcodeSystem::lastOpcodePtr - address; // opcode position
auto base = (DWORD)BaseIP;
if (base == 0) base = (DWORD)scmBlock;
auto currPos = (DWORD)CCustomOpcodeSystem::lastOpcodePtr;

ss << "offset {" << address << "}"; // Sanny offsets style
if (IsMission() && !IsCustom())
{
if (currPos >= (DWORD)missionBlock)
{
// we are in mission code buffer
// native missions are loaded from script file into mission block area
currPos += ((DWORD*)CTheScripts::MultiScriptArray)[MissionIndex]; // start offset of this mission within source script file
}
else
{
base = (DWORD)scmBlock; // seems that mission uses main scm code
}
}

auto offset = currPos - base;

ss << "offset {" << offset << "}"; // Sanny offsets style
ss << " - ";
ss << std::hex << std::uppercase << std::setw(4) << std::setfill('0') << CCustomOpcodeSystem::lastOpcode;

Expand Down Expand Up @@ -1524,6 +1541,7 @@ namespace CLEO
if (*MissionLoaded)
throw std::logic_error("Starting of custom mission when other mission loaded");
*MissionLoaded = 1;
MissionIndex = -1;
BaseIP = CurrentIP = missionBlock;
}
else {
Expand Down
1 change: 1 addition & 0 deletions source/CScriptEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ namespace CLEO
}

extern BYTE *scmBlock, *missionBlock;
extern int MissionIndex;

extern float VectorSqrMagnitude(CVector vector);
}
Expand Down

0 comments on commit 42dcc5f

Please sign in to comment.