Skip to content

Instantly share code, notes, and snippets.

@andanteyk
Created August 17, 2018 20:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andanteyk/4c62297f29adfd4b540b2ed8db5acd5a to your computer and use it in GitHub Desktop.
Save andanteyk/4c62297f29adfd4b540b2ed8db5acd5a to your computer and use it in GitHub Desktop.
v2 resource name solver
using System;
using System.Linq;
namespace GetKcs2ResourceName
{
class Program
{
// note: $"{12:d4}" -> "0012"
// resourceType = ["album_status", "banner", "card", "character_full", "character_up", "full", "supply_character"]
public static string GetShipResourcePath(int shipID, bool isDamaged, string resourceType)
{
if (resourceType == "album_status")
isDamaged = false;
// if (isEnemy(shipID))
// isDamaged = false;
if (isDamaged)
resourceType += "_dmg";
return $"<root>/resources/ship/{resourceType}/{shipID:d4}_{CreateKey(shipID, "ship_" + resourceType)}.png";
}
// resourceType = ["btxt_flat", "card", "card_t", "item_character", "item_on", "item_up", "remodel", "statustop_item"]
public static string GetEquipmentResourcePath(int equipmentID, string resourceType)
{
return $"<root>/resources/slot/{resourceType}/{equipmentID:d3}_{CreateKey(equipmentID, "slot_" + resourceType)}.png";
}
static readonly int[] resourceTable = new int[100]
{
6657,5699,3371,8909,7719,
6229,5449,8561,2987,5501,
3127,9319,4365,9811,9927,
2423,3439,1865,5925,4409,
5509,1517,9695,9255,5325,
3691,5519,6949,5607,9539,
4133,7795,5465,2659,6381,
6875,4019,9195,5645,2887,
1213,1815,8671,3015,3147,
2991,7977,7045,1619,7909,
4451,6573,4545,8251,5983,
2849,7249,7449,9477,5963,
2711,9019,7375,2201,5631,
4893,7653,3719,8819,5839,
1853,9843,9119,7023,5681,
2345,9873,6349,9315,3795,
9737,4633,4173,7549,7171,
6147,4723,5039,2723,7815,
6201,5999,5339,4431,2911,
4435,3611,4423,9517,3243
};
static string CreateKey(int id, string resourceType)
{
if (id == 0)
return "";
var s = resourceType.ToCharArray().Sum(c => (int)c);
var a = Math.Max(resourceType.Length, 1);
return (17 * (id + 7) * resourceTable[(s + id * a) % 100] % 8973 + 1000).ToString();
}
// example
static void Main(string[] args)
{
for (int i = 1; i < 2000; i++)
{
Console.WriteLine($"{i,4}: {GetShipResourcePath(i, false, "full")}");
}
for (int i = 1; i < 1000; i++)
{
Console.WriteLine($"{i,4}: {GetEquipmentResourcePath(i, "card")}");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment