Created
May 2, 2016 05:03
-
-
Save DarkLotus/af6eac3f261d729560e3e302e836c7e2 to your computer and use it in GitHub Desktop.
Doesnt work, client reads the new cliloc file fine in most cases, but displays blank text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ClilocGen | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var clis = new Ultima.StringList("ENU"); | |
var output = new UOStream(); | |
output.Write("FORM"); | |
long len1position = output.Position; // this is total bytes - 8 | |
output.Write((int)0x00); | |
output.Write("DATAFORM"); | |
long len2position = output.Position; // this is total bytes - 20 | |
output.Write((int)0x00); | |
output.Write("LANGINFO"); | |
output.Write((short)0); | |
output.Write((byte)0); | |
output.Write((byte)0x1D); // Unsure some kind of magic code? | |
output.Write("enu"); | |
output.Write((byte)0); | |
output.Write((byte)0x01); //char length in bytes i think | |
output.Write((int)0); | |
output.Write((short)0); | |
output.Write((byte)0); | |
output.Write("cliloc61"); | |
output.Write((byte)0x00); | |
output.Write((byte)0x01); | |
output.Write((short)0x00); | |
output.Write((byte)0); | |
long countPos = output.Position; | |
output.Write((ushort)999); // think this is count of strings zero based? | |
output.Write((byte)0); | |
output.Write((short)0x00); | |
output.Write("TEXT"); | |
long len3position = output.Position; // this is total bytes - 70 | |
output.Write((int)0x00); | |
int cnt = 0; | |
for (int i = 1061000; i < 1062000;i++) | |
{ | |
var entry = clis.Entries.Where(c => c.Number == i).FirstOrDefault(); | |
if (entry != null && entry.Text.Length > 1) | |
output.Write(entry.Text); | |
output.Write((byte)0x00); | |
cnt++; | |
} | |
var totalLen = output.Position; | |
output.Position = len1position +2; | |
output.Write((ushort)(totalLen - 8)); | |
output.Position = len2position +2; | |
output.Write((ushort)(totalLen - 20)); | |
output.Position = len3position +2; | |
output.Write((ushort)(totalLen - 70)); | |
output.Position = countPos; | |
var bytes = new byte[2]; | |
bytes[0] = (byte)cnt; | |
bytes[1] = (byte)(cnt >> 8); | |
output.Write(bytes[0]); | |
output.Write(bytes[1]); | |
File.OpenWrite("cliloc61.enu").Write(output.GetBuffer(), 0, (int)output.Length); | |
} | |
} | |
public class UOStream : MemoryStream | |
{ | |
/*public override string ToString() | |
{ | |
var curPos = this.Position; | |
this.Position = 0; | |
var buf = new byte[this.Length]; | |
var results = ""; | |
this.Read(buf, 0, (int)this.Length); | |
foreach (var b in buf) | |
results += b + " "; | |
return results; | |
}*/ | |
public UOStream(byte[] Data) : base(Data, 0, Data.Length, true, true) | |
{ | |
this.Position = 0; | |
} | |
public UOStream() : base() | |
{ | |
} | |
public void Write(int Value) | |
{ | |
byte[] data = new byte[4]; | |
data = BitConverter.GetBytes(Value); | |
this.Write(data, 0, 4); | |
} | |
public void Write(short Value) | |
{ | |
byte[] data = new byte[2]; | |
data = BitConverter.GetBytes(Value); | |
this.Write(data, 0, 2); | |
} | |
public void Write(ushort Value) | |
{ | |
var bytes = new byte[2]; | |
bytes[0] = (byte)Value; | |
bytes[1] = (byte)(Value >> 8); | |
Write(bytes[1]); | |
Write(bytes[0]); | |
return; | |
byte[] data = new byte[2]; | |
data = BitConverter.GetBytes(Value); | |
this.Write(data, 0, 2); | |
} | |
public void Write(byte Value) | |
{ | |
this.Write(new byte[] { Value }, 0, 1); | |
} | |
internal byte[] ReadBytes(int v) | |
{ | |
throw new NotImplementedException(); | |
} | |
public void Write(string Value, int RequiredLength = 0) | |
{ | |
//RequiredLength 0 if you dont need padding. | |
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); | |
if (RequiredLength == 0) | |
{ | |
byte[] Data = encoding.GetBytes(Value); | |
this.Write(Data, 0, Data.Length); | |
} | |
else | |
{ | |
byte[] Data = new byte[RequiredLength]; | |
for (int i = 0; i < Data.Length; i++) | |
{ | |
Data[i] = 0x00; | |
} | |
if (Data.Length <= RequiredLength) | |
encoding.GetBytes(Value).CopyTo(Data, 0); | |
this.Write(Data, 0, Data.Length); | |
} | |
} | |
internal void WriteUInt(uint v) | |
{ | |
throw new NotImplementedException(); | |
} | |
public int ReadInt() | |
{ | |
byte[] results = new byte[4]; this.Read(results, 0, 4); | |
return (int)((results[0] << 24 | results[1] << 16) | (results[2] << 8) | results[3]); | |
} | |
public byte ReadBit() | |
{ | |
byte[] results = new byte[1]; this.Read(results, 0, 1); | |
return results[0]; | |
} | |
public short ReadShort() | |
{ | |
byte[] results = new byte[2]; this.Read(results, 0, 2); | |
return (short)(results[0] << 8 | results[1]); | |
} | |
public string Read30CharString() | |
{ | |
char[] mystring = new char[30]; | |
for (int i = 0; i < 30; i++) | |
{ | |
mystring[i] = (char)this.ReadBit(); | |
} | |
return new string(mystring); | |
} | |
public string ReadString(int bytesToRead) | |
{ | |
char[] mystring = new char[bytesToRead]; | |
for (int i = 0; i < bytesToRead; i++) | |
{ | |
var charr = (char)this.ReadBit(); | |
if (charr != 0x00) | |
mystring[i] = (char)charr; | |
} | |
return new string(mystring); | |
} | |
public string ReadNullTermString() | |
{ | |
byte current; | |
byte previous = 1; | |
List<char> ms = new List<char>(); | |
while (true) | |
{ | |
current = this.ReadBit(); | |
if (current == 0x00 && previous == 0x00) // Reads untill null terminated | |
break; | |
ms.Add((char)current); | |
previous = (byte)(current + 0); | |
} | |
return new string(ms.ToArray()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment