Skip to content

Commit

Permalink
New Set DB Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
marcussacana committed May 19, 2019
1 parent 68fb9bb commit 7a786d6
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 14 deletions.
12 changes: 6 additions & 6 deletions SRL/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ internal static void CompileStrMap() {

ReadDump(TLMap, ref In, ref Out, IgnoreMask: true);

string DBN = Path.GetFileName(TLMap);
DBN = MaskReplace(Path.GetFileName(TLMapSrcMsk), DBN, "{0}");
const string NamedLstPrefix = "Strings-";
string DBN = Path.GetFileNameWithoutExtension(TLMap);
DBN = DBN.Substring(NamedLstPrefix.Length);

DBAr.Add(new SRLDatabase2() {
Original = In.ToArray(),
Expand Down Expand Up @@ -331,16 +332,15 @@ static void LoadData() {
if (MultipleDatabases)
FinishDatabase();
}
Log("String Reloads Initialized, {0} Databases Created, {1} Reload Entries, {2} Mask Entries", true, Databases.Count - 1, ReloadEntries, MaskEntries);
Log("String Reloads Initialized, {0} Databases Created, {1} Reload Entries, {2} Mask Entries", true, Databases.Count, ReloadEntries, MaskEntries);


Log("Registring Databases Name...", true);
DBNames = new Dictionary<long, string>();
for (long i = 0; i < Data.Databases.LongLength; i++) {
for (long i = 0; i < Data.Databases.Length; i++) {
DBNames[i] = Data.Databases[i].Name;

if (LogAll)
Log("Database ID: {0} Named As: {1}", true, i, DBNames[i]);
Log("Database ID: {0} Named As: {1}", true, i, DBNames[i]);
}

if (Data.Version > 0) {
Expand Down
2 changes: 1 addition & 1 deletion SRL/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static IntPtr ProcessReal(IntPtr Target) {
LastInput = Input;

if (Input != Reloaded) {
Reloaded = UpdateOverlay(Reloaded);
Reloaded = PostReload(Reloaded);
}

//Prevent inject a string already injected
Expand Down
37 changes: 31 additions & 6 deletions SRL/PipeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ private static void Service(string ServiceName) {
Writer.Flush();
Log("Command Finished, In: {0}, Out: {1}", true, 1, 1);
break;
case PipeCommands.SetDBID:
DBID = Reader.ReadInt32();
Log("Command Finished, In: {0}, Out: {1}", true, 2, 0);
break;
default:
if (!OK)
MessageBox.Show("Recived Invalid Command to the pipe service...", "SRL Engine", MessageBoxButtons.OK, MessageBoxIcon.Error);
Expand Down Expand Up @@ -341,9 +345,7 @@ private static string GetEntry(string Key) {
int OID = 0;

if (Debugging) {
PipeWriter.Write((byte)PipeCommands.GetDBID);
PipeWriter.Flush();
OID = PipeReader.ReadInt32();
OID = GetDBID();
}

PipeWriter.Write((byte)PipeCommands.GetReload);
Expand All @@ -352,16 +354,39 @@ private static string GetEntry(string Key) {
string Return = PipeReader.ReadString();

if (Debugging) {
PipeWriter.Write((byte)PipeCommands.GetDBID);
PipeWriter.Flush();
int NID = PipeReader.ReadInt32();
int NID = GetDBID();
if (OID != NID) {
Log("Database Changed to {0}, ID: {0}", true, GetDBNameById(NID), NID);
}
}

return Return;
}

private static int GetDBID()
{
PipeWriter.Write((byte)PipeCommands.GetDBID);
PipeWriter.Flush();
return PipeReader.ReadInt32();
}

private static void SetDBID(int ID)
{
if (Debugging)
{
Log("Database Changed to {0}, ID: {0}", true, GetDBNameById(ID), ID);
}

if (Multithread)
{
DBID = ID;
return;
}

PipeWriter.Write((byte)PipeCommands.SetDBID);
PipeWriter.Write(ID);
PipeWriter.Flush();
}
private static int GetPipeID() {
return new Random().Next(0, int.MaxValue);
}
Expand Down
37 changes: 37 additions & 0 deletions SRL/Reloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,38 @@ internal static string StrMap(string Input, IntPtr InputPtr, bool Native) {
return Input;
}

internal static string PostReload(string Reloaded)
{
Reloaded = UpdateOverlay(Reloaded);

const string SwitchDatabasePrefix = "::SETDB-";
if (Reloaded.StartsWith(SwitchDatabasePrefix))
{
string DB = Reloaded.Substring(SwitchDatabasePrefix.Length);
DB = DB.Substring(0, DB.IndexOf("::"));

bool IsDBName = false;
if (int.TryParse(DB, out int DBID))
{
if (DBNames.ContainsKey(DBID))
SetDBID(DBID);
else IsDBName = true;
}
else IsDBName = true;
if (IsDBName)
{
if (DBNames.ContainsValue(DB))
SetDBID((int)DBNames.ReverseMatch(DB));
else
Error("Database \"{0}\" not found", DB);
}

Reloaded = Reloaded.Substring(Reloaded.IndexOf("::", 2) + 2);
}

return Reloaded;
}

internal static string UpdateOverlay(string Text) {
try {
if (Overlay != null && OverlayEnabled) {
Expand Down Expand Up @@ -353,6 +385,11 @@ private static string GetDBNameById(long ID) {
return DBNames[ID];
}

private static long GetDBIdByName(string Name)
{
return DBNames.ReverseMatch(Name);
}

private static void WindowHook() {
if (WindowHookRunning)
return;
Expand Down
3 changes: 2 additions & 1 deletion SRL/Variables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ enum PipeCommands : byte {
ChkMask = 11,
RldMask = 12,
AdvDB = 13,
GetDBID = 14
GetDBID = 14,
SetDBID = 15
}

struct Range {
Expand Down

0 comments on commit 7a786d6

Please sign in to comment.