Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion YRpp
1 change: 1 addition & 0 deletions src/Spawner/Spawner.Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void SpawnerConfig::LoadFromINIFile(CCINIClass* pINI)
QuickMatch = pINI->ReadBool(pSettingsSection, "QuickMatch", QuickMatch);
SkipScoreScreen = pINI->ReadBool(pSettingsSection, "SkipScoreScreen", SkipScoreScreen);
WriteStatistics = pINI->ReadBool(pSettingsSection, "WriteStatistics", WriteStatistics);
GenerateStatistics = pINI->ReadBool(pSettingsSection, "GenerateStatistics", GenerateStatistics);
AINamesByDifficulty = pINI->ReadBool(pSettingsSection, "AINamesByDifficulty", AINamesByDifficulty);
ContinueWithoutHumans = pINI->ReadBool(pSettingsSection, "ContinueWithoutHumans", ContinueWithoutHumans);
DefeatedBecomesObserver = pINI->ReadBool(pSettingsSection, "DefeatedBecomesObserver", DefeatedBecomesObserver);
Expand Down
2 changes: 2 additions & 0 deletions src/Spawner/Spawner.Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ class SpawnerConfig
bool QuickMatch;
bool SkipScoreScreen;
bool WriteStatistics;
bool GenerateStatistics;
bool AINamesByDifficulty;
bool ContinueWithoutHumans;
bool DefeatedBecomesObserver;
Expand Down Expand Up @@ -241,6 +242,7 @@ class SpawnerConfig
, QuickMatch { false }
, SkipScoreScreen { Main::GetConfig()->SkipScoreScreen }
, WriteStatistics { false }
, GenerateStatistics { true }
, AINamesByDifficulty { false }
, ContinueWithoutHumans { false }
, DefeatedBecomesObserver { false }
Expand Down
92 changes: 91 additions & 1 deletion src/Spawner/Statistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Spawner.h"

#include <CCFileClass.h>
#include <FPSCounter.h>
#include <HouseClass.h>
#include <PacketClass.h>
#include <ScenarioClass.h>
Expand All @@ -28,14 +29,95 @@
#include <Utilities/Debug.h>
#include <Utilities/Macro.h>

#include <cstdio>
#include <cstring>
#include <Windows.h>

bool __forceinline IsStatisticsEnabled()
{
return Spawner::Active
&& Spawner::GetConfig()->WriteStatistics
&& !SessionClass::IsCampaign();
}

// Write stats.dmp
static void WriteDTALog()
{
if (!Spawner::Active)
return;

if (!Spawner::GetConfig()->GenerateStatistics)
return;

CreateDirectoryA("debug", nullptr);

CCFileClass file = CCFileClass("debug\\Statistic.log");
if (!file.Open(FileAccessMode::Write))
return;

using GetUnitCountFunc = int(__fastcall*)(void*);
const auto GetUnitCount = reinterpret_cast<GetUnitCountFunc>(0x49FB60);

const int count = HouseClass::Array.Count;

for (int i = 0; i < count; i++)
{
const auto pHouse = HouseClass::Array.GetItem(i);
if (!pHouse)
continue;

if (pHouse->Type && pHouse->Type->MultiplayPassive)
continue;

if (pHouse->IsInitiallyObserver())
continue;

char name[64] = { 0 };
if (pHouse->IsHumanPlayer)
{
WideCharToMultiByte(CP_UTF8, 0, pHouse->UIName, -1, name, sizeof(name), nullptr, nullptr);
}
else
{
strcpy_s(name, "Computer");
}

const char* result = pHouse->Defeated ? "Loser" : "Winner";

int lost = *reinterpret_cast<const int*>(
reinterpret_cast<const char*>(pHouse) + 21556)
+ *reinterpret_cast<const int*>(
reinterpret_cast<const char*>(pHouse) + 21640);

const int* k1 = reinterpret_cast<const int*>(
reinterpret_cast<const char*>(pHouse) + 21476);
const int* k2 = reinterpret_cast<const int*>(
reinterpret_cast<const char*>(pHouse) + 21560);
int kills = 0;
for (int j = 0; j < 20; ++j) kills += k1[j];
for (int j = 0; j < 20; ++j) kills += k2[j];

int built = GetUnitCount(reinterpret_cast<char*>(pHouse) + 21920)
+ GetUnitCount(reinterpret_cast<char*>(pHouse) + 21940)
+ GetUnitCount(reinterpret_cast<char*>(pHouse) + 21960)
+ GetUnitCount(reinterpret_cast<char*>(pHouse) + 21980);

int score = *reinterpret_cast<const int*>(
reinterpret_cast<const char*>(pHouse) + 21736);
Comment thread
GreyVacuum marked this conversation as resolved.
Outdated

char buffer[256] = { 0 };
sprintf_s(buffer, "%s: %s\n Lost = %d\n Kills = %d\n Built = %d\n Score = %d\n",
name, result, lost, kills, built, score);
file.WriteBytes(buffer, static_cast<int>(strlen(buffer)));
}

char fpsBuffer[128] = { 0 };
sprintf_s(fpsBuffer, "Game loop finished. Average FPS = %d\n",
static_cast<int>(FPSCounter::GetAverageFrameRate()));
file.WriteBytes(fpsBuffer, static_cast<int>(strlen(fpsBuffer)));

file.Close();
}

DEFINE_HOOK(0x6C856C, SendStatisticsPacket_WriteStatisticsDump, 0x5)
{
if (IsStatisticsEnabled())
Expand All @@ -50,6 +132,8 @@ DEFINE_HOOK(0x6C856C, SendStatisticsPacket_WriteStatisticsDump, 0x5)
statsFile.Close();
}

WriteDTALog();

bool& bStatisticsPacketSent = *reinterpret_cast<bool*>(0xA8F900);
bStatisticsPacketSent = true;

Expand All @@ -59,6 +143,12 @@ DEFINE_HOOK(0x6C856C, SendStatisticsPacket_WriteStatisticsDump, 0x5)
return 0;
}

DEFINE_HOOK(0x5C9D47, MPScore_InitDialog_WriteDTALog, 0x6)
{
WriteDTALog();
return 0;
}

// Send AI player
// Dont send observer
DEFINE_HOOK(0x6C73F8, SendStatisticsPacket_HouseFilter, 0x6)
Expand Down