Skip to content

Commit

Permalink
Added fileSize logic in RBR_Replay function.
Browse files Browse the repository at this point in the history
  • Loading branch information
mika-n committed May 16, 2020
1 parent 2556b3a commit bfa2b45
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 138 deletions.
60 changes: 60 additions & 0 deletions src/CreateReleaseZip.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@echo off

SET APPNAME=NGPCarMenu
SET VERSIONTAG=%~1
SET RELEASE_FOLDER=Release\VER_%VERSIONTAG%
SET RELEASE_PKG=%APPNAME%_%VERSIONTAG%.zip

SET ZIP_TOOL=C:\Program Files\7-Zip\7z.exe

echo [%DATE% %TIME%] %~nx0 %APPNAME% %VERSIONTAG%
echo [%DATE% %TIME%] Release folder %RELEASE_FOLDER%
echo [%DATE% %TIME%] Release package %RELEASE_PKG%


if "%~1" == "" (
echo Missing cmdline argument: versionTag
echo Example: CreateReleaseZip.cmd 1.14
goto END
)

if NOT EXIST "Release" (
echo Release folder missing. Re-build the project in C++ compiler usign Release configuration
goto END
)

if NOT EXIST "Release\%APPNAME%.dll" (
echo %APPNAME%.dll Re-build the project in C++ compiler using Release configuration
goto END
)

echo Do you want to create a release package %APPNAME%_%VERSIONTAG%.zip?
echo Press CTRL-C to quit, other key to continue...
pause


mkdir "%RELEASE_FOLDER%\"
mkdir "%RELEASE_FOLDER%\Replays\"
mkdir "%RELEASE_FOLDER%\Plugins\"
mkdir "%RELEASE_FOLDER%\Plugins\%APPNAME%\"
mkdir "%RELEASE_FOLDER%\Plugins\%APPNAME%\preview\1920x1080\"
mkdir "%RELEASE_FOLDER%\Plugins\%APPNAME%\preview\1366x768\"

copy "Release\%APPNAME%.dll" "%RELEASE_FOLDER%\Plugins\"
copy "%APPNAME%.ini" "%RELEASE_FOLDER%\Plugins\"
copy "%APPNAME%.rpl" "%RELEASE_FOLDER%\Replays\"
copy "..\LicenseText.txt" "%RELEASE_FOLDER%\Plugins\%APPNAME%\"
copy "..\ReadMe.md" "%RELEASE_FOLDER%\Plugins\%APPNAME%\"
copy "..\ReadMe.md" "%RELEASE_FOLDER%\Plugins\%APPNAME%\ReadMe.txt"

type NUL > "%RELEASE_FOLDER%\Plugins\%APPNAME%\preview\1920x1080\carImages.txt"
type NUL > "%RELEASE_FOLDER%\Plugins\%APPNAME%\preview\1366x768\carImages.txt"

PUSHD "%RELEASE_FOLDER%\"
del "..\%RELEASE_PKG%"
"%ZIP_TOOL%" a -r -tzip "..\%RELEASE_PKG%" *.*
POPD

echo [%DATE% %TIME%] Release\VER_%VERSIONTAG% package build completed

:END
116 changes: 116 additions & 0 deletions src/D3D9Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@

#include "D3D9Helpers.h"

#if USE_DEBUG == 1
#include "NGPCarMenu.h"
#endif

namespace fs = std::filesystem;

//
Expand Down Expand Up @@ -167,6 +171,118 @@ bool _StringToRect(const std::wstring& s, RECT* outRect, const wchar_t separator
return (items.size() >= 4);
}


//---------------------------------------------------------------------------------------------------------------
#if USE_DEBUG == 1

//-----------------------------------------------------------------------------------------------------------------------------
// Debug printout functions. Not used in release build.
//

FILE* g_fpDebugLogFile = nullptr;
void DebugPrintCloseFile();

void DebugPrintFunc(LPCSTR lpszFormat, ...)
{
va_list args;
va_start(args, lpszFormat);

SYSTEMTIME t;
char szTxtTimeStampBuf[32];
char szTxtBuf[1024];

try
{
GetLocalTime(&t);
if (GetTimeFormat(LOCALE_USER_DEFAULT, 0, &t, "hh:mm:ss ", (LPSTR)szTxtTimeStampBuf, sizeof(szTxtTimeStampBuf) - 1) <= 0)
szTxtTimeStampBuf[0] = '\0';

if (_vsnprintf_s(szTxtBuf, sizeof(szTxtBuf) - 1, lpszFormat, args) <= 0)
szTxtBuf[0] = '\0';

if (g_fpDebugLogFile == nullptr)
fopen_s(&g_fpDebugLogFile, "NGPCarMenu.log", "a+t");

if (g_fpDebugLogFile)
{
fprintf(g_fpDebugLogFile, szTxtTimeStampBuf);
fprintf(g_fpDebugLogFile, szTxtBuf);
fprintf(g_fpDebugLogFile, "\n");
}
}
catch (...)
{
// Do nothing
}

va_end(args);
}

void DebugPrintEmptyFile()
{
FILE* fpDebugLogFile = nullptr;
DebugPrintCloseFile();
fopen_s(&fpDebugLogFile, "NGPCarMenu.log", "w");
if (fpDebugLogFile != nullptr) fclose(fpDebugLogFile);
}

void DebugPrintCloseFile()
{
FILE* fpDebugLogFile = g_fpDebugLogFile;
g_fpDebugLogFile = nullptr;
if (fpDebugLogFile != nullptr) fclose(fpDebugLogFile);
}

void DebugDumpBuffer(byte* pBuffer, int iPreOffset = 0, int iBytesToDump = 64)
{
char txtBuffer[64];

byte* pBuffer2 = pBuffer - iPreOffset;
for (int idx = 0; idx < iBytesToDump; idx += 8)
{
int iAppendPos = 0;
for (int idx2 = 0; idx2 < 8; idx2++)
iAppendPos += sprintf_s(txtBuffer + iAppendPos, sizeof(txtBuffer), "%02x ", (byte)pBuffer2[idx + idx2]);

iAppendPos += sprintf_s(txtBuffer + iAppendPos, sizeof(txtBuffer), " | ");

for (int idx2 = 0; idx2 < 8; idx2++)
iAppendPos += sprintf_s(txtBuffer + iAppendPos, sizeof(txtBuffer), "%c", (pBuffer2[idx + idx2] < 32 || pBuffer2[idx + idx2] > 126) ? '.' : pBuffer2[idx + idx2]);

DebugPrint(txtBuffer);
}
}

void DebugDumpBufferToScreen(byte* pBuffer, int iPreOffset = 0, int iBytesToDump = 64, int posX = 850, int posY = 1)
{
WCHAR txtBuffer[64];

D3DRECT rec = { posX, posY, posX + 440, posY + ((iBytesToDump / 8) * 20) };
g_pRBRIDirect3DDevice9->Clear(1, &rec, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 50, 50, 50), 0, 0);

byte* pBuffer2 = pBuffer - iPreOffset;
for (int idx = 0; idx < iBytesToDump; idx += 8)
{
int iAppendPos = 0;

iAppendPos += swprintf_s(txtBuffer + iAppendPos, COUNT_OF_ITEMS(txtBuffer) - iAppendPos, L"%04x ", idx);
for (int idx2 = 0; idx2 < 8; idx2++)
iAppendPos += swprintf_s(txtBuffer + iAppendPos, COUNT_OF_ITEMS(txtBuffer) - iAppendPos, L"%02x ", (byte)pBuffer2[idx + idx2]);

iAppendPos += swprintf_s(txtBuffer + iAppendPos, COUNT_OF_ITEMS(txtBuffer) - iAppendPos, L" | ");

for (int idx2 = 0; idx2 < 8; idx2++)
iAppendPos += swprintf_s(txtBuffer + iAppendPos, COUNT_OF_ITEMS(txtBuffer) - iAppendPos, L"%c", (pBuffer2[idx + idx2] < 32 || pBuffer2[idx + idx2] > 126) ? L'.' : pBuffer2[idx + idx2]);

pFontDebug->DrawText(posX, (idx / 8) * 20 + posY, D3DCOLOR_ARGB(255, 240, 250, 0), txtBuffer, 0);
//pFontDebug->DrawText(posX, (idx / 8) * 20 + posY, D3DCOLOR_ARGB(255, 240, 250, 0), txtBuffer, 0);
}
}

#endif // USE_DEBUG



//---------------------------------------------------------------------------------------------------------------

//
Expand Down
30 changes: 30 additions & 0 deletions src/D3D9Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,36 @@
//#include <windows.h>
//#include <string>


//------------------------------------------------------------------------------------------------

#ifdef _DEBUG
#define USE_DEBUG 1 // 1=Custom debug outputs and calculations (spends few cycles of precious CPU time), 0=No custom debugging, run the game code without extra debug code
#endif

#ifndef _DEBUG
#undef USE_DEBUG
#endif


#if USE_DEBUG == 1
#include "D3D9Font\D3DFont.h"

#define DebugPrint DebugPrintFunc // DEBUG version to dump logfile messages
#else
#define DebugPrint // RELEASE version of DebugPrint doing nothing
#endif

#if USE_DEBUG == 1
extern CD3DFont* pFontDebug;

extern void DebugPrintCloseFile();
extern void DebugPrintEmptyFile();
extern void DebugPrintFunc(LPCSTR lpszFormat, ...);
#endif

//------------------------------------------------------------------------------------------------

#ifndef SAFE_RELEASE
#define SAFE_RELEASE( p ) if( p ){ p->Release(); p = nullptr; }
#endif
Expand Down
113 changes: 2 additions & 111 deletions src/NGPCarMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,115 +116,6 @@ char* g_RBRPluginMenu_CreateOptions[2] = {
};


#if USE_DEBUG == 1

//-----------------------------------------------------------------------------------------------------------------------------
// Debug printout functions. Not used in release build.
//

FILE* g_fpDebugLogFile = nullptr;
void DebugPrintCloseFile();

void DebugPrintFunc(LPCSTR lpszFormat, ...)
{
va_list args;
va_start(args, lpszFormat);

SYSTEMTIME t;
char szTxtTimeStampBuf[32];
char szTxtBuf[1024];

try
{
GetLocalTime(&t);
if (GetTimeFormat(LOCALE_USER_DEFAULT, 0, &t, "hh:mm:ss ", (LPSTR)szTxtTimeStampBuf, sizeof(szTxtTimeStampBuf) - 1) <= 0)
szTxtTimeStampBuf[0] = '\0';

if (_vsnprintf_s(szTxtBuf, sizeof(szTxtBuf) - 1, lpszFormat, args) <= 0)
szTxtBuf[0] = '\0';

if (g_fpDebugLogFile == nullptr)
fopen_s(&g_fpDebugLogFile, "NGPCarMenu.log", "a+t");

if (g_fpDebugLogFile)
{
fprintf(g_fpDebugLogFile, szTxtTimeStampBuf);
fprintf(g_fpDebugLogFile, szTxtBuf);
fprintf(g_fpDebugLogFile, "\n");
}
}
catch (...)
{
// Do nothing
}

va_end(args);
}

void DebugPrintEmptyFile()
{
FILE* fpDebugLogFile = nullptr;
DebugPrintCloseFile();
fopen_s(&fpDebugLogFile, "NGPCarMenu.log", "w");
if (fpDebugLogFile != nullptr) fclose(fpDebugLogFile);
}

void DebugPrintCloseFile()
{
FILE* fpDebugLogFile = g_fpDebugLogFile;
g_fpDebugLogFile = nullptr;
if (fpDebugLogFile != nullptr) fclose(fpDebugLogFile);
}

void DebugDumpBuffer(byte* pBuffer, int iPreOffset = 0, int iBytesToDump = 64)
{
char txtBuffer[64];

byte* pBuffer2 = pBuffer - iPreOffset;
for (int idx = 0; idx < iBytesToDump; idx += 8)
{
int iAppendPos = 0;
for (int idx2 = 0; idx2 < 8; idx2++)
iAppendPos += sprintf_s(txtBuffer + iAppendPos, sizeof(txtBuffer), "%02x ", (byte)pBuffer2[idx + idx2]);

iAppendPos += sprintf_s(txtBuffer + iAppendPos, sizeof(txtBuffer), " | ");

for (int idx2 = 0; idx2 < 8; idx2++)
iAppendPos += sprintf_s(txtBuffer + iAppendPos, sizeof(txtBuffer), "%c", (pBuffer2[idx + idx2] < 32 || pBuffer2[idx + idx2] > 126) ? '.' : pBuffer2[idx + idx2]);

DebugPrint(txtBuffer);
}
}

