Merge pull request #336 from Nick007J/master

script utilities 1
This commit is contained in:
Nikolay Korolev 2020-03-01 23:48:48 +03:00 committed by GitHub
commit f72453d03e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 1728 additions and 339 deletions

View File

@ -106,18 +106,18 @@ void COnscreenTimerEntry::Process() {
return;
}
uint32* timerPtr = (uint32*)&CTheScripts::ScriptSpace[m_nTimerOffset];
uint32 oldTime = *timerPtr;
int32 newTime = int32(oldTime - uint32(20.0f * CTimer::GetTimeStep()));
int32* timerPtr = CTheScripts::GetPointerToScriptVariable(m_nTimerOffset);
int32 oldTime = *timerPtr;
int32 newTime = oldTime - int32(CTimer::GetTimeStepInSeconds() * 1000);
if(newTime < 0) {
*timerPtr = 0;
m_bTimerProcessed = 0;
m_nTimerOffset = 0;
m_aTimerText[0] = 0;
} else {
*timerPtr = (uint32)newTime;
uint32 oldTimeSeconds = oldTime / 1000;
if(oldTimeSeconds <= 11 && newTime / 1000 != oldTimeSeconds) {
*timerPtr = newTime;
int32 oldTimeSeconds = oldTime / 1000;
if(oldTimeSeconds < 12 && newTime / 1000 != oldTimeSeconds) {
DMAudio.PlayFrontEndSound(SOUND_CLOCK_TICK, newTime / 1000);
}
}
@ -144,13 +144,13 @@ bool COnscreenTimerEntry::ProcessForDisplay() {
}
void COnscreenTimerEntry::ProcessForDisplayClock() {
uint32 time = *(uint32*)&CTheScripts::ScriptSpace[m_nTimerOffset];
uint32 time = *CTheScripts::GetPointerToScriptVariable(m_nTimerOffset);
sprintf(m_bTimerBuffer, "%02d:%02d", time / 1000 / 60,
time / 1000 % 60);
}
void COnscreenTimerEntry::ProcessForDisplayCounter() {
uint32 counter = *(uint32*)&CTheScripts::ScriptSpace[m_nCounterOffset];
uint32 counter = *CTheScripts::GetPointerToScriptVariable(m_nCounterOffset);
sprintf(m_bCounterBuffer, "%d", counter);
}

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,8 @@ class CPed;
class CObject;
class CPlayerInfo;
class CRunningScript;
#define KEY_LENGTH_IN_SCRIPT 8
struct CScriptRectangle
@ -48,7 +50,26 @@ struct CTextLine
float m_fAtY;
wchar m_Text[SCRIPT_TEXT_MAX_LENGTH];
void Reset();
void Reset()
{
m_fScaleX = 0.48f;
m_fScaleY = 1.12f;
m_sColor = CRGBA(225, 225, 225, 255);
m_bJustify = false;
m_bRightJustify = false;
m_bCentered = false;
m_bBackground = false;
m_bBackgroundOnly = false;
m_fWrapX = 182.0f; /* TODO: scaling as bugfix */
m_fCenterSize = 640.0f; /* --||-- */
m_sBackgroundColor = CRGBA(128, 128, 128, 128);
m_bTextProportional = true;
m_bTextBeforeFade = false;
m_nFont = 2; /* enum? */
m_fAtX = 0.0f;
m_fAtY = 0.0f;
memset(&m_Text, 0, sizeof(m_Text));
}
};
static_assert(sizeof(CTextLine) == 0x414, "Script.h: error");
@ -62,121 +83,12 @@ struct CScriptSphere
float m_fRadius;
};
enum {
MAX_STACK_DEPTH = 6,
NUM_LOCAL_VARS = 16,
NUM_TIMERS = 2
};
class CRunningScript
struct CStoredLine
{
CRunningScript *next;
CRunningScript *prev;
char m_abScriptName[8];
uint32 m_nIp;
uint32 m_anStack[MAX_STACK_DEPTH];
uint16 m_nStackPointer;
int32 m_anLocalVariables[NUM_LOCAL_VARS + NUM_TIMERS];
bool m_bCondResult;
bool m_bIsMissionScript;
bool m_bSkipWakeTime;
uint32 m_nWakeTime;
uint16 m_nAndOrState;
bool m_bNotFlag;
bool m_bDeatharrestEnabled;
bool m_bDeatharrestExecuted;
bool m_bMissionFlag;
public:
void SetIP(uint32 ip) { m_nIp = ip; }
CRunningScript* GetNext() { return next; }
void UpdateTimers(float timeStep){
m_anLocalVariables[NUM_LOCAL_VARS] += timeStep;
m_anLocalVariables[NUM_LOCAL_VARS + 1] += timeStep;
}
bool ThisIsAValidRandomPed(uint32 pedtype){
switch (pedtype){
case PEDTYPE_CIVMALE:
case PEDTYPE_CIVFEMALE:
case PEDTYPE_GANG1:
case PEDTYPE_GANG2:
case PEDTYPE_GANG3:
case PEDTYPE_GANG4:
case PEDTYPE_GANG5:
case PEDTYPE_GANG6:
case PEDTYPE_GANG7:
case PEDTYPE_GANG8:
case PEDTYPE_GANG9:
case PEDTYPE_CRIMINAL:
case PEDTYPE_PROSTITUTE:
return true;
default:
return false;
}
}
float LimitAngleOnCircle(float angle) { return angle < 0.0f ? angle + 360.0f : angle; }
void CollectParameters(uint32*, int16);
int32 CollectNextParameterWithoutIncreasingPC(uint32);
int32* GetPointerToScriptVariable(uint32*, int16);
void StoreParameters(uint32*, int16);
void Init();
void RemoveScriptFromList(CRunningScript**);
void AddScriptToList(CRunningScript**);
void Process();
int8 ProcessOneCommand();
void DoDeatharrestCheck();
int8 ProcessCommands0To99(int32);
int8 ProcessCommands100To199(int32);
int8 ProcessCommands200To299(int32);
int8 ProcessCommands300To399(int32);
int8 ProcessCommands400To499(int32);
int8 ProcessCommands500To599(int32);
int8 ProcessCommands600To699(int32);
int8 ProcessCommands700To799(int32);
int8 ProcessCommands800To899(int32);
int8 ProcessCommands900To999(int32);
int8 ProcessCommands1000To1099(int32);
#ifndef GTA_PS2
int8 ProcessCommands1100To1199(int32);
#endif
void UpdateCompareFlag(bool);
int16 GetPadState(uint16, uint16);
void LocatePlayerCommand(int32, uint32*);
void LocatePlayerCharCommand(int32, uint32*);
void LocatePlayerCarCommand(int32, uint32*);
void LocateCharCommand(int32, uint32*);
void LocateCharCharCommand(int32, uint32*);
void LocateCharCarCommand(int32, uint32*);
void LocateCharObjectCommand(int32, uint32*);
void LocateCarCommand(int32, uint32*);
void LocateSniperBulletCommand(int32, uint32*);
void PlayerInAreaCheckCommand(int32, uint32*);
void PlayerInAngledAreaCheckCommand(int32, uint32*);
void CharInAreaCheckCommand(int32, uint32*);
void CarInAreaCheckCommand(int32, uint32*);
private:
enum {
ANDOR_NONE = 0,
ANDS_1 = 1,
ANDS_2,
ANDS_3,
ANDS_4,
ANDS_5,
ANDS_6,
ANDS_7,
ANDS_8,
ORS_1 = 21,
ORS_2,
ORS_3,
ORS_4,
ORS_5,
ORS_6,
ORS_7,
ORS_8
};
CVector vecInf;
CVector vecSup;
uint32 color1;
uint32 color2;
};
enum {
@ -313,12 +225,12 @@ enum {
MAX_NUM_USED_OBJECTS = 200,
MAX_NUM_MISSION_SCRIPTS = 120,
MAX_NUM_BUILDING_SWAPS = 25,
MAX_NUM_INVISIBILITY_SETTINGS = 20
MAX_NUM_INVISIBILITY_SETTINGS = 20,
MAX_NUM_STORED_LINES = 1024
};
class CTheScripts
{
public:
static uint8(&ScriptSpace)[SIZE_SCRIPT_SPACE];
static CRunningScript(&ScriptsArray)[MAX_NUM_SCRIPTS];
static int32(&BaseBriefIdForContact)[MAX_NUM_CONTACTS];
@ -332,6 +244,7 @@ public:
static int32(&MultiScriptArray)[MAX_NUM_MISSION_SCRIPTS];
static tBuildingSwap(&BuildingSwapArray)[MAX_NUM_BUILDING_SWAPS];
static CEntity*(&InvisibilitySettingArray)[MAX_NUM_INVISIBILITY_SETTINGS];
static CStoredLine(&aStoredLines)[MAX_NUM_STORED_LINES];
static bool &DbgFlag;
static uint32 &OnAMissionFlag;
static CMissionCleanup &MissionCleanup;
@ -355,19 +268,75 @@ public:
static uint16 &NumScriptDebugLines;
static uint16 &NumberOfIntroRectanglesThisFrame;
static uint16 &NumberOfIntroTextLinesThisFrame;
static bool &UseTextCommands;
static uint8 &UseTextCommands;
static uint16 &CommandsExecuted;
static uint16 &ScriptsUpdated;
public:
static void ScriptDebugLine3D(float x1, float y1, float z1, float x2, float y2, float z2, int col, int col2);
static void Init();
static void Process();
static CRunningScript* StartTestScript();
static bool IsPlayerOnAMission();
static void ClearSpaceForMissionEntity(const CVector&, CEntity*);
static void UndoBuildingSwaps();
static void UndoEntityVisibilitySettings();
static void ScriptDebugLine3D(float x1, float y1, float z1, float x2, float y2, float z2, uint32 col, uint32 col2);
static void RenderTheScriptDebugLines();
static void SaveAllScripts(uint8*, uint32*);
static void LoadAllScripts(uint8*, uint32);
static bool IsDebugOn() { return DbgFlag; };
static void InvertDebugFlag() { DbgFlag = !DbgFlag; }
static int32* GetPointerToScriptVariable(int32 offset) { assert(offset >= 8 && offset < CTheScripts::GetSizeOfVariableSpace()); return (int32*)&ScriptSpace[offset]; }
static void ResetCountdownToMakePlayerUnsafe() { CountdownToMakePlayerUnsafe = 0; }
static bool IsCountdownToMakePlayerUnsafeOn() { return CountdownToMakePlayerUnsafe != 0; }
static int32 Read4BytesFromScript(uint32* pIp) {
int32 retval = ScriptSpace[*pIp + 3] << 24 | ScriptSpace[*pIp + 2] << 16 | ScriptSpace[*pIp + 1] << 8 | ScriptSpace[*pIp];
*pIp += 4;
return retval;
}
static int16 Read2BytesFromScript(uint32* pIp) {
int16 retval = ScriptSpace[*pIp + 1] << 8 | ScriptSpace[*pIp];
*pIp += 2;
return retval;
}
static int8 Read1ByteFromScript(uint32* pIp) {
int8 retval = ScriptSpace[*pIp];
*pIp += 1;
return retval;
}
static float ReadFloatFromScript(uint32* pIp) {
return Read2BytesFromScript(pIp) / 16.0f;
}
static void ReadTextLabelFromScript(uint32* pIp, char* buf) {
strncpy(buf, (const char*)&CTheScripts::ScriptSpace[*pIp], KEY_LENGTH_IN_SCRIPT);
}
static wchar* GetTextByKeyFromScript(uint32* pIp) {
wchar* text = TheText.Get((const char*)&CTheScripts::ScriptSpace[*pIp]);
*pIp += KEY_LENGTH_IN_SCRIPT;
return text;
}
static int32 GetSizeOfVariableSpace()
{
uint32 tmp = 3;
return Read4BytesFromScript(&tmp);
}
private:
static CRunningScript* StartNewScript(uint32);
static void CleanUpThisVehicle(CVehicle*);
static void CleanUpThisPed(CPed*);
static void CleanUpThisObject(CObject*);
static void Init();
static CRunningScript* StartNewScript(uint32);
static void Process();
static CRunningScript* StartTestScript();
static bool IsPlayerOnAMission();
static bool IsPedStopped(CPed*);
static bool IsPlayerStopped(CPlayerInfo*);
static bool IsVehicleStopped(CVehicle*);
@ -376,10 +345,13 @@ public:
static void UpdateObjectIndices();
static void ReadMultiScriptFileOffsetsFromScript();
static void DrawScriptSpheres();
static void ClearSpaceForMissionEntity(const CVector&, CEntity*);
static void HighlightImportantArea(uint32, float, float, float, float, float);
static void HighlightImportantAngledArea(uint32, float, float, float, float, float, float, float, float, float);
static void DrawDebugSquare(float, float, float, float);
static void DrawDebugAngledSquare(float, float, float, float, float, float, float, float);
static void DrawDebugCube(float, float, float, float, float, float);
static void DrawDebugAngledCube(float, float, float, float, float, float, float, float, float, float);
static void AddToInvisibilitySwapArray(CEntity*, bool);
static void AddToBuildingSwapArray(CBuilding*, int32, int32);
@ -388,36 +360,130 @@ public:
static int32 GetNewUniqueScriptSphereIndex(int32 index);
static void RemoveScriptSphere(int32 index);
static int32 Read4BytesFromScript(uint32* pIp){
int32 retval = 0;
for (int i = 0; i < 4; i++){
retval |= ScriptSpace[(*pIp)++] << (8 * i);
friend class CRunningScript;
friend class CHud;
friend void CMissionCleanup::Process();
};
enum {
MAX_STACK_DEPTH = 6,
NUM_LOCAL_VARS = 16,
NUM_TIMERS = 2
};
class CRunningScript
{
enum {
ANDOR_NONE = 0,
ANDS_1 = 1,
ANDS_2,
ANDS_3,
ANDS_4,
ANDS_5,
ANDS_6,
ANDS_7,
ANDS_8,
ORS_1 = 21,
ORS_2,
ORS_3,
ORS_4,
ORS_5,
ORS_6,
ORS_7,
ORS_8
};
CRunningScript* next;
CRunningScript* prev;
char m_abScriptName[8];
uint32 m_nIp;
uint32 m_anStack[MAX_STACK_DEPTH];
uint16 m_nStackPointer;
int32 m_anLocalVariables[NUM_LOCAL_VARS + NUM_TIMERS];
bool m_bCondResult;
bool m_bIsMissionScript;
bool m_bSkipWakeTime;
uint32 m_nWakeTime;
uint16 m_nAndOrState;
bool m_bNotFlag;
bool m_bDeatharrestEnabled;
bool m_bDeatharrestExecuted;
bool m_bMissionFlag;
public:
void SetIP(uint32 ip) { m_nIp = ip; }
CRunningScript* GetNext() const { return next; }
void UpdateTimers(float timeStep) {
m_anLocalVariables[NUM_LOCAL_VARS] += timeStep;
m_anLocalVariables[NUM_LOCAL_VARS + 1] += timeStep;
}
return retval;
void Init();
void Process();
void RemoveScriptFromList(CRunningScript**);
void AddScriptToList(CRunningScript**);
private:
void CollectParameters(uint32*, int16);
int32 CollectNextParameterWithoutIncreasingPC(uint32);
int32* GetPointerToScriptVariable(uint32*, int16);
void StoreParameters(uint32*, int16);
int8 ProcessOneCommand();
void DoDeatharrestCheck();
void UpdateCompareFlag(bool);
int16 GetPadState(uint16, uint16);
int8 ProcessCommands0To99(int32);
int8 ProcessCommands100To199(int32);
int8 ProcessCommands200To299(int32);
int8 ProcessCommands300To399(int32);
int8 ProcessCommands400To499(int32);
int8 ProcessCommands500To599(int32);
int8 ProcessCommands600To699(int32);
int8 ProcessCommands700To799(int32);
int8 ProcessCommands800To899(int32);
int8 ProcessCommands900To999(int32);
int8 ProcessCommands1000To1099(int32);
#ifndef GTA_PS2
int8 ProcessCommands1100To1199(int32);
#endif
void LocatePlayerCommand(int32, uint32*);
void LocatePlayerCharCommand(int32, uint32*);
void LocatePlayerCarCommand(int32, uint32*);
void LocateCharCommand(int32, uint32*);
void LocateCharCharCommand(int32, uint32*);
void LocateCharCarCommand(int32, uint32*);
void LocateCharObjectCommand(int32, uint32*);
void LocateCarCommand(int32, uint32*);
void LocateSniperBulletCommand(int32, uint32*);
void PlayerInAreaCheckCommand(int32, uint32*);
void PlayerInAngledAreaCheckCommand(int32, uint32*);
void CharInAreaCheckCommand(int32, uint32*);
void CarInAreaCheckCommand(int32, uint32*);
float LimitAngleOnCircle(float angle) { return angle < 0.0f ? angle + 360.0f : angle; }
bool ThisIsAValidRandomPed(uint32 pedtype) {
switch (pedtype) {
case PEDTYPE_CIVMALE:
case PEDTYPE_CIVFEMALE:
case PEDTYPE_GANG1:
case PEDTYPE_GANG2:
case PEDTYPE_GANG3:
case PEDTYPE_GANG4:
case PEDTYPE_GANG5:
case PEDTYPE_GANG6:
case PEDTYPE_GANG7:
case PEDTYPE_GANG8:
case PEDTYPE_GANG9:
case PEDTYPE_CRIMINAL:
case PEDTYPE_PROSTITUTE:
return true;
default:
return false;
}
static int16 Read2BytesFromScript(uint32* pIp){
int16 retval = 0;
for (int i = 0; i < 2; i++){
retval |= ScriptSpace[(*pIp)++] << (8 * i);
}
return retval;
}
static int8 Read1ByteFromScript(uint32* pIp){
int8 retval = 0;
for (int i = 0; i < 1; i++){
retval |= ScriptSpace[(*pIp)++] << (8 * i);
}
return retval;
}
static float ReadFloatFromScript(uint32* pIp){
return Read2BytesFromScript(pIp) / 16.0f;
}
static void ReadTextLabelFromScript(uint32* pIp, char* buf){
strncpy(buf, (const char*)&ScriptSpace[*pIp], KEY_LENGTH_IN_SCRIPT);
}
static wchar* GetTextByKeyFromScript(uint32* pIp) {
wchar* text = TheText.Get((const char*)&ScriptSpace[*pIp]);
*pIp += KEY_LENGTH_IN_SCRIPT;
return text;
}
};

View File

@ -735,7 +735,7 @@ void CMenuManager::Draw()
rightText = TheText.Get(gString);
break;
case MENUACTION_SETDBGFLAG:
rightText = TheText.Get(CTheScripts::DbgFlag ? "FEM_ON" : "FEM_OFF");
rightText = TheText.Get(CTheScripts::IsDebugOn() ? "FEM_ON" : "FEM_OFF");
break;
case MENUACTION_SWITCHBIGWHITEDEBUGLIGHT:
rightText = TheText.Get(gbBigWhiteDebugLightSwitchedOn ? "FEM_ON" : "FEM_OFF");
@ -2148,7 +2148,7 @@ void CMenuManager::ProcessOnOffMenuOptions()
SaveSettings();
break;
case MENUACTION_SETDBGFLAG:
CTheScripts::DbgFlag = !CTheScripts::DbgFlag;
CTheScripts::InvertDebugFlag();
DMAudio.PlayFrontEndSound(SOUND_FRONTEND_MENU_SUCCESS, 0);
break;
case MENUACTION_SWITCHBIGWHITEDEBUGLIGHT:

View File

@ -164,7 +164,7 @@ void
CPlayerInfo::MakePlayerSafe(bool toggle)
{
if (toggle) {
CTheScripts::CountdownToMakePlayerUnsafe = 0;
CTheScripts::ResetCountdownToMakePlayerUnsafe();
m_pPed->m_pWanted->m_bIgnoredByEveryone = true;
CWorld::StopAllLawEnforcersInTheirTracks();
CPad::GetPad(0)->DisablePlayerControls |= PLAYERCONTROL_DISABLED_20;
@ -185,7 +185,7 @@ CPlayerInfo::MakePlayerSafe(bool toggle)
CWorld::ExtinguishAllCarFiresInArea(GetPos(), 4000.0f);
CReplay::DisableReplays();
} else if (!CGame::playingIntro && !CTheScripts::CountdownToMakePlayerUnsafe) {
} else if (!CGame::playingIntro && !CTheScripts::IsCountdownToMakePlayerUnsafeOn()) {
m_pPed->m_pWanted->m_bIgnoredByEveryone = false;
CPad::GetPad(0)->DisablePlayerControls &= ~PLAYERCONTROL_DISABLED_20;
m_pPed->bBulletProof = false;

View File

@ -325,7 +325,7 @@ void CRadar::DrawBlips()
if (blipEntity) {
uint32 color = GetRadarTraceColour(ms_RadarTrace[blipId].m_nColor, ms_RadarTrace[blipId].m_bDim);
if (ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) {
if (CTheScripts::DbgFlag) {
if (CTheScripts::IsDebugOn()) {
ShowRadarMarker(blipEntity->GetPosition(), color, ms_RadarTrace[blipId].m_Radius);
ms_RadarTrace[blipId].m_Radius = ms_RadarTrace[blipId].m_Radius - 0.1f;
if (ms_RadarTrace[blipId].m_Radius < 1.0f)
@ -364,7 +364,7 @@ void CRadar::DrawBlips()
uint32 color = GetRadarTraceColour(ms_RadarTrace[blipId].m_nColor, ms_RadarTrace[blipId].m_bDim);
if (ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) {
if (CTheScripts::DbgFlag) {
if (CTheScripts::IsDebugOn()) {
ShowRadarMarker(ms_RadarTrace[blipId].m_vecPos, color, ms_RadarTrace[blipId].m_Radius);
ms_RadarTrace[blipId].m_Radius = ms_RadarTrace[blipId].m_Radius - 0.1f;
if (ms_RadarTrace[blipId].m_Radius < 1.0f)
@ -429,7 +429,7 @@ void CRadar::DrawBlips()
if (blipEntity) {
uint32 color = GetRadarTraceColour(ms_RadarTrace[blipId].m_nColor, ms_RadarTrace[blipId].m_bDim);
if (ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) {
if (CTheScripts::DbgFlag) {
if (CTheScripts::IsDebugOn()) {
ShowRadarMarker(blipEntity->GetPosition(), color, ms_RadarTrace[blipId].m_Radius);
ms_RadarTrace[blipId].m_Radius = ms_RadarTrace[blipId].m_Radius - 0.1f;
if (ms_RadarTrace[blipId].m_Radius < 1.0f)
@ -478,7 +478,7 @@ void CRadar::DrawBlips()
uint32 color = GetRadarTraceColour(ms_RadarTrace[blipId].m_nColor, ms_RadarTrace[blipId].m_bDim);
if (ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[blipId].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) {
if (CTheScripts::DbgFlag) {
if (CTheScripts::IsDebugOn()) {
ShowRadarMarker(ms_RadarTrace[blipId].m_vecPos, color, ms_RadarTrace[blipId].m_Radius);
ms_RadarTrace[blipId].m_Radius = ms_RadarTrace[blipId].m_Radius - 0.1f;
if (ms_RadarTrace[blipId].m_Radius < 1.0f)

View File

@ -48,6 +48,7 @@
#include "RpAnimBlend.h"
#include "Frontend.h"
#include "AnimViewer.h"
#include "Script.h"
#define DEFAULT_VIEWWINDOW (Tan(DEGTORAD(CDraw::GetFOV() * 0.5f)))
@ -356,7 +357,7 @@ RenderScene(void)
void
RenderDebugShit(void)
{
// CTheScripts::RenderTheScriptDebugLines()
CTheScripts::RenderTheScriptDebugLines();
if(gbShowCollisionLines)
CRenderer::RenderCollisionLines();
}