<commit_before>#include "stdafx.h"
#include "common.h"
#include "combat.h"
#include "tig/tig_mes.h"
#include "obj.h"
#include "critter.h"
#include "temple_functions.h"
#include "party.h"
#include "location.h"
#include "bonus.h"
#include "history.h"
#include "ai.h"
#include "util/fixes.h"
#include "weapon.h"
#include "float_line.h"
#include "pathfinding.h"
#include "action_sequence.h"
#include "turn_based.h"
#include "gametime.h"
#include "ui/ui_combat.h"
#include "raycast.h"
#include "gamesystems/objects/objsystem.h"
#include "python/python_integration_obj.h"
#include "gamesystems/gamesystems.h"
#include "maps.h"
#include "tutorial.h"
#include "objlist.h"
#include "ui/ui_dialog.h"
#include "condition.h"


struct CombatSystemAddresses : temple::AddressTable
{
	int(__cdecl* GetEnemiesCanMelee)(objHndl obj, objHndl* canMeleeList);
	void(__cdecl*CombatTurnProcessAi)(objHndl obj);
	void(__cdecl*CombatTurnAdvance)(objHndl obj);
	BOOL (__cdecl*CheckFleeCombatMap)();
	int(__cdecl*GetFleecombatMap)(void*); // MapPacket
	int (*GetFleeStatus)();
	int* combatTimeEventIndicator;
	int * combatTimeEventSthg; 
		objHndl * combatActor; 
		int * combatRoundCount;
	ActionBar** barPkt;

	CombatSystemAddresses()
	{
		rebase(GetEnemiesCanMelee, 0x100B90C0);
		rebase(EndTurn, 0x100632B0);
		rebase(CombatPerformFleeCombat, 0x100633C0);
		rebase(CombatTurnAdvance, 0x100634E0);
		rebase(CombatTurnProcessAi, 0x100635E0);
		rebase(Subturn, 0x10063760);
		rebase(GetFleecombatMap, 0x1006F970);
		rebase(CheckFleeCombatMap, 0x1006F990);
		rebase(GetFleeStatus, 0x1006F9B0);

		rebase(barPkt, 0x10AA8404);
		rebase(combatRoundCount,0x10AA841C);
		rebase(combatActor, 0x10AA8438);
		rebase(combatTimeEventSthg, 0x10AA8440);
		rebase(combatTimeEventIndicator, 0x10AA8444);
	}

	void (*Subturn)();
	void (*EndTurn)();
	void (*CombatPerformFleeCombat)(objHndl obj);
} addresses;

class CombatSystemReplacements : public TempleFix
{
public:
	static objHndl CheckRangedWeaponAmmo(objHndl obj);
	static objHndl(__cdecl *orgCheckRangedWeaponAmmo)(objHndl obj);

	static void CombatTurnAdvance(objHndl obj);
	static void (__cdecl*orgCombatTurnAdvance)(objHndl obj);

	static void ActionBarResetCallback(int resetArg)
	{
		if (resetArg != 0)
		{
			int dumm = 1;
			// seems to be 0 always... might've been some debug thing
		}
		
		auto actor = tbSys.turnBasedGetCurrentActor();
		if (actor)
			logger->debug("Greybar Reset! Current actor: {} ({})", description.getDisplayName(actor), actor);
		else
			logger->debug("Greybar Reset! Actor is null.");
		if (actor && objSystem->IsValidHandle(actor) && !objects.IsPlayerControlled(actor))
		{<commit_msg>Fix for greybar reset crash if invalid current actor<commit_after>#include "stdafx.h"
#include "common.h"
#include "combat.h"
#include "tig/tig_mes.h"
#include "obj.h"
#include "critter.h"
#include "temple_functions.h"
#include "party.h"
#include "location.h"
#include "bonus.h"
#include "history.h"
#include "ai.h"
#include "util/fixes.h"
#include "weapon.h"
#include "float_line.h"
#include "pathfinding.h"
#include "action_sequence.h"
#include "turn_based.h"
#include "gametime.h"
#include "ui/ui_combat.h"
#include "raycast.h"
#include "gamesystems/objects/objsystem.h"
#include "python/python_integration_obj.h"
#include "gamesystems/gamesystems.h"
#include "maps.h"
#include "tutorial.h"
#include "objlist.h"
#include "ui/ui_dialog.h"
#include "condition.h"


struct CombatSystemAddresses : temple::AddressTable
{
	int(__cdecl* GetEnemiesCanMelee)(objHndl obj, objHndl* canMeleeList);
	void(__cdecl*CombatTurnProcessAi)(objHndl obj);
	void(__cdecl*CombatTurnAdvance)(objHndl obj);
	BOOL (__cdecl*CheckFleeCombatMap)();
	int(__cdecl*GetFleecombatMap)(void*); // MapPacket
	int (*GetFleeStatus)();
	int* combatTimeEventIndicator;
	int * combatTimeEventSthg; 
		objHndl * combatActor; 
		int * combatRoundCount;
	ActionBar** barPkt;

	CombatSystemAddresses()
	{
		rebase(GetEnemiesCanMelee, 0x100B90C0);
		rebase(EndTurn, 0x100632B0);
		rebase(CombatPerformFleeCombat, 0x100633C0);
		rebase(CombatTurnAdvance, 0x100634E0);
		rebase(CombatTurnProcessAi, 0x100635E0);
		rebase(Subturn, 0x10063760);
		rebase(GetFleecombatMap, 0x1006F970);
		rebase(CheckFleeCombatMap, 0x1006F990);
		rebase(GetFleeStatus, 0x1006F9B0);

		rebase(barPkt, 0x10AA8404);
		rebase(combatRoundCount,0x10AA841C);
		rebase(combatActor, 0x10AA8438);
		rebase(combatTimeEventSthg, 0x10AA8440);
		rebase(combatTimeEventIndicator, 0x10AA8444);
	}

	void (*Subturn)();
	void (*EndTurn)();
	void (*CombatPerformFleeCombat)(objHndl obj);
} addresses;

class CombatSystemReplacements : public TempleFix
{
public:
	static objHndl CheckRangedWeaponAmmo(objHndl obj);
	static objHndl(__cdecl *orgCheckRangedWeaponAmmo)(objHndl obj);

	static void CombatTurnAdvance(objHndl obj);
	static void (__cdecl*orgCombatTurnAdvance)(objHndl obj);

	static void ActionBarResetCallback(int resetArg)
	{
		if (resetArg != 0)
		{
			int dumm = 1;
			// seems to be 0 always... might've been some debug thing
		}
		
		auto actor = tbSys.turnBasedGetCurrentActor();
		if (actor )
			if (objSystem->IsValidHandle(actor))
				logger->debug("Greybar Reset! Current actor: {} ({})", description.getDisplayName(actor), actor);
			else
			{
				logger->debug("Greybar Reset! Current actor is invalid handle.");
			}
				
		else
			logger->debug("Greybar Reset! Actor is null.");

		if (actor && objSystem->IsValidHandle(actor) && !objects.IsPlayerControlled(actor))
		{
{'fraction_non_alphanumeric': 0.13236644024233524, 'fraction_numerical': 0.03965485588397283, 'mean_word_length': 6.264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '729365', 'n_tokens_mistral': 2371, 'n_tokens_neox': 2097, 'n_words': 386}