<commit_before>﻿using System;
using UnityEngine;

public class Vars : MonoBehaviour
{
	public MenuStyle Style;

	private bool pauseVarsTracking;

	private byte[] memory = new byte[512];
	private Var[] vars = new Var[207];
	private Var[] cvars = new Var[44];

	private byte[] varsMemoryPattern = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2E, 0x00, 0x2F, 0x00, 0x00, 0x00, 0x00 };
	private long varsMemoryAddress = -1;

	private byte[] cvarsMemoryPattern = new byte[] { 0x31, 0x00, 0x0E, 0x01, 0xBC, 0x02, 0x12, 0x00, 0x06, 0x00, 0x13, 0x00, 0x14, 0x00, 0x01 };
	private long cvarsMemoryAddress = -1;

	private bool compare;
	private bool oldcompare;
	private bool ignoreDifferences;

	private string focusedControlName;

	public void OnEnable()
	{
		ignoreDifferences = !compare;
	}

	private short ReadShort(byte a, byte b)
	{
		unchecked
		{
			return (short)(a | b << 8);
		}
	}

	private void WriteShort(int value, byte[] data, int offset)
	{
		unchecked
		{
			data[offset + 0] = (byte)(value & 0xFF);
			data[offset + 1] = (byte)(value >> 8);
		}
	}

	void Update()
	{
		ProcessMemoryReader processReader = GetComponent<DosBox>().ProcessReader;
		if (processReader != null)
		{
			if (!pauseVarsTracking)
			{
				if (varsMemoryAddress != -1)
				{
					ProcessInput(vars);
					processReader.Read(memory, varsMemoryAddress, 207 * 2);
					CheckDifferences(memory, vars, varsMemoryAddress);
				}

				if (cvarsMemoryAddress != -1)
				{
					ProcessInput(cvars);
					processReader.Read(memory, cvarsMemoryAddress, 44 * 2);
					CheckDifferences(memory, cvars, cvarsMemoryAddress);
				}

				ignoreDifferences = false;
			}
		}

		//hide table
		if (Input.GetMouseButtonDown(1))
		{
			this.enabled = false;
		}
	}

	void OnGUI()
	{
		GUIStyle panel = new GUIStyle(Style.Panel);
		panel.normal.background = Style.BlackTexture;
		Rect screen = new Rect(0, 0, Screen.width, Screen.height - 30 * 1);
		Rect areaA = new Rect(0, 0, screen.width, screen.height * 22.0f / 28.0f);
		Rect areaB = new Rect(0, screen.height * 22.0f / 28.0f, screen.width, screen.height * 6.0f / 28.0f);
		Rect areaC = new Rect(0, screen.height, screen.width, 30 * 1);

		//table
		GUILayout.BeginArea(areaA, panel);
		DisplayTable(areaA, 10, 21, vars, "VARS");
		GUILayout.EndArea();

		GUILayout.BeginArea(areaB, panel);
		DisplayTable(areaB, 10, 5, cvars, "CVARS");
		GUILayout.EndArea();

		//buttons
		GUIStyle button = new GUIStyle(Style.Button);
		GUIStyle buttonToggled = new GUIStyle(button);
		buttonToggled.normal = buttonToggled.active; 
		buttonToggled.hover = buttonToggled.active;

		button.fixedWidth = areaC.width / 3.0f;		
		GUILayout.BeginArea(areaC, panel);
		GUILayout.BeginVertical();
		GUILayout.BeginHorizontal();
		if (GUILayout.Button("Freeze", pauseVarsTracking ? buttonToggled : button) && Event.current.button == 0)
		{
			pauseVarsTracking = !pauseVarsTracking;
		}

		if (GUILayout.Button("Save state", button))
		{<commit_msg>VARS: buttons should have fixed width regardless they are toggled or not<commit_after>﻿using System;
using UnityEngine;

public class Vars : MonoBehaviour
{
	public MenuStyle Style;

	private bool pauseVarsTracking;

	private byte[] memory = new byte[512];
	private Var[] vars = new Var[207];
	private Var[] cvars = new Var[44];

	private byte[] varsMemoryPattern = new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2E, 0x00, 0x2F, 0x00, 0x00, 0x00, 0x00 };
	private long varsMemoryAddress = -1;

	private byte[] cvarsMemoryPattern = new byte[] { 0x31, 0x00, 0x0E, 0x01, 0xBC, 0x02, 0x12, 0x00, 0x06, 0x00, 0x13, 0x00, 0x14, 0x00, 0x01 };
	private long cvarsMemoryAddress = -1;

	private bool compare;
	private bool oldcompare;
	private bool ignoreDifferences;

	private string focusedControlName;

	public void OnEnable()
	{
		ignoreDifferences = !compare;
	}

	private short ReadShort(byte a, byte b)
	{
		unchecked
		{
			return (short)(a | b << 8);
		}
	}

	private void WriteShort(int value, byte[] data, int offset)
	{
		unchecked
		{
			data[offset + 0] = (byte)(value & 0xFF);
			data[offset + 1] = (byte)(value >> 8);
		}
	}

	void Update()
	{
		ProcessMemoryReader processReader = GetComponent<DosBox>().ProcessReader;
		if (processReader != null)
		{
			if (!pauseVarsTracking)
			{
				if (varsMemoryAddress != -1)
				{
					ProcessInput(vars);
					processReader.Read(memory, varsMemoryAddress, 207 * 2);
					CheckDifferences(memory, vars, varsMemoryAddress);
				}

				if (cvarsMemoryAddress != -1)
				{
					ProcessInput(cvars);
					processReader.Read(memory, cvarsMemoryAddress, 44 * 2);
					CheckDifferences(memory, cvars, cvarsMemoryAddress);
				}

				ignoreDifferences = false;
			}
		}

		//hide table
		if (Input.GetMouseButtonDown(1))
		{
			this.enabled = false;
		}
	}

	void OnGUI()
	{
		GUIStyle panel = new GUIStyle(Style.Panel);
		panel.normal.background = Style.BlackTexture;
		Rect screen = new Rect(0, 0, Screen.width, Screen.height - 30 * 1);
		Rect areaA = new Rect(0, 0, screen.width, screen.height * 22.0f / 28.0f);
		Rect areaB = new Rect(0, screen.height * 22.0f / 28.0f, screen.width, screen.height * 6.0f / 28.0f);
		Rect areaC = new Rect(0, screen.height, screen.width, 30 * 1);

		//table
		GUILayout.BeginArea(areaA, panel);
		DisplayTable(areaA, 10, 21, vars, "VARS");
		GUILayout.EndArea();

		GUILayout.BeginArea(areaB, panel);
		DisplayTable(areaB, 10, 5, cvars, "CVARS");
		GUILayout.EndArea();

		//buttons
		GUIStyle button = new GUIStyle(Style.Button);
		button.fixedWidth = areaC.width / 3.0f;	

		GUIStyle buttonToggled = new GUIStyle(button);
		buttonToggled.normal = buttonToggled.active; 
		buttonToggled.hover = buttonToggled.active;
			
		GUILayout.BeginArea(areaC, panel);
		GUILayout.BeginVertical();
		GUILayout.BeginHorizontal();
		if (GUILayout.Button("Freeze", pauseVarsTracking ? buttonToggled : button) && Event.current.button == 0)
		{
			pauseVarsTracking = !pauseVarsTracking;
		}

		if (GUILayout.Button("Save state", button))
		{
{'fraction_non_alphanumeric': 0.12930746068919372, 'fraction_numerical': 0.049849447975911676, 'mean_word_length': 3.8256658595641646, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1740706', 'n_tokens_mistral': 2602, 'n_tokens_neox': 2154, 'n_words': 525}