void DebugDumpBufferToScreen(byte* pBuffer, int iPreOffset = 0, int iBytesToDump = 64, int posX = 850, int posY = 1)
{
WCHAR txtBuffer[64];

D3DRECT rec = { posX, posY, posX + 440, posY + ((iBytesToDump / 8) * 20) };
g_pRBRIDirect3DDevice9->Clear(1, &rec, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 50, 50, 50), 0, 0);

byte* pBuffer2 = pBuffer - iPreOffset;
for (int idx = 0; idx < iBytesToDump; idx += 8)
{
int iAppendPos = 0;

iAppendPos += swprintf_s(txtBuffer + iAppendPos, COUNT_OF_ITEMS(txtBuffer) - iAppendPos, L"%04x ", idx);
for (int idx2 = 0; idx2 < 8; idx2++)
iAppendPos += swprintf_s(txtBuffer + iAppendPos, COUNT_OF_ITEMS(txtBuffer) - iAppendPos, L"%02x ", (byte)pBuffer2[idx + idx2]);

iAppendPos += swprintf_s(txtBuffer + iAppendPos, COUNT_OF_ITEMS(txtBuffer) - iAppendPos, L" | ");

for (int idx2 = 0; idx2 < 8; idx2++)
iAppendPos += swprintf_s(txtBuffer + iAppendPos, COUNT_OF_ITEMS(txtBuffer) - iAppendPos, L"%c", (pBuffer2[idx + idx2] < 32 || pBuffer2[idx + idx2] > 126) ? L'.' : pBuffer2[idx + idx2]);

pFontDebug->DrawText(posX, (idx / 8) * 20 + posY, D3DCOLOR_ARGB(255, 240, 250, 0), txtBuffer, 0);
//pFontDebug->DrawText(posX, (idx / 8) * 20 + posY, D3DCOLOR_ARGB(255, 240, 250, 0), txtBuffer, 0);
}
}

#endif // USE_DEBUG


//-----------------------------------------------------------------------------------------------------------------------------
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
Expand Down Expand Up @@ -1003,7 +894,7 @@ void CNGPCarMenu::HandleFrontEndEvents(char txtKeyboard, bool bUp, bool bDown, b

// Set a flag that custom replay generation is active during replays. If this is zero then replay plays the file normally
m_iCustomReplayState = 1;
::RBRAPI_Replay(C_REPLAYFILENAME_SCREENSHOT);
::RBRAPI_Replay(this->m_sRBRRootDir, C_REPLAYFILENAME_SCREENSHOT);
}
else
m_sMenuStatusText1 = "All cars already have a preview image. Did not create any new images.";
Expand Down Expand Up @@ -1255,7 +1146,7 @@ HRESULT __fastcall CustomRBRDirectXBeginScene(void* objPointer)
g_pRBRPlugin->m_iCustomReplayState = 1;
}

RBRAPI_Replay(C_REPLAYFILENAME_SCREENSHOT);
RBRAPI_Replay(g_pRBRPlugin->m_sRBRRootDir, C_REPLAYFILENAME_SCREENSHOT);
}
}
}
Expand Down
23 changes: 0 additions & 23 deletions src/NGPCarMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@

//#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
//#include <windows.h>

#ifdef _DEBUG
#define USE_DEBUG 1 // 1=Custom debug outputs and calculations (spends few cycles of precious CPU time), 0=No custom debugging, run the game code without extra debug code
#endif

#ifndef _DEBUG
#undef USE_DEBUG
#endif

//#include <assert.h>
//#include <stdio.h>
#include <d3d9.h>
Expand Down Expand Up @@ -73,20 +64,6 @@ enum class T_PLUGINSTATE
};


//------------------------------------------------------------------------------------------------

#if USE_DEBUG == 1
extern void DebugPrintFunc(LPCSTR lpszFormat, ...);
#endif

#if USE_DEBUG == 1
#define DebugPrint DebugPrintFunc // DEBUG version to dump logfile messages
#else
#define DebugPrint // RELEASE version of DebugPrint doing nothing
#endif



//------------------------------------------------------------------------------------------------

#define MAX_CARMENUNAME_NORMALCHARS 28
Expand Down
Loading

0 comments on commit bfa2b45

Please sign in to comment